Skip to content

SCA-91: make account deletion durable before auth removal - #10444

Merged
Git-on-my-level merged 2 commits into
mainfrom
agent/m1-studio-codex-terra/96f2b066
Jul 25, 2026
Merged

Git-on-my-level merged 2 commits into
mainfrom
agent/m1-studio-codex-terra/96f2b066

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

Summary

Account deletion now has one durable, fenced authority. The request persists intent before queue acceleration and makes no irreversible billing or Firebase Auth mutation. The claimed worker owns billing cancellation, Auth deletion, external purges, Firestore deletion, and completion.

Only the matching wipe_job_id can transactionally promote deleting_auth to pending and enqueue. Repeat requests preserve pending, retrying, running, failed, and completed state and do not create another task. A retry can recover the narrow deleting_auth handoff; concurrent promotions are fenced so only one dispatches.

After durable intent is committed, queue failure returns the existing compatible 200 acceptance response, marks the intent failed, and relies on reconciliation for eventual completion. It no longer returns 500 while retaining actionable deletion authority.

Failure class (fixes)

Failure-Class: FC-split-mutation-authority

The request handler previously split destructive authority across itself and the queue worker. This change converges destructive transitions behind the claimed worker and persisted job-scoped marker.

Authority ordering

Request → create/join durable intent → atomically promote matching job to pending → queue acceleration. Claimed worker → running → billing → Firebase Auth → external purge → Firestore wipe → completed.

Product invariants affected

These IDs are named solely for the older, unrelated desktop paths in this PR’s full merge-base diff; this deletion follow-up does not alter them.

  • INV-AGENT-*
  • INV-AUTH-1
  • INV-CHAT-1
  • INV-VOICE-1

Verification

  • RED: the production-shaped Cloud Tasks route test reproduced running → pending plus a duplicate task; queue NotFound returned 500 with an actionable marker.
  • GREEN: backend/.venv/bin/python -m pytest backend/tests/services/users/test_account_deletion.py backend/tests/routers/test_users.py backend/tests/unit/test_delete_account_stripe_cancel.py backend/testing/e2e/test_account_deletion_cloud_tasks.py -q — 59 passed.
  • GREEN: backend/.venv/bin/pyright backend/services/users/account_deletion.py — 0 errors, 0 warnings.
  • GREEN: OMI_PR_BODY_FILE=pr-body.md make preflight — local selected checks passed (advisory size warnings only).
  • CI at deaae3a4889751faa65d65f135303aaa14f14c73: deletion-specific and metadata/stack checks passed, but the full PR remains red on unrelated merge-base coverage: tests/unit/test_action_item_date_validation.py and tests/unit/test_lock_bypass_fixes.py have pre-existing langchain_core.messages test-isolation/import failures; Desktop Swift Build & Tests is also red in the older desktop diff. This follow-up intentionally does not broaden FC-split-mutation-authority scope to modify those subsystems.

Rollback

Revert the two account-deletion commits. No schema, queue, IAM, deployment, or production-data change is included.

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: 558e826240

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

@Git-on-my-level

Copy link
Copy Markdown
Member Author

Independent exact-head review of PR #10444 (558e82624099b69b9341cba72a7e23c30fd8ba24) found two behavioral blockers plus one CI blocker. Please fix on the same PR branch, add the regressions below, rerun focused/preflight/CI, update the PR body/head evidence, and return SCA-91 to in_review only when green.

1. P1: repeat request moves a live wipe backwards and dispatches a duplicate task

mark_user_deletion_wipe_intent() correctly reuses the existing job id for pending/retrying/running/failed/completed, but start_account_deletion() then unconditionally calls mark_user_deletion_wipe_started(), whose plain merge changes every one of those states back to pending, and it enqueues again. This contradicts the PR's monotonic/idempotent claim.

I proved this on the exact PR head with a production-shaped route test:

  1. First DELETE /v1/users/delete-account -> pending.
  2. Claim the task and move the marker to running.
  3. Send a second authenticated delete request before worker auth removal.
  4. Expected: marker remains running, one Cloud Task total.
  5. Actual: marker becomes pending; the assertion fails ('pending' != 'running') and a second task is created.

Fix the shared transition atomically/job-id-conditionally. A repeated API request must join the existing authority without moving retrying/running/completed backwards or enqueueing another task. Add this exact route-level regression and concurrent/repeated-request coverage.

2. P1: enqueue failure returns 500 but remains authorized for later destructive deletion

The new queue-NotFound E2E explicitly expects HTTP 500, leaves marker failed, then reconciliation immediately claims it and eventually deletes billing/Auth/data. That means the caller is told deletion failed (Could not delete account. Please try again) but the account may still be irreversibly deleted later. This is still an acknowledgment/authority split and can surprise a user who stops after the 500.

Choose one coherent contract and test it end to end:

  • preferred: once actionable durable intent is committed, queue dispatch is acceleration; return accepted/success (200/202 under current client compatibility) even if enqueue fails, and prove reconciliation owns eventual completion; or
  • if returning 500, transition to a non-actionable/cancelled state so reconciliation cannot later delete.

Do not keep 500 + actionable failed marker.

3. CI is red on PR-specific pyright

Backend unit suite fails at backend/services/users/account_deletion.py:173: reportUnnecessaryIsInstance on wipe_result. Fix without suppressing a real type contract. Current PR is therefore not merge-ready.

Verified positives

  • Independently reran the exact-head focused suite: 57 passed in 4.43s.
  • Hermetic Backend E2E and merge gate are green.
  • Moving billing/Auth/data behind the claimed worker is the correct root direction.
  • Structured wipe errors and missing-root child deletion now have useful regression coverage.

Do not merge or deploy. Preserve the same focused PR and failure class FC-split-mutation-authority.

@Git-on-my-level

Copy link
Copy Markdown
Member Author

Both trusted review threads were verified as already addressed by commit fence duplicate deletion dispatch (the second PR commit, pushed after the comments landed):

  • P1 (stale Stripe cancellation tests): test_delete_account_stripe_cancel.py now asserts start_account_deletion() does NOT call get_user_subscription, cancel_subscription, or auth.delete_account — confirming billing/Auth work moved to background_wipe_user_data().
  • P2 (resetting live deletion jobs to pending): mark_user_deletion_wipe_intent() now returns dispatch_claimed, and mark_user_deletion_wipe_started(uid, wipe_job_id) is transactional + job-id-fenced — only an exact-matching deleting_auth record is promoted to pending, preventing a live running/retrying/completed job from moving backwards or dispatching a duplicate task.

Verified locally: 34 test_account_deletion.py + 3 test_delete_account_stripe_cancel.py = 37 passed (0.05s) via the test.sh runner.

The two failing CI checks (Backend unit suite, Desktop Swift) are unrelated to this PR: the unit failure is a pre-existing ModuleNotFoundError: No module named 'langchain_core.messages' in test_action_item_date_validation.py, and the Swift checks fail on a no-Swift-changes path filter — neither file is touched by this PR.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

SCA-91 make account deletion durable before auth removal — approve only (DIRTY + auth-sensitive)

Reconstructed clean from PR diff onto origin/main (original branch
had unrelated history with no merge base).
@Git-on-my-level
Git-on-my-level force-pushed the agent/m1-studio-codex-terra/96f2b066 branch from deaae3a to b9ea539 Compare July 24, 2026 23:19
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Rebased onto latest main and reconstructed the PR from a clean diff. The original branch (agent/m1-studio-codex-terra/96f2b066) had unrelated Codex agent history with no merge base to main — the single commit contained 10k+ files. Rebuilt from origin/main with only the PR's 7 actual files (account deletion service, database, tests, line-count baseline). Applied black formatting to match CI.

All checks green: backend unit suite, OpenAPI contract, static contracts.

@Git-on-my-level
Git-on-my-level merged commit 158a4f9 into main Jul 25, 2026
35 checks passed
@Git-on-my-level
Git-on-my-level deleted the agent/m1-studio-codex-terra/96f2b066 branch July 25, 2026 01:58
Git-on-my-level added a commit that referenced this pull request Aug 4, 2026
…ks (#11029)

## Summary

- Make the durable `account_deletions/{uid}` marker a single fail-closed
admission policy across Firebase, developer/MCP keys, OAuth issuance,
HTTP/WebSocket entry points, Agent proxy sessions, and Agent VM
provisioning. Completed and unknown markers remain fenced so an old
token cannot revive a deleted UID.
- Make deletion admission atomic at `pending`, revoke UID-bearing
API/OAuth credentials, delete the account's GCE Agent VM before its
Firestore pointer disappears, and transactionally fence late proxy/VM
writes so in-flight work cannot recreate owner data.
- Make accepted macOS cleanup durable across restart, drain owner-bound
VM/sync work before deleting storage, remove the legacy anonymous
fallback, upload a consistent SQLite snapshot with cancellable
compression and bounded retries, and preserve typed startup errors in
Flutter.

Repeated delete requests during `pending`/`running` intentionally
receive typed `403 account_deletion_in_progress` responses without
marker rollback or requeue. The deletion fence is preserved.

Canonical project: [BasedHardware Project
#15](https://github.com/orgs/BasedHardware/projects/15)

## Sanitized incident evidence

- A delete confirmation preceded a later same-provider
sign-in/onboarding sequence by nine days.
- The deleted UID's user document and GCE instance were gone, while its
durable deletion marker completed after retried queue acceleration
failures.
- No verified event proves old server memory reads after deletion. This
PR treats legacy local-database migration, still-valid old credentials,
and late owner-scoped work as identity-isolation risks; typed readiness
failures remain timeout-class evidence rather than proof of server data
disclosure.

Related lineage: #10444, #7696, #9632, #10597, #9821, #6891, #6892,
#10600, and #10694.

## Failure class

Failure-Class: none

This is an audit-driven hardening sweep across durable deletion
admission, credential revocation, local owner-data disposal, and Agent
VM/proxy lifecycle safety. The reusable prevention surfaces are the
shared fail-closed policy, transactional admission/CAS writers, the
durable local cleanup journal, the effective-owner generation fence, and
behavioral regression tests.

## Product invariants affected

- INV-AUTH-1 — preserves the exclusive effective-owner transition,
clears accepted-deletion storage before credential/session publication,
blocks every credential family after durable admission, and rejects late
owner-bound Agent VM continuations.
- INV-CHAT-1 — drains Agent VM/sync work at the existing owner
transition, transactionally fences late proxy message/session writes,
and preserves typed startup failures without changing canonical
transcript ownership.

## Changed paths

-
`.github/scripts/product_file_line_count_ratchet_baseline/backend-database.json`
-
`.github/scripts/product_file_line_count_ratchet_baseline/backend-routers.json`
-
`.github/scripts/product_file_line_count_ratchet_baseline/desktop-swift-root.json`
- `app/lib/services/agent_chat_service.dart`
- `app/test/services/agent_chat_service_test.dart`
- `backend/agent-proxy/Dockerfile`
- `backend/agent-proxy/main.py`
- `backend/database/account_deletion_projection_fence.py`
- `backend/database/mcp_oauth.py`
- `backend/database/users.py`
- `backend/dependencies.py`
- `backend/routers/apps.py`
- `backend/routers/desktop_agent_vm.py`
- `backend/routers/mcp_sse.py`
- `backend/routers/oauth.py`
- `backend/routers/transcribe.py`
- `backend/services/users/account_deletion.py`
- `backend/testing/e2e/test_account_deletion_cloud_tasks.py`
- `backend/tests/services/users/test_account_deletion.py`
- `backend/tests/unit/test_account_deletion_auth_fence.py`
- `backend/tests/unit/test_agent_proxy_async_boundaries.py`
- `backend/tests/unit/test_agent_proxy_startup_client_gone.py`
- `backend/tests/unit/test_byok_security.py`
- `backend/tests/unit/test_dependency_async_boundaries.py`
- `backend/tests/unit/test_desktop_agent_vm.py`
- `backend/tests/unit/test_mcp_api_key_auth_context.py`
- `backend/tests/unit/test_mcp_oauth.py`
- `backend/tests/unit/test_oauth_token_async_boundaries.py`
- `backend/utils/account_deletion_access.py`
- `backend/utils/other/endpoints.py`
- `desktop/macos/Desktop/Sources/AgentSyncService.swift`
- `desktop/macos/Desktop/Sources/AgentVMService.swift`
- `desktop/macos/Desktop/Sources/AuthService.swift`
- `desktop/macos/Desktop/Sources/Chat/RuntimeOwnerIdentity.swift`
- `desktop/macos/Desktop/Sources/DefaultsKey.swift`
- `desktop/macos/Desktop/Sources/DesktopAutomationBridge.swift`
-
`desktop/macos/Desktop/Sources/MainWindow/Pages/Settings/Components/SettingsContentView+SettingsUpdates.swift`
-
`desktop/macos/Desktop/Sources/Rewind/Core/RewindDatabase+AccountDeletion.swift`
- `desktop/macos/Desktop/Tests/AgentSyncBatchQueryTests.swift`
- `desktop/macos/Desktop/Tests/AgentVMLifecycleFenceTests.swift`
- `desktop/macos/Desktop/Tests/AuthSessionCoordinatorTests.swift`
- `desktop/macos/Desktop/Tests/OnboardingPersistenceClearingTests.swift`
- `desktop/macos/Desktop/Tests/RewindDatabaseLifecycleTests.swift`
-
`desktop/macos/changelog/unreleased/20260802-account-deletion-local-data.json`
- `desktop/macos/e2e/flows/logout.yaml`

## Verification

- Focused backend deletion/auth/proxy/VM suite: `194 passed`.
- Hermetic Cloud Tasks deletion suite: `5 passed`; repeated
pending/running requests are asserted as typed `403` without requeue.
- Focused macOS deletion, owner-fence, snapshot, and sync suite: `32
tests`, `0 failures`.
- Focused Flutter Agent Chat suite: `2 passed`.
- Follow-up MCP OAuth consent suite: `37 passed`.
- Follow-up macOS cleanup/bridge compile suite: `17 tests`, `0
failures`.
- Python runtime sources compile cleanly; pinned Python/Dart/Swift
formatters and `git diff --check` are clean.
- Required CI-lane PR-body preflight: `34 checks passed` in `108.01s`.

Backend Hermetic Merge Gate: in scope because backend runtime and
hermetic contract code changed.

## Limitations

- No production Firebase/Auth, Firestore, Cloud Tasks, GCE, deployment,
release, or customer-data mutation was performed.
- Same-provider recreation is covered hermetically at the UID/auth
boundary; no live Google sign-in was attempted.
- Agent readiness and teardown are covered through backend
state-machine, proxy protocol, owner-generation, snapshot/upload,
credential cleanup, and stale-pointer tests; no live GCE VM was
provisioned.

<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/11029?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
undivisible pushed a commit to undivisible/omi that referenced this pull request Sep 29, 2026
…are#10444)

## Summary

Account deletion now has one durable, fenced authority. The request
persists intent before queue acceleration and makes no irreversible
billing or Firebase Auth mutation. The claimed worker owns billing
cancellation, Auth deletion, external purges, Firestore deletion, and
completion.

Only the matching `wipe_job_id` can transactionally promote
`deleting_auth` to `pending` and enqueue. Repeat requests preserve
`pending`, `retrying`, `running`, `failed`, and `completed` state and do
not create another task. A retry can recover the narrow `deleting_auth`
handoff; concurrent promotions are fenced so only one dispatches.

After durable intent is committed, queue failure returns the existing
compatible 200 acceptance response, marks the intent `failed`, and
relies on reconciliation for eventual completion. It no longer returns
500 while retaining actionable deletion authority.

## Failure class (fixes)

Failure-Class: FC-split-mutation-authority

The request handler previously split destructive authority across itself
and the queue worker. This change converges destructive transitions
behind the claimed worker and persisted job-scoped marker.

## Authority ordering

Request → create/join durable intent → atomically promote matching job
to `pending` → queue acceleration. Claimed worker → `running` → billing
→ Firebase Auth → external purge → Firestore wipe → `completed`.

## Product invariants affected

These IDs are named solely for the older, unrelated desktop paths in
this PR’s full merge-base diff; this deletion follow-up does not alter
them.

- INV-AGENT-*
- INV-AUTH-1
- INV-CHAT-1
- INV-VOICE-1

## Verification

- RED: the production-shaped Cloud Tasks route test reproduced `running
→ pending` plus a duplicate task; queue NotFound returned 500 with an
actionable marker.
- GREEN: `backend/.venv/bin/python -m pytest
backend/tests/services/users/test_account_deletion.py
backend/tests/routers/test_users.py
backend/tests/unit/test_delete_account_stripe_cancel.py
backend/testing/e2e/test_account_deletion_cloud_tasks.py -q` — 59
passed.
- GREEN: `backend/.venv/bin/pyright
backend/services/users/account_deletion.py` — 0 errors, 0 warnings.
- GREEN: `OMI_PR_BODY_FILE=pr-body.md make preflight` — local selected
checks passed (advisory size warnings only).
- CI at `deaae3a4889751faa65d65f135303aaa14f14c73`: deletion-specific
and metadata/stack checks passed, but the full PR remains red on
unrelated merge-base coverage:
`tests/unit/test_action_item_date_validation.py` and
`tests/unit/test_lock_bypass_fixes.py` have pre-existing
`langchain_core.messages` test-isolation/import failures; `Desktop Swift
Build & Tests` is also red in the older desktop diff. This follow-up
intentionally does not broaden FC-split-mutation-authority scope to
modify those subsystems.

## Rollback

Revert the two account-deletion commits. No schema, queue, IAM,
deployment, or production-data change is included.

<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/10444?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
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