diff --git a/src/main/daemon/daemon-pty-adapter-wsl-distro-loss.test.ts b/src/main/daemon/daemon-pty-adapter-wsl-distro-loss.test.ts index 270c8978a26..1f452f03177 100644 --- a/src/main/daemon/daemon-pty-adapter-wsl-distro-loss.test.ts +++ b/src/main/daemon/daemon-pty-adapter-wsl-distro-loss.test.ts @@ -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() diff --git a/src/main/daemon/daemon-pty-adapter.ts b/src/main/daemon/daemon-pty-adapter.ts index dad2fed546d..273b10d1867 100644 --- a/src/main/daemon/daemon-pty-adapter.ts +++ b/src/main/daemon/daemon-pty-adapter.ts @@ -250,11 +250,18 @@ export class DaemonPtyAdapter extends DaemonPtyDaemonRecovery implements IPtyPro wslDistro: string, exitAt: number ): Promise { - 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)` )