Skip to content

fix(memory): disk space from finished reindexes is not returned until the Gateway restarts - #197230

Merged
obviyus merged 5 commits into
openclaw:mainfrom
ericcaiwx-star:codex/fix-197216-reindex-shadow-descriptors
Nov 11, 2026
Merged

obviyus merged 5 commits into
openclaw:mainfrom
ericcaiwx-star:codex/fix-197216-reindex-shadow-descriptors

Conversation

@ericcaiwx-star

@ericcaiwx-star ericcaiwx-star commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

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 retireSqliteDatabaseAdmissionForPath for exactly this case: explicit removal after the owner has joined its native consumers.

removeMemoryDatabaseFiles, which only removes a closed reindex shadow (after closeShadow() and publication), now retires that path's admission before deleting the files. openclaw/plugin-sdk/sqlite-runtime exports 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 in docs/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:

Build after 1st 2nd 3rd 4th reindex Bytes held
main, run 1 1 2 3 4 97 MB
main, run 2 1 2 3 4 97 MB
fix, run 1 0 0 0 0 0
fix, run 2 0 0 0 0 0

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.ts now 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 /proc diagnosis.

@clawsweeper

clawsweeper Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 11, 2026
@clawsweeper

clawsweeper Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR releases finished memory-reindex shadows’ retained SQLite descriptors before deleting their files.

Example: Four agents build memory indexes in a running Linux Gateway.

  • Before: Four deleted shadow databases retain about 97 MB until the Gateway restarts.
  • After: No deleted shadows remain open, and searches and subsequent indexing continue working.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused production-path proof, a minimal owner-based repair, and the committed regression resolve the previous blocker; broad CI remains pending.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The supplied Linux Docker Gateway trace exercises bundled memory-core through memory search, shows retained deleted shadows falling from four to zero, and verifies subsequent indexing and restart behavior; production code is unchanged since that proven head.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Finished memory reindexes consume hidden disk space until the Gateway restarts.
Reason: The bounded repair addresses a confirmed production leak, preserves existing database behavior, and has explicit collaborator support.

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
Reviewed head: 5d953222c9578cbc528bc105c7c21a688b960003

Before merge

None.

Findings

None.

Agent review details

How this fits together

Memory-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]
Loading

Technical review

Best 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

  • Process-lifetime SQLite identity descriptors keeps the original intent (perf(sqlite): reuse admission across workers and reopens #167739: Retained physical identity prevents inode reuse and avoids releasing sibling SQLite POSIX locks when worker descriptors close; local historical blob inspection could not establish the retirement helper’s exact introduction.)
  • Shadow disposal ordering keeps the original intent (55e261d: Keep cleanup asynchronous and remove a shadow only after native resources release and its identity matches.)
  • Accepted-transfer failure regression keeps the original intent (a1f9ced: Preserve the published index and prevent failed worker publication from replaying inline; the extended test retains those assertions and adds descriptor-release coverage.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +4, Tests -1, Docs +6. Total +9 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 4 0 +4
Tests 1 11 12 -1
Docs 1 6 0 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 21 12 +9

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: Repeated reindexes retain substantial disk space in a running Gateway, with an affected official release and a report of 36.6 GB retained.
  • merge-risk: 🚨 compatibility: The PR adds a public SQLite SDK export; it is additive, documents its closed-consumer precondition, and has collaborator-backed direction without removing an existing contract.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (2 earlier review cycles)
  • reviewed 2026-11-11T13:48:25.830Z sha a081e2c :: needs real behavior proof before merge. :: none
  • reviewed 2026-11-11T14:15:47.333Z sha 7540599 :: needs changes before merge. :: [P2] Commit a regression that detects retained shadow descriptors

Reviewed November 11, 2026, 9:28 AM ET / 14:28 UTC (Revision 3).

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation extensions: memory-core Extension: memory-core plugin: file-transfer labels Nov 11, 2026
@obviyus

obviyus commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator

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 openclaw memory search --agent <id> builds each index through the in-place shadow reindex; after each one the proof counts deleted *.memory-reindex-* files still open in Gateway /proc/<pid>/fd. main = 93e4800, fix = edbfec6f1734 (runs 1-2) and this head 7540599 (run 3).

main-1  a1=1 a2=2 a3=3 a4=4  | 97 MB held | after restart: 0 held
main-2  a1=1 a2=2 a3=3 a4=4  | 97 MB held | after restart: 0 held
cand-1  a1=0 a2=0 a3=0 a4=0  | 0 bytes held | after restart: 0 held
cand-2  a1=0 a2=0 a3=0 a4=0  | 0 bytes held | after restart: 0 held
pr-1    a1=0 a2=0 a3=0 a4=0  | 0 bytes held | after restart: 0 held

24330240 02400001 ~/state/agents/a1/agent/openclaw-agent.sqlite.memory-reindex-1a87f951-1f91-4310-a9b9-9c94464c4ea9 (deleted)

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; plugin-sdk:check-exports in sync.

@obviyus obviyus changed the title fix(memory): release discarded reindex shadow descriptors fix(memory): disk space from finished reindexes is not returned until the Gateway restarts Nov 11, 2026
@obviyus

obviyus commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator

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.

@obviyus

obviyus commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added the clawsweeper:intake:bug Preliminary submission classification; full source review pending. label Nov 11, 2026
@ericcaiwx-star
ericcaiwx-star marked this pull request as ready for review November 11, 2026 14:09
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 11, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Nov 11, 2026
@obviyus

obviyus commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 11, 2026
@obviyus
obviyus merged commit a0aa49c into openclaw:main Nov 11, 2026
136 of 137 checks passed
@obviyus

obviyus commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator

Landed in a0aa49c. Thanks @ericcaiwx-star and @unitedyachtclubs.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 12, 2026
… 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]>
obviyus added a commit that referenced this pull request Nov 15, 2026
#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]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 16, 2026
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]>
maplel pushed a commit to maplel/openclaw that referenced this pull request Nov 24, 2026
… 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation extensions: memory-core Extension: memory-core merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. plugin: file-transfer proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

memory-core: Gateway keeps a descriptor on every unlinked memory-reindex shadow DB — 36.6 GB of deleted-but-open files in 53 h (2026.11.1)

2 participants