fix(desktop): stop holding a socket to every cloud workspace
Found while trying to test sandbox standby for SUPER-1908: the sandbox under test could never idle, because the app was the thing keeping it awake.
What was happening
Two always-on subscribers open an event-bus WebSocket to every host in the fan-out. Cloud sandboxes became hosts in #6505, so that meant every cloud workspace in the sidebar — for as long as the app is open. Blaxel defines activity as "has an active connection" (its docs: "sandboxes remain active as long as there's an active connection to them, typically through a WebSocket"). So no cloud workspace can ever idle while Superset is running.
Measured: two sandboxes untouched for 2h+ still read RUNNING in the provider, lastUsedAt never advancing past the last real use — because a desktop with them in its sidebar was holding a socket the whole time. Ten cloud workspaces in the sidebar would be ten warm VMs, billing, whether or not anyone is looking at them.
Why neither subscription is needed for a sandbox
useHostWorkspaceslistens forworkspace:changedto patch the cached list. A sandbox holds exactly one workspace whose identity the cloud row owns; the only field the sidebar reads off its served row isbranch, which falls back to the cloud row and can only change while someone is inside the workspace — at which point the open workspace's own subscribers hold a socket anyway.DashboardSidebarWorkspaceStatusProviderretains a bus per host for agent-status and git badges. For a sandbox that is a warm VM to keep a badge fresh on a row nobody is looking at.
Change
Sandboxes are polled at the fan-out level and connected to only while open. HostWorkspacesCacheOps gains isSandboxHost(hostId) so callers that hold a socket per host can make that decision without learning anything else about cloud workspaces. Two files, ~26 lines.
What this does not do
- The open workspace still connects (
useWorkspaceEvent,useHostReachability, file store, terminals) — that's correct; you're looking at it. - Agent-status and git badges on a closed cloud row will lag until the workspace is opened. That's the trade, and it's the right one. If we want them live, the shape is a cheap poll, not a held socket.
Verification
Typecheck clean, bun test in apps/desktop 2593 pass / 0 fail. The idle behaviour itself can only be confirmed by a build that a desktop with cloud rows actually runs — my dev app is on the local DB and can't see the prod sandboxes. So: merge, canary, then check the provider shows those two sandboxes' lastUsedAt advancing to standby. I'll follow up with that measurement.
Also worth knowing: this is what makes SUPER-1908 (standby/resume behaviour) testable at all. Until now the test subject could never sleep.
Summary by cubic
Stops the desktop app from holding an event-bus WebSocket to every cloud sandbox. Previously the app kept a socket per host, which the provider counts as activity, preventing sandboxes from idling; now sandboxes are polled and only connect while open. Closed cloud rows may show stale agent and git badges until opened. Enables standby/resume testability for SUPER-1908.
Review notes
- Adds
isSandboxHost(hostId)toHostWorkspacesCacheOpsso socket holders can skip sandbox hosts. useHostWorkspacesno longer subscribes toworkspace:changedfor sandbox hosts; relies on polling.DashboardSidebarWorkspaceStatusProviderpassesnullhostUrlfor sandbox rows, deferring live status until the workspace is opened.- No migrations or config changes required.
Summary by CodeRabbit
- Bug Fixes
- Improved sandbox workspace handling in the dashboard.
- Sandbox workspaces no longer display stale live status updates in the sidebar.
- Sandbox workspace data continues to update through polling and active-view connections.
- Live status monitoring resumes when a sandbox workspace is opened.