Skip to content

feat(pi): let /supervision-model pick branch reasoning effort - #3079

Merged
kunchenguid merged 3 commits into
mainfrom
fm/fm-supervision-branch-effort-r1
Aug 26, 2026
Merged

kunchenguid merged 3 commits into
mainfrom
fm/fm-supervision-branch-effort-r1

Conversation

@kunchenguid

Copy link
Copy Markdown
Owner

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:

  • /supervision-model must set reasoning effort TOO, as a FOLLOW-UP picker shown AFTER the model pick, consistent with Pi's own effort menu. This is NOT a second slash command - it is one more step in the same /supervision-model flow.
  • A pinned choice (model and/or effort) persists - the pin stays put.
  • 'Follow main' follows effort too: an unpinned branch follows main's current effort exactly as it already follows main's model, including mid-session live-follow and on every create/reopen.
  • Use Pi's OWN effort/thinking menu the same way the model step uses Pi's own model selector - do NOT invent a parallel Firstmate effort catalog. Discover the supported set from Pi, matching how the model list was obtained.
  • Persist the effort as a gitignored config/ value matching the existing single-value config convention, keeping model and effort independently expressible: a pin may set model, effort, or both.
  • Apply the effort pin on branch create AND every reopen/resume/fork/reload, overriding Pi's session restore, exactly as the model is applied; when unpinned, apply main's current effort including mid-session live-follow via the same revision mechanism (modelSelectionRevision path).
  • Keep it consistent with the model behavior: same command, same persistence style, same create/reopen + live-follow application, same honest-message discipline - never report an effort was applied that was not; the success message must reflect what was actually applied.
  • Do not change the model-selection behavior itself except where the two must share the picker flow, the config, or the revision/apply path.
  • docs/configuration.md owns the operator-facing schema: document the effort persistence, its absent=follow-main semantics, and how it relates to the model pin, in or next to the existing 'Pi supervision branch model' section. Update docs/pi-supervision-branch.md where it describes /supervision-model so it mentions the effort step.
  • This edits Firstmate's shared tracked material, so the firstmate-coding-guidelines skill was loaded and followed: one sentence per line in tracked Markdown prose, plain dash never an em dash, shellcheck-clean bin scripts, colocated tests updated in the same change, and maintainer-verification evidence recorded. No agent/tool/AI name as a commit co-author.
  • Colocated tests must cover: effort-pinned -> branch uses it on create and reopen; effort-unpinned -> follows main including a mid-session change; model-only and effort-only pins each working independently. They must exercise the real read/apply path or a typed model of it, never source-text assertions.

Decisions and findings made while doing the work, which a reviewer reading only the diff would not know:

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. 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.

  7. 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.

  8. 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.

  9. 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.

  10. 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.

  11. 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.

  12. 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.

  13. 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.

  14. 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.

  15. 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

  • Add a Pi-native reasoning-effort picker after the /supervision-model model selection, with independent persistent model and effort pins.
  • Apply pinned effort on branch creation and reopen, while unpinned branches follow main's effort live and clamp unsupported levels through Pi's APIs.
  • Document the model-and-effort configuration and expand portable, type-level, and real-SDK regression coverage.

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-model flow, 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

ok - fm_branch_outcomes hides through ToolExecutionComponent while Calm-off and HTML export stay stock
ok - branch owns accepted wakes with a stable prefix contract and verdict-driven merge delivery
ok - scopeForUnreadWake excludes every main-only class without vetoing eligible task-local rows, and writes the eligible snapshot
ok - branch prompt_cache_key is stable per home across sessions and distinct between homes
ok - branch default-on eligibility (task-scoped, heartbeat, afk) binds and a broken branch falls back to main
ok - pre-drain eligibility re-check defers a newly main-owned row
ok - pre-drain eligibility re-check excludes a newly main-owned row without deferring eligible work
ok - a settled branch turn releases an unacknowledged grant for main replay
ok - a stale main claim cannot silently suppress later wake delivery
ok - pre-drain eligibility re-check no-ops an already-drained wake
ok - dialog mirror filters tool and operational traffic, lands before wakes, and keeps a durable cursor
ok - branch session persists across process restarts through the recorded pointer
ok - the current pin state binds every branch create and reopen, and clearing it returns the branch to main's model
ok - unpinned branches follow main model changes live while pinned branches stay fixed
ok - supervision-model command persists the captain's pick and rebinds the live branch
ok - the effort pin binds every branch create and reopen, and clearing it returns the branch to main's effort
ok - unpinned branches follow main effort changes live while pinned branches stay fixed
ok - supervision-model runs an effort picker after the model picker and persists both independently
ok - an unusable model pin falls back to main and an unparseable one is treated as no pin
ok - replacement activation cleans old branch leases and retries failed cleanup
ok - branch activates on a cold start once the lock is acquired, never before
ok - queued wakes and mirrors stop mutating branch state after lock ownership is lost
ok - stale reports, shells, mirrors, cursors, leases, and prompts perform no side effects
ok - a Pi session that does not own the lock accepts nothing and mutates no branch state
ok - an extension rebind re-mirrors undelivered dialog instead of dropping it
Evidence: Real Pi SDK model and effort precedence transcript

Source: Real Pi SDK model and effort precedence transcript

ok - real Pi SDK 0.81.1 accepts the branch session construction and preserves an unpromptable wake
ok - real Pi SDK 0.81.1 applies an explicit branch model on create and over a reopened session's recorded model
ok - real Pi SDK 0.81.1 reports its own supported effort levels and applies an explicit branch effort over a reopened session's recorded level

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 a max effort pin produces "Effort: max," but createAgentSession restores the shallow model and clamps the actual session to high. 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 --short and git diff --stat 9a01dea3995c7f80ff4890d6f77142bba32d4ba3..9ec8115f4b1f56029477d0ebafe69ab2efb3eda9
  • bash tests/fm-pi-branch-extension.test.sh
  • FM_PI_BRANCH_LIVE_E2E=1 bash tests/fm-pi-branch-live-e2e.test.sh
  • Verified the worktree remained clean after testing.
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

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.
@greptile-apps

greptile-apps Bot commented Aug 25, 2026

Copy link
Copy Markdown

Confidence Score: 5/5

The 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

@kunchenguid
kunchenguid merged commit f7a387f into main Aug 26, 2026
14 checks passed
@kunchenguid
kunchenguid deleted the fm/fm-supervision-branch-effort-r1 branch August 26, 2026 05:08
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.
akrcdev added a commit to akrcdev/firstmate that referenced this pull request Aug 29, 2026