Skip to content

fix(cli): resolve global/persistent flag values in legacy telemetry#5830

Merged
Coly010 merged 3 commits into
developfrom
columferry/cli-1896-legacy-telemetry-doesnt-record-globalpersistent-flags-eg
Jul 9, 2026
Merged

fix(cli): resolve global/persistent flag values in legacy telemetry#5830
Coly010 merged 3 commits into
developfrom
columferry/cli-1896-legacy-telemetry-doesnt-record-globalpersistent-flags-eg

Conversation

@Coly010

@Coly010 Coly010 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

What changed

Go's changedFlags(cmd) (apps/cli-go/cmd/root_analytics.go:52-76) walks cmd.Parent() at every ancestor collecting PersistentFlags() (global/root flags: --debug, --yes, --experimental, --create-ticket, --output, --dns-resolver, --agent, --profile, --workdir, --network-id) in addition to a command's own flags, then reports booleans and enum-typed flags verbatim in cli_command_executed telemetry.

The TS port's withLegacyCommandInstrumentation had no way to resolve any global/persistent flag's value — only the invoking command's own locally-declared flags option was ever consulted. So a changed global flag always fell back to the literal string "<redacted>", even a boolean like --debug, diverging from Go's flags: {debug: true}.

This adds legacyGlobalFlagValues (shared/legacy/global-flags.ts) to resolve every global flag's live value via Effect.serviceOption (a no-op outside the real CLI tree, so it adds no R requirement and no per-command wiring), and threads it into buildFlagsMap as a fallback used only when a changed CLI flag name isn't already declared in the invoking command's own flags record — mirroring Go's ancestor-walk precedence (a command's own flag always wins on a name collision, e.g. db diff's local --output file-path flag shadowing the global --output enum, exactly as it does in Go's cobra tree).

safeFlags/config-based safety classification is now restricted to values that actually came from the handler's own flags record, so a future per-command safe/choice annotation can never be misapplied to an unrelated global flag's value purely by CLI-name collision (raised in review).

Scope is deliberately narrow: this fixes the 4 boolean globals (--debug, --yes, --experimental, --create-ticket) immediately. The 3 global choice flags (--output, --dns-resolver, --agent) remain redacted — that gap is the already-tracked CLI-1904, not this ticket.

Fixes CLI-1896.

Why

Found during CLI-1868's review (architect-reviewer finding) as a systemic gap affecting all ~73 withLegacyCommandInstrumentation({ flags }) call sites — it was previously unreachable for telemetry enable/disable specifically (hardcoded to analytics: false), but CLI-1868 made it reachable there, surfacing the gap.

Reviewer-relevant context

  • One judgement call deliberately left open: global choice flags (--output/--dns-resolver/--agent) still redact. This is intentional — CLI-1904 already tracks teaching the safety pipeline about global EnumFlags, and folding it into this change would blur two independent tickets.
  • Heads-up for whoever owns the CLI PostHog dashboards: flags.debug (and yes/experimental/create-ticket) will now emit real booleans going forward instead of the literal string "<redacted>" for these four flags specifically. Any saved insight/funnel doing exact-string matching on "<redacted>" for these keys will stop matching after this ships.

…CLI-1896)

Go's changedFlags() walks cmd.Parent()'s PersistentFlags() in addition to a
command's own flags, so a global boolean flag like --debug reports its real
value in cli_command_executed telemetry. The TS port's
withLegacyCommandInstrumentation had no way to resolve any global/persistent
flag (shared/legacy/global-flags.ts) at all, so a changed global flag always
fell back to "<redacted>" -- even --debug/--yes/--experimental/--create-ticket,
which Go always shows verbatim via its boolean-is-safe rule.

Add legacyGlobalFlagValues (shared/legacy/global-flags.ts) to resolve every
global flag's live value, and thread it into buildFlagsMap as a fallback used
only when a changed CLI flag name isn't already declared in the invoking
command's own flags record -- mirroring Go's ancestor-walk precedence (a
command's own flag always wins, e.g. db diff's local --output shadowing the
global --output enum). Restrict safeFlags/config-based safety classification
to values that actually came from the handler's own flags record, so a
future per-command safe/choice annotation can never be misapplied to an
unrelated global flag's value purely by CLI-name collision.

Scope is deliberately narrow: this fixes the 4 boolean globals; the 3 global
choice flags (--output/--dns-resolver/--agent) remain redacted, matching the
existing carve-out for CLI-1904.
@Coly010

Coly010 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@Coly010

This comment was marked as off-topic.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 08602fa5f0

ℹ️ 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".

Comment thread apps/cli/src/legacy/telemetry/legacy-command-instrumentation.ts
Comment thread apps/cli/src/legacy/telemetry/legacy-command-instrumentation.ts
@Coly010 Coly010 self-assigned this Jul 8, 2026
Coly010 added 2 commits July 8, 2026 17:54
…review: #5830)

Go's changedFlags() reports the canonical flag name for a persistent flag's
shorthand too (pflag.Visit), but extractChangedFlagNames only consulted each
command's own aliases map, so `-o json` never resolved to `output` and the
CLI-1896 global-flag fallback silently dropped it. Derive a short-alias map
from LEGACY_GLOBAL_FLAGS itself (today just `-o` -> `output`, cmd/root.go:330)
and merge it ahead of each command's own aliases.
…ated global flags (review: #5830)

A local value-consuming flag not listed in VALUE_CONSUMING_LONG_FLAGS/
VALUE_CONSUMING_SHORT_FLAGS made extractChangedFlagNames mis-scan its raw
space-separated value as a separate flag name (e.g. `secrets set --env-file
--debug`, where pflag consumes the literal token `--debug` as --env-file's
value). Previously harmless, the CLI-1896 global-flag fallback now turns that
stray name into a fabricated `flags.debug` value Go never records. Extend both
sets to cover every value-consuming flag declared across legacy/commands/ and
add a static completeness test so a future command that adds one and forgets
to register it fails CI.
@Coly010

Coly010 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 98e3da5e19

ℹ️ 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 marked this pull request as ready for review July 9, 2026 08:53
@Coly010 Coly010 requested a review from a team as a code owner July 9, 2026 08:53
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Supabase CLI preview

npx --yes https://pkg.pr.new/supabase/cli/supabase@98e3da5e1905e20e5675582963a259f8655bda3b

Preview package for commit 98e3da5.

@Coly010 Coly010 added this pull request to the merge queue Jul 9, 2026
Merged via the queue into develop with commit f590487 Jul 9, 2026
42 checks passed
@Coly010 Coly010 deleted the columferry/cli-1896-legacy-telemetry-doesnt-record-globalpersistent-flags-eg branch July 9, 2026 09:52
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