Repository navigation
Description
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.selectupdatesattached.selectionand then callsswitchModel(sessions.ts#L183-L191).- The
session.model.selectedevent for an earlier switch arrives throughentry.selected(sessions.ts#L60-L66) and is folded bychanged, which overwritesattached.selectionwith that older model (sessions.ts#L81-L90). - If that lands before
setSessionConfigOptionreads 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
- Have several models configured (any providers).
- Save the script below as
acp-switch-probe.mjsand runnode acp-switch-probe.mjs 3in a project directory. It opens oneopencode acpsession and switches through every model 3 times, waiting for each reply before sending the next request. - It prints each reply whose model
currentValuediffers 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
opencodejr commentedon Nov 2, 2026
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.selectedecho of the previous switch overwrites the selection thatselectjust wrote, so theset_config_optionreply 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:
set_config_optionreply carries the previous model'scurrentValueand options because of a late echo.The bot will close this issue as a duplicate in 1 day unless you reply explaining how your problem is different.
dimiboi commentedon Nov 2, 2026
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.
mahammedmahieousman commentedon Nov 2, 2026
opencodejr commentedon Nov 3, 2026
Closing this as a duplicate of #60316, since no reply explained how this one differs. Both describe the same race: a late
session.model.selectedecho from the previous switch overwrites the new selection, so thesession/set_config_optionreply 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.