Skip to content

feat: switch models and thinking levels on live OMP workers - #327

Open
dnth wants to merge 18 commits into
mainfrom
fm/fm-control-switch-model
Open

dnth wants to merge 18 commits into
mainfrom
fm/fm-control-switch-model

Conversation

@dnth

@dnth dnth commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

Summary

fm-control.sh <task> switch-model changes a live OMP worker's model and thinking level inside its current session.
It applies at once, like OMP's own /switch picker: the request already in flight finishes on the old model, and the next request uses the new one, even mid-task.
setModelTemporary, the picker's setter, is not exposed to extensions, so the extension calls pi.setModel then pi.setThinkingLevel, which are the session-only equivalents.
On a Responses-WebSocket model a reply already streaming can be cut by the switch, the same as the picker; the fm-control.sh header documents that once.

fm-control.sh <task> switch-model --model <provider/id> [--effort <level>] [--wait <s>]
  fold late receipts, then check the worker's channel (OMP ship or scout, extension ready)
  publish model-switch.<id>.request.json     beside the doorbell dir, never chat
  worker extension
    claim by rename -> pi.setModel -> pi.setThinkingLevel -> read back -> model-switch.<id>.ack.json
  verify the readback equals the target, then write meta model= and effort=
  -> switched | refused <reason> | partial | superseded
  deadline (default 15 s, monotonic)
  -> cancelled (request withdrawn by rename, with proof) | pending-unknown <id>
  switch-model --status folds a late receipt into meta; a changed worker generation is never rewritten

Removed after review and a captain decision: any idle wait, turn-admission gate, queued-message check, race result, and boundary field.
The inbox doorbell library is unchanged from main.

Evidence

  • Before: a typed /model <id> sent to a busy worker arrived as chat, /switch could not be typed, and task meta and the Herdr label kept the old model.
    After: live Herdr-lab guard on OMP 18.22.2 and Herdr 0.9.5, driven from commit 832c8e29 of the earlier history (ran, exit 0; later pipeline fix commits changed code, and the pipeline's own live Test run below covers the final head):
    • an idle switch changes model and thinking level, the next turn runs on the new model, the model-change entry is recorded, meta and the pane label follow;
    • a switch requested while a 25-second foreground sleep tool call is unanswered: that call's request ran on the old model, the model-change entry precedes its result, and every later request ran on the new model; the user-message sequence shows no /model or /switch chat;
    • an unknown model and a model without credentials are refused with typed reasons and meta unchanged;
    • the documented resume path (no --model) keeps the switched model;
    • the global ~/.omp config files are byte-identical before and after, and the default Herdr session is intact.
  • Portable tests drive the real extension library through a fake OMP host: tests/fm-omp-task-model-switch.test.sh (refusal matrix including a target with no thinking levels, partial, superseded, withdrawn, ownership) and tests/fm-control-switch-model.test.sh (mid-task apply, cancellation with proof via a stopped extension, late receipt reconciliation including for an exited worker, status ordered by acknowledgement sequence, native thinking recorded, argument contract).
    I broke the code on purpose for the effort preflight, the receipt fold order and the status order; each test failed as intended (ran).
  • The pipeline's Test step drove the product live (see the Pipeline section below).
  • CI on the final head 53837e29: 20 of 20 checks passed (cited, gh-axi pr view).
    The first CI round here had failures that also fail on main; main's runner pin to ubuntu-24.04 (merged separately) fixed them, and the pipeline rebased onto it.
    The Stock macOS Bash snapshot job then failed for a real reason in this change: tests/fm-omp-task-model-switch.test.sh held a quoted heredoc inside a command substitution, which Bash 3.2 cannot parse (line 236).
    The pipeline's CI fix round removed the command substitution, and the job passes.
  • Failing locally on main too (ran, parent commit d0ec00f0 equals the old origin/main): fm-omp-harness, fm-omp-relaunch-guard, fm-omp-branch-types, fm-omp-primary, fm-send-turn-start.
    These are local-environment failures; they pass on CI's pinned image.

Deferred findings

By captain decision the PR ships after its last fix round with these findings left open; no issue was commented on.

Raised by the final review round (this pipeline run):

  • omitted-effort-differs-from-omp-picker-role-preference (ask-user): without --effort the extension skips the thinking setter, so a role-configured effort that the picker would apply is not applied, and the receipt records the retained level as a success.
  • unrequired-switch-option-repetition (ask-user): a repeated --model, --effort or --wait, or a repeated --status, is accepted with last-value-wins instead of being refused.
  • unrequired-live-guard-selection-for-fake-host-edits (ask-user): bin/fm-test-run.sh maps a fake-host edit to the opt-in live guard, which never loads that fixture.
  • relaunch-stops-worker-after-known-fold-failure (auto-fix, not applied): an OMP relaunch can stop a healthy worker when a late receipt is already known to be unreconciled.
  • status-can-report-success-with-unfolded-receipt (auto-fix, not applied): --status can exit 0 with last-state=acknowledged-unfolded and unresolved=0 when the receipt lands between two scans.

Raised by the previous pipeline run's last re-review and not raised again by this rerun (not fixed or re-verified by me):

  • switch-publishes-after-its-own-deadline: the staged request is made visible without re-checking the deadline.
  • unrequired-live-guard-keep-running-mode: the FM_OMP_MODEL_SWITCH_KEEP_FAILED mode of the live guard is not needed.
  • resume-can-regress-acknowledgement-sequence: after a same-generation resume a backward clock step can seed the acknowledgement sequence below an already-folded one.
  • switch-fixture-cleanup-signals-reaped-pids: the fixture cleanup can signal a reused PID.

The Pipeline Review block below lists the findings as the pipeline recorded them.

Merge Danger

Door: two-way.

The change adds one lifecycle verb and an extension channel, and it restricts a relaunch's switch coordination to OMP transitions; reverting the merge removes both.
The branch also carries main's CI runner pin through the rebase; that file is not part of this change's diff against main.

Blast Radius: OMP workers

A switch is session-only and never edits global config, but a worker launched before this lands has no channel and is refused until it is relaunched.
On a Responses-WebSocket model, a switch can cut a reply that is still streaming.

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 5 issues (1 error, 4 warnings)
  • 🚨 bin/fm-control.sh:1594 - An OMP relaunch can stop a healthy worker when a late switch receipt is already known to be unreconciled. If a concurrent steer holds the task metadata lock beyond the fold budget, the pre-relaunch fold failure is discarded here. Relaunch then calls do_exit at bin/fm-control.sh:1529 and aborts if the fold still fails at bin/fm-control.sh:1532. Reject a known reconciliation failure before stopping the worker and retain the post-stop check for receipts that arrive during shutdown. The direct spawn path already refuses an unfolded current-generation receipt at bin/fm-spawn.sh:4419.
  • ⚠️ bin/fm-control.sh:1048 - Status can exit 0 with last-state=acknowledged-unfolded and unresolved=0. After the fold scan at bin/fm-control.sh:1096, the request-ID glob at bin/fm-control.sh:1047 can capture only the processing file. If OMP publishes the receipt and removes the claim at .omp/extensions/lib/fm-task-model-switch.ts:221 and :363 before the shell checks that path, the ID is omitted from the count. The later scan sees the receipt and updates only the last result at bin/fm-control.sh:1113–1116. Derive the count and exit result from the same observations, including any newly seen unresolved receipt.
  • ⚠️ .omp/extensions/lib/fm-task-model-switch.ts:273 - The accepted design says “exactly like OMP’s own /switch picker.” Without --effort, this hunk calls pi.setModel and skips the thinking setter at .omp/extensions/lib/fm-task-model-switch.ts:286. If the current effort is low and the target supports low and high with a configured role using high, OMP’s picker applies the role’s high, while the extension setter can retain low. The receipt at .omp/extensions/lib/fm-task-model-switch.ts:309 and metadata fold at bin/fm-control.sh:832 then record low as a successful switch. Decide whether omitted effort should follow the picker’s role preference or the extension setter’s native result. OMP picker · OMP model controls
  • ⚠️ bin/fm-control.sh:309 - The switch parser adds last-value-wins handling for repeated --model, --effort, and --wait at bin/fm-control.sh:309–314 and accepts repeated --status at bin/fm-control.sh:354. For example, --model p/a --model p/b silently switches to p/b. The intent needs one value per option or standalone --status. Remove duplicate-option acceptance for this verb.
  • ⚠️ bin/fm-test-run.sh:1017 - A change confined to the fake host selects the live OMP guard, which never loads that fixture. With the live opt-in already set, a fake-only edit starts a real lab and spends model turns. No acceptance criterion needs live execution for that input. Remove the fake-host-to-live-guard mapping and keep the two fake-host consumers at bin/fm-test-run.sh:1015–1016.
✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 9 of 9 scenarios driven live against the product
Scenario Result Live Evidence
Switch an idle local OMP worker from synthetic alpha/low to beta/medium and verify the next turn, task metadata, and Herdr label ✅ pass live Committed live OMP and Herdr guard, Local model requests during the committed guard, Live Herdr sidebar showing the switched model and native effort
Switch a local OMP worker during a synthetic foreground sleep and see subsequent requests use the new model ✅ pass live Committed live OMP and Herdr guard, Local model requests during the committed guard
Switch while a synthetic localhost HTTP reply is streaming and see the old reply finish and the next request use the new model ✅ pass live Live refusals, HTTP streaming, and deadline behavior, Local HTTP stream and delayed metadata requests
Submit invalid switch targets, unsupported effort, malformed options, and ineligible synthetic task records to the local CLI ✅ pass live Live refusals, HTTP streaming, and deadline behavior
Resume the switched local OMP session without a model override and verify the next turn and disposable profile ✅ pass live Committed live OMP and Herdr guard, Local model requests during the committed guard
Let a local switch time out while OMP is suspended and verify withdrawal before claim ✅ pass live Live refusals, HTTP streaming, and deadline behavior
Delay a claimed switch at the synthetic localhost provider and recover its receipt through status and the next switch ✅ pass live Live refusals, HTTP streaming, and deadline behavior, Local HTTP stream and delayed metadata requests, Live relaunch, generation fencing, and reconciliation
Relaunch a local OMP worker after a switch and replay a request and receipt from its old generation ✅ pass live Live relaunch, generation fencing, and reconciliation, Live Herdr sidebar showing the switched model and native effort
Request high effort in a local OMP SDK session with a low ceiling and verify the partial receipt ✅ pass live Real OMP SDK partial result
  • FM_OMP_MODEL_SWITCH_LIVE_E2E=1 FM_OMP_MODEL_SWITCH_LIVE_REV=86b197c8b40c1199b18adf2fb213c03bcf40b0c6 FM_OMP_MODEL_SWITCH_LIVE_FROM=lab/alpha FM_OMP_MODEL_SWITCH_LIVE_TO=lab/beta bash tests/fm-omp-model-switch-live-e2e.test.sh in a disposable network and PID namespace
  • bash /tmp/guard-extra.sh against the archived target with the local streaming and metadata provider, including fm-control.sh &lt;task&gt; switch-model --wait 1 and switch-model --status
  • bash /tmp/guard-relaunch.sh against the archived target, including fm-control.sh &lt;task&gt; relaunch --note &lt;test note&gt; and old-generation request and receipt replay
  • bun /tmp/sdk-partial-18.mjs &#34;$PWD/.omp/extensions/lib/fm-task-model-switch.ts&#34; with the real OMP 18.22.2 SDK and a synthetic low effort ceiling
  • bash tests/fm-control-switch-model.test.sh and bash tests/fm-omp-task-model-switch.test.sh for supplemental portable coverage
  • timeout -k 3s 75s bash tests/&lt;selector&gt;.test.sh on archived d0ec00f0 and 86b197c8b40 for fm-omp-harness, fm-omp-relaunch-guard, fm-omp-primary, and fm-send-turn-start
  • herdr session attach &lt;lab&gt; in a sized, drained PTY to render and inspect the sidebar screenshot
⚠️ **Document** - 1 info
  • ℹ️ tests/fm-omp-branch-types.test.sh:52 - The SDK check comment lists ctx.isIdle among the fields it verifies. The checked model-switch context omits that field. The test file falls outside this documentation phase.
✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

dnth added 17 commits November 24, 2026 13:25
…-control verb

- Add `fm-control.sh <task> switch-model --model <provider/id> [--effort <level>] [--wait <s>] | --status`.
  The request is files in the task's doorbell request directory, applied by the worker's own extension through OMP's session-only `setModel` and `setThinkingLevel`, never typed into the TUI.
- Add `.omp/extensions/lib/fm-task-model-switch.ts`, which owns the wire contract.
  A request applies while the session is idle or inside the awaited `turn_end` or terminal `agent_end` handler, never mid-stream.
  Every request carries a unique id, and the acknowledgement records the id, the model and thinking level before and after, and a typed outcome (applied, partial, refused, superseded).
- On timeout the verb withdraws the request by an atomic rename the worker's claim cannot also win (cancelled), or reports pending-unknown with the request id.
  `--status` and every later verb fold a late acknowledgement into task meta, and a changed worker generation is never rewritten (meta-stale).
  Task meta and the Herdr pane label change only after the extension's readback equals the target.
- Refuse non-OMP harnesses, secondmates, and workers that predate the channel with the concrete reason.
- Tests: a fake-host extension test, a verb test (refusals, mid-turn deferral, cancellation, late acknowledgement, partial, meta-stale), an SDK typecheck of the library, and an opt-in live Herdr-lab guard (idle and mid-turn switches, documented resume, unchanged global OMP config).
- The busy-wiring test's fake OMP host now runs every handler registered for an event, as OMP does.
- Document the verb in the fm-control header, the harness-adapters omp table, agent-control, and the Herdr pane label contract, and record the dated live result in runtime-backends verification.
…n-admission gate

- Drop the turn_end boundary: OMP does not await extension turn_end handlers, so a slow setter landed mid-run (probed on OMP 18.22.2).
- Apply at settled idle (terminal agent_end or the idle watcher) when the message queue is empty, with credentials resolved first.
- Hold the apply in one capped critical section: before_agent_start and the inbox doorbell wait on a process-global gate.
- Count provider requests prepared during the apply and report raced instead of a clean switch.
- Require the emitted ack sequence as the only order field, take only separate --model/--effort arguments, and limit relaunch coordination to OMP transitions.
- Use a monotonic deadline with one last receipt check, rank a folded receipt above a leftover claim, and always republish the pane label for the newest verified receipt.
- Run the live guard from an explicit Git revision and prove the busy case: the whole in-flight run stays on the old model, the next turn runs on the new one.
…ive guard

- The echoed prompt text satisfied the old wait before the turn had run, so the model check could read an empty reply.
…ell lib to its gate tests

- Replace the awaited turn_end claims in the verification record with the probe evidence and the 2026-11-23 live result.
- Run the gate tests when the doorbell library changes.
…ch picker

- Drop the settled-idle wait, the turn-admission gate with its doorbell hold, the queued-message check, the race witness and its raced result, and the boundary field.
- The extension claims a request as soon as it sees it and calls the session-only extension setter pi.setModel then pi.setThinkingLevel; the request in flight finishes on the old model and the next one uses the new model, even mid-task.
- Keep the request-file channel, the typed refusals, partial and superseded results, the ack sequence, readback, and the meta update; keep the bounded ack wait with cancel-with-proof or pending-unknown, now 15 s by default.
- Record the native thinking level in meta and clear stale effort only when the model reports none; restore the doorbell library and its test mapping.
- Rework the fake host and tests: a busy session with queued messages is switched at once, a stopped extension proves cancellation, and the live guard shows the in-flight request on the old model and the next on the new one.
- The turn-admission gate hold no longer exists, so the doorbell needs no change.
- Replace the settled-idle wording with the picker-equivalent behavior and the 2026-11-23 live run from commit c5f87a0.
…st, order status by sequence, trim extras

- Refuse an effort on a target with no thinking levels with the typed effort-unsupported before changing anything.
- Fold late receipts before the channel check refuses a switch, and derive the latest result from the emitted sequence.
- Document once in the fm-control header that a streaming Responses-WebSocket reply can be cut, as with the picker.
- Use one internal poll interval, drop the unconsumed ack pid and ready timestamp, the fake responder's busy and idle commands, and the extra operator docs.
- The live guard blocks a fixture tool until the switch receipt arrives and checks that the first later request ran on the new model.
…marker

- The worker reads its inbox message with tool calls first, so the guard waits for the call that names the release file.
… sleep

- OMP turns a long polling loop into a background job and ends the turn, so the guard uses a 25-second foreground sleep and requires the switch receipt to arrive while its tool call is unanswered.
…ly in the live guard

- After the switch the worker acknowledges its inbox message before replying; every one of those requests must run on the new model, and one of them carries the reply.
@dnth
dnth force-pushed the fm/fm-control-switch-model branch from 59237ad to 82c6196 Compare November 24, 2026 06:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant