Repository navigation
Description
Description
Over ACP, a session/set_config_option response can describe the previous selection instead of the one just made.
select in packages/cli/src/acp/sessions.ts writes the new selection into the session's selection Ref and then calls the server's switch; the server's session.model.selected echo is folded back into the same Ref ("Update selection before switching so the echoed event is a no-op"). That holds only while the echo arrives before the next selection. When a client sends its next set_config_option before the previous switch's echo has landed, the echo overwrites the newer selection, and setSessionConfigOption answers from the Ref: the model option's currentValue and the effort options are the previous model's. The newer echo lands a moment later and the Ref is right again, but the response has gone out.
With the script below, eight back-to-back model selections per session: on a 4-vCPU Linux container (2.0.30) 12 of 160 responses named the previous model; pinned to one core with taskset -c 0, 33 of 160. On an M-series Mac a single copy never reproduces (the echo lands within a millisecond), four copies at once reproduce it on v2.2.1: 6 of 480. Every wrong answer was the model selected just before. Same code path at dev head f7b4d509.
A client that makes one selection per session never sees it; one that sets model then effort, or walks the model list, does. #59789 is the failure-side twin of the same Ref-before-switch design.
Plugins
None
OpenCode version
v2.2.1 (npm @opencode/cli, macOS arm64) and 2.0.30 (Linux x64); same code at dev f7b4d50
Steps to reproduce
# acp_echo_repro.py — select models back to back over ACP and compare each
# response's model currentValue with the model just selected.
import json, os, subprocess, sys, tempfile, threading, queue
binary = sys.argv[1] if len(sys.argv) > 1 else "opencode"
models = ["openai/gpt-4o", "openai/gpt-5", "openai/gpt-5-pro", "openai/gpt-5.1",
"openai/gpt-5.2", "openai/gpt-5.5", "openai/gpt-5.6", "openai/gpt-6-astra"]
wrong = total = 0
for run in range(20):
home, cwd = tempfile.mkdtemp(), tempfile.mkdtemp()
env = {"HOME": home, "PATH": os.environ["PATH"], "OPENAI_API_KEY": "x",
"OPENCODE_DISABLE_MODELS_FETCH": "1", "OPENCODE_DISABLE_AUTOUPDATE": "true",
"OPENCODE_CONFIG_CONTENT": json.dumps({"agents": {"title": {"disabled": True}}})}
p = subprocess.Popen([binary, "acp"], cwd=cwd, env=env, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, text=True, bufsize=1)
out = queue.Queue(); threading.Thread(target=lambda: [out.put(l) for l in p.stdout], daemon=True).start()
def call(i, method, params):
p.stdin.write(json.dumps({"jsonrpc": "2.0", "id": i, "method": method, "params": params}) + "\n"); p.stdin.flush()
while True:
try: m = json.loads(out.get(timeout=60))
except json.JSONDecodeError: continue
if m.get("id") == i: return m["result"]
call(1, "initialize", {"protocolVersion": 1, "clientCapabilities": {}, "clientInfo": {"name": "repro", "version": "0"}})
sid = call(2, "session/new", {"cwd": cwd, "mcpServers": []})["sessionId"]
for n, model in enumerate(models, start=3):
r = call(n, "session/set_config_option", {"sessionId": sid, "configId": "model", "value": model})
current = next(o["currentValue"] for o in r["configOptions"] if o["id"] == "model")
total += 1
if current != model:
wrong += 1; print(f"run {run}: selected {model}, response says {current}")
p.terminate()
print(f"{wrong} of {total} responses described a different model than the one just selected")taskset -c 0 python3 acp_echo_repro.py /path/to/opencodeon Linux; on a fast Mac, run four copies at once instead.- Expected:
0 of 160. Observed:33 of 160on one Linux core,6 of 480across four concurrent copies on a Mac, each line naming the model selected just before.
In the ACP wire fixture under packages/cli/test/acp, the same thing should show by delivering the first switch's session.model.selected event after the second set_config_option request.
Screenshot
N/A, protocol only.
Operating System
Linux x64 (Debian-based container, 4 vCPU) and macOS arm64 under contention
Terminal
N/A (ACP over stdio)
Activity
opencodejr commentedon Oct 29, 2026
Thanks for the detailed report. I can confirm this.
On
@opencode/cli2.2.1 (Linux, pinned to one core withtaskset -c 0), I ran a version of your script that takes 8openai/models from the session's own model list. Some of the hard-coded IDs aren't in the bundled catalog. It startsopencode acp, opens a session and sendssession/set_config_optionfor each model back to back. 93 of 160 responses reported the wrongmodelcurrentValue, and each one named the model selected just before.It still happens on the latest
dev(f7b4d50) run from source: 50 of 160 wrong, same pattern. The script below reproduces it.This fits your analysis:
selectwrites the new selection before switching, and a late echo of the previous switch then overwrites it before the response is built. Related: #59789, the failure-side version of the same pattern.Reproduction script (acp_echo_repro.py)
Run it:
python3 acp_echo_repro.pyVaili commentedon Oct 31, 2026
I reproduced the stale
currentValuewith back-to-back selections and I'd like to take it. I'll start with a failing ACP test that sends a secondset_config_optionbefore the first echo lands, then stop a late echo from overwriting a newer selection.dimiboi commentedon Nov 2, 2026
Two more data points from #61302, which I've closed as a duplicate of this:
opencode acpprocess on an M-series Mac when the models are real providers (LM Studio local models plus OpenRouter), not the bundled catalogue: 12 of 70 replies across ten 7-switch sweeps, 1 of 24 in a 3×8 sweep, and 2 of 1092 across 364 models with all plugins and MCP servers removed. Every wrong reply named the model selected just before.Downstream effect: bb's ACP model discovery walks the model list and stores each reply's
thought_leveloption under the requested model, so one model's reasoning levels end up under another (get-bb/bb#6871).