From 66bbe1c443db5dccc27869661000d3003add6843 Mon Sep 17 00:00:00 2001 From: "buf0-bot[bot]" <252831055+buf0-bot[bot]@users.noreply.github.com> Date: Tue, 19 May 2026 12:47:47 -0700 Subject: [PATCH] fix: pr-bug-scan validated finding from #2304 (#2336) Co-authored-by: orca-bug-scan-bot --- .../agent-hook-completion-notifications.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/renderer/src/hooks/agent-hook-completion-notifications.ts b/src/renderer/src/hooks/agent-hook-completion-notifications.ts index dd080d8b4..ce85ead16 100644 --- a/src/renderer/src/hooks/agent-hook-completion-notifications.ts +++ b/src/renderer/src/hooks/agent-hook-completion-notifications.ts @@ -39,7 +39,22 @@ function getPtyIdForPaneKey(paneKey: string): string | null { if (!parsed) { return null } - return useAppStore.getState().ptyIdsByTabId?.[parsed.tabId]?.[0] ?? null + const state = useAppStore.getState() + const tabPtyIds = state.ptyIdsByTabId?.[parsed.tabId] + if (!tabPtyIds || tabPtyIds.length === 0) { + return null + } + // Why: split-pane leaves share one tab-level pty list, so a tab-level lookup + // would return a sibling's pty for an already-closed leaf and let a late + // 'done' hook event fire a spurious notification. Resolve liveness through + // the leaf-keyed binding maintained by syncPanePtyLayoutBinding, which + // deletes the entry when the leaf closes. + const ptyIdsByLeafId = state.terminalLayoutsByTabId?.[parsed.tabId]?.ptyIdsByLeafId + if (ptyIdsByLeafId) { + const leafPtyId = ptyIdsByLeafId[parsed.leafId] + return leafPtyId && tabPtyIds.includes(leafPtyId) ? leafPtyId : null + } + return tabPtyIds[0] ?? null } function paneHasLivePty(paneKey: string): boolean {