Repository navigation
fix(memory-core): keep memory search usable during dirty sync - #112214
roboclaw-bot merged 1 commit into
Conversation
8712260 to
02c7f72
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 02c7f72ac8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| @@ -732,7 +732,7 @@ export class MemoryIndexManager extends MemoryManagerEmbeddingOps implements Mem | |||
| } | |||
| const cleaned = preflight.normalizedQuery; | |||
| void this.warmSession(opts?.sessionKey); | |||
| await startAsyncSearchSync({ | |||
| startAsyncSearchSync({ | |||
There was a problem hiding this comment.
Avoid blocking one-shot search cleanup on detached sync
When memory_search runs with oneShotCliRun (local CLI/embedded one-shot paths), this detached search sync is still stored as this.syncing; the tool tracks CLI managers and closes them in finally, and MemoryIndexManager.close() waits for this.syncing. With a dirty existing index and a slow sync, the query can compute results immediately but the tool still waits in cleanup until sync finishes or the 15s cleanup deadline expires, so the one-shot user path still spends the request deadline on dirty sync instead of returning the stale-index results promptly.
Useful? React with 👍 / 👎.
| @@ -732,7 +732,7 @@ export class MemoryIndexManager extends MemoryManagerEmbeddingOps implements Mem | |||
| } | |||
| const cleaned = preflight.normalizedQuery; | |||
| void this.warmSession(opts?.sessionKey); | |||
| await startAsyncSearchSync({ | |||
| startAsyncSearchSync({ | |||
There was a problem hiding this comment.
Keep searches off sync's mutable database state
When a dirty search detaches sync and then continues on the same manager, the query can now overlap sync/reindex work that mutates manager state instead of reading the stable old index. In particular, runInPlaceReindex() temporarily assigns this.db to the shadow database while it awaits indexing, so a search that proceeds from here during that window can inspect an empty/partial temp index or other in-flight sync state, returning empty or inconsistent recall even though the existing published index was still usable.
Useful? React with 👍 / 👎.
|
Codex review: needs maintainer review before merge. Reviewed August 29, 2026, 10:26 PM ET / August 30, 2026, 02:26 UTC. ClawSweeper reviewWhat this changesThe PR lets Memory Core search the last published index while dirty-index maintenance runs separately, adds cross-process SQLite generation leases, and excludes those transient lease files from backups. Regression provenancePossible regression — probable (reproduction; reviewed change). No predecessor PR is attributed. Merge readinessThis PR remains necessary: current main still awaits dirty synchronization before searching. The exact head moves that work to a separate maintenance manager, protects published reads during atomic publication, and addresses the prior backup exclusion finding; no blocking introduced defect was established. Priority: P1 Review scores
Verification
How this fits togetherMemory Core indexes agent memory and session files into SQLite for tools and CLI search. The change separates serving reads from index refreshes so a valid published index remains searchable while maintenance creates the next generation. flowchart LR
Sources[Memory and session sources] --> Maintenance[Detached index maintenance]
Maintenance --> Publisher[Atomic index publication]
Publisher --> Index[Published SQLite index]
Query[Memory search request] --> Reader[Generation read lease]
Reader --> Index
Index --> Results[Search results]
Publisher --> BackupFilter[Transient lease backup filter]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +583, Tests +806, Other -1. Total +1388 across 29 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Copy recommended automerge instructionTechnical reviewBest possible solution: Merge the serving/maintenance separation only after exact-head CI confirms the lease, lifecycle, and backup boundaries; retain the transient lease-file backup exclusion. Do we have a high-confidence way to reproduce the issue? Yes: current main visibly awaits dirty synchronization at search entry, and the supplied exact-head built-CLI trace covers a held reindex lock, stale results, and later atomic publication. Is this the best way to solve the issue? Yes: separating maintenance from the serving manager, leasing published generations, and excluding lease state from backups is a coherent owner-boundary repair rather than a timeout workaround. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 1a221897f354. 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
HistoryReview history (23 earlier review cycles; latest 8 shown)
|
b5c900b to
df111d3
Compare
df111d3 to
62c7297
Compare
|
@clawsweeper re-review\n\nAddressed the exact-head findings by isolating dirty maintenance on a durable manager and adding a database-generation read/publication lease. Please review head |
|
@clawsweeper re-review\n\nCI exposed one missing production import in the exact-head repair; fixed at |
9678558 to
0e230d6
Compare
|
@clawsweeper re-review Addressed the P1 at exact head |
|
🦞👀 Command router queued. I will update this comment with the next step. |
0e230d6 to
0b12b10
Compare
|
@clawsweeper re-review CI exposed that the first generation hook widened the exported base-class API. Reworked it into an internal WeakMap coordinator at exact head |
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Serve the last published generation while detached maintenance refreshes dirty sources, preserving lifecycle, shutdown, and freshness invariants. Co-authored-by: VACInc <[email protected]> Worked on by: - @VACInc
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
Land-ready verification for exact head
Commands: Behavior proof: with the real reindex lock held, the built CLI returned the published Known proof gap: no separate native Windows/macOS smoke was run. Cross-process SQLite ordering, writer fairness, cancellation, teardown, fallback, publication, and backup lifecycle are covered by deterministic child-process/owner tests, the real Linux CLI proof, the full changed-surface gate, build, and exact-head CI. Squash attribution is guarded: the source commit retains Adrian as author and |
|
Merged via squash.
|
Fixes #112196.
What Problem This Solves
memory_searchcould block behind dirty-index synchronization even when a valid published generation was available. Independent review found connected lifecycle and coordination gaps: serving-manager writes, lost dirty fallback state, mixed cross-process generations, teardown waits after results were ready, uncancellable lease acquisition, and publisher starvation under sustained readers.Why This Change Was Made
Memory search should read one stable published generation while maintenance builds and atomically publishes the next one. Dirty work now belongs to a separate transient maintenance manager for persistent and CLI search paths. Incomplete maintenance returns its dirty generation to the serving owner.
A shared/exclusive SQLite coordination lease extends generation isolation across processes. Publisher admission uses SQLite's native PENDING-lock transition: an exclusive-locking-mode, schema-free transaction retains writer intent after its first reader collision, blocks later readers, then retains exclusive admission until publication releases it. AbortSignal removes local read waiters and interrupts cross-process polling immediately.
Transient CLI teardown waits for active serving operations but not for detached refresh owned by its separate maintenance manager. Persistent managers still drain detached maintenance before closing shared resources.
The generation-writer and generation-lock SQLite files are live coordination state, not durable memory. Backup creation and verification now classify those exact databases and their
-wal,-shm, and-journalsidecars as transient, alongside the existing reindex coordinator.User Impact
Search returns the last valid memory results while refresh is blocked or running, then moves to the new index only after atomic publication. CLI, Gateway, and concurrent-process searches no longer observe partial or mixed generations; publishers make progress even when their first admission collides with a reader; timed-out searches stop waiting immediately; failed fallback setup remains visibly dirty and retryable; and transient commands do not remain blocked after results are ready.
Backups no longer snapshot or restore volatile generation-lease state, while unrelated durable SQLite files remain included and verified.
Evidence
ce77bae087c53433c2c2e2dd00394080856a4c46.node scripts/check-changed.mjspassed all core, extension, test, and tooling lanes, including formatting, ratchets, doctor contracts, boundaries, dead exports, all typecheck graphs, lint, storage, sidecar, and import-cycle guards.pnpm buildpassed through runtime postbuild, plugin control-plane loads, Plugin SDK exports, and Control UI gates.OLD-CANARYwith a stale warning and exited while the lock was still held. After release, the next maintenance pass atomically publishedNEW-CANARY.user_versionheader field is rewritten only inside the lock transaction to obtain SQLite's native PENDING transition.main; the only changed-path overlap is assertion-baseline bookkeeping.git diff --checkpassed. The final commit retains the required attribution block.Worked on by: