fix(agent-manager): restore focus to question options and prompt on session switch - #12795
Conversation
…ession switch - Route keyboard tab switching (Meta+Alt+ArrowLeft/Right) through coordinated focus path - Retry focus across render lifecycle to handle VS Code focus transitions - Focus first enabled question option after question dock mounts - Focus prompt textarea for sessions without pending questions - Preserve focus when terminal, history, or review surfaces are active - Add focusQuestionOption helper with unit tests - Add changeset for patch release Fixes race conditions where keyboard navigation would leave focus on webview body instead of the intended question option or prompt input.
Code Review SummaryStatus: 2 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
SUGGESTION
Files Reviewed (3 files)
Resolved since the previous review: the question effect regained the Incremental review scope: only the three files changed since Fix these issues in Kilo Cloud Previous Review Summaries (2 snapshots, latest commit 61467b8)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit 61467b8)Status: 3 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
SUGGESTION
Files Reviewed (4 files)
Resolved since the previous review: the forced refocus was removed from No new memory or resource leaks: the added Fix these issues in Kilo Cloud Previous review (commit 21cc7b4)Status: 5 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
SUGGESTION
Files Reviewed (5 files)
No new memory/resource leaks found: the added Reviewed by claude-opus-5 · Input: 54 · Output: 15.1K · Cached: 2.1M Review guidance: REVIEW.md from base branch |
…ession switch (Kilo-Org#12795) * fix(agent-manager): restore focus to question options and prompt on session switch - Route keyboard tab switching (Meta+Alt+ArrowLeft/Right) through coordinated focus path - Retry focus across render lifecycle to handle VS Code focus transitions - Focus first enabled question option after question dock mounts - Focus prompt textarea for sessions without pending questions - Preserve focus when terminal, history, or review surfaces are active - Add focusQuestionOption helper with unit tests - Add changeset for patch release Fixes race conditions where keyboard navigation would leave focus on webview body instead of the intended question option or prompt input. * fix(agent-manager): preserve tab and question focus ownership * fix(agent-manager): guard deferred focus during async questions
Problem
When switching between Agent Manager sessions using keyboard shortcuts (Meta+Alt+ArrowLeft/Right), focus would be lost and remain on the webview body instead of being restored to the appropriate UI element:
This made keyboard-only navigation impossible when switching to a session with a question, requiring users to click with the mouse.
Root Causes
Two focus race conditions:
Keyboard tab switching bypassed focus restoration: The
Meta+Alt+ArrowLeft/Rightshortcut usedfocusTab()which changed the active session but did not invoke the focus restoration logic.VS Code focus transition timing: During keyboard command execution,
document.hasFocus()was temporarilyfalse, causing the focus restoration code to return early without scheduling a retry. The previous focused element was removed during the session switch, leaving focus on the webview<body>.Question mount timing: Question UI mounted slightly after the session switch. The prompt input could autofocus while the question was still rendering, and nothing reliably moved focus to the question option once it appeared.
Solution
queueMicrotaskand multiplerequestAnimationFramecalls to handle VS Code focus transitionscreateEffectthat focuses the first enabled question option after the question dock mountsfocusQuestionOptionhelper with unit tests covering enabled/disabled states and inert containersTesting
Verified in isolated VS Code:
All regression tests pass (38 tests across focus and question dock suites).
Files Changed
AgentManagerApp.tsx: AddedrequestChatFocuscoordinator and question mount effectPromptInput.tsx: Skip prompt autofocus when question is presentfocus.ts: NewfocusQuestionOptionhelperagent-manager-focus.test.ts: Unit tests for focus helperfix-agent-manager-focus.md: Changeset for patch release