Skip to content

fix(cli): telemetry enable/disable fire cli_command_executed on pre-toggle consent#5798

Merged
Coly010 merged 2 commits into
developfrom
columferry/cli-1868-telemetry-disable-fire-cli_command_executed-with-pre-toggle
Jul 7, 2026
Merged

fix(cli): telemetry enable/disable fire cli_command_executed on pre-toggle consent#5798
Coly010 merged 2 commits into
developfrom
columferry/cli-1868-telemetry-disable-fire-cli_command_executed-with-pre-toggle

Conversation

@Coly010

@Coly010 Coly010 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

Bug fix (Go parity).

What is the current behavior?

Go's cli_command_executed telemetry event is gated on a consent snapshot read once at process start (PersistentPreRunE, apps/cli-go/cmd/root.go:131-138), before a command's own handler runs, and fired after the handler completes (:171-181) based on that snapshot — not on any value the handler itself just wrote. This applies uniformly to every command, including telemetry enable/disable themselves.

The TS legacy port instead unconditionally suppressed this event for both telemetry enable and telemetry disable via analytics: false, so neither command ever fired it, regardless of prior telemetry state.

What is the new behavior?

analytics: false is removed from both commands. The existing legacyAnalyticsLayer/telemetryRuntimeLayer machinery already reads consent from disk once, at Effect layer-construction time — before either handler mutates telemetry.json — so this reproduces Go's snapshot semantics without any new bespoke logic:

  • Running disable while telemetry is enabled fires the event one last time (using the pre-toggle, still-enabled snapshot); running it while already disabled stays silent.
  • Running enable while telemetry is already enabled (a redundant/idempotent invocation) fires the event; the common case (enabling from disabled) stays silent.

This is intentionally broader than the original report's "disable only" framing — tracing Go's actual gate (internal/telemetry/service.go's canSend()) showed it's symmetric and state-based, not command-based, so scoping the fix to disable alone would have left a real (if narrow) parity gap for the redundant-enable case.

Also documents a previously-unmentioned side effect: when the event fires, the command now waits (bounded, ~5s) for a PostHog flush attempt before exiting, since the analytics client's shutdown is a finalizer around the whole command run.

Closes CLI-1868

Coly010 added 2 commits July 6, 2026 19:25
…oggle consent

Go's cli_command_executed gate (cmd/root.go:131-138,171-181) reads the
telemetry consent snapshot at process start, before the command's own
handler runs — not the value it just wrote. TS unconditionally suppressed
the event on both telemetry enable and disable via analytics: false, so
neither ever fired.

Removing analytics: false from both commands lets the existing
legacyAnalyticsLayer/TelemetryRuntime machinery reproduce this correctly:
those layers are built once, before the handler mutates telemetry.json, so
whichever command runs fires the event exactly when telemetry was already
enabled beforehand and stays silent otherwise — matching Go's uniform,
state-based gate for all four enable/disable x already-enabled/disabled
combinations, not just the "disable only" framing in the original report.

Fixes CLI-1868.
…try toggle

Review (architect/engineer/security/supabase-dx) converged on one gap: the
CLI-1868 regression tests only used mockAnalytics(), which unconditionally
records every capture and never touches legacyAnalyticsLayer's actual
consent gate — so they proved the wiring fix but not the pre-toggle-snapshot
behavior itself.

- Add a runtime.layer.unit.test.ts case proving TelemetryRuntime.consent is
  captured once and survives a later on-disk write to telemetry.json — the
  core mechanism CLI-1868 depends on.
- Add two telemetry.integration.test.ts cases that run disable/enable
  through the real legacyAnalyticsLayer (not the mock), proving the
  production wiring completes cleanly end-to-end.
- Correct the "(see Notes)" dangling doc cross-references and document the
  new bounded (~5s) PostHog flush wait the fix introduces on the event-fires
  path, previously unmentioned.

Filed CLI-1895 (should next/ adopt this behavior too?) and CLI-1896 (global
flag redaction gap made reachable by this fix) as separate follow-ups.
@Coly010

Coly010 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 0794bf9d64

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Coly010 Coly010 self-assigned this Jul 7, 2026
@Coly010 Coly010 marked this pull request as ready for review July 7, 2026 15:18
@Coly010 Coly010 requested a review from a team as a code owner July 7, 2026 15:18
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Supabase CLI preview

npx --yes https://pkg.pr.new/supabase/cli/supabase@0794bf9d6442ee63b82b2e87626197566f18f12a

Preview package for commit 0794bf9.

@Coly010 Coly010 added this pull request to the merge queue Jul 7, 2026
Merged via the queue into develop with commit 59f235f Jul 7, 2026
28 checks passed
@Coly010 Coly010 deleted the columferry/cli-1868-telemetry-disable-fire-cli_command_executed-with-pre-toggle branch July 7, 2026 15:50
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.

2 participants