Skip to content

fix(sync): reject soft-deleted conversation tombstones in capture provenance - #20891

Closed
miso466 wants to merge 1 commit into
BasedHardware:mainfrom
miso466:fix/sync-provenance-tombstone-guard
Closed

miso466 wants to merge 1 commit into
BasedHardware:mainfrom
miso466:fix/sync-provenance-tombstone-guard

Conversation

@miso466

@miso466 miso466 commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

What changed and why

Follow-up to #19762, #19774, #19796, #19804, #19860, #19864, #19867, #19870, #20763, #20772, #20783, #20800, #20871, #20877.

Reject soft-deleted conversation tombstones in capture_matches_server_conversation to prevent tombstone bypass in capture provenance verification.

In capture_matches_server_conversation (backend/utils/sync/provenance.py), validation for whether a parent conversation is soft-deleted was missing when verifying capture file provenance for server-created conversations.

Even when a conversation was soft-deleted (deleted: True), capture_matches_server_conversation would return True as long as timestamps aligned within the configurable time-matching tolerance window (slop window), allowing:

  1. claim_fresh_capture_provenance (POST /v1/sync/capture/manifest) to associate manifest claims with soft-deleted conversation tombstones.
  2. POST /v1/sync (sync_files) to grant has_server_capture_proof and elevate sync requests targeting deleted conversations into the trusted sync lane (classify_sync_lane).

This fix:

  1. Rejects soft-deleted tombstones in capture_matches_server_conversation (backend/utils/sync/provenance.py), returning False immediately when conversations_db.is_soft_deleted(conversation) is true.
  2. Adds unit tests covering active matching, soft-deleted tombstone rejection, missing conversations, device mismatch, invalid timestamps, and window bounds.

Regression Risk

Zero. Only affects soft-deleted conversations (deleted: True). All active
conversations continue to match captures identically.

Product invariants affected

none

How it was verified

  • Reproducer test (reproducer_test.py) verified against unpatched code (vulnerability confirmed: tombstone accepted) and patched code (pass: tombstone rejected).
  • Unit tests in backend/tests/unit/test_sync_provenance.py (7 passed in 0.54s).
  • Related sync tests (test_sync_two_lane.py, test_sync_file_paths_filename_none.py - 41 passed in 0.95s, zero regressions).
  • Code formatting via scripts/backend-python-format --check passed cleanly (Black 26.5.1, 0 violations).
  • scripts/pr-preflight verified all checks pass.

Tests

  • backend/tests/unit/test_sync_provenance.py::test_capture_matches_server_conversation_active_matches
  • backend/tests/unit/test_sync_provenance.py::test_capture_matches_server_conversation_rejects_soft_deleted_tombstone
  • backend/tests/unit/test_sync_provenance.py::test_capture_matches_server_conversation_missing_conversation
  • backend/tests/unit/test_sync_provenance.py::test_capture_matches_server_conversation_mismatched_device
  • backend/tests/unit/test_sync_provenance.py::test_capture_matches_server_conversation_missing_ids
  • backend/tests/unit/test_sync_provenance.py::test_capture_matches_server_conversation_invalid_timestamps
  • backend/tests/unit/test_sync_provenance.py::test_capture_matches_server_conversation_outside_window

Failure class (fixes)

Failure-Class: none

Review in cubic

@Git-on-my-level

Copy link
Copy Markdown
Member

Verified this fix against the head — it is correct and well-scoped.

  • backend/utils/sync/provenance.py: adding conversations_db.is_soft_deleted(conversation) to the early-return guard in capture_matches_server_conversation is the right minimal change. The predicate already exists (backend/database/conversations.py, is_soft_deleted) and its documented contract — content operations must reject tombstones so deleted data cannot be resurrected — is exactly what was missing here.
  • Impact confirmed: the function's return value feeds has_server_capture_proof at backend/routers/sync.py:240 (manifest claims) and :946 (sync_files), which then passes client_device_id into classify_sync_lane. Before this change, a soft-deleted conversation with a matching client_device_id and timestamps inside the slop window could grant trusted-lane elevation. The PR description's bypass analysis matches the code.
  • backend/tests/unit/test_sync_provenance.py: good coverage — active match, tombstone rejection (with mock_window.assert_not_called() proving early exit before the time-window computation), missing conversation, device mismatch, missing IDs, invalid timestamps, and out-of-window. Patch targets are the correct namespaces.
  • One tiny nit, non-blocking: import pytest at the top of the new test file is unused.

