Skip to content

Commit 97ad8c3

Browse files
nikomatsakisClaude
andcommitted
fix(vscode): route approval requests to correct tab by agentId
Previously approval requests were always sent to the first tab, which broke multi-tab scenarios. Now looks up the tab whose config matches the requesting agent's agentId. Co-authored-by: Claude <[email protected]>
1 parent 726ef1d commit 97ad8c3

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

vscode-extension/src/chatViewProvider.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -868,11 +868,17 @@ export class ChatViewProvider implements vscode.WebviewViewProvider {
868868
// Generate unique approval ID
869869
const approvalId = uuidv4();
870870

871-
// Find the tab for this session (we don't have sessionId in params, so we'll send to all tabs)
872-
// For now, we'll use the first tab - TODO: improve this to target the right tab
873-
const tabIds = Array.from(this.#tabToAgentSession.keys());
874-
if (tabIds.length === 0) {
875-
logger.error("approval", "No tabs available for approval request");
871+
// Find the tab for this agent by looking up which tab has a config with matching agentId
872+
let tabId: string | undefined;
873+
for (const [tid, config] of this.#tabToConfig.entries()) {
874+
if (config.agentId === agentId) {
875+
tabId = tid;
876+
break;
877+
}
878+
}
879+
880+
if (!tabId) {
881+
logger.error("approval", "No tab found for agent", { agentId });
876882
// Fallback: deny
877883
const rejectOption = params.options.find(
878884
(opt) => opt.kind === "reject_once",
@@ -885,8 +891,6 @@ export class ChatViewProvider implements vscode.WebviewViewProvider {
885891
return { outcome: { outcome: "cancelled" } };
886892
}
887893

888-
const tabId = tabIds[0]; // Use first tab for now
889-
890894
logger.debug("approval", "Requesting user approval", {
891895
approvalId,
892896
tabId,

0 commit comments

Comments
 (0)