Skip to content

Make account deletion cleanup durable - #9117

Merged
Git-on-my-level merged 8 commits into
mainfrom
codex/issue-8405-durable-account-deletion
Jul 6, 2026
Merged

Git-on-my-level merged 8 commits into
mainfrom
codex/issue-8405-durable-account-deletion

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Jul 6, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes #8405.

  • Moves account-deletion wipes onto durable Cloud Tasks dispatch when ACCOUNT_DELETION_DISPATCH_MODE=cloud_tasks, with API success returned only after the deletion marker is persisted and the wipe task enqueue succeeds.
  • Adds an OIDC-protected account deletion wipe task handler with Redis run-locking, Firestore job-claim gating, cancellation-safe lock handling, and retry/final-attempt responses for Cloud Tasks.
  • Tightens cleanup semantics so required Twilio, vector, recording-storage, and Firestore cleanup failures remain retryable instead of being hidden by a completed wipe.
  • Updates account-deletion observability/reconciliation docs and tests.

Validation

  • PYTHON=.venv/bin/python bash test-preflight.sh passed with optional integration warnings only.
  • python -m pytest tests/services/users/test_account_deletion.py tests/routers/test_users.py tests/unit/test_sync_cloud_tasks.py tests/unit/test_delete_account_stripe_cancel.py tests/unit/test_delete_account_purge_storage.py tests/unit/test_twilio_account_deletion.py tests/unit/test_claim_deletion_wipe_txn.py -q -> 91 passed.
  • python scripts/scan_import_time_side_effects.py -> 0 violations.
  • python scripts/scan_async_blockers.py -> 0 selected blocking findings.
  • python scripts/check_module_stub_pollution.py -> 0 violations.
  • python scripts/validate-backend-runtime-env.py --env dev --check-workflows passed.
  • python scripts/validate-backend-runtime-env.py --env prod --check-workflows passed.
  • Oracle review Add printing BLE device address to serial monitor #3: no P0/P1 findings.

Notes

  • scripts/check_response_model_coverage.py still fails on unrelated pre-existing untyped routes in staged_tasks.py.

Review in cubic

@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: ba4d63a9c4

ℹ️ 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 backend/routers/users.py
logger.warning(f'account_deletion handler: non-actionable task for {uid}, claim_status={claim_status}')
return JSONResponse(status_code=200, content={'status': 'dropped', 'reason': claim_status})

ok = await run_blocking(cleanup_executor, background_wipe_user_data, uid)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid marking queued wipes as running

At this point the preceding claim_deletion_wipe_for_task has already changed the marker to running, but the actual wipe is only submitted to cleanup_executor here. If the four cleanup workers are occupied by long deletions, another task can sit queued until the 1500s request timeout and be cancelled before its worker starts; retries then see a fresh running marker and return 409 until the 6-hour stale window, delaying the account wipe. Keep the marker in a queued/retrying state until the cleanup function actually starts, or claim running from inside the worker.

Useful? React with 👍 / 👎.

@cubic-dev-ai cubic-dev-ai 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.

3 issues found across 17 files

Confidence score: 3/5

  • In backend/utils/twilio_service.py, the strict deletion path can treat any delete_caller_id(...)=False as a hard failure, so account-deletion retries may get stuck after a partial Twilio cleanup and never converge. Before merging, make the strict flow idempotent by handling expected Twilio error codes as already-deleted/non-fatal outcomes.
  • In backend/database/users.py, the claim transaction marks a wipe job as running before work actually starts in cleanup_executor via the router handler, which can leave jobs stranded if the executor never picks them up. Add a guard (for example, a heartbeat/timeout requeue or only flipping to running at actual start) before merging.
  • backend/utils/twilio_service.py now has overlapping logic between the new function and delete_user_caller_ids, which raises drift risk if Twilio cleanup behavior changes in one path but not the other. Reduce risk by extracting a shared helper with configurable failure policy so both paths stay consistent.

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread backend/utils/twilio_service.py Resolved
Comment thread backend/database/users.py Resolved
Comment thread backend/utils/twilio_service.py Resolved

