From 9279cc359ca53993fc828fcc2898985e75cf126f Mon Sep 17 00:00:00 2001 From: Brennan Benson <79079362+brennanb2025@users.noreply.github.com> Date: Tue, 10 Nov 2026 01:28:37 -0800 Subject: [PATCH] Keep buffered terminal retirement within delivery modules --- .../reattach/reattach-result-handler.ts | 9 +++------ .../pty-transport/delivery/pty-dispatcher.ts | 20 ++++++------------- .../pty-transport/delivery/pty-notice-exit.ts | 15 ++++++++++++++ 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/renderer/src/components/terminal-pane/pty-connection/reattach/reattach-result-handler.ts b/src/renderer/src/components/terminal-pane/pty-connection/reattach/reattach-result-handler.ts index 7d67c22ecb2..d31382d2da5 100644 --- a/src/renderer/src/components/terminal-pane/pty-connection/reattach/reattach-result-handler.ts +++ b/src/renderer/src/components/terminal-pane/pty-connection/reattach/reattach-result-handler.ts @@ -15,10 +15,7 @@ import { shouldIgnoreStalePanePtyLayoutBinding } from './pane-pty-layout-binding import { hasEmptyReattachRetireEvidence } from './empty-reattach-retire-evidence' import { mainStartsPane } from '../spawn/main-starts-pane' -import { - acceptMainPaneResumeStart, - showMainPaneResumeOutcome -} from '../spawn/main-pane-resume-banner' +import * as mainPaneResume from '../spawn/main-pane-resume-banner' import type { ColdRestoreAgentResumeStartup } from '../startup/fresh-spawn-types' import type { ConnectPanePtySession } from '../connect-pane-pty-session' @@ -326,8 +323,8 @@ export function bindHandleReattachResult(sessionBag: ConnectPanePtySession): voi session.warnParkRevealNoHostImage(ptyId, noHostImageReason) } session.scheduleReattachIdleAgentCursorReset() - acceptMainPaneResumeStart(sessionBag, ptyId) - showMainPaneResumeOutcome(sessionBag, ptyId) + mainPaneResume.acceptMainPaneResumeStart(sessionBag, ptyId) + mainPaneResume.showMainPaneResumeOutcome(sessionBag, ptyId) scheduleRuntimeGraphSync() return true diff --git a/src/renderer/src/components/terminal-pane/pty-transport/delivery/pty-dispatcher.ts b/src/renderer/src/components/terminal-pane/pty-transport/delivery/pty-dispatcher.ts index 163ff7cbd43..9b8c762ed7b 100644 --- a/src/renderer/src/components/terminal-pane/pty-transport/delivery/pty-dispatcher.ts +++ b/src/renderer/src/components/terminal-pane/pty-transport/delivery/pty-dispatcher.ts @@ -1,5 +1,5 @@ import { getTerminalNoticeLifetime } from '../../provider-notices/terminal-notice-lifetime' -import { prepareTerminalNoticeExit } from './pty-notice-exit' +import { captureTerminalNoticeExitHandler } from './pty-notice-exit' import { TERMINAL_SCROLLBACK_SESSION_BUFFER_BYTE_LIMIT } from '../../../../../../shared/terminal/replay/terminal-scrollback-limits' import { clearProcessedPtyCharTotal, @@ -323,22 +323,14 @@ export function registerEagerPtyBuffer( eagerPtyHandles.set(ptyId, handle) drainPreHandlerPtyData(ptyId, dataHandler) - const noticeLifetime = getTerminalNoticeLifetime(ptyId) + const deliverBufferedExit = captureTerminalNoticeExitHandler( + getTerminalNoticeLifetime(ptyId), + exitHandler + ) // Why: defer the pre-handler exit one microtask so the caller receives the returned handle before onExit fires. queueMicrotask(() => { if (ptyExitHandlers.get(ptyId) === exitHandler) { - drainPreHandlerPtyExit( - ptyId, - (code, exitIncarnationId) => { - const finishNotice = prepareTerminalNoticeExit(noticeLifetime, code, exitIncarnationId) - try { - exitHandler(code) - } finally { - finishNotice() - } - }, - incarnationId - ) + drainPreHandlerPtyExit(ptyId, deliverBufferedExit, incarnationId) } else { clearPreHandlerPtyState(ptyId) } diff --git a/src/renderer/src/components/terminal-pane/pty-transport/delivery/pty-notice-exit.ts b/src/renderer/src/components/terminal-pane/pty-transport/delivery/pty-notice-exit.ts index 3ec5ba7b96b..1a51bdba337 100644 --- a/src/renderer/src/components/terminal-pane/pty-transport/delivery/pty-notice-exit.ts +++ b/src/renderer/src/components/terminal-pane/pty-transport/delivery/pty-notice-exit.ts @@ -49,3 +49,18 @@ export function prepareAcceptedTerminalNoticeExit( } return () => retireTerminalNoticeLifetime(lifetime) } + +/** Bind buffered-exit delivery to its original admitted contribution. */ +export function captureTerminalNoticeExitHandler( + lifetime: TerminalNoticeLifetime | undefined, + handler: (code: number) => void +): (code: number, incarnationId?: string) => void { + return (code, incarnationId) => { + const finish = prepareTerminalNoticeExit(lifetime, code, incarnationId) + try { + handler(code) + } finally { + finish() + } + } +}