Skip to content

feat(server): a workflow repeat grows within one run from its judge's result - #19

Merged
EtanHey merged 3 commits into
wf/integrationfrom
wf/10-grow-within
Oct 31, 2026
Merged

EtanHey merged 3 commits into
wf/integrationfrom
wf/10-grow-within

Conversation

@EtanHey

@EtanHey EtanHey commented Oct 31, 2026 •

Copy link
Copy Markdown
Owner

Size: M. 211+/50− hand-written in workflowRun.ts plus 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

repeat reran a fixed set of inner stages until until matched. 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:

"In an inner loop workflow, the workflow grows within. It doesn't need to go out and get to the one who created it."

"the growth within is deterministic upon what the judge ... decides".

Design

  • Spec. A repeat can 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.
  • What the judge can ask for. Its structured result can carry:
    • addAgents: [{key, template, input, stage?}]. Each entry adds one agent to the named inner stage in the next round; with no stage, 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 rounds. A round that adds no new agent and asks for no rerun is a dry vote. With dry: K, K dry votes in a row end the loop with exit: "dry". max is still the backstop, and onExhausted still 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.
  • Recording added agents. An added agent is recorded as a launch with key stage.key#round and 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.
    • A recorded launch starts only when its stage is current, through the same start step that now also covers launches a crash cut off before their task id was saved.
    • Resume only re-awaits launches that have a task. It no longer starts every saved intent eagerly, so it never starts an added agent from a later stage early.
  • Derived state. Seen keys, the dry streak and each round's stage selection are not stored separately. They are a pure fold over the persisted launches and the judge results already in the snapshot, so a resumed transition always recomputes the same result.
    • Deviation from the brief, flagged here: the brief asked to persist these as their own snapshot fields. A separate copy could disagree with the judge results it came from. It would also add bytes to every row update: the workflowRun state 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:

  • B, the October weave critic. The critic returns structured gaps, the code de-duplicates them by key into seenGaps, and spawns one agent per new gap. Here that is addAgents, de-duplicated against the run's seen keys.
  • A, deep weave R2. dry < 2 && round <= 12; audit failures do not count as dry. Here that is dry: K, max, and an invalid judge result failing the run.
  • C, the BFS weave. A round is dry if it found no new children and nothing needed re-mining; the boss's targets reopen earlier exploration. Here that is rerun, and a non-empty rerun makes 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.ts before writing any runner code. On the base, 6 of them failed: rejects bad references… (on the reserved input stage id), grows the next round…, exits after K consecutive dry votes…, resumes a grown run…, a stop after growth…, and a 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:

Test Property
waits for grown agents before starting the next stage or judge StageBarrier
resumes a grown run without launching an instance twice UniqueLaunch
a stop after growth never starts a grown instance, across restart NoStartAfterStop
never grows a round beyond max RoundsBounded
a run that grows survives a crash at, and instead of, every persist crash sweep: snapshots stay well formed, no duplicate launches

The 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.mjs applies one fault at a time and restores the file afterwards. Each fault turned the named test red:

Fault Failing test
A phase advances while an added agent is still running waits for grown agents…
Resume starts every saved intent at once resumes a grown run…, a stop after growth…, crash sweep
An already-seen key is added again grows the next round…
A resumed transition forgets the agents it recorded grows the next round…
An invalid judge result counts as a dry vote exits after K…, repeat success requires…
A stop no longer blocks starting an added agent 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/integration is green:

  • lint: 3 files, 0 diagnostics;
  • fmt: clean;
  • typecheck: apps/server and packages/contracts;
  • workflowRun.test.ts: 22/22.

Beyond the gate:

  • WorkflowRuns.test.ts, WorkflowRunRows.test.ts and McpHttpServer.test.ts: 39/39 on this branch.
  • A repo-wide typecheck I ran by accident: 36/36 packages.

Review round 1 (Codex: CHANGES_REQUESTED), fixed in bacd92f6f5

  • MUST_FIX 1. Growth was checked only when the judge rejected. An accepting judge with an unknown rerun stage, an unknown template, or a malformed addAgents passed the repeat. Growth is now checked before until, 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.
  • MUST_FIX 2. Seen keys covered only the current repeat. A grown key could collide with a static agent elsewhere in the spec, and the same key could grow in two repeats. Seen keys are now every spec agent id plus every earlier launch in the run, excluding only the agents being recorded in the current round's batch. Failed first: deduplicates grown keys across the whole run, not just the current repeat.
  • Mutation check. Two new faults are added and caught: an accepting judge skipping growth validation, and seen keys local to the repeat. All 8 faults turn their named test red.
  • Gate. workflowRun.test.ts 24/24.

Merged wf/integration after #18 (9cd41b551c)

Implementer: Claude Opus 5.5. Review rounds: 1.

🤖 Generated with Claude Opus 5.5 in T3 Code Nightly

… 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>
@github-actions github-actions Bot added the vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. label Oct 31, 2026
@github-actions github-actions Bot added the size:L Large coherent reviewed change, over 400 added lines label Oct 31, 2026
EtanHey and others added 2 commits October 31, 2026 04:43
…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
@EtanHey
EtanHey merged commit 61a2c42 into wf/integration Oct 31, 2026
9 of 11 checks passed
@EtanHey
EtanHey deleted the wf/10-grow-within branch November 2, 2026 00:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L Large coherent reviewed change, over 400 added lines vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant