Repository navigation
fix(sync): reject soft-deleted conversation tombstones in audio playback and download endpoints - #20935
fix(sync): reject soft-deleted conversation tombstones in audio playback and download endpoints#20935miso466 wants to merge 2 commits into
Conversation
|
Thanks @miso466 — reviewed this against the head commit. This is a clean, correct fix in the right direction. What I verified:
Checks are green (Backend unit suite, Hygiene, Formatting, Backend Hermetic Merge Gate). Since this changes access-control behavior on user audio endpoints (signed URLs and raw audio streaming), leaving the merge call to a human maintainer — the change itself looks ready. AI-generated maintainer feedback on behalf of the Omi maintainers. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
|
Thanks @miso466 — verified this end to end on the current head.
Backend unit suite and the hermetic merge gate are green on this head. Keeping the by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
fda781d to
094d80e
Compare
Git-on-my-level
left a comment
There was a problem hiding this comment.
Verdict: the production edit itself is safe and consistent, but this PR needs work before merge - the description materially overstates the impact, and the new test file duplicates existing coverage.
Findings:
-
backend/routers/sync.py (+3/-3): swapping conversation.get('deleted', False) for conversations_db.is_soft_deleted(conversation) in precache_conversation_audio_endpoint, get_audio_signed_urls_endpoint, and download_audio_file_endpoint is behavior-identical. is_soft_deleted (backend/database/conversations.py:798) is bool(conversation) and bool(conversation.get('deleted')), and all three call sites already short-circuit on
not conversation, so soft-deleted conversations already got a 404 before this PR. Consolidating onto the shared predicate is still good hygiene - it matches the merge/reprocess paths and protects against future drift if the predicate gains conditions - but this is a consistency refactor, not a vulnerability fix. -
PR description: 'none of them verified is_soft_deleted ... allowed data leakage of audio records after deletion' is not accurate - the inline deleted check already blocked those calls. On a PR carrying the security-review label, please correct the Summary/Problem sections so the merge decision is made on accurate framing.
-
backend/tests/unit/test_sync_audio_playback_tombstone_guard.py (+113): near-duplicate of the existing test_sync_audio_conversation_tombstone_guard.py, which already covers all three endpoints (precache/urls/download) for deleted, nonexistent, locked, and active cases - strictly broader than this new file. Please drop it, or fold any unique assertion you want to keep (e.g. asserting the playback helper is never invoked on the deleted path) into the existing file instead.
Security: no new exposure - behavior is unchanged, and the test env bootstrap (including the ENCRYPTION_SECRET value) matches the established pattern in test_sync_audio_merge_job_tombstone_guard.py, so no new secret material.
USER IMPACT: none - users see identical behavior; soft-deleted conversations were already hidden from these endpoints.
Requested changes: (1) drop or merge the duplicate test file, (2) correct the description's vulnerability claim. The predicate consolidation itself is welcome and I'd be glad to see this land once those two items are addressed. Leaving for human maintainer review given the security-review label on this audio data-handling surface.
by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.
…ack and download endpoints
…e duplicate test file per review
094d80e to
10f5ddc
Compare
|
Thanks for the detailed review @Git-on-my-level! Both requested changes have been addressed on head 10f5ddc:
All 13 unit tests pass locally and CI is re-running. |
Dismissing as resolved on head 10f5ddc: the duplicate test file was dropped with its unique assertions folded into test_sync_audio_conversation_tombstone_guard.py, and the description was corrected to accurately frame the change as a zero-behavior-change predicate consolidation.
Git-on-my-level
left a comment
There was a problem hiding this comment.
Since my last review: addressed (duplicate test file dropped, with the unique helper-never-invoked assertions folded into test_sync_audio_conversation_tombstone_guard.py; description rewritten to accurately frame this as a zero-behavior-change consistency refactor) · still open (nothing blocking) · newly introduced (nothing).
Verdict: this addresses everything from my earlier review — the predicate consolidation is correct and welcome, and nothing blocking remains from my side.
Findings on the new head:
-
backend/routers/sync.py (+3/-3): all three call sites (precache_conversation_audio_endpoint, get_audio_signed_urls_endpoint, download_audio_file_endpoint) now use conversations_db.is_soft_deleted(conversation). Verified behavior-identical: is_soft_deleted (backend/database/conversations.py:807) is bool(conversation) and bool(conversation.get('deleted')), and each call site already short-circuits on
not conversation, so the 404 outcomes are unchanged. The consolidation matches the merge/reprocess paths and protects these endpoints if tombstone semantics ever gain conditions (e.g. redirect tombstones). -
backend/tests/unit/test_sync_audio_conversation_tombstone_guard.py (+9): the folded mock_precache/mock_get_urls/mock_download assertions with assert_not_called() on each deleted-conversation path are exactly the strengthening I asked for; the existing deleted/nonexistent/locked/active coverage for all three endpoints is intact.
Security: no new exposure — behavior is unchanged on an audio data-handling surface; the test bootstrap (including ENCRYPTION_SECRET) matches the established pattern in sibling tombstone-guard tests, so no new secret material.
USER IMPACT: none — internal change; soft-deleted conversations were already hidden from these endpoints.
One optional nit: the title reads as a bug fix ('reject ... tombstones') while behavior is unchanged — consider 'refactor(sync):' so the history matches the (now accurate) description.
Formal approval is left to a human maintainer given the security-review label on this audio data surface.
by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.
|
Closing. This is already on main via #19864. Not merged. |
|
Hey @miso466 👋 Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request. After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:
Before your next PR, please skim:
If this was declined for direction or taste, maintainers should cite an invariant ID or open a proposed one — ask if that citation is missing. Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out. Thank you for being part of the Omi community! |
…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. -->
…n_for_capture_check (#20948) ### 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_check` to prevent decrypting deleted transcripts and exposing them to duplicate capture grouping and shadow LLM evaluation. ### Problem `backend/database/conversations.py` provides `get_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 checking `is_soft_deleted(raw)`. Because soft-deleted conversations retain their Firestore documents with `deleted: True`, `snapshot.exists` evaluates to `True`. Consequently: 1. `prepare_conversation_for_read(raw, uid)` decrypted and returned transcripts of conversations that users had explicitly deleted. 2. In `duplicate_capture.py` (`_group_confirmed_captures`), soft-deleted transcripts were compared against active captures via `measure_shared_speech` and `measure_capture_containment`. 3. In `capture_jev_shadow.py` (`_run`), soft-deleted conversation data was passed directly into shadow LLM pipeline evaluations. 4. While downstream `link_duplicate_capture` contains a transactional guard against deleted rows (`if row.get('deleted'): return False`), the preceding read and decryption step leaked deleted content without protection. ### Solution - In `backend/database/conversations.py:get_conversation_for_capture_check`: ```python if not raw or is_soft_deleted(raw): return None, None ``` - Soft-deleted conversation tombstones return `(None, None)` exactly like missing documents. - Protects deleted transcript content from being decrypted or measured in duplicate capture algorithms. - Replaces the existing existence check in-place 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 be fetched, decrypted, and grouped normally. ### Verification - Added unit tests in `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)`. - Verified all related capture group and policy test suites (`test_capture_groups.py`, `test_capture_jev_shadow.py`, `test_capture_containment_policy.py`) passed cleanly (106 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/20948?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.
Consolidate inline tombstone checks onto the shared
conversations_db.is_soft_deleted(conversation)predicate across sync audio playback and download endpoints for code hygiene and consistency with merge/reprocess paths.Problem
backend/routers/sync.pyexposes three client-facing audio playback and download endpoints:POST /v1/sync/audio/{conversation_id}/precache(precache_conversation_audio_endpoint)GET /v1/sync/audio/{conversation_id}/urls(get_audio_signed_urls_endpoint)GET /v1/sync/audio/{conversation_id}/{audio_file_id}(download_audio_file_endpoint)While all three previously checked
conversation.get('deleted', False)to return 404 on soft-deleted conversations, they used ad-hoc inline dictionary checks rather than the standardizedconversations_db.is_soft_deleted(conversation)predicate used across the rest of the codebase (such as the merge and reprocess paths).Consolidating onto the shared predicate improves consistency and ensures future changes to tombstone semantics remain uniform across all sync endpoints.
Solution
backend/routers/sync.py, update existence checks inprecache_conversation_audio_endpoint,get_audio_signed_urls_endpoint, anddownload_audio_file_endpointto use the shared predicate:Product invariants affected
none
Regression Risk
Zero.
conversations_db.is_soft_deleted(conversation)isbool(conversation) and bool(conversation.get('deleted')). Live and active conversations continue to precache, fetch signed URLs, and stream audio identically.Verification
mock_precache.assert_not_called(),mock_get_urls.assert_not_called(),mock_download.assert_not_called()) intobackend/tests/unit/test_sync_audio_conversation_tombstone_guard.pyand removed duplicate test file per review.13 passed in 3.24s).scripts/backend-python-format --check(0 violations).scripts/failure-class validate.Failure-Class: none