Repository navigation
fix(opencode): sync v2 session option state and apply live agent switches - #1186
Merged
catatafishen merged 1 commit intoOct 17, 2026
Conversation
…ches OpenCode v2 pushes no config_option_update notifications: the full updated configOptions array is returned only as the session/set_config_option response echo, and the plugin discarded it everywhere. Session option state therefore went stale for the whole session: switching the model (which resets the per-model effort to its default) left the Effort tick on the pre-switch value, and agent switches were silent no-ops because the Agent menu restarts the process expecting buildCommand to forward the selection, while v2 removed session/set_model and session/new silently ignores agent params, so every session kept running build. - AcpClient.setConfigOption applies the echoed configOptions array to the local option state via a shared applyConfigOptionEcho hook; rejected options (-32602) complete exceptionally and leave state untouched. - OpenCodeClient.sendSetModel's v2 branch, which routes model changes through session/set_config_option, attaches the same hook so model-switch cross-effects are captured too. - The gear menu tick-marks the agent-reported live value (new SessionOption.effectiveValue) with the stored pick as pre-session fallback, instead of preferring the stale stored selection. - New AbstractClient.canSwitchAgentLive(slug): OpenCode v2 exposes its session modes (build, plan, and custom project agents registered as mode values) as the mode config option, and session/set_config_option(mode) switches the live session. The menu applies switchable slugs live via setCurrentAgentSlug, persists them for future sessions and applies them on session creation; other agents keep the process-restart flow and v1 keeps the legacy behavior.
BambinoSK
requested a deployment
to
fuzzing-gate
October 15, 2026 17:07 — with
GitHub Actions
Waiting
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
catatafishen
approved these changes
Oct 17, 2026
This branch is waiting to be deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1185.
Problem
OpenCode v2 pushes no
config_option_updatenotifications: the full updatedconfigOptionsarray is returned only as thesession/set_config_optionresponse echo, and the plugin discarded it everywhere. Session option state therefore went stale for the whole session (the Effort tick kept the pre-switch value after a model change reset the per-model effort), and agent switches were silent no-ops: the menu restarts the process expectingbuildCommandto forward the selection, butOpenCodeClientnever passes an agent flag, v2 removedsession/set_model, andsession/newsilently ignoresagent/modeIdparams, so every session kept runningbuild. Wire evidence and step-by-step repros are in the issue.What this PR does
set_config_optionecho to local option state. New sharedAcpClient.applyConfigOptionEchois attached to the request future insetConfigOption; the echoed array (including cross-effects such as effort resetting on a model switch) is merged through the same path asconfig_option_updatenotifications. Rejected options (-32602) complete exceptionally and leave state untouched.OpenCodeClient.sendSetModel's v2 branch, which routes model changes throughsession/set_config_option(v2 removedsession/set_model), attaches the same hook. ThewhenCompleteruns before the blocking wait, so a late echo still applies after a timeout.SessionOption.effectiveValue: the agent-reported live value wins, the locally stored pick is only the pre-session fallback, so the menu no longer keeps stale selections after agent-side resets.AbstractClient.canSwitchAgentLive(slug). OpenCode v2 advertises its session modes (build,plan, plus custom agents from.opencode/agents/) as themodeconfig option's values, andsession/set_config_option(mode)switches the live session, soOpenCodeClientoverridesonAgentSlugChanged(live push) andonSessionCreated(deferred push of a selection stored before the session existed), guarded by the advertised values so invalid slugs are never sent and redundant switches are suppressed. The menu applies switchable slugs without a process restart, persists them for future sessions, and shows a status banner; non-switchable agents keep the restart flow and v1 keeps the legacy behavior.Notes for reviewers
configOptionskey or push notifications instead (same merge path, idempotent replace by id); agents whose options are static (no liveinitialValue) keep the stored-pick behavior in the menu.AcpClientEchoGuardTestpins these guards.onAgentSlugChanged/onSessionCreatedextension points and the deferred-then-applied selection flow follow the existing Kiro v3 pattern.AcpClientEchoGuardTest,OpenCodeClientModelEchoTest,OpenCodeClientAgentSwitchTest,SessionOptionEffectiveValueTest.Verification
:plugin-core:testgreen on this branch forAcpClientEchoGuardTest,OpenCodeClientModelEchoTest,OpenCodeClientAgentSwitchTest,SessionOptionEffectiveValueTest,OpenCodeClientBehaviorTest,OpenCodeClientModelRoutingTest,AcpClientProtocolTest.build/planswitches apply to the running session (the agent's self-reported mode changes in-session, same session id, no restart); a persisted selection is applied when a new session starts; a custom agent in.opencode/agents/is listed, live-switchable, and runs with its own system prompt.How to verify the interactive behavior