Repository navigation
Conversation
Git-on-my-level
left a comment
There was a problem hiding this comment.
Verified the core change first: in backend/database/conversations.py, update_conversation now reads doc_data = doc_snapshot.to_dict() or {} and returns False when is_soft_deleted(doc_data) — placed before _prepare_conversation_for_write and doc_ref.update, so neither the tombstone document nor derived state (stats cache invalidation, _sync_conversation_search_index) is touched. This matches the module's shared tombstone predicate (is_soft_deleted, used at the other rejection sites like merge/reprocess/list) and the function's documented gone-owner contract. Reusing doc_data for data_protection_level and _guard_match_score_size also removes the duplicate .to_dict() calls — good.
The new backend/tests/unit/test_update_conversation_tombstone_guard.py covers the tombstone path (False return, no document mutation, _sync_conversation_search_index not called) and the live-conversation path returning True, and the Backend unit suite passes on this head.
Two check failures block merge, both quick fixes:
- Formatting (black) — the new test file has a double blank line after
import database.conversations as conversations_db; remove one blank line (or runblack backend/tests/unit/test_update_conversation_tombstone_guard.py). - Hygiene
product-file-line-count-ratchet—backend/database/conversations.pyis line-count frozen at 3722 and this change grows it to 3726. Add exactlyLine-Count-Exception: backend/database/conversations.py | 3722 -> 3726 | reasonto the PR body with a short reason, or restructure so the file doesn't grow.
Once those land, this looks good to go — thanks for the clean, well-tested follow-up in this series.
by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.
Dismissing my earlier changes-requested review: both blockers are resolved on head b62b0b3 — the formatting issue in the test file was fixed in 1ff8ed8, and the hygiene line-count ratchet is now satisfied via the Line-Count-Exception entry in the PR body. Backend unit suite, Formatting, and Hygiene are green at this head.
|
Both blockers from the prior automated review are resolved on this head - thanks for the quick turnaround.
Re-verified the change itself: in From my side this is ready - leaving the merge decision with the maintainers. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
|
@miso466 this conflicts with |
b62b0b3 to
d00aea9
Compare
|
Rebased onto latest |
|
Reviewed the rebased head — the conflict resolution in The new tests in This matches the tombstone-rejection contract already enforced elsewhere in the module (the upsert path rejects existing by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
d00aea9 to
3631604
Compare
|
Verdict: the production change is correct and nicely scoped - no blocking issues. backend/database/conversations.py - backend/tests/unit/test_update_conversation_tombstone_guard.py - new suite with an in-memory Firestore mock pinning the three contract clauses (False return, no tombstone mutation, no search-index sync) plus a live-conversation control case. Good coverage of the exact regression. USER IMPACT: none - internal change; conversations you deleted stay deleted instead of being quietly updated by background workers. Nice continuation of the tombstone-guard series. Formal approval left to a human maintainer since this guards user-data deletion semantics in the conversations store. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
3631604 to
f1f5a85
Compare
|
Verdict: the production change here is correct and nicely scoped — one guard, one read consolidation, no behavior change for live conversations. The red Backend unit suite on this head is a pre-existing failure on main (test_open_loops_recap_integration.py, same failures on current main runs), unrelated to this diff. Findings:
Security/blast radius: privacy-positive — prevents writes to user-deleted conversations and stops search-index sync and stats-cache invalidation from firing for tombstones. Performance: no new reads; slightly fewer to_dict() calls per update. USER IMPACT: once a conversation is deleted from trash, background workers stop writing to it and stop regenerating derived data for it — deleted means deleted. What I'd still want as a reviewer: (1) in the live-conversation test, also assert _sync_conversation_search_index fires when an indexed root (e.g. structured.*) is touched, so the guard's no-side-effect assertion has a positive control; (2) optionally assert record_owner_out stays empty for a soft-deleted batch-lane row. CI note for maintainers: the Backend unit suite failure on this head reproduces on main (open-loops recap integration tests) and is not caused by this PR. Leaving for human maintainer merge decision (deletion-contract change in the user-data layer from a contributor outside the automated-approval set). by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
…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.
Enforce the gone-owner contract in
database.conversations.update_conversationfor soft-deleted conversation tombstones to prevent tombstone mutation and unnecessary worker execution.Problem
database.conversations.update_conversationdocuments that it:However,
update_conversationonly checked physical existence viaif not doc_snapshot.exists: return Falseand lacked a check foris_soft_deleted(doc_data).When a conversation was soft-deleted (
deleted: True),doc_snapshot.existsremainedTrue. Consequently:update_conversationreturnedTrueand proceeded to commit updates (doc_ref.update(prepared_data)), mutating the tombstone conversation document.Trueand continued producing work for a deleted owner instead of ceasing execution and releasing resources._sync_conversation_search_index) and stats cache invalidation—executed for deleted conversations.Solution
database.conversations.update_conversation, readdoc_data = doc_snapshot.to_dict() or {}and checkif is_soft_deleted(doc_data): return False.doc_datafor resolvingdata_protection_leveland match score guards instead of repeated.to_dict()calls.Product invariants affected
none
Regression Risk
Zero. Active live conversations proceed with identical update logic and side effects.
Verification
backend/tests/unit/test_update_conversation_tombstone_guard.py:test_update_conversation_rejects_soft_deleted_tombstone: assertsFalsereturn, verifies no document mutation, and confirms search index sync is skipped (demonstrated failure on unpatched code returningTrue).test_update_conversation_succeeds_for_live_conversation: assertsTruereturn and successful document mutation for live conversations.scripts/pr-preflightverification and Black 26.5.1 code formatting.Failure-Class: none
Line-Count-Exception: backend/database/conversations.py | 3722 -> 3726 | minimal soft-deleted tombstone guard preventing mutation