Skip to content

Commit 62ffa79

Browse files
author
Eric Wheeler
committed
fix: prevent spurious onDidEndTerminalShellExecution from breaking terminal output
Add explicit checks and error logging to handle problematic event sequence: 0. terminal.running=false 1. terminal.shellIntegration.executeCommand(command) 2. onDidEndTerminalShellExecution // from unexpected 'OSC 633 D' sequence 3. onDidStartTerminalShellExecution 4. stream begins 5. onDidEndTerminalShellExecution The first onDidEndTerminalShellExecution (from unexpected OSC 633 D) is ignored because terminal.running is false, preventing process=undefined from being set prematurely. After the stream begins and sets terminal.running to true, the second onDidEndTerminalShellExecution proceeds normally. Signed-off-by: Eric Wheeler <[email protected]>
1 parent e3adee4 commit 62ffa79

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

src/integrations/terminal/TerminalRegistry.ts

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,42 @@ export class TerminalRegistry {
4343
async (e: vscode.TerminalShellExecutionEndEvent) => {
4444
const terminalInfo = this.getTerminalByVSCETerminal(e.terminal)
4545
const process = terminalInfo?.process
46-
const exitDetails = process
47-
? TerminalProcess.interpretExitCode(e?.exitCode)
48-
: { exitCode: e?.exitCode }
46+
47+
if (!terminalInfo) {
48+
console.error("[TerminalRegistry] Shell execution ended but terminal not found:", {
49+
exitCode: e?.exitCode,
50+
})
51+
return
52+
}
53+
54+
if (!terminalInfo.running) {
55+
console.error(
56+
"[TerminalRegistry] Shell execution end event received, but process is not running for terminal:",
57+
{
58+
terminalId: terminalInfo?.id,
59+
command: process?.command,
60+
exitCode: e?.exitCode,
61+
},
62+
)
63+
return
64+
}
65+
66+
if (!process) {
67+
console.error(
68+
"[TerminalRegistry] Shell execution end event received on running terminal, but process is undefined:",
69+
{
70+
terminalId: terminalInfo.id,
71+
exitCode: e?.exitCode,
72+
},
73+
)
74+
return
75+
}
76+
77+
const exitDetails = TerminalProcess.interpretExitCode(e?.exitCode)
4978
console.info("[TerminalRegistry] Shell execution ended:", {
5079
...exitDetails,
80+
terminalId: terminalInfo.id,
81+
command: process?.command ?? "<unknown>",
5182
})
5283

5384
// Signal completion to any waiting processes

0 commit comments

Comments
 (0)