Repository navigation
SCA-1819: Reland #26215 conversation delete scope with sibling-safe staging and durable audio retry - #26225
SCA-1819: Reland #26215 conversation delete scope with sibling-safe staging and durable audio retry#26225Git-on-my-level wants to merge 12 commits into
Conversation
…inked batch rows and the retired v2 profile (#26215) * fix(backend): conversation delete erases sync staging audio, ledger-linked 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. * test(backend): register sync ledger source queries; add failure class * fix(backend): type the conversation audio purge steps * fix(backend): forget-profile update names both fields literally
…tion delete Fixes the Owners FIX BEFORE RELEASE findings on #26215 (reapplied in the previous commit on top of revert #26219). - A shared upload's staging directory (syncing/{uid}/{job_id}/, both buckets) is erased only once every conversation that upload job fed is tombstoned and the upload completed (sync_ledger_sources.staging_plan). A live sibling keeps the bytes; the last sibling's deletion removes them. All ledger rows naming the job are read, not only the deleted one's. - Every delete that erases audio (both cascade modes) now arms a durable conversation_audio_erasure_jobs obligation before the primary row goes. The existing reconciler/queue/handler dispatch it (kind audio_erasure); run_audio_erasure_job needs only the tombstone, runs every step under the account's audio deletion gate (refuses a legal hold), records storage holds and in-flight staging on the obligation and retries them, and lets ledger-read failures redrive. Kill switch CONVERSATION_AUDIO_ERASURE_OBLIGATION_ENABLED (default on) restores the after-response background erasure. - Ledger-owed batch segments are journaled up front, so a resumed cursor already past discovery still erases them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…A-1819) Co-Authored-By: Claude Opus 5.5 <[email protected]>
- F1: staging still retained after the 14-day window stays owed as staging_unsettled (error-logged every pass, rechecked daily); never discharged while the prefix is kept. - F2: staging_plan treats the deleting conversation and its merge donors as deleted, so an obligation racing the cascade's donor tombstones still erases the donor upload's staging. - F3: kill switch gates the reconciler's audio dispatch and the runner (held as switched_off, resumes when back on). - F4: runner holds (conversation_row_live) while the conversation row is still visible after a delete that failed past arming. - F5: due_jobs query driver covers conversation_audio_erasure_jobs. - F6: route tests for the switch off (falsy tokens) and on. - F7: change note documents drain-before-rollback and switch-off semantics. - F8: a fed conversation with neither row nor tombstone is gone, not live; completions that keep staging for a live sibling are logged. - F9: a re-armed run records last_reason=rearmed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
omi-panel review-20261124t110029-ab1c (FIX at
Verification:
The PR body and change note are updated. Release owns merge/deploy; this still needs the full custody review (Owners/batch-custody). |
- F1: the audio obligation records every staging job it reaches, with the job's fed conversations, on its first run (before any hold or kill-switch check). staging_plan treats that record as authoritative alongside the ledger, so a held obligation that outlives the 45-day ledger still erases its prefixes and still honors recorded live siblings. It is never discharged while a recorded prefix is kept for a live sibling: it is held and rechecked daily. - F2: lost_gate_to_peer takes the gate kind; the audio runner classifies audio_conversation_deletion contention as busy. - F3: non-obligation callers (switch-off background path, v3 recording purge) are documented as explicit retention exceptions in the change note; the v3 purge has no tombstone to authorize an obligation. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
omi-panel round 2, review-20261124t113730-254b (FIX at
Also in this commit: query drivers registered for Verification:
The change note and PR body are updated. Release owns merge/deploy; this still needs the full custody review (Owners/batch-custody). |
- F1: the after-response fallback sweep runs entirely under the account's audio_conversation_deletion gate (delete_conversation_audio_under_gate); a legal hold, unreadable hold authority or busy gate stops it before any erasure and the retention is logged (documented retention exception). - F2: the obligation records per-job settled state; a recorded job whose ledger rows expired counts as settled only if a pass saw it completed, otherwise it is held in flight. Passes left waiting re-read the ledger and merge newly fed siblings into the record. - F3: deliberate audio holds reset attempts so they do not trip the stuck-obligation alert; real failures still count. - F4: a held canonical pack object is reported as a blocked object (storage_hold) and the other steps still run. - F5: each audio outcome clears detail fields it does not set. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
omi-panel round 3, review-20261124t120520-00cb (FIX at
Route tests now patch Verification:
The change note and PR body are updated. Release owns merge/deploy; this still needs the full custody review (Owners/batch-custody). |
- F1 (ruled DOCUMENT): a sync conversation deleted after its ledger rows expired cannot be traced to its staging; accepted retention exception in the change note. The audio obligation records sync_sourced at arm and the runner logs staging_undiscoverable_after_ledger_ttl. - F2: owed batch segment ids are journaled in chunks of <=400 writes; a cursor past discovery is rewound and persisted first, so dependents run only after every chunk is recorded. - F3: every audio pass re-reads the ledger (read-only, before any hold) and merges fed siblings and settled state into the record. - F4: a visible conversation row backs off 5 min doubling to hourly, then daily after 24 h, when it also counts toward the stuck alert; budget basis text updated. - F5: the emulator route fixture patches delete_conversation_audio_under_gate. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
omi-panel round 4 (review-20261124t123120-563a): addressed in 50f52f7.
Tests:
Release owns merge and deploy. This change still needs a full custody review (Owners/batch-custody). |
- F1: the arming request writes delete_completed_at on the audio obligation right after the primary row is deleted (an ordinary delete removes the row in both cascade modes); the runner erases on that marker, and a held-for-row run is made due at once. A request that fails after arming leaves it unset and the row-live backoff applies. Emulator tests drive the real route for both. - F2: staging_plan treats a soft-deleted sibling, or an absorbed merge donor whose redirect chain (resolve_snapshot) ends deleted or at the deleting conversation, as deleted; a donor of a live survivor stays live. - F3: a shared-live settled job with an empty prefix in every staging bucket no longer holds the obligation. - F4: sibling reads batched with get_all, capped at 200 per pass; the deleted ones are recorded on the obligation and the rest continue (staging_siblings_pending). Budget basis restated per sibling. - F5: cloud-tasks contract test for the audio erasure task. - F6: erase_conversation_audio re-enters the real audio gate. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Final panel (review-20261124t131246-1258): addressed in 72f0d97.
Tests:
Release owns merge and deploy. This change still needs a full custody review (Owners/batch-custody). |
- F2+F3: mark_audio_delete_completed is transactional and writes only onto an existing obligation; a discharged one is never recreated. - F4: an upload whose ledger rows ended in a failure state with an empty staging prefix in every bucket no longer holds the obligation; with bytes left it stays in flight, then staging_unsettled (daily, error log). - F1: the staging plan reuses the pass's ledger read (no second ledger query); the audio budget restates per-pass and daily reads with the arithmetic. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Confirmation panel (review-20261124t135937-5266): addressed in 3892a75.
Tests:
Release owns merge and deploy. Next is the full custody review (Owners/batch-custody). |
The mixed-version emulator proofs run the reconciler against the pre-coalescing jobs module, which has no AUDIO_COLLECTION; the dispatch loop read it from that module for every due job. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Also fixed in a22dad3: CI |
Brings the reland onto current main, which now carries the #26219 revert and #26316 (SCA-4363 audio legal-hold gate). Conflict resolutions: - storage: delete_privacy_conversation_audio holds the account's audio_conversation_deletion gate across every step (main's SCA-4363 contract, also relied on by the v3 purge); the steps moved to _delete_conversation_audio_steps. The gate is re-entrant, so the durable obligation (erase_conversation_audio) and the kill-switch sweep (delete_conversation_audio_under_gate) still hold one gate. - routers/conversations: the kill-switch after-response sweep keeps main's LegalHoldActive -> defer_audio_erasure durable follow-up; other gate refusals are retained and reported as before. _delete_conversation_under_gate takes both audio_source_ids and expected_exists. - conversation_batch_purge_jobs.finish_run: keeps the audio obligation's detail, arm_revision, retry_after and count_attempt handling together with main's erased_audio_source_ids donor check and post-window _schedule. - Tests: main's shared fake now seeds a live c1 row and applies DELETE_FIELD; the audio fixtures delete the row as the route would. Main's hold-gate route tests run with the obligation switched off (the path they cover); donor prefixes are now erased with the recording. Episodes driver entries stay deleted with the engine; flag registry regenerated. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Relands #26215 (Nik, merge
3e1a54b0) with the custody fixes the Owners reviewer required on SCA-1819 (FIX BEFORE RELEASE, 2026-11-24 09:50Z).Base: refreshed onto current
mainon 2026-11-29 by mergingmain(953f27b0432e) into this branch; the earlier commits keep their reviewed SHAs. Revert #26219 merged as755471d81eee, so GitHub's diff againstmainis now only the reland and the fixes. Commit618ec333re-applies #26215 unchanged; the later commits add the Owners fixes; the merge commit records the conflict resolutions below.Refresh onto main (2026-11-29)
Main gained #26316 (SCA-4363), which holds one
audio_conversation_deletiongate across the whole conversation audio delete and, on the after-response path, turns aLegalHoldActiverefusal into a durabledefer_audio_erasurefollow-up. Both fixes in this PR are preserved and reconciled with it:staging_plan/delete_conversation_sync_stagingstill erase a job'ssyncing/{uid}/{job_id}/only when every fed conversation is tombstoned and the upload completed.conversation_audio_erasure_jobsbefore the primary row goes, andrun_audio_erasure_jobretries storage holds, in-flight staging, ledger-read failures and legal holds.storage.py).delete_privacy_conversation_audionow holds the account's audio gate across every step, as main requires; the v3 purge relies on that. The steps moved to_delete_conversation_audio_steps. The gate is re-entrant for the same uid and kind, soerase_conversation_audio(obligation) anddelete_conversation_audio_under_gate(kill-switch sweep) still run under one gate token.routers/conversations.py). Main'sLegalHoldActive→defer_audio_erasureis kept on this path. A hold that lands after acceptance is now durably owed through the accepted-delete erasure obligation, where it was previously retained and logged. Other gate refusals are still retained and reported._delete_conversation_under_gatetakes bothaudio_source_ids(this PR) andexpected_exists(main).finish_run. The audio obligation'sdetail,arm_revision,retry_afterandcount_attemptare combined with main'serased_audio_source_idsdonor check and post-window_schedule.c1row and appliesDELETE_FIELD, so the audio-obligation fixtures delete the row as the route would.CONVERSATION_AUDIO_ERASURE_OBLIGATION_ENABLED=false, the path they cover. They now also expect the donor prefix erasure.test_no_hold_lands_between_canonical_and_prefix_deletesexpects the v3 sweep's donor prefixes twice: once from the helper and once from the sweep's own loop. The repeat is an idempotent delete under the same gate.What #26215 did (re-applied in commit 1)
database/sync_ledger_sources.pyreads the owner's sync content ledger to find which uploads fed a conversation:job_id(the staging directory),batch_pipeline.segment_ids(batch rows), andresult/partial_result(conversation ids).syncing/{uid}/{job_id}/insyncing-localand the derived bucket). It uses the existing owner-prefix purge.cascade=false) now erases audio as well.ai_user_profile_v2field (backend/database/users.py, tested intest_ai_user_profile_route.py)..github/failure-classes/FC-conversation-delete-misses-upload-keyed-storage.jsonexactly as fix(backend): conversation delete erases sync staging audio, ledger-linked batch rows and the retired v2 profile #26215 had it.Owners findings and the fixes
1. Live sibling loss (blocking).
staging_job_idsand the prefix purge deleted a shared upload's whole staging prefix when any conversation it fed was deleted, including bytes a live sibling still needed.Fix: the new
sync_ledger_sources.staging_planapplies the same "every fed conversation tombstoned" rule that #26215 applies to batch rows.job_id ==query), not only the rows that list the deleted conversation, because the directory is keyed by job.erasableonly when every conversation fed by any of those rows has a tombstone and every row iscompleted.shared_liveand its bytes stay. The last sibling's delete removes them. An obligation that keptshared_livestaging stays held (last_reason=staging_kept_for_live_sibling, rechecked daily) and erases the prefix once the sibling is deleted.staging_sources). That record is authoritative alongside the ledger, so a held obligation that outlives the 45-day ledger TTL still erases its prefixes and still protects recorded live siblings.in_flight. The job still reads that staging and may feed another conversation, so the durable runner retries it later.staging_job_idsnow returns only the erasable jobs.storage.delete_conversation_sync_stagingpurges only the erasable jobs and logs counts of retained ones.2. Default-delete audio erasure was not durable. The route returned 204 before the work, the callback only logged
StoragePrefixPurgeBlocked, a retry exitedalready_deleted, and the batch obligation did not replay staging cleanup.Fix: audio erasure now goes through the existing obligation machinery in
database/conversation_batch_purge_jobs.py, extended with a third obligation kind._delete_conversation_under_gatecallsarm_audio_erasure(both cascade modes). It records merge donors and runs after the tombstone and before the primary row is deleted. If the arm fails, the request returns 503 while the row is still there, so a retry is not answeredalready_deleted.conversation_audio_erasure_jobsis a separate collection, so a consumer that predates it can never run a cascade for it. An old consumer drops the unknown kind and the reconciler redrives it.reconcile_conversation_batch_purgesdispatches it withkind: audio_erasure, spread per account like erasures.POST /v1/conversations/deletion-batch-purges/runsends it torun_audio_erasure_job(erase=storage.erase_conversation_audio).assert_account_deletion_permittedfirst.erase_conversation_audioruns every step (canonical packs, conversation and donor prefixes, staging) under the account'saudio_conversation_deletiondestructive-operation gate. The gate refuses an active legal hold. This also covers the Owners point that staging deletes ran outside any hold check after the route gate was released.audio_conversation_deletiongate for every step (storage.delete_conversation_audio_under_gate). A legal hold placed after acceptance stops it, and the audio is retained and logged; that path has no retry and is a documented retention exception.StoragePrefixPurgeBlockedis recorded on the obligation (last_outcome=held,last_reason=storage_hold,blocked_objects,unverified), logged as a warning with counts only, and rechecked hourly. It is never dropped.last_reason=staging_in_flightand rechecked hourly. After 14 days the obligation is not discharged while staging is retained: it stays owed aslast_reason=staging_unsettled, is escalated with an error log on every pass, and is rechecked daily until the prefix is erased.last_reason=conversation_row_live, rechecked after 5 minutes) instead of erasing the audio.failedwith the exception type recorded, then return 500 so the queue retries and the reconciler redrives.arm_revision, so the run does not complete the obligation (last_reason=rearmed) and it runs again.3. Resumed batch-purge discovery (Owners "Batch rows" point).
purge_conversationsnow journals the ledger-owed segment ids that still hold this owner's content, before scanning. If the cursor is already past that namespace's discovery, it resumes at that namespace's dependents. A run checkpointed before the rule existed, or before the last sibling was tombstoned, therefore still erases them. Erased results are not journaled again.4. Hold and ordering. Covered by the audio gate in fix 2.
David's ruling
Kill switch
CONVERSATION_AUDIO_ERASURE_OBLIGATION_ENABLEDis an envops_killswitch, default on and registered inconfig/feature-flags.yaml.false,off,0ornorestores the after-response background erasure from fix(backend): conversation delete erases sync staging audio, ledger-linked batch rows and the retired v2 profile #26215.last_reason=switched_off). Armed obligations resume when the switch is back on.conversation_audio_erasure_jobscannot serve it. Before rolling back backend-sync, drain the collection, or redeploy a serving consumer afterwards (rows stay due and are never lost). The change note documents this.Unchanged: tombstone-first ordering, legal-hold deferral (
_accept_held_conversation_deletestill returns before any erasure), existing erasure obligations, the account gate, theai_user_profile_v2deletion, and automatic empty-generation teardown keeping its audio (that teardown does not use this route).New collection
conversation_audio_erasure_jobshas its read budget declared in.github/firestore-collection-budgets.json(planning-bound: 30 reads per delete, 300k reads/day upper bound).Change note
backend/docs/listen_pusher_pipeline/changes/2026-11-24-conversation-delete-durable-audio-erasure.mdcovers the widened default-delete audio scope (David's ruling), sibling-safe staging, the durable retry path, the kill switch, and the rollout and verification plan.omi-panel reviews
305e6eb5): all nine findings are fixed in5965abf86f4, withd289ecfc3b3adding the reader classification.d289ecfc): all three findings are fixed in the follow-up commit.7ecbf8d9): all five findings are fixed in the follow-up commit.3cfb67fa): fixed in the follow-up commit.staging_undiscoverable_after_ledger_ttl.delete_conversation_audio_under_gate.tests/integration/test_conversation_batch_purge_emulator.pywas run against the Firestore emulator (firebase emulators:exec, through omi-heavy): 16 passed.50f52f7e): fixed in the follow-up commit.users/{uid}/conversations/{id}(no soft-delete flag; only an accepted or held delete hides it withdeleted=True), so the runner was not holding these forever. It could still hold for up to 5 minutes when it ran between arming and the row delete. The arming request now writesdelete_completed_aton the obligation right after the row delete. That makes the obligation due at once, and the runner erases on that marker without checking the row. A request that fails after arming leaves the marker unset, and the backoff for a still-visible row applies. Emulator tests drive the real route for both cases.is_soft_deleted) or is an absorbed donor whose redirect chain (resolve_snapshot) ends deleted or at the deleting conversation. A donor absorbed into a live survivor stays live.list_blobs(max_results=1)) no longer holds the obligation, unless that upload is still running.get_alland capped at 200 per pass. Siblings found deleted are recorded (staging_deleted_siblings) and the rest continue after 60 s (staging_siblings_pending). The budget basis is restated per fed sibling.erase_conversation_audiowith the realdestructive_operation_gate(fake Firestore, GCS stubbed) that re-enters the same-kind gate.72f0d97e): fixed in the follow-up commit.retryable,failed,partial,partial_failure) and whose prefix is empty in every staging bucket no longer holds the obligation. If bytes are left, it follows the existing in-flight path, thenstaging_unsettledwith the daily error log.users.pychange from fix(backend): conversation delete erases sync staging audio, ledger-linked batch rows and the retired v2 profile #26215 is in this branch and tested. See the note under What changed.Backend emulator proofshad failed since round 2 intest_conversation_purge_mixed_version_emulator.py. That suite runs the reconciler against the pre-coalescing jobs module, which has noAUDIO_COLLECTION. The reconciler now binds the audio collection name at import. The mixed-version suite (19) and the batch purge emulator suite (19) pass locally.PR comments list each finding with its commit.
Tests
Refreshed head, run on m1 through
omi-heavy(bounded timeouts):backend/test.shwithBACKEND_UNIT_TEST_FILE_LISTcovering 244 unit files: 10,709 passed, 0 failed, 8 skipped. The files are every unit test that references the touched delete, purge, obligation, tombstone, ledger, storage-audio, cloud-task, profile or flag paths, plustest_firestore_query_shapes.py,test_firestore_outside_query_contract.py,test_utils_import_boundary.pyandtest_client_processing_trust_boundary.py.test_conversation_batch_purge_emulator.py(73),test_conversation_purge_coalescing_emulator.py(25),test_conversation_purge_mixed_version_emulator.py(20) andtest_record_wal_handoff_emulator.py(37). 155 passed.scripts/typecheck.sh(pyright): 0 errors.check_feature_flag_registry.py: OK.Earlier rounds' test additions are unchanged; see the PR comments for each finding and its commit.
Not run here: any dev or prod exercise of the route. The production readback is owned on SCA-1819.
Release owns merge/deploy; needs full custody review (Owners/batch-custody).
The #26219 revert removed
.github/failure-classes/FC-conversation-delete-misses-upload-keyed-storage.jsonfrom main. This PR adds it back exactly as #26215 had it, so the class is declarednew.Failure-Class: new
Line-Count-Exception: backend/utils/other/storage.py | 2817 -> 3075 | staging plan and durable audio erasure sit beside the conversation audio purge they extend; same helpers and blocked-object aggregation
Line-Count-Exception: backend/routers/conversations.py | 3523 -> 3575 | delete route arms the durable audio obligation before primary deletion
Line-Count-Exception: backend/routers/users.py | 2923 -> 2933 | obligation task handler routes the audio_erasure kind
Line-Count-Exception: backend/database/users.py | 3112 -> 3115 | forget-profile must also clear the retired v2 field
🤖 Generated with Claude Code