Skip to content

feat(api): PII scrubbing Phase 3b — historical backfill CLI - #475

Merged
unjica merged 3 commits into
developfrom
feat/pii-scrubbing-phase3b-backfill
Jul 16, 2026
Merged

unjica merged 3 commits into
developfrom
feat/pii-scrubbing-phase3b-backfill

Conversation

@unjica

@unjica unjica commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

Implements the remaining historical backfill work from #470.

  • Opt-in CLI pnpm --filter api pii-scrub-backfill (requires --project-id or --org-id; no global runs)
  • Scrubs stored events (properties), occurrences (stack/context), groups (message/top_stack)
  • Sessions only with both --include-sessions and project scrubSessionUserEmail
  • Fingerprints unchanged by default; --scrub-fingerprints is opt-in and skips unique conflicts
  • Human summary + JSON output; progress on stderr; non-zero exit on DB failures / fatal errors

Safety verification

Check Status
Opt-in only; scope required ✅
--dry-run never writes ✅
Scanned / modified / skipped / fingerprint conflicts / DB errors reported ✅
Idempotent re-runs (placeholders stable) ✅
Partial DB failures continue (unless --fail-fast) ✅
Batched cursor reads; per-row updates (interrupt-safe for committed rows) ✅
Sessions never touched without dual opt-in ✅
Fingerprints not modified by default ✅

Example summary:

Scanned:
- Events: 15000
- Occurrences: 3500
- Groups: 180
- Sessions: 42

Modified:
- Events: 812
- Occurrences: 114
- Groups: 12
- Sessions: 6

Skipped:
- Already scrubbed: 917
- Fingerprint conflicts: 2

Failures:
- Database errors: 0

Completed successfully.

Final #470 status

After this PR merges, #470 is complete for:

  • Phase 1 ingest scrubbing
  • Phase 2 SDK scrubbing and project controls
  • Phone and payment-card heuristics
  • Audit logging
  • Session email scrubbing
  • Historical backfill

Track separately (not in this PR):

  • custom regex controls
  • organization-level settings

Please close #470 after merge (do not use Closes here so merge can proceed independently of follow-up issues).

Test results

pnpm lint                         ✅
pnpm --filter api test            ✅  638 passed | 58 skipped
pnpm --filter api build           ✅

Test plan

  • pnpm --filter api pii-scrub-backfill -- --help
  • --dry-run --project-id … shows scanned/modified with no DB writes
  • Apply run then re-run → modified≈0, already scrubbed increases
  • --include-sessions without project flag → sessions untouched
  • --scrub-fingerprints with colliding fingerprints → conflict count > 0, group associations intact

Made with Cursor

Add a scoped, idempotent backfill job with dry-run reporting,
batched per-row updates, optional session/fingerprint scrubbing,
and resilient partial-failure handling.

Co-authored-by: Cursor <[email protected]>

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 692799e. Configure here.

Comment thread apps/api/src/jobs/pii-scrub-backfill.ts Resolved
Comment thread apps/api/src/jobs/pii-scrub-backfill.ts Resolved
unjica and others added 2 commits July 16, 2026 21:08
Require exactly one of --project-id/--org-id and exit non-zero when
the resolved project query is empty so operators cannot mistake a no-op
for a successful scrub.

Co-authored-by: Cursor <[email protected]>
Share the per-table row budget across projects under --org-id so
limit is not multiplied by project count. Empty-scope failure was
already fixed on this branch.

Co-authored-by: Cursor <[email protected]>
@unjica
unjica merged commit 232fb72 into develop Jul 16, 2026
5 checks passed
@unjica
unjica deleted the feat/pii-scrubbing-phase3b-backfill branch July 16, 2026 19:16
@unjica unjica added this to the v1.12.x — PII scrubbing milestone Jul 17, 2026
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.

PII scrubbing for ingest and stored telemetry

1 participant