Skip to content

ACP: a failed model or agent switch still changes the selection #59789

Done

Description

@andreivince

Description

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.

Plugins

None

OpenCode version

2.2.0 (dev at 76e1f5b)

Steps to reproduce

Using the ACP wire test fixture in packages/cli/test/acp:

  1. Start a session on test/test-model, which has high effort. test/second-model only has low and medium.
  2. Make the first POST /api/session/<id>/model return a 503.
  3. Switch the model to test/second-model with session/set_config_option. It returns an error, which is right.
  4. Set effort to high. It fails with -32602, effort not found: high.

The agent version: fail a switch from build to plan, then change effort. The response reports plan as the mode.

Expected: a failed switch leaves the selection as it was, and later valid changes keep working.

Screenshot

N/A, protocol only.

Operating System

macOS 26.6.2 (arm64), Bun 1.4.4

Terminal

N/A, not a TUI issue.

Activity

  1. opencodejr commented on Oct 28, 2026

    @opencodejr
    Contributor

    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 -32602 Invalid 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.ts
    import { describe, expect, test } from "bun:test"
    import { currentValue } from "./select-options"
    import { rpcError, startWire } from "./wire-fixture"
    
    function failFirst(suffix: string) {
      let failed = false
      return (request: { method: string; path: string }) => {
        if (!failed && request.method === "POST" && request.path.endsWith(suffix)) {
          failed = true
          return new Response(JSON.stringify({ message: "unavailable" }), { status: 503 })
        }
        return undefined
      }
    }
    
    describe("#59789 failed switch keeps selection", () => {
      test("failed model switch", async () => {
        await using acp = await startWire({ fetch: failFirst("/model") })
        await acp.initialize()
        const sessionId = (await acp.newSession()).sessionId
        const set = (configId: string, value: string) =>
          acp.request("session/set_config_option", { sessionId, configId, value })
    
        console.log("model switch error:", JSON.stringify(await rpcError(set("model", "test/second-model"))))
        const result = await set("effort", "high").then(
          (r) => ({ ok: r }),
          (e) => ({ error: e?.code, message: e?.message }),
        )
        console.log("effort=high after failed switch:", JSON.stringify("ok" in result ? currentValue(result.ok, "model") : result))
        expect("ok" in result).toBe(true)
      })
    
      test("failed agent switch", async () => {
        await using acp = await startWire({ fetch: failFirst("/agent") })
        await acp.initialize()
        const sessionId = (await acp.newSession()).sessionId
        const set = (configId: string, value: string) =>
          acp.request("session/set_config_option", { sessionId, configId, value })
    
        console.log("mode switch error:", JSON.stringify(await rpcError(set("mode", "plan"))))
        const after = await set("effort", "high")
        console.log("mode reported after failed switch:", currentValue(after, "mode"))
        expect(currentValue(after, "mode")).toBe("build")
      })
    })

    Run it: bun repro-59789.test.ts

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