Skip to content

feat: Switch compaction model from session model#14665

Open
ryanwyler wants to merge 1 commit intoanomalyco:devfrom
gignit:feature/compaction-model
Open

feat: Switch compaction model from session model#14665
ryanwyler wants to merge 1 commit intoanomalyco:devfrom
gignit:feature/compaction-model

Conversation

@ryanwyler
Copy link
Contributor

Issue for this PR

Closes #13946
Closes #12135
Related: #14368, #14259, #14233

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Adds a dedicated compaction model selector so users can run one model for chat and a different model for summarization. Run Claude Sonnet or Opus 4.6 for interactive coding while compacting with Zen Big Pickle (free) to eliminate compaction cost entirely, or GPT-5.3 Codex (400k context) for detail-oriented summaries that capture nuance your session model would lose — with headroom to compact sessions that have already exceeded their primary model's context limit.

For best results use this enhanced compaction prompt: #14662

Why not just use agent.compaction.model in config?

The existing agent.compaction.model config option is static — it requires editing opencode.json and is fixed for the lifetime of the config. This PR adds runtime switching without touching config files, matching how the primary model switcher works:

  • Switch compaction models on the fly without restarting or editing config
  • Different sessions can use different compaction models in the same instance
  • Browse available models with the same familiar picker UI
  • See the active compaction model in the prompt footer at a glance

Both approaches coexist. Model resolution priority: TUI selection > config file (agent.compaction.model) > session model. When no TUI selection is made, the config-based approach works exactly as before. Nothing is broken.

Features:

  • Reuses existing provider infrastructure — same providers, API keys, and auth as the primary model picker
  • /compaction-models slash command and "Switch compaction model" in the command menu
  • Model resolution priority: compaction model override > agent config > session model
  • Compaction model preference stored via kv.signal in kv.json, matching how all other TUI settings are persisted
  • Prompt footer displays active compaction model when set
  • When unset, behavior is identical to upstream

Changes:

  • DialogModel accepts target="compaction" prop — no duplicate component
  • SessionCompaction.process() accepts and resolves the override model
  • CompactionPart schema extended with optional compactionModel field
  • compaction_model_list keybind added (default: none)
  • SDK regenerated via ./script/generate.ts

How did you verify your code works?

Tested with Claude Sonnet 4.5 (chat) + GPT-5.3 Codex (compaction). Confirmed correct model at each pipeline stage via [compaction-model] log entries. Compaction completed successfully, session resumed on the original model. Also tested auto-compaction with no override set to verify identical upstream behavior. Verified that existing agent.compaction.model config continues to work when no TUI override is set.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

image
image
image

Allow users to select a different LLM model for compaction at runtime
via TUI, independent of the session model. Enables using cheaper or
specialized models for context summarization without changing the
primary chat model.

Model resolution priority:
  TUI compaction model override > agent config > session model

TUI:
  app.tsx             - register command + slash /compaction-models
  dialog-model.tsx    - target prop; compaction mode shows session
                        model default option
  context/local.tsx   - kv.signal('compaction_model') state
  prompt/index.tsx    - compact model indicator in prompt footer

Server:
  routes/session.ts   - summarize route accepts compactionModel
  message-v2.ts       - CompactionPart gains compactionModel field
  compaction.ts       - 3-tier model resolution in process()
  prompt.ts           - passes compactionModel through to process()

Config:
  config.ts           - compaction_model_list keybind

SDK:
  types.gen.ts, sdk.gen.ts, openapi.json - regenerated
@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

Based on my search, I found related PRs but no duplicate PRs. The PR #14665 is unique in its focus on adding runtime compaction model switching.

The related PRs found are addressing different aspects of the compaction system:

These are complementary changes, not duplicates of PR #14665.

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

Projects

None yet

1 participant