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

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