Skip to content

SCA-1819: Reland #26215 conversation delete scope with sibling-safe staging and durable audio retry - #26225

Draft
Git-on-my-level wants to merge 12 commits into
mainfrom
reland/sca-1819-delete-scope
Draft

Git-on-my-level wants to merge 12 commits into
mainfrom
reland/sca-1819-delete-scope

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

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 main on 2026-11-29 by merging main (953f27b0432e) into this branch; the earlier commits keep their reviewed SHAs. Revert #26219 merged as 755471d81eee, so GitHub's diff against main is now only the reland and the fixes. Commit 618ec333 re-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_deletion gate across the whole conversation audio delete and, on the after-response path, turns a LegalHoldActive refusal into a durable defer_audio_erasure follow-up. Both fixes in this PR are preserved and reconciled with it:

  • Sibling-safe staging. Unchanged: staging_plan / delete_conversation_sync_staging still erase a job's syncing/{uid}/{job_id}/ only when every fed conversation is tombstoned and the upload completed.
  • Durable erasure retries. Unchanged: the delete arms conversation_audio_erasure_jobs before the primary row goes, and run_audio_erasure_job retries storage holds, in-flight staging, ledger-read failures and legal holds.
  • Gate (storage.py). delete_privacy_conversation_audio now 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, so erase_conversation_audio (obligation) and delete_conversation_audio_under_gate (kill-switch sweep) still run under one gate token.
  • Kill-switch fallback (routers/conversations.py). Main's LegalHoldActive → defer_audio_erasure is 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_gate takes both audio_source_ids (this PR) and expected_exists (main).
  • finish_run. The audio obligation's detail, arm_revision, retry_after and count_attempt are combined with main's erased_audio_source_ids donor check and post-window _schedule.
  • Tests.
    • Main's shared fake Firestore now seeds a live c1 row and applies DELETE_FIELD, so the audio-obligation fixtures delete the row as the route would.
    • Main's two route-level audio-gate tests run with 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_deletes expects 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.
    • The Episodes driver entries stay deleted with the engine. The flag registry was regenerated.

