Skip to content

fix(backend): sync-bridge donor retraction no longer claims the account destructive gate (503 on sync intake) - #15340

Merged
Git-on-my-level merged 1 commit into
mainfrom
fix/sync-bridge-retraction-gate
Sep 21, 2026
Merged

Git-on-my-level merged 1 commit into
mainfrom
fix/sync-bridge-retraction-gate

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Sep 21, 2026 •

Copy link
Copy Markdown
Member

Summary

POST /v2/sync-local-files started returning HTTP 503 after PR #15193 (prod SHA 527d9b45093c58de335ecc8f6c5558204461b70c, 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 raised DestructiveOperationInProgress (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 via assert_no_destructive_operation_transaction, and does not acquire or weaken legal_holds. If the gate is already held, bridge.py defers retraction (no cleanup receipt) and retries on the next append. Unexpected retraction errors still fail the job. Copy/checkpoint failures still retry.

bridge.py now emits bounded event=sync_bridge logs and omi_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-budget does 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_deletion with 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

  • INV-MEM-1
  • INV-MEM-3
  • INV-MEM-4

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 through MemoryService.retract_conversation_memories.

Test plan

  • Regression test_intake_accepts_chunk_when_destructive_gate_is_held_and_retraction_converges_later fails before the fix (DestructiveOperationInProgress at ingest(2)) and passes after (chunk accepted, outcome=deferred, then later append outcome=converged with receipt).
  • test_sync_bridge_retraction_does_not_claim_the_account_destructive_gate fails before (claim_destructive_gate is None) and passes after (False).
  • BACKEND_UNIT_TEST_FILE_LIST suite: lifecycle, capture continuity/pipeline, cross-job, live-stub, legal_holds, merge-skip, merge canonical delete, conversation replacement backoff.
  • scripts/backend-python-format --write on changed Python (unchanged).
  • bash backend/scripts/typecheck.sh (0 errors).
  • OMI_PR_BODY_FILE=... .githooks/pre-push origin </dev/null
  • XDG_CONFIG_HOME=/tmp/omi-grok503-firebase-config npm run test:listen-pusher-stack:emulator
  • XDG_CONFIG_HOME=/tmp/omi-grok503-firebase-config npm run test:sync-cloud-tasks-stack:emulator

🤖 Generated with Claude Code

Review in cubic

…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:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 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.

Fix in Cursor Fix in Web

Reviewed by Cursor Security Reviewer for commit ca77374. Configure here.

@Git-on-my-level
Git-on-my-level merged commit 8169b2e into main Sep 21, 2026
68 of 71 checks passed
@Git-on-my-level
Git-on-my-level deleted the fix/sync-bridge-retraction-gate branch September 21, 2026 05:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant