Skip to content

fix(telemetry): coalesce session_started/session_ended per daemon boot - #23

Merged
whysosaket merged 1 commit into
mainfrom
fix/coalesce-session-telemetry
Jul 2, 2026
Merged

whysosaket merged 1 commit into
mainfrom
fix/coalesce-session-telemetry

Conversation

@whysosaket

Copy link
Copy Markdown
Collaborator

Summary

  • root.session_started / root.session_ended used to fire once per shim→daemon connection; MCP host subprocess churn (Cursor MCP restarts, IDE reloads, tool-list refreshes) meant a single active user could easily generate 20+ event pairs a day, drowning the signal in PostHog.
  • Now each fires at most once per daemon lifetime — session_started on the first shim registration, session_ended in the shutdown path, only if a session actually existed.
  • Per-shim tab-group broadcasts, session bookkeeping, and rate-limiter wiring are untouched; only the PostHog event volume is capped. root.daemon_shutdown.total_sessions still records the true shim-connection count.

Test plan

  • pnpm --filter @browserops/bridge exec tsc --noEmit clean
  • pnpm --filter @browserops/bridge exec vitest run src/telemetry/ — 36 tests pass (redact allowlist unchanged, schema stable)
  • Manual: BROWSEROPS_POSTHOG_HOST=<local-capture> browserops start, launch two MCP clients, restart both a few times, browserops stop — expect exactly one root.session_started + one root.session_ended bracketed by root.daemon_started / root.daemon_shutdown, with total_sessions >= 4 on shutdown.
  • Manual: start daemon, no shim connects, browserops stop — expect zero session events.

Previously the daemon emitted root.session_started and root.session_ended
once per shim→daemon connection. Every MCP client subprocess restart
(Cursor MCP reloads, IDE reboots, tool-list refreshes) generated a full
event pair, so a single active user could easily produce 20+ pairs a day
and drown the signal in PostHog.

Now:
- root.session_started fires once per daemon lifetime, on the FIRST shim
  registration, with the first client's name/version.
- root.session_ended fires once per daemon lifetime, inside the shutdown
  path, only if at least one session existed, with duration measured
  from the first session_started.
- Per-shim tab-group broadcasts, session bookkeeping, and rate-limiter
  wiring stay untouched — only the PostHog event volume is capped.

root.daemon_shutdown.total_sessions still records real shim-connection
volume, so analytics fidelity is preserved.
@whysosaket
whysosaket merged commit 7b757a7 into main Jul 2, 2026
1 check passed
@whysosaket
whysosaket deleted the fix/coalesce-session-telemetry branch July 2, 2026 06:30
whysosaket added a commit that referenced this pull request Aug 31, 2026
#23)

Previously the daemon emitted root.session_started and root.session_ended
once per shim→daemon connection. Every MCP client subprocess restart
(Cursor MCP reloads, IDE reboots, tool-list refreshes) generated a full
event pair, so a single active user could easily produce 20+ pairs a day
and drown the signal in PostHog.

Now:
- root.session_started fires once per daemon lifetime, on the FIRST shim
  registration, with the first client's name/version.
- root.session_ended fires once per daemon lifetime, inside the shutdown
  path, only if at least one session existed, with duration measured
  from the first session_started.
- Per-shim tab-group broadcasts, session bookkeeping, and rate-limiter
  wiring stay untouched — only the PostHog event volume is capped.

root.daemon_shutdown.total_sessions still records real shim-connection
volume, so analytics fidelity is preserved.
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