What #26215 did (re-applied in commit 1)

  • database/sync_ledger_sources.py reads the owner's sync content ledger to find which uploads fed a conversation: job_id (the staging directory), batch_pipeline.segment_ids (batch rows), and result / partial_result (conversation ids).
  • Conversation delete also erases merge-donor prefixes and the sync staging of the uploads that fed the conversation (syncing/{uid}/{job_id}/ in syncing-local and the derived bucket). It uses the existing owner-prefix purge.
  • Default delete (cascade=false) now erases audio as well.
  • Both conversation batch purges also erase ledger-linked batch rows, but only once every conversation that upload fed has a tombstone.
  • "Forget AI profile" also clears the retired ai_user_profile_v2 field (backend/database/users.py, tested in test_ai_user_profile_route.py).
  • Keeps the failure-class record .github/failure-classes/FC-conversation-delete-misses-upload-keyed-storage.json exactly 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_ids and 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_plan applies the same "every fed conversation tombstoned" rule that #26215 applies to batch rows.

  • It reads every ledger row that names the job (a job_id == query), not only the rows that list the deleted conversation, because the directory is keyed by job.
  • A job is erasable only when every conversation fed by any of those rows has a tombstone and every row is completed.
  • A fed conversation counts as deleted when it has a tombstone, when it is the deleting conversation or one of its merge donors (the deletion owns their audio even before the cascade writes their tombstones), or when neither its row nor a tombstone exists (tombstone-first ordering makes it gone).
  • If a fed conversation is still live, the job is shared_live and its bytes stay. The last sibling's delete removes them. An obligation that kept shared_live staging stays held (last_reason=staging_kept_for_live_sibling, rechecked daily) and erases the prefix once the sibling is deleted.
  • On its first run, before any hold or kill-switch check, the obligation records every staging job it reaches with the job's fed conversations (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.
  • If every fed conversation is tombstoned but the upload has not completed, the job is in_flight. The job still reads that staging and may feed another conversation, so the durable runner retries it later.
  • staging_job_ids now returns only the erasable jobs.
  • storage.delete_conversation_sync_staging purges 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 exited already_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.

  • Arming. _delete_conversation_under_gate calls arm_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 answered already_deleted.
  • Collection. conversation_audio_erasure_jobs is 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.
  • Dispatch and runner. The obligation uses the same lease, generation and redrive path as the others. reconcile_conversation_batch_purges dispatches it with kind: audio_erasure, spread per account like erasures. POST /v1/conversations/deletion-batch-purges/run sends it to run_audio_erasure_job(erase=storage.erase_conversation_audio).
  • Runner checks. The runner needs only the tombstone, so it finishes after the primary row is gone. A missing tombstone means an account wipe already removed everything, so it completes. It calls assert_account_deletion_permitted first.
  • Gate. erase_conversation_audio runs every step (canonical packs, conversation and donor prefixes, staging) under the account's audio_conversation_deletion destructive-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.
  • Kill-switch fallback. The after-response sweep holds the account's audio_conversation_deletion gate 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.
  • Canonical packs. A held canonical pack is reported as a blocked object like any other held object.
  • Ledger re-reads. Passes that left staging waiting re-read the ledger and merge new siblings into the record. A recorded job counts as settled after its ledger rows expire only if a pass saw it completed; otherwise it is held as in flight.
  • Alerts. Deliberate holds reset the attempt count, so only real failures reach the stuck-obligation alert. Each outcome clears stale detail fields.
  • Storage holds. StoragePrefixPurgeBlocked is 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.
  • In-flight staging. Recorded as last_reason=staging_in_flight and rechecked hourly. After 14 days the obligation is not discharged while staging is retained: it stays owed as last_reason=staging_unsettled, is escalated with an error log on every pass, and is rechecked daily until the prefix is erased.
  • Conversation row still visible. If the delete failed after arming (it answered 503), the runner holds the obligation (last_reason=conversation_row_live, rechecked after 5 minutes) instead of erasing the audio.
  • Ledger-read and provider errors. These end as failed with the exception type recorded, then return 500 so the queue retries and the reconciler redrives.
  • A delete retried during a run gets a new arm_revision, so the run does not complete the obligation (last_reason=rearmed) and it runs again.
  • Accepted (busy-gate) deletes. These also arm the audio obligation, passing the donors recorded at acceptance.

3. Resumed batch-purge discovery (Owners "Batch rows" point). purge_conversations now 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

RULING (David Zhang, 2026-11-24T10:24Z, Shipping lead chat, scope #26215 reland): "Approve widening: default conversation delete (cascade=false) erases that conversation's audio (canonical, donor, sync staging). Condition: audio cleanup moves onto the durable erasure path so failures (storage holds, ledger-read errors) are retried, not only logged."

Kill switch

CONVERSATION_AUDIO_ERASURE_OBLIGATION_ENABLED is an env ops_kill switch, default on and registered in config/feature-flags.yaml.

  • false, off, 0 or no restores the after-response background erasure from fix(backend): conversation delete erases sync staging audio, ledger-linked batch rows and the retired v2 profile #26215.
  • It only takes effect where conversation obligation dispatch is configured. Dev and local keep the background erasure.
  • The sibling-safe staging rule is not switchable; it applies on both paths.
  • With the switch off, the reconciler does not dispatch audio obligations, and a queued task holds its obligation (last_reason=switched_off). Armed obligations resume when the switch is back on.
  • Rollback: an image that predates conversation_audio_erasure_jobs cannot 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_delete still returns before any erasure), existing erasure obligations, the account gate, the ai_user_profile_v2 deletion, and automatic empty-generation teardown keeping its audio (that teardown does not use this route).

