every part of a dreamport is made as a task. a coding agent takes one, writes that part of the game from the original, proves it frame by frame and opens a pull request. a week ago i made the tools behind that proof lighter. this time i looked at whole tasks, at where their hours and their money went. i measured 59 of them, changed the tools, the command and the page that starts tasks, and measured again. some of it got much better. what a task costs now i can't say yet, and i'd rather show that than hide it.
nearly half the time inside tools was spent waiting, and nearly half the money was spent reading the same conversation again.
the tasks ran between 3 and 10 november, all with the same agent program, and each kept a log with a time and a count of tokens for every step. together they took 11,208 steps and 12,302 calls to a tool, and cost $888 at list prices. the median task took 106 steps, ran 23 proofs and cost $10.13. its first run, up to the pull request, was 58 steps, $4.65 and 27 minutes. 42% of all the spending came after the pull request existed, on merges, conflicts and reviews.
| what | share |
|---|---|
| loops that only wait | 46% |
| the proof tools | 41% |
| the agent's own scripts | 8% |
| everything else | 5% |
| what | share |
|---|---|
| reading the conversation again on every step | 46% |
| writing new context | 32% |
| the model's own output | 22% |
so there were two things to go after. a slow proof costs hours, and a talkative one costs money on every step that follows it.
the proof wasn't slow where i expected. the original game was never the slow side.
a proof plays each recording of button presses in the original and in the port, and compares every frame. sonic advance has 72 recordings. its version in C is built to webassembly before it can run, which takes nine seconds, and the tool built it once for every recording: the same code, 72 times, eleven minutes of a 23-minute proof. the original runs at about 3,000 frames a second and was played twice, the second time only for pictures.
now the game is built once, and only when its code has changed. the original is played once. and recordings play several at a time, each in its own page of one browser, as many as the computer has idle cores and free memory for, eight at most.
| version | before | after |
|---|---|---|
| sonic advance in c, 72 recordings | 23:10 | 1:51 |
| sonic advance, 72 | 15:21 | 2:13 |
| sonic battle in c, 75 | 9:54 | 0:31 |
| sonic battle, 75 | 4:20 | 0:37 |
the small cases matter as much, since an agent runs them all day. one round of a proof on code that hasn't changed went from 12.5 seconds to 3.2. the check that ends a task, which proves the whole game and then runs the site's checks and its build, took 19.7 minutes in real tasks and takes 2.4.
playing recordings at once took two tries. my first version ran them as several jobs in one thread, and it stopped gaining past four: the tool's own thread was the limit, as filtering the sound alone was 15% of each job. giving each recording a thread of its own fixed that.
a proof that prints 200,000 characters is read again on every step after it. now it prints 2,346.
a whole proof used to print a report for every recording, matching or not. most of that was the same every time: this recording matched, as it did an hour ago. now it says in full only what's news, a recording that differs or one that changed, and sums up the rest by name.
| what prints | before | after |
|---|---|---|
| a whole proof of sonic advance in c | 200,580 | 2,346 |
| the check that ends a task | over 200,000 | 2,511 |
| the list of tasks free to take | 4,883 | 2,229 |
| the list of every note, asked at the start | 10,443 | not asked |
| the command itself | 21,212 | 19,857 |
the tools also took over two things the command used to make each agent work out. one asks which task to take and gets a name back in about 120 characters. the other writes the pull request's text, with its tracking lines, its clips and the game's numbers before and after, and leaves six lines for the agent to fill in. it refuses a text that still has an empty one.
the tools print half of what they did. the whole task didn't get reliably shorter, and that's the honest result.
to compare the old wording with the new, i ran whole tasks in a sealed copy: an agent on a cheap model, a made-up game, and a stand-in person who answers only with the path to the game. each ran from the command to its pull request.
| wording | steps | the tools printed | its own reading | whole proofs |
|---|---|---|---|---|
| old | 42 | 28,258 | 48,963 | 2 |
| old | 44 | 31,480 | 45,052 | 3 |
| new | 44 | 16,820 | 24,961 | 2 |
| new, cut off by the free plan's limit | 26 | n/a | n/a | 1 |
| new | 39 | 13,558 | 93,018 | 1 |
the tools' half is steady: about 30,000 characters a task before, about 15,000 after. the total is not. what an agent chooses to read by itself varies more than what the tools save, so the steps and the tokens of a whole task didn't fall in any way i could count on.
what changed is what the steps do. with the old wording the agent opened the tools' own code to learn how parts work, six times in one task, proved the whole game two and three times, and wrote the pull request by hand. with the new one it asked for its task, did quick rounds, never opened the tools' code and filled in a text the tool had written.
several agents can work on one game at once. they collided in code none of them meant to disagree on.
nothing in the tools is shared between agents, so they can run side by side. the trouble comes later, when each branch meets the others. i took the last eight pull requests that added a level to sonic advance in C and did again every merge they had made.
| result | merges |
|---|---|
| clean | 12 |
| a few files in conflict | 20 |
| 19 to 34 files in conflict | 4 |
in the 20, past the files the tools write themselves, three files carried nearly all of it: act.c in 16 merges, front.c in 13 and act.h in 12. none of it was real disagreement. each level registered itself by adding its name to the same shared lines, and in one file more than half the collisions were a comment that listed the levels made so far.
now every level has a row of its own in a table, in its zone's own file, and the engine reads the row where it used to name the level. a new level writes its row and changes one line, its own. the lines that name a level in those three files went from 95 to 2, and the game does exactly what it did: all 74 recordings came out as before, and the file of its progress is the same byte for byte.
all four wide conflicts were in branches built on a pull request still in review. that pull request went on changing, and the branch above never took the new commits: it was 11 to 30 commits behind when the one below was merged as a single commit. git then sees two unrelated histories of the same files.
the tool that brings a branch up to date now takes the newest commits of what the branch is built on first, and once that has merged, tells git that the main branch holds it. on one real branch, done again as it was, the files left for a person went from 26 to 5. on another they went from 31 to about as many, and that one is worth a section of its own.
that second branch was the second level of a zone, made at the same time as the first. both wrote the same new files, the zone's backdrop, its objects and its enemies. no tool settles two agents writing the same files at once, so i chose order: each level of a zone after its first now waits for the one before it. it doesn't wait for a review or a merge, only for a pull request to exist, and then starts on top of it.
that has a price, and i paid it knowingly. in sonic advance 3, 21 levels were free to take at once, and now 7 are, with the other 14 each waiting for the one before. the first two real levels made at once in different zones, after the table, collided in nothing a person wrote.
both were mine, both were sensible, and each blocked every case it hadn't thought of.
every change to a game's code has to show a clip of new frames, the original beside the port. moving the levels into a table changes no frame, so it had nothing to show and could never pass. a whole proof now keeps a small record of what it found, and when that proof is the same file as the main branch's, the record goes where the clip would. a check holds it to the very files that would merge.
the other rule was that a branch is only brought up to date when every recording matches. sonic advance in C shares the game's 74 recordings and matches 25 of them so far, so for that version the tool could never finish, and every conflict went to an agent or to me. it now finishes when no frame that matched before differs. what matched before is read from the last commit, never from a file an earlier run may have rewritten, so a merge that breaks a frame is refused however often it's tried.
the first real task on the new tools ended with its work done and its page saying it was still at it, for 48 minutes.
before its last words the agent had left a small wait running: sleep until no proof command is running. it looked for that command by name among everything running, and its own command line held the name. so it found itself every 20 seconds and could never end. the agent's program stays alive while anything it started still runs, and the page that starts my tasks took a live program for work.
the same kind of wait had already cost that task ten minutes, when the check it was waiting for had ended after four and a half. and the cause was partly mine: the page's instructions still said that check takes many minutes, from before it got faster, so the agent set it aside and watched it.
the page now ends a task by itself once its turn is over, nothing has been written for ten minutes and its processes have used under 3% of a core in that time. the stuck one used 0.5%. no model is asked, so it costs nothing. the instructions now say to run the tools and wait for them, and to write no waiting loop. the command had said that all along, and this agent did otherwise, so the page's rule is the one i count on.
three things i believed along the way, each corrected by measuring once more.
i said the new flow printed a third less into the conversation, after one pair of sealed tasks. the next task printed more than the old ones, by what it chose to read. one pair is not a result.
i planned to have the page bring conflicted branches up to date with no model, and found it had done so for four days. it had run 11 times: 4 settled alone, and 7 ended in real conflicts. it was only switched off while the part that looks after stuck tasks was paused, and that switch is gone.
and i expected the command to be a third shorter, as the table above shows. the saving was never in the words of the command. it was in what the tools print after it.
the number i set out to move.
a task cost $10.13 at the median before. after, i have two real tasks, both whole levels, which are among the largest tasks there are: $23.57 and $17.81, in 107 and 125 minutes. they don't compare with a median of every kind of task, and two of anything isn't a measure. they did still spend 19 and 39 minutes in waiting loops, which ran before the instructions against them changed.
so the proof is about twelve times faster, the tools say about a hundredth of what they did, and agents collide less. whether a task is cheaper needs a week of tasks on the new tools, measured with the same scripts. i expected 10 to 20% fewer tokens, and nothing so far proves or disproves that. i'll add the number here when i have it.
the proof is the same proof.
all eight versions were proven whole by the old tools and by the new. every file of progress came out the same, byte for byte. all 398 reports are the same but for their timings, and all 356 pictures are the same in the three games i compared them in. one row in one game was already stale before any of this, and both tools find it stale in the same way.
real tasks from their own logs, tools on the same commit, and conflicts by doing the merges again.
the 59 tasks are every task the page started in that week with that agent program. each log has a time for every step and the tokens it read, wrote and cached, and the cost is those tokens at the model's list prices. time inside a tool is the time between a call and its answer. a waiting loop is a call whose command sleeps until something else ends.
each proof was timed before and after on the same commit of the games, with other work running on the computer both times, so a small difference means little and a tenfold one means what it says. the sealed tasks ran in a sandbox with a made-up game, so that nothing of a real one was needed. the merges were done again with git, from the commits as they were, and counted by the files left in conflict.
the code is at github.com/NahuelGenchi/dreamports. the faster proof is its pull request 1051, the quieter tools 1052, the command 1055, the branches that keep up 1058, the table of levels 1059, and the order of a zone's levels 1070 and 1072.