Repository navigation
fix(memory): disk space from finished reindexes is not returned until the Gateway restarts - #197230
Conversation
|
🦞👀 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 releases finished memory-reindex shadows’ retained SQLite descriptors before deleting their files. Example: Four agents build memory indexes in a running Linux Gateway.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR fixes a confirmed disk-space leak still present on main; the previous regression-test finding is resolved, with no new actionable findings and current-head CI still pending. Priority: P1 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherMemory-core builds replacement indexes in private SQLite shadow files, publishes their contents into the live agent database, then closes and removes the shadows. flowchart TD
A[Memory search or sync] --> B[Private shadow index]
B --> C[Close shadow workers]
C --> D[Publish into live database]
D --> E[Retire shadow admission descriptor]
E --> F[Remove shadow files]
Technical reviewBest possible solution: Retire each discarded shadow’s admission through the existing SQLite owner after all native consumers finish and before unlinking it. Do we have a high-confidence way to reproduce the issue? Current-main source explains the retained descriptor after unlinking, corroborated by the reporter’s official-release diagnosis and supplied Gateway comparisons; this read-only review ran no target code. Is this the best way to solve the issue? The patch is the smallest complete repair: it connects existing shadow disposal to existing admission retirement while preserving native-consumer closure, identity checks and asynchronous file removal. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 29c445e7843f. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +4, Tests -1, Docs +6. Total +9 across 4 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel 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 HistoryReviewed November 11, 2026, 9:28 AM ET / 14:28 UTC (Revision 3). |
|
Proof: built Gateway, Node 24.22.1, secretless Docker, bundled memory-core (FTS-only), four agents with about 6 MB of memory notes each. The first Controls on every run: searches return hits after each reindex; a memory file written afterwards is indexed into the live database and found; the live agent databases stay open; after a Gateway restart no shadow is held and searches still work. Focused tests pass on this head: manager-shadow-write, manager-db, sqlite-database-admission.retention; oxlint/oxfmt clean; |
|
Thanks @ericcaiwx-star for picking this up. We added the fix on top of your claim commit (the shadow's admission descriptor is retired right before its files are deleted) and a Gateway proof showing the deleted shadows are no longer held. When you're happy with it, please mark the PR ready for review. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Landed in a0aa49c. Thanks @ericcaiwx-star and @unitedyachtclubs. |
… the Gateway restarts (openclaw#197230) fix(memory): release reindex shadow database descriptors before deleting them The Gateway keeps SQLite write descriptors open for the life of the process (openclaw#167739), and memory-core deleted finished *.memory-reindex-<uuid> shadow databases without releasing theirs, so each reindex left a deleted file held open and its disk space was never returned until a restart. Memory-core now calls the existing retireSqliteDatabaseAdmissionForPath before deleting a shadow database whose writer is closed and whose publication has finished. openclaw/plugin-sdk/sqlite-runtime exports that existing helper as a compatible optional addition, documented in docs/plugins/sdk-runtime.md. Live database descriptors, the schema, retention and what is stored are unchanged. No text changes. Evidence: a built Gateway with memory-core and four agents with about 6 MB of notes each, counting deleted shadow files the Gateway still held open after each agent's first index, two runs each. On main the count rose 1, 2, 3, 4 and 97 MB stayed held; with this change it stayed 0 and nothing was held. Search after each index, indexing of a new memory file into the live database, the live databases staying open and a Gateway restart behave correctly on both. The shadow-write regression fails on main, at -1 net test lines. Details: openclaw#197230 (comment). Fixes openclaw#197216. Thanks @ericcaiwx-star for the PR and @unitedyachtclubs for the report. Co-authored-by: Ayaan Zaidi <[email protected]>
#197510 moved SQLite admission descriptor opens from fs.openSync to fs.open, so the shadow-descriptor regression from #197230 saw no shadow opens and failed on main. Record descriptors from the fs.open callback; retirement still closes them with closeSync. Co-authored-by: obviyus <[email protected]>
openclaw#197510 moved SQLite admission descriptor opens from fs.openSync to fs.open, so the shadow-descriptor regression from openclaw#197230 saw no shadow opens and failed on main. Record descriptors from the fs.open callback; retirement still closes them with closeSync. Co-authored-by: obviyus <[email protected]>
… the Gateway restarts (openclaw#197230) (cherry picked from commit a0aa49c) Co-authored-by: Ayaan Zaidi <[email protected]> Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit 51ef340e9495185ba6812ce292670a49ff7c2b39) (cherry picked from commit 772e56bd7c49e256106edbd3171fc1b484dabb40)
Fixes #197216
What Problem This Solves
Fixes: the Gateway keeps disk space from every finished memory reindex until it restarts. Each in-place reindex builds a
*.memory-reindex-<uuid>shadow database and deletes it when done, but the Gateway keeps a write-only descriptor on it, so the deleted file keeps its blocks. The reporter saw 154 of them (36.6 GB) after 53 hours.User Impact
User impact: disk space used by a finished reindex comes back as soon as the shadow is removed, without a Gateway restart.
Why This Change Was Made
SQLite admission keeps one identity descriptor per database file for the life of the process, because closing it could release SQLite's POSIX locks held by other connections (#167739). That is right for live databases, but a reindex shadow is deleted after its writer and publication are done, and nothing released its descriptor. The same change added
retireSqliteDatabaseAdmissionForPathfor exactly this case: explicit removal after the owner has joined its native consumers.removeMemoryDatabaseFiles, which only removes a closed reindex shadow (aftercloseShadow()and publication), now retires that path's admission before deleting the files.openclaw/plugin-sdk/sqlite-runtimeexports the existing helper so memory-core can call it; this is a compatible optional addition to an existing subpath (no new subpath, nothing removed or changed), documented indocs/plugins/sdk-runtime.md. Live databases, the schema, retention and what is stored are unchanged.Production lines: +4 (memory-core +3, SDK facade +1), docs +6. Tests: net -1.
Evidence
Built Gateway on Node 24.22.1 in secretless Docker, bundled memory-core (FTS-only), four agents with about 6 MB of memory notes each. The first
openclaw memory search --agent <id>builds each agent's index through the in-place shadow reindex. After each one, the proof counts deleted*.memory-reindex-*files still open in the Gateway's/proc/<pid>/fd:On main each held descriptor is write-only (
flags 02400001), as in the report. Controls, same on both builds: searches return hits after every reindex; a memory file written afterwards is indexed into the live database and found; the live agent databases stay open; after a Gateway restart no shadow is held and searches still work. Full capture: proof comment.Regression: the existing failed-transfer test in
manager-shadow-write.test.tsnow also checks that every shadow descriptor opened by its completed and failed rebuilds is closed. It fails on main (three shadow descriptors never closed) and passes here; duplicate assertions in the same file were folded to keep tests net -1. Focused tests pass on this head:extensions/memory-core/src/memory/manager-shadow-write.test.ts,extensions/memory-core/src/memory/manager-db.test.ts,src/infra/sqlite-database-admission.retention.test.ts. oxlint and oxfmt are clean on the changed files.Merge danger: two-way door; a revert restores the old behavior and nothing is migrated. Blast radius: memory-core reindex cleanup. If the retirement ran too early it could drop a descriptor another connection to the shadow still needs; it runs only after the shadow's writer is closed and its publication has finished.
Thanks @ericcaiwx-star for opening this PR and @unitedyachtclubs for the report and the
/procdiagnosis.