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 <roo-code@z.ewheeler.org>
This commit is contained in:
Eric Wheeler 2025-03-10 18:49:16 -07:00
parent e3adee4f15
commit 62ffa7973c

View file

@ -43,11 +43,42 @@ export class TerminalRegistry {
async (e: vscode.TerminalShellExecutionEndEvent) => {
const terminalInfo = this.getTerminalByVSCETerminal(e.terminal)
const process = terminalInfo?.process
const exitDetails = process
? TerminalProcess.interpretExitCode(e?.exitCode)
: { exitCode: e?.exitCode }
if (!terminalInfo) {
console.error("[TerminalRegistry] Shell execution ended but terminal not found:", {
exitCode: e?.exitCode,
})
return
}
if (!terminalInfo.running) {
console.error(
"[TerminalRegistry] Shell execution end event received, but process is not running for terminal:",
{
terminalId: terminalInfo?.id,
command: process?.command,
exitCode: e?.exitCode,
},
)
return
}
if (!process) {
console.error(
"[TerminalRegistry] Shell execution end event received on running terminal, but process is undefined:",
{
terminalId: terminalInfo.id,
exitCode: e?.exitCode,
},
)
return
}
const exitDetails = TerminalProcess.interpretExitCode(e?.exitCode)
console.info("[TerminalRegistry] Shell execution ended:", {
...exitDetails,
terminalId: terminalInfo.id,
command: process?.command ?? "<unknown>",
})
// Signal completion to any waiting processes