Skip to content

fix(conversations): reject soft-deleted conversation tombstones in in-progress retrieval - #20871

Open
miso466 wants to merge 2 commits into
BasedHardware:mainfrom
miso466:fix/retrieve-in-progress-conversation-tombstone-guard
Open

miso466 wants to merge 2 commits into
BasedHardware:mainfrom
miso466:fix/retrieve-in-progress-conversation-tombstone-guard

Conversation

@miso466

@miso466 miso466 commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

What changed and why

Reject soft-deleted conversation tombstones in retrieve_in_progress_conversation when resolved via the fast-path Redis pointer, and add defense-in-depth in POST /v1/conversations.

retrieve_in_progress_conversation is the primary intake for POST /v1/conversations (process_in_progress_conversation) and the listen session connection pipeline.

While the fallback query get_in_progress_conversation properly filters out soft-deleted conversations (not is_soft_deleted(conversation)), the fast-path Redis pointer branch (get_in_progress_conversation_id -> get_conversation) only verified that status == 'in_progress'. If a conversation was soft-deleted while recording or shortly after, the tombstone remained referenced by Redis and was returned unfiltered. This allowed POST /v1/conversations to finalize and resurrect a deleted conversation, generating summaries, memories, and notifications for user-deleted data.

This fix:

  1. In retrieve_in_progress_conversation (backend/utils/conversations/process_conversation.py), rejects soft-deleted tombstones (conversations_db.is_soft_deleted(existing)) when resolving via the Redis pointer, resetting existing = None so it can fall back to clean storage or return None.
  2. In process_in_progress_conversation (backend/routers/conversations.py), adds defense-in-depth to ensure any tombstone reaching the router is rejected with HTTP 404 ("Conversation in progress not found").

Product invariants affected

  • INV-MEM-4
  • INV-TASK-2

How it was verified

  • Reproducer test (reproducer_test.py) verified against unpatched code (vulnerability confirmed) and patched code (pass).
  • Unit tests in backend/tests/unit/test_conversations_in_progress_tombstone_guard.py (2 passed in 2.68s).
  • Extended listen session tests in backend/tests/unit/test_listen_session_survives_redis_maxmemory.py (31 passed in 2.43s).
  • Regression suite backend/tests/unit/test_conversations_processing_rollback.py (12 passed in 2.96s).
  • Code formatting via scripts/backend-python-format --check passed cleanly (Black 26.5.1).
  • scripts/pr-preflight verified all checks pass.

Tests

  • backend/tests/unit/test_conversations_in_progress_tombstone_guard.py::test_retrieve_in_progress_conversation_ignores_soft_deleted_redis_cached_conversation
  • backend/tests/unit/test_conversations_in_progress_tombstone_guard.py::test_process_in_progress_conversation_rejects_soft_deleted_tombstone
  • backend/tests/unit/test_listen_session_survives_redis_maxmemory.py::test_retrieve_in_progress_conversation_ignores_soft_deleted_from_redis
  • backend/tests/unit/test_listen_session_survives_redis_maxmemory.py::test_retrieve_in_progress_conversation_falls_back_when_redis_target_is_soft_deleted

Failure class (fixes)

Failure-Class: none

Review in cubic

…-progress retrieval

`retrieve_in_progress_conversation` is the primary intake for `POST /v1/conversations` (process_in_progress_conversation) and the listen session connection pipeline.

While the fallback query `get_in_progress_conversation` filters out soft-deleted conversations (`not is_soft_deleted(conversation)`), the fast-path Redis pointer branch (`get_in_progress_conversation_id` -> `get_conversation`) only verified that `status == 'in_progress'`. If a conversation was soft-deleted while recording or shortly after, the tombstone remained referenced by Redis and was returned unfiltered. This allowed `POST /v1/conversations` to finalize and resurrect a deleted conversation, generating summaries, memories, and notifications for user-deleted data.

This commit:
1. Rejects soft-deleted tombstones in `retrieve_in_progress_conversation` when resolved via the Redis pointer, resetting `existing = None` so it can fall back to clean storage or return None.
2. Adds defense-in-depth in `POST /v1/conversations` to ensure any tombstone reaching the router is rejected with HTTP 404.
3. Adds regression tests covering tombstone rejection and fallback behavior.

Failure-Class: none
@Git-on-my-level

Copy link
Copy Markdown
Member

Verified a real gap and a clean fix. Reviewed file by file against the PR head:

  • backend/utils/conversations/process_conversation.py — the Redis-pointer fast path in retrieve_in_progress_conversation only checked status == 'in_progress', so a conversation soft-deleted mid-recording stayed resolvable and POST /v1/conversations could finalize it, generating derived data (summaries, memories, notifications) for user-deleted content. Adding conversations_db.is_soft_deleted(existing) here is exactly right: it resets the fast path so the code falls back to get_in_progress_conversation, which already filters tombstones (database/conversations.py get_in_progress_conversation filters not is_soft_deleted(conversation)). This also matches the documented contract on is_soft_deleted itself, which says content operations that read a tombstone and write derived state must reject it.
  • backend/routers/conversations.py — the defense-in-depth 404 guard in process_in_progress_conversation is a sensible second layer in case a future code path reintroduces the leak; conversations_db is already imported in this module so the guard is safe there.
  • backend/tests/unit/test_conversations_in_progress_tombstone_guard.py — both tests genuinely exercise the router guard (None → 404 and tombstone → 404) by monkeypatching retrieve_in_progress_conversation at the router module level, which is the correct patch point.
  • backend/tests/unit/test_listen_session_survives_redis_maxmemory.py — the two new tests cover the important behavioral branches: soft-deleted pointer falls back to a valid Firestore conversation, and returns None when no fallback exists (so the listen pipeline sees "no in-progress conversation" rather than a tombstone).

One trivial nit, non-blocking: MagicMock is imported but unused in the new test file.

Nice bug report and write-up — the reproducer-verified description made this easy to confirm. Leaving for human maintainer merge sign-off (user-data deletion behavior warrants a maintainer decision even though the code matches the established tombstone contract).


AI-generated maintainer feedback posted 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

Verified the gap and the fix against the head:

  • backend/utils/conversations/process_conversation.py (retrieve_in_progress_conversation): the Redis fast path only rejected status != 'in_progress', while the Firestore fallback get_in_progress_conversation already filters is_soft_deleted — so a soft-deleted tombstone referenced by the pointer really could slip through and get finalized. Adding conversations_db.is_soft_deleted(existing) with the existing = None reset is exactly right, and switching to .get('status') also removes a latent KeyError on malformed rows.
  • backend/routers/conversations.py (process_in_progress_conversation): the 404 defense-in-depth reuses conversations_db.is_soft_deleted, matching the existing pattern in _get_valid_conversation_by_id — consistent.
  • backend/tests/unit/test_conversations_in_progress_tombstone_guard.py: both router branches (None and tombstone dict) covered, including exact detail string.
  • backend/tests/unit/test_listen_session_survives_redis_maxmemory.py: covers fast-path rejection with Firestore fallback and with no fallback — directly exercises the changed branch.

Nice catch, and thanks for the reproducer-driven verification writeup. One non-blocking thought for a follow-up: after rejecting a tombstone the stale Redis pointer isn't cleared, so each subsequent call pays a get_conversation read plus the fallback query until the pointer is overwritten or expires (same as the pre-existing non_in_progress case).

This tightens deletion enforcement on the conversation intake path (a user-data integrity surface), so leaving for human maintainer sign-off before merge.


Feedback sent by an AI reviewer acting for the Omi maintainers. Human review may follow.


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

Verified the fix on head — the tombstone bypass was real and this closes it cleanly.

  • backend/utils/conversations/process_conversation.py: the Redis-pointer fast path in retrieve_in_progress_conversation previously only checked status == 'in_progress', while the Firestore fallback (get_in_progress_conversation) already filtered soft-deleted rows — so a conversation soft-deleted mid-recording could still be finalized, resurrecting user-deleted data. The new is_soft_deleted rejection at line 3569 closes the asymmetry, and switching to existing.get('status') also avoids a KeyError on malformed rows. Nice catch.
  • backend/routers/conversations.py: the defense-in-depth 404 in process_in_progress_conversation is sound — conversations_db is imported (line 9), and the guard mirrors the existing tombstone guards in this router (lines 136/145/774).
  • backend/tests/unit/test_conversations_in_progress_tombstone_guard.py: both the None case and the tombstone case are covered with the exact 404 contract.
  • backend/tests/unit/test_listen_session_survives_redis_maxmemory.py: good that you covered both fallback outcomes — the soft-deleted pointer falling back to a valid Firestore conversation, and the no-fallback case returning None. The monkeypatching matches how the production code resolves these modules.

Backend unit suite and Backend Hermetic Merge Gate are green on head. This is a well-scoped privacy fix with solid tests — thanks @miso466.

Since this touches deletion semantics for user data (which conversations may be finalized), it needs a human maintainer sign-off before merge. Leaving for human maintainer review.

This review was AI-generated on behalf of the 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.

@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 eeb6f59a22f9b54af578a8a9c592b3af653aebbf. retrieve_in_progress_conversation in backend/utils/conversations/process_conversation.py on main keeps a deleted in-progress row. This head drops it 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 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. -->

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend Task (python) needs-maintainer-review Needs a human maintainer to sign off before merge positive-signal Automation verified a genuine fix/quality contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants