Repository navigation
fix(host-service): restore workspace_created/deleted telemetry lost in local-first migration - #5909
Conversation
…n local-first migration PR #5731 retired workspace cloud sync, which was the only path that fired the cloud-side workspace_created/workspace_deleted captures for v2 workspaces. Typed creation events fell from ~5.0k/day to ~2.0k/day tracking 1.16 adoption, with no replacement emission. Emit both events from the local workspace store's insert/delete choke points via the authenticated analytics.captureEvent relay (the CLI pattern) — property parity with the retired cloud capture plus host_service_version and source=host_service. Claude-Session: https://claude.ai/code/session_01JGkCApsJ22Ujd2hadHEftJ
📝 WalkthroughWalkthroughWorkspace store contexts now carry optional API and host identity fields. Workspace creation and deletion can emit analytics events, while project removal, workspace cleanup, existing-worktree adoption, and main-workspace setup pass the enriched context through. ChangesWorkspace telemetry and context propagation
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant WorkspaceOperation
participant LocalWorkspaceStore
participant Database
participant AnalyticsAPI
WorkspaceOperation->>LocalWorkspaceStore: provide database, API, organization, and machine context
LocalWorkspaceStore->>Database: create or delete workspace
Database-->>LocalWorkspaceStore: workspace row
LocalWorkspaceStore->>AnalyticsAPI: capture workspace lifecycle event
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/host-service/src/workspaces/local-workspace-store.ts`:
- Around line 33-56: Update trackWorkspaceEvent to wrap synchronous telemetry
preparation and the analytics captureEvent mutation invocation in try/catch,
including host ID and package metadata resolution, so telemetry errors cannot
propagate into workspace creation or deletion. Preserve the existing
asynchronous .catch(() => {}) for rejected analytics requests.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: e9c9a130-3bf1-4471-8625-bf3792f53761
📒 Files selected for processing (5)
packages/host-service/src/trpc/router/project/project.tspackages/host-service/src/trpc/router/project/utils/ensure-main-workspace.tspackages/host-service/src/trpc/router/workspace-cleanup/workspace-cleanup.tspackages/host-service/src/trpc/router/workspace-creation/shared/adopt-existing-worktree.tspackages/host-service/src/workspaces/local-workspace-store.ts
🧹 Preview Cleanup CompleteThe following preview resources have been cleaned up:
Thank you for your contribution! 🎉 |
Hand-rolled test stubs shape ctx.api with only the routes they mock, so the analytics property access threw synchronously and failed the workspace operation. Telemetry is best-effort; swallow the throw. Claude-Session: https://claude.ai/code/session_01JGkCApsJ22Ujd2hadHEftJ
Problem
workspace_createddropped ~30–40%/day starting 2026-07-21 — flagged as a possible product bug, but it's an instrumentation gap:type=worktree|main) were captured cloud-side inv2Workspace.create/delete, firing only on an actualv2Workspacesinsert/delete.workspace-cloud-sync.ts, which feat(desktop,host-service): local-first projects — host.db owns projects, workspace cloud sync retired #5731 (local-first projects, shipped in 1.16.0) deleted. The local-first creation path emitted no analytics at all.workspace_opened,workspace_initialized, andagent_session_launchall stayed flat — no real usage drop, no error spike.Fix
Emit
workspace_created/workspace_deletedfrom the local store's choke points (insertLocalWorkspaceafter a real insert,deleteLocalWorkspacewhen the row existed), relayed through the authenticatedanalytics.captureEventcloud endpoint — the same pattern the CLI uses, so no PostHog SDK or key in the host build anddistinctIdcomes from the host's authenticated user, matching the retired cloud capture.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.Non-changes / caveats
/workspaces. No create double-count is possible — upgraded hosts have no code path to the cloud capture, old hosts don't have the relay.source=host_service.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_createdandworkspace_deletedtelemetry in@superset/host-serviceafter the local-first migration. Events now emit on local insert/delete and relay to cloud analytics without affecting workspace operations.insertLocalWorkspaceanddeleteLocalWorkspacevia the authenticatedanalytics.captureEventrelay (fire-and-forget; no SDK or keys in the host).host_service_versionandsource=host_service.WorkspaceStoreContextwith optionalapi/organizationId/clientMachineId; thread through ensure-main-workspace, adopt-existing-worktree, project delete, and destroy; calls now usedeleteLocalWorkspace(ctx, id).apiroutes and network failures; swallow both sync throws and rejections so reporting never interrupts workspace flows.Written for commit c035d9b. Summary will update on new commits.
Summary by CodeRabbit
Bug Fixes
Improvements