Plan: the cold reviewer thinks at the session’s level and answers under the model’s own ceiling (#192)

Closes: #192. Branch: fix/reviewer-thinking-ceiling. Status: Done (2026-09-21) — shipped as pi-workflow 0.22.0 / pi-modes 0.33.0

TL;DR

reflection-review.ts calls the reviewer with maxTokens = 8 000 (16 000 with declared files), doubled once on a cut, and no thinking level. What the reviewer does with that depends on the model: an adaptive model that cannot turn thinking off (Fable 5.1, offSupported: false) thinks at the API’s default effort out of that same pot; a budget model does not think at all (pi-ai maps an absent reasoning to thinkingEnabled: false); a non-reasoning model is fine by accident. Pivot lost the verdict six times in sixteen attempts on one plan (#190); the #190 fix itself twice came back with no VERDICT: line and fell to self-review.

The fix is to do what pi does for an ordinary turn, through pi-ai’s own functions, so it holds for every model pi-ai can drive: the level is the session’s, clamped to the reviewer model (clampThinkingLevel, which knows ["off"] for a non-reasoning model, snaps xhigh to high where undeclared and off upward where a model cannot stop thinking); no maxTokens (each provider adapter then uses the model’s cap and fits the level’s budget inside - adaptive effort, Anthropic budgets, OpenAI reasoning_effort, Gemini budgets, fixed-reasoning servers, none of it ours); the answer bounded by format - VERDICT: first, then J1-J8 one line each; one retry that asks for the verdict, not a bigger pot; and usage on every review log line, plus the reviewer’s text when a review is unreviewed, so the level is tuned from evidence.

Design

The contract, by model class

Reviewer model Level sent Ceiling sent

No reasoning (reasoning unset)

none - getSupportedThinkingLevels is ["off"], so clampThinkingLevel returns off and no reasoning option is passed

none - the adapter uses the model’s cap (Anthropic: model.maxTokens; OpenAI/Google: provider default)

Adaptive, thinking cannot be off (Fable 5.1)

the wanted level, off snapped upward by pi-ai’s clamp; pi-ai maps it to output_config.effort

none - max_tokens = model.maxTokens (128 000)

Adaptive, xhigh undeclared (Sonnet 4.6)

wanted xhigh → high by the clamp

none - 64 000

Budget-based (older Claude, Gemini budgets)

the wanted level; pi-ai’s adjustMaxTokensForThinking(undefined, cap, level) fits the level’s budget inside the cap, MIN_ANSWER_TOKENS kept

none - the cap

OpenAI effort, fixed-reasoning or effort-less servers

the wanted level; the adapter’s thinkingLevelMap / compat decides what reaches the wire, exactly as for pi’s own turn

none

Nothing in this table is code of ours: one call to clampThinkingLevel, one reasoning option when the result is not off, and the absence of maxTokens. That is the whole universality argument - pi-ai already encodes each provider’s rules, and pi’s agent-session.js drives every turn through the same two functions with no ceiling of its own.

The wanted level

Priority: reviewThinking in gadhs-pi-workflow.json (a ModelThinkingLevel name, off included, validated by name) → the session’s level from the bridge (thinkingLevel?() - pi.getThinkingLevel() as pi-modes already reads it for #181) → medium. Review at the level you write at; an operator who wants the reviewer more or less diligent than the author says so once. The clamp runs on whatever wins, so a config xhigh against a Sonnet reviewer is high, and off against Fable is Fable’s lowest.

The answer bounded by format

Both system prompts (reviewSystemPrompt, planReviewSystemPrompt) end today with "Finish with one line: VERDICT: …". They will open the answer with it instead: "Your FIRST line is VERDICT: CLEAN or VERDICT: FLAGS (n). Then J1-J8 (P1-P4), one line each: the question, PASS | FAIL | N/A, one sentence with file:line. Nothing before the verdict, nothing after the last question." The answer is then a dozen lines; the thinking is whatever the level buys.

verdictOf reads the FIRST line when it is a verdict line, else the LAST occurrence as today. Erratum (2026-09-21): the LAST line that is only a verdict, else the last mention - a reviewer that wrote CLEAN first and FLAGS after must read FLAGS; nothing positional, so body and framed text agree (cold-review catch). The rest as written: (a model that still closes with it, or the existing tests' J1 PASS\nVERDICT: CLEAN). All three readers - isClean beside it, classifyOutcome in reflection-cycle.ts, reviewFindings in review-findings.ts - keep deriving from verdictOf, so "which line is the verdict" stays one decision.

The retry

finishReview today re-asks at budget * 2 in two cases: stop reason length (an empty body included), or a non-empty body with no verdict; an empty body with any other stop reason is reported without a second call, because a doubled budget does not cure a 400. With no ceiling, doubling is meaningless. New rule, one retry at most:

  • empty body, stop reason not length (provider error, abort): reported at once with the provider’s message, exactly as today - no retry;

  • stop reason length at the model’s cap: nothing more to give - unreviewed at once, with the usage in the reason ("output 128 000 of which 126 900 reasoning");

  • non-empty body, no verdict, stop reason not length (the observed failure): one more turn in the same conversation - a user message "You stopped without the VERDICT line. Answer now in the required form: the VERDICT line, then one line per question." - same options. Still no verdict → unreviewed with the reason, the stop reason, the usage and the first 2 KiB of what it wrote. Erratum (2026-09-21): characters, not bytes - PARTIAL_CHARS = 2_048; the log’s one content field, noted there.

ReviewDeps.maxTokens stays as the explicit override it is (tests, an embedding that must cap); when set, a length cut retries once at double, as before - the override path keeps its old semantics, the default path has none to keep.

Usage, recorded

ReviewAnswer gains usage? (pi-ai’s Usage: input, output, cacheRead, cacheWrite, reasoning?). runColdReview sums it across every ask of the review (tool rounds and the retry included) and puts it on ReviewOutcome as usage?: ReviewUsage. logReviewDone (commit) and the plan review’s plan_review.done log it; git_guard.reflection_unreviewed and its plan twin log it with partial (≤ 2 KiB of the reviewer’s text, absent today - the #190 failure could not be inspected). The level actually sent and the level wanted are logged too (level, wanted), so a clamp is visible.

What goes

REVIEW_MAX_TOKENS, REVIEW_MAX_TOKENS_WITH_FILES, reviewBudget, ReviewSubject.hasFiles. Their tests (review-files.test.ts budget cases, reflection-review-run.test.ts and plan-review-run.test.ts maxTokens assertions) are replaced by the cases below - a changed contract, not a weakened test: each old assertion has a successor that pins the new behaviour of the same call.

Scope

Files

File Change

packages/pi-workflow/reflection-review.ts

reviewerLevel(model, wanted) → ModelThinkingLevel via clampThinkingLevel; askProvider passes reasoning when not off and no maxTokens unless deps.maxTokens; ReviewDeps.thinking?; ReviewAnswer.usage?; ReviewOutcome.usage?, partial?; finishReview per The retry; verdictOf first-line rule; both system prompts' closing paragraph; constants and reviewBudget removed

packages/pi-workflow/workflow-config.ts

reviewThinking?: ModelThinkingLevel; validated by name against the seven levels; KNOWN_KEYS and the docs table gain the key

packages/pi-workflow/runtime-bridge.ts

thinkingLevel?(): ModelThinkingLevel | undefined

packages/pi-workflow/commit-pause.ts, plan-pause.ts

pass thinking: config.reviewThinking ?? bridge.thinkingLevel?.() ?? "medium"; log usage, level, wanted, partial

packages/pi-modes/session-wiring.ts

the bridge publishes thinkingLevel: () ⇒ pi.getThinkingLevel()

packages/pi-workflow/package.json, packages/pi-modes/package.json

pi-workflow 0.22.0, pi-modes 0.33.0 (a bridge member each side)

docs/modules/ROOT/pages/modes.adoc

the reflection-pause paragraph: level, ceiling, format, retry, usage

docs/modules/ROOT/pages/tuning.adoc

reviewThinking recipe beside reviewTimeoutMs

CHANGELOG.adoc

== Unreleased, === Fixed

Tests (vitest; every case names the property it asserts)

Contract by model class (reflection-review-run.test.ts, a fake registry returning pi-ai-shaped models, the provider recording options):

  • a model with no reasoning gets no reasoning option and no maxTokens;

  • an adaptive model with thinkingLevelMap.off = null asked for off gets its lowest declared level; asked for xhigh with xhigh unmapped gets high; asked for high gets high;

  • a budget model gets the level and no maxTokens (pi-ai sizes it; the test asserts what leaves this package);

  • deps.maxTokens set: passed through unchanged, and a length cut retries once at double (the override path’s old test, kept);

  • the wanted level comes from config over bridge over medium, in that order (commit-pause through the real handler with a bridge publishing thinkingLevel; config file with reviewThinking).

Format and verdict (reflection-review.test.ts):

  • verdictOf takes the first line when it is a verdict and the last occurrence otherwise; a body that quotes VERDICT: CLEAN in a J5 sentence after a first-line VERDICT: FLAGS (1) reads FLAGS;

  • both system prompts open the answer with the verdict and close it after the last question (string pins).

Retry (reflection-review-run.test.ts):

  • non-empty body, no verdict, stop stop: exactly one more ask, in the same conversation, carrying the nudge as the last user turn; a verdict on the second answer is a reviewed outcome; none is unreviewed whose reason names the stop reason, the usage and carries partial;

  • empty body, stop error (with errorMessage) and stop aborted: one ask only, unreviewed at once, the provider’s message in the reason (the existing case, kept);

  • stop length with no override: unreviewed at once, one ask, usage in the reason.

Usage (reflection-review-run.test.ts, review-context-pause.test.ts):

  • usage summed across tool rounds and the retry lands on the outcome and in git_guard.reflection_done / reflection_unreviewed with level and wanted; a provider that reports no usage logs undefined, not zeros.

Config (workflow-config tests): reviewThinking accepts the seven names, rejects "HIGH", 1, "medium "; unknown-key message lists it.

Regression: the #190 shape - a reviewer whose first answer ends stop without a verdict - now ends reviewed after the nudge; fails on the old code (old code re-asks at double and reports "truncated review even at 32000 tokens").

Risks

Risk Direction Mitigation

A model with a large cap and a high level thinks long: wall clock

silent (cost)

reviewTimeoutMs bounds it as today; usage is logged, so a long review is a number, not a feeling; reviewThinking lowers it

A provider rejects an unset max_tokens

fail-closed (unreviewed → self-review after two attempts)

pi’s own turns run this way through the same adapters; the unreviewed reason carries the provider’s message

verdictOf first-line rule misreads a body that opens with a quoted verdict

fail-open (wrong verdict)

the first line must be only a verdict line (anchored ^\s*\**VERDICT:) to count; pinned

The nudge turn confuses a tool-calling reviewer mid-investigation

fail-closed

the nudge is sent only after askWithSnapshot returned an answer (no pending tool calls); the round budget still applies

An older pi-modes without thinkingLevel

silent (falls to medium)

logged as wanted: "medium", source: "default"

Not in scope

Reviewer choice (chooseReviewer, the ranking) is untouched. Round counting and the plan-path remit (#190’s proposals not taken) stay out. Per-provider special cases: none are added; a model pi-ai cannot drive at the wanted level is pi-ai’s to clamp, and the log shows what it did.

Delivery

  1. Branch fix/reviewer-thinking-ceiling; commit this plan (docs:), nav entry Planned → Active.

  2. pi-modes bridge member + test; pi-workflow config key + tests.

  3. reflection-review.ts: level, ceiling, format, verdict rule, retry, usage; tests per above; old constant tests replaced.

  4. commit-pause.ts / plan-pause.ts plumbing and logs; wiring tests.

  5. modes.adoc, tuning.adoc, CHANGELOG.adoc; versions.

  6. node tools/task.mjs validate green; MR Closes #192; merge; one line on #192 with the SHA; plan Status → Done, nav → Archive; release cut (0.56.0) - a reviewer that cannot finish is a guard that is off.

Edit this page · latest