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 ( |
none - |
none - the adapter uses the model’s cap (Anthropic: |
Adaptive, thinking cannot be off (Fable 5.1) |
the wanted level, |
none - |
Adaptive, |
wanted |
none - 64 000 |
Budget-based (older Claude, Gemini budgets) |
the wanted level; pi-ai’s |
none - the cap |
OpenAI effort, fixed-reasoning or effort-less servers |
the wanted level; the adapter’s |
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
lengthat 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 |
|---|---|
|
|
|
|
|
|
|
pass |
|
the bridge publishes |
|
pi-workflow 0.22.0, pi-modes 0.33.0 (a bridge member each side) |
|
the reflection-pause paragraph: level, ceiling, format, retry, usage |
|
|
|
|
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
reasoninggets noreasoningoption and nomaxTokens; -
an adaptive model with
thinkingLevelMap.off = nullasked foroffgets its lowest declared level; asked forxhighwithxhighunmapped getshigh; asked forhighgetshigh; -
a budget model gets the level and no
maxTokens(pi-ai sizes it; the test asserts what leaves this package); -
deps.maxTokensset: passed through unchanged, and alengthcut 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-pausethrough the real handler with a bridge publishingthinkingLevel; config file withreviewThinking).
Format and verdict (reflection-review.test.ts):
-
verdictOftakes the first line when it is a verdict and the last occurrence otherwise; a body that quotesVERDICT: CLEANin a J5 sentence after a first-lineVERDICT: 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 carriespartial; -
empty body, stop
error(witherrorMessage) and stopaborted: one ask only, unreviewed at once, the provider’s message in the reason (the existing case, kept); -
stop
lengthwith 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_unreviewedwithlevelandwanted; a provider that reports nousagelogsundefined, 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) |
|
A provider rejects an unset |
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 |
|
fail-open (wrong verdict) |
the first line must be only a verdict line (anchored |
The nudge turn confuses a tool-calling reviewer mid-investigation |
fail-closed |
the nudge is sent only after |
An older pi-modes without |
silent (falls to |
logged as |
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
-
Branch
fix/reviewer-thinking-ceiling; commit this plan (docs:), nav entry Planned → Active. -
pi-modes bridge member + test; pi-workflow config key + tests.
-
reflection-review.ts: level, ceiling, format, verdict rule, retry, usage; tests per above; old constant tests replaced. -
commit-pause.ts/plan-pause.tsplumbing and logs; wiring tests. -
modes.adoc,tuning.adoc,CHANGELOG.adoc; versions. -
node tools/task.mjs validategreen; MRCloses #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.