Skip to content

feat(acp): follow model and agent changes from other clients - #52499

Merged
nexxeln merged 2 commits into
v2from
acp-selection-sync
Oct 1, 2026
Merged

nexxeln merged 2 commits into
v2from
acp-selection-sync

Conversation

@nexxeln

@nexxeln nexxeln commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

#35457 | #48759

Why the change

When the TUI, the desktop app, or another ACP connection switches the model or agent of a session that ACP has open, the ACP client's model, effort, and mode pickers now follow the change instead of showing a stale value.

Special things to note

  • One event subscription per ACP connection. It starts before any session attaches, keeps only session.model.selected / session.agent.selected, and hands each event to the attached session it names. Each attached session then runs one fold that applies catalog reloads and selection changes in order, so a reload racing a switch cannot leave stale options on the client. Closing, detaching, or re-attaching a session ends its fold with the session scope.
  • No echo: ACP updates its own selection before it calls switchModel / switchAgent, so the server's echoed event diffs to the same options and nothing is pushed. A comment at the write sites in service.ts records this ordering. Variant rule: the event's model ref replaces the selection as a whole, so a ref without a variant shows the default effort, matching core's switchModel.
  • Remaining gap: a switch made after ACP fetches the session but before the session is attached is not seen. The window is a few local steps and is left as is. This PR covers only the ACP side; the TUI picker sync from [FEATURE]: Session-scoped bidirectional model and agent selection for attached TUI / ACP #48759 is not included, hence Refs.

Change outline

Event routing and the per-session fold:

 make()
+  subscribe once: client.event.subscribe()
+    filter session.model.selected | session.agent.selected
+    sessions.get(event.sessionID)?.selected.offer({ model } | { modeID })

 attach(session)
+  wait for the subscription to connect
   selection = { model: session.model, modeID: session.agent }
-  fold catalog.changes
+  fold merge(catalog.changes, selected queue)
+    selection = { ...selection, ...patch }      # applied before any push
     if configOptions(catalog, selection) changed → push config_option_update
     if catalog commands changed → push available_commands_update

Files:

 packages/cli/
 ├── src/acp/
 │   ├── sessions.ts                 # + connection subscription, one fold per session
 │   └── service.ts                  # + no-echo ordering comment
 └── test/acp/
+    └── selection.test.ts           # external switch, variant, no echo, routing, close/re-attach, catalog race

Refs #48759

@nexxeln
nexxeln merged commit 7e42a89 into v2 Oct 1, 2026
10 checks passed
@nexxeln
nexxeln deleted the acp-selection-sync branch October 1, 2026 13:15
Ichinose-Kazuki pushed a commit to Ichinose-Kazuki/opencode that referenced this pull request Oct 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant