Plan: model roles resolved against the models a user can reach

Closes: #715 (filed on approval, before this plan is committed). Relates to: #714 (step 1, done), #666 (the helper model lock), #439 (the helper reach check this replaces), #432 (the commit reviewer), #70 (plan review’s two rounds). Branches: feat/model-roles (U1-U3), feat/model-roles-reviewers (U4), feat/model-roles-helpers (U5), in that order. Status: Done (2026-11-04) — the five units merged in three MRs and shipped in 0.156.0 with step 1 (#714); every role resolves against the models a user can reach, with the deviations in the errata below

Why

The operator (2026-11-04): the distribution must work on pi’s own logins, not only Vertex, and different users have different sources. Step 1 (#714) made pi-vertex load without a GCP project. What remains is that every role still names a Vertex model, and an unreachable model is handled per consumer (each read in the code on 2026-11-04):

Role Named at Today, when unreachable

Mode model

pi-modes/modes.json (auto, plan, manual, yolo)

mode-controller.ts applyModel: an error notice on every switch, the current model kept

Judge, and its fallbackModel

modes.json per mode

judge.ts runJudge: failed("no judge model is available"), a defer, so every ask goes to the human or the pending queue; the fallback is consulted only on a policy refusal

Commit reviewer

pi-workflow/workflow-config.ts DEFAULT_COMMIT_REVIEWER

reflection-review.ts resolveReviewer: unreviewed; commit-pause.ts reviewWithFallback falls back to the author’s model at or above the floor; two unreviewed attempts, then self-review

Reviewer floor

reflection-review.ts REVIEW_FLOOR

the same path; the floor itself unreachable means unreviewed

Plan’s second reviewer

workflow-config.ts DEFAULT_PLAN_SECOND_REVIEWER

plan-pause.ts blockWithSecondOpinion: round two "did not happen", round one stands

Helpers (Explore, Research, Verify)

pi-agents/agents/*.md model:

pi-agents/index.ts seedNotices: one warning; pi-subagents then runs the best fuzzy match, or the session’s model, silently

Image model

pi-modes/image-tool.ts DEFAULT_IMAGE_MODEL, chosen in command-wiring.ts registerImageTool (config.imageModel ?? DEFAULT_IMAGE_MODEL)

image-tool.ts modelOf throws a tool error naming the available image models

Fallback summarizer

pi-modes/config.ts DEFAULT_FALLBACK_SUMMARIZER, read by config.ts fallbackSummarizer

compaction.ts fallbackFor: undefined, a warning, then pi’s default compaction

The fact that makes the fix small: pi’s native anthropic and google providers carry the same model ids as our Vertex catalogue (pi-ai 1.5.0, dist/providers/data/{anthropic,google}.json: claude-opus-5-5, claude-sonnet-5-5, claude-haiku-5-5, claude-fable-5-1, gemini-3.8-flash, gemini-4-argon; github-copilot carries the two Gemini). So "the same model through another source" is a provider swap on an identical id, and the battery’s evidence carries over. Native Google has no image model under our ids, so the image role has Vertex candidates only.

The operator’s decisions (2026-11-04)

  1. Sources: anything in pi’s registry. Shipped candidates name Vertex, the Anthropic API or Claude subscription (anthropic), and Google AI Studio (google); other sources by override.

  2. When a whole vendor is unreachable, a role falls back to the other vendor’s nearest measured tier, labelled a substitute. If nothing fits, the role’s own fallback applies.

  3. Plan review’s round two, when no second vendor is reachable: a different model from the same vendor, labelled "same vendor, no second vendor reachable".

Design

U1 - the role table and the resolver (pi-modes/model-roles.ts, new)

ROLE_CANDIDATES: per role, an ordered list of { ref, substitute? }. The first entry is today’s shipped value, so a Vertex box resolves exactly as now. Tier one is the same id through each source; tier two is the other vendor’s nearest tier, substitute: true, unmeasured by the battery until it runs:

Role Same model, by source Substitute

mode:auto, mode:manual, mode:yolo

vertex-anthropic/claude-opus-5-5, anthropic/claude-opus-5-5

vertex-gemini/gemini-4-argon, google/gemini-4-argon

mode:plan

vertex-anthropic/claude-fable-5-1, anthropic/claude-fable-5-1

vertex-gemini/gemini-4-argon, google/gemini-4-argon

judge

vertex-anthropic/claude-sonnet-5-5, anthropic/claude-sonnet-5-5

vertex-gemini/gemini-3.8-flash, google/gemini-3.8-flash

judgeFallback

vertex-anthropic/claude-sonnet-5, anthropic/claude-sonnet-5

none (the fallback is for a policy refusal by the same vendor)

commitReviewer, planSecondReviewer

vertex-gemini/gemini-4-argon, google/gemini-4-argon

vertex-anthropic/claude-sonnet-5-5, anthropic/claude-sonnet-5-5

reviewFloor

vertex-anthropic/claude-sonnet-5-5, anthropic/claude-sonnet-5-5

vertex-gemini/gemini-4-argon, google/gemini-4-argon

helper:Explore

vertex-gemini/gemini-3.8-flash, google/gemini-3.8-flash

vertex-anthropic/claude-haiku-5-5, anthropic/claude-haiku-5-5

helper:Research

vertex-anthropic/claude-sonnet-5-5, anthropic/claude-sonnet-5-5

vertex-gemini/gemini-4-argon, google/gemini-4-argon

helper:Verify

vertex-anthropic/claude-haiku-5-5, anthropic/claude-haiku-5-5

vertex-gemini/gemini-3.8-flash, google/gemini-3.8-flash

image

vertex-gemini/gemini-nano-banana-2.1

none

summarizer

vertex-gemini/gemini-3.8-flash, google/gemini-3.8-flash

vertex-anthropic/claude-haiku-5-5, anthropic/claude-haiku-5-5

resolveRoles(available: readonly { provider; id }[], overrides) picks, per role, the first candidate present in the registry’s getAvailable() (configured auth, pi 1.5.0 model-registry.d.ts). Per role the result is { ref, substitute } | undefined, with the candidates tried kept for the session line. An override (modelRoles.<role>: a ref or a list) replaces the role’s list; sourceOrder (a list of provider ids) stably reorders every list by provider before resolution, so ["anthropic", "vertex-anthropic"] prefers the subscription on a box that has both.

Resolution runs in pi-modes' session_start handler (the registry exists then, not at load; session-wiring.ts onSessionStart) and is kept on the session state. It reaches pi-workflow and pi-agents through the bridge pi-modes already publishes on globalThis under Symbol.for("gadhs:pi-modes-runtime") (session-wiring.ts publishBridge; read by pi-workflow/runtime-bridge.ts modesBridge, no-op when absent): one more callback, modelRoles(): RoleResolution | undefined. Order holds because pi loads 10-modes before 12-workflow and 25-agents (packages/pi/package.json pi.extensions) and fires session_start handlers in registration order, so pi-modes has resolved before either reads. A consumer that finds no bridge, or undefined before resolution, keeps today’s constant; that is the test harness’s case, not a version skew, since the three packages release together.

Overlay keys modelRoles and sourceOrder join ModesConfig, TOP_LEVEL_KEYS and the check validation in config.ts (an unknown top-level key is accepted silently today, per OVERLAY_KEYS’s comment; these are declared so they are documented and typed, not to be refused), each with a `modes.adoc table row and a public-surface.adoc row (#280’s test fails without them).

U2 - the session line (session-wiring.ts startupNotices; /mode status)

One info line at session start, only when any role did not resolve to its first candidate: models: judge claude-sonnet-5-5 via anthropic; Explore gemini-3.8-flash via google; commit reviewer claude-sonnet-5-5 (substitute: no Gemini reachable); image: none. `/mode’s status output lists every role, every session. A role with no candidate reachable says so and names its fallback.

U3 - the pi-modes consumers

  • mode-controller.ts applyModel: the resolved mode:<id> ref in place of mode.model. With none, the current model is kept and said once per session, not on every switch.

  • judge.ts resolveJudge: judge and judgeFallback in place of the mode’s judge.model and fallbackModel. With none, as today (defer), announced by U2’s line.

  • command-wiring.ts registerImageTool: the default model is the resolved image ref, read at call time (the resolution comes after registration), in place of config.imageModel ?? DEFAULT_IMAGE_MODEL; config.imageModel stays the override. With none, `modelOf’s error says no image model is reachable and names the candidates.

  • config.ts fallbackSummarizer: the resolved summarizer ref in place of the default; compaction.fallbackModel stays the override.

U4 - the reviewers (pi-workflow/reflection-review.ts, commit-pause.ts, plan-pause.ts)

commitReviewers and planReviewers take the resolved commitReviewer, reviewFloor and planSecondReviewer through modesBridge().modelRoles(), else the constants. chooseReviewer keeps its rank rule (TIERS, by model id through any provider, so Sonnet through anthropic ranks as through Vertex). Round two: when the resolved planSecondReviewer is a substitute from round one’s vendor (no Gemini reachable, so Sonnet), it runs, and `blockWithSecondOpinion’s text carries "(same vendor: no second vendor reachable)"; when it is round one’s model through any provider, no round two, as now.

U5 - the helpers (pi-agents/index.ts, model-reach.ts)

Seeding stays at load. In session_start, pi-agents reads modesBridge().modelRoles() (pi-agents gains the same two-line reader; it imports nothing of pi-workflow) and re-renders each managed agent file whose model: differs from the resolved helper:<name> ref (renderAgent with the override, seedAgents’ managed-marker rule, so a user-owned file is never written), so pi-subagents reads a reachable model and its silent fallback has nothing to do. The model lock (#666) keeps its meaning: it reads the file pi-subagents will run. With no candidate, the file keeps its packaged model and the session line says the helper will run on the session’s model; `misdirectedHelpers (#439) becomes that one line. A gadhs-pi-agents.json model override still wins over the table.

Risks

Risk Mode Mitigation

A substitute changes a role’s behaviour (Explore on Haiku answers differently from Flash)

Silent, labelled

The label is on the session line and in /mode; the table’s comment marks substitutes unmeasured until the battery runs. A Vertex box’s first candidate is unchanged, so no measured seat moves.

getAvailable() lists a provider whose key is present but invalid

Fail-open: a role resolves to a model that then refuses

Each consumer keeps its request-time handling (the judge defers, a reviewer is unreviewed, a helper’s spawn errors). The resolver is a choice, not a promise; the line names the source, so the operator sees which login to fix.

A consumer reads before pi-modes has resolved, or with no bridge

Silent: today’s constant

Load and handler order give pi-modes first place (U1); a contract test runs the three handlers in that order on one fake pi and asserts each consumer saw the resolution.

Re-rendering a managed agent file at every session start

Fail-open: a file rewritten each session

Written only when the resolved ref differs from the file’s; a user-owned file is never written.

Out of scope

Running the battery (the operator’s); sources beyond the three shipped (an override); a UI to pick sources; pi-vertex’s catalogue; the judge’s prompt; refusing unknown overlay keys (the 1.0 freeze, #701).

Scope

Three MRs, in order, each validate green; consumer-sim 17/17 after U3 and U5. One release after U5, whose note says what moves for a non-Vertex box.

U1-U3 (feat/model-roles)

pi-modes/model-roles.ts; the bridge callback; config.ts keys, validation and OVERLAY_KEYS; session-wiring.ts resolution and line; mode-controller.ts, judge.ts, command-wiring.ts, config.ts fallbackSummarizer reading it. Tests: unit, the resolver over fake registries (Vertex only, anthropic+google only, one vendor only, nothing, an override, a source order); regression, every role’s first candidate equals the constant it replaces, which catches a table edit that silently moves a Vertex seat; contract, the bridge callback’s shape as pi-workflow and pi-agents read it; unit per consumer, with and without a resolution; the session line’s wording. modes.adoc (a roles section, the overlay rows), public-surface.adoc rows, CHANGELOG.adoc. Relates to #715.

U4 (feat/model-roles-reviewers)

reflection-review.ts, commit-pause.ts, plan-pause.ts reading the bridge; the same-vendor round two and its label. Tests: unit, reviewers with Vertex, with anthropic only (round two on the substitute, labelled), with no bridge (today’s constants); regression, the "did not happen" path when even the substitute is unreachable. modes.adoc’s review section. `Relates to #715.

U5 (feat/model-roles-helpers)

pi-agents/index.ts re-render at session start; model-reach.ts reduced to the one line. Tests: unit, a managed file re-rendered to the resolved ref, a user-owned file untouched, an override winning, no candidate leaving the packaged model and saying so; contract, the three session_start handlers in load order on one fake pi, each consumer seeing the resolution (Risks row 3); contract-drift.test.ts still pinning the packaged models. Closes #715.

Erratum (2026-11-04): the bridge exposes pickModel(role, configured), not a resolution snapshot. Each consumer’s configured model (a mode’s model, pi-workflow’s reviewer setting, an agent file’s model) leads its role’s candidates, so existing settings keep working as the first choice and the table supplies what follows.

Erratum (2026-11-04): U2’s session line names pi-modes' own roles (modes, judge, image, summarizer). The reviewers report a substitute in their review text (U4), and the helpers in pi-agents' line (U5), since each puts its own setting first and pi-modes cannot see it. /mode has no status output, so the full list is /mode models.

Erratum (2026-11-04): U5 keeps each session’s helper answer in <agentDir>/gadhs-pi-agents.resolved.json, and the seed at load renders it. Without it, the load put the packaged model back at every start and the session start rewrote the resolved one: the churn Risks row 4 rules out.

Erratum (2026-11-04): pi-modes reads the agent files in its own session_start, before pi-agents re-renders them. pi-agents now says gadhs:agents-seeded on pi’s bus when it re-rendered, and pi-modes reads the files again, so the model lock (#666) and the helpers' pricing see the model pi-subagents will run.

Edit this page · latest