Skip to content

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

Merged
saddlepaddle merged 2 commits into
mainfrom
investigate-workspace-dro
Jul 24, 2026
Merged

saddlepaddle merged 2 commits into
mainfrom
investigate-workspace-dro

Conversation

@saddlepaddle

@saddlepaddle saddlepaddle commented Jul 24, 2026 •

Copy link
Copy Markdown
Collaborator

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 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.
  • 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.

Written for commit c035d9b. Summary will update on new commits.

Review in cubic

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.

…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
@coderabbitai

coderabbitai Bot commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Workspace 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.

Changes

Workspace telemetry and context propagation

Layer / File(s) Summary
Local workspace telemetry
packages/host-service/src/workspaces/local-workspace-store.ts
Adds optional API and host identity context, captures workspace creation and deletion analytics with workspace metadata, and preserves existing event-bus notifications.
Workspace operation wiring
packages/host-service/src/trpc/router/project/utils/ensure-main-workspace.ts, packages/host-service/src/trpc/router/workspace-creation/shared/adopt-existing-worktree.ts, packages/host-service/src/trpc/router/project/project.ts, packages/host-service/src/trpc/router/workspace-cleanup/workspace-cleanup.ts
Propagates API, organization, and client machine context into workspace persistence and passes full request context to local deletion helpers.

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
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title is conventional, concise, and accurately summarizes the restored workspace telemetry in host-service.
Description check ✅ Passed The description covers the problem, fix, caveats, and testing, but it doesn't follow the repo's exact template headings.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch investigate-workspace-dro

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4edf951 and 86c66b3.

📒 Files selected for processing (5)
  • packages/host-service/src/trpc/router/project/project.ts
  • packages/host-service/src/trpc/router/project/utils/ensure-main-workspace.ts
  • packages/host-service/src/trpc/router/workspace-cleanup/workspace-cleanup.ts
  • packages/host-service/src/trpc/router/workspace-creation/shared/adopt-existing-worktree.ts
  • packages/host-service/src/workspaces/local-workspace-store.ts

@github-actions

github-actions Bot commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

🧹 Preview Cleanup Complete

The following preview resources have been cleaned up:

  • ✅ Neon database branch

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

This branch was previously deployed

1 inactive deployment
preview — c035d9bb Deployed Jul 24, 2026 by saddlepaddle via Deploy Docs #6810
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant