Repository navigation
fix(chat-first): reject blocks referencing soft-deleted conversation and task tombstones - #20783
Conversation
|
Verified a real gap and a clean fix.
Note on the red "Backend unit suite" check: the failing tests ( by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
|
Verified this change — the guards are load-bearing and the fix is correct. backend/routers/chat_first.py — backend/tests/unit/test_chat_first_tombstone_guard.py — good coverage: all five rejection paths plus an active-entity regression asserting accepted receipts, using the same seams as the sibling About the failing Backend unit suite: the shard failures are in Thanks for the tight, well-tested fix — the invariant that tombstones are invisible to user-facing workflows is exactly right. Leaving merge sign-off to a human maintainer. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
…and task tombstones Guard `_entity_available` in `backend/routers/chat_first.py` against admitting journal blocks referencing soft-deleted conversation tombstones or soft-deleted tasks. Rejects them with entity_unavailable to preserve entity invariants and avoid leaking deleted records into chat workflows. Failure-Class: none
400c817 to
fb9a963
Compare
|
The production change here is correct and nicely scoped — the chat-first block validator now honors the tombstone invariant, and every branch is tested. Findings (all verified against the head):
Security/privacy: this is the material dimension — before this change, a validation request referencing a soft-deleted conversation or task returned USER IMPACT: journal entries can no longer link to conversations or tasks you've deleted — previously they could still pass validation and resurface deleted content. Still wanted as a reviewer: nothing blocking. Optional niceties: a test asserting a conversation with Verified correct; formal approval is left to a human maintainer. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
aryanorastar
left a comment
There was a problem hiding this comment.
Approved fb9a963bd50144e27c9113d84d3b5c8521afd844. _entity_available in backend/routers/chat_first.py on main accepts a deleted task or capture. This head rejects it 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. -->
…rame request promotion (#20895) ### Summary Follow-up to #19762, #19774, #19796, #19804, #19860, #19864, #19867, #19870, #20763, #20772, #20783, #20800, #20871, #20877, #20891. Reject soft-deleted conversation tombstones in `attach_frame_request_to_conversation` to prevent tombstone bypass during just-in-time frame evidence promotion. ### Problem `attach_frame_request_to_conversation` validated conversation existence using `conversation_snapshot.exists` inside the promotion transaction, but did not check `is_soft_deleted(conversation_data)`. Even when a conversation was soft-deleted (`deleted: True`), callers of `POST /v1/frame-requests/{request_id}/promote` could: 1. Write permanent photo metadata into the soft-deleted conversation's `photos` subcollection (`photo_ref`). 2. Mutate the tombstone conversation document with `has_content: True, has_photos: True`. 3. Transition the temporary frame request to `attached` state with permanent evidence linked to a deleted conversation. This violated Omi's conversation tombstone invariant and allowed resurrecting evidence references on deleted conversations. ### Solution - Import `is_soft_deleted` from `database.conversations`. - In `attach_frame_request_to_conversation`, check `if not conversation_snapshot.exists or is_soft_deleted(conversation_data): raise KeyError("conversation not found")`. - Reuse `conversation_data` for resolving `data_protection_level` instead of redundant `.to_dict()` calls. - The router layer continues mapping `KeyError` to HTTP 404 `frame_request_not_found`. ### Product invariants affected none ### Regression Risk Zero. Only affects soft-deleted conversations (`deleted: True`). All active conversations continue to attach and promote frame evidence identically. ### Verification - Added unit tests in `backend/tests/unit/test_frame_request_promotion_safety.py`: - `test_attach_frame_request_rejects_soft_deleted_conversation_tombstone`: asserts `KeyError("conversation not found")` on tombstone conversation. - `test_promote_frame_request_maps_tombstone_rejection_to_404`: asserts router-level HTTP 404 response. - Verified all frame request test suites pass hermetically (70 passed). - Formatted via Black 26.5.1 specification. Failure-Class: none <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/BasedHardware/omi/pull/20895?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. -->
…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.
Guards the chat-first block validation endpoint against admitting journal blocks that reference soft-deleted conversation tombstones or soft-deleted tasks.
Problem
In
backend/routers/chat_first.py:_entity_availablevalidates entity references forChatFirstJournalBlockSpecduringPOST /v1/chat-first/blocks/validate.CaptureLinkSpec,ConversationLinkSpec, andsubject.kind == 'capture'), the check inspecteddiscardedandis_locked, but omittedconversations_db.is_soft_deleted.TaskCardSpecandsubject.kind == 'task'), the check inspectedis_locked, but omittedtask.get('deleted').As a result, client validation requests referencing soft-deleted conversation tombstones or soft-deleted tasks returned
accepted: trueinstead ofaccepted: false, code: 'entity_unavailable', violating the invariant that tombstones are invisible and inaccessible to user-facing workflows.Solution
not conversations_db.is_soft_deleted(...)checks toCaptureLinkSpec,ConversationLinkSpec, andsubject.kind == 'capture'branches in_entity_available.not task.get('deleted', False)checks toTaskCardSpecandsubject.kind == 'task'branches in_entity_available.entity_unavailable.Verification
pytest backend/tests/unit/test_chat_first_tombstone_guard.py(5/5 passed in 1.60s)pytest backend/tests/unit/test_chat_first*.py(127/127 passed in 2.77s)scripts/backend-python-format --check(exit code 0)scripts/pr-preflightRegression Risk
Zero. Only rejects soft-deleted records (
deleted: True). All active conversations, captures, and tasks continue to validate identically.Failure-Class: none