Repository navigation
fix(conversations): reject soft-deleted tombstones in get_conversation_for_capture_check - #20948
Conversation
…n_for_capture_check
Git-on-my-level
left a comment
There was a problem hiding this comment.
Verified against head 938f8fd. This closes a real deleted-data exposure seam in the capture pipeline.
backend/database/conversations.py—get_conversation_for_capture_checkpreviously checked only physical existence, so soft-deleted tombstones (deleted: Truekeeps the Firestore doc,snapshot.existstrue) were decrypted byprepare_conversation_for_readand consumed byduplicate_capture._group_confirmed_capturesandcapture_jev_shadow._run. The transactionaldeletedguard inlink_duplicate_capturefires only later, after the read-and-decrypt step. Reusing the sharedis_soft_deletedpredicate here is the right shape — and correctly distinct fromdiscarded, which deliberately stays revivable.backend/tests/unit/test_capture_check_tombstone_guard.py— solid regression coverage through the real seam (StrictFirestorerows rather than mocking the module), including parametrized truthy tombstone values (True,1,"true","yes") plus active, missing, and empty-doc paths. I also checked both callers degrade gracefully on(None, None):_group_confirmed_capturesfalls through tooutcome='none', and the shadow_runskips via its existingnot first or not secondbranch.
Checks are green on this head (Backend unit suite, Backend Hermetic Merge Gate, Formatting, Hygiene) and the PR body declares Failure-Class: none. Nice minimal fix — guard at the boundary instead of patching call sites.
Since this sits on the deleted-user-data decryption boundary, it should get a maintainer sign-off before merge rather than an automated approval.
by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.
aryanorastar
left a comment
There was a problem hiding this comment.
Approved 938f8fd0ea67c7a02a75aa38678ee8e904a2cd63. get_conversation_for_capture_check in backend/database/conversations.py on main returns a deleted row. This head returns (None, None) and Hygiene succeeded.
…ion_photos (#20949) ### Summary Follow-up to #19762, #19774, #19796, #19804, #19860, #19864, #19867, #19870, #20763, #20772, #20783, #20800, #20871, #20877, #20891, #20895, #20899, #20901, #20935, #20948. Reject soft-deleted conversation tombstones in `store_conversation_photos` to prevent persisting orphaned photo subcollections and mutating soft-deleted conversation documents. ### Problem `backend/database/conversations.py` provides `store_conversation_photos(uid, conversation_id, photos)` to persist conversation photo records into the `photos` subcollection and update the parent conversation's content flags. While it checked physical existence (`if not getattr(conversation_snapshot, 'exists', False): return False`), it omitted checking `is_soft_deleted(raw)`. Because soft-deleted conversations retain their Firestore documents with `deleted: True`, `conversation_snapshot.exists` evaluates to `True`. Consequently: 1. Photos arriving after a conversation was deleted were written into orphaned `photos` subcollections that Firestore does not cascade-delete. 2. The transactional write mutated the soft-deleted parent document via `transaction.update(conversation_ref, {'has_content': True, 'has_photos': True})`, violating the tombstone immutability invariant. 3. Callers relying on the boolean return to stop pipeline steps (such as `backend/routers/listen/transcripts.py`) received `True` and proceeded with post-commit source mutations on soft-deleted conversations. ### Solution - In `backend/database/conversations.py:store_conversation_photos`: ```python conversation_snapshot = conversation_ref.get(transaction=transaction) raw = conversation_snapshot.to_dict() if getattr(conversation_snapshot, 'exists', False) else None if not raw or is_soft_deleted(raw): return False level = raw.get('data_protection_level', 'standard') ``` - Reject soft-deleted tombstones by returning `False` without writing photo subcollection documents or updating the parent document. - Inlines `client.transaction()` to replace the previous checks without adding any lines (ratchet diff: +0 lines). ### Product invariants affected none ### Regression Risk Zero. Only affects soft-deleted conversations (`deleted: True`). Active live conversations continue to persist photos and update flags identically. ### Verification - Added unit tests in `backend/tests/unit/test_store_conversation_photos_tombstone_guard.py`: - `test_store_conversation_photos_live_conversation`: asserts photos are stored and parent flags updated for active conversations. - `test_store_conversation_photos_missing_conversation`: asserts `False` is returned and nothing is written when parent doc is absent. - `test_store_conversation_photos_rejects_soft_deleted_tombstone`: asserts `False` is returned, no photo docs created, and parent flags left untouched for tombstones. - Verified existing photo contract tests (`test_merge_conversation_photos.py`, `test_conversation_revision_contract.py`) passed cleanly (25 passed). - Verified Black 26.5.1 code formatting (`0 violations`). - Passed `scripts/failure-class validate`. Failure-Class: none <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/BasedHardware/omi/pull/20949?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="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a> <!-- End of auto-generated description by cubic. -->
Summary
Follow-up to #19762, #19774, #19796, #19804, #19860, #19864, #19867, #19870, #20763, #20772, #20783, #20800, #20871, #20877, #20891, #20895, #20899, #20901, #20935.
Reject soft-deleted conversation tombstones in
get_conversation_for_capture_checkto prevent decrypting deleted transcripts and exposing them to duplicate capture grouping and shadow LLM evaluation.Problem
backend/database/conversations.pyprovidesget_conversation_for_capture_check(uid, conversation_id)to retrieve a decrypted conversation document and its transcript fingerprint for cross-device capture grouping and shadow evaluation.While it checked physical existence (
if not raw:), it omitted checkingis_soft_deleted(raw). Because soft-deleted conversations retain their Firestore documents withdeleted: True,snapshot.existsevaluates toTrue.Consequently:
prepare_conversation_for_read(raw, uid)decrypted and returned transcripts of conversations that users had explicitly deleted.duplicate_capture.py(_group_confirmed_captures), soft-deleted transcripts were compared against active captures viameasure_shared_speechandmeasure_capture_containment.capture_jev_shadow.py(_run), soft-deleted conversation data was passed directly into shadow LLM pipeline evaluations.link_duplicate_capturecontains a transactional guard against deleted rows (if row.get('deleted'): return False), the preceding read and decryption step leaked deleted content without protection.Solution
backend/database/conversations.py:get_conversation_for_capture_check:(None, None)exactly like missing documents.Product invariants affected
none
Regression Risk
Zero. Only affects soft-deleted conversations (
deleted: True). Active live conversations continue to be fetched, decrypted, and grouped normally.Verification
backend/tests/unit/test_capture_check_tombstone_guard.py:test_get_conversation_for_capture_check_active_conversation: asserts live conversations return decrypted conversation and fingerprint.test_get_conversation_for_capture_check_missing_conversation: asserts missing documents return(None, None).test_get_conversation_for_capture_check_rejects_soft_deleted_tombstone: asserts tombstones return(None, None)and are never decrypted.test_get_conversation_for_capture_check_empty_doc: asserts empty documents return(None, None).test_capture_groups.py,test_capture_jev_shadow.py,test_capture_containment_policy.py) passed cleanly (106 passed).0 violations).scripts/failure-class validate.Failure-Class: none