Repository navigation
fix(backend): a batch purge that loses the account gate to a peer hands off instead of failing its task - #25393
Merged
Merged
Conversation
…ds off instead of failing its task A purge unit waits 30 s for the account's destructive gate. When a peer of the same kind (another of the account's purges, an accepted delete's erasure, a user delete) held it longer, run_job raised DestructiveOperationInProgress and the Cloud Tasks handler answered 500: 1,293 of 1,462 purge task failures on backend-sync since 2026-11-12. The run now records the existing busy outcome (redriven in 30 s), as run_erasure_job already does. The unit erased nothing because it never acquired the gate, and the scan position is already checkpointed. Legal holds, account wipes and other gate kinds still stop the run as before. The handler's failure line now names the obligation kind, generation, error type and sanitized message. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Problem
On Cloud Run
backend-sync,POST /v1/conversations/deletion-batch-purges/runhas 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 afterbackend-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,ValueErrorcommit 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 raisesDestructiveOperationInProgress.run_jobtreated 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 thebusyoutcome for erasures (run_erasure_job), but batch purges never got it.Fix
run_jobmaps a unit that lost the gate to a same-kind peer (_lost_gate_to_peer, the helperrun_erasure_jobalready uses) to the existingbusyoutcome. That means a 200, the lease released, and a redrive inBUSY_RETRY_SECONDS.busyis 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.held.settle()before each unit, and is still reported byevent=destructive_gate_remote_unresolved.sanitize(str(e)), so every 500 states its reason.run_jobBODY_DIGEST. It adds no query: its only stream is stillsegment_records, and the gate check is the existing point read.Blast radius (read-only)
DestructiveOperationInProgress.conversation_batch_purge_jobsandconversation_erasure_jobs, so they completed._Defaultsink exclusionapp-stdout-info-sample90. 2xx request logs are also kept at 10% (cost-audit-cloud-run-success-sample).conversation-erasure.conversation_batch_purge_consumer_ready), which is expected.Not in this PR
/v2/audio-merge-jobs/run500s on 11-15 (171 so far) have a different cause. All of them arestamped 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.MAX_ERASURES_PER_ACCOUNTwould cut how many gate waiters there are. With this fix those waiters hand off withbusyinstead 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_resumesreproduces the prod failure. Onmainit raisesDestructiveOperationInProgress: another destructive operation owns the account gate. With the fix it returnsbusy, 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_retrygains abusycase (200).test_task_handler_logs_why_a_run_failedchecks the new failure line and that it is sanitized.test_conversation_batch_purge_{resumable,deadlines,authority}.py,test_conversation_delete_gate_wait.py,test_conversation_delete_accept.py.test_firestore_query_shapes.pyalso passes.make preflightwas run.Product invariants affected
none
Failure class (fixes)
Failure-Class: FC-user-intent-queued-behind-account-exclusive-work
🤖 Generated with Claude Code