Skip to content

Bug: REST API session model ignored when loading session via ACP #27645

Closed as not planned

Description

@oudeis01

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 dev branch as of 2026-05-15, commit f179dcb)
  • OS: Linux

Related

Activity

  1. github-actions commented on May 15, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    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.

  2. github-actions commented on Jul 14, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions