feat: open the waiting pane for cloud agent launches the desktop did not create

Merged
KI
9d ago
+648-70

Stacked on #9937.

Summary

  • host-service: new query sandbox.pendingLaunch({ workspaceId }). It returns the box's launch as a CloudAgentLaunchDescriptor while the launch has a promised terminal id and the launch marker is absent. It returns null otherwise, on non-sandbox hosts, and for any other workspace id.
  • trpc: startCloudWorkspace gives every launch a terminal id (queuedLaunch: the caller's terminalId, or a new UUID). The queued launch and initialLaunch always carry it. Before this, the CLI and automation dispatch sent none, so the box picked its own and sandbox.pendingLaunch had nothing to report for exactly those creators.
  • desktop: one pure rule, withPendingCloudLaunch(layout, launch). It adds the waiting pane as a new tab unless a pane already claims the launch's terminal id. Both the create path's collections writer (seedPendingCloudLaunch) and a new workspace-route hook (useHostPendingCloudLaunch) use it.

Why

A cloud workspace created outside this desktop (CLI ws create --cloud --agent, automation cloudDispatch) opened on the empty workspace view while its box booted. Only the creator gets initialLaunch back from cloudWorkspace.create. The box already knows its own launch (from its env) and knows when it claims it (launchSandboxAgentOnce writes the marker before launching and removes it if the launch fails). So the box is the source of truth. There is no DB column, schema change or migration. There is one API change: startCloudWorkspace (start.ts) now assigns the terminal id that every launch carries.

Agent tasks (agent/tasks.ts) are out of scope: they start the workspace with no launch, so there is no agent launch to show a waiting pane for.

How it works

  • readPendingSandboxLaunch(workspaceId, env) in sandbox-self-seed reads the identity from env and reuses describeCloudAgentLaunch from @superset/shared/cloud-agent-launch.
  • useHostPendingCloudLaunch runs only for a sandbox host target, once the layout is ready. It refetches when the host reconnects, so a box that is still booting is asked again. It skips a launch whose terminal the user dismissed (isChatTerminalIgnored; closing the waiting pane already calls ignoreChatTerminal), so a closed pane does not come back, including one the create path opened. There is no separate "seeded" set. An open or attached pane still claims the terminal id, a closed or dropped one is in the ignore record, and a launch that already started is null on the host. One case reopens the pane: a chat pane released on timeout while the box has still not launched. That launch really is still pending.
  • The query also returns the launch prompt (PendingCloudAgentLaunch = the shared descriptor plus prompt). The pane opened from the box shows it as launchPrompt, the same as the creator's pane.
  • fetchPendingCloudLaunch maps a missing procedure (isMissingProcedureError) to null, so an older host keeps today's behaviour. Other errors stay errors, so the query retries.
  • Behaviour change on the create path: a layout that already had tabs used to be skipped. Now it gets the waiting pane as a new tab unless a pane claims the terminal id. A freshly created workspace has no layout, so this path is unchanged in practice.
  • No empty-view flash: canShowEmptyLayout treats the layout as known to be empty only once it is ready and, on a sandbox host, the first sandbox.pendingLaunch fetch has settled. useHostPendingCloudLaunch returns it from its own query, so there is no second fetch. Until then the pane area renders a blank element instead of WorkspaceEmptyState. Non-sandbox hosts never wait. An old host settles at once (null), and an unreachable box settles after the query's retries. Seeding runs in a layout effect, so the frame that has the answer is not painted without the pane. This also means a local workspace no longer shows the empty state before its layout's live query is ready.
  • useCreateCloudWorkspace no longer mints agentTerminalId; the server owns the id and returns it in initialLaunch.
  • Enforcement: a source-scan test keeps sandbox.pendingLaunch behind fetchPendingCloudLaunch, and keeps construction of the PENDING_CLOUD_LAUNCH_PANE_KIND pane inside the pendingCloudLaunch store.

tRPC compatibility

  • The procedure is new and additive. No existing input, output or error code changed.
  • cloudWorkspace.create: the agentTerminalId input stays optional and is still honoured, because released desktops send it. initialLaunch.terminalId is now always set for an agent launch. It was nullable before and stays nullable in the type.
  • Rollout: this desktop no longer sends agentTerminalId, so it needs the API from this PR (rule 9). The API deploys on merge, long before a desktop release ships it. A desktop on an API without this change would get no waiting pane on create, but nothing would break.
  • New desktop with an old host: the "No procedure found" error reads as no pending launch, which is today's behaviour. MIN_HOST_SERVICE_VERSION is not raised because the client handles this case.

Testing

  • bun test on readPendingSandboxLaunch.test.ts (host-service): returns the descriptor before the marker exists and null after; keeps the chat surface; null outside sandbox mode; null for another workspace, an idle box, or a launch with no terminal id.
  • bun test on queued-launch.test.ts (trpc): a launch with no terminal id gets a UUID in both the queued launch and initialLaunch; a caller's id and the chat surface are kept. Fails without the change.
  • bun test on pendingCloudLaunch.test.ts and fetchPendingCloudLaunch.test.ts (desktop): seeds once, never over a pane that claims the terminal id, never for a null or absent launch, null for a host without the procedure, other errors rethrown, plus the source-scan test.
  • Proved the new tests fail without the change. Removing the marker and run-mode checks fails 2 host tests. Removing the claim check and the missing-procedure mapping fails 4 desktop tests. A probe file that calls sandbox.pendingLaunch fails the scan test.
  • bun test on seedHostPendingLaunch.test.ts (desktop): the box's launch opens one waiting pane that shows its prompt, and a pane the user closed does not come back. Each test fails without its change. The host test also checks the returned prompt and fails without it. The "only the store builds the waiting pane" scan test now lives in pendingCloudLaunch.test.ts.
  • bun test on canShowEmptyLayout.test.ts (desktop): a sandbox host waits while its first answer is pending and stops waiting on success or error; a non-sandbox host never waits; a layout that is not ready is not known to be empty. Fails without the pending check.
  • bun test src/router/cloud-workspace (trpc) also has 7 failures, all undici markAsUncloneable load errors in suites this PR does not touch. They are identical with the original start.ts.
  • Passed: bun run typecheck (packages/trpc), bunx tsc --noEmit (apps/desktop), bunx tsc --noEmit (packages/host-service, packages/shared), biome on the changed files. No new strings, so check:i18n is not needed.

Not verified here

I did not run this end to end. That is planned against a fake cloud box: create a cloud workspace with an agent from the CLI (an automation works too), open it in the desktop while the box boots, and check that "Starting " shows and turns into the agent's terminal or chat in place. Reopening after the launch should show no waiting pane.

Summary by CodeRabbit

  • New Features
    • Cloud sandbox launches can appear as waiting panes with their prompt while the workspace loads.
    • Existing panes are preserved when a waiting pane is added, and duplicate waiting panes are avoided.
    • Queued launches receive a terminal identifier when one is not provided.
  • Bug Fixes
    • The workspace empty state stays hidden while a sandbox launch is pending and appears after the launch check completes or fails.