New collection conversation_audio_erasure_jobs has 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.md covers 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

  • Round 1 (review-20261124t110029-ab1c, FIX at 305e6eb5): all nine findings are fixed in 5965abf86f4, with d289ecfc3b3 adding the reader classification.
  • Round 2 (review-20261124t113730-254b, FIX at d289ecfc): all three findings are fixed in the follow-up commit.
    • F1: staging sources are recorded on the obligation.
    • F2: contention on the audio gate is classified with its own gate kind.
    • F3: the two non-obligation paths are documented as retention exceptions in the change note, not armed.
  • Round 3 (review-20261124t120520-00cb, FIX at 7ecbf8d9): all five findings are fixed in the follow-up commit.
    • F1: the fallback sweep runs under the audio gate and retains on a hold.
    • F2: a recorded job is settled only if a pass saw it completed, and siblings are re-merged on waiting passes.
    • F3: deliberate holds reset attempts.
    • F4: a held canonical pack is reported as a blocked object.
    • F5: stale detail fields are cleared.
  • Round 4 (review-20261124t123120-563a, FIX at 3cfb67fa): fixed in the follow-up commit.
    • F1: per the coordinator's ruling, a delete issued after the 45-day ledger TTL is an accepted retention exception, documented in the change note. The runner logs staging_undiscoverable_after_ledger_ttl.
    • F2: owed segment ids are journaled in chunks of at most 400.
    • F3: the ledger is re-read and recorded on every pass, before any hold.
    • F4: a visible row backs off from 5 minutes up to hourly, then daily after 24 hours, and then counts toward the alert.
    • F5: the emulator test patches delete_conversation_audio_under_gate. tests/integration/test_conversation_batch_purge_emulator.py was run against the Firestore emulator (firebase emulators:exec, through omi-heavy): 16 passed.
  • Final panel (review-20261124t131246-1258 at 50f52f7e): fixed in the follow-up commit.
    • F1: verified against the real route. An ordinary delete in either cascade mode physically deletes users/{uid}/conversations/{id} (no soft-delete flag; only an accepted or held delete hides it with deleted=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 writes delete_completed_at on 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.
    • F2: a fed sibling also counts as deleted when its row is soft-deleted (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.
    • F3: a shared-live job whose prefix is empty in every staging bucket (list_blobs(max_results=1)) no longer holds the obligation, unless that upload is still running.
    • F4: sibling reads are batched with get_all and 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.
    • F5: added the cloud-tasks contract test for the audio task name, payload and probe.
    • F6: added a test of erase_conversation_audio with the real destructive_operation_gate (fake Firestore, GCS stubbed) that re-enters the same-kind gate.
    • Emulator suite: 19 passed.
  • Confirmation panel (review-20261124t135937-5266 at 72f0d97e): fixed in the follow-up commit.
    • F2+F3: the completion marker is written in a transaction and only onto an existing obligation. A discharged obligation is not recreated.
    • F4: an upload whose ledger rows ended in a failure state (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, then staging_unsettled with the daily error log.
    • F1: each pass reads the ledger once, and the staging plan reuses that read. The budget is restated with its arithmetic: about 27 reads per pass for a typical delete, a ceiling of about 23 + 400 sibling reads, and 400,000 reads per day.
    • F5: verified. The users.py change 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.
    • CI Backend emulator proofs had failed since round 2 in test_conversation_purge_mixed_version_emulator.py. That suite runs the reconciler against the pre-coalescing jobs module, which has no AUDIO_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.
    • Unit selection: 2,441 passed, 1 failed (the existing failure).

PR comments list each finding with its commit.

Tests

Refreshed head, run on m1 through omi-heavy (bounded timeouts):

  • backend/test.sh with BACKEND_UNIT_TEST_FILE_LIST covering 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, plus test_firestore_query_shapes.py, test_firestore_outside_query_contract.py, test_utils_import_boundary.py and test_client_processing_trust_boundary.py.
  • Firestore emulator proofs on a private emulator: test_conversation_batch_purge_emulator.py (73), test_conversation_purge_coalescing_emulator.py (25), test_conversation_purge_mixed_version_emulator.py (20) and test_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.json from main. This PR adds it back exactly as #26215 had it, so the class is declared new.

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

kodjima33 and others added 5 commits November 24, 2026 05:27
…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]>
- 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]>
@Git-on-my-level

Copy link
Copy Markdown
Member Author

omi-panel review-20261124t110029-ab1c (FIX at 305e6eb5): every finding is addressed in 5965abf86f4. d289ecfc3b3 registers the two new conversation-row reads with the reader-classification check. New head: d289ecfc3b3.

# Finding Fix (5965abf) Test
F1 Obligation completed after 14 days while staging was still retained Past the window, the obligation stays held with last_reason=staging_unsettled. Every pass logs an error event=conversation_audio_erasure outcome=staging_unsettled, and it is rechecked daily (AUDIO_STAGING_UNSETTLED_RECHECK_SECONDS). It is discharged only when the erase succeeds. test_staging_still_in_use_stays_owed_past_the_window_and_is_escalated_not_dropped
F2 Donor tombstones raced the obligation staging_plan treats its own conversation_ids (the deleting conversation plus its merge donors, the obligation's audio_source_ids) as deleted. The deletion owns their audio before the cascade writes their tombstones. The F4 row check keeps the runner off a conversation whose delete has not finished. test_obligation_runs_before_donor_tombstones_and_still_erases_the_donor_upload, test_merge_donor_of_the_deletion_counts_as_deleted_before_its_tombstone_lands
F3 Kill switch only gated arming The reconciler skips the audio due-scan when durable_audio_erasure() is false. The handler passes enabled=durable_audio_erasure to run_audio_erasure_job, which holds the obligation (last_reason=switched_off) instead of erasing. Obligations resume when the switch is back on. test_kill_switch_off_holds_armed_audio_obligations_and_they_resume_when_on
F4 Obligation could erase a still-visible conversation after a failed delete The runner point-reads the conversation row. If the row exists and is not deleted, it holds with last_reason=conversation_row_live and rechecks in 5 minutes. test_visible_conversation_row_waits_instead_of_losing_its_audio
F5 due_jobs query driver was missing the audio collection conversation_audio_erasure_jobs added to its collection domains. test_firestore_query_shapes.py
F6 No kill-switch route test Real-route tests: with dispatch configured, the falsy tokens off, false, 0, no and OFF arm nothing and run the background erasure; with the switch on, a default delete arms the obligation. test_kill_switch_off_arms_no_audio_obligation_and_erases_after_the_response[*], test_kill_switch_on_arms_the_audio_obligation_for_a_default_delete
F7 Change note lacked drain-before-rollback The change note documents switch-off semantics (armed obligations held and resumed; new deletes use the background path). It also states that rolling backend-sync back to an image without conversation_audio_erasure_jobs requires draining the collection first, or redeploying a serving consumer afterwards. n/a
F8 shared_live never retried, and an untracked fed id kept staging forever A fed conversation with neither a row nor a tombstone is treated as gone; tombstone-first ordering makes that safe. A completion that kept staging for a live sibling logs last_reason=staging_kept_for_live_sibling shared_live=N; that sibling's own deletion owes the staging. test_fed_conversation_with_neither_row_nor_tombstone_is_gone_not_live, test_staging_kept_for_a_live_sibling_is_logged_when_the_obligation_completes
F9 Re-armed run recorded last_reason=completed It now records last_reason=rearmed. test_rearm_during_a_run_is_erased_again_not_completed

Verification:

  • backend/test.sh through bin/omi-heavy, on the same 52-file affected selection: 2,398 passed, 1 failed. The failure is test_client_processing_trust_boundary.py::test_pinned_reference_set_is_exact, which already fails without this branch; SCA-4146: Keep persisted client projection display-only on retry #26222 fixes it.
  • pyright: 0 errors.
  • check_feature_flag_registry, check_firestore_collection_budget and check_conversation_readers pass.
  • The pre-push preflight passed with this PR body.

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]>
@Git-on-my-level

Copy link
Copy Markdown
Member Author

omi-panel round 2, review-20261124t113730-254b (FIX at d289ecfc): all three findings are addressed in 7ecbf8d99b6, which is the new head.

# Finding Fix (7ecbf8d) Test
F1 A held obligation could outlive the 45-day ledger TTL On its first run, before any hold or kill-switch check, run_audio_erasure_job records every staging job the deletion reaches, with all conversations that job fed (sync_ledger_sources.staging_sources). The record goes on the obligation as staging_sources and staging_recorded_at, written under run ownership. staging_plan(recorded=...) treats the record as authoritative alongside any fresh ledger read: recorded jobs are always considered and recorded siblings always count, and a job whose ledger rows are gone counts as settled. The obligation is never discharged while a recorded prefix remains. Held objects keep it storage_hold. Staging kept for a live sibling keeps it held (staging_kept_for_live_sibling, rechecked daily) until that sibling is deleted. test_recorded_staging_outlives_the_ledger_and_keeps_the_obligation_owed, test_recorded_live_sibling_still_protects_its_staging_after_the_ledger_expires, test_staging_kept_for_a_live_sibling_stays_owed_until_that_sibling_is_deleted, test_recorded_staging_reaches_the_plan_on_the_durable_path
F2 Contention on the audio gate was classified as a failure lost_gate_to_peer(error, uid, kind=...). The audio runner passes audio_conversation_deletion (AUDIO_GATE_KIND), so peer contention counts as busy (30 s retry). test_audio_gate_contention_is_busy_not_failure
F3 Callers without an obligation keep in-flight staging forever Chose to document rather than arm. The change note now has a Retention exceptions section covering the switch-off/no-dispatch background path (the kill switch's fallback) and the v3 recording purge purge_audio. That purge has no tombstone, which is the runner's only authority to erase, so arming there would complete as no_tombstone. The note also covers the residual case: a sibling deleted after the ledger expired with nothing recorded, where account deletion still sweeps syncing/{uid}/. n/a

Also in this commit: query drivers registered for staging_sources and _job_rows, plus the recorded domain for staging_plan.

Verification:

  • backend/test.sh through bin/omi-heavy, on the same 52-file affected selection: 2,404 passed, 1 failed. The failure is the same pre-existing test_client_processing_trust_boundary.py::test_pinned_reference_set_is_exact; it fails without this branch and SCA-4146: Keep persisted client projection display-only on retry #26222 fixes it.
  • test_firestore_query_shapes.py and test_firestore_outside_query_contract.py: 671 passed.
  • pyright: 0 errors.
  • Reader classification, feature-flag registry and collection budget checks pass, and the pre-push preflight passed.

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]>
@Git-on-my-level

Copy link
Copy Markdown
Member Author

omi-panel round 3, review-20261124t120520-00cb (FIX at 7ecbf8d9): all five findings are addressed in 3cfb67fa348, which is the new head.

# Finding Fix (3cfb67f) Test
F1 With the switch off, the fallback could delete audio after a legal hold was placed The after-response fallback (and the accepted-delete cleanup without the switch) now calls storage.delete_conversation_audio_under_gate. It holds audio_conversation_deletion for the whole sweep (canonical, prefixes, staging). Gate acquisition refuses an active hold, so LegalHoldActive, LegalHoldAuthorityUnavailable or a busy gate stops it before any erasure. _delete_privacy_audio_after_response then logs event=conversation_audio_purge outcome=retained reason=<name>. Other errors still raise. Recorded under Retention exceptions in the change note, since this path has no retry. test_best_effort_audio_sweep_holds_the_audio_gate_and_a_hold_stops_it, test_background_audio_sweep_stopped_by_a_hold_retains_and_reports[*], test_background_audio_sweep_surfaces_unexpected_errors
F2 A recorded job with expired ledger rows was treated as settled staging_sources now returns fed and settled (jobs whose ledger rows were all seen completed). The obligation stores both (staging_sources, staging_settled); the record is merged and never shrinks. A recorded job with no ledger rows is settled only if it is in staging_settled; otherwise it is in flight and held. Passes whose last reason was staging_in_flight, staging_unsettled or staging_kept_for_live_sibling re-run staging_sources(extra_jobs=recorded) and merge newly fed siblings. test_sibling_fed_after_the_first_record_survives_the_ledger_ttl, test_unsettled_recorded_job_is_held_after_its_ledger_expires, test_recorded_job_without_ledger_rows_is_settled_only_if_a_pass_saw_it_completed, test_staging_sources_records_fed_conversations_and_settled_jobs
F3 Deliberate holds tripped the "still pending" alert finish_run resets attempts for every held audio outcome (storage hold, staging waits, switched off, row live, legal hold). failed keeps counting, so the alert stays for real failures. test_deliberate_holds_reset_attempts_but_failures_keep_counting
F4 A hold on a canonical audio-pack object was a generic failure A Forbidden objectUnderActiveHold/retentionPolicyNotMet from audio_packs.delete_conversation becomes a blocked object, so the obligation records storage_hold and rechecks. The remaining steps still run. Any other Forbidden still raises. test_held_canonical_pack_is_reported_as_a_blocked_object_and_other_steps_run, test_non_hold_canonical_failure_still_raises
F5 Stale detail fields survived a later outcome Each audio release writes firestore.DELETE_FIELD for every detail field (last_reason, blocked_objects, unverified, in_flight_uploads, shared_live) that the new outcome does not set. test_a_new_outcome_clears_detail_fields_it_does_not_set

Route tests now patch delete_conversation_audio_under_gate instead of delete_privacy_conversation_audio. The query drivers classify the new settled and extra_jobs parameters.

Verification:

  • backend/test.sh through bin/omi-heavy, on the same 52-file affected selection: 2,417 passed, 1 failed. The failure is the same pre-existing test_client_processing_trust_boundary.py::test_pinned_reference_set_is_exact; it fails without this branch and SCA-4146: Keep persisted client projection display-only on retry #26222 fixes it.
  • pyright: 0 errors.
  • Reader classification passes, and the pre-push preflight passed with the updated line-count exceptions.

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]>
@Git-on-my-level

