Summary
After auto-compaction, the session.compacted handler injects the restored memories with session.prompt({ noReply: true, agent }). Since #236 it passes agent, but it still omits model and variant. OpenCode resolves the model of a new user message as input.model ?? agent.model ?? session.model (SessionPrompt.createUserMessage), so when the active agent declares its own model, the injected "Restored Session Memory" message is recorded with the agent's default model instead of the session's current one, and the session continues on that model after every compaction.
Environment
- OpenCode 1.18.31
- opencode-mem 2.26.0 (first observed on 2.20.1)
- A primary agent with its own model (e.g. oh-my-openagent's Sisyphus)
Reproduction
- Pin the default primary agent to a model, e.g.
"agent": { "build": { "model": "provider-a/model-x" } }.
- In a session, send a message with a different model and variant (e.g.
provider-b/model-y, variant max) so that auto-capture stores a session memory.
- Trigger compaction (
POST /session/:id/summarize).
- The injected "Restored Session Memory" user message carries
provider-a/model-x with no variant, instead of provider-b/model-y / max.
In real use this switched a Sisyphus session from deepseek-flash (max) to gpt-5.6-sol (medium) after compaction, the model oh-my-openagent resolves for that agent.
Suggested fix
Read the session's current model (session.get().model, which compaction does not modify) and pass model and variant together with agent. I'll open a PR.
Summary
After auto-compaction, the
session.compactedhandler injects the restored memories withsession.prompt({ noReply: true, agent }). Since #236 it passesagent, but it still omitsmodelandvariant. OpenCode resolves the model of a new user message asinput.model ?? agent.model ?? session.model(SessionPrompt.createUserMessage), so when the active agent declares its own model, the injected "Restored Session Memory" message is recorded with the agent's default model instead of the session's current one, and the session continues on that model after every compaction.Environment
Reproduction
"agent": { "build": { "model": "provider-a/model-x" } }.provider-b/model-y, variantmax) so that auto-capture stores a session memory.POST /session/:id/summarize).provider-a/model-xwith no variant, instead ofprovider-b/model-y/max.In real use this switched a Sisyphus session from
deepseek-flash (max)togpt-5.6-sol (medium)after compaction, the model oh-my-openagent resolves for that agent.Suggested fix
Read the session's current model (
session.get().model, which compaction does not modify) and passmodelandvarianttogether withagent. I'll open a PR.