Repository navigation
feat(server): a workflow repeat grows within one run from its judge's result - #19
Merged
Merged
Conversation
… result A repeat can declare agent templates. Its judge's structured result may add agents for the next round (addAgents, deduplicated by key across the run), choose which inner stages rerun, and an optional dry: K ends the loop after K rounds that add nothing and ask for no rerun. An invalid or missing judge result fails the run instead of voting dry. Grown agents are recorded as launches (stage.key#round) when the judge's result is processed, one per update, so their rows show before the next round starts and resume never starts them twice. Seen keys, the dry streak and each round's stage selection are derived from the persisted judge results. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nd its keys are unique run-wide An accepting judge whose addAgents or rerun named an unknown template or stage, or was malformed, passed the repeat. Growth is now validated first, so invalid growth fails the run and never accepts or votes dry. Grown keys were deduplicated only within the current repeat, so a key could collide with a static agent elsewhere or grow in two repeats; seen keys now cover every spec agent and every earlier launch in the run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…thin # Conflicts: # apps/server/src/mcp/workflowRun.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Size: M. 211+/50− hand-written in
workflowRun.tsplus a one-word contract change, and 263+ lines of tests. This is the runner half of a stack; the service and tool half is the next PR.Problem
repeatreran a fixed set of inner stages untiluntilmatched. A judge could reject, but it could not add agents for what it found, and it could not send only some earlier stages back. Runs that needed to "dig deeper" had to go back to the agent that started them. Etan, verbatim:Design
repeatcan now take:templates: {<name>: {task, target?, resultSchema?}}. A template's task can use{{input.x}}as well as{{stage}},{{stage.agent}}and{{feedback}}.dry: K.addAgents: [{key, template, input, stage?}]. Each entry adds one agent to the named inner stage in the next round; with nostage, it goes to the first inner stage. A key counts once per run: a key the run has already seen, including a static agent id, is ignored.rerun: [innerStageId…]. Only these stages rerun their spec agents next round; the default is all. The judge's own stage always runs, and so does any stage that received new agents.until, unchanged.dry: K, K dry votes in a row end the loop withexit: "dry".maxis still the backstop, andonExhaustedstill decides fail or pass at the cap. A judge result that is missing, or that names an unknown template or stage, fails the run; it never counts as a dry vote.stage.key#roundand no task id the moment the judge's result is processed. That is one record per update, which keeps every update within the 2 KB wire budget. All of them are recorded before the next round starts anything.startstep that now also covers launches a crash cut off before their task id was saved.workflowRunstate is sent in full each time, and with 20 added agents it went over 2 KB in my first attempt.The native pattern it mirrors
This follows
INNER-LOOP-NATIVE-EXAMPLES.md:seenGaps, and spawns one agent per new gap. Here that isaddAgents, de-duplicated against the run's seen keys.dry < 2 && round <= 12; audit failures do not count as dry. Here that isdry: K,max, and an invalid judge result failing the run.rerun, and a non-emptyrerunmakes the round not dry.The spec is still JSON, not a script: templates are fixed in the spec, and the judge only picks instances of them.
Tests that failed first
I added the tests to
workflowRun.test.tsbefore writing any runner code. On the base, 6 of them failed:rejects bad references…(on the reservedinputstage id),grows the next round…,exits after K consecutive dry votes…,resumes a grown run…,a stop after growth…, anda run that grows survives a crash…. All 22 pass now.Each new test is named for the TLA property it checks for the new transitions:
waits for grown agents before starting the next stage or judgeresumes a grown run without launching an instance twicea stop after growth never starts a grown instance, across restartnever grows a round beyond maxa run that grows survives a crash at, and instead of, every persistThe fake port's barrier monitor now checks started, unsettled tasks instead of persisted intents, because a recorded added agent is an intent that is not running yet.
Mutation check.
wf10/mutations.mjsapplies one fault at a time and restores the file afterwards. Each fault turned the named test red:waits for grown agents…resumes a grown run…,a stop after growth…, crash sweepgrows the next round…grows the next round…exits after K…,repeat success requires…a stop after growth…Bytes
No tool text changes in this PR. The per-update wire budget is measured in the stacked PR (largest update 1,436 B with growth to 20 agents).
Gate
gate.sh fork/wf/integrationis green:apps/serverandpackages/contracts;workflowRun.test.ts: 22/22.Beyond the gate:
WorkflowRuns.test.ts,WorkflowRunRows.test.tsandMcpHttpServer.test.ts: 39/39 on this branch.Review round 1 (Codex: CHANGES_REQUESTED), fixed in
bacd92f6f5rerunstage, an unknown template, or a malformedaddAgentspassed the repeat. Growth is now checked beforeuntil, so invalid growth fails the run and never accepts or counts as dry. Failed first:an accepting judge whose growth is invalid fails the run instead of passing. It also pins that non-object results (null, a string,[]) fail.deduplicates grown keys across the whole run, not just the current repeat.workflowRun.test.ts24/24.Merged
wf/integrationafter #18 (9cd41b551c)<stage> · round N), built fromworkflowRun.round. Grown agents used to be recorded while the round was still N−1, so their phase didn't exist yet. Now the judge's turn validates the growth, then exits or advances to round N. The grown agents are recorded at the start of round N, one per update, before anything in that round launches.toRownow lists each phase's agents throughphaseAgents(): the spec agents of that stage, unless the last judge'srerunleft the stage out, followed by that round's grown agents. A grown agent'sphaseIndexpoints at its own round's phase.queuedAt. If the run ends before they launch, fix(server): server-run workflows list every phase up front with each agent's model and time #18 marks them not started. The catch is that fix(server): server-run workflows list every phase up front with each agent's model and time #18'ssnapshotOfdrops a queued row with noqueuedAton resume. The runner then re-records the first grown agent not already present, not the one at positionrecorded.length. A grown agent that launched before the restart is never recorded twice.workflowRun.ts: fix(server): server-run workflows list every phase up front with each agent's model and time #18'sworkflowPhasesnext to my growth helpers. I kept both, andrunsAgainnow takes the round.puts a judge's grown agents in their own round's phase, which reads as not started until they launchruns fix(server): server-run workflows list every phase up front with each agent's model and time #18's realderiveWorkflowGroupson the row. Round 1's phases readdone;draft · round 2andcritique · round 2readpending. With fix(server): server-run workflows list every phase up front with each agent's model and time #18's originaltoRowit fails, because the grown rows never appear.workflowRun.test.tsandWorkflowRuns.test.ts40/40.WorkflowRunRowsandMcpHttpServerpass 31/31, and client-runtimesubagentRuntime15/15. The mutation check still catches all 8 faults.Implementer: Claude Opus 5.5. Review rounds: 1.
🤖 Generated with Claude Opus 5.5 in T3 Code Nightly