Repository navigation
fix(backend): account wipes stop failing on oversized Pinecone owner checks - #25298
Merged
Merged
Conversation
…checks Account-deletion wipes on backend-sync looped on HTTP 500 for three accounts: - OwnerIndex._mutate pre-fetched all ids of a 1,000-id delete chunk in one Pinecone fetch. Fetch is a GET with every id in the query string; 1,000 production ids (~69 KB) is rejected with 413, so conversation and memory vector purges could never finish for accounts with >~800 rows. Batch the ownership check by URL byte budget. - verify_empty_all_copies refused while any mutation on the route was uncertain, including the purge's own filtered delete whose ack was lost to a connection reset. That marker never clears without an operator, so the wipe retried forever. A late delete cannot resurrect data; only uncertain non-delete work (and pending work or copying) still blocks completion. Migration still refuses on any uncertain operation. 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.
Summary
Account-deletion wipes on Cloud Run
backend-sync(queueaccount-deletion) have returned HTTP 500 since 2026-11-09. Three accounts are stuck in a permanent retry loop. Firebase Auth is already removed for them, but their conversations, memories, vectors and storage are still there 1 to 5 days after the wipe came due.This PR fixes the two causes, both in the Pinecone owner adapter.
Blast radius (prod, read-only: Cloud Logging + Firestore
account_deletions)failed1,retrying1,running1). None can finish without this fix.Account Deletion Wipe Completedevents in the last 3 days. Totals: 1,200 completed, 70 in grace (pending_deletion), 6 cancelled.final attempt failed, and each one was re-enqueued by the reconciler.Root cause
Both causes came in with 0c3047b, "perf: route Pinecone searches through verified owner partitions" (#24315, author Nik Shevchenko, merged 2026-11-01). That commit moved every account-wipe vector delete from
index.delete(ids=…)toowner_index(…).delete(…).OwnerIndex._mutatesends all ids of a delete chunk to a singleindex.fetch(vector_dbchunks at 1,000 ids) before deleting them. Pineconefetchis aGETwith every id in the query string. I probed the prod index read-only with synthetic, non-existent ids of production length: 800 ids returned OK and 1,000 ids returned HTTP 413. So any account with more than about 800 conversations or memories can never finish purging.delete_account purge conversation vectors failed: (413).memory_vectors only deleted 339/1339. The first 1,000-id chunk fails and the 339-id remainder succeeds.delete_all_copieson ns3. The admitted full-owner delete was correctly markeduncertain. Its route now showsuncertain_count=1, and its operations journal holds exactly oneuncertainop of kinddelete.verify_empty_all_copiesrefuses while any op is uncertain, and only an operator can reconcile that marker. So every retry since then has failed withAccount purge must wait for outstanding vector work.Fix
OwnerIndex._mutatenow runs the owner check in URL-bounded batches (_fetch_batches, 16 KB query budget, about 228 ids per fetch). The check and the delete behave exactly as before. Only the provider request size changes.verify_empty_all_copiesstill refuses while there is pending work, an active copy, or any uncertain op other thandelete. A late delete cannot bring data back. The proof of emptiness is unchanged: an LSN-fenced query of both copies must return no matches. The new read-only transactionstate.uncertain_mutations_are_deletesre-reads the route at the verified revision and checks the kinds in the operations journal (single-field equality, bounded byuncertain_count + 1). It runs only whenuncertain_count > 0.acquire_destructive_operationstill runs first).Tests
test_account_wipe_sized_delete_fetches_owner_check_in_url_bounded_batchesuses a fake index that returns 413 when the query string is over 60 KB, then deletes 1,000 production-length ids. On origin/main it fails withPineconeApiException: (413). With the fix it passes, all fetch batches stay inside the budget, and every id is checked in both copies.test_account_purge_completes_after_its_own_delete_outcome_was_lostreplays account B: a connection reset on the purge delete, then a retry and a repeat. On origin/main it fails withPartitionBusy: Account purge must wait for outstanding vector work. With the fix it passes, and migration is still blocked.test_account_purge_still_waits_for_an_uncertain_write[upsert|update]passes before and after. It guards the remaining fence.test_purge_attempts_known_erasures_despite_uncertainty_but_never_claims_done(uncertain op ofunknownkind) still blocks.test_pinecone_partition_index.pyandtest_pinecone_partition_state.py(147 passed), andtest_firestore_query_shapes.py(583 passed). I also ran each selected unit file that touches vectors or account deletion (252 files: 251 passed.test_empty_capture_recovery.pyfails locally only because native libopus is missing on this machine, which has nothing to do with this change).Not run: a live wipe. Prod is read-only for this change, and a dev account with more than 1,000 vectors was not available. Once this is deployed, the three stuck accounts should complete on their next reconciler retry. Account B's ns3 uncertain op stays in the journal for operator reconciliation, and nothing reads it again after the wipe.
Product invariants affected
none
Failure class (fixes)
Failure-Class: new
🤖 Generated with Claude Code