Repository navigation
fix(cli): telemetry enable/disable fire cli_command_executed on pre-toggle consent - #5798
Merged
Coly010 merged 2 commits intoJul 7, 2026
Conversation
…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.
Contributor
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Contributor
Supabase CLI previewnpx --yes https://pkg.pr.new/supabase/cli/supabase@0794bf9d6442ee63b82b2e87626197566f18f12aPreview package for commit |
avallete
approved these changes
Jul 7, 2026
Coly010
deleted the
columferry/cli-1868-telemetry-disable-fire-cli_command_executed-with-pre-toggle
branch
July 7, 2026 15:50
AmitKulkarni23
pushed a commit
to AmitKulkarni23/supabase_cli
that referenced
this pull request
Nov 28, 2026
The three documented telemetry opt-outs (`supabase telemetry disable`, `SUPABASE_TELEMETRY_DISABLED=1`, `DO_NOT_TRACK=1`) stop events on the normal path, but five paths still sent or re-enabled after a user had opted out. I closed those paths, removed the user-chosen project name from the project group, and corrected the notice and docs. **Changed:** - **`telemetry disable` reported the opt-out, and could write it to the wrong place**: consent is read before the handler writes the file, so the command sent its own `cli_command_executed`. It now sends nothing (this reverses supabase#5798 for `disable` only; the Go CLI behaviour it matched no longer exists). `telemetry enable` and `disable` also resolved `SUPABASE_HOME` from the shell alone while the CLI reads consent from the settings, so with `SUPABASE_HOME` in a project `.env` the opt-out landed in a directory nothing read. All state reads and writes now use the runtime's resolved directory. - **A damaged or unreadable `telemetry.json` re-enabled telemetry**: a file that could not be read or decoded counted as "no file", and the next write regenerated it as enabled. It now reads as an opt-out, and undecodable content is rewritten as one. Only a missing or empty file is a first run. A home directory that cannot be searched and a file with an empty device or session id read as an opt-out too. The per-command state writes used to overwrite the file in place, so a run killed mid-write left an empty file that read as a first run. They now go through a temporary file and a rename. The one-time write that stores the account id after the first authenticated response still writes in place. - **Env opt-outs left state behind and `telemetry status` ignored them**: every command wrote an enabled `telemetry.json` under `DO_NOT_TRACK=1`, which later suppressed the first-run notice. While opted out the CLI now updates an existing file but creates none, and `status` reports the run as disabled. - **The first interactive run sent before the user could react**: the notice printed in the same invocation as the first event. That invocation now sends nothing, and sending starts with the next one. `config convert --to toml` skips its telemetry-only reason question on that run, since the answer would be dropped. Non-interactive first runs are unchanged. The notice no longer says "anonymous", and project groups send the organization slug without the project name. **Note:** several existing tests asserted the old behaviour as intended (regenerate a malformed file as enabled, `disable` emits its event, `status` creates the file or repairs a corrupted one). I changed those assertions on purpose, removed the status test for regenerating identity from a file with a malformed field because `status` no longer writes, and changed the e2e status tests to run without the harness's env opt-out so they read the file's consent. Two measurement effects for opted-in users follow from the first-run change: `is_first_run = true` no longer appears together with `is_tty = true`, and a first interactive `supabase login` persists the account id without sending the alias, which loses nothing because that device has no earlier events to merge. ## Linear - part of GROWTH-1573
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce?
Bug fix (Go parity).
What is the current behavior?
Go's
cli_command_executedtelemetry 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, includingtelemetry enable/disablethemselves.The TS legacy port instead unconditionally suppressed this event for both
telemetry enableandtelemetry disableviaanalytics: false, so neither command ever fired it, regardless of prior telemetry state.What is the new behavior?
analytics: falseis removed from both commands. The existinglegacyAnalyticsLayer/telemetryRuntimeLayermachinery already reads consent from disk once, at Effect layer-construction time — before either handler mutatestelemetry.json— so this reproduces Go's snapshot semantics without any new bespoke logic:disablewhile telemetry is enabled fires the event one last time (using the pre-toggle, still-enabled snapshot); running it while already disabled stays silent.enablewhile 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'scanSend()) showed it's symmetric and state-based, not command-based, so scoping the fix todisablealone would have left a real (if narrow) parity gap for the redundant-enablecase.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