Skip to content

The agent that grows with you

fix(desktop): app quit no longer drops terminal tabs from the restored layout

Teknium985be7a3894b
diff --git a/apps/desktop/electron/terminal-gateway-owner.test.ts b/apps/desktop/electron/terminal-gateway-owner.test.ts
index 4efa10efa4f..21a7db46fb0 100644
--- a/apps/desktop/electron/terminal-gateway-owner.test.ts
+++ b/apps/desktop/electron/terminal-gateway-owner.test.ts
@@ -140,3 +140,16 @@ test('an SSH teardown leaves the tab disconnected instead of closing it', async
[{ code: null, signal: 'disconnected' }]
)
})
+
+test('app quit kills shells without telling the tabs they exited', async () => {
+ const { api, start } = register(null)
+ const local = await spawnFor(start, { connectionId: 'local' })
+ const attach = handles.map.get('hermes:terminal:attach') as (event: unknown, id: string) => boolean
+
+ assert.equal(attach({ sender: local.sender }, local.session.id), true)
+ api.disposeAllTerminalSessions()
+
+ // An exit here would close the tab and drop it from the restored layout.
+ assert.equal(local.fake.pty.kill.mock.calls.length >= 1, true)
+ assert.equal(local.sender.send.mock.calls.filter(([channel]) => String(channel).endsWith(':exit')).length, 0)
+})
diff --git a/apps/desktop/electron/terminal-ipc.ts b/apps/desktop/electron/terminal-ipc.ts
index 7736f8196af..bcf2478703e 100644
--- a/apps/desktop/electron/terminal-ipc.ts
+++ b/apps/desktop/electron/terminal-ipc.ts
@@ -282,7 +282,8 @@ export function registerTerminalIpc({
// App shutdown: kill every open PTY before environment teardown.
function disposeAllTerminalSessions() {
- for (const id of [...terminalSessions.keys()]) {
+ for (const [id, info] of [...terminalSessions.entries()]) {
+ info.outputGate.silence()
disposeTerminalSession(id)
}
}
diff --git a/apps/desktop/electron/terminal-output-gate.ts b/apps/desktop/electron/terminal-output-gate.ts
index eb81a0f62be..ca28087828b 100644
--- a/apps/desktop/electron/terminal-output-gate.ts
+++ b/apps/desktop/electron/terminal-output-gate.ts
@@ -50,6 +50,12 @@ export function createTerminalOutputGate({ onExitFlushed, sendData, sendExit }:
pendingData = `${pendingData}${chunk}`.slice(-MAX_PENDING_OUTPUT)
},
+ /** App quit: the renderer must not read the kill as the shell exiting,
+ * or it closes the tab and drops it from the restored layout. */
+ silence(): void {
+ exited = true
+ pendingExit = null
+ },
exit(payload: TerminalExitPayload): void {
// The first exit is the verdict: a teardown's `disconnected` must not be
// overwritten by the kill's own exit that follows it.