Repository navigation
Conversation
A standalone `openclaw memory search` starts a background index refresh when memory files change, prints the results, and closes its manager. The close did not wait for that refresh, and the refresh writes through the closing manager's connection, so it failed with "Memory database owner closed or changed before write admission" and the edit never became searchable. Transient CLI managers now drain search-time maintenance before closing, like persistent managers. Results are still printed first. Fixes openclaw#177685
|
🦞👀 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: needs maintainer review before merge. What this changesThis PR drains search-triggered indexing before standalone CLI exit while delivering Gateway-routed results before cleanup finishes. Example: Append “The boat is named heron.” to indexed MEMORY.md, then run openclaw memory search heron --json twice.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it fixes a current memory-refresh lifecycle bug, resolves the earlier findings, and has sufficient runtime proof; exact-head CI remains pending. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherMemory Core searches a published SQLite index and starts maintenance when files change; CLI and Gateway lifecycle owners retain the resources needed to publish that maintenance. flowchart TD
A[Edited memory files] --> B[Memory Core search]
C[Standalone CLI or Gateway RPC] --> B
B --> D[Published index results]
B --> E[Tracked index maintenance]
D --> F[Validated result delivery]
E --> G[Drain before resource cleanup]
Technical reviewBest possible solution: Retain the existing maintenance and read-scope owners, drain standalone refreshes before resource release, and deliver authorized Gateway results before cleanup. Do we have a high-confidence way to reproduce the issue? Current-main source exposes the teardown failure path, and supplied published-release and main-baseline CLI runs demonstrate lost refreshes; this read-only review ran no target code. Is this the best way to solve the issue? This is the smallest complete repair using existing owners: drain tracked work before closing its connection and preserve prompt Gateway delivery through the established acceptance callback. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 853e92c5110d. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +12, Tests +58, Docs +4. Total +74 across 6 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes: No label changes. Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (2 earlier review cycles)Reviewed October 23, 2026, 12:50 AM ET / 04:50 UTC (Revision 3). |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…enclaw#180624) * fix(memory): keep CLI search refreshes from failing at exit A standalone `openclaw memory search` starts a background index refresh when memory files change, prints the results, and closes its manager. The close did not wait for that refresh, and the refresh writes through the closing manager's connection, so it failed with "Memory database owner closed or changed before write admission" and the edit never became searchable. Transient CLI managers now drain search-time maintenance before closing, like persistent managers. Results are still printed first. Fixes openclaw#177685 * fix(memory): deliver routed search results before maintenance drains * test(memory): use default deferred result type * test(memory): mark disposable idle spy as intentionally unused * test(memory): configure the disposable idle spy explicitly * test(cli): revoke search authority before result acceptance --------- Co-authored-by: Peter Steinberger <[email protected]>
|
Confirmed the same failure on the published npm Reproduction: stop the separately managed Gateway so there is only one indexing owner; edit a test-owned memory Markdown source after a successful index; run a standalone The search returned valid matches and exit status 0, but stderr reported The installed release and exact release-tag source still contain GitHub comparison shows this merge and the release commit diverge, so this is evidence of a release/backport gap, not proof that this merged fix was included and then reverted. Please consider the complete change for the maintained release branch / next published fix release if applicable. |
Closes #177685
What Problem This Solves
Fixes: after a memory file is edited,
openclaw memory searchrun from the CLI never makes the edit searchable because the index refresh it starts fails when the command exits.User Impact
A standalone
openclaw memory searchnow finishes the index refresh it starts before the process exits, so the next search finds the edited text. The first search after an edit still answers from the existing index, as before. When the refresh has to compute embeddings, the command stays open until they finish, which is the same workopenclaw memory indexdoes.Why This Change Was Made
A search that finds changed memory files answers from the published index and starts a refresh in the background. That refresh runs on a maintenance manager that writes through the CLI manager's database connection. Before this change, when the CLI manager closed, it skipped waiting for search-time refreshes, so it released that connection while the refresh was still running. On
mainthe refresh fails withMemory database owner closed or changed before write admission; on 2026.10.5 it fails withAgent database resources are closing. In both cases the edit is never indexed.The fix removes the CLI exemption from the manager's idle wait. Every manager, including the short-lived CLI one, now waits for the search-time work it started before it closes. The CLI prints results before it closes the manager, so output is not delayed.
The Gateway's
memory.searchRPC uses the same short-lived manager and closes it after responding, so it also waits now, after the response is sent. I did not run that path live.The existing test
keeps transient CLI search off the serving manager write path(renamed topublishes transient CLI search maintenance before close, off the serving write path) asserted the old behavior: close finished while the paused refresh was still running. It now checks that close waits for the refresh and that the next CLI search finds the edited file. Onmainit fails at the first of those checks.Related draft #139230 renames the set of tracked background syncs and keeps the CLI exemption, so both PRs edit the same line in
awaitManagerIdle.Evidence
Setup: isolated
HOME,OPENCLAW_STATE_DIR, andOPENCLAW_CONFIG_PATH;agents.defaults.workspacepoints at a scratch workspace;memory.search.provider: "none"(keyword search, no network).MEMORY.mdstarts with a# Memoryheading and one line,The garden gate code is kestrel.Each run used a fresh state directory and ran the same script: index, append a line toMEMORY.md, then search twice for the new word.Published
[email protected](npm):mainat 4f6666a (built withOPENCLAW_FORCE_BUILD=1):This branch at 8184f5c (built with
OPENCLAW_FORCE_BUILD=1; memory-core has no changes between 4f6666a and the new base 936599f):Tests (run on the same change before the rebase onto 936599f):
manager-search-orchestration.test.ts -t "transient CLI search": passes on this branch; fails onmain(expected "vi.fn()" to not be called at all, meaning close finished while the refresh was paused).src/gateway/server-methods/memory-search.test.ts): 280 of 281 pass. The failure,manager-search-knn-subprocess.test.ts > queries the real source child across WAL writer visibility and source filters, also fails onmainon this machine (KNN child loaded unrelated runtime: kysely).pnpm tsgo:core,oxlinton the changed files, andgit diff --checkpass.node scripts/check-changed.mjs --base origin/main --head HEAD: 29 of 31 gates pass, includingtypecheck extensions,typecheck extension tests, andlint extension changed files. The two failures name only files this PR does not touch: the max-lines suppression ratchet flags threeui/src/pagesfiles, and the dead export scan lists 160 unused exports in other files.Maintainer follow-up
Retains @Sedrak-Hovhannisyan's standalone refresh-drain fix and preserves prompt results for Gateway-routed CLI searches. The existing channel-read lifecycle now accepts the owner-validated search result before settling manager cleanup; the handler still awaits cleanup, including rejected acquisitions. Cleanup errors are logged without replacing an accepted result. Maintainer decision: standalone searches keep draining before exit; Gateway calls deliver ready results before that drain. No new maintenance owner, setting, dependency, or SDK contract.
The CLI drain regression now synchronizes at the actual idle boundary instead of sleeping. Gateway coverage gates cleanup, verifies early/exactly-once response delivery and awaited settlement, and covers authority revocation during acquisition. Both regressions fail on the original behavior and pass with the repair. The CLI docs explain result delivery versus process exit.
Validation on macOS with Node 26.12.1 and real Ollama
nomic-embed-text(main baseline16920345c878):MEMORY.mdThe Gateway trace explicitly matches all three CLI calls to
memory.search.owner. Relative ordering: request 94.102s → RPC response 94.195s → CLI JSON 94.199s → edited-document gate 94.322s → release 94.325s → real embedding HTTP 200 at 94.354s → committed edit observed 104.177s → next search finds edit. The gate was released by observing the response, not an elapsed sleep. CLI wall times include startup (7.505s / 15.135s for the two Gateway searches).All 48 original focused tests passed (22 Gateway, 8 channel-read scope, 18 memory orchestration; 649.68s total including artifact preparation). Runtime build, production/test types, formatting, and scoped lint passed. The six other requested ratchets passed again after the CI follow-up; max-lines reproduces the same three unrelated UI suppression failures on the exact contributor base. Whole-PR delta: production +31/-19 (net +12), tests +75/-17 (net +58), docs +4. The small production growth connects the existing acceptance and cleanup owners; the public owner wrapper remains intact for its documented callers.
Limitations: macOS-only live proof. Commands used the supported built launcher
pnpm exec node ./openclaw.mjsbecause the source wrapper completed indexing but stranded its launcher during teardown. The successful runtime build and offline proof were at54a8a93450e; later commits only adjust tests, with identical production files. The Gateway retry records69b4cdad633; its production files also match the final head. The contributor's reported source-child KNN/Kysely isolation failure predates this change (#172681); compiled-worker base control passes, while the bounded source-mode attempt did not reach assertions. It is separate from this repair.CI follow-up: the existing CLI ownership test revoked the owner while cleanup was blocked, after production had already accepted and sent the response. Its synthetic transport waits for handler teardown, hiding that timing. The test now blocks the search itself before revocation and retains the same rejection, no-output, and no-local-fallback assertions. The old gate reproduced the CI failure locally (446.37s including preparation); all 9 ownership tests pass with the corrected gate (138.05s total). Scoped types, lint, formatting, and affected ratchets pass. Production is unchanged.
Final-head (
3efc0ef7e9f) isolated Codex review: scoped-clean, with no actionable P0–P2 findings.