PR #9937 review: cloud agent launches no longer open on an empty workspace

PR #9937 · Review workspace · author Kitenite · head 2493b60e · reviewed 2026-11-18

Summary

A cloud workspace launched with a terminal agent showed an empty view for about 30 s, until the box started the agent. The PR sends every desktop cloud create through one hook, useCreateCloudWorkspace. That hook seeds a waiting pane for both the chat and the terminal surfaces, and the pane becomes the agent's terminal or chat in place. On the host side, host-service now broadcasts a listed terminal:lifecycle event, and a new useWorkspaceTerminalSessions hook refreshes terminal.list when it gets one. Terminals started outside the desktop now get a tab right away, without waiting for a poll.

Verdict

minor issues The structure is sound: one create path and one terminal.list reader, both guarded by source-scan tests, plus exhaustive surface switches. One edge case in the terminal surface can leave a spinner on screen for 3 minutes, and a few small points need cleanup.

Findings

Medium · correctness

A terminal launch attaches only when a live agent binding exists, not when its terminal exists

apps/desktop/.../PendingCloudLaunchPane/hooks/usePendingCloudLaunch/usePendingCloudLaunch.ts:81: launchedTerminal needs a binding for terminalId with no endedAt. Agent hook events create that binding (terminal-agents/store.ts recordEvent). While the pane waits, TERMINAL_CLAIMING_KINDS stops auto-adopt from opening the terminal on its own.

Scenario: the box starts Claude in the promised terminal, and Claude exits at once (no auth, a bad flag, a crash on start). The binding ends before the pane sees it live. Another case is an agent whose start hook never fires. In both cases the user sees "Starting Claude" for the full 3-minute PENDING_CLOUD_LAUNCH_TIMEOUT_MS. Then the pane is dropped, and only after that does auto-adopt open the terminal with the error in it. The terminal had been in terminal.list all that time.

Fix: for surface === "terminal", attach when terminalId shows up in useWorkspaceTerminalSessions (the new listed event makes that immediate), or when any binding exists, ended or not. Keep the live-binding rule only for the chat surface's fallback to a terminal. Add a pendingLaunchOutcome case for "terminal listed, agent ended".

Low · docs

The compatibility note says every consumer filters on eventType, but several do not

useTerminalAgentBindings.ts:67, usePageWatchers.ts:50, usePageWatchersForPage.ts:91 and DashboardSidebarWorkspaceStatusProvider.tsx:304 invalidate on every terminal:lifecycle event. Each new listed terminal therefore triggers extra refetches of bindings and page watchers, in both released and new desktops. Nothing breaks, but the PR's compatibility statement is wrong. Fix: correct the statement. Optionally, have those listeners skip listed where it adds nothing, since bindings come from agent events.

Low · docs

A JSDoc block now sits on the wrong declaration

packages/shared/src/cloud-agent-launch.ts:41: the new CLOUD_AGENT_LAUNCH_SURFACES constant was inserted between the "What a cloud workspace launches on first boot…" doc comment and cloudAgentLaunchSchema. Editor hovers now attach that comment to the constant. Fix: move the constant and its type above the comment.

Nit

The timeout clock and the elapsed counter start at different times

usePendingCloudLaunch.ts:44 starts the 3-minute timeout when the pane mounts (useState(Date.now)). PendingCloudTerminal.tsx:19 shows elapsed time from provisioningSince(workspaceId). If the user leaves the workspace and comes back, the timeout starts again while the counter keeps going. Fix: base both on the same start time, or accept the difference on purpose.

Checked and found fine: Move to cloud passes no agent, so it seeds no pane and keeps its moved-chat seeding. RunInWorkspacePopover now does a cancel, setData and invalidate for each task, and the last refetch wins with server truth. Old saved panes without a surface read as chat. The persisted kind string is unchanged.

Evidence

Desktop (Electron) — could not run. The box has 7.9 GB RAM, which is below the dev-stack's 8 GB desktop threshold. The provisioned desktop window exited with code 137. I retried once with NODE_OPTIONS=--max-old-space-size=3072 and RENDERER_REMOTE_DEBUG_PORT=9333. The renderer loaded (Renderer loaded successfully), and then bun run dev exited with 137 again. dmesg shows an Electron general-protection fault in ld-linux. I captured no screenshots, so I have not verified the UI behaviour myself. The author's before/after page is here.

Host-service (listed event) — verified with a real pty-daemon and a real host DB:

node --import tsx --test src/terminal/terminal.listed-event.node-test.ts
  ✔ a new listed terminal is announced once, so renderers see it without polling (82ms)
  ✔ an unlisted terminal is announced when it joins the list (21ms)
ℹ pass 2  ℹ fail 0

# with `if (session.listed) announceListed(session);` removed locally (reverted after):
  ✖ a new listed terminal is announced once, so renderers see it without polling
ℹ pass 1  ℹ fail 1

Locally, this needed better-sqlite3 rebuilt for Node's ABI first (ERR_DLOPEN_FAILED). That is an environment problem, not caused by the PR.

Mobile, web, CLI: not changed by this PR.

Questions for the author

Test / CI notes