Skip to content

ship-budget resume opens a new meter epoch for a successor thread (GST-1655) - #4088

Merged
capy-ai[bot] merged 7 commits into
mainfrom
capy/gst-1655-ship-budget-successor
Nov 6, 2026
Merged

capy-ai[bot] merged 7 commits into
mainfrom
capy/gst-1655-ship-budget-successor

Conversation

@garrytan

@garrytan garrytan commented Nov 6, 2026 •

Copy link
Copy Markdown
Owner
{
  "schema_version": 1,
  "pr": 4088,
  "head": "1bd410ddf43cb021564b2da290d16a79cccc92b2",
  "version": "1.96.0.0",
  "base": "main",
  "gate": {
    "default": {
      "pass": 1614,
      "fail": 0,
      "skip": 0
    }
  },
  "ci_carried": [
    {
      "lane": "default",
      "run": 42266234508,
      "attempt": 1,
      "tree": "dc2e9bfbe6659429e1091bc40e0e4ca7fcd3e980"
    }
  ],
  "session_kind": "unattended",
  "head_tree": "dc2e9bfbe6659429e1091bc40e0e4ca7fcd3e980",
  "product_patch_id": "4fedf49a68a70accae9669c4d4b4bed18f65738f",
  "gstack_version": "1.96.0.0",
  "review_depth": {
    "depth": "full",
    "class": "code",
    "runtime_lines": 68,
    "rules": "70895942bb8a8ee2",
    "base": "cb8f9eaeacf950180a5fc9ecb6e78a2787d35768",
    "registry": "cb8f9eaeacf950180a5fc9ecb6e78a2787d35768",
    "gate_scan": {
      "tagged": 0,
      "head": "1bd410ddf43cb021564b2da290d16a79cccc92b2"
    },
    "reasons": [
      "risk:money",
      "runtime=68"
    ],
    "risk": [
      "money"
    ],
    "mode": "panel"
  },
  "pregate": "requires-remote cleared @dc2e9bfbe665 (7 checks, current for 1bd410ddf43c)",
  "requires_remote": [
    "free-tests.yml/cso-macos-launcher: https://github.com/garrytan/gstack/actions/runs/42266234508/attempts/1",
    "free-tests.yml/macos-named-regressions: https://github.com/garrytan/gstack/actions/runs/42266234508/attempts/1",
    "windows-smoke.yml/windows-smoke: https://github.com/garrytan/gstack/actions/runs/42265249826/attempts/1",
    "pregate.json/remote_gate: remote-gate tree=dc2e9bfbe665 tests=35999 skipped=93 runs=42266234508/1 profiles=ci-reuse/free-tests heads=1bd410ddf43c verified=2026-11-06T18:06:35.142Z"
  ],
  "issues": {
    "fixes": [],
    "refs": [],
    "flakes": []
  },
  "docs": {
    "status": "current",
    "scope": "docs/ (ship-budget.md, troubleshooting.md and the rest of docs/) plus the changed bin usage and changelog.d fragment"
  },
  "review_loop": {
    "passes": 2,
    "blocking_found": 1,
    "deferred": 0,
    "noted": 4,
    "fixed": 1,
    "scope": "frozen",
    "rounds": 2,
    "ledgers_read": 3,
    "dispatches": {
      "specialist": 6,
      "red-team": 2
    }
  },
  "review_targeted": {
    "classes": [
      "money"
    ],
    "rules": "30e6bce187be0d59",
    "brief_sha": "7f92a0d0a8319c3c0e076fb3b1a4689c45120b2be2c14dfc7d4cb03aafa9d6a5",
    "product_patch_id": "4fedf49a68a70accae9669c4d4b4bed18f65738f",
    "status": "done",
    "findings": 1,
    "raised_by": "targeted"
  }
}

What changed

A successor resume now refuses while a reader dispatch still spends on the previous thread's counter, instead of opening an epoch that drops that spend

A successor resume now refuses while a reader dispatch still spends on the previous thread's counter, instead of opening an epoch that drops that spend.

Before/after as text: A successor resume now refuses while a reader dispatch still spends on the previous thread's counter, instead of opening an epoch that drops that spend
--- Before · before.txt · captured output
+++ After · after.txt · captured output
 $ gstack-ship-budget check --step 9 --next dispatch:specialist --reading 41M   # thread A reserves a reader dispatch
 $ gstack-ship-budget resume --meter-source jam_B --reading 3M   # successor thread B takes over while the reader runs
+resume --meter-source jam_B: dispatch reservation <run>-r2 (step 9, open) still has readers on jam_A counter, 
+which the new epoch cannot see; wait for them to settle, settle each with a reading of that counter 
+(gstack-ship-budget settle --run <run> --reservation <run>-r2 --dispatched-at <its reading when the readers 
+started> --reading <its cost.tokens>), then resume
+exit=2 (BUDGET_READING_REJECTED)
-EPOCH: 2 meter=capy unit=capy-tokens carried_used=1000000 source=jam_B previous_source=jam_A
-RESUMED: from=running
-BUDGET: used=1000000 reserved=7430000 unknown=0 admission_cap=200000000 tail=4480000 unit=capy-tokens meter=ca
-py epoch=2 call=unknown call_floor=150000 above_floor=unknown next=- projected=0 calibration=step:prior,dispat
-ch:prior verdict=continue
-exit=0
 

