diff --git a/src/hooks/use-connection-lifecycle.ts b/src/hooks/use-connection-lifecycle.ts index 6dfe0ae..e98d168 100644 --- a/src/hooks/use-connection-lifecycle.ts +++ b/src/hooks/use-connection-lifecycle.ts @@ -266,9 +266,14 @@ export function useConnectionLifecycle({ // Clean up on unmount (e.g. tab closed): disconnect the ACP connection // so it doesn't leak, and remove lingering tasks. + // However, if the agent is actively prompting (generating a response), + // keep it alive so it can finish in the background — the idle sweep + // will clean it up once it transitions back to "connected". useEffect(() => { return () => { - connDisconnectRef.current().catch(() => {}) + if (statusRef.current !== "prompting") { + connDisconnectRef.current().catch(() => {}) + } if (taskIdRef.current) { removeTask(taskIdRef.current) }