fix(host-service): restore workspace_created/deleted telemetry lost in local-first migration

Merged
SA
4mo ago
+69-8

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 in v2Workspace.create/delete, firing only on an actual v2Workspaces insert/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, and agent_session_launch all 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, same clientMachineId ?? getHostId() host_kind semantics), plus new host_service_version and source=host_service.
  • WorkspaceStoreContext gains optional api/organizationId/clientMachineId mirroring HostServiceContext field names, so sites passing full ctx get 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-service typecheck 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 insertLocalWorkspace and deleteLocalWorkspace via the authenticated analytics.captureEvent relay (fire-and-forget; no SDK or keys in the host).
    • Keep property parity with the old cloud events; add host_service_version and source=host_service.
    • Extend WorkspaceStoreContext with optional api/organizationId/clientMachineId; thread through ensure-main-workspace, adopt-existing-worktree, project delete, and destroy; calls now use deleteLocalWorkspace(ctx, id).
    • Guard telemetry against partial or missing api routes 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.

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.