Capture and report Extension Terminal exit code on startup failure#5526
Capture and report Extension Terminal exit code on startup failure#5526JustinGrote merged 1 commit intomainPowerShell/vscode-powershell:mainfrom andyleejordan/investigate-5031-startup-timeoutPowerShell/vscode-powershell:andyleejordan/investigate-5031-startup-timeoutCopy head branch name to clipboard
Conversation
When the PowerShell process exits during startup -- as in #5031, where pwsh terminated ~3 seconds after spawn -- we threw away the terminal's exit status and surfaced a generic "PowerShell Language Server process didn't start!" message. That's unactionable: the logs show a *fast process exit*, not a slow start, and we had no way to know *why* pwsh died. We now capture `terminal.exitStatus` in `onTerminalClose` before disposing the process, expose it via `getExitStatus()`, and include a non-zero exit code in both the log warning and the failure notification ("...exited with code: N before connecting!"). When the code is `undefined` (the user or VS Code closed the terminal, or it simply timed out) we fall back to the original wording. I don't claim this fixes the underlying exit -- that's almost certainly environmental (AV/EDR, profile, module load) -- but it turns an undiagnosable report into a diagnosable one. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
JustinGrote
left a comment
There was a problem hiding this comment.
LGTM, might be useful when submitting logs, IDK.
JustinGrote
left a comment
There was a problem hiding this comment.
@andyleejordan you need to switch this from draft.
|
Ah, this one spawned out of a "Copilot thinks it can fix this bug" until I went and said, no I already fixed that lol but I didn't know we had |
There was a problem hiding this comment.
Pull request overview
This PR improves startup failure diagnostics by capturing and reporting the Extension Terminal's exit code when the PowerShell process terminates before connecting to the LSP client. Previously, users saw only a generic "PowerShell Language Server process didn't start!" message, making it impossible to diagnose the underlying cause. Now, a non-zero exit code is surfaced in both the warning log and the user-facing error message.
Changes:
- Capture the terminal's
exitStatusinonTerminalClosebefore disposal and expose it via agetExitStatus()getter onPowerShellProcess. - Use the captured exit code in
handleFailedProcessto produce a more actionable error message when the exit code is non-zero. - Add a new test file
test/core/process.test.tscovering exit status capture, logging, and the unrelated-terminal guard.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/process.ts |
Adds exitStatus field, getExitStatus() getter, captures exit status in onTerminalClose, and enriches the warning log with the exit code. |
src/session.ts |
Reads the exit code from the process in handleFailedProcess and produces a code-specific error message for non-zero exits. |
test/core/process.test.ts |
New test file verifying exit status is undefined before close, captured/logged on close, and ignored for unrelated terminals. |
| shouldUpdate = false; | ||
| // If the process terminated before connecting, VS Code gives us the | ||
| // terminal's exit code, which is far more actionable than a generic | ||
| // failure. A `undefined` code means it timed out or was closed |
Summary
Improves diagnostics for #5031. When the PowerShell process exits during
startup — as in that report, where pwsh terminated ~3 seconds after spawn — we
discarded the Extension Terminal's exit status and surfaced a generic
"PowerShell Language Server process didn't start!" message. The logs there show
a fast process exit, not a slow start, so neither the 60s version-details
timeout nor the 4-minute session-file wait was ever the culprit, and we had no
way to know why pwsh died.
Changes
src/process.ts: captureterminal.exitStatusinonTerminalClosebefore disposing the process, expose it via a new
getExitStatus()getter,and include the exit code in the warning log.
src/session.ts: inhandleFailedProcess, reportexited with code: N before connecting! Check the PowerShell output for errors.for non-zero codes, falling back to the original"...didn't start!" wording when the code is
undefined(the user/VS Codeclosed the terminal, or it timed out).
test/core/process.test.ts(new): covers no-status-before-close,capture + log on close, and ignoring unrelated terminals' close events.
This does not fix the underlying exit — that's almost certainly environmental
(AV/EDR, profile, module load) — so it intentionally does not auto-close
#5031. It turns an undiagnosable report into a diagnosable one by asking
reporters for the exit code.
Notes
src/session.tsandsrc/process.ts, which overlap PRs Don't prompt to restart Extension Terminal on shutdown (#4101, #4145) #5520and Handle version-details timeout and stalled connects during startup #5523. A rebase may be needed depending on merge order.
npm run compile,npm run lint,npm run formatallclean;
npm test107 passing (was 104), 4 pending. The pre-existingtscTelemetryReportererror insession.tsis unrelated and untouched.Drafted by Copilot (Claude Opus 4.8).