Skip to content

fix(backend): account wipes stop failing on oversized Pinecone owner checks - #25298

Merged
kodjima33 merged 1 commit into
mainfrom
fix/account-wipe-500
Nov 14, 2026
Merged

kodjima33 merged 1 commit into
mainfrom
fix/account-wipe-500

Conversation

@kodjima33

@kodjima33 kodjima33 commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Account-deletion wipes on Cloud Run backend-sync (queue account-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)

  • 3 accounts stuck. All 3 non-grace wipes in flight right now are in this loop (failed 1, retrying 1, running 1). None can finish without this fix.
    • A: due 2026-11-09 00:11Z, failing since 00:12Z, 524 attempts. Cause 1 (memory vectors).
    • B: due 2026-11-09 18:47Z, 417 attempts. Cause 1 (conversation vectors) since 18:47Z. Cause 2 (ns3) since 2026-11-10 17:40Z.
    • C: grace wipe requested 2026-10-30, came due 2026-11-13, failing since 23:33Z, 56 attempts. Cause 1 (conversation + memory vectors).
  • 4 more accounts each hit one transient failure (GCS DELETE, Firestore contention, shutdown drain) and completed within 15 minutes. They are unrelated to this PR.
  • Other wipes keep completing: 22 Account Deletion Wipe Completed events in the last 3 days. Totals: 1,200 completed, 70 in grace (pending_deletion), 6 cancelled.
  • Wipe 500s per day: 11-09 77, 11-10 156, 11-11 168, 11-12 129, 11-13 137, 11-14 125 (through 13:00Z). The first 500 of this wave was at 2026-11-09 01:26Z. There were none from 11-01 to 11-08. The handler also logged 116 final attempt failed, and each one was re-enqueued by the reconciler.
  • A separate 500 wave ran 2026-10-20 to 10-28. It predates the introducing PR and stopped by itself.

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=…) to owner_index(…).delete(…).

  1. 413 on the ownership pre-check. OwnerIndex._mutate sends all ids of a delete chunk to a single index.fetch (vector_db chunks at 1,000 ids) before deleting them. Pinecone fetch is a GET with 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.
    • Logs: delete_account purge conversation vectors failed: (413).
    • Logs: memory_vectors only deleted 339/1339. The first 1,000-id chunk fails and the 339-id remainder succeeds.
  2. The purge's own lost delete blocks it forever. On 2026-11-10 17:40Z, a connection reset hit account B's delete_all_copies on ns3. The admitted full-owner delete was correctly marked uncertain. Its route now shows uncertain_count=1, and its operations journal holds exactly one uncertain op of kind delete. verify_empty_all_copies refuses while any op is uncertain, and only an operator can reconcile that marker. So every retry since then has failed with Account purge must wait for outstanding vector work.

Fix

  • OwnerIndex._mutate now 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_copies still refuses while there is pending work, an active copy, or any uncertain op other than delete. 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 transaction state.uncertain_mutations_are_deletes re-reads the route at the verified revision and checks the kinds in the operations journal (single-field equality, bounded by uncertain_count + 1). It runs only when uncertain_count > 0.
  • What still holds:
    • Migration and rollback still refuse on any uncertain op.
    • Uncertain upserts and updates still block the purge (new test).
    • Legal holds are untouched (acquire_destructive_operation still runs first).
    • Retries stay idempotent: the full-owner delete and the barrier repeat safely (the test repeats the purge).

Tests

  • test_account_wipe_sized_delete_fetches_owner_check_in_url_bounded_batches uses 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 with PineconeApiException: (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_lost replays account B: a connection reset on the purge delete, then a retry and a repeat. On origin/main it fails with PartitionBusy: 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.
  • The existing test_purge_attempts_known_erasures_despite_uncertainty_but_never_claims_done (uncertain op of unknown kind) still blocks.
  • I ran the local suites: test_pinecone_partition_index.py and test_pinecone_partition_state.py (147 passed), and test_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.py fails 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

…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 kodjima33 added the mux-proposal Mobile UX improver (MUX) proposal; waits for Nik's ship label Nov 14, 2026
@kodjima33
kodjima33 merged commit ef42ee8 into main Nov 14, 2026
74 of 75 checks passed
@kodjima33
kodjima33 deleted the fix/account-wipe-500 branch November 14, 2026 15:13
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. -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mux-proposal Mobile UX improver (MUX) proposal; waits for Nik's ship

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant