feat(ship-budget): --delegate measured: an unknown charge continues, a measured call 150k above the floor delegates

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-30 05:27:52 +00:00
1 parent d9ce8b9cba
commit 5282f34dfd
5 files changed
+25 -6

No files matched your search

+1 -1
View File
@@ -6,7 +6,7 @@
* reserve fit under the cap.
*
* start --record <path> [--token-cap <n|none>] [--meter capy|claude|estimate] [--reading <n>] [--prior-reading <n>]
* [--session <id>|--nonce <v>] [--reserve <n>] [--delegate auto|never] [--calibration <file>] [--ledger <path>]
* [--session <id>|--nonce <v>] [--reserve <n>] [--delegate auto|never|measured] [--calibration <file>] [--ledger <path>]
* check --run <id>|--record <path> --step <id> --next <id|dispatch:<role>[,<role>...]> [--reading <n>] [--prior-reading <n>] [--returned <id>[,<id>...]] [--runtime-lines <n>]
* settle --run|--record --reservation <id> [--unknown] [--reading <n>] release --run|--record --reservation <id>
* handoff --run|--record --from <step> --to <step> --base origin/<base> [--reviewed-tree <t>] [--trail <f> --trail-run <id>]
+4 -1
View File
@@ -169,7 +169,10 @@ line prints `call`, `call_floor` and `above_floor`, so each verdict can be check
grandchild's.
`--delegate never` turns delegate into stop for a parent on a host without children; a child
continues with a `CONTEXT_HIGH:` note instead.
continues with a `CONTEXT_HIGH:` note instead. `--delegate measured` (what `ship/DRIVER.md` starts
with) delegates only when a measured call is 150k or more above the floor at a segment boundary; an
unknown charge continues there. A parent driving /ship from the driver carries no skill text a fresh
child would shed, so a child pays its fixed cost only when the parent's own context grew.
**Small runs keep their segment.** `check --runtime-lines <n>` (runtime_lines from
`gstack-review-plan --json`, which `gstack-ship-preflight` prints) continues at the Step 7 and
+3 -3
View File
@@ -129,7 +129,7 @@ export function writeReturnFile(file: string, lines: string[]): void {
/**
* Admission and the delegate rule for one boundary; reserves the admitted work
* under a cap (a dispatch batch goes to admitBatch). The rule compares the call's context above the host floor (an
* unknown charge delegates at a segment boundary, never at start). A light diff
* unknown charge delegates at a segment boundary, never at start; under --delegate measured it continues). A light diff
* whose segment costs less than a child keeps it (keepsSmallRun). A child
* never stops on it: after a completed step it hands its remaining steps to a
* grandchild, and before one, at the maximum depth or past its segment it
@@ -148,7 +148,7 @@ export function decide(l: Ledger, step: string, next: Next, call: number | null,
const boundary = (startThreshold ? next.step === '1' : next.step === '7' || next.step === '12');
const to = l.parent ? l.parent.to : SEGMENTS[next.step]!;
const small = boundary && !startThreshold ? keepsSmallRun(loadCalibration(l.calibration), { runtimeLines, from: next.step, to, call }) : null;
const wants = boundary && !small && (above === null ? !startThreshold : above >= threshold);
const wants = boundary && !small && (above === null ? !startThreshold && l.delegate !== 'measured' : above >= threshold);
const depth = l.depth ?? (l.parent ? 1 : 0);
const hold = !wants || !l.parent ? undefined
: !l.steps_done?.length ? 'no step completed since verify-handoff'
@@ -234,7 +234,7 @@ export function cmdStart(argv: string[], ctx: Ctx): Outcome {
const cap = rawCap === undefined || rawCap === 'none' ? null : parseTokens(rawCap, '--token-cap');
const callFloor = tokensOpt(o, 'call-floor');
const delegate = str(o, 'delegate') ?? 'auto';
if (delegate !== 'auto' && delegate !== 'never') throw usageError(`--delegate '${delegate}' is not auto or never`);
if (delegate !== 'auto' && delegate !== 'never' && delegate !== 'measured') throw usageError(`--delegate '${delegate}' is not auto, never or measured`);
const existing = parseRecordBlock(record);
if (existing?.ledger && fs.existsSync(existing.ledger) && !readLedger(existing.ledger).closed_at) {
const l = readLedger(existing.ledger);
+1 -1
View File
@@ -70,7 +70,7 @@ export interface Handoff {
}
export interface Ledger {
schema_version: 1; kind: 'gstack-ship-budget'; run: string; dir: string; file: string; record?: string; created_at: string;
cap: number | null; tail: number; stop_overhead: number; delegate: 'auto' | 'never'; role: 'parent' | 'child';
cap: number | null; tail: number; stop_overhead: number; delegate: 'auto' | 'never' | 'measured'; role: 'parent' | 'child';
parent?: { run: string; ledger: string; handoff_sha: string; from: string; to: string; return_file: string };
meter: { contract: MeterContract; epoch: number; baseline: number; last: number | null; last_at?: string; sessions?: string[]; config_dir?: string };
epochs: Array<{ epoch: number; contract: MeterContract; baseline: number; last: number | null; used: number }>;
+16
View File
@@ -73,6 +73,22 @@ describe('per-call thresholds above the host floor', () => {
expect(h.field(unknown.out, 'BUDGET', 'verdict')).toBe('delegate');
});
test('--delegate measured (ship/DRIVER.md): an unknown charge continues at a segment boundary; 150k above the floor still delegates', () => {
const h = fresh();
const s = start(h, ['--token-cap', '80M', '--reading', '1000000', '--delegate', 'measured']);
const unknown = check(h, s.run, '6', '7', ['--reading', '1100000']);
expect(unknown.code, unknown.out + unknown.err).toBe(0);
expect(h.field(unknown.out, 'BUDGET', 'above_floor')).toBe('unknown');
expect(h.field(unknown.out, 'BUDGET', 'verdict')).toBe('continue');
expect(unknown.out).not.toContain('DELEGATE:');
const high = check(h, s.run, '11.5', '12', ['--reading', '2000000', '--prior-reading', '1700000']);
expect(h.field(high.out, 'BUDGET', 'above_floor')).toBe('150000');
expect(h.field(high.out, 'BUDGET', 'verdict')).toBe('delegate');
const bad = h.sb(['start', '--record', h.record(), '--token-cap', '60M', '--reading', '0', '--delegate', 'sometimes']);
expect(bad.code).toBe(2);
expect(bad.err).toContain("--delegate 'sometimes' is not auto, never or measured");
});
test('--call-floor overrides the calibrated floor and is recorded in the ledger', () => {
const h = fresh();
const s = start(h, ['--token-cap', '60M', '--reading', '218000', '--prior-reading', '98000', '--call-floor', '0']);