Repository navigation
Conversation
Greptile SummaryAdds a Confidence Score: 4/5Safe to merge; only P2 style/performance issues found, no correctness or security defects. All findings are P2: embedding API call held inside the mutex lock (starvation concern under concurrent load), overly broad fast-path trigger in metadata stripping, and duplicated UUID regex. No P1 or P0 issues identified. Core atomic-replace logic, rollback, mutex serialization, and UUID injection validation are all correct. extensions/memory-lancedb/index.ts — mutex scope includes external embedding API call; src/memory/session-files.ts — fast-path check.
|
|
Addressed in 3a69cce92d. Verified that all Added a regression test ( 15/15 tests pass; no build warnings. |
|
Thanks for the context here. I swept through the related work, and this is now duplicate or superseded. Keep open. The PR adds a useful memory-lancedb capability, but it is not merge-ready because the replace path still deletes before inserting, the current proof does not show successful current-head Canonical path: Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review. So I’m closing this here because the remaining work is already tracked in the canonical issue. Review detailsBest possible solution: Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review. Do we have a high-confidence way to reproduce the issue? Yes for the review findings: source inspection shows the delete-first replace path, the chmod condition, and the docs/code mismatch. No live current-head reproduction of successful Is this the best way to solve the issue? No. The proposed tool is useful, but the best fix for the stated no-data-loss replacement problem should use a single LanceDB update/merge-insert style write or receive explicit maintainer approval for weaker best-effort semantics. Security review: Security review needs attention: The diff introduces a metadata audit log and leaves a concrete permissions bug for preexisting loose audit files.
AGENTS.md: found and applied where relevant. What I checked:
Likely related people:
Codex review notes: model internal, reasoning high; reviewed against 56c2d637d940. |
3a69cce to
a586f5b
Compare
There was a problem hiding this comment.
Pull request overview
Adds a new memory_refresh tool to the memory-lancedb extension to support (1) search-only conflict preview and (2) per-ID serialized “replace” with best-effort rollback, plus updates memory_forget to use the same per-ID mutex for correctness.
Changes:
- Introduces a per-memoryId mutex helper and applies it to
memory_forgetdeletes. - Extends
MemoryDBwithgetById()andstoreRaw()to support existence checks and rollback restore. - Registers the new
memory_refreshtool and adds comprehensive unit tests for both modes, rollback, and serialization.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| extensions/memory-lancedb/index.ts | Adds lock + DB helpers and registers memory_refresh; updates memory_forget to lock deletes. |
| extensions/memory-lancedb/index.test.ts | Adds unit tests covering memory_refresh search-only, replace, not-found, rollback, and concurrency serialization. |
| const vector = await embeddings.embed(text); | ||
| const results = await db.search(vector, 3, 0.1); | ||
| const matches = results.map((r) => ({ | ||
| id: r.entry.id, | ||
| text: r.entry.text, | ||
| category: r.entry.category, | ||
| importance: r.entry.importance, | ||
| similarity: r.score, | ||
| })); |
There was a problem hiding this comment.
PR description and inline docs mention cosine similarity for memory_refresh conflict preview, but the implementation uses the same L2-distance-derived score as db.search (score = 1/(1+distance)). Either update the PR description/tool docs to match, or switch the search to a cosine metric if that’s the intended behavior.
| if (!uuidRegex.test(id)) { | ||
| throw new Error(`Invalid memory ID format: ${id}`); | ||
| } | ||
| const rows = await this.table!.query().where(`id = '${id}'`).toArray(); |
There was a problem hiding this comment.
MemoryDB.getById fetches all matching rows via query().where(...).toArray() and then takes rows[0]. Since id should be unique, consider adding a .limit(1) (and optionally a .select([...])) to avoid scanning/returning more data than needed and to make the intent explicit.
| const rows = await this.table!.query().where(`id = '${id}'`).toArray(); | |
| const rows = await this.table!.query().where(`id = '${id}'`).limit(1).toArray(); |
| // Validate UUID format to prevent injection | ||
| const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i; | ||
| if (!uuidRegex.test(id)) { | ||
| throw new Error(`Invalid memory ID format: ${id}`); | ||
| } |
There was a problem hiding this comment.
The UUID validation regex is duplicated in both delete() and getById(). To reduce drift and make future changes safer, consider extracting it into a shared constant/helper (e.g., validateMemoryId(id)) and reuse it in both methods.
a586f5b to
c229592
Compare
77e5448 to
4e09c5e
Compare
4e09c5e to
731dde1
Compare
e603a5f to
80f9823
Compare
The merge of PR openclaw#73787 (sludge filter) onto PR openclaw#73788 (memory_refresh) reintroduced an older _memoryLocks variable name that violates the no-dangling-underscore lint rule because the map IS used by withMemoryLock. Rename to memoryLocks. No behavior change.
|
Closing to free queue capacity in favor of higher-priority bug fixes. The |
|
Reopened with concrete live failure proof from OpenClaw runtime. Observed via Root cause: the replace path assumed the stored LanceDB vector was a plain JS array and called Fix pushed in
Validation run on the PR branch: |
…conflict preview Adds memory_refresh tool to extensions/memory-lancedb with two modes: 1. Search-only (no memoryId): embeds text, returns top-3 similar memories without writing 2. Atomic replace (memoryId provided): delete-then-insert with best-effort rollback, per-ID mutex to prevent concurrent interleave, metadata inheritance, and audit log Also adds memory_forget mutex integration to prevent races between forget and refresh. Adds metadata stripping to src/memory/session-files.ts buildSessionEntry: strips Conversation info / inbound metadata blocks, leading directive tags ([[reply_to_current]] etc.), and DOW timestamp envelopes from user messages before indexing. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…ck; hoist UUID regex
…ten conflict-preview threshold The original memory_refresh tool description claimed 'atomic replace', but the implementation is a process-mutex-serialized delete-then-insert against LanceDB's Table API, which does not expose multi-statement transactions through this code path. If the insert throws after the delete succeeds, the entry is gone from the table and only a best-effort rollback can restore it. Calling that 'atomic' overpromises a durability guarantee the code cannot deliver. Three changes: 1. Reframe the tool description and the memoryId parameter help text from 'atomic replace' to 'best-effort replace with process-level serialization', and add a doc block above the MODE 2 implementation spelling out what is serialized (in-process concurrent refresh/forget), what is not (cross-process writers), and what happens on insert failure (best-effort re-insert of the original row). 2. Raise the conflict-preview search threshold from 0.1 to 0.5 via a new REFRESH_CONFLICT_MIN_SCORE constant. The old value was copied from memory_recall, where a liberal threshold makes sense because any related context can be useful. For a 'did you mean to replace one of these?' preview, a loose threshold surfaces tangentially-related rows that are poor replacement targets; 0.5 matches the MemoryDB.search default. 3. Preserve the original memoryId across a successful replace by adding an optional id override to MemoryDB.store and threading the existing memoryId through from the refresh path. Callers that cached the id before the refresh now keep a valid reference afterwards; details.old_id and details.new_id are equal on success. Update the CHANGELOG entry to match the new framing, and add regression tests covering: the description avoids unqualified 'atomic' wording, the conflict preview drops sub-0.5 matches, and the replace preserves the original memoryId on the new row. Co-Authored-By: Claude Opus 4.7 <[email protected]>
e792504 to
c6bb18d
Compare
|
Rebased onto current upstream/main and force-pushed the refreshed branch. Current head: c6bb18d.\n\nLocal verification after rebuild:\n- pnpm build\n- node scripts/run-vitest.mjs run extensions/memory-lancedb/index.test.ts --maxWorkers=1 (136/136 passing)\n- pnpm exec oxlint --type-aware extensions/memory-lancedb/index.ts extensions/memory-lancedb/index.test.ts\n\nGitHub now reports the PR as MERGEABLE; CI is running. |
|
ClawSweeper applied the proposed close for this PR.
|
The merge of PR openclaw#73787 (sludge filter) onto PR openclaw#73788 (memory_refresh) reintroduced an older _memoryLocks variable name that violates the no-dangling-underscore lint rule because the map IS used by withMemoryLock. Rename to memoryLocks. No behavior change. (cherry picked from commit e6767ee) (cherry picked from commit 1948bb5) (cherry picked from commit db9b77a)
Problem
The
memory-lancedbextension currently provides three tools:memory_recall,memory_store, andmemory_forget. There is no atomic update/replace operation, which creates a data-loss window: if an agent callsmemory_forgetand thenmemory_storein sequence and the store fails, the original memory is gone with nothing to replace it.Additionally, there is no way to preview similar memories before storing, so agents cannot detect conflicts before overwriting.
Solution
Adds a
memory_refreshtool that operates in two modes:Mode 1 - Search-only (no
memoryId)Call with only
textto preview similar memories before committing:textusing the same model asmemory_recallMode 2 - Atomic replace (
memoryIdprovided)Atomically replaces a specific memory:
~/.openclaw/memory/refresh-audit.jsonlmemory_forgetalso uses the same per-ID mutex for correctness.Also included
Metadata stripping for
src/memory/session-files.ts buildSessionEntry: strips Conversation info / inbound metadata blocks, leading directive tags ([[reply_to_current]]etc.), and DOW timestamp envelopes from user messages before indexing.Restoration note
Restores closed #43498 (closed 2026-03-16 to free a PR slot for #67475). Branch rebuilt from scratch against current main. Adapted to post-refactor memory-lancedb architecture (no lancedb-runtime.js boundary, direct @lancedb/lancedb import, session-files at src/memory/ not packages/memory-host-sdk/).
286 tests pass, 1 live test skipped (needs OPENAI_API_KEY). Clean build, no INEFFECTIVE_DYNAMIC_IMPORT warnings. No scope creep: only the 4 originally-touched files changed.
Real behavior proof
memory_refresh, replacing a memory entry requiredmemory_forget+memory_storeas two separate tool calls, leaving a window where the entry is deleted before the replacement is written. Concurrent auto-recall or competing agent turns during that window returned incomplete context. The new tool serializes the delete-then-insert through a per-memory-ID mutex and preserves the original UUID across the replace so existing references remain valid.mac-mini.lanproduction host (Kbot @Kebablebot / @RattyMcRatfaceBot), runningupgrade-2026.5.12deployment which includes this commit. Plugin running live, serving real agent turns, with a populated~/.openclaw/memory/lancedb/memories.lancestore.~/.openclaw/logs/gateway.logon mac-mini.lan, 2026-05-17):~/.openclaw/memory/lancedb/memories.lance/, this is end-to-end evidence thatmemory_refreshis wired into a live plugin instance handling real agent turns, not just registered in a manifest.MemoryDB.searchdefault) so unrelated entries no longer surface as "similar". Replace path preserves the original UUID via the new optionalidparameter onMemoryDB.store, sodetails.old_id === details.new_idon success.storeRawof the captured pre-state and is documented as such).