Repository navigation
fix(backend): cascade every subcollection when a conversation is deleted - #10597
Merged
kodjima33 merged 2 commits intoJul 26, 2026
Merged
Conversation
delete_conversation() purged only the `photos` subcollection before deleting the document. Firestore does not cascade, and a conversation owns more children than photos: the per-provider post-processing transcripts (deepgram_streaming / soniox_streaming / speechmatics_streaming / fal_whisperx, which store verbatim TranscriptSegment text), the Hume emotion predictions, and the analytics_markers marker added by the memory-extraction telemetry. Everything but photos therefore survived a user deleting a conversation — and survived it permanently: the account-deletion wipe walks *existing* documents (`limit().stream()`), and a deleted conversation is not one, so its orphaned children are unreachable by both the delete endpoint and "delete my account". Enumerate the children live (`conversation_ref.collections()`) and purge each one recursively, so any subcollection added later is covered by construction. The recursive purge that account deletion already used moves to database/_client as `delete_collection_recursive(ref, client=...)` and is now shared by both callers instead of being duplicated. ## Verification - backend/tests/unit/test_delete_conversation_cascade.py (new, 3 tests): 2 of 3 fail against the pre-fix delete_conversation (the transcript segments and the analytics marker survive; nested children are left dangling) and all 3 pass on the fix. - Full backend unit suite via `backend/test.sh` (740 files, per-file processes): exit 0. - Adjacent suites re-run individually: test_account_deletion.py (34), test_delete_account_purge_storage.py (5), test_conversation_recordings_purge.py, test_merge_conversations_canonical_delete.py, test_listen_fallback_removal.py, test_dev_api_lock_bypass.py, test_developer_from_segments_idempotency.py, test_conversation_memories_telemetry.py (18) — all pass. Failure-Class: none
Six unit modules replace database._client with a hand-built stub that enumerates exactly what production imports from it. Moving the recursive subcollection purge into that module added a name none of them carried, so importing database.users raised ImportError at collection time.
kodjima33
force-pushed
the
watchdog/delete-conversation-subcollection-cascade
branch
from
July 26, 2026 12:18
0c52aee to
451e832
Compare
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
…ted (BasedHardware#10597) * fix(backend): cascade every subcollection when a conversation is deleted delete_conversation() purged only the `photos` subcollection before deleting the document. Firestore does not cascade, and a conversation owns more children than photos: the per-provider post-processing transcripts (deepgram_streaming / soniox_streaming / speechmatics_streaming / fal_whisperx, which store verbatim TranscriptSegment text), the Hume emotion predictions, and the analytics_markers marker added by the memory-extraction telemetry. Everything but photos therefore survived a user deleting a conversation — and survived it permanently: the account-deletion wipe walks *existing* documents (`limit().stream()`), and a deleted conversation is not one, so its orphaned children are unreachable by both the delete endpoint and "delete my account". Enumerate the children live (`conversation_ref.collections()`) and purge each one recursively, so any subcollection added later is covered by construction. The recursive purge that account deletion already used moves to database/_client as `delete_collection_recursive(ref, client=...)` and is now shared by both callers instead of being duplicated. ## Verification - backend/tests/unit/test_delete_conversation_cascade.py (new, 3 tests): 2 of 3 fail against the pre-fix delete_conversation (the transcript segments and the analytics marker survive; nested children are left dangling) and all 3 pass on the fix. - Full backend unit suite via `backend/test.sh` (740 files, per-file processes): exit 0. - Adjacent suites re-run individually: test_account_deletion.py (34), test_delete_account_purge_storage.py (5), test_conversation_recordings_purge.py, test_merge_conversations_canonical_delete.py, test_listen_fallback_removal.py, test_dev_api_lock_bypass.py, test_developer_from_segments_idempotency.py, test_conversation_memories_telemetry.py (18) — all pass. Failure-Class: none * test(backend): teach database._client stubs the shared recursive delete Six unit modules replace database._client with a hand-built stub that enumerates exactly what production imports from it. Moving the recursive subcollection purge into that module added a name none of them carried, so importing database.users raised ImportError at collection time.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
Deleting a conversation left most of its child data in Firestore permanently.
database.conversations.delete_conversation()purged only thephotossubcollection and then deleted the document. Firestore does not cascade, and a conversation owns more children than photos:deepgram_streaming/soniox_streaming/speechmatics_streaming/fal_whisperx— the per-provider post-processing transcripts written bystore_model_segments_result, i.e. verbatimTranscriptSegmenttextstore_model_emotion_predictions_resultanalytics_markers/conversation_memories_extracted— the marker added five hours ago by feat(desktop): instrument macOS memory activation and extraction outcomes #10543 (try_claim_conversation_memory_analytics), so every conversation with extracted memories now grows oneEverything but photos survived
DELETE /v1/conversations/{id}— and survived it permanently.users.delete_user_data()walks each collection withlimit().stream(), which returns only existing documents; a deleted conversation is not one, so the wipe never descends into the orphans it left behind. Neither the delete endpoint nor "delete my account" can reach that data afterwards.Fix
delete_conversation()now enumerates the conversation's children live (conversation_ref.collections()) and purges each recursively before deleting the document, so a subcollection added later is covered by construction rather than by remembering to add another special case.The recursive purge account deletion already used moves to
database/_client.pyasdelete_collection_recursive(ref, *, client)and is shared by both callers instead of being duplicated.delete_conversation_photos()is unchanged — its other callers (lifecycle.py,merge_conversations.py) still use it.What I tested
backend/tests/unit/test_delete_conversation_cascade.py(3 tests) — drives productiondelete_conversationagainst an in-memory Firestore fake. 2 of 3 fail on the pre-fix code (the transcript segments and the analytics marker survive; a nested child is left dangling) and all 3 pass on the fix.backend/test.sh(740 files, one process per file): exit 0.test_account_deletion.py(34),test_delete_account_purge_storage.py(5),test_conversation_recordings_purge.py,test_merge_conversations_canonical_delete.py,test_listen_fallback_removal.py,test_dev_api_lock_bypass.py,test_developer_from_segments_idempotency.py,test_conversation_memories_telemetry.py(18) — all pass.make preflightgreen.Not exercised against live Firestore (no prod write from a watchdog run); the behaviour is proven through the production code path with the storage layer faked.
Known follow-up (not in this PR)
Conversations deleted before this lands still have orphaned children, and account deletion cannot see them because its walk is query-based. Reaching those needs
list_documents()(which does return references to non-existent parents) in the account-deletion walk — a change to the irreversible wipe path that deserves its own review.Failure-Class: none
🤖 automated by the hourly watchdog — tested and merged