From c19d708ecb74155755f7431161efa9c21a270bd5 Mon Sep 17 00:00:00 2001 From: Brennan Benson <79079362+brennanb2025@users.noreply.github.com> Date: Sat, 31 Oct 2026 14:32:44 -0700 Subject: [PATCH] Keep the terminal when its agent's status is only restored from before a restart Continue in Chat UI closes the terminal only while its agent is confirmed running there; a status row carried over a restart, with no live update since, now takes the keep-the-terminal path. --- .../tab-bar/cli-chat-resume-run.test.ts | 28 +++++++++++-------- .../components/tab-bar/cli-chat-resume-run.ts | 8 ++++-- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/renderer/src/components/tab-bar/cli-chat-resume-run.test.ts b/src/renderer/src/components/tab-bar/cli-chat-resume-run.test.ts index 683017641c4..86f592929a2 100644 --- a/src/renderer/src/components/tab-bar/cli-chat-resume-run.test.ts +++ b/src/renderer/src/components/tab-bar/cli-chat-resume-run.test.ts @@ -634,9 +634,9 @@ const row = (paneKey: string, extra: Record = {}) => ({ ...extra }) // The clicked pane still shows its agent on this conversation, so continuing stops it. -const showAgentInSource = () => +const showAgentInSource = (extra: Record = {}) => useAppStore.setState({ - agentStatusByPaneKey: { [SOURCE.paneKey]: row(SOURCE.paneKey, { tabId: 'tab-1' }) } + agentStatusByPaneKey: { [SOURCE.paneKey]: row(SOURCE.paneKey, { tabId: 'tab-1', ...extra }) } }) describe('close terminal then continue on capable hosts', () => { @@ -757,25 +757,26 @@ describe('close terminal then continue on capable hosts', () => { }) // The same host refusal on an older host (terminal kept, CLI source sent) and a capable one (closed first). -// A capable host whose pane agent already quit keeps the terminal, exactly as an older host does. +// A capable host whose pane agent already quit, or only has a row restored from before a +// restart, keeps the terminal exactly as an older host does. describe.each([ - { host: 'an older host', closeCapable: false, live: false }, - { host: 'a capable host, agent already quit', closeCapable: true, live: false }, + { host: 'an older host', closeCapable: false }, + { host: 'a capable host, agent already quit', closeCapable: true }, + { host: 'a capable host, agent unconfirmed since restart', closeCapable: true, restored: true }, { host: 'a capable host, agent running', closeCapable: true, live: true } -])('the same create outcome on $host', ({ closeCapable, live }) => { +])('the same create outcome on $host', ({ closeCapable, live, restored }) => { const closes = closeCapable && live beforeEach(() => { mocks.closeCapability.mockResolvedValue(closeCapable) - if (live) { - showAgentInSource() + if (live || restored) { + showAgentInSource({ restoredUnconfirmed: restored }) } }) - const owner = { sessionId: 'owner-chat', workspaceId: 'owner-workspace' } it.each([ { name: 'it opens', refusal: null, older: null, capable: null, opens: true }, { name: 'a chat owns it', - refusal: held(owner), + refusal: held({ sessionId: 'owner-chat', workspaceId: 'owner-workspace' }), older: null, capable: null, activates: true @@ -785,6 +786,9 @@ describe.each([ refusal: held(), older: 'Claude is running this conversation in another terminal. Quit it there or close that terminal, then try again.', + // The kept terminal's own row names the conversation, so the older copy points here. + restoredOlder: + 'Claude is still running this conversation in this terminal. Quit Claude here, then try again.', capable: "Claude's terminal was closed, but Claude is running this conversation in another terminal. Quit it there or close that terminal, then open the conversation from Session History." }, @@ -815,7 +819,7 @@ describe.each([ capable: null, recoveryTab: true } - ])('$name', async ({ refusal, older, capable, activates, recoveryTab, opens }) => { + ])('$name', async ({ refusal, older, restoredOlder, capable, activates, recoveryTab, opens }) => { if (refusal) { mocks.call.mockResolvedValue({ ok: false, refusal }) } @@ -826,7 +830,7 @@ describe.each([ }) expect(mocks.closeTerminal).toHaveBeenCalledTimes(closes ? 1 : 0) expect(mocks.activate).toHaveBeenCalledTimes(activates ? 1 : 0) - const expected = closes ? capable : older + const expected = closes ? capable : (restored && restoredOlder) || older expect(mocks.toast.mock.calls.map(([text]) => text)).toEqual( expected === null ? [] diff --git a/src/renderer/src/components/tab-bar/cli-chat-resume-run.ts b/src/renderer/src/components/tab-bar/cli-chat-resume-run.ts index 0c847e222ca..7e19a170e6e 100644 --- a/src/renderer/src/components/tab-bar/cli-chat-resume-run.ts +++ b/src/renderer/src/components/tab-bar/cli-chat-resume-run.ts @@ -148,9 +148,13 @@ export async function runCliChatResume( controller.signal ) const state = useAppStore.getState() - // An agent that already quit leaves nothing to stop, so its terminal stays and main's create runs. + // An agent that already quit leaves nothing to stop, so its terminal stays and main's create runs; + // a row restored from before a restart says nothing about whether its agent came back. + const paneRow = state.agentStatusByPaneKey[source.paneKey] const agentLiveInPane = - state.agentStatusByPaneKey[source.paneKey]?.providerSession?.id === source.providerSessionId + !!paneRow && + !paneRow.restoredUnconfirmed && + paneRow.providerSession?.id === source.providerSessionId if (closeSupported && agentLiveInPane) { // Main's answer to a chat that already holds the conversation; the host's create judges terminals. const ownerRow = Object.values(state.agentStatusByPaneKey).find(