Skip to content

fix(agent): recover cold model switches with --model at spawn (#277) - #288

Merged
kahme247 merged 2 commits into
mainfrom
fix/277-cold-model-switch
Oct 25, 2026
Merged

kahme247 merged 2 commits into
mainfrom
fix/277-cold-model-switch

Conversation

@kahme247

Copy link
Copy Markdown
Collaborator

Fixes #277

A cold set_model request used to fail when the session's saved model could no longer be restored: POST /api/agent/[id] spawned omp with only --resume, so omp exited with "Could not restore model " before the set_model RPC ever ran, and the UI only logged the failure to the console.

Changes:

  • lib/rpc-manager.ts: buildSessionSpawnArgs() and startRpcSession() accept a spawn model, passed as --model alongside --resume on cold starts only.
  • app/api/agent/[id]/route.ts: a cold set_model request binds the requested model at spawn time, tries the normal set_model RPC first (so a successful RPC still records the new model), and if that RPC fails spuriously but live get_state already shows the requested model, returns success instead of a false failure; a real mismatch rethrows the RPC error.
  • hooks/useAgentSession.ts: a failed model switch now shows an error notice instead of only console.error.
  • Tests in lib/rpc-manager.test.mjs, lib/api-contract.test.mjs, and hooks/useAgentSession.rpc.test.mjs.

Verification (omp 18.12.6, no provider credentials, no prompt sent):

  • A crafted session with saved model bogusprovider/bogus-model-123 reproduced the issue exactly: resume alone exits 1 with "Could not restore model bogusprovider/bogus-model-123", while resume + --model anthropic/claude-sonnet-4-5 stayed alive and get_state reported the replacement model.
  • End to end through the patched ompweb dev server, a cold POST set_model for that session returned HTTP 200 success and the session was then running with claude-sonnet-4-5 (previously HTTP 500).
  • Typecheck and lint clean. Full test suite: 1443 pass, 1 fail in bin/omp-web-systemd.test.mjs, which also fails on clean main and is unrelated to this change.

@kahme247
kahme247 merged commit 2f47165 into main Oct 25, 2026
3 checks passed
@kahme247
kahme247 deleted the fix/277-cold-model-switch branch October 25, 2026 21:48
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.

[Bug] Cannot switch models when resuming a session whose saved model cannot be restored

1 participant