feat(chat): a chat pane of its own, host-started chats, and no leaked chat agents
Links
- Issue: SUPER-2635
Summary
- Chat gets a pane of its own (
chat-v3), keyed by its chat session. Any chat the host runs that has no pane — Roster'screateSession, an automation run, a new workspace — gets one when the workspace is open. - The host now starts chats itself: a new workspace's chat starts at create time instead of waiting for the workspace page to mount, and automation runs (flag on) start a chat and continue the previous run's chat.
- Chat agent processes no longer leak when a workspace is deleted or a chat pane remounts while its session starts.
- A reply the agent writes on its own (after a background task finishes) is saved when its cycle ends, instead of staying empty until the user's next message — which is why the last reply only appeared after sending something.
- A chat whose agent stopped resumes by itself (with backoff) and keeps its conversation on screen while it does; the "This chat was stopped" panel only appears for a chat that moved to a terminal or still fails after three attempts.
- The chat no longer spins forever when the host service is down: the transcript and composer render at once, messages are held and sent once the host connects, and the pane says "Connecting to the host service…" meanwhile.
- Smaller: the composer's footer buttons (send, stop, mic, plus) go back to rounded squares — #8216 made them circles; its 26px sizing stays. Also: account usage popover in the chat header, background-task notices as one plain line, the ChatV3Pane prototype and its "Superset" agent choice removed.
Why / Context
Chats lived inside the agent's terminal pane and were tracked by the terminal's id. Switching to chat kills that terminal, so:
- chats with no pane (Roster, automations) never appeared in the UI;
- a continued automation run looked for a terminal that no longer existed and launched a new agent every run (SUPER-2635);
- a new workspace's chat was created by the pane's own effect, so it only started once you opened the workspace.
On top of that, every chat session keeps a claude-agent-acp + Claude CLI pair alive until something closes it. One user host had 27 of them (~7.7 GB), 10 in worktrees that no longer existed.
How It Works
- Chat pane.
ChatPanerenders the existing ACP chat (AcpChatPane) with data keyed by the chat session id; the pane still records aterminalIdas the stable id the host binds the chat to. Saved layouts with a chat-on-terminal pane are converted on first render. - Toggle. CLI/CHAT replaces the pane with the other kind and stops the process behind the one it leaves (chat → CLI resumes the same agent session in a terminal; CLI → chat resumes it in a chat).
- Adoption.
useAutoAdoptChatSessionslists the workspace's live chat sessions and opens a pane for any that no pane holds, refetching onchat:sessions-changed. - Host-started chats.
agents.runand the workspace-create agent launch acceptsurface: "chat": the host creates the chat session in the worktree (with model, mode and attachments) and sends the first prompt. The result keepskind: "terminal"for released clients and addschatSessionId, which the desktop uses to skip opening a terminal tab. A continued automation run prompts the previous run's chat when it is still live. The API asks for a chat when the automation owner has theacp-chatflag. - Leaks. Workspace cleanup now stops the workspace's chat sessions (
closeScope) next to its terminals. A chat pane that remounts while its session is being created joins the create in flight; a session that finishes starting after its pane is gone is closed. - Host unreachable.
useChatSessionretries its seed with backoff and a 10 s per-attempt timeout (it used to try once and leave the pane loading forever on any failure), and only flushes the outbox while the stream is open.SessionViewno longer gates on loading. A chat with no session yet rendersDraftChat— the composer with a queue on the pane (queuedPrompts) — andcreateSessionretries with the same command id while the host is unreachable, stopping on an error the host answered with or once no pane waits for it. Queued prompts are sent in order once the session is ready. - Usage. The host captures the chat agent's account from its launch env (same
CLAUDE_CONFIG_DIR/CODEX_HOME+ API-key checks as the terminal hook) and keeps it on the chat binding, so the sharedAccountUsagebutton works in the chat header.
Manual QA Checklist
Run in a dev app from this branch (local stack, acp-chat flag overridden on). Process counts are claude-agent-acp children of the dev host and every process whose cwd is in the test worktree.
- New workspace with a prompt, left the screen the moment it opened: the renderer made 0
createSession/prompt calls, the host started the chat in the new worktree and it replied while the app stayed on Automations - Opening that workspace shows one chat tab with the conversation, no stray terminal tab
- Deleting a workspace stops its chat agent within 2 s; no Claude process left in its worktree; the other workspace's chat keeps running
- Claude preset button opens a chat pane directly (no terminal, one
createSession, one new agent) - Switching tabs while a chat starts (1.5 s / 3 s injected latency): coming back mid-create joins it (1 call, 1 agent); coming back after it finished closes the stranded session instead of leaking it
- Closing a chat pane stops its agent within 1 s
- CLI ↔ CHAT, three round trips: on CLI the chat agent and its Claude stop and a shell + Claude CLI run; back on CHAT those are gone and the chat resumes with its history; after the cycles the worktree has exactly the processes it started with
- Host blocked (CDP
setBlockedURLs), workspace reloaded on a chat: composer and "Connecting to the host service…" instead of a spinner; a message sent while blocked shows as pending, goes out on unblock and is answered - Host blocked, Claude button: the new chat opens with the composer and notice; a message typed then waits in the queue strip and is sent and answered after unblock (~18 s with backoff)
- 30-turn chat, quit Electron, relaunch: the pane opens straight onto the conversation (turn 30 visible ~1 s after the pane renders) with "Resuming the conversation…", no spinner, no panel; resumed in ~7 s
- Kill the chat's agent while it is open, three rounds: history stays visible, it resumes by itself, exactly one live session for the pane each time, and a new message is answered in 2–3 s
- Background
sleep 15, turn ends, Claude replies on its own when it finishes: the reply is in the journal with its text 1 s after it starts (before: an empty item until the next prompt, as in the user's Canary journal), and is still shown after switching tabs away and back - Account usage popover in the chat header shows the account, plan and windows
- Background-task notice renders as one 14px line matching "Ran N commands", no disclosure
- Automation run with
surface: "chat"through the API — not run: PostHog is off in local dev, so the API's flag check always says no. Covered by unit tests only.
Testing
bun run typecheck(desktop, host-service, chat-runtime) — clean apart from the existing better-auth type errors inpackages/auth/packages/trpcbunx biome checkon changed filesbun run check:i18n— catalogs translated, no diffbun test— chat-runtime, host-service (agents, chat-v3, terminal-agents, workspace-cleanup, workspaces, workspace-creation), trpc automation, desktop workspace-creates / acpHarness / v2-workspace
Compatibility
All tRPC changes are additive and optional (surface input on agents.run and workspace-create agent launches, chatSessionId on the run result, live/terminalId on chat listSessions). A released desktop, CLI or API never sends surface and keeps getting terminals. An older host strips surface and launches a terminal agent, which the desktop still shows.
Known Limitations
- At the moment a resumed chat switches to its new session the transcript can blank for under half a second while the new session's history loads.
- Queued prompts on a chat with no session yet are display-only (no edit/remove) until the session exists.
- Right after an app restart the
acp-chatflag can still be resolving; a preset click inside that 2 s window opens a terminal (pre-existing inuseAwaitAcpChatEnabled). - Toggling CLI → CHAT resets the chat's permission mode ("Full access" came back as "Approve for me"), drops the chat title, and the resumed history shows "Worked for 0s".
- Idle chats still keep their agent process until closed; the close path's SIGKILL fallback kills the adapter but not its Claude child. A host-side sweep (worktree gone, or idle with no viewers) is the follow-up.
- A turn can stay "running" after the agent finished when a prompt is folded into a background-task notification cycle — upstream
claude-agent-acp#1145, fix in #1185. Not addressed here. AgentSurfaceToggle/useAgentSurfaceSwitchstill live underAgentTerminalPanewhile the chat header also uses them (pre-existing import pattern).
Rollout / Rollback
- Behind the
acp-chatflag: with it off, panes, launches and automations behave as today. - Rollback: revert the PR. Layouts saved while it was live hold
chat-v3panes, which the reverted build renders in the old ChatV3 prototype pane; reopen those chats from the agent if they look wrong.
Summary by CodeRabbit
-
New Features
- Chat conversations now open in workspace panes and can be launched directly with supported agents.
- Live chat sessions can be restored into the workspace automatically, and agents can switch between chat and terminal views.
- Prompts sent while connecting are queued, and chats can recover from stopped or interrupted sessions.
-
Improvements
- Connection and recovery states are clearer, with automatic retries when the host is unavailable.
- The separate “Chat v3” add-menu option is no longer available; chat is integrated into agent workflows.