Regression risk is indeed near zero: only conversations with deleted set are affected; active conversations match identically. Backend unit suite, Formatting, Hygiene, and the Backend Hermetic Merge Gate are green on this head.

Because this gates the trusted sync lane (a security- and privacy-sensitive user-data surface), it needs a maintainer sign-off before merge — leaving for human maintainer review rather than a formal approval.

This review was generated by an automated maintainer assistant acting 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 need human response.

@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks @miso466 — reviewed on head a89f0a7.

backend/utils/sync/provenance.py — the guard is placed correctly: conversations_db.is_soft_deleted(conversation) is checked before the client_device_id comparison and before any window evaluation, so a soft-deleted tombstone can no longer satisfy capture provenance even when its timestamps fall inside the 30-minute slop window (_CAPTURE_PROVENANCE_SLOP_SECONDS). Reusing the shared tombstone predicate from database/conversations.py instead of re-deriving deleted semantics matches how the merge/reprocess paths treat tombstones, and no new import is needed since the module was already imported.

backend/tests/unit/test_sync_provenance.py — good coverage. The tombstone case asserts capture_times_within_window is never reached (mock_window.assert_not_called()), which confirms genuine early rejection rather than an accidental downstream miss. Device mismatch, missing conversation, missing/empty ids, invalid timestamps, and window-bound cases are all covered, and the mocks target the right module seams (database.conversations.get_conversation, utils.sync.provenance.capture_times_within_window).

Backend unit suite and Backend Hermetic Merge Gate pass on this head.

This closes a real gap: without the guard, manifest claims could attach provenance to deleted conversations and elevate sync requests into the trusted lane. Since this gates trusted-lane classification, keeping security-review for maintainer sign-off before merge — the fix direction looks right and the regression surface is minimal (only soft-deleted conversations change behavior).


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 the positive-signal Automation verified a genuine fix/quality contribution label Oct 8, 2026

@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 on head a89f0a7: the new guard in backend/utils/sync/provenance.py correctly routes through conversations_db.is_soft_deleted (the same bool(conversation.get('deleted')) tombstone convention used across backend/database/conversations.py), and because it sits before the timestamp/window checks, a soft-deleted conversation can no longer obtain capture provenance via the slop window — the new test's mock_window.assert_not_called() pins that ordering nicely. I also confirmed both call sites in backend/routers/sync.py (manifest claim verification and sync_files) consume this function to grant has_server_capture_proof, so the fix genuinely closes the trusted-lane elevation path described in the PR body. The seven cases in backend/tests/unit/test_sync_provenance.py cover the full guard chain (active match, tombstone, missing conversation, device mismatch, missing ids, invalid timestamps, window bounds) and patch the right module attributes. One trivial nit, non-blocking: 'import pytest' in the test file is unused. Backend unit suite and the hermetic merge gate are green. Since this changes the sync trust-lane gate (a security-sensitive surface), maintainer sign-off on the security-review label is requested before merge.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

…venance

Reject soft-deleted conversation tombstones in
`capture_matches_server_conversation` by checking
`conversations_db.is_soft_deleted(conversation)`.

Failure-Class: none
@omiagent

omiagent Bot commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Thanks for this fix, @miso466! Your commits are being carried forward in #23080 (cherry-picked with your original authorship intact) so they can land with the current CI and repo conventions. Closing this in favor of that branch — your contribution is credited there and in the git history.

@omiagent omiagent Bot closed this Oct 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

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:

  • Project standards — Ensuring consistency across the codebase
  • User needs — Making sure changes align with what our users need
  • Code best practices — Maintaining code quality and maintainability
  • Project direction — Keeping aligned with our product principles and locked invariants

Before your next PR, please skim:

  • PRODUCT.md — product north star
  • Product invariants — locked rules (shared chat, memory tiers, agent control plane, integrations, brand)

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!

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 added a commit that referenced this pull request Oct 29, 2026
…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. -->
aryanorastar added a commit that referenced this pull request Nov 9, 2026
…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. -->
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.

2 participants