Repository navigation
feat(pi): let /supervision-model pick branch reasoning effort - #3079
Merged
Merged
Conversation
Supervision is an easier job than the captain's own conversation, so the Pi supervision branch does not need main's reasoning effort any more than it needs main's model. /supervision-model now settles both in one flow: the existing model picker, then a follow-up effort picker built from Pi's own supported thinking levels for the model just chosen. Firstmate keeps no effort catalog of its own; the menu, the clamp, and the vocabulary all come from Pi. The pick persists as one line in this home's gitignored config/supervision-branch-effort, independent of the model pin: a captain may pin a model, an effort, both, or neither. The effort pin's current state decides the branch effort on every branch build - the first wake of a cold start and the reopen after /new, /resume, /fork, or reload - and overrides Pi's restore of whatever level a reopened branch session recorded, which is what keeps "Follow main" honest. With no pin, main's own current effort is applied explicitly and followed live through Pi's thinking_level_select event, the same way an unpinned branch already follows main's model, and the two selections now share one build revision so either change invalidates an in-flight build. The branch is never refused over effort. Pi owns the clamp, so a pinned level the branch's model cannot run becomes that model's nearest supported level while the captain's raw pick is kept for a model that supports it, and the command reports the level the branch will really run at rather than the raw pin. A token Pi would not recognize at all is treated as no pin rather than passed to that clamp, which would otherwise collapse a typo into the model's lowest level. Only when main's effort cannot be read either does a build pass no effort override at all, which is the behavior from before this file existed. Pi's own effort vocabulary is pinned by a bidirectional type assertion against Pi's getThinkingLevel return type, so the tracked strict typecheck against the installed package fails the moment Pi adds or removes a level. docs/configuration.md owns the operator-facing schema for both pins. Portable regressions cover the pin on create and reopen, model-only and effort-only pins working independently, clearing a pin returning the branch to main's effort, live-follow of a mid-session change, the clamp, an unrecognized token, the unknown-main-effort fallback, and the command's two-step flow, persistence, cancellation, and honest reporting. The opt-in real-SDK guard proves the vendor surface all of that rests on, and also repairs a pre-existing gap that left it unable to load the extension at all.
Confidence Score: 5/5The PR appears safe to merge, with no concrete changed-code defect established. The implementation keeps model and effort pins independent, explicitly reapplies effort across branch lifecycle transitions, follows unpinned main effort through the shared revision path, and reports unresolved or clamped selections without claiming an unapplied value. Reviews (1): Last reviewed commit: "no-mistakes(document): Clarify Pi-owned ..." | Re-trigger Greptile |
knowttl
added a commit
to knowttl/firstmate
that referenced
this pull request
Aug 26, 2026
Rebuilt from the current fork main (c3a2490), which had independently absorbed 4 of the original 7 upstream commits via its own kunchenguid:main merge while this sync was in progress. This merges the 3 that remained: - 9ce69ac fix(bin): stop a correlation token from hiding and stranding decisions (kunchenguid#1967) - 07bf0c8 fix: keep routine supervision noise out of captain chat (kunchenguid#3093) - f7a387f feat(pi): let /supervision-model pick branch reasoning effort (kunchenguid#3079) Conflict resolution (2 files), both from upstream kunchenguid#3093 adding a new adapter "silent" no-op suppression path, against the process-event adapter this fork renamed lavish -> atelier in df367d7: - bin/fm-procevent-atelier.sh: adopted upstream's new `silent` subcommand, its doc block, and the extended usage() range, keeping the fork's Atelier naming and Atelier-specific header notes. Auto-merged cmd_silent() body and dispatch retained; the one leftover upstream "Lavish" mention renamed. - .agents/skills/process-event-sources/SKILL.md: kept the fork's two Atelier guidance lines and inserted upstream's new "routine no-op" line rewritten for Atelier. Renamed upstream-introduced Lavish/lavish orphans to Atelier/atelier in docs/configuration.md, docs/verification/process-event-sources.md, tests/fm-procevent.test.sh, tests/fm-pi-watch-extension.test.sh so nothing references the nonexistent fm-procevent-lavish.sh. Full-tree grep confirms zero lavish references remain. Verified: bin/fm-lint.sh clean (shellcheck 0.11.0, actionlint 1.7.12); fm-procevent, fm-pi-watch-extension, fm-classify-corr-token all green. One flaky timing failure in an fm-pi-watch-extension watcher-lock case passed on re-run and passes identically on plain main, so it is pre-existing flakiness, not a merge regression.
Intent
Extend the existing Pi /supervision-model command so it also lets the operator set the supervision branch's reasoning EFFORT, persisted and applied the same way the model already is. This builds directly on the just-merged model-selection feature (PR #3028, now on main) in .pi/extensions/fm-branch-supervision.ts.
What the captain asked for:
Decisions and findings made while doing the work, which a reviewer reading only the diff would not know:
Pi DOES expose an in-flow effort surface, so the brief's fallback clause ('if Pi exposes no in-flow effort picker') did not apply and no needs-decision was raised. Pi's effort concept is ThinkingLevel. The implementation deliberately uses Pi's own surfaces end to end rather than any Firstmate catalog: getSupportedThinkingLevels and clampThinkingLevel from @earendil-works/pi-ai for the menu and the clamp, pi.getThinkingLevel() for main's current effort, and pi.on('thinking_level_select') for live-follow. This mirrors Pi's own thinking selector, which builds its menu from getSupportedThinkingLevels(model) and labels entries with the bare level name.
The new @earendil-works/pi-ai import is safe and not a new dependency risk: Pi's extension loader exposes pi-ai to extensions as a first-class module in BOTH its Node/jiti alias table and its compiled-binary VIRTUAL_MODULES table, aliasing the root specifier to its compat entrypoint - the same standing as the @earendil-works/pi-tui and typebox imports the extension already had. This was verified by reading the installed loader and is recorded in a comment at the import site.
Effort is persisted in a parallel single-value file config/supervision-branch-effort rather than by extending the model pin's format, because that matches how config/supervision-branch-model and config/calm are written and read and keeps the two pins independently expressible. config/ is gitignored wholesale so no .gitignore change was needed. The model pin's atomic 0600 write/clear helpers were generalized from writeModelPin/clearModelPin into writePinFile(path, value)/clearPinFile(path) and are now shared by both pins rather than duplicated.
The effort step runs AFTER the model step because the model decides which levels exist: the effort menu is Pi's supported-level list for the model just chosen, so xhigh/max disappear on a model that maps neither and a non-reasoning model offers only 'off'. The model resolved by the model step is captured and reused for the effort menu rather than resolved a second time through another isolated ModelRuntime.
Cancellation semantics were chosen deliberately: cancelling the model picker cancels the whole command and changes neither choice (preserving today's behavior); cancelling only the effort picker keeps the standing effort choice and STILL applies the model pick made in the same run. Ordering was arranged so the model pick is persisted before the effort step, so an effort-step cancellation or failure can never swallow it. A failing effort step is caught so the branch still rebinds and the captain still hears what took effect and what did not.
Honest-message discipline: the two steps report through ONE closing notification whose severity is the worse of the two parts, so the existing single-notice contract is preserved. Because Pi clamps a level a model cannot run, the message reports the level the branch will REALLY run at - 'Effort: max, which this model runs at high.' - rather than echoing the raw pin, while the captain's raw pick is kept on disk so it applies again on a model that supports it.
A token Pi would not recognize is rejected as 'no pin' rather than passed to Pi's clamp. This was chosen after verifying against the real SDK that clampThinkingLevel collapses an unrecognized token to the model's LOWEST level, which for a reasoning model is 'off' - so a typo in a hand-edited pin would otherwise silently turn supervision reasoning off. That contradicts the model pin's established absent/unparseable = follow-main semantics.
Rejecting an unrecognized token needs a runtime level list, which Pi does not export. Rather than hardcode a catalog that could silently drift, BRANCH_EFFORT_LEVELS is paired with a BIDIRECTIONAL compile-time assertion against Pi's own getThinkingLevel return type, so the tracked strict typecheck against the INSTALLED Pi package (tests/fm-pi-primary-types.test.sh) fails the moment Pi adds or removes a level in either direction. Both failure directions were confirmed by deliberately drifting the array. The picker's options and every clamp still come from Pi's own functions; this array exists solely for that one validation job.
Main's effort needs no tracking state, unlike main's model: Pi answers pi.getThinkingLevel() directly on demand including at wake time, so it is read at build time inside a try/catch. Unlike model_select, Pi emits thinking_level_select ONLY on an actual change and not on session restore, which is why the baseline is read rather than tracked.
modelSelectionRevision was renamed to branchSelectionRevision and releaseBranchForModelChange to releaseBranchForSelectionChange, because both selections now share exactly one revision and one release path - a model or effort change invalidates an in-flight branch build identically. This is a pure rename of the existing mechanism, not a behavior change to model selection.
The unpinned branch applies main's effort EXPLICITLY rather than merely omitting the option. This was proven necessary against the real SDK: a reopened session with no override restores its own recorded thinking level, so omitting the option would let a cleared pin silently restore the level that pin left behind. Only when main's effort cannot be read either does a build pass no effort override at all, which is the pre-feature behavior; the branch is never refused over effort.
Verification added: three new portable regression suites in tests/fm-pi-branch-extension.test.sh covering the pin on create and reopen, model-only and effort-only pins working independently, clearing a pin returning the branch to main's effort, live-follow of a mid-session change with pins staying authoritative, Pi's clamp, an unrecognized token, the unknown-main-effort fallback, and the command's two-step flow, persistence, cancellation and honest reporting. All six plausible failure modes were mutation-tested (dropped override, ignored pin, no live-follow, no clamp, loose validation, model-blind menu) and each is caught. A third real-SDK probe was added to the opt-in live guard tests/fm-pi-branch-live-e2e.test.sh proving Pi's own level lists, the clamp behavior including the unrecognized-token collapse, and that an explicit effort beats a genuinely RECORDED session level. Because Pi only flushes a session file once an assistant message exists, that probe appends the level change and a message through the real SessionManager rather than hand-writing the format.
Pre-existing unrelated breakage fixed in the same pass, per the standing instruction to fix test failures encountered even when not caused by the current work: tests/fm-pi-branch-live-e2e.test.sh was ALREADY BROKEN on main - its fixture never copied lib/fm-calm-visibility.ts, so the guard could not load the extension at all and failed before running any probe. This was confirmed by stashing all local changes and reproducing on a clean checkout. The missing copy is now added, and all three live probes pass. The pi-ai symlink additions in that file and in tests/fm-pi-primary-types.test.sh are required by the new import.
docs/configuration.md's section heading was renamed from 'Pi supervision branch model' to 'Pi supervision branch model and effort' so one command has one owner section; all three referring anchors in docs/pi-supervision-branch.md and README.md plus the AGENTS.md config inventory line were updated in the same change, and bin/fm-doc-audience-check.sh passes.
docs/verification/runtime-backends.md was updated with the dated maintainer-verification evidence for the new vendor surface, including the exact effort-level lists and clamp results observed, and noting that the strict typecheck is the enforcement for the declared effort vocabulary.
Verification run locally before validation: bin/fm-lint.sh clean, bin/fm-doc-audience-check.sh clean, strict Pi typecheck green against installed Pi 0.81.1, all 25 assertions in tests/fm-pi-branch-extension.test.sh pass, all three real-SDK live probes pass, and bin/fm-test-run.sh --changed --base origin/main reported 75 scripts with 0 failures.
What Changed
/supervision-modelmodel selection, with independent persistent model and effort pins.Risk Assessment
✅ Low: The fix resolves the effective restored branch model before constructing or describing effort choices, avoids fabricated picker levels, and reports unresolved effort honestly without disrupting branch wake fallback behavior.
Testing
Inspected the scoped diff, then exercised the two-step
/supervision-modelflow, independent model/effort persistence, create/reopen behavior, live follow-main changes, model-specific menus, clamping, unknown-model messaging, and cancellation through the executable extension harness; real Pi SDK 0.81.1 probes confirmed explicit effort overrides recorded session effort and used Pi-owned level/clamp behavior. No screenshot was captured because this is an interactive Pi TUI picker and the isolated real-SDK probe intentionally runs without provider credentials; reviewer-visible command transcripts were recorded instead. All targeted checks passed and left the worktree clean.Evidence: Executable supervision branch extension behavior transcript
Source: Executable supervision branch extension behavior transcript
Evidence: Real Pi SDK model and effort precedence transcript
Source: Real Pi SDK model and effort precedence transcript
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 2 issues found → auto-fixed ✅
.pi/extensions/fm-branch-supervision.ts:1104- This fallback builds the effort picker from the hardcoded BRANCH_EFFORT_LEVELS array when main's selected model cannot be resolved. That directly contradicts the required criterion, "Use Pi's OWN effort/thinking menu ... do NOT invent a parallel Firstmate effort catalog. Discover the supported set from Pi," and the stated decision that this array exists "solely for that one validation job." The path is reachable after choosing Follow main with an extension-only or otherwise unavailable main model. Ask whether the effort step should instead derive the restored branch model through Pi's runtime/session boundary or present an explicitly indeterminate Pi-owned flow..pi/extensions/fm-branch-supervision.ts:1134- When branchModel is unresolved, describeBranchEffort treats the raw choice as the applied level. For example, an existing shallow branch session plus an unavailable main model and amaxeffort pin produces "Effort: max," but createAgentSession restores the shallow model and clamps the actual session tohigh. This violates the required criterion, "never report an effort was applied that was not; the success message must reflect what was actually applied." Resolve the effective restored model before reporting, or report that the effective effort is unknown rather than claiming the raw level.🔧 Fix: Resolve effective branch effort honestly
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
git status --shortandgit diff --stat 9a01dea3995c7f80ff4890d6f77142bba32d4ba3..9ec8115f4b1f56029477d0ebafe69ab2efb3eda9bash tests/fm-pi-branch-extension.test.shFM_PI_BRANCH_LIVE_E2E=1 bash tests/fm-pi-branch-live-e2e.test.shVerified the worktree remained clean after testing.✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.