Repository navigation
fix(backend): sync-bridge donor retraction no longer claims the account destructive gate (503 on sync intake) - #15340
Conversation
…tructive gate PR #15193 ran donor retraction on the routine sync intake path through deletion machinery that takes the exclusive per-account lock. Concurrent GCS staging then 503'd as DestructiveOperationInProgress. Sync-bridge cleanup is bounded per-conversation derived-data retraction, so it no longer claims that lock; if the gate is already held, retraction defers onto the revision-fenced receipt and converges on a later append. Failure-Class: FC-destructive-gate-keyed-on-proxy-for-intent Co-authored-by: Cursor <[email protected]>
| ) -> ConversationSourceReplacementResult: | ||
| collections = MemoryCollections(uid=uid) | ||
| if writes: | ||
| if writes or not require_deletion_gate: |
There was a problem hiding this comment.
🔒 Agentic Security Review
Severity: MEDIUM
Sync-bridge donor retraction with claim_destructive_gate=False commits empty replacement through assert_no_destructive_operation_transaction, which re-reads only the exclusive wipe gate. Legal-hold coverage is a point preflight (assert_account_deletion_permitted) and is not revalidated in the same Firestore transaction that tombstones remaining canonical rows (and then action items/vectors). An already-active hold still defers; a hold placed after preflight can still lose donor-sourced derived data.
Impact: A legal hold placed in the window after preflight and before the replacement commit can fail to freeze irreversible per-conversation derived cleanup, even though user deletes still hold the exclusive gate.
Reviewed by Cursor Security Reviewer for commit ca77374. Configure here.


Summary
POST /v2/sync-local-filesstarted returning HTTP 503 after PR #15193 (prod SHA527d9b45093c58de335ecc8f6c5558204461b70c, 2026-09-21T03:17:42Z) because donor retraction on the routine sync intake path claimed the exclusive per-account destructive-operation gate. Concurrent GCS staging for the same account then raisedDestructiveOperationInProgress(event=sync_dispatch outcome=staging_failed). Measured: 0 failures in the hour before deploy, 31 in the hour after; interleaved 503/202 for the same user within seconds.Donor retraction is bounded per-conversation cleanup of derived data for a row the assignment transaction already tombstoned. It now passes
claim_destructive_gate=False: it still retracts memories, action items, and vectors, still fences against a live wipe viaassert_no_destructive_operation_transaction, and does not acquire or weakenlegal_holds. If the gate is already held,bridge.pydefers retraction (no cleanup receipt) and retries on the next append. Unexpected retraction errors still fail the job. Copy/checkpoint failures still retry.bridge.pynow emits boundedevent=sync_bridgelogs andomi_sync_bridge_retraction_total(outcome=attempted|deferred|converged|failed,reason=none|gate_busy|hold_active|authority_unavailable|other). Logs may carry uid/source_id; metric labels do not.Rollback of #15193 is not an option: it would reintroduce conversation fragmentation and orphan already-written data.
Failure-Class
Failure-Class: FC-destructive-gate-keyed-on-proxy-for-intent
FC-degraded-fallback-consumes-protected-budgetdoes not match: this is not a quota fallback dumping work onto a protected budget. The violated contract is that the exclusive destructive-operation gate must be keyed on whether the operation is account-scale destruction, not on the proxy of "this call entered deletion machinery." Sync-bridge donor retraction shared_delete_conversation_and_related_data/@_legal_hold_gated_deletionwith user deletes, so a hot intake path claimed a lock reserved for genuinely destructive work.Line-Count-Exception: backend/database/memory_apply_store.py | 3390 -> 3393 | Thread require_deletion_gate through the existing replacement transaction rather than split the owner during a production hotfix.
Line-Count-Exception: backend/utils/memory/canonical_memory_adapter.py | 4085 -> 4121 | Thread claim_destructive_gate through the existing retraction owner so sync-bridge cleanup can retract without taking the exclusive account lock.
Line-Count-Exception: backend/utils/memory/memory_service.py | 4312 -> 4324 | Forward claim_destructive_gate from the existing legal-hold-gated retraction wrapper; splitting MemoryService is out of scope for this hotfix.
Product invariants affected
No change to fail-closed canonical authority, privacy tombstones, or the exclusive gate itself. User-initiated deletes still claim the gate (default
claim_destructive_gate=True). Sync-bridge retraction still goes throughMemoryService.retract_conversation_memories.Test plan
test_intake_accepts_chunk_when_destructive_gate_is_held_and_retraction_converges_laterfails before the fix (DestructiveOperationInProgressatingest(2)) and passes after (chunk accepted,outcome=deferred, then later appendoutcome=convergedwith receipt).test_sync_bridge_retraction_does_not_claim_the_account_destructive_gatefails before (claim_destructive_gate is None) and passes after (False).BACKEND_UNIT_TEST_FILE_LISTsuite: lifecycle, capture continuity/pipeline, cross-job, live-stub, legal_holds, merge-skip, merge canonical delete, conversation replacement backoff.scripts/backend-python-format --writeon changed Python (unchanged).bash backend/scripts/typecheck.sh(0 errors).OMI_PR_BODY_FILE=... .githooks/pre-push origin </dev/nullXDG_CONFIG_HOME=/tmp/omi-grok503-firebase-config npm run test:listen-pusher-stack:emulatorXDG_CONFIG_HOME=/tmp/omi-grok503-firebase-config npm run test:sync-cloud-tasks-stack:emulator🤖 Generated with Claude Code