Repository navigation
fix(memory): keep concurrent maintenance from stalling search - #139698
Conversation
Keep source invalidation incremental, reuse initialized maintenance schema, yield SQLite write admission, and retain permitted keyword hits at the existing search deadline. Preserve transaction, purge, provider, and full-rebuild recovery ownership. Related: #137056. Reported by @anyech; latency reports from @imEXSV and @hannesrudolph.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. Reviewed September 6, 2026, 1:17 AM ET / 05:17 UTC. ClawSweeper reviewWhat this changesMemory Core yields during SQLite write contention, retries changed files incrementally, and preserves completed memory-file keyword matches when semantic search reaches its deadline. Merge readiness⛔ Blocked before merge - 2 items remain This remains a useful repair for source-confirmed failures on current main. No blocking code defect was found; the SDK contract concern is addressed, while the declared stable-index upgrade validation remains outstanding. Priority: P1 Review scores
Verification
How this fits togetherMemory Core indexes notes and session transcripts in the agent’s SQLite database. Searches combine keyword and semantic retrieval while background maintenance updates the published index. flowchart TD
A[Changed notes and transcripts] --> B[Prepare index updates]
B --> C[Yield for SQLite write admission]
C --> D[Published memory index]
E[Memory search request] --> D
D --> F[Keyword and semantic retrieval]
F --> G[Complete results or permitted partial matches]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +191, Tests +459, Docs +29. Total +679 across 27 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain the cooperative admission and incremental recovery design, with stable-created-index proof establishing preserved results and successful maintenance after upgrade. Do we have a high-confidence way to reproduce the issue? Yes: current main contains synchronous file-write admission and corpus-wide retry escalation, and the captured Gateway evidence provides concrete contention and concurrent-edit scenarios. This review did not execute them. Is this the best way to solve the issue? Yes: repairing admission and dirty-state ownership preserves existing search policy, and the new SDK contract is documented; the remaining validation concerns stable-index upgrade behavior. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 53be9a6fe21c. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
|
Merged via squash.
|
* fix(memory): keep cleanup from blocking concurrent searches Consolidate source deletion under cooperative SQLite admission, preserve indexed hash snapshots across waits, and prune excess embeddings in bounded batches. Keep the existing retention policy and source scope. Related: #137056. Follow-up to #139698. Thanks to @anyech and @imEXSV for the reports and @hannesrudolph for stable-release evidence. * fix(memory): retry fingerprint refresh after source invalidation Preserve dirty session state when schema reconciliation wins the guarded metadata update. Retry through the existing revision-conflict owner so the next pass rebuilds the current transcript instead of publishing captured stale bytes. Shrink the assertion baseline to match the removed cache cast. Related: #137056.
…aw#139698) * fix(memory): keep concurrent maintenance from stalling search Keep source invalidation incremental, reuse initialized maintenance schema, yield SQLite write admission, and retain permitted keyword hits at the existing search deadline. Preserve transaction, purge, provider, and full-rebuild recovery ownership. Related: openclaw#137056. Reported by @anyech; latency reports from @imEXSV and @hannesrudolph. * style(memory): align maintenance repair with lint rules * docs(sdk): define cooperative SQLite preparation contract
…#139821) * fix(memory): keep cleanup from blocking concurrent searches Consolidate source deletion under cooperative SQLite admission, preserve indexed hash snapshots across waits, and prune excess embeddings in bounded batches. Keep the existing retention policy and source scope. Related: openclaw#137056. Follow-up to openclaw#139698. Thanks to @anyech and @imEXSV for the reports and @hannesrudolph for stable-release evidence. * fix(memory): retry fingerprint refresh after source invalidation Preserve dirty session state when schema reconciliation wins the guarded metadata update. Retry through the existing revision-conflict owner so the next pass rebuilds the current transcript instead of publishing captured stale bytes. Shrink the assertion baseline to match the removed cache cast. Related: openclaw#137056.
…aw#139698) * fix(memory): keep concurrent maintenance from stalling search Keep source invalidation incremental, reuse initialized maintenance schema, yield SQLite write admission, and retain permitted keyword hits at the existing search deadline. Preserve transaction, purge, provider, and full-rebuild recovery ownership. Related: openclaw#137056. Reported by @anyech; latency reports from @imEXSV and @hannesrudolph. * style(memory): align maintenance repair with lint rules * docs(sdk): define cooperative SQLite preparation contract (cherry picked from commit 4681f8d)
…#139821) * fix(memory): keep cleanup from blocking concurrent searches Consolidate source deletion under cooperative SQLite admission, preserve indexed hash snapshots across waits, and prune excess embeddings in bounded batches. Keep the existing retention policy and source scope. Related: openclaw#137056. Follow-up to openclaw#139698. Thanks to @anyech and @imEXSV for the reports and @hannesrudolph for stable-release evidence. * fix(memory): retry fingerprint refresh after source invalidation Preserve dirty session state when schema reconciliation wins the guarded metadata update. Retry through the existing revision-conflict owner so the next pass rebuilds the current transcript instead of publishing captured stale bytes. Shrink the assertion baseline to match the removed cache cast. Related: openclaw#137056. (cherry picked from commit 2a48854)
Related: #137056
What Problem This Solves
Fixes an issue where searches and Gateway requests stall while changed memory files and dirty-index maintenance contend for SQLite's writer lock. A file changing during indexing also made the next pass rebuild the entire corpus.
Why This Change Was Made
Search maintenance reuses its serving manager's initialized connection and effective schema. It joins an already-running sync instead of taking that sync's dirty generation. File writes prepare and validate their immutable snapshot before each admission attempt, yield between failed BEGIN attempts within the existing SQLite wait limit, and never replay an admitted transaction.
Changed or removed files retain incremental retry work while other sources finish; actual full-rebuild failures retain their full-retry state. The existing 15-second tool deadline now preserves completed memory-file keyword matches with a partial-result warning. Session hits are excluded from deadline recovery because they need current visibility checks. Provider transitions invalidate snapshots, caller cancellation remains cancellation, and expired one-shot responses do not wait through a second cleanup timeout.
The single-use maintenance wrapper and duplicate keyword finalization were removed. The public cooperative SQLite helper's repeatable preparation, undefined skip result, synchronous callback, and lifetime requirements are documented and tested. No configuration, environment variable, schema, dependency, or version changes are introduced.
User Impact
Published memory remains searchable while changed-file maintenance waits for a writer. One changed source no longer causes a full-corpus rebuild. Available memory-file keyword matches survive semantic deadlines and do not trigger a whole-corpus cooldown.
Thanks to @anyech for the original report, @imEXSV on X for the user-facing latency report, and @hannesrudolph for the stable-release evidence in #137056 (comment). Related drafts #139230 and #139013 address different scheduling and reader-acquisition policies.
The required cleanup follow-up landed in #139821 as 2a48854. It covers stale-row deletion, unchanged-session fingerprint conflicts, and bounded cache pruning through the same admission owner. Both merges are verified on main and #137056 is closed with proof.
Evidence
Remote proof used Blacksmith Testbox through the repository Crabbox wrapper: lease
tbx_01m1takkw5skz9pqswgqjsh8zz, run 34007941301. Linux x64, Node 24.19.0, isolated HOME/state and dynamically allocated ports. All content was synthetic; a deterministic local HTTP fixture supplied 3,072-dimensional embeddings. No external model or embedding API was called.The workload contained 3,200 notes plus MEMORY.md. Packaged 2026.9.2 produced a 4.31 GB agent database; main's newer chunker produced 3.35 GB from the same files. A current-main control independently reproduced the same two five-second waits as stable. The first was maintenance setup before query embedding; the second was watched-file write admission.
Independent contention windows were separated by 62 seconds and a successful recovery search. There was no added provider delay in these SQLite cases. The repaired runtime was built and run at
f9c3ec903a3bec2b019bfcb8ef840a46b66401ab, verified treec49b4503d335b9a4d41e2295ea7bc2cce892dbbc; the later commit only adds SDK documentation and a contract test, with identical executable source.The source-race transcript records stable escalating one edit to all 3,201 files; the repaired pass remains incremental:
A separate, explicitly controlled 17-second query-embedding fixture proved the real tool deadline contract while a watched file changed. Stable returned unavailable at 15,013 ms and immediately replayed its cooldown. The repaired runtime returned five permitted keyword hits at 15,020.71 ms with
partial:trueand an explicit semantic-deadline/no-session-results warning; an immediate retry succeeded in 799.33 ms. HTTP health latency stayed below 7.74 ms. This controlled provider case is distinct from the SQLite-contention reproduction.Validation: 126 focused tests passed; the complete Memory Core suite passed 1,471 tests with three skips. After the final lint cleanup, pinned oxfmt 0.65, owner lint, 49 focused tests, the build, and source-tree verification passed. Exact-head CI 34010688889 passed on the final executable revision. The final docs/test-only head
97d2859fa7d23ca02a713d565842b5be8f703730passed CI 34012902694 and all 16 SQLite transaction tests, including repeated preparation and undefined skip. Native branch autoreview is scoped-clean at P0/P1. ClawSweeper found no blocking code defect; both SDK and stable-index validation requests are addressed.The copied stable-index upgrade ran on the final head using lease
tbx_01m1thgcn29h9pf3eaz02c2dd1, run 34012961729. SQLite online backup left the original database SHA-256 unchanged. Schema remained 19; all 3,201 source identities and the path/source/hash digest were preserved. Normal indexing performed the expected chunking-version 3→4 rebuild in 107.03 seconds (28,791→22,401 chunks). Published search succeeded, and search under a competing writer took 879 ms with maximum HTTP health latency 24.33 ms. Both leases are stopped; the second also completed the landed cleanup follow-up proof in #139821.The first CI run exposed lint/formatter issues, which were fixed. An unrelated Doctor 256 MiB heap failure also occurred on main before this PR; the same main lane and the fresh PR run subsequently passed without changing that code. Local worktree tests were blocked by a shared Vitest dependency mismatch; actual regression, build, and live proof ran remotely.
git diff --numstatagainst the merge base: production +410/-219, net +191; tests/support +535/-76, net +459; docs +29/-0. The negative-production target is exceeded for the missing recovery paths: safe partial results require a bounded snapshot handoff and invalidation/visibility checks, and nonblocking write admission requires repeatable preparation with non-replayed synchronous callbacks. Existing duplicate maintenance/finalization paths were removed.Landed through native scripts/pr as 4681f8d, verified on main. Against the landed parent, production is +405/-218 (net +187), tests/support +535/-76 (net +459), and docs +29; independent main imports account for the difference from the reviewed-branch count. The separate follow-up removes another 43 production lines.