Plan: system prompts reach the provider under pi-ai 0.87 — the judge and the cold review (#195)
Closes: #195. Branch: fix/provider-context. Status: Done (2026-09-22) — the form observed again on 0.87 through the live harness; the judge eval gate is the release’s precondition
TL;DR
#195 was filed as "the reviewer loses the J1-J8 form on large diffs".
The size was a coincidence. The cause is an upstream contract change:
pi-ai 0.87 (bundled in pi 0.87.0, on this box since 2026-09-21 17:08)
folds systemPrompt and tools into a leading role: "system" message
via normalizeContext() before a request reaches a provider, and all
four of its API implementations read the prompt from that message only —
grep context.systemPrompt finds nothing in anthropic-messages.js,
google-generative-ai.js, openai-completions.js or
openai-responses.js (0.84.3, the version the repo’s lock pins, still
reads the field). pi’s own ModelRuntime.streamSimple normalizes before
it calls a provider; our code calls registry.getProvider(id).streamSimple(
model, { systemPrompt, messages }, …) directly and never did. Under pi
0.87 the system prompt is silently dropped on every such call, whichever
publisher the model resolves to.
Observed, not inferred: the tiny-diff review through the live harness
(repo pi-ai 0.84.3) answers in perfect form at high and xhigh, with and
without the snapshot tools; the same code under the installed pi answers
freeform every time, asking for "the question list".
~/.pi/agent/npm/node_modules/@gadhs/pi-vertex has no pi-ai of its own;
pi’s loader resolves it to the bundled 0.87.0.
Every direct call, and what happens to it
| Call site | Today | Change |
|---|---|---|
|
|
U1 |
|
|
U1, U4 |
|
One user turn, no system prompt. |
none |
|
Hands pi’s own |
none |
|
Pass the context they are given to pi-ai’s APIs. |
none (types only, U2) |
|
Wraps |
inherits U1 |
|
Callers pass |
U1 (one place) |
|
Builds |
U1 |
|
Runs pi headless; pi’s runtime normalizes. |
none |
The table is the grep streamSimple( / systemPrompt: over packages/
and tools/, run again as the last implementation step so no caller is
left sending the dead shape while the changelog says fixed.
Design
U1 — normalize as pi does, at every direct provider call
Import normalizeContext from @earendil-works/pi-ai and call it on the
{ systemPrompt, messages, tools } we build; hand the result to
provider.streamSimple. That is the runtime’s own sequence. It returns a
new object — { messages: [systemMessage, …context.messages] } — and
does not touch the array it was given, so calling it per ask over the
review’s accumulating conversation (tool rounds, the nudge) yields
exactly one system message each time; U3 pins that rather than trusts it.
No guard and no legacy branch: the floor moves to 0.87 (U2). pi-workflow
imports nothing from pi-modes by design (model-registry.ts says why),
so each package makes the call at its own site; it is one line.
Not taken: routing through pi’s ModelRegistry.streamSimple, which would
also centralize auth. The composed-provider path was chosen deliberately
(ADC, the judge’s own pricing and retry) and swapping it is a larger
change for no gain here — an issue if wanted.
U2 — floor 0.87, and the repo tests against it
The lock resolves @earendil-works/pi-ai and pi-coding-agent (from
packages/pi’s `"*") to 0.84.3, three minors behind the box, which is
why every test and the live harness stayed green through the loss. Move
both to 0.87.0 (pnpm update on the two names; the lock is the record)
and raise the peer floors that carry the contract: pi-modes and
pi-workflow to @earendil-works/pi-ai >=0.87.0 and
@earendil-works/pi-coding-agent >=0.87.0; packages/pi names the same
floor for pi-coding-agent. A pi below the floor fails to link the import
at load, which is the right answer to an unsupported host — clearer than
a judge that quietly runs without its rubric. Type fallout is expected
and is types only: TranscriptContext is a branded type that only
normalizeContext produces, and pi’s extension-facing streamSimple
signatures may name it; the vertex extension’s declarations and the two
packages' structural registry interfaces are adjusted to what 0.87
declares. No pass-through behaviour changes.
U3 — contract tests against the real normalizeContext
| Case | Asserts |
|---|---|
judge: the rubric reaches the provider |
A recording fake provider under |
review: the questions and the tools reach the provider |
The same under |
review: one system message per ask, across the conversation |
Across one snapshot tool round and one |
plan review |
The same first assertion under |
battery |
Covered by |
No mock of normalizeContext anywhere: the point is the shipped one.
Existing tests that read context.systemPrompt off a fake provider
(pi-modes/test/session-wiring.test.ts, wiring.test.ts;
pi-workflow/test/plan-review-run.test.ts, reflection-review-run.test.ts,
review-snapshot-loop.test.ts) are re-pointed at the transcript through
one small reader per test tree (systemPromptOf(received)).
U4 — a verdict is CLEAN or FLAGS, nothing else
verdictOf’s last resort, `lastMention, accepts any text after
VERDICT:, so "VERDICT: APPROVE" read as a verdict and, being neither
CLEAN nor FLAGS, gated nothing. It now accepts CLEAN, FLAGS (n) or
bare FLAGS; anything else is no verdict. Bare FLAGS stays because
reviewFindings (review-findings.ts, FLAGS_COUNT) counts it as at
least one, so requireDisposition gates it — pinned by a test. The
verdict-only-line rule (#192) is unchanged.
What "no verdict" then does is the existing path, named honestly: one
VERDICT_NUDGE, then an unreviewed outcome counted against
MAX_UNREVIEWED_ATTEMPTS (2), after which the commit proceeds on the
author’s self-review with the block text saying so. That is a bounded
degrade, not a fail-closed gate; it is the same degrade an unreachable
reviewer gets, it is visible and counted, and with U1 in place a
verdict-less answer is a provider fault again rather than the norm.
Making the last attempt block instead is a policy change and is not
taken here.
Tests: "VERDICT: APPROVE — merge" → undefined; "Verdict: LGTM" →
undefined; "verdict: clean" inside prose still reads CLEAN; "VERDICT:
FLAGS" reads FLAGS and reviewFindings gives flagCount ≥ 1; the
CLEAN-then-FLAGS ordering pins stand.
Versions, notes, docs
@gadhs/pi-modes 0.33.1, @gadhs/pi-workflow 0.22.2; the changelog’s
== Unreleased under Fixed, naming the exposure plainly (pi 0.87.0 on a
box from 2026-09-21: the judge deferring every gated ask, the reviewer
answering without its questions; nothing allowed that a rubric would have
denied, because the failure mode is defer). The modes page’s "The
judge" and reflection-pause sections each get one sentence on the
provider contract (the prompt travels as the transcript’s leading system
message, as pi’s runtime sends it). security.adoc’s "enforcement that
looks wired is not evidence" paragraph gains this as its fifth instance,
with the two things that would have caught it: a lock at the box’s
version, and a contract test on the wire shape. Release `0.57.2 follows
at once: a degraded gate is a bug cut.
Verification
-
node tools/task.mjs validategreen on pi-ai 0.87.0. -
node tools/task.mjs eval—security.adocmakes the 145-case judge gate mandatory before any change to the judge ships, and U1 changes the judge’s wire. It spends model calls, so it is the operator’s to run or to approve; the plan does not proceed to release without it. -
node tools/task.mjs test:live(operator-run): the reviewer suite, now on 0.87 through the live harness, must observe aVERDICT:line and J-lines again — it would have shown the loss had the repo been current. -
The next real commit’s block text is the end-to-end proof for the reviewer; the first judge-gated command in auto (an
allowor adenywith a reason in the log, not adefer) is the judge’s.
Scope
In: U1-U4, versions, notes, the doc sentences, release 0.57.2.
Out (named, not taken): naming a cut diff’s unread files in the block
text (unrelated to the cause; its own small issue); repeating
ANSWER_FORM at the end of the user turn (the original #195 idea —
recency was not the problem); accepting natural-language verdicts
("approve", "LGTM") as CLEAN; routing model calls through pi’s
ModelRegistry.streamSimple; blocking on the last unreviewed attempt;
splitting a large review by file; the two provider-side terminations seen
at ~113 k input tokens (the retry handles them). Each is an issue if it
is wanted.
Erratum ledger:
-
Erratum (2026-09-22): U2’s "move both to 0.87.0 (
pnpm updateon the two names)" does not work — pnpm auto-installs*/range peers per workspace package andupdate <name>re-resolves only declared dependencies, so each package kept its own instance (pi-vertex on 0.84.3). The unifying lever isoverridesinpnpm-workspace.yaml(pi-ai, pi, pi-tui, pi-agent-core at 0.87.0), which alone resolves every package to the root’s one instance; the first "reproduction on 0.87" before that change had in fact run pi-vertex on 0.84.3, which is why it passed. -
Erratum (2026-09-22): pi-ai 0.87 creates Anthropic requests through the SDK’s beta surface (
client.beta.messages.create); the realAnthropicVertexclient has it, pi-vertex’s contract-test fake did not and gained it. The snapshot tools' type moved fromparameters: unknownto pi-ai’sTool, whichnormalizeContextrequires — types only.