Why

A /ship run handed to a successor thread hit BUDGET_READING_REJECTED because the new thread's counter starts near zero, so the run could not continue on one budget. gstack-ship-budget resume --meter-source <jam id> now opens a new meter epoch at the successor's readings and carries the tokens and credits already spent. It refuses while a handoff child or a reader dispatch still spends on the old counter, so that spend gets settled first and is never dropped.

Blast radius

Only gstack-ship-budget resume --meter-source and start --meter-source take the new path; a resume without --meter-source runs the same code as before, and no /ship prose passes the flag yet (see Review notes). The existing ship-budget suite (24 cases) and the 10 successor cases pass at this tree, and the refusals were walked end to end against the bin in a scratch state root (QA probes below).

Approvals

Approved: yes (record r-ab96ab5e21a3). The full approval record stays private: this repository is public or its visibility is unknown.

Review-loop grant: the Captain (GStack Minder) granted one more scoped fix and fix-check for this PR (approval a-702b77e0ebd1); it was spent on the dispatch-reservation guard below.

Summary

A run that moves to a successor thread keeps one budget. The successor's counter opens its own epoch, spend carries across epochs in both tokens and credits, and the observe hard stop and admission count every epoch. A reading below the last one of the same epoch is still refused. Pre-landing review added two guards on the successor path. A resume is refused while a handoff child is unreconciled (with the reconcile command that keeps the child's spend), and while a reader dispatch reservation is open or consumed (with the settle command). resume --rebuild-from-record takes the same flags.

Test Coverage

Step 7 audit (pass 1, tree f60bbb92): 14 of 14 new code paths covered (100% value-weighted), quality ★★★ 11, ★★ 3. Tests: 1739 → 1739 (+0 new from the audit; the branch adds test/ship-budget-successor.test.ts). Test value: 0 tests written, 1 rejected by the authoring gate (rebuild with --credits on a record that held no credits: no credible regression), 0 existing tests extended, 0 paths weakly covered.

The pre-landing fix adds one case, written failing first: "a successor cannot open an epoch while a dispatch reservation still has readers on the predecessor's counter" (failed at 7a7b49e with exit 0 instead of 2; passes at 887accd).

Tests ran: default (bun run test) carried from CI free-tests at the pushed head (see Test plan).

Pre-Landing Review

Pass 1 (full panel, money path, depth full) at 7a7b49e, plus Step 11 voices (adversarial-native, outside voice openai/gpt-6.1-sol, targeted): 1 blocking finding.

  • CRITICAL (outside voice, p1/outside-voice#1; targeted#1 and the red team saw the same gap below the floor): a successor resume guarded open handoffs but not open or consumed dispatch reservations, so readers still running on the predecessor's counter settled on the new epoch and their remaining spend left the budget. Fixed in 887accd: the resume is refused with BUDGET_READING_REJECTED naming each reservation and its settle command; failing-first test added; docs/ship-budget.md says so.

Pass 2 (full on the fix range 7a7b49e..887accd: specialists, red team, targeted): no blocking findings; 3 notes below.

REVIEW_LOOP: passes=2 blocking_found=1 deferred=0 noted=4 fixed=1 scope=frozen ledgers_read=3 dispatches=8

Gate edits: none detected (1 listed, 0 read; patterns: RH-1,RH-3,RH-4,RH-12,RH-13,RH-14,RH-15,RH-16; unlisted idioms: none)

Outside review: completed (openai/gpt-6.1-sol via host subagent, pass 1); its one finding was the blocker above, now fixed. Pass 2 ran no outside voice (once per invocation by plan).

Review notes

Below the blocking floor (advisory, informational, test-gap or wording items); recorded here and not fixed in this PR. Items marked (accepted) were accepted by the Captain as PR-body notes before this run.

  • INFORMATIONAL ship/DRIVER.md.tmpl:60 (accepted) no /ship prose passes --meter-source, so a successor counter above the last reading is folded into the old epoch silently (red-team, adversarial-native)
  • INFORMATIONAL lib/ship-budget.ts:481 (accepted) epochs[].credits stores the cumulative credits total, not the closed epoch's own spend; nothing reads the field today (state-machines, targeted)
  • INFORMATIONAL lib/ship-budget-cli.ts:457 (accepted) --meter-source '' counts as a successor but is never recorded, so every resume opens a new epoch and skips the monotonic guard
  • INFORMATIONAL lib/ship-budget-cli.ts:457 (accepted, part of the --meter-source note) on a ledger with no recorded source, a same-thread resume naming its own jam id opens a spurious epoch and drops the spend since the last reading; the EPOCH line omits carried_credits when the run meters no credits (red-team, targeted, adversarial-native)
  • INFORMATIONAL lib/ship-budget.ts:464 after a successor resume, the predecessor's trailing note passes the value>=last check against the successor's floor and books phantom spend; note/check carry no source
  • INFORMATIONAL lib/ship-budget-cli.ts:494 resume --rebuild-from-record drops handoffs before the successor check, so an open handoff child is not refused on a rebuilt ledger
  • INFORMATIONAL lib/ship-budget-cli.ts:463 the settle remedy (and the handoff reconcile remedy) omit --credits, so on a credits-metered run the readers' predecessor-side credits drop from the run's credits total when the epoch closes
  • INFORMATIONAL lib/ship-budget-cli.ts:463 the refusal tells operators to settle an open (never-started) dispatch reservation; release is the matching action for an unstarted one
  • INFORMATIONAL test/ship-budget-successor.test.ts:145 the new dispatch-reservation test covers only an open reservation; the consumed branch of the guard has no test
  • (accepted) coverage gaps for tokens-only and non-capy successors; a reconcile without --return writes a child off (main's semantics, documented)

Exploratory QA

Report-only smoke against the bin in a scratch state root (qa/ and qa2/ under the run directory), 5 probes, all pass:

  1. Successor resume while a handoff child is open: exit 2, the refusal names reconcile --run <run> --return <return file>, ledger bytes unchanged.
  2. Child returns, reconcile --return charges it (child=complete child_used=4800000), then the successor resume opens epoch 2 with carried_used=6000000.
  3. Successor resume with an open dispatch reservation (at 887accd): exit 2 naming the settle command.
  4. After settle on the predecessor's counter, the successor resume opens epoch 2 with carried_used=6000000.
  5. Same-source resume behaves as before (no epoch for the recorded source).
    The QA method sections (qa/sections/exploratory.md, scope.md) were not read for this smoke, to keep spend down; the probes are direct CLI checks, not a charter run.

Design Review

No frontend files changed — design review skipped.

Eval Results

No prompt-related files changed — evals skipped.

Review bot comments

No review bot comments.

Plan Completion

Plan completion audit: not run (no plan is bound to this branch and no docs/designs/ file matches).

Verification Results

No Step 8.1 obligations (no bound plan). Exploratory QA: 5 PASS, 0 FAIL, 0 BLOCKED, 0 NOT RUN.

TODOS

No TODO items completed in this PR.

Documentation

Status: current. The docs already describe the successor-handoff budget change, so no edits were needed.

Scope: the committed diff 8d7091a..HEAD on capy/gst-1655-ship-budget-successor (8 files; no staged, unstaged or new files). Searched for docs that mention resume, --rebuild-from-record and --meter-source.

File Status
docs/ship-budget.md Current: the new Successor handoff section matches cmdResume and newEpoch
docs/troubleshooting.md Current: the BUDGET_READING_REJECTED and BUDGET_LEDGER_INVALID fixes match result-codes-budget.ts
changelog.d/capy-gst-1655-ship-budget-successor.md Current: fragment present
bin/gstack-ship-budget Current: its usage header lists --meter-source and --credits
ship/sections/budget-handoff.md.tmpl Not edited: accurate, but successor resume is not mentioned (workflow prose)

Coverage debt: resume --meter-source has reference docs (ship-budget.md, troubleshooting.md) and how-to docs (the ship-budget.md example), but the /ship budget-handoff section doesn't mention it. That section is a common gap and can be filled with /document-generate or a separate skill-prose change. Diagram drift: none; no diagrams cover the ship-budget ledger.

Test plan

  • bun run test (lane default): carried from CI free-tests run 42266234508/1 at 1bd410d, tree dc2e9bfbe665 (EVIDENCE: FRESH, tests_ran=1614 files, 35999 tests); pregate requires-remote lanes cleared (cso-macos-launcher and macos-named-regressions from run 42266234508, windows-smoke from run 42265249826)
  • bun --no-env-file test --timeout=30000 test/ship-budget-successor.test.ts test/ship-budget.test.ts: 34 pass, 0 fail at 887accd
  • bun run typecheck: zero errors at 887accd

🤖 Generated with Claude Code

Open in Capy

…ounter (GST-1655)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@trunk-io

trunk-io Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

😎 This pull request was merged.

garrytan and others added 6 commits November 6, 2026 16:40
…test-of-test ratchet, GST-1655)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Review-Finding: p1/red-team#1 reader=red-team
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
…ing review)

Review-Finding: p1/outside-voice#1 reader=outside-voice
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
…out it writes the child off (GST-1655 fix-check#1)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
…readers on the previous counter (pre-landing review)

Review-Finding: p1/outside-voice#1 reader=outside-voice
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@capy-ai
capy-ai Bot merged commit a19130d into main Nov 6, 2026
67 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant