perf(terminal): a clean WSL bridge exit skips the boot-id read (#35138)

On awin a wsl --terminate exited each bridge pane with -1, while exit and exit 0 gave 0, so a
terminate never yields 0. A clean exit keeps today's verdict without the extra wsl.exe spawn.

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Neil
2026-10-28 07:10:03 -07:00
committed by GitHub
co-authored by Claude
parent f5ee5b4984
commit 2a3fc8372b
2 changed files with 25 additions and 3 deletions
@@ -168,6 +168,21 @@ describe('a WSL bridge pane exit', () => {
expect(exits[1]).not.toHaveProperty('hostLost')
})
// awin: a terminate exited each bridge pane with -1, never 0; a user's `exit` gives 0.
it('reads no boot id for a clean exit, which stays an exit even across a reboot', async () => {
bootIds = ['boot-1', 'boot-2']
const exits = collectExits()
const id = await spawnBridgePane()
await waitFor(() => readBootId.mock.calls.length === 1)
subprocesses[0]!._simulateExit(0)
await waitFor(() => exits.length > 0)
expect(exits[0]).toMatchObject({ id, code: 0 })
expect(exits[0]).not.toHaveProperty('hostLost')
expect(readBootId).toHaveBeenCalledOnce()
})
it('stays a normal exit when the running list cannot answer', async () => {
running = async () => ({ status: 'unavailable' })
const exits = collectExits()
+10 -3
View File
@@ -250,11 +250,18 @@ export class DaemonPtyAdapter extends DaemonPtyDaemonRecovery implements IPtyPro
wslDistro: string,
exitAt: number
): Promise<void> {
const verdict = await classifyWslBridgeExit(wslDistro, exitAt, this.readRunningWslDistros, () =>
this.wslBridgeBootIdentity.rebootedSinceSpawn(sessionId, wslDistro)
// A terminate never exits 0 (awin: -1 for each bridge pane; `exit`/`exit 0` gave 0), so a clean
// exit skips the boot-id read and stays an exit.
const verdict = await classifyWslBridgeExit(
wslDistro,
exitAt,
this.readRunningWslDistros,
async () =>
exit.code !== 0 &&
(await this.wslBridgeBootIdentity.rebootedSinceSpawn(sessionId, wslDistro))
)
// Lost, or booted again since the spawn, keeps the tab; an unanswered check reads as an exit.
// The code lets a verify run show which codes a terminate yields (only 1 is on record).
// The code shows a verify run which codes a terminate yields.
console.info(
`[pty] WSL bridge exit: ${verdict} (distro ${wslDistro}, code ${exit.code}, probe ${Math.round(performance.now() - exitAt)}ms)`
)