@cubic-dev-ai cubic-dev-ai 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.

1 issue found across 6 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread backend/utils/twilio_service.py Resolved

@cubic-dev-ai cubic-dev-ai 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.

1 issue found across 6 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread backend/database/users.py Resolved
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Reviewed the remaining account-deletion wipe thread against the current PR code and did not make a code change.

Finding:

  • The thread says claim_deletion_wipe_for_task marks a task running before it enters cleanup_executor.
  • Current PR code does not do that: _claim_deletion_wipe_task_txn keeps the marker in retrying, and background_wipe_user_data transitions to running only when the cleanup worker starts. That preserves retryability if the HTTP request is cancelled while waiting for a cleanup thread.

Verification:

  • Re-read current PR HEAD for backend/database/users.py and backend/routers/users.py.
  • GitHub checks are green: Backend unit suite, Hermetic Backend E2E, Lint/Format Check, and Public Developer API contract all passed.

No review thread was resolved because no new code change was needed.

@Git-on-my-level
Git-on-my-level merged commit edbe51e into main Jul 6, 2026
6 checks passed
@Git-on-my-level
Git-on-my-level deleted the codex/issue-8405-durable-account-deletion branch July 6, 2026 05:51
Git-on-my-level added a commit that referenced this pull request Jul 15, 2026
## Summary

Closes #9760.

- Makes production account deletion fail closed: a deletion intent is
durably recorded with an opaque wipe job ID before the wipe can be
dispatched, and production startup rejects inline or incomplete Cloud
Tasks configuration.
- Dispatches only the opaque job ID to the dedicated account-deletion
queue; the handler resolves the user server-side and drops unknown,
ambiguous, terminal, and unsupported legacy payloads before any
mutation.
- Adds reconciliation for persisted-but-undispatched intents, validates
the GKE/Cloud Run deployment contract, and gives deletion tasks an
account-deletion-specific OIDC audience.

## Root cause and recurrence

The deletion workflow previously relied on inline execution as a
reachable deployment mode and accepted a payload that could identify a
user directly. A crash or configuration drift between the delete request
and its side effects could therefore leave a deletion incomplete without
a durable, safely replayable dispatch contract.

This follows the same dispatch/reliability failure class addressed in
#5088, #6750, #7640, #8405, #9117, and #9632. The durable guard is now
the persisted wipe-job identity plus production-only Cloud Tasks
configuration validation, queue payload minimization, dedicated OIDC
audience verification, and reconciliation through the same dispatcher.

## Verification

- `cd backend && ENCRYPTION_SECRET=local-test-secret
BACKEND_PYTEST_WORKERS=1 bash test.sh` — passed all 603 isolated
unit-test files.
- `cd backend && PATH="/tmp/omi-predeploy-9760/bin:$PATH" bash
scripts/pre-deploy-check.sh` — passed (69 tests); validates dev/prod
runtime and deploy contracts.
- `make preflight` — passed.
- Exercised the controlled recovery path: persisted intent -> injected
enqueue crash -> reconciler dispatch -> first handler completion ->
repeat delivery no-op. This is covered by
`test_persisted_wipe_recovers_after_enqueue_crash_and_handler_runs_once`.

No live Cloud Task was dispatched because this PR does not authorize a
deployment mutation.

## Review

Sol review completed before opening. It identified an OIDC
audience-isolation issue; the fix uses
`ACCOUNT_DELETION_TASKS_OIDC_AUDIENCE` (defaulting only to the dedicated
deletion handler URL) for both task creation and verification. A second
independent Sol review after rebasing identified the deploy-order
compatibility path for queued legacy UID tasks; the resolved branch
accepts the former sync audience only for those legacy payloads and
drops job-ID payloads before resolution or mutation.
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.

Make account deletion cleanup durable and observable

1 participant