fix: avoid duplicate terminal output accumulation

Optimize terminal output handling to reduce memory pressure by:
- Remove continuous result accumulation during line processing
- Only store the same final output from the "completed" event that came from TerminalProcess

Also:
- Add clear error messages for undefined exit details

Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
This commit is contained in:
Eric Wheeler 2025-03-09 19:10:19 -07:00
parent 5be49e1d15
commit 269ddf9a0e

View file

@ -966,9 +966,7 @@ export class Cline {
const { terminalOutputLineLimit } = (await this.providerRef.deref()?.getState()) ?? {}
let result = ""
process.on("line", (line) => {
result += line
if (!didContinue) {
sendCommandOutput(truncateOutput(line, terminalOutputLineLimit))
} else {
@ -977,10 +975,11 @@ export class Cline {
})
let completed = false
let result: string = ""
let exitDetails: ExitCodeDetails | undefined
process.once("completed", (output?: string) => {
// Use provided output if available, otherwise keep existing result.
result = output || result
result = output ?? ""
completed = true
})
@ -1014,10 +1013,8 @@ export class Cline {
userFeedback.images,
),
]
}
if (completed) {
let exitStatus = "No exit code available"
} else if (completed) {
let exitStatus: string
if (exitDetails !== undefined) {
if (exitDetails.signal) {
exitStatus = `Process terminated by signal ${exitDetails.signal} (${exitDetails.signalName})`
@ -1030,6 +1027,9 @@ export class Cline {
} else {
exitStatus = `Exit code: ${exitDetails.exitCode}`
}
} else {
result += "<VSCE exitDetails == undefined: terminal output and command execution status is unknown.>"
exitStatus = `Exit code: <undefined, notify user>`
}
const workingDirInfo = workingDir ? ` from '${workingDir.toPosix()}'` : ""