fix(desktop): cloud agent launches no longer open on an empty workspace

Merged
KI
9d ago
+945-371

Links

Summary

  • A cloud workspace created with a terminal agent opened on the empty workspace view for ~30 s until the sandbox started the agent. Every cloud launch surface now gets a waiting pane that becomes the agent's terminal or chat in place.
  • Terminals started outside the desktop (CLI, automations, mobile, cloud boxes) now get their tab right away. The host announces a terminal as it joins terminal.list, so nothing depends on another component's poll.

Why / Context

Reported from a cloud workspace with Claude in the terminal: empty view, then the terminal ~30 s later. Two causes:

  1. The waiting pane was seeded only when initialLaunch.surface === "chat". A terminal launch wrote no layout, so the workspace stayed empty until the terminal was adopted.
  2. Adoption reads terminal.list, which nothing refreshed except the activity menu's 10 s poll, and that poll pauses while the window is unfocused. The host had no "terminal created" event, only exit and resumed.

How It Works

Commit 1: one create path, every surface (desktop)

  • useCreateCloudWorkspace is the only place the renderer calls cloudWorkspace.create. It promises the agent a terminal id, seeds the waiting pane and seeds the cloud list. The new-workspace screen, environment setup, Tasks "Run in Workspace" and Move to cloud all use it. Run in Workspace used to seed nothing.
  • The waiting pane (PendingCloudChatPane → PendingCloudLaunchPane) records its surface. Terminal shows "Starting " and attaches the terminal in place. If it never arrives, the pane is removed instead of turning into an empty chat. Chat behavior is unchanged.
  • The persisted pane kind string pending-cloud-chat is unchanged. Saved panes without a surface read as chat.

Commit 2: listed lifecycle event (host-service + desktop)

  • createTerminalSessionUnlocked broadcasts terminal:lifecycle { eventType: "listed" } when a session joins the list (new, adopted, or unlisted → listed).
  • useWorkspaceTerminalSessions owns terminal.list and refreshes on terminal:lifecycle and on host reconnect. All four readers use it: auto-adopt, activity menu, automation-run link, session dropdown.

Enforced

  • CLOUD_AGENT_LAUNCH_SURFACES plus exhaustive satisfies never switches in the pane, its title and the outcome logic: a new surface fails typecheck until it is handled.
  • Source-scan tests: only useCreateCloudWorkspace may call cloudWorkspace.create, and only useWorkspaceTerminalSessions may call terminal.list.useQuery. Both were checked to fail when bypassed.

Manual QA Checklist

Dev app over CDP with real input, against a local API and gate with a fake cloud sandbox (a local host-service in sandbox mode, boot held 20 s to match a real box):

  • New Workspace → Cloud → prompt → Claude, Chat setting off: empty view 4.9–35.5 s before; after, a "Starting Claude" tab from 4.6 s, becoming the terminal in the same tab at 26.4 s under the promised terminal id; no console errors
  • Same journey with the Chat setting on: waiting chat unchanged, becomes the chat in place
  • Terminal created on the box from outside the desktop (terminal.createSession, what superset terminals create calls): old host gave no tab after 30 s (window unfocused); new host gave a tab in 64–225 ms over 4 runs
  • Not run against a real production cloud sandbox

Testing

  • bun run typecheck (desktop), tsc --noEmit (host-service, workspace-client)
  • bun test src/renderer (desktop): 7627 pass
  • bun test host-service events / terminal / terminal-agents / page-watch
  • New terminal.listed-event.node-test.ts (added to test:integration:terminal), shown to fail with the broadcast removed
  • bun run check:i18n: the tab reuses the existing "Starting {agentLabel}" message; one new sentence, translated into all 17 locales
  • Biome on changed files

Compatibility

  • Released desktops and host listeners that branch on eventType ignore the new listed variant. Four hooks refetch on any terminal:lifecycle event (agent bindings, page watchers, the sidebar status provider), so listed adds one refetch per new terminal there.
  • A new desktop against an older host-service (remote host, older cloud box) falls back to today's poll.
  • Cloud boxes get the host change with the next host bundle release.

Review follow-ups (949069fa)

  • A terminal launch attaches once its terminal is listed or on any agent binding, live or ended, instead of waiting out the 3 min timeout when the agent exits at once.
  • The timeout starts at provisioning, like the on-screen timer.
  • Seeding the cloud list drops an already-cached row, so a new workspace never shows twice.

Stacked

  • #9939: workspaces created outside the desktop (CLI, automations) get the same waiting pane from the box's own pending launch.

Summary by CodeRabbit

  • New Features
    • Cloud workspace launches can now open in chat or terminal. While a launch is pending, the workspace shows its destination, agent, and setup time; prompts appear when available.
    • Terminal session lists update when a session becomes available.
    • Added translated guidance explaining where a cloud workspace’s terminal opens.
  • Bug Fixes
    • Pending terminal launches now wait for the terminal to start and are dismissed if startup times out or no terminal is available.