fix(ship-budget): thresholds above the host call floor; a child hands off instead of stopping; parallel batches admit a prefix (GSTA-167)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
This commit is contained in:
garrytanandcapy-ai[bot] committed 2026-10-29 19:04:15 +00:00
1 parent ac8cd2abe1
commit d33461825a
12 files changed
+557 -83

No files matched your search

+37 -9
View File
@@ -50,7 +50,7 @@ With a cap set and no readable meter, start refuses
## The BUDGET line
BUDGET: used=<n> reserved=<n> unknown=<n> admission_cap=<n|none> tail=<n> unit=<u> meter=<m> epoch=<n> call=<n|unknown> next=<id> projected=<n> calibration=step:<f|prior>,dispatch:<f|prior> verdict=continue|delegate|stop
BUDGET: used=<n> reserved=<n> unknown=<n> admission_cap=<n|none> tail=<n> unit=<u> meter=<m> epoch=<n> call=<n|unknown> call_floor=<n> above_floor=<n|unknown> next=<id> projected=<n> calibration=step:<f|prior>,dispatch:<f|prior> verdict=continue|delegate|stop
| Field | Meaning |
|---|---|
@@ -61,6 +61,7 @@ With a cap set and no readable meter, start refuses
| `tail` | Tail reserve (scaled by the step factor once measured) plus stop overhead, held back from every admission |
| `unit`, `meter`, `epoch` | The meter contract: `capy-tokens` (root counter), `claude-usage-tokens` (journal usage), `estimate-tokens`; a meter change opens a new epoch |
| `call` | The per-call charge: two Capy readings in consecutive calls, or the last Claude Code call's usage |
| `call_floor`, `above_floor` | The host's per-call floor (see Delegation) and the charge above it, max(0, call − floor); the delegate rule compares `above_floor` |
| `next`, `projected` | What the check was for and its projection: the prior times the run's factor for that kind |
| `calibration` | The run's step and dispatch factors (see Calibration), or `prior` before the first measurement |
| `verdict` | `continue` (exit 0, prints `RESERVATION:` under a cap), `delegate` (exit 0), `stop` (exit 3) |
@@ -79,6 +80,11 @@ gstack-ship-budget check --run <id> --step 9 --next dispatch:specialist,red-team
gstack-review-log --start review --reservation <id>
```
Each reader is priced at max(its projection, the run's measured mean for that role over settled
dispatches). When the whole batch does not fit, `check` admits the largest prefix that does and
prints `ADMIT: k of n (remaining=<roles>)`: dispatch those k, then re-check the remaining roles
once they settle. Only a batch whose first reader does not fit stops, and `close` flags remaining
roles no later check requested (`DROPPED:`, status=incomplete until the owner accepts).
Roles are review-depth's: `specialist`, `red-team`, `adversarial-native`, `outside-voice`,
`fix-check`. `--finish <token>` is the pass's completion receipt: it settles that reservation and
every other dispatch reservation started in the same step, so reviewers admitted one at a time
@@ -92,27 +98,47 @@ BUDGET_CHECK_SKIPPED line and the run ends status=incomplete for the owner to ac
## Delegation
At start, a per-call charge of 100k or more delegates the whole /ship. Before Step 7 and before
Step 12, 150k or more (or an unknown charge) delegates the next segment (7–11.5, 12–22):
The delegate rule measures context above the host's per-call floor: what one call costs in a
fresh session with the ship skill loaded, before any /ship work. The floor is `call_floor` per
unit in `lib/ship-budget-calibration.json` (150k on Capy, where a fresh thread's calls cost
150–230k; 40k on Claude Code; 0 for the estimate meter, whose charge is always unknown), or
`start --call-floor <n>`, which the ledger records and every child inherits. At start, 100k or
more above the floor delegates the whole /ship. Before Step 7 and before Step 12, 150k or more
above the floor (or an unknown charge) delegates the next segment (7–11.5, 12–22). The BUDGET
line prints `call`, `call_floor` and `above_floor`, so each verdict can be checked:
1. `gstack-ship-budget handoff --run <id> --from 12 --to 22 --base origin/<base> --reading <n>` writes a
brief (mode 0600, under the run directory) with the pins (HEAD, merge base, working tree,
reviewed tree), the record with its six headings and start tokens, the decisions in scope
with the owner's words, the decision trail, the budget and the return contract. It reserves
the child's sub-cap: min(cap − used − reserved − unknown − the calibrated tail reserve and stop
overhead, the segment estimate), or `--sub-cap`.
overhead, the segment estimate), or `--sub-cap`. A child handing off reserves its whole
remaining sub-cap instead (cap − used − reserved − unknown − its stop overhead).
2. The child is a Capy subagent on the shared machine, or on Claude Code
`gstack-ship-budget launch --in <brief>`: a background `claude -p` (resolved through lib/claude-bin.ts)
with explicit permission flags and the return file named.
3. The child runs `verify-handoff` first; a moved pin refuses
([HANDOFF_PIN_MOVED](troubleshooting.md#handoff-pin-moved)). It admits against its sub-cap
with child_used = reading − reading at handoff, is the only writer of the record, and never
delegates again: a delegate rule stops it. It ends with `return` (at most 40 lines).
with child_used = reading − reading at handoff and is the only writer of the record. The
context rule never stops a child. When it fires at one of the child's boundaries:
- once the child has completed a step since `verify-handoff`, `verdict=delegate` hands its
remaining steps (the next step through the end of its segment) to a fresh grandchild
through these same four steps. The chain depth (1 for a child, 2 for a grandchild, at most
3) is recorded in the brief, the handoff and the new ledger;
- before its first completed step, at depth 3, or when the next step is past its segment,
`verdict=continue` with one `CONTEXT_HIGH:` line (call, floor, threshold, depth, reason).
The admission cap still stops a child (`reason=budget_exhausted`). It reconciles any
grandchild, then ends with `return` (at most 40 lines).
4. `gstack-ship-budget reconcile --run <id> --return <file> --reading <n>`; idempotent per handoff hash,
so a duplicate return charges nothing twice. A refused, incomplete or interrupted child
exits 3: regenerate the handoff or stop.
exits 3: regenerate the handoff or stop. Up a chain each token is charged once: the Capy
counter already includes the whole subtree, a session `launch` starts joins the Claude Code
meter of every ancestor, and under `meter=estimate` a child's returned `used` carries its
grandchild's.
`--delegate never` turns delegate into stop for hosts without children.
`--delegate never` turns delegate into stop for a parent on a host without children; a child
continues with a `CONTEXT_HIGH:` note instead.
## Stop and resume
@@ -144,7 +170,9 @@ largest observation times 1.5, rounded up to 10,000 tokens. The leave-one-out te
(test/ship-budget-calibration.test.ts) covers the per-call constant only, the one observed
across three runs; per-dispatch has two observations and stop overhead one. Only the Capy
meter has observations; the Claude Code and estimate units are seeded from it until a
Claude-metered /ship completes.
Claude-metered /ship completes. Each unit's `call_floor` is calibrated separately, with its
evidence in `call_floor_why`; a floor is the largest 10,000 multiple at or below its smallest
observed fresh call.
These constants are the prior. Each settled step or dispatch is measured on the next fresh
reading (a step from its check's reading to the next one; dispatches settled together as one