Repository navigation
SCA-441: map account-gate delete contention to 409 - #12707
Merged
Merged
Conversation
There was a problem hiding this comment.
All reported issues were addressed across 10 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Concurrent single-memory deletes for one uid collided on the exclusive destructive-operation gate and escaped as 500. Return 409 + Retry-After instead, and send Windows bulk cleanup through DELETE /v3/memories/batch. Co-authored-by: Cursor <[email protected]>
…umps Conversation-router unit tests stub database/utils.other at load, so the gate-busy mapping must not import those modules at router import time. PINNED_CONVERSATION_DUMPS now includes the daily-summary stats model_dump sites already on main. Co-authored-by: Cursor <[email protected]>
Pinning the daily-summary dump sites puts this file in the changed set; its red-proof scans exceed 0.30s CPU under saturated pre-push fanout. Co-authored-by: Cursor <[email protected]>
Git-on-my-level
force-pushed
the
agent/memory-delete-gate
branch
from
September 4, 2026 04:11
7a845e1 to
1ed990a
Compare
…isection - Wire deleteAppIndexMemories to window.omi.memoriesBulkDelete so the shipped delete flow actually uses the batch route + 409 retry behavior instead of per-ID deletes (thread 1). - Drop baseURL from the renderer-supplied IPC args; the main process derives it from VITE_OMI_API_BASE like ipc/auth.ts / ipc/byok.ts, so a compromised renderer cannot redirect bearer-token requests (thread 2). - Bisect a 404 batch chunk instead of fanning the whole chunk out through the 60/hour single-delete limiter; only genuinely stale ids reach the single-delete route (thread 3). - Rewrite the cascade 409 static test as a structural regex tying the RuntimeError/name-check catch to account_gate_busy_http_exception(), matching the 503 sibling test, so mapping regressions fail the guard (thread 4). Verification: - desktop/windows: vitest run src/main/memoryCleanup/bulkDelete.test.ts (12 passed, incl. 2 new bisection tests); npm run typecheck (0 errors); full vitest suite 5562 passed, 1 pre-existing Modal.test.tsx failure (fails at HEAD too, unrelated pointerdown assertion). - backend: pytest test_delete_conversation_cascade_retraction_fence.py + test_account_gate_busy_http.py (6 passed), test_memories_batch_delete.py + test_legal_holds.py (31 passed). Co-authored-by: Cursor <[email protected]>
# Conflicts: # backend/tests/fast_unit_duration_allowlist.txt
Git-on-my-level
added a commit
that referenced
this pull request
Sep 4, 2026
…#12729) Two exact-set pins fail on main, so any PR whose test selection reaches them goes red for reasons unrelated to its diff. #12707 is failing on this today. Both share a cause: the change that broke each one did not touch a file that selects the test that pins it, so the selector never ran it on the PR that introduced it. 25a7d76 added two model_dump() calls in external_integrations.py. The trust-boundary scanner keys on the call, not the receiver's type, so both are reported as conversation serialization sites. Both dump a DailySummaryDayStatsPayload, so neither can carry client_processing; pinned with that reasoning beside the entries. 44d4888 deleted two onboarding views the task-intelligence manifest still lists as desktop_manual owner paths. Removing them uncovers a second failure the first was masking: ContextReminderCoordinator writes and updates action items and is registered nowhere. That one is a judgement. It is registered as desktop_manual / direct_command, not as a proactive writer. The directory says ProactiveAssistants, which is why the code was read: the create runs inside a user-invoked reminder flow on the user's own text, its failure strings ask the user to try again, and updateActionItem is reached from markDone, a button. Nothing fires on a timer or on observed context alone. Under INV-TASK-2 that is a direct command. If context reminders are meant to propose rather than write, the code is what should change, not this entry. Co-authored-by: Claude Opus 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.
What changed and why
Live
DELETE /v3/memories/{id}was 500-ing because two concurrent deletes for one account contend on the exclusivedestructive_operation_gate. The router only mappedValueError→ 404;DestructiveOperationInProgressescaped as 500. The Windows bulk cleaner made this worse withCONCURRENCY = 4single deletes (three of every four in-flight requests lose the gate, then retry 5xx).Smallest fix that closes it: keep the 6h exclusive gate (do not weaken account deletion / legal holds), map contention to 409 +
Retry-After: 2+detail: account_gate_busyon the single, batch, and cascade-conversation delete routes, and send Windows bulk cleanup throughDELETE /v3/memories/batchin chunks of ≤100 so one request holds the gate once.Closes SCA-441
Product invariants affected
HTTP mapping only: delete still goes through
MemoryService/ the existing exclusivedestructive_operation_gate. No new intake path, no extra tier, no bypass of canonical delete. Conversation cascade retract still uses the same memory-delete owner; this PR only mapsDestructiveOperationInProgressto 409 instead of 500.Line-Count-Exception: backend/routers/conversations.py | 2203 -> 2210 | Map DestructiveOperationInProgress on cascade retract to 409; extracting a new owner is out of scope.
How it was verified
Backend (worktree venv):
25 + 14 passed (legal_holds file 25; combined targeted run 14 including the new 409 tests). Concurrent gate test: one
destructive_operation_gate(uid)succeeds, the other raisesDestructiveOperationInProgress;external_write_fencestill blocks while the live gate is held.GATE_STALE_AFTER_SECONDSremains 6h.Windows:
11 passed.
./node_modules/.bin/tsc --noEmit -p tsconfig.node.json --composite falseexited 0.Did not serve the live FastAPI process against a real Firestore gate in this run (no prod/dev GCP writes). The router tests drive the production handlers with a service that raises the typed exception.
Tests
Red proof (unfixed tree: only
ValueErrorwas caught on delete):test_delete_memory_maps_gate_busy_to_409_not_500:pytest.raises(HTTPException)failed becauseDestructiveOperationInProgress: another destructive operation owns the account gateescaped uncaught.test_batch_delete_maps_gate_busy_to_409_not_500: same uncaught exception fromdelete_batch.classifyStatus(409)expected'retry', received'fail'.test_concurrent_single_deletes_one_succeeds_other_raises_typed_exceptionis the reproduction and stays: two concurrentdestructive_operation_gate(uid)contexts, one winner, typed exception on the loser.Green after: 409 +
Retry-After: 2+account_gate_busyon single and batch delete; conversation retract source-maps the same helper; Windows bulk path issuesDELETE /v3/memories/batch(100+1 for 101 ids) and retries 409 using the header.Failure class (fixes)
Failure-Class: none
First instance of this HTTP mapping. The gate itself is unchanged (still exclusive, still 6h stale). Existing
FC-destructive-gate-keyed-on-proxy-for-intentis a different contract (empty replacement set vs destroy).Part B (POST /v3/memories 503) — findings, not this PR
PR #12524 already resolves an identical-content resubmission after the account head has moved (
_existing_identical_add_rowcomparescontent.strip()only). WindowsPOST /v3/memoriesdoes not send an id; the server derives it fromuid+source_id("unknown"when omitted) + stripped content. Tags, category, andsourceare outside that identity, so a focus/insight dual-write with different text cannot share an id. Remaining 503s are likely (1) two in-flight identical POSTs racing before the winner's snapshot is readable, so_existing_identical_add_rowreturnsNoneandcreate_memorystill wraps every exception as 503, or (2) aninvalid_patchreason other thanadd patch new_memory_id already exists. A red-proof fix would be a bounded snapshot re-read on that specific reason, plus not mapping unrelated apply failures to 503. Not done here.Follow-ups not in this PR
deleteAllMemories; singledeleteMemoryis not fanned out. InsightTaskGroupis mark-read, not delete. No change.deleteMemoryServeris per-row; bulk usesDELETE /v3/memories. No fan-out. No change.DestructiveOperationInProgressescape as 500.AdvancedTab/deleteMemoriesPacedstill treat 409 as a hard fail (serial, so they do not self-collide; they can still lose to another in-flight gated op).DELETE /v3/memories(delete-all) is ungated in the router the same way.Do not merge; coordinator reviews.