fix(am): terminal button showing "Session not found" for remote sessions in Agent Manager #5208
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 pressing the terminal button on resumed sessions in the Agent Manager, users always see "Session not found" error.
Root Cause
The
SessionTerminalManager.showTerminal()method was checking if the session exists inAgentRegistry, but remote sessions (from cloud history) are only stored in the webview's Jotai state, not in the backend registry.Solution
Modified
showTerminal()to handle remote-only sessions gracefully:showOrCreateTerminal()helper method for code reuseChanges
src/core/kilocode/agent-manager/SessionTerminalManager.ts- Handle remote-only sessionssrc/core/kilocode/agent-manager/__tests__/SessionTerminalManager.spec.ts- Updated testsNotes
For remote worktree sessions, the terminal will open in the workspace folder (not the worktree) because the worktree path info is only available in the registry after the session is resumed. This is a reasonable fallback that can be improved later when worktree resumption is fixed.