Skip to content

M18 slice 2: token governance — phase metering + footprint/turn levers (#224) - #226

Merged
surlymochan merged 4 commits into
mainfrom
m18s2-token-governance
Nov 22, 2026
Merged

surlymochan merged 4 commits into
mainfrom
m18s2-token-governance

Conversation

@surlymochan

Copy link
Copy Markdown
Owner

Implements M18 slice 2 (#224): metering first, then the two token levers. Verification steps (seals / replay / quality gate / I6d) are untouched — no token is saved by cutting verification.

Step 0 — metering (commits 5d508a9, f6ce7de)

Product side:

  • phase-cost entries and totals now carry six fields: turns, input, output, cache_read, cache_write, total. extractTokenUsage reads turns + cache splits from agent-stream usage (bench total convention when no explicit total: input+output+cache_read+cache_write); bare input/output keys are only accepted as real numbers so payload text is never misread as usage.
  • Every workflow run now appends .as-xflow/phase-cost-ledger.jsonl next to phase-cost.json: one flat row per phase with workflow_run_id, change_id, phase, status, duration_ms, turns, input, output, cache_read, cache_write, total, recorded_at — joinable to bench runs by run id.

Bench side:

  • New bench/swebench/harness/phase_usage.py: buckets each pi assistant message_end usage record into workflow phases using the phase_started/phase_completed windows in execution.ndjson (timestamps are epoch ms inside the message object); records outside any window go to _outside_workflow so totals still reconcile. run.py writes phases-<tag>.jsonl (keyed by task_id) inside the same lock as the runs row, before the cell rundir is deleted; metering failures never fail a cell.
  • Tests: test/phase-cost.test.js 11/11 (incl. a real executor run asserting the ledger file lands on disk with all fields), bench/swebench/test_phase_usage.py 6/6, and test_phase_usage added to the harness-isolation module list.

Step 1 — Lever A: per-turn footprint (commit 799a0c3)

Injection point Before After Measured
intake.json in every phase prompt (agent-invoke) full pretty-printed inline >1KB: reference block (path + bytes + top-level keys + scalar digest); ≤1KB: compact one-line JSON fixture 1919B → 559B (−71%)
B2.status.read output echoed into prompts indent=2 JSON compact separators, identical value for parsers fixture 384B → 305B (−21%)
phase prompt templates (phase-execution.md, phase-artifact.md) "read any plan/proposal/spec in the artifact directory" read only the artifacts the phase consumes (plan + previous phase's main artifact) instruction-level; removes whole-directory re-reads

New test: a large intake enters the generated phase prompt as a reference and its body is absent (test/heavy-atoms.test.js, 65/65).

Step 2 — Lever B: round trips (commit f9f8650)

  • workflows/yolo.yaml: brainstorm and proposal are now lite_skip. Brainstorm is a status transition plus a human-gate stop with no artifacts; proposal-freeze is a status transition over an artifact change-init already scaffolds and plan consumes directly. Counted on the workflow definition (backend change, via the repo's own loader): lite-executed phases 11 → 9, human-gate stops per lite run 2 → 1. The verification spine (tdd-red/green seals, I6d, J1, J6), set-in-progress (hosts the repo-doctor readiness check) and the execute human gate are unchanged; the full track is unchanged.
  • Bench AGENTS.md entry (arms.py): mandated startup drops from 5 CLI round trips (guide, goal set, doctor, goal audit, validate) to 2 (goal set, validate); the other three are demoted to on-demand diagnostics.
  • xflow/yolo/SKILL.md: drive with one workflow run invocation per gate stop instead of stepping atoms; planning rules deduplicated to a pointer at xflow:plan (net +487B one-time, for the new driving rules). Note: the goal-alignment phrase the competitive score greps for is kept on one line — splitting it across lines cost 2 score points in testing.
  • Wiring assertions added in test/lite-track.test.js (41/41 with lite-track-auto).

Step 3 — long-tail budget gate: skipped

Per the issue's option: the step-0 ledger now records exactly the data a budget gate would enforce on, but setting budget numbers before slice 3 produces same-caliber phase data would be guessing. Skipped deliberately; the ledger is the deliverable that unblocks it.

Tests

Full suite run in three batches (the runner is fail-fast): 838 tests, 834 pass, 4 fail. All 4 failures are the pre-existing I6d family and fail identically on clean main e137c87 in this VM (A/B verified):

  • test/i6d-acceptance-demo.test.js — 1 fail (same on main)
  • test/xflow-audit.test.js — 3 fails in the I6d assertion-execution gate describe (same 3 on main, 68/71 there too)

An intermediate regression (competitive score 100 → 98 via the SKILL.md line wrap above) was caught by cli-usability and fixed; that file is back to 68/68.

CI status at open time: not yet checked — do not merge until CI is green.

Refs #224. Rename PR #225 is still open and not merged, so this branch is based on current main e137c87; if #225 lands first, this branch needs a rebase (it touches xflow/yolo/SKILL.md text only, no bin changes).

…#224 step 0)

extractTokenUsage now carries turns/cache_read/cache_write (bench caliber
total = input+output+cache when no explicit total); buildPhaseCostReport
aggregates them and stamps workflow_run_id/change_id; the executor appends
one row per phase to .as-xflow/phase-cost-ledger.jsonl on every run, so
per-phase acceptance no longer depends on per-run raw trees.
…(M18 #224 step 0)

New harness/phase_usage.py joins the workflow execution log's phase
windows with pi message_end usage timestamps and emits one row per
(run, phase); run.py appends them to phases-<tag>.jsonl next to the runs
jsonl, keyed by the cell task id, before the rundir is deleted. This is
the metering whose absence forced M18 slice 1 onto proxy metrics.
… lever A)

- agent-invoke: a large intake.json now enters phase prompts as a
  reference (path + bytes + top-level keys + scalar digest) instead of a
  full pretty-printed inline; small intakes go in compact single-line
  form. Measured on a 1919-byte intake fixture: 1919 -> 559 bytes.
- phase prompt templates: read only the artifacts the phase consumes
  instead of the whole artifact directory.
- B2.status.read: compact JSON separators (same value for parsers);
  measured 384 -> 305 bytes on a typical status document.
- yolo.yaml: brainstorm and proposal-freeze are lite_skip. Brainstorm is
  a status transition plus a human-gate stop with no artifacts;
  proposal-freeze is a status transition over an artifact change-init
  already scaffolds and plan consumes directly. Verification spine
  (tdd seals, I6d, J1, J6) and the execute human gate are untouched.
  Counted on the workflow definition (backend change): lite-executed
  phases 11 -> 9, human-gate stops per lite run 2 -> 1.
- bench AGENTS.md entry: mandated startup drops from five CLI round
  trips (guide, goal set, doctor, goal audit, validate) to two (goal
  set, validate); the other three become on-demand diagnostics.
- yolo SKILL: drive with one workflow-run invocation per gate stop
  instead of stepping atoms; planning rules deduped to a pointer at
  xflow:plan (net file size +487B one-time for the new driving rules).
@surlymochan
surlymochan merged commit 5387db5 into main Nov 22, 2026
2 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