Skip to content

fix(server): t3_workflow_run typed spec, strict decoding and a forwarded judge contract - #22

Merged
EtanHey merged 6 commits into
wf/integrationfrom
wf/12-tool-description
Oct 31, 2026
Merged

EtanHey merged 6 commits into
wf/integrationfrom
wf/12-tool-description

Conversation

@EtanHey

@EtanHey EtanHey commented Oct 31, 2026 •

Copy link
Copy Markdown
Owner

Size: L. Why L: description rewrite + the decoder fixes it needs; 391 of 626 added lines are tests. (6 commits.)

Problem

A plain-model eval (real T3 sessions of bare Claude Code and Codex, CLI subscriptions, no user instructions) showed that models rarely write a valid t3_workflow_run spec on the first call: Haiku 0/10, Luna 4/10, Sol 1/10. A judge grew the run in only 1 of 12 growth trials. The server also accepted some wrong specs silently:

  • A stage with both agents and repeat ran its agents and dropped the repeat.
  • Unknown keys were stripped, so the run differed from what the model wrote.

Fix

Server (each with a failing test first):

  • Rejected now (invalid_request, stage named):
    • agents + repeat in one stage.
    • Unknown keys at any level. The tool outline passes them through via StructWithRest, so the service's strict decode sees them.
    • Placeholders that mention a spec id but resolve to nothing ({{stage.draft}}, {{draft.a.result}}).
    • Stage errors are judged by the stage's own variant, not the union, so a repeat error no longer also reports "missing agents".
  • until.path checks: a path is rejected in only two cases. Either a segment falls on a closed object (additionalProperties: false) where neither properties nor any patternProperties pattern matches it, or the path starts with one of the loop's own stage/agent ids that the schema doesn't declare (the stage.agent.field guess). A matching pattern allows the segment and the check continues into that pattern's schema. A pattern that fails to compile counts as open and never causes a rejection. Open schemas stay valid. Both reviewer schemas complete, as they did on the base: {"properties":{"reason":…},"required":["ok"]}, and the closed {"properties":{"reason":…},"patternProperties":{"^ok$":{"type":"boolean"}},"additionalProperties":false,"required":["ok"]}, each with until.path:"ok".
  • Judge schema. If the parent gives none, the server generates one with feedback: string plus the field until reads. That field is written last, so until.path:"feedback" and "feedback.ok" keep their type; this is tested through the real result validator. With templates, the server adds addAgents (template and stage enums) and rerun. If the parent gives a judge schema, the parent's schema wins. Its properties, required, and any addAgents/rerun it declares are kept as written; the server only adds growth fields the parent left out. A test pins this decision.
  • Defaults:
    • judge defaults to the last inner stage's only agent.
    • An inner loop stage may be agents: [], as a slot the judge grows into.
  • Loop look-ahead reads: inside a loop, a stage may read a same-loop stage at or after its own position. It gets the last round that stage ran in, never a sibling that finished earlier in the current round, including after a resume. With nothing earlier, whole-stage and agent reads are both null.
  • Advertised schema: agents (also inside repeat.stages) are typed as objects. Codex sent every agent as a JSON string when the array had no item type. advertisedJsonSchema drops the allOf/additionalProperties: {} noise that StructWithRest adds (unit test).

Description: the spec is a compact TypeScript type. equals now includes null.

Final description (1,261 B serialized)

Run agents in stages; returns now, wakes you when done.
type Spec={name:string;stages:Stage[]}
type Stage={id:string;agents:Agent[]}|{id:string;repeat:Loop} // never both; agents parallel
type Agent={id:string;task:string;target?:{model?:string;options?:object}/*omit to inherit model/options; options must match model*/;isolation?:'shared'|'worktree';resultSchema?:JSONSchema}
type Loop={stages:{id:string;agents:Agent[]/*may be empty*/}[];judge?:string/*agent id in LAST stage; defaults to its sole agent*/;until:{path:string/*judge result field, e.g. 'ok'*/;equals:string|number|boolean|null};max:number/*1-10 rounds*/;onExhausted?:'fail'|'pass';dry?:number;templates?:{[name:string]:{task:string}}}
Tasks: {{stageId}} or {{stageId.agentId}} insert earlier results. After a loop use inner stage ids, never its id. Loops rerun stages in order; forward/self references and {{feedback}} read last round (null in round 1). The judge's result must have until's field; its schema is generated if omitted. With templates, judge may return addAgents:{template:string;task?:string;input?:object/*{{input.x}}*/;stage?:string}[] for next round and rerun:stageId[]. dry:N ends after N rounds with neither. Only loop judges add agents; put round 1 inside the loop.

Eval evidence (same bare harness, eval-bare/run.cjs; 6 prompts × 3 models × 2 trials; trial prompts unchanged)

Iteration Head Haiku first-call Luna first-call Sol first-call Growth (Haiku / Luna / Sol) Never found the tool
Baseline 7231106412 0/10 4/10 1/10 1/4 · 0/4 · 0/4 (1/12) 0/30
1: TS description, strict decode, server-generated judge schema 46e2bcdc35 2/10 4/10 4/10 4/4 · 0/4 · 4/4 (8/12) 0/30
2: object-typed agents, loop look-ahead reads bbe4da2d06 1/7 ¹ 5/10 7/10 1/1 · 3/4 · 4/4 0/27
3: judge default, empty loop stages edda7a6354 7/10 7/10 10/10 3/4 · 2/4 · 4/4 (9/12) 0/30
4: review round 1 fixes + description cut ddb61bd8e4 7/10 5/10 10/10 4/4 · 1/4 · 4/4 (9/12) 0/30
5: restore the judge-result/until sentence 154db3ec33 5/10 6/10 10/10 4/4 · 1/4 · 4/4 (9/12) 0/30

Targets: Haiku ≥ 5, Luna ≥ 7, Sol ≥ 7, growth ≥ 6/12. Iteration 5 misses the Luna target (6/10); Haiku meets its target exactly.

Iteration 4's two Luna until-omitted misses lined up with the cut dropping the sentence tying the judge's result to until. Restoring it (iteration 5) left 0 until-omitted misses.

Iteration 5's first-call misses:

  • Luna:
    • 2× dry:0 (must be 1–10).
    • 1× no judge with several agents in the last stage.
    • 1× judge not in the last stage.
  • Haiku:
    • 3× fastMode/serviceTier in target.options (see the finding below).
    • 1× tool-input JSON that failed to parse.
    • 1× {{revise.draft.writer}}.

With 2 samples per case, iterations 3–5 put Luna at 7, 5, 6 and Haiku at 7, 7, 5.

Iteration 5 also:

  • Ever accepted: 10/10 · 8/10 · 10/10.
  • Completed: 8/10 · 8/10 · 10/10.
  • Delegate control: 6/6.
  • Wakes: exactly one per accepted run (28/28).
  • Isolation probe: passed on attempt 6 of 8.

¹ Iteration 2's matrix stopped on the harness's 8-minute trial watchdog during a long Haiku growth run. I resumed it, but my own source edits then restarted the resumed dev server mid-trial. Those resumed trials are excluded, so iteration 2 counts only the 31 trials recorded before the watchdog.

Harness notes

  • Luna probe flake: the pre-matrix isolation probe sometimes fails because Luna (Codex code mode at low effort) doesn't find the deferred MCP tools. The baseline had this too. The probe prompt alone (not the trial prompts) gained one sentence pointing at code mode. The probe passed on attempt 6 in iteration 3, attempt 1 in iteration 4, and attempt 6 in iteration 5. No trial's parent failed to find t3_workflow_run (0/30 every iteration).
  • Rerun state: the harness isn't idempotent on one checkout, since its project and auth cookie persist in the checkout's .t3. My runner moves that state aside between attempts, never deletes it.
  • Report sentence (review N1): the report's relaunch sentence is now derived from each trial's recorded attempts. Iteration 4 reads "No trial launched more than one workflow attempt".
  • Unreviewed labels: false-claim labels are unreviewed; the harness never auto-labels them.

Finding outside this PR

T3 accepts a Haiku parent selection carrying fastMode:false, then rejects those same inherited options when a child targets Haiku. This is checkTarget, shared with delegate_task, and it is 3 of Haiku's 5 first-call misses in iteration 5. The description says to omit target; a server-side decision is a separate PR.

Bytes

Tool list (mcpToolListJsonBytes): 48,093. That is +987 over wf/integration (47,106) and +1,984 over upstream main (46,109). The t3_workflow_run description is 434 → 1,261 B: the round-1 cut saved 153 B and restoring the until sentence added 42 B back. Its input schema is 278 → 438 B. Agent instructions: +0 (Claude append 5,135, Codex additional context 6,865, both unchanged). agentContextBudget.json updated.

Gate

bash gate.sh fork/wf/integration is green on 0795c5b13e: lint 0 diagnostics on 8 files, fmt clean, typecheck apps/server + evals, 80 server tests in 4 changed files, 411 eval grader tests. AgentContextBudget.test.ts and advertisedJsonSchema.test.ts also pass. All 8 cases of the reviewer's round-2 probe (reviewer-probes-r2-extended.mjs) complete on this source, including the closed pattern schema. The round-2 fix is decoder-only and the description is unchanged, so iteration 5's eval numbers still apply.

Implementer: Claude Opus 5.5 (T3 Code Nightly). Review rounds: 2 (Codex gpt-6.1-sol; round 1 FIX, round 2 one blocker on R3). Defects found in review and fixed here:

  • R1: look-ahead reads could see the current round.
  • R2: the default feedback field overwrote until's field.
  • R3: open judge schemas were rejected, and in round 2 a closed schema whose patternProperties allow the field.
  • N2/N3/N1: addressed as described above.

🤖 Generated with Claude Opus 5.5 in T3 Code Nightly

EtanHey and others added 3 commits October 31, 2026 13:31
… its spec

A stage with both agents and repeat ran its agents and silently dropped the repeat;
unknown keys anywhere in a spec were stripped, so a run differed from what the model
wrote. Both are now invalid_request with the stage named. Placeholders that mention a
spec id but resolve to nothing are rejected, and until.path is checked against the
judge's declared resultSchema.

The judge no longer needs a parent-written resultSchema: the server gives it one with
the field until reads, and adds the addAgents/rerun contract when the repeat has
templates, so the judge sees the growth shape in its task.

The tool description now types the spec as TypeScript.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rtise as objects

Codex parents sent every agent as a JSON string because the advertised schema gave
agents no item type; agents (also inside repeat.stages) now advertise as objects.

Inside a repeat, a stage may now read a same-loop stage that has not run yet this
round: it gets last round's results, or null in round 1. A rewriter can fix its own
previous version instead of failing with "has not run yet".

The description says target can be omitted to inherit the parent's model and options,
and that only a loop's judge adds agents, so round 1 belongs inside the loop.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… loop stages

A repeat that names no judge now takes its last stage's only agent; Sol parents left
judge out while naming that agent "judge". A loop's stage may start with no agents,
as the slot its judge grows agents into.

The description says target options must be ones that model lists, and that after a
loop its inner stages are referenced, not the loop's id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:L Large coherent reviewed change, over 400 added lines labels Oct 31, 2026
EtanHey and others added 3 commits October 31, 2026 14:57
…a, until checks

- A same-loop stage that has not run this round reads only the last round it ran in,
  never a sibling finishing first in the current round, including after a resume.
  A whole-stage read with nothing earlier is null, as an agent read is.
- The generated judge schema writes until's field after the default feedback field,
  so until.path "feedback" or "feedback.ok" keeps its type.
- until.path is rejected only when the judge's schema rules it out: a closed object
  (additionalProperties: false), or a path starting with one of the loop's own
  stage/agent ids that the schema does not declare. Open schemas stay valid.
- A parent's own judge schema wins; the server only adds absent growth fields.
- Description: cut 153 B and advertise equals as nullable.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ntil again

The round-1 cut dropped the sentence linking the judge's result to until, and Luna
then omitted until in both grow-critics trials. Restore it, worded for a parent schema
or a generated one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A closed judge schema (additionalProperties: false) still allows fields its
patternProperties match, so until.path is now allowed when any pattern matches the
segment, and descends into that pattern's schema. A pattern that fails to compile is
treated as open and never rejects.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@EtanHey
EtanHey merged this pull request into wf/integration Oct 31, 2026
9 of 11 checks passed
@EtanHey
EtanHey deleted the wf/12-tool-description 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