Repository navigation
Description
Description
When creating a session via the REST API (POST /session) with a specific model, the model is correctly stored in the database. However, when that session is subsequently loaded (e.g., via POST /session/:id/message or POST /session/:id/prompt_async), the stored model is ignored and replaced with defaultModel().
Root Cause
Two files contribute to this bug:
1. packages/opencode/src/acp/session.ts — load() ignores session data
// Line 46-62
async load(sessionId, cwd, mcpServers, model?) {
const session = await this.sdk.session.get(...) // session.model exists here!
const resolvedModel = model // BUG: ignores session.model, uses only parameter
// ...
}The load() method fetches the full session from DB (which includes session.model), but then ignores it and uses only the model parameter.
2. packages/opencode/src/acp/agent.ts — passes defaultModel() to load()
// Around line 599, 684, 739 in loadSession()
const model = await defaultModel(this.config, directory)
await this.sessionManager.load(sessionId, params.cwd, params.mcpServers, model)loadSession() always resolves the model via defaultModel() and passes it to load(), overriding any model stored in the session.
Impact
This affects any workflow that creates sessions via the REST API with a specific model:
- Third-party MCP servers that create sessions with specific models
- External tools that use the REST API to manage sessions
- Any programmatic session creation where the model should differ from the default
Suggested Fix
In ACPSessionManager.load(), prefer the model stored in the session data over the parameter:
async load(sessionId, cwd, mcpServers, model?) {
const session = await this.sdk.session.get(...)
// Prefer session-stored model, fall back to parameter
const sessionModel = session.model
? { providerID: session.model.providerID, modelID: session.model.id, variant: session.model.variant }
: undefined
const resolvedModel = sessionModel ?? model
// ...
}Additionally, in Agent.loadSession(), pass undefined instead of defaultModel() to load(), so the session's own model is used.
Environment
- opencode version: v1.14.51 (latest
devbranch as of 2026-05-15, commit f179dcb) - OS: Linux
Related
- Feature Request: Retain current model and agent selection when switching sessions #4930 (model persistence across sessions)
- Plugins using noReply seem to cause model to switch to agent default #4475 (model switching with plugins)
Activity
github-actions commentedon May 15, 2026
This issue might be a duplicate of existing issues. Please check:
modelvsvariant/effortin session APIs #24299: Describes the same core symptom — model set viaPOST /sessionis not reliably applied as the session default on subsequent messages, with the same root cause ofdefaultModel()overriding the stored session model.prompt_asyncwithout explicit model fields overrides the session's active model with the default.If your issue is distinct from these (e.g. you've identified a specific code path in
ACPSessionManager.load()that the others don't cover), please clarify the difference. Otherwise, consider adding your findings as a comment on one of the existing issues.github-actions commentedon Jul 14, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.