Skip to content

fix(cli): redact two-segment app ids and use a stable install id for telemetry - #2947

Merged
riderx merged 1 commit into
mainfrom
posthog-self-driving/fixcli-redact-2-segment-app-ids-and-fix-a3e2b5
Aug 8, 2026
Merged

fix(cli): redact two-segment app ids and use a stable install id for telemetry#2947
riderx merged 1 commit into
mainfrom
posthog-self-driving/fixcli-redact-2-segment-app-ids-and-fix-a3e2b5

Conversation

@posthog-eu

@posthog-eu posthog-eu Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Two contained telemetry-correctness fixes in cli/src/posthog.ts, both independent.

Why

  • distinct_id was cli:<version>:<command>, not a person — so "users affected" on every CLI error-tracking issue counted version-by-command pairs, and each release minted a fresh synthetic person. Triage read that number as users when it never meant that.
  • The <app_id> scrubber matched only ids with three or more dot-separated segments, so two-segment ids reached the error title raw — App com.phantom already exists. cli/src/analytics/error-category.ts promises telemetry "never leaks error text, paths, or user input"; the exception path must hold to that too.

Changes

Fix Before After
App-id scrubber (?:\.[\w-]+){2,} — needs 3+ segments (?:\.[\w-]+){1,} — redacts two-segment ids too
distinct_id cli:${version}:${command} Anonymous per-install id (UUID), generated once and persisted in the CLI config dir
  • The install id holds no personal data and is stable across releases and commands, so one install equals one person. Version and command name still ship as the cli_version and function_name properties.
  • A read-only or unwritable HOME (CI, sandbox) falls back to an ephemeral id, so telemetry never breaks.

Scope note: the CLI's usage-analytics events (cli/src/analytics/track.ts) are actor-scoped through the Capgo backend by API key and org id — they carry no PostHog distinct_id. capturePosthogException is the only direct PostHog sender in the CLI, so the install id applies there.

Test plan

  • bun run test:posthog-exception — updated to assert the anonymous UUID distinct_id (no version, no command), its persistence, and two-segment app-id redaction (App com.phantom already existsApp <app_id> already exists).
  • bun run cli:lint
  • bun run cli:typecheck
  • bun run cli:build

Screenshots

Not applicable — telemetry payload change only, no user-facing output.

Checklist

  • My code follows the code style of this project and passes
    bun run lint:backend && bun run lint.
  • My change requires a change to the documentation.
  • I have updated the documentation
    accordingly.
  • My change has adequate E2E test coverage.
  • I have tested my code manually, and I have provided steps how to reproduce
    my tests

Agent context


Created with PostHog Desktop from this inbox report.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Review in cubic

…telemetry

Two telemetry-correctness fixes in cli/src/posthog.ts:

- Widen the app-id scrubber from `{2,}` to `{1,}` so two-segment ids
  (com.phantom) get redacted, not only ids with three or more segments.
  Raw customer app ids no longer reach the error-tracking title.
- Replace the `cli:<version>:<command>` distinct_id with an anonymous,
  stable per-install id. It holds no personal data, is generated once and
  persisted in the CLI config directory, and makes "users affected" count
  real installs. The version and command name still ship as the
  cli_version and function_name properties.

Generated-By: PostHog Code
Task-Id: 6afc8b8f-3bdd-416e-8e37-08261732fbce
@riderx
riderx marked this pull request as ready for review August 8, 2026 17:42
@riderx
riderx merged commit 4cd207a into main Aug 8, 2026
38 of 40 checks passed
@riderx
riderx deleted the posthog-self-driving/fixcli-redact-2-segment-app-ids-and-fix-a3e2b5 branch August 8, 2026 17:43
@codspeed-hq

codspeed-hq Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 43 untouched benchmarks
⏩ 2 skipped benchmarks1


Comparing posthog-self-driving/fixcli-redact-2-segment-app-ids-and-fix-a3e2b5 (670fc91) with main (09ad7af)

Open in CodSpeed

Footnotes

  1. 2 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@sonarqubecloud

sonarqubecloud Bot commented Aug 8, 2026

Copy link
Copy Markdown

posthog-eu Bot added a commit that referenced this pull request Aug 9, 2026
A transient database failure in `getUserIdFromApikey` returned null, which the
files service reported as `400 user_not_found`. The CLI showed users a bad-key
message and opened an error-tracking issue for each failure.

Backend:
- `getUserIdFromApikey` now rethrows a query failure instead of returning null,
  so a backend blip surfaces as a 500, not a missing user.
- `checkWriteAppAccess` returns `401 user_not_found` (was 400), matching how
  `invalid_apikey` behaves on the same route.

CLI:
- Add a shared `buildTusUploadError` helper that turns a tus failure into a real
  Error carrying the HTTP status, backend message, and request id. `uploadTUS`
  and the delta path (`partial.ts`) both use it, so the delta path no longer
  rejects the raw tus blob that leaked the URL and per-file object key.
- The attached `.status` and the new `user_not_found` marker let
  `isExpectedUserError` classify the auth failure and skip error tracking.

Merging this fix cuts a CLI release that also carries the earlier fixes (#2885,
#2933, #2934, #2947) that no released build contains yet.

Generated-By: PostHog Code
Task-Id: c66eba6b-af49-4627-84ac-2c007ed83bc0
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