fix(vscode): sync mode picker with agent mode changes from backend#8426
Merged
Conversation
When the agent switched modes automatically (e.g. plan → code via plan follow-up), the VS Code mode picker stayed stuck on the previous value. The root cause was that agentSelections was only written on explicit user picker actions, not updated from incoming message events. - Add resolveSessionAgent() helper that derives the active agent from the latest valid user message, ignoring assistant messages and unknown agent names - Wire handleMessagesLoaded() to reconcile agentSelections from history so the picker is correct when reopening or switching sessions - Wire handleMessageCreated() to update agentSelections whenever a user message arrives with a changed agent field (covers live plan→code, shell commands, command execution, and synthetic mode-switch messages) - Add mode?: string to QuestionOption so the VS Code webview preserves the same question option metadata the backend and shared app already support - Wire QuestionDock.pick() to call session.selectAgent() immediately when a predefined single-choice option carries a mode field, giving instant feedback before the next user message arrives
05569ee to
fc014b1
Compare
Contributor
Code Review SummaryStatus: 3 Issues Found | Recommendation: Address before merge Overview
Fix these issues in Kilo Cloud Issue Details (click to expand)WARNING
Other Observations (not in diff)No additional observations outside the diff. Files Reviewed (9 files)
Reviewed by gpt-5.4-20260305 · 603,405 tokens |
lambertjosh
approved these changes
Apr 6, 2026
This was referenced Apr 9, 2026
jliounis
pushed a commit
to jliounis/kilocode
that referenced
this pull request
May 18, 2026
…-sync fix(vscode): sync mode picker with agent mode changes from backend
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.
Problem
When the agent switched modes automatically — for example from
plantocodeafter a plan follow-up — the VS Code mode picker stayed stuck on the old value (e.g.ask). This was confusing because the agent was already operating in a different mode while the UI still showed the previous one.The root cause:
agentSelectionsin the session store was only written on explicit user picker actions. It was never updated from incoming backend message events.What this PR fixes
Demo
Screen.Recording.2026-04-06.at.12.02.59.PM.mp4
Every backend agent/mode change manifests as a user message with the
agentfield set, followed by amessage.updatedSSE event. The fix intercepts those messages in two places to keep the picker in sync.createUserMessage()setsagenton user msg →message.updatedSSEhandleMessageCreatedPlanFollowup.inject()writes synthetic user msg withagent: "code"→ SSEhandleMessageCreatedPlanFollowup.inject()writes synthetic user msg withagent: "plan"→ SSEhandleMessageCreatedshell()creates user msg withagent: input.agent→ SSEhandleMessageCreatedcommand()→createUserMessage()with resolved agent → SSEhandleMessageCreatedloadMessages→ history batch loadhandleMessagesLoadedmodefield clickedQuestionDock.pick()detectsoption.modeselectAgent()Changes
session-agent.ts— new pure helperresolveSessionAgent(messages, names)that finds the latest valid user-message agent from a message list, ignoring assistant messages and unrecognized namessession.tsx—handleMessagesLoadednow callsresolveSessionAgentand writes result toagentSelections;handleMessageCreatedupdatesagentSelectionswhen a user message with a changedagentarrivestypes/messages.ts— addedmode?: stringtoQuestionOptionso the VS Code webview preserves the same question option metadata the backend and shared app already supportquestion-dock-utils.ts— newresolveQuestionMode(options, answer)helperQuestionDock.tsx— callssession.selectAgent(mode)on pick when the selected option carries amode, giving instant feedback before the next user message arrivesTests
packages/kilo-vscode/tests/unit/session-agent.test.ts— 5 unit tests for the reconciliation helperpackages/kilo-vscode/tests/unit/question-dock-utils.test.ts— 3 new cases forresolveQuestionModepackages/kilo-vscode/tests/unit/kilo-provider-utils.test.ts— extended question.asked test to assertoption.modesurvives SSE mapping