Skip to content

fix(compaction): keep session model and variant on memory restore - #326

Open
CodeChenL wants to merge 1 commit into
tickernelz:mainfrom
CodeChenL:fix/compaction-preserve-session-model
Open

CodeChenL wants to merge 1 commit into
tickernelz:mainfrom
CodeChenL:fix/compaction-preserve-session-model

Conversation

@CodeChenL

Copy link
Copy Markdown

Fixes #325

Summary

The session.compacted handler passes agent (#236) but not model/variant when it injects restored memories. OpenCode resolves input.model ?? agent.model ?? session.model, so an agent that declares its own model takes over the session after every compaction.

This adds resolveSessionModel(), which reads the session's current model from session.get() (compaction does not change it), and passes model and variant alongside agent. A "default" variant is omitted, matching OpenCode's own normalization. When the model cannot be resolved, the injection behaves as before.

The OpenCode v2 compatibility client turns noReply prompts into ctx.session.synthetic(...), which does not go through model resolution, so that path is unaffected.

Testing

  • New unit tests for resolveSessionModel and two compaction scenarios (model passed through / left unset) in tests/compaction-agent-preservation.test.ts.
  • bun run typecheck, bun run lint and bun run format:check pass.
  • bun test: 465 pass, 11 fail. The same 11 fail on main (460 pass); they inspect the built dist/ bundle and need bun run build first.
  • End to end against OpenCode 1.18.31, using an equivalent patch on the published 2.26.0 build: default agent pinned to one model, session on another model with variant max, real auto-capture, then POST /session/:id/summarize. The injected message carried the session's model and variant, and session.model was unchanged. The same request without model (current behaviour) was recorded with the agent's model.

The session.compacted handler passed agent but not model/variant when
injecting restored memories. OpenCode resolves the model as
input.model ?? agent.model ?? session.model, so an agent with its own
model took over the session after each compaction.

Read the session's current model from session.get() and pass model and
variant with the injection. A "default" variant is omitted, matching
OpenCode's own normalization.
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.

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

1 participant