Skip to content

exhaustion: a leaf that ran out of tokens settles ✓ on a judge's say-so — budget is not a first-class outcome and never crosses the exec→resident seam #271

Closed

Description

@santoshkumarradha

Problem

Headless run, 2026-09-01, dev 05b9953 (aforge do, deepseek-v4-flash pinned). A leaf hit its token grant mid-sh with a red build (undefined: logf at turn 20; an earlier blind edit had swallowed a test function's opening line), got its 4 landing turns, stopped with ⏳ ran out of tokens — 33 turns (cost: 178086 of 176834) — and 2 seconds later the node was ✓ done, summary = its own last line: "All 722 tests pass. Let me verify the dry-run tests specifically:". The two sibling tasks then briefed on truncated work and opened with "everything is already in place". The turn the ✓ bought away — actually running the binary — is exactly where the run's fatal bug (the blocker discarded at construction) would have surfaced. Same shape in #267's run; the two issues are one law in two organs.

Where it lives

  • The journal is honest: leaf_exhausted is recorded, and internal/store/leafrun.go's header says status is the scheduler's decision. The decision point is cmd/aforge/chat.go (~:1322): on leafRanOutOfRoom, revision.JudgeRemainder is asked, and remainder.Done overwrites the verdict to VerdictVerifiedSuccess — the else arm (splice a continuation via ReplanOverrunAs) never runs. Journal proof: the first exhaustion took the splice arm (plan_graph → subtree_spliced → job_growth → leaf_resumed); the second has none of those — just leaf_exhausted → one 10k-token judge call → node_completed, 2s apart.
  • The judge is shown almost nothing: internal/revision/judge.go (~:2149) sends the brief + the leaf's final text — not the transcript (which held the red build), not the diff, not the verification reading, not even that the leaf was cut off; the prompt actively says "exhaustion is not evidence of incompleteness". JudgeRemainder has zero tests.
  • The fact cannot cross the seam anyway: resident.ExecResult (internal/resident/runner.go ~:33) carries summary, money, turns — and no budget/exhaustion field. runOne sees err == nil and calls graph.Complete. Mid-graph nodes get no delivery gate (shouldGate = root children only), so the judge was the only check.
  • Metering defect on the same path: outcome.Meter.Reached is frozen at grant time and never updated across the landing turns — every ⏳ line and every stored leaf_exhausted.reached under-reports by ~12–14% (recomputed from the run's own usage rows: 172,791 actual vs 152,090 reported; 199,131 vs 178,086).
  • Verified pre-existing: the branch is byte-identical before one worker: swe and bare go, and the choice surface goes with them — chat and do always run linear #227 (the deleted worker-menu argument aside). The grant itself is not undersized — context sat at ~45k tokens, 92–99% cache hit, 33 turns bought; the spend went to blind-edit repair and four cold prefixes at replan.

The law

A leaf that ran out has no account. Its work is evidence for the next attempt, never a result. Only a leaf that itself reported done, inside its budget, settles a node ✓. Exhaustion is a measured fact; doneness is a claim; a measured fact is never overturned by an unmeasured claim (the same law as #267).

The fix

  • Budget crosses the seam: resident.ExecResult carries the exhaustion kind + meter; runOne routes it through the requeue rule it already applies on the error arm — never graph.Complete.
  • chat.go's remainder arm is demoted: JudgeRemainder may size the remainder, never manufacture a ✓. remainder.Done on a cut leaf still splices a continuation with the stated remainder "verify" — one cheap leaf when the judge was right, the missing turn when it was wrong. Loops are already bounded (MaxOverrunRounds = 3).
  • Feed the judge what it judges: the exhaustion record, the last N banked turns, the workspace diff, the verification reading.
  • Meter: recompute Reached at land time.
  • Surfaces: a ⏳ line is followed by ↻ or by "carried over", never by ✓ on the same node with no splice between.

Replication and acceptance (functional, required)

Harness exists: the runaway scripted completer in internal/exec (a leaf that tool-calls every turn, billing tuned to cross the grant) + cmd/aforge's scripted brain with the judge scripted to answer {"done": true} — the adversarial-but-observed case.

  1. The node is not done; no node_completed without an intervening splice. (Red today.)
  2. leaf_exhausted.reached equals the final spend, not the grant-time reading. (Red today.)
  3. Either the splice triple exists or the node is released pending with attempt+1 — and the next brief carries the continuation headers and the stated remainder.
  4. Exit 2, never 0; the stream shows ⏳ then ↻, and never ✓ <task> between them.
  5. Seam unit: Outcome{Stop: budget} → ExecResult carries it and runOne does not complete.

Dependencies

Same law as #267 (settlement side); independent code. #133 is the same law in the shaper (cite as precedent). Meter drift is adjacent to #161 but mechanically distinct (usage blocks all arrived; the frozen field is local).


Drafted with CodeAF · reviewed and owned by the author

Activity

  1. santoshkumarradha commented on Sep 1, 2026

    @santoshkumarradha
    MemberAuthor

    Live evidence, 2026-09-01: a balanced-crew headless do run at dev 32fd51c (glm-5.3-flash hands / glm-5.3 brain, $1.45, 52m, 14 nodes, exit 2) was given THIS issue as its brief — and reproduced it ~8 times while working on it. Textbook signature from the stream: ⏳ runner.go edits — it was still working when it ran out of its tokens — 9 turns in (cost: 381163 of 302008) at 18m56s, then ✓ runner.go edits (linear) at 18m58s — two seconds, no splice between. Every worker cut mid-edit was marked ✓, successors briefed on truncated work and re-litigated the same four sites; roughly ten leaves' grants went to that re-work. The delivery gate then refused correctly (no #267 acquittal shape) — its refusal independently named the unverified claims. The run's attempted fix is not usable (the new ExecResult budget fields were never populated at the construction site — dead code — and its test file never compiled), but the shape of the failed attempt is itself confirmation of the issue's premise: nothing that runs after the ✓ can recover the cut work.

  2. added 2 commits that reference this issue on Sep 1, 2026
    fb264e4
    74e4a7d
  3. added a commit that references this issue on Sep 1, 2026
    9a1678a
  4. santoshkumarradha commented on Sep 2, 2026

    @santoshkumarradha
    MemberAuthor

    Post-merge evidence from a same-task/same-model re-bench on dev 805b615 (caddy-analyzer#78, deepseek-v4-flash pinned):

    The fix holds. All three exhausted leaves carried a resume before completion (leaf_exhausted → growth → leaf_resumed → node_completed in the journal; 4 leaf_resumed events vs 1 pre-fix), and zero ⏳→✓ with nothing between (pre-fix: 1 of 2 was a free ✓).

    One number to look at: the ⏳ lines now report 284719 of 150000, 234065 of 168586, 223156 of 152322 — 137–190 % overruns, where both pre-fix lines said ~101 %. Consistent with Meter.Reached now being read at land rather than at the last write, but the magnitude is far beyond the 12–14 % under-report this PR's message predicted. Either leaves genuinely overrun their meter by that much before landing (a budget-enforcement question), or the landed figure double-counts. Worth a look; not re-opening this issue for it.

  5. added
    bug
    on Oct 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions