You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ACP: a failed model or agent switch still changes the selection #59789
When a model or agent switch over ACP fails, the adapter keeps the new value as the current selection anyway. The server is still on the old one, so ACP and the server disagree from then on.
You see it on the next config change. After a failed switch from a model with high effort to one that only has low and medium, setting effort to high fails with effort not found: high, even though the session never left the original model. A failed agent switch does the same thing: the next config response shows the rejected agent as the current mode.
Thanks for the clear report! I reproduced both cases with the ACP wire test fixture, and they still happen on the latest dev (86ce19d).
Model: the first POST /api/session/<id>/model returns 503, and switching to test/second-model fails as it should. Setting effort to high afterwards then fails with -32602Invalid params: effort not found: high, even though the session is still on test/test-model.
Agent: the first POST /api/session/<id>/agent returns 503, and the switch from build to plan fails. The next config response still reports plan as the mode.
The cause appears to be select in packages/cli/src/acp/sessions.ts. It saves the new model or agent as the current selection before asking the server to switch, and it doesn't put the old one back when the request fails. The test below reproduces both cases. The related fix proposal is #59790.
Reproduction script (repro-59789.test.ts)
// Reproduction for anomalyco/opencode#59789. Place in packages/cli/test/acp/ and run:// cd packages/cli && bun test test/acp/repro-59789.test.tsimport{describe,expect,test}from"bun:test"import{currentValue}from"./select-options"import{rpcError,startWire}from"./wire-fixture"functionfailFirst(suffix: string){letfailed=falsereturn(request: {method: string;path: string})=>{if(!failed&&request.method==="POST"&&request.path.endsWith(suffix)){failed=truereturnnewResponse(JSON.stringify({message: "unavailable"}),{status: 503})}returnundefined}}describe("#59789 failed switch keeps selection",()=>{test("failed model switch",async()=>{await using acp=awaitstartWire({fetch: failFirst("/model")})awaitacp.initialize()constsessionId=(awaitacp.newSession()).sessionIdconstset=(configId: string,value: string)=>acp.request("session/set_config_option",{ sessionId, configId, value })console.log("model switch error:",JSON.stringify(awaitrpcError(set("model","test/second-model"))))constresult=awaitset("effort","high").then((r)=>({ok: r}),(e)=>({error: e?.code,message: e?.message}),)console.log("effort=high after failed switch:",JSON.stringify("ok"inresult ? currentValue(result.ok,"model") : result))expect("ok"inresult).toBe(true)})test("failed agent switch",async()=>{await using acp=awaitstartWire({fetch: failFirst("/agent")})awaitacp.initialize()constsessionId=(awaitacp.newSession()).sessionIdconstset=(configId: string,value: string)=>acp.request("session/set_config_option",{ sessionId, configId, value })console.log("mode switch error:",JSON.stringify(awaitrpcError(set("mode","plan"))))constafter=awaitset("effort","high")console.log("mode reported after failed switch:",currentValue(after,"mode"))expect(currentValue(after,"mode")).toBe("build")})})
Activity
opencodejr commentedon Oct 28, 2026
Thanks for the clear report! I reproduced both cases with the ACP wire test fixture, and they still happen on the latest
dev(86ce19d).POST /api/session/<id>/modelreturns 503, and switching totest/second-modelfails as it should. Setting effort tohighafterwards then fails with-32602Invalid params: effort not found: high, even though the session is still ontest/test-model.POST /api/session/<id>/agentreturns 503, and the switch frombuildtoplanfails. The next config response still reportsplanas the mode.The cause appears to be
selectinpackages/cli/src/acp/sessions.ts. It saves the new model or agent as the current selection before asking the server to switch, and it doesn't put the old one back when the request fails. The test below reproduces both cases. The related fix proposal is #59790.Reproduction script (repro-59789.test.ts)
Run it:
bun repro-59789.test.ts