Skip to content

fix(conversations): reject soft-deleted tombstones in get_conversation_for_capture_check - #20948

Merged
aryanorastar merged 2 commits into
BasedHardware:mainfrom
miso466:fix/capture-check-tombstone-guard
Nov 9, 2026
Merged

aryanorastar merged 2 commits into
BasedHardware:mainfrom
miso466:fix/capture-check-tombstone-guard

Conversation

@miso466

@miso466 miso466 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

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:
    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

View guided diff

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified against head 938f8fd. This closes a real deleted-data exposure seam in the capture pipeline.

  • backend/database/conversations.py — get_conversation_for_capture_check previously checked only physical existence, so soft-deleted tombstones (deleted: True keeps the Firestore doc, snapshot.exists true) were decrypted by prepare_conversation_for_read and consumed by duplicate_capture._group_confirmed_captures and capture_jev_shadow._run. The transactional deleted guard in link_duplicate_capture fires only later, after the read-and-decrypt step. Reusing the shared is_soft_deleted predicate here is the right shape — and correctly distinct from discarded, which deliberately stays revivable.
  • backend/tests/unit/test_capture_check_tombstone_guard.py — solid regression coverage through the real seam (StrictFirestore rows 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_captures falls through to outcome='none', and the shadow _run skips via its existing not first or not second branch.

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.

@Git-on-my-level Git-on-my-level added backend Backend Task (python) positive-signal Automation verified a genuine fix/quality contribution security-review Touches auth, provider routing, secrets, or security-sensitive surfaces labels Oct 8, 2026

@aryanorastar aryanorastar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

aryanorastar added a commit that referenced this pull request Oct 29, 2026
…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. -->
@aryanorastar
aryanorastar merged commit 4b000df into BasedHardware:main Nov 9, 2026
55 of 56 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend Task (python) positive-signal Automation verified a genuine fix/quality contribution security-review Touches auth, provider routing, secrets, or security-sensitive surfaces

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants