fix(host-service): restore workspace_created/deleted telemetry lost in local-first migration
Problem
workspace_created dropped ~30–40%/day starting 2026-07-21 — flagged as a possible product bug, but it's an instrumentation gap:
- Typed v2 events (
type=worktree|main) were captured cloud-side inv2Workspace.create/delete, firing only on an actualv2Workspacesinsert/delete. - The only high-volume caller was host-service
workspace-cloud-sync.ts, which #5731 (local-first projects, shipped in 1.16.0) deleted. The local-first creation path emitted no analytics at all. - Typed daily counts fell 5,041 (7/20) → 1,973 (7/23), tracking 1.16 fleet adoption almost exactly (57% adoption → −50% on 7/22; 60% → −61% on 7/23). v1 events,
workspace_opened,workspace_initialized, andagent_session_launchall stayed flat — no real usage drop, no error spike.
Fix
Emit workspace_created / workspace_deleted from the local store's choke points (insertLocalWorkspace after a real insert, deleteLocalWorkspace when the row existed), relayed through the authenticated analytics.captureEvent cloud endpoint — the same pattern the CLI uses, so no PostHog SDK or key in the host build and distinctId comes from the host's authenticated user, matching the retired cloud capture.
- Property parity with the old cloud events (
workspace_id,project_id,organization_id,host_id,branch,type,host_kind,client_machine_id, sameclientMachineId ?? getHostId()host_kind semantics), plus newhost_service_versionandsource=host_service. WorkspaceStoreContextgains optionalapi/organizationId/clientMachineIdmirroringHostServiceContextfield names, so sites passing fullctxget emission with no changes; literal constructions now pass the fields.- Fire-and-forget with swallowed rejection — an unreachable cloud can't fail a workspace operation.
Non-changes / caveats
- The cloud-side captures stay: they're still the only emitters for ≤1.15 hosts (long tail still creating ~700/day) and web
/workspaces. No create double-count is possible — upgraded hosts have no code path to the cloud capture, old hosts don't have the relay. - Deletes of pre-7/20 mirrored rows by upgraded hosts double-fire (relay + legacy cloud cleanup) until legacy mirrors are gone; relay events are distinguishable via
source=host_service. - The 7/21 → release-adoption window remains unbackfillable in PostHog.
Testing
packages/host-servicetypecheck clean; workspace-related integration tests (37) pass; root lint clean.
https://claude.ai/code/session_01JGkCApsJ22Ujd2hadHEftJ
Summary by cubic
Restores workspace_created and workspace_deleted telemetry in @superset/host-service after the local-first migration. Events now emit on local insert/delete and relay to cloud analytics without affecting workspace operations.
- Bug Fixes
- Emit events from
insertLocalWorkspaceanddeleteLocalWorkspacevia the authenticatedanalytics.captureEventrelay (fire-and-forget; no SDK or keys in the host). - Keep property parity with the old cloud events; add
host_service_versionandsource=host_service. - Extend
WorkspaceStoreContextwith optionalapi/organizationId/clientMachineId; thread through ensure-main-workspace, adopt-existing-worktree, project delete, and destroy; calls now usedeleteLocalWorkspace(ctx, id). - Guard telemetry against partial or missing
apiroutes and network failures; swallow both sync throws and rejections so reporting never interrupts workspace flows. - Retain legacy cloud captures for ≤1.15 hosts and web; deletes of old mirrored rows may double-fire until mirrors are gone.
- Emit events from
Summary by CodeRabbit
-
Bug Fixes
- Improved reliability of local workspace deletion by passing the full execution context through all deletion phases.
- Enhanced local workspace adoption and “main workspace” handling by providing additional host identity and API context where needed, preserving expected workspace/project state.
-
Improvements
- Added optional telemetry for local workspace create/delete events, including host identity details, with failures isolated so operations continue uninterrupted.