Skip to content

ACP: session/set_config_option reply can describe the previously selected model #61302

Closed as duplicate

Description

@dimiboi

Description

When an ACP client calls session/set_config_option on the model option several times in a row, the reply sometimes describes the model chosen by the previous call: its model currentValue and its thought_level option belong to that earlier model. The session still ends up on the requested model; only the reply is stale. A client that reads per-model settings from these replies (for example bb's ACP model discovery) records one model's reasoning levels under another.

Likely cause, from reading v2.2.5:

  • ACPSessions.select updates attached.selection and then calls switchModel (sessions.ts#L183-L191).
  • The session.model.selected event for an earlier switch arrives through entry.selected (sessions.ts#L60-L66) and is folded by changed, which overwrites attached.selection with that older model (sessions.ts#L81-L90).
  • If that lands before setSessionConfigOption reads the selection for its reply (service.ts#L226-L232), the reply is built from the older model.

The comment "Update selection before switching so the echoed event is a no-op" holds for the echo of the same switch, but not for a late echo of the previous one.

Plugins

Reproduces with none: global plugins and MCP servers removed through a temporary XDG_CONFIG_HOME. Also reproduces with the usual config (@dietrichgebert/ponytail, a local model-shortlist plugin, @upstash/context7-opencode).

OpenCode version

2.2.5. The code is unchanged on dev at 1bf08ae.

Steps to reproduce

  1. Have several models configured (any providers).
  2. Save the script below as acp-switch-probe.mjs and run node acp-switch-probe.mjs 3 in a project directory. It opens one opencode acp session and switches through every model 3 times, waiting for each reply before sending the next request.
  3. It prints each reply whose model currentValue differs from the requested value.

Actual output (8 models, usual config):

requested lmstudio/recursivesi/flint -> reply currentValue lmstudio/prism-ml/bonsai-27b
1 of 24 set_config_option replies described a different model (8 models)

With plugins and MCP removed (364 models): 2 of 1092 replies. In ten earlier sweeps through the same 8 models, 7 had at least one stale reply (12 of 70). In every case I could check, the stale reply named the model requested just before.

Expected: each reply describes the model just set, with currentValue equal to the requested value and that model's own thought_level option.

acp-switch-probe.mjs
// Switch an `opencode acp` session through every model several times and
// report replies whose model currentValue is not the model just requested.
import { spawn } from 'node:child_process';
import { createInterface } from 'node:readline';
const rounds = Number(process.argv[2] ?? 3);
const child = spawn('opencode', ['acp'], { stdio: ['pipe', 'pipe', 'ignore'] });
const pending = new Map(); let next = 0;
createInterface({ input: child.stdout }).on('line', line => {
  let msg; try { msg = JSON.parse(line); } catch { return; }
  if (pending.has(msg.id)) { pending.get(msg.id)(msg); pending.delete(msg.id); }
});
const rpc = (method, params) => new Promise(resolve => {
  const id = ++next; pending.set(id, resolve);
  child.stdin.write(JSON.stringify({ jsonrpc: '2.0', id, method, params }) + '\n');
});
const modelOf = options => options?.find(o => o.category === 'model');
await rpc('initialize', { protocolVersion: 1, clientCapabilities: {} });
const { result: session } = await rpc('session/new', { cwd: process.cwd(), mcpServers: [] });
const option = modelOf(session.configOptions);
const values = option.options.map(o => o.value);
let calls = 0, stale = 0;
for (let r = 0; r < rounds; r++) {
  for (const value of values) {
    const { result, error } = await rpc('session/set_config_option',
      { sessionId: session.sessionId, configId: option.id, value });
    calls++;
    const current = modelOf(result?.configOptions)?.currentValue;
    if (error || current !== value) { stale++; console.log(`requested ${value} -> reply currentValue ${current}${error ? ` (error ${error.message})` : ''}`); }
  }
}
console.log(`${stale} of ${calls} set_config_option replies described a different model (${values.length} models)`);
child.kill();

Operating System

macOS 26.6.1, Node 26.13.0

Terminal

Not applicable: ACP over stdio, driven by the script above.

Found while debugging bb's ACP model discovery. Investigated and filed with the help of an AI agent; the outputs above are from real runs.

Activity

  1. opencodejr commented on Nov 2, 2026

    @opencodejr
    Contributor

    Thanks for the thorough report and the probe script! I think this is a duplicate of #60316. It describes the same race: a late session.model.selected echo of the previous switch overwrites the selection that select just wrote, so the set_config_option reply describes the model selected just before. It has already been reproduced, and a contributor has offered to work on it.

    Possible duplicates and related issues, ordered by likelihood:

    The bot will close this issue as a duplicate in 1 day unless you reply explaining how your problem is different.

  2. dimiboi commented on Nov 2, 2026

    @dimiboi
    Author

    Duplicate of #60316, which describes the same race and is already reproduced. I've added the 2.2.5 and single-process macOS data points there.

  3. mahammedmahieousman commented on Nov 2, 2026

    @mahammedmahieousman
  4. opencodejr commented on Nov 3, 2026

    @opencodejr
    Contributor

    Closing this as a duplicate of #60316, since no reply explained how this one differs. Both describe the same race: a late session.model.selected echo from the previous switch overwrites the new selection, so the session/set_config_option reply describes the previously selected model. #60316 has already been reproduced and a contributor has offered to work on it, so please follow that issue for progress. Thanks again for the detailed analysis and the probe script. If you find something it doesn't cover, feel free to comment there or open a new issue.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions