Skip to content

fix(backend): conversation delete erases sync staging audio, ledger-linked batch rows and the retired v2 profile - #26215

Merged
kodjima33 merged 4 commits into
mainfrom
fix/delete-purges-audio
Nov 24, 2026
Merged

kodjima33 merged 4 commits into
mainfrom
fix/delete-purges-audio

Conversation

@kodjima33

@kodjima33 kodjima33 commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Bugs

A support data-deletion request showed three gaps in how conversation and profile deletion erase data. They affect every user, not one account.

  1. Conversation delete leaves the raw sync audio. Sync uploads are staged under syncing/{uid}/{job_id}/ in syncing-local. That bucket has no lifecycle delete, on purpose: scripts/check_sync_staging_lifecycle.py requires that. Staging cleanup only runs with a custody receipt, so most staging stays. These objects are keyed by the upload job, not the conversation, and the delete path never looked them up. For one account this was 14,340 objects (about 4.5 GB) that would never expire. Also, a cascade=false delete erased no audio at all, and merge-donor audio prefixes were only collected when BUCKET_CANONICAL_AUDIO is set, which it isn't in prod.
  2. Conversation delete leaves batch-pipeline rows. Sync-upload batch jobs and results are keyed by the upload's provisional capture identity (chunk_identity). They are only reachable by the final conversation id after projection. The purge matched by conversation identity only, so un-projected jobs, results, artifacts and intakes, plus their GCS audio and transcripts, survived until their 28–44 day TTL. On a read-only sample of 200 current prod jobs, 34 link to a live conversation only through the sync ledger (8 of 200 results); once projected, a row is matched by today's code.
  3. "Forget AI profile" misses ai_user_profile_v2. The retired Dream state pass wrote that field (removed in a96ada8). Nothing reads it, but DELETE /v1/users/ai-profile only removed ai_user_profile, so conversation-derived profile text stayed on the user doc.

Fix

  • New database/sync_ledger_sources.py reads the owner's sync content ledger, the durable link from an upload to the conversations it fed. A row has job_id (staging dir), batch_pipeline.segment_ids (batch rows), and result/partial_result conversation ids. The lookup is 4 single-field array_contains_any queries per 30 ids, registered with the Firestore query guard.
  • delete_privacy_conversation_audio now also purges the conversation's merge-donor prefixes and every staging dir (syncing/{uid}/{job_id}/, plus the derived bucket) of the uploads that fed it. It uses the existing _delete_owner_bucket_prefix / delete_owner_bucket_prefix helper (all generations, legal/retention holds honoured, StoragePrefixPurgeBlocked raised after every prefix is attempted). It adds no new raw deletes. This covers the request path and the accepted/deferred erasure runner from a9aa629, since both call this function.
  • Both cascade modes now erase audio. The audio purge (and the donor snapshot read) moved out of if cascade:. I found no deliberate reason to keep audio on cascade=false: the WS-J matrix and the Q8 note cover memories only, and the non-cascade path already deletes the transcript doc, screen frames and vectors. Automatic empty-generation teardown (bb7cb3f) does not use this route and still keeps its audio.
  • Both conversation batch purges (purge_batch_owner(conversation_id=...) inline and purge_conversations in the obligation runner) also treat ledger-linked segment ids as the conversation's. This happens only when every conversation that upload fed has a tombstone, so a shared upload never erases a live sibling's pipeline rows. Rows already matched by identity behave as before.
  • delete_ai_user_profile also deletes ai_user_profile_v2.
  • Unchanged: the tombstone-first ordering, the legal-hold deferral (_accept_held_conversation_delete still returns before any erasure), erasure obligations, and the account gate.
  • Account deletion already covers these stores: delete_all_user_storage_objects sweeps syncing/{uid}/ in both buckets, purge_user_subtree runs the full purge_batch_owner(uid), and the user-doc wipe removes the v2 field. No change needed there.

Exception, explained: a staging dir shared by an upload that fed several conversations (about 6% of ledger rows in a 2,000-row prod sample) is removed when any of them is deleted. That matches the existing raw-sync/raw-mobile-batch original handling in delete_conversation_audio_files. Batch rows from such an upload wait until all of its conversations are deleted. Staging for uploads that produced no conversation (silence or failed jobs) has no conversation owner; only account deletion removes it.

Tests

  • test_sync_ledger_sources.py (new) covers: all four result fields queried, unsafe job_id dropped, 30-id chunking, the "every fed conversation tombstoned" rule, no stage means no read, and the inline purge_batch_owner erasing ledger-linked rows.
  • test_owner_storage_purge_and_gate.py covers: staging and donor prefixes erased only for this owner and job; a held staging object kept and reported after every prefix is tried; no ledger row leaves staging untouched.
  • test_conversation_batch_purge_resumable.py covers: the obligation runner erases provisional-identity rows the ledger names and keeps an unrelated upload. With the change reverted this test fails.
  • Updated to the new contract: test_conversation_tombstones.py (a non-cascade delete schedules the audio purge with donors) and test_delete_conversation_cancels_task_reminders.py (donors are read without the canonical bucket).
  • test_ai_user_profile_route.py checks that forget clears both profile fields.
  • Ran locally with backend/test.sh: all 78 unit files that reference the delete/purge/profile paths, plus test_firestore_query_shapes.py and test_firestore_outside_query_contract.py, pass.

Dev verification

Synthetic test account only (no customer data). Evidence: object listings before and after, plus scripts, kept outside the repo.

  • Dev, before merge. The branch can't be deployed to dev before merge: gcp_backend.yml deploys only merged main SHAs, and auto-dev follows Release Eligibility. So I ran the real DELETE /v1/conversations/{id}?cascade=true route function in-process with the dev Cloud Run env and secrets, against dev GCS (syncing-local-development, omi-dev-private-cloud-sync) and the _dev Firestore collections. Base commit 4a680e2e7c was the control.
    • Each conversation is fed by a real dev sync upload's staging object and ledger row. Two fixture steps were needed: dev STT fails every job (STT_SERVICE_MODELS lists retired Deepgram models), so I wrote the conversation doc and ledger link a successful job writes, plus one chunk object.
    • Control (main code): 204 tombstoned. Its staging syncing/<uid>/887add7f…/…wav remains (bug reproduced).
    • Branch: 204 tombstoned. Its staging syncing/<uid>/48078ee3…/…wav and chunks/<uid>/<cid>/… are gone, and the tombstone is recorded. The unrelated upload's staging is untouched.
  • Dev environment problems found on the way (not changed here):
    1. BUCKET_OBJECT_LAKE=omi-dev-object-lake-uc1 does not exist, so every dev conversation delete returns 503. Both runs above used BUCKET_OBJECT_LAKE= to skip it.
    2. Dev Cloud Run has no BUCKET_PRIVATE_CLOUD_SYNC, so it falls back to the prod bucket name.
    3. api.omiapi.com routes most paths to prod (dev-to-prod-api).
  • Prod run with today's code (synthetic account, normal API): two sync uploads, the second merged into the first conversation, so its batch rows carry the provisional capture id. DELETE ?cascade=true returned 204 tombstoned. After the batch purge obligation settled (about 40 min, artifact_pending behind the late-upload window), every object was gone and only 2 content-free projection_state: erased ordering rows remained. The merged segment was caught here because its result had been projected onto the conversation. The gap this PR closes is narrower: rows not projected (yet, or ever), which only the ledger links. In a read-only sample that was 34 of 200 jobs and 8 of 200 results. These upload-path batch uploads stage nothing in syncing-local, so bug 1 concerns the legacy sync path and existing staging.

Failure-Class: new
Line-Count-Exception: backend/utils/other/storage.py | 2803 -> 2848 | the staging purge sits next to the conversation audio purge it extends; same helpers and blocked-object aggregation
Line-Count-Exception: backend/database/users.py | 2719 -> 2722 | forget-profile must also clear the retired v2 field

🤖 Generated with Claude Code

…inked batch rows and the retired v2 profile

- Delete (cascade and non-cascade) now erases the conversation's sync staging
  (syncing/{uid}/{job_id}/, found via the sync content ledger) and merge-donor
  audio prefixes through the existing owner-prefix purge; held objects stay.
- Both conversation batch purges also erase batch rows the ledger links to the
  conversation, once every conversation the upload fed is tombstoned.
- Forget AI profile clears the orphaned ai_user_profile_v2 field.
@kodjima33
kodjima33 merged commit 3e1a54b into main Nov 24, 2026
75 checks passed
@kodjima33
kodjima33 deleted the fix/delete-purges-audio branch November 24, 2026 09:20
Git-on-my-level added a commit that referenced this pull request Nov 25, 2026
)

## Summary

On resumed keyed from-segments uploads, keep the persisted client
projection display-only. Validate retry projections against submitted
segments, then discard them during an active resume because the admitted
row's stored transcript remains authoritative. Keep projection data out
of coordinator input and persistence writes; reuse the same admitted row
and transcript. Existing digest-checked late binding on completed
idempotency hits remains unchanged. The regression test covers valid and
schema-incompatible stored projections and a valid retry projection. The
pipeline change note records this lifecycle boundary and its
release-train handling.

PR #26219 remains untouched as the exact revert of #26215.

## Verification

- `test_client_processing_trust_boundary.py`: 61 passed on M1 through
`bin/omi-heavy`.
- `test_developer_from_segments_idempotency.py`: 94 passed on M1 through
`bin/omi-heavy`.
- `git diff --check`: passed.

Failure-Class: none
Line-Count-Exception: backend/routers/developer.py | 2897 -> 2907 |
preserve keyed retry projection trust boundary
Git-on-my-level added a commit that referenced this pull request Nov 25, 2026
Reverts #26215 at `3e1a54b0b924fcd460db162507ee4c9429a34162` under
Shipping’s R26 ruling on SCA-1819. Deleting one conversation in a shared
upload currently erases staging audio that a live sibling still
references. The PR also expanded default delete audio erasure without
durable retry on the regular request path.

The patch is byte-for-byte the inverse of #26215 relative to its first
parent. The tree diff from that parent to this PR head matches #26207’s
first-parent patch byte-for-byte, preserving keyed from-segments
uploads. `git diff --check` passed.

Release owns merge after green exact-head CI. The re-land requires a
full custody review of the repaired head.

Line-Count-Exception: backend/routers/conversations.py | 3197 -> 3199 |
Restore the pre-#26215 cascade-only audio deletion block and its storage
guard to preserve shared-upload custody.

<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/26219?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>
<a
href="https://www.cubic.dev/action/auto-fix/pr/BasedHardware/omi/26219?returnTo=https%3A%2F%2Fgithub.com%2FBasedHardware%2Fomi%2Fpull%2F26219&source=description"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"><img
alt="Turn on auto-fix"
src="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
shubhxho pushed a commit to shubhxho/omi that referenced this pull request Nov 25, 2026
Git-on-my-level added a commit that referenced this pull request Nov 25, 2026
Records the shared-upload custody regression and the pre-#26215 behavior
restored by #26219. Shipping authorized this docs-only PR to preserve
the exact revert patch.

The note records the reviewed revert head and the last serving receipt
available at publication. Add the merged revert SHA when Release
verifies it. Add the serving receipt when available, or link the pending
rollout record if service verification is still open at the four-hour
docs deadline.

[Connector
finding](#26219 (comment))


<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/26224?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>
<a
href="https://www.cubic.dev/action/auto-fix/pr/BasedHardware/omi/26224?returnTo=https%3A%2F%2Fgithub.com%2FBasedHardware%2Fomi%2Fpull%2F26224&source=description"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"><img
alt="Turn on auto-fix"
src="https://www.cubic.dev/buttons/turn-on-auto-fix-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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant