Skip to content

Compaction memory restore switches the session to the agent's default model #325

Description

@CodeChenL

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

  1. Pin the default primary agent to a model, e.g. "agent": { "build": { "model": "provider-a/model-x" } }.
  2. 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.
  3. Trigger compaction (POST /session/:id/summarize).
  4. 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions