Review Phase Token Rebuild
Spec: Review Phase Token Rebuild
Context
One Full Code Review Pass of review-phase costs 25–30M tokens today.
Most of the cost is a gate subagent that does mechanical work over about 90
turns: it reads about 31k tokens of graph documentation, hashes inputs, builds
the Review Packet and writes the report. Two axis subagents only start the
vendored autoreview helper and wait. The helper is a frozen May 2026 fork:
in prepared mode it applies none of the upstream review method. When the Codex
quota ran out on 2026-10-22, the skill text made the agent retry the same
engine, and one pass ran 200 minutes with no result. Reports live in the wiki
and enter later review scopes. Evidence: the
Brainstorm Brief
Findings table and the closed grill.
The rebuild keeps the two review axes (Standards, Spec) and the delivery pass rules. It moves all mechanical work into scripts, runs the upstream helper unchanged through a wrapper, adds Engine Fallback, uses one Adjudicator, and stores a temporary Pass Report in the delivery folder.
Actors: the root delivery agent, the review.mjs script, the engine CLIs
(claude --print, codex exec), the Adjudicator subagent, human operators,
and maintainers who publish the Baseline. Terms follow the
glossary.
Root agent review.mjs Engines
status ───────────▶ next step + pass count
prepare ──────────▶ freeze, packet, budget, context, --dry-run size, mechanical checks
run (background) ─▶ Axis Run standards ──▶ host engine ─fail─▶ next engine
Axis Run spec ───────▶ host engine ─fail─▶ next engine
Adjudicator ◀────── packet + 2 Review Lens Results → adjudication.json
retain ───────────▶ pass-<n>.json (exclusive create, pathspec commit) → routeNon-Goals
- PR bots (for example greptile) and CI overlap.
- Usage accounting for the Claude engine.
- The 2026-10-05 to 2026-10-19 subagent start-context inflation.
- Migration or deletion of existing wiki review reports (Q18).
- A runtime token guard (Q19).
- Review of content that is not a Git change (Q15).
Requirements and Outcomes
OUT-001: A pass is cheap and its cost is measured
The median Full Code Review Pass costs at most 4M tokens and at most 10 model turns outside the Adjudicator. Each Pass Report records the usage needed to measure this.
Architecture: OUT-001, ARC-012, FLOW-001.
OUT-002: Scripts own the mechanical pass work
review.mjs freezes the target, builds the Review Packet, checks budget, size
and mechanical evidence, controls engines, writes the Pass Report and derives
routing. No model turn does this work.
Architecture: OUT-002, ARC-002, ARC-003, FLOW-001.
OUT-003: Axis Runs apply the upstream review method with axis guidance
Each pass has a Standards Axis Run and a Spec Axis Run. Each calls the upstream helper unchanged with its axis guidance and source context.
Architecture: OUT-003, ARC-006, FLOW-001-STEP-004.
OUT-004: Engines never stall a pass
The pass uses the host's own model by default and moves to the next engine on any engine failure or timeout. When every engine fails, the pass stops with an exact blocker.
Architecture: OUT-004, ARC-005, FLOW-002.
OUT-005: One Adjudicator verifies candidates
One readonly subagent verifies every distinct candidate against the real code and sets final severity and route.
Architecture: OUT-005, ARC-007, FLOW-001-STEP-006.
OUT-006: The Pass Report is the temporary, single source of the pass count
A completed pass writes one Pass Report in the delivery folder. The number of valid Pass Reports is the completed pass count. Reports never enter a review target or the wiki.
Architecture: OUT-006, ARC-009, FLOW-001-STEP-007.
OUT-007: A pass resumes without repeating completed work
After an interruption, a pass reruns only what is missing.
Architecture: OUT-007, ARC-008, FLOW-003.
OUT-008: Standalone review covers committed artifacts
An operator can review a committed plan, spec, docs or code change without a delivery budget.
Architecture: OUT-008, ARC-011, FLOW-004.
OUT-009: review-phase is one small skill with a vendored upstream helper
review-phase holds one short procedure, four references, its scripts and the
unchanged upstream helper. The autoreview and review skills no longer exist.
Architecture: OUT-009, ARC-001, ARC-004.
OUT-010: Delivery consumes the new pass contract
delivery-phase reads the Pass Report path and run identity and derives the
pass count.
Architecture: OUT-010, ARC-010.
OUT-011: Harness consumers, docs and release move with the change
The HI catalog, manifests, prompts, wiki, runbook, other skills and the
Baseline changelog describe the new pass, and consumer repos converge through
hi update.
Architecture: OUT-011, ARC-013.
OUT-012: Tests prove the pass through its public seams
CLI and library tests with fake engines replace the graph contract tests.
Architecture: OUT-012, ARC-014.
OUT-013: Agent-facing text follows the writing discipline
Every prompt and skill text this change creates or edits applies
$writing-for-agents.
Architecture: OUT-013, ARC-015.
Acceptance Criteria
- AC-001: Every Pass Report records, for each Axis Run attempt,
engine,model,seconds,outcomeand upstreamusage(ornullwhen the engine reports none), and records the Adjudicator'ssubagent_tokens. - AC-002: A validation of at least three Full Code Review Passes over real deliveries shows a median of at most 4M tokens per pass (root-agent review turns plus Adjudicator
subagent_tokensplus recorded engine usage) and at most 10 root-agent model turns fromstatusto route return. - AC-003: No pass fails or stops because of its token use; the only runtime limits are the per-attempt engine timeout and the
--dry-runsize check. - AC-004:
review.mjsprovidesprepare,run,retainandstatus; each prints exactly one JSON line on stdout with the fields of Q32, and a non-nullblockeris one sentence. - AC-005:
preparefreezesbase..HEAD, derives the Review Packet identity, checks the pass budget, selects source context, sizes both axes with upstream--dry-run, and runs the skill-evidence cardinality check and the acceptance-criterion-to-Verification record check, all without starting a model; gaps from the two checks become candidates, and oversize, budget exhaustion or a missing source returns ablockerbefore any engine starts.- Covers: OUT-002, OUT-003
- Architecture: AC-005, FLOW-001-STEP-002
- AC-006:
review-contract.mjsexportsreviewPacketIdentity,planDeliveryReviewGate,deriveReviewRouting,recoverPassCount,validatePassReport,planEngineOrderandselectSourceContext, and no longer exportsvalidateRetainedPass,resolveRetainedRun, wiki report path, Markdown report encode/parse, retained-ref or standalone bundle functions. - AC-007: Each Axis Run calls
scripts/vendor/autoreviewwith--mode branch --base <base>(or the standalone commit or range),--max-priority P2,--engine <engine>,--engine-timeout-seconds,--prompt-fileof itsaxis-standards.mdoraxis-spec.md, its--source-contextlist, and--json-output/--status-outputinside the run directory.- Covers: OUT-003
- Architecture: AC-007, FLOW-001-STEP-004
- AC-008: The Standards source context holds the
AGENTS.mdchain of the touched paths, the matched Codebase Rules and each assigned skill'sSKILL.md; the Spec source context holdsSPEC.md,ARCHITECTURE.md,PLAN.mdandIMPLEMENTATION-NOTES.md. - AC-009:
axis-standards.mdstates documented repo standards as hard rules, labels Fowler smells as P3 information, and contains no simplify check. - AC-010: With
CLAUDECODE=1the engine order is[claude, codex]; withCODEX_THREAD_IDset it is[codex, claude];HI_REVIEW_ENGINESreplaces the order when set; models stay at upstream defaults unless overridden.- Covers: OUT-004
- Architecture: AC-010, FLOW-002-STEP-001
- AC-011: When an engine attempt ends in
reviewer_unavailable,timed_out,incompleteor a refusal exit,runstarts the same Axis Run on the next engine at once and never retries the same engine. - AC-012: When every engine fails for an axis, its Review Lens Result is
incompletewith every attempt and cause,runprints ablocker, and no completed pass is counted.- Covers: OUT-004
- Architecture: AC-012, FLOW-002-STEP-004
- AC-013: The
review-phaseprocedure startsrunin the background and contains no step that watches, polls or sleeps on an engine process.- Covers: OUT-004, OUT-002
- Architecture: AC-013, FLOW-001-STEP-003
- AC-014: The Adjudicator is one readonly subagent that receives the packet and both Review Lens Result paths and writes
adjudication.jsonwith findings (id,axis,severity,location,evidence,action,return_route) and rejected candidates with reasons;retainrefuses an invalid file. - AC-015:
references/adjudicator.mdallows a command only to test one specific candidate and contains no repeat of Task Gate validation.- Covers: OUT-005
- Architecture: AC-015, FLOW-001-STEP-006
- AC-016:
retaincreates.devpunks/delivery/<goal>/reviews/pass-<n>.jsonwith an exclusive create and commits only that path; a second writer for the samenfails without overwriting.- Covers: OUT-006
- Architecture: AC-016, FLOW-001-STEP-007
- AC-017: A Pass Report follows
pass-report-v1with the fields of Q34 and has no Markdown body or wiki frontmatter. - AC-018: The completed pass count equals the number of valid Pass Reports for the goal;
statusreports it; one pass is the default, a second needs an accepted-risk trigger and a further pass needs explicit human direction. - AC-019: Every review target excludes
.devpunks/delivery/**/reviews/. - AC-020: No new pass writes to the wiki; Pass Reports stay in the delivery folder after closeout; legacy wiki review reports are not read for the count.
- AC-021: Run state lives only in
$TMPDIR/hi-review/<run-id>/, andretainremoves that directory. - AC-022: On resume,
runkeeps each Review Lens Result whose packet identity is unchanged and reruns only failed or missing axes; with no run directory both axes run from a newprepare. - AC-023:
prepare --standaloneaccepts a commit or commit range, refuses a target that is not a Git change, and reads and writes no delivery counter. - AC-024:
review-phase/scripts/vendor/autoreviewholds the upstreamv0.6.0helper bytes unchanged,scripts/vendor/UPSTREAM.mdrecords the tag and its--versionsource-sha256, and no test asserts byte identity. - AC-025:
review-phasehasSKILL.md,references/{adjudicator,axis-standards,axis-spec,routing}.md, the mattpocockUPSTREAM.mdandLICENSE, andscripts/;phases/,AUTHORING-HANDOFF.mdandreferences/{durable-report,runtime-handoff,state-graph,targets,review-packet}.mdare absent. - AC-026:
skills/agnostic/quality/autoreview/andskills/agnostic/quality/review/are absent from the skills repo. - AC-027:
delivery-phasereferences/phase-handoff.mdandartifact-state.mdcarrypass_reportandreview_run_idinstead of report path, report SHA-256, report commit andverified_retained_ref; no file storesreview_count;phases/{review,router,closeout,implement,debug}.mdmatch. - AC-028: The HI catalog (
skills.ts,packs.ts) and both subagent manifests contain noautorevieworreviewentry;spec-reviewerkeepsreview-phase; the publisher test pinsskills/review-phase/scripts/vendor/autoreviewas an executable copy. - AC-029:
hi updatein a consumer repo removes unedited copies ofautoreviewandreviewand reports edited copies, andBASELINE_CHANGELOG.mdUnreleased tells operators to runhi update --yesfor edited copies and that in-flight deliveries restart their pass count. - AC-030:
ask-hireferences, thedebugging-phaseandfinder-phase$review-phaseinvocations, the harness prompt templates,harness/entrypoints/review.mdxwith the other review wiki pages, and runbookhi-cli-scaffolding.mddescribe the new pass;project/reviews/is marked frozen history; the scaffolded wiki contract has noreviews/section. - AC-031:
tests/review-phase-cli.test.mjsproves Engine Fallback, timeout to the next engine, resume reuse, exclusive ordinal, the oversize blocker and routing with fake engines throughCODEX_BIN/CLAUDE_BIN;review-contract.mjsunit tests exist; the graph andv43-frozen-reviewtests and their fixtures are removed; text-pin tests that named removed files are updated;npm testpasses in the skills repo. - AC-032: The implementation notes record
$writing-for-agentsapplication for every prompt and skill text created or edited.
Constraints
- Skills are edited only in
/home/stefan/repos/skillsonmain, then synced withbun run sync:skills(rootAGENTS.md). - The upstream helper stays unchanged; local behaviour lives in
review.mjs(Q6). - Engines see only the bundle and source context (upstream S:4236).
- Upstream reviews only Git changes (upstream S:4224, S:2055).
- Canonical terms: Axis Run, Adjudicator, Engine Fallback, Pass Report, Full Code Review Pass, Review Packet, Review Lens Result.
Dependency Readiness
Ready.
openclaw/agent-skillstagv0.6.0, commitaa2f8f7afd8ff26a26ac0b20b8d5a62b7dd16fae, pathskills/autoreview/scripts/autoreview(landed upstream release).wearedevpunks/skillsmain@979a504f0fd7cd49f01b16689e224db608c89f5c(current source ofreview-phase,review,autoreview).
Branch/Base Intent
wearedevpunks/skills: commit onmaindirectly (rootAGENTS.mdshared skills rule); no pull request.wearedevpunks/harness-intelligence: one delivery branch frommain, one pull request againstmain(one PR per Touched Repository).
Architecture Source
- URL: https://github.com/wearedevpunks/harness-intelligence/blob/12a6d5eef978d0b0b885755a2513d35b50b9d04d/apps/wiki/content/docs/project/specs/cli/review-phase-token-rebuild/ARCHITECTURE.md
- Commit:
12a6d5eef978d0b0b885755a2513d35b50b9d04d - Path:
apps/wiki/content/docs/project/specs/cli/review-phase-token-rebuild/ARCHITECTURE.md - Content sha256:
3568746824f876255e31d47987bb186ad0e2816ee573b695ef9478b0d2253f2a
Accepted Technical Decisions
- Pass shape prepare → run → adjudicate → retain; no axis subagents (Q3, Q4; ARC-002).
- Node ESM
review-phase/scripts/review.mjswithprepare,run,retain,status; one JSON line each;--standaloneflag (Q20, Q32). - Side effects in
review.mjs, pure logic inreview-contract.mjs(Q33, Q36). - Run state
$TMPDIR/hi-review/<run-id>/, removed byretain(Q21). - Upstream helper unchanged at
review-phase/scripts/vendor/autoreviewwithvendor/UPSTREAM.md(tag +--versionsource-sha256) (Q25). - Upstream review prompt in both Axis Runs; axis guidance through
--prompt-file;--max-priority P2; no third run (Q7, Q8). - Host detection
CLAUDECODE=1/CODEX_THREAD_ID; order[host, other]; overrideHI_REVIEW_ENGINES; upstream model defaults (Q9, Q26). - Engine Fallback on any engine failure or timeout; all engines fail →
incomplete+ blocker (Q10). - Pass Report
pass-report-v1at.devpunks/delivery/<goal>/reviews/pass-<n>.json; exclusive create; pathspec commit; count = valid files; debt keys = report path + finding ID (Q13, Q23, Q34). - Delivery handoff
pass_report+review_run_id; derived count (Q37). reviewguidance moves toaxis-standards.md/axis-spec.md;reviewandautoreviewskills deleted (Q25, Q29).- One delivery across skills and harness; consumers converge through STEP-011 stale removal (Q38).
Explanation and diagrams: architecture.
Accepted Testing Decisions
- The engine test seam is upstream
CODEX_BIN/CLAUDE_BINwith fake engine binaries (Q33). tests/review-phase-cli.test.mjsplusreview-contract.mjsunit tests replace the graph andv43-frozen-reviewtests (Q39).- No byte-identity test on the vendored helper (Q25).
Verification Seams
review.mjsstdout JSON lines and exit codes.- The Pass Report file and its Git commit.
- The run directory contents under
$TMPDIR/hi-review/<run-id>/. - Fake engine binaries on
CODEX_BIN/CLAUDE_BIN. hi updatereport rows (removed,stale-reported) in a consumer fixture.npm testin the skills repo; harness catalog and publisher tests.
Parked Decisions
- PR bots and CI, Claude-engine usage, subagent start-context inflation:
owner maintainer; resume trigger a later grill (status branch
Out of scope).
Decision Log
| Decision | Evidence | Rationale |
|---|---|---|
| Scripts own mechanical work | Q2; Brief Findings | Gate subagent costs 12–26M tokens per pass |
| Upstream helper unchanged + wrapper | Q6, Q25 | Clean updates; helper only inside review-phase |
| Engine Fallback on any failure | Q10; upstream S:5910 | Upstream cannot detect quota and never switches engine |
| Temporary Pass Report | Q13, Q16, Q23 | One count source; out of wiki and review scope |
| Acceptance measurement, not runtime guard | Q19 | A token guard leaves code unreviewed |