Copy link
Copy Markdown
Member Author

omi-panel round 4 (review-20261124t123120-563a): addressed in 50f52f7.

Finding Fix Test
F1: staging can't be traced after the 45-day ledger TTL Documented as an accepted retention exception in the change note, per Shipping's ruling. The obligation records sync_sourced when armed. When a sync conversation has nothing found or recorded, the runner logs staging_undiscoverable_after_ledger_ttl at info level. test_sync_conversation_with_nothing_traceable_logs_the_accepted_retention
F2: unbounded owed-segment journal transaction Ids are journaled in chunks of at most 400 writes. If the cursor is already past discovery, it is first rewound and checkpointed, so dependents run only after every chunk is recorded. test_more_than_500_owed_segments_are_journaled_in_bounded_chunks
F3: deferred passes skipped the ledger refresh Every pass re-reads staging_sources and persists the merged fed and settled state before any hold (legal hold, switched off, row live, and so on). test_a_legal_hold_pass_still_records_the_ledger_before_it_expires
F4: fixed 5-minute retry on conversation_row_live The retry starts at 5 minutes and doubles up to hourly. After 24 hours it checks daily, and those attempts count toward the stuck alert. The budget basis text is corrected. test_visible_row_backs_off_to_hourly_then_daily_and_counts_toward_the_alert
F5: emulator test patched the old function The emulator test now patches delete_conversation_audio_under_gate. Ran against the Firestore emulator via omi-heavy: 16 passed

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]>
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Final panel (review-20261124t131246-1258): addressed in 72f0d97.

Finding Verification / fix Test
F1 [blocking]: row-live check holds ordinary deletes Checked against the real route. _delete_conversation_under_gate → delete_conversation_and_frame_evidence → delete_conversation_with_sync_sources → conversations_db.delete_conversation, which calls conversation_ref.delete(). So an ordinary delete in either cascade mode, once it answers 204, leaves no row in users/{uid}/conversations/{id} and no soft-delete flag. Only an accepted or held delete hides the row with deleted=True, and the runner already treats that as gone. Ordinary deletes were therefore not held forever. They could be held for up to 5 minutes when the runner ran between arming and the row delete. Fix anyway: the arming request now writes delete_completed_at on the obligation right after the row delete, and that makes it due at once. With the marker set, the runner erases without looking at the row. A held-for-row run whose marker lands mid-run is also made due at once. A request that fails after arming leaves the marker unset, and the backoff for a still-visible row applies. Emulator (real route, real transactions): test_ordinary_delete_through_the_route_lets_the_runner_erase_audio_and_discharge[false/true] and test_delete_failing_after_arming_leaves_the_audio_held_for_the_visible_row. Unit: marker ordering in the route, and the runner's marker, redrive and mid-run cases.
F2 [major]: absorbed donors look live A fed sibling is deleted if it is tombstoned, in the deletion's ids, has no row, or its row passes conversations_db.is_soft_deleted. If that row also has sync_merged_into, the chain is resolved with sync_conversation_snapshot.resolve_snapshot: the donor counts as deleted only if the chain ends deleted or at the deleting conversation. A donor of a live survivor stays live, because its upload is that survivor's audio. Reads are batched with get_all: one tombstone read per sibling, plus one row read if it is untombstoned. Absorbed into a deleted survivor, into the deletion itself, or into a live survivor (two hops, later deleted); soft-deleted with no redirect.
F3: no exit for empty protected prefix A shared-live job is not counted as kept when its prefix is empty in every staging bucket (list_blobs(max_results=1) per bucket). An empty prefix of a still-running upload stays owed. test_staging_kept_for_a_live_sibling_but_already_empty_is_not_owed, test_empty_prefix_of_an_unsettled_shared_upload_stays_owed
F4: unbounded sibling fan-out Capped at 200 siblings per pass and batched with get_all. Siblings found deleted are recorded on the obligation (staging_deleted_siblings) and skipped later. A job with unread siblings and no live one holds as staging_siblings_pending (60 s, attempts not counted). The budget basis is restated per fed sibling. test_sibling_reads_are_batched_and_capped_per_pass_then_continue, test_siblings_over_the_per_pass_cap_are_recorded_and_continued; query-shape registry entries added
F5: cloud_tasks contract Added test_audio_erasure_task_name_payload_and_probe_contract
F6: real gate re-entry Added: the real destructive_operation_gate (fake Firestore, real transaction bodies), GCS stubbed test_durable_erasure_reenters_the_real_audio_gate_it_already_holds

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]>
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Confirmation panel (review-20261124t135937-5266): addressed in 3892a75.

Finding Fix Test
F2+F3: the completion marker could recreate a discharged obligation mark_audio_delete_completed now runs in a transaction. It reads the obligation, writes nothing if it is missing (already discharged), and otherwise updates delete_completed_at and due_at. test_marker_after_the_obligation_was_discharged_recreates_nothing: the runner completes and deletes the obligation, then the marker write leaves no document
F5: users.py missing from the diff Verified: present, not lost. The branch is #26219's revert head with #26215 re-applied. Against that base it includes #26215's delete_ai_user_profile change (it clears ai_user_profile_v2), tested in test_ai_user_profile_route.py. GitHub diffs against main, and main still carries #26215 because #26219 has not merged, so the change does not show there. It appears again after the rebase onto the merged revert. I corrected the PR body text and the Line-Count-Exception note; there is no code change. existing test_ai_user_profile_route.py
F4: uploads that ended in a failure state held the obligation forever staging_plan now flags in-flight jobs whose ledger rows all ended completed or in retryable/failed/partial/partial_failure (none still running). If that job's prefix is empty in every staging bucket (list_blobs(max_results=1)), it is no longer waited on. If bytes are left, it stays in flight and, after 14 days, becomes staging_unsettled with the existing daily error log. Nothing new was added for this. test_upload_that_ended_in_a_failure_state_is_marked_failed_not_running, test_failed_upload_with_an_empty_prefix_keeps_nothing_and_is_not_waited_on, test_failed_upload_with_bytes_left_stays_in_flight_for_the_unsettled_escalation
F1: budget Each pass now reads the ledger once: the runner's staging_sources result is passed to staging_plan, which no longer queries the ledger again. The budget is restated with its arithmetic. A typical pass is about 27 reads (budget 30); the ceiling is about 23 + 1 job query per upload + 200 siblings × 2 per pass. Per day: 10,000 × 30 + 1% held × 24 × 30 + 1,440 polls ≈ 373,000, so the daily budget moves from 300,000 to 400,000. test_plan_reuses_the_passes_ledger_read_without_querying_again; query-shape registry updated

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]>
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Also fixed in a22dad3: CI Backend emulator proofs had failed since round 2. In test_conversation_purge_mixed_version_emulator.py, 5 tests failed with AttributeError: ... has no attribute 'AUDIO_COLLECTION', because that suite runs the reconciler against the pre-coalescing jobs module. The reconciler now binds the audio collection name at import. The mixed-version suite (19) and the batch purge emulator suite (19) both pass locally on the Firestore emulator through omi-heavy.

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]>

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants