fix(memory): retry Lance writes on concurrency conflict — store path (INT-2817)#304
Merged
Merged
Conversation
…INT-2817) The lastAccessed fix (#303) removed the per-search write, but the store path (table.add) and predicated update/delete can still collide under 'openswarm review --max' — up to 16 reviewer subagents are SEPARATE processes sharing one on-disk Lance table, and Lance's built-in commit-retry budget (~2 attempts/30s) is too small for that fan-out. An in-process mutex can't help across processes, so wrap every memory write in withMemoryWriteRetry: retry on optimistic-concurrency conflicts with exponential backoff + full jitter (max 8 attempts) so racing writers desynchronize and re-commit against the latest version. Applied to all 5 write sites (add x2, delete x2, update x1). Non- retryable errors rethrow immediately; matcher kept tight to real conflict signals.
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.
Follow-up to #303. That PR removed the per-search
lastAccessedwrite; this hardens the remaining store path the residual note called out.Problem
Under
openswarm review --max, up to 16 reviewer subagents run as separate processes sharing one on-disk Lance table.table.add(and predicatedupdate/delete) commit optimistically, and Lance's built-in retry budget (~2 attempts / 30s) is too small for that fan-out →Too many concurrent writers. An in-process mutex can't serialize across processes.Fix
withMemoryWriteRetry(op, label)— retry on optimistic-concurrency conflicts with exponential backoff + full jitter (max 8 attempts) so racing writers desynchronize and re-commit against the latest table version. Appends and predicated update/delete are safe to re-run (Lance re-commits against latest each attempt, so no double-apply). Non-retryable errors rethrow immediately; the matcher is kept tight to genuine conflict signals (concurrent writers/commit conflict/version conflict/retry_timeout).Applied to all 5 memory write sites:
memoryCore.ts:saveMemoryadd,saveCognitiveMemoryadd,deleteMemoriesByDerivedFromdeletememoryOps.ts:updateMemoryRecordupdate,deleteMemoryIdsdeleteVerification
npx tsc --noEmit— cleansrc/memory/— 36 pass, incl. newmemoryWriteRetry.test.ts(success / retry-then-succeed / non-retryable rethrow / give-up-after-cap, via fake timers)openswarm review— APPROVE (suggested tightening the retryable matcher → applied;too manydropped as redundant/over-broad)Deferred
Reviewer suggested a cross-process concurrent-write stress harness — genuinely useful but heavier/flakier than this fix warrants; left as a future item.
🤖 Generated with Claude Code