fix(desktop): a task's cloud launch opens one tab, not an empty chat beside it

HA
1d ago
+408-14

Problem

A customer started a workspace from a task and got an empty tab, then a second tab with the finished job.

Starting a cloud workspace from a task (Tasks → Create workspace → Run) opens a waiting pane for the agent launch. Since #9937, Run in Workspace seeds that pane too. It ends in two tabs when:

  • The agent finished or the box slept before the user opened the workspace. The host listed a chat's terminal id only while its harness ran. The launch's chat came back with terminalId: null, so useSyncChatSessionTabs adopted it under its session id as a second tab (the job). The waiting pane only bound to a live chat on its terminal, so it timed out into a blank chat (the empty tab).
  • The box took longer than three minutes to provision. The waiting pane's budget started at provisioning, so it gave up on mount, before the host's first answer. It released into a blank chat, and the launch's chat was adopted next to it.

Fix

  • chat-runtime: store the launch's terminal id on the session row (0006, nullable terminal_id). listSessions reports live?.terminalId ?? row.terminalId, so a finished chat still names its terminal and the waiting pane's claim on it holds.
  • Waiting pane (pendingLaunchOutcome): binds to the launch's chat whether or not it is live, preferring live, then open, then closed. On hosts without the column it falls back to the agent binding's chatSessionId. It never gives up before the host's first answer, and the budget starts then, not at provisioning. It marks the session live only when it is.
  • History (historyEntries): reopens a stopped chat on a fresh terminal, so a stored terminal id never puts two panes on one terminal.

Compatibility

  • Old desktop + new host: no schema change on the wire. Only the meaning of terminalId widens to non-live chats. The old waiting pane still times out and the chat is adopted after it: same two tabs as today, nothing new breaks.
  • New desktop + old host: stopped chats still list no terminal. The give-up gate and timer fix apply. The binding fallback helps only while the host still holds the chat binding.
  • Chats created before the host update have no stored terminal id and are not matched.

Verification

In the dev desktop over CDP:

  • Local task launches (chat and terminal surface, with and without a setup script): one agent tab each time. "Workspace Setup" is second when the project has setup. Not affected.
  • Before: the waiting pane that useCreateCloudWorkspace seeds, keyed to a chat whose harness had stopped, opened as "Claude" (waiting, later blank) plus an adopted "Chat" tab with the job.
  • After: same flow with a chat started by the fixed host, seeded through the app's own seedPendingCloudLaunch. The workspace opens on one tab bound to the launch's chat.

This was not run against a real cloud box. The dev env has no sandbox, so the pane was seeded on a local workspace, and the outcome logic ran against a real host.

Tests:

  • chat-runtime: full suite passes, including a new test that a session keeps its terminal after its harness stops (it fails without the change).
  • Desktop: pendingLaunchOutcome, historyEntries and chatSessionsToAdopt tests pass. The new cases fail on the old code.
  • host-service: typecheck passes.
  • Desktop typecheck ran out of memory on this 8 GB box and was not run locally. CI covers it.

Summary by cubic

Fixes cloud workspace launches from a task opening an extra empty chat tab alongside the real chat. Now the waiting pane binds to the launch's chat even when its harness already stopped, so you get one tab with the job's transcript instead of an empty chat and an adopted copy.

Changes

  • Stores the launch's terminal id on the session row (migration 0006, nullable terminal_id) so a finished chat still reports its terminal.
  • The waiting pane binds to the launch's chat whether live or not, preferring live first, and never gives up before the host's first answer.
  • History entries reopen stopped chats on a fresh terminal, so a stored id never creates two panes on one terminal.

Summary by CodeRabbit

  • Bug Fixes
    • Improved chat history and session handling so stopped chats are shown without being treated as live.
    • Improved pending cloud launch matching, including finished chats, and ensured waiting and timeout behavior accounts for when the host responds.
    • Chat sessions now retain their terminal association after stopping, improving matching with pending launches and session tabs.