Repository navigation
fix(backend): give conversation erasure its own task queue - #25299
Merged
Merged
Conversation
Conversation batch purges and accepted-delete erasures dispatched onto the account-deletion queue (4 dispatches) and ran on the same 4-worker cleanup pool as account wipes. A 533-conversation cleanup queued ~760 of them; real users' accepted deletes and account deletions waited up to 40 minutes, and the reconciler redrove every obligation that waited past 10 minutes, adding duplicate tasks to the same backlog. - New CONVERSATION_ERASURE_TASKS_QUEUE (prod: conversation-erasure) on every dispatcher; the deploy creates the queue (20 concurrent, 5/s, 5 attempts) before traffic moves. Unset, or the queue missing at enqueue, keeps the shared queue (recorded fallback). Account wipes stay alone on account-deletion. - The handler runs on its own 20-worker erasure pool, off cleanup. - The reconciler probes the previous generation's task (new queue, then the shared one) and leaves a still-queued task to run instead of redriving it. An unanswered probe redrives as before (recorded fallback, once per pass). Failure-Class: FC-backlog-release-shares-lane-with-fresh-work Co-Authored-By: Claude Opus 5.5 <[email protected]>
Failure-Class: FC-backlog-release-shares-lane-with-fresh-work Co-Authored-By: Claude Opus 5.5 <[email protected]>
kodjima33
added a commit
that referenced
this pull request
Nov 15, 2026
…ds off instead of failing its task (#25393) ## Problem On Cloud Run `backend-sync`, `POST /v1/conversations/deletion-batch-purges/run` has answered HTTP 500 1,461 times since 2026-11-12T18:05Z. Per day: 53 on 11-12, 1,179 on 11-13, 85 on 11-14 and 144 on 11-15 up to about 11:07Z. The first 500 came an hour after `backend-sync-83c5eaa` (2026-11-12T17:04Z), the first revision to serve the route from #25124. The 11-13 peak was before #25299 (queue switch) and #25298, so neither of those caused it. The handler did log every failure, but only the exception class, and the line is not attached to the request trace. Across the WARNING lines (kept in full), 1,293 of 1,462 failures are `DestructiveOperationInProgress`. The rest are scattered transient Firestore errors (`DeadlineExceeded`, `ServiceUnavailable`, `ValueError` commit contention, `ReadTimeout`). ## Root cause A purge unit waits `UNIT_GATE_WAIT_SECONDS` (30 s) for the account's destructive gate. A same-account multi-delete arms one obligation per conversation, and the reconciler dispatches all of them at once. They then queue on that one gate together with the account's accepted-delete erasures and foreground deletes. A unit that waits past 30 s raises `DestructiveOperationInProgress`. `run_job` treated that as a hard failure: `last_outcome=failed`, a 600 s redrive, and a 500 that also burns the queue's 5 retries. Most 500s therefore take about 30 s, the wait budget. #25197 added the `busy` outcome for erasures (`run_erasure_job`), but batch purges never got it. ## Fix - `run_job` maps a unit that lost the gate to a same-kind peer (`_lost_gate_to_peer`, the helper `run_erasure_job` already uses) to the existing `busy` outcome. That means a 200, the lease released, and a redrive in `BUSY_RETRY_SECONDS`. - `busy` is safe because a unit acquires the gate before erasing anything, so the losing unit erased nothing. The scan position and segment records were already checkpointed under the run's ownership, and the next generation resumes from them. - Privacy invariants from #25124 are unchanged: - An account wipe, retention or audio-deletion gate is never a peer. It still fails the run (tested for each kind). - A legal hold still ends as `held`. - Every erasure is still fenced by its unit's authority. - Run and unit deadlines are unchanged. - A stuck remote-erasure gate is still settled by `settle()` before each unit, and is still reported by `event=destructive_gate_remote_unresolved`. - The handler's failure line now includes the obligation kind, generation, exception type and `sanitize(str(e))`, so every 500 states its reason. - Re-pinned the `run_job` `BODY_DIGEST`. It adds no query: its only stream is still `segment_records`, and the gate check is the existing point read. ## Blast radius (read-only) - 301 distinct obligations failed at least one attempt since 11-12, 202 of them with `DestructiveOperationInProgress`. - None is stuck: all 301 are gone from `conversation_batch_purge_jobs` and `conversation_erasure_jobs`, so they completed. - Success lines look missing for 237 of them only because app stdout INFO is kept at 10% by the `_Default` sink exclusion `app-stdout-info-sample90`. 2xx request logs are also kept at 10% (`cost-audit-cloud-run-success-sample`). - Live right now: 19 batch-purge and 5 erasure obligations, all from one account and all under 1 h old. 18 tasks are queued on `conversation-erasure`. - The roughly 300 403s a day on this path are the reconciler's unauthenticated readiness probe (`conversation_batch_purge_consumer_ready`), which is expected. ## Not in this PR - `/v2/audio-merge-jobs/run` 500s on 11-15 (171 so far) have a different cause. All of them are `stamped playback source could not be read` (`utils/other/storage.py`, strict-source download failure), across 7 conversations, and each fails in under 1 s. They have nothing to do with the gate. - The reconciler still dispatches every due batch-purge obligation of one account at once. A per-account spread like `MAX_ERASURES_PER_ACCOUNT` would cut how many gate waiters there are. With this fix those waiters hand off with `busy` instead of failing, so the spread is a follow-up. ## Tests - `test_unit_losing_its_gate_wait_to_a_same_account_peer_hands_off_busy_and_resumes` reproduces the prod failure. On `main` it raises `DestructiveOperationInProgress: another destructive operation owns the account gate`. With the fix it returns `busy`, erases nothing without the gate, keeps progress, and the next generation purges. - `test_unit_blocked_by_another_destructive_kind_still_fails_the_run[account_deletion|retention_cleanup|audio_conversation_deletion]`. - `test_task_handler_maps_run_outcomes_to_queue_retry` gains a `busy` case (200). `test_task_handler_logs_why_a_run_failed` checks the new failure line and that it is sanitized. - Purge, gate and accept suites pass (111 tests): `test_conversation_batch_purge_{resumable,deadlines,authority}.py`, `test_conversation_delete_gate_wait.py`, `test_conversation_delete_accept.py`. `test_firestore_query_shapes.py` also passes. `make preflight` was run. ## Product invariants affected none ## Failure class (fixes) Failure-Class: FC-user-intent-queued-behind-account-exclusive-work 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/BasedHardware/omi/pull/25393?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/25393?returnTo=https%3A%2F%2Fgithub.com%2FBasedHardware%2Fomi%2Fpull%2F25393&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. -->
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed and why
#25124/#25197 put conversation batch purges and accepted-delete erasures on the
account-deletionCloud Tasks queue (prod: 4 concurrent dispatches). Their handler also ran on the same 4-workercleanup_executoras account wipes. On 2026-11-14 a cleanup of 533 half-deleted conversations queued about 760 tasks there. The queue drained 2 to 3 tasks a minute. 32 real users' accepted deletes and 2 account deletions waited up to 40 minutes. The reconciler also redrove every obligation that had waited longer thanREDRIVE_SECONDS(600 s), which added duplicate tasks to the same backlog.CONVERSATION_ERASURE_TASKS_QUEUE(prod valueconversation-erasure) is set on all 5 hosts that run the reconciler: backend-listen (manifest and chart), backend, backend-sync, backend-sync-backfill and backend-integration. Both kinds of erasure unit now dispatch there. Account wipes stay alone onaccount-deletion. The prod dispatch contract pins the literal./v1/conversations/deletion-batch-purges/runnow runs on a newerasure_executorwith 20 workers. Without this, wipes and units would still contend oncleanup's 4 threads inside each backend-sync instance.conversation-erasureand then inaccount-deletion. If that task is still waiting, delivering or retrying, it is left to run that same generation, and the obligation is re-checked afterREDRIVE_SECONDS. Only an authoritative NotFound in both queues allows a redrive. If the probe fails (permission or transport error), the reconciler redrives as before and records the fallback (blind_redrive, once per pass), so no obligation is stranded.deploy-backend-stackcreates or updatesconversation-erasurebefore any traffic shift. It uses the same list-based step asbatch-quarantine-recovery, and an inventory error fails the step. Staging getsstaging-conversation-erasureinqueue_mapandcreate_queues.sh.Rollout safety (no task lost)
account-deletion. Their tasks still reach the same handler, and the new reconciler probes both queues for them.conversation-erasuredoes not exist at enqueue time (NotFound), the unit goes toaccount-deletioninstead. This is recorded viarecord_fallback,conversation_erasure_queue -> account_deletion_queue. A rollback deploy therefore never strands work.begin_runandrun_token) is unchanged. A late duplicate is stillsupersededand the lease still prevents overlap.account-deletionare left alone. They drain there, and new passes stop adding duplicates on top of them.Queue sizing
--max-concurrent-dispatches=20 --max-dispatches-per-second=5 --max-attempts=5 --min-backoff=5s --max-backoff=300serasurepool means a delivered task never waits for a thread against its 1500 s dispatch deadline.Infra step
The deploy creates the queue. The new step
Configure production conversation-erasure Cloud Tasks queueruns on the next prod backend deploy, before traffic moves. Nothing manual is needed. The equivalent command, for reference only:No IAM change is needed. Read-only on 2026-11-14:
backend-runtime@andbackend-listen-runtime@already hold project-levelroles/cloudtasks.enqueuerandroles/cloudtasks.viewer(the viewer role covers thetasks.getprobe).omi-ci-deployer-prod@holdsroles/cloudtasks.queueAdmin. Neither queue has queue-level IAM bindings. Staging: runbackend/deploy/staging/create_queues.sh --applyon the dev-operator tier.Product invariants affected
backend/main.py(a log condition only). Memory promotion is not touched.How it was verified
UNVERIFIED in production. Nothing here is deployed, and I created and changed no live queue. Prod reads only:
gcloud tasks queues describe/list/get-iam-policy,gcloud projects get-iam-policy,gcloud run services describe backend-sync.Run locally in a Python 3.11.15 worktree venv:
pytest tests/unit/test_conversation_erasure_queue_deploy.py test_conversation_delete_gate_wait.py test_conversation_delete_accept.py test_conversation_batch_purge_{resumable,authority,deadlines}.py test_executors.py: 146+ passed.test_backend_runtime_env_validator(271),test_render_backend_runtime_env(93),test_staging_overlay(21),test_cross_service_deploy_contract(30, 3 skipped),test_sync_cloud_tasks(209),test_cloud_run_live_caps(50),test_batch_pipeline_recovery_runtime_contract(8),tests/routers/test_users.py(327): all passed.tests/integration/test_conversation_batch_purge_emulator.py14 passed.backend/scripts/pre-deploy-check.sh: 578 passed.scan_async_blockers,check_module_stub_pollution,scan_import_time_side_effects,verify_pusher_cohost_env_diff,check_agents_md_lean: clean.Tests
test_generation_still_in_its_queue_is_not_redriven: a backlog older than the redrive delay leaves generation 1 queued, and the waiting task still purges it. This would have caught the duplicate backlog.test_generation_gone_from_its_queue_is_redriven,test_unanswered_probe_redrives_rather_than_strand,test_one_unanswered_probe_per_pass,test_running_generation_is_skipped_without_a_probe,test_queued_hold_never_touches_a_newer_generation.test_units_ride_the_conversation_erasure_queue_apart_from_account_wipes,test_task_probe_looks_in_the_erasure_queue_then_the_shared_one,test_missing_erasure_queue_keeps_units_on_the_shared_queue.test_task_handler_runs_on_its_own_pool_not_the_account_wipe_pool.test_conversation_erasure_queue_deploy.py: the deploy step runs before the traffic shift with the bounded flags and fails closed on inventory errors. Every prod dispatcher, the GKE chart and staging name the queue, and the prod contract rejects erasure units on the wipe queue.UI evidence
UI-Evidence: none -- backend and deploy only
Failure class (fixes)
Failure-Class: FC-backlog-release-shares-lane-with-fresh-work
The redrive half also matches
FC-queued-delivery-invalidated-by-redrive: queue delay past the retry interval made the dispatcher mint new generations for tasks that were still queued.🤖 Generated with Claude Code