Skip to content

fix(memory): expose storage usage and guide safe disk recovery - #137876

Merged
steipete merged 2 commits into
mainfrom
codex/memory-recovery-135347
Sep 4, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/memory-recovery-135347

Conversation

@steipete

@steipete steipete commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Operators investigating a large agent database could see indexed chunk payloads but not retained embedding-cache bytes, WAL size, or reusable pages. After memory reset, the file stays allocated, and the CLI sent operators straight back to rebuilding without explaining the supported disk-recovery step.

Closes #135347. Follows the bounded cache-publication fix in #135373 and safe reset in #135653. Thanks @AlexisBallo2 for the original report.

Why This Change Was Made

Keep one SQLite database per agent and preserve its existing transaction, schema, reset, and compaction owners. Explicit memory diagnostics now report main-file bytes, WAL bytes, reusable pages, and retained cache payload/entry totals, including when caching is disabled. Normal serving status does not collect these facts.

Reset output and recovery docs point to the existing offline doctor --session-sqlite compact --session-sqlite-agent <id> command. The documented disk-recovery order is verified backup, stopped writers, reset when needed, compaction, rebuild, and verification. The maintainer decision to retain the shared database is recorded at #135347 (comment).

No database layout, table, schema-version, retention, embedding representation, configuration, environment variable, or dependency changes.

User Impact

Operators can distinguish retained cache payload, WAL growth, and reusable allocation before choosing recovery. The displayed sizes have explicit scope and are not presented as additive components or a complete attribution of the original reported 35 GB.

Existing sessions, transcripts, origins, tombstones, and deletion/rebuild coordination remain with their current owner. Byte inspection is limited to explicit diagnostics and uses the existing query/runtime abstractions.

Evidence

  • Focused regression runs: 134 tests passed across CLI, status aggregation, database publication/reset, and reindex recovery; the complete index plus storage suites then passed all 72 tests. The latter includes retained cache with caching disabled and diagnostics remaining off the serving path.
  • Independent Codex review: no actionable P0–P2 findings on the final staged candidate. Local lint found an unbound Kysely val reference; the final correction calls eb.val(0), passes extension lint, and passed all 72 index/storage tests again.
  • Full Linux pnpm build: passed on Blacksmith Testbox tbx_01m1n6wajy307qjtdjyde2a49h (hydration run).
  • Real built CLI/Gateway proof on that Testbox: all 10 changed source-file SHA-256 digests matched the initial reviewed candidate (0782a52cb3d). An isolated synthetic agent used keyword-only search with no external provider requests. Status reported 1,024 retained cache entries (9,438,208 payload bytes) despite caching being disabled, plus 11,272,352 WAL bytes. Compaction refused a running Gateway. After stopping it, reset preserved all 43 non-index tables, including transcript rows, origins, and tombstones; compaction reduced the database from 11,771,904 to 675,840 bytes, reclaiming 11,096,064 bytes. Schema SQL and version 19 stayed unchanged. Reindex produced searchable memory and a 679,936-byte database. Both remote commands exited 0.
  • Probe sequence: memory status --json → memory index → seed synthetic canonical/cache/vector rows → memory status --json → start Gateway → refused doctor --session-sqlite compact → stop Gateway → memory reset --yes → doctor --session-sqlite compact → memory index → memory status --json → memory search.
  • Full local pnpm build: passed. The completed macOS build passed the same isolated real Gateway/CLI proof with identical reclaimed-byte, canonical-preservation, schema, and rebuilt-search results. An earlier local probe started before plugin packaging completed and correctly failed Gateway registry validation; the completed-build rerun passed. The corrected runtime build and final macOS live probe passed with the same reclaimed-byte, canonical-row, schema, and search results. The complete node scripts/check-changed.mjs --base c86d5b2d270eb2eb2a98cf5070f5efe19eb068c3 suite passed after the lint correction. Exact-head CI is complete. All other applicable checks passed or were skipped; the only failed checks are security-fast and its aggregate openclaw/ci-gate. The sole failing security step is the production dependency audit: npm’s bulk advisory endpoint timed out after three attempts, and independent local audit/minimal POST probes also timed out. No audit clearance was obtained. The maintainer explicitly waived this external npm-audit timeout for landing; no dependency, workflow, check result, or repository rule is changed.
  • Diff: production +65 net lines, tests +61, docs +37. Production growth adds explicit read-only storage diagnostics and recovery guidance; no duplicate reset, migration, or compaction path.
  • Dependency proof: real SQLite/vec0 fixture survived integrity checks and VACUUM without loading vec0 on the compaction connection. SQLite documents reusable pages and temporary compaction space at https://sqlite.org/lang_vacuum.html.

Known limits: the original corpus/configuration is unavailable, so this does not attribute the full reported 35 GB or recover already deleted sessions. Broader representation/corpus work remains #131085 and #114612. A separate diagnostic follow-up is to include WAL bytes in Doctor's older database-bloat warning heuristic; this change exposes them directly in memory status.

Review disposition

The ClawSweeper review treats the cache table as optional in the published agent database. That premise confuses the temporary memory-only rebuild schema with the canonical agent schema:

Both rank-up moves were considered. The proposed absent-table guard is declined because it would add a fallback for a shape that the canonical agent store does not support. The requested live cache-disabled scenario was run through the real built CLI on the final head: with caching disabled from the start, memory status --json succeeded before indexing without creating a database file; memory index then created a valid schema-19 agent database, and another status succeeded with one indexed chunk, zero cache rows/bytes, and the cache table present. No table was manually added. An indexed canonical agent database without this table cannot be produced by the supported flow. The retained-cache case is also covered by the existing integration test and both full live recovery probes.

The review's inferred data-model-change flag does not match the diff: there are no schema, storage representation, migration, or persistence-semantic changes. Full schema SQL/version and all 43 non-index tables remained identical through the live recovery proof. Production growth (+65 lines) provides read-only diagnostic facts and recovery guidance through existing owners.

@clawsweeper

clawsweeper Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation extensions: memory-core Extension: memory-core size: S maintainer Maintainer-authored PR labels Sep 4, 2026
@steipete
steipete marked this pull request as ready for review September 4, 2026 03:35
@steipete steipete self-assigned this Sep 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 4, 2026, 12:13 AM ET / 04:13 UTC.

ClawSweeper review

What this changes

The PR adds Memory Core storage diagnostics plus CLI and documentation guidance for safely reclaiming space from an agent’s shared SQLite database.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Blocked before merge - 5 items remain

Keep this PR open: its new storage query makes memory status fail for cache-disabled indexes whose intentionally optional cache table does not exist. The diagnostic and recovery direction is otherwise coherent and is not already on current main.

Priority: P1
Reviewed head: 29dc920da6e6b0ce3b55549ed00296509b8aee76

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The operator-focused direction is useful, but a high-confidence cache-disabled status regression blocks merge.
Proof confidence 🌊 off-meta tidepool Not applicable: The repository state identifies this as a maintainer-authored PR, so external-contributor proof is not a gate; the supplied CLI/Gateway evidence does not cover the newly identified cache-table-absent setup.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The repository state identifies this as a maintainer-authored PR, so external-contributor proof is not a gate; the supplied CLI/Gateway evidence does not cover the newly identified cache-table-absent setup.
Evidence reviewed 6 items Optional cache-table contract: The canonical memory schema deliberately omits memory_embedding_cache when caching is disabled, so an indexed agent can validly have no such table.
Introduced failing query: The new diagnostic always selects from memory_embedding_cache; SQLite raises a missing-table error on the valid disabled-cache database shape.
Status command reaches the query: memory status always requests source inspection, and inspected status now invokes the new storage collector before returning the status object.
Findings 1 actionable finding [P1] Handle disabled-cache databases before querying cache metrics
Security None None.

How this fits together

Memory Core indexes memory in each agent’s shared SQLite database, while the memory CLI presents diagnostic and recovery information to operators. This change carries database measurements through Memory Core status into JSON and terminal output, then points users to the existing Doctor compaction flow.

flowchart LR
  A[Agent SQLite database] --> B[Memory Core status]
  B --> C[Storage diagnostics]
  C --> D[Memory CLI and JSON]
  D --> E[Operator recovery decision]
  E --> F[Doctor compaction]
Loading

Before merge

  • Handle disabled-cache databases before querying cache metrics (P1) - memory status requests inspected status, but cache-disabled databases legitimately omit memory_embedding_cache. This unconditional select therefore turns normal status into a missing-table failure for those existing setups; return zero cache metrics when the table is absent and cover that path.
  • Resolve merge risk (P1) - Existing installations with memory.search.cache.enabled: false can have no cache table, causing the normal status command to fail after merge.
  • Resolve merge risk (P1) - The bug-fix branch adds production +65 net lines; the diagnostic capability justifies growth only once the absent-table compatibility path is handled without another recovery flow.
  • Complete next step (P2) - Handle the absent optional cache table and add a cache-disabled memory status regression before merge.
  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.

Findings

  • [P1] Handle disabled-cache databases before querying cache metrics — extensions/memory-core/src/memory/manager-status-state.ts:27-28
Agent review details

Security

None.

PR surface

Source +65, Tests +61, Docs +37. Total +163 across 10 files.

View PR surface stats
Area Files Added Removed Net
Source 5 67 2 +65
Tests 3 62 1 +61
Docs 2 38 1 +37
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 167 4 +163

Review metrics

Metric Value Why it matters
Production versus test delta production +65 net, tests +61 net, docs +37 net The new diagnostic surface is substantial for a bug-fix PR and needs the cache-disabled compatibility case before its added runtime path is safe.

Stored data model

Persistent data-model change detected: migration/backfill/repair: extensions/memory-core/src/cli-reset.runtime.ts, vector/embedding metadata: extensions/memory-core/src/cli-status.runtime.ts, vector/embedding metadata: extensions/memory-core/src/memory/manager-status-state.ts, vector/embedding metadata: extensions/memory-core/src/memory/manager.ts, vector/embedding metadata: packages/memory-host-sdk/src/host/types.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Preserve cache-disabled status (recommended)
    Guard the optional cache-table query and add a regression proving status succeeds for an indexed agent created with caching disabled.
  2. Accept the disabled-cache break
    Land the diagnostic knowing that affected operators must re-enable or recreate cache state before using memory status.

Technical review

Best possible solution:

Keep diagnostics read-only and report zero cache entries and bytes when the optional cache table is absent, with a regression covering cache-disabled memory status.

Do we have a high-confidence way to reproduce the issue?

Yes, from source: create or retain an indexed agent database with caching disabled before the cache table exists, then run openclaw memory status; the read-only status path reaches an unconditional select from that absent table. This was not executed in this read-only review.

Is this the best way to solve the issue?

No. The storage diagnostics must respect the existing optional-cache schema contract; returning zero cache metrics when the table is absent is the narrow owner-boundary repair.

Full review comments:

  • [P1] Handle disabled-cache databases before querying cache metrics — extensions/memory-core/src/memory/manager-status-state.ts:27-28
    memory status requests inspected status, but cache-disabled databases legitimately omit memory_embedding_cache. This unconditional select therefore turns normal status into a missing-table failure for those existing setups; return zero cache metrics when the table is absent and cover that path.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against cd80cce329d4.

Labels

Label justifications:

  • P1: The introduced path can break the normal memory-status command for existing cache-disabled agents.
  • merge-risk: 🚨 compatibility: The query assumes a table that current supported disabled-cache schema instances intentionally omit.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: The repository state identifies this as a maintainer-authored PR, so external-contributor proof is not a gate; the supplied CLI/Gateway evidence does not cover the newly identified cache-table-absent setup.

Evidence

What I checked:

Likely related people:

  • unknown: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Guard the optional cache table and add the cache-disabled status regression.
  • Run the built CLI status case against an agent database whose cache table was never created.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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 Sep 4, 2026
@steipete

steipete commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Final-head review and landing decision for 29dc920da6e6b0ce3b55549ed00296509b8aee76:

Fresh independent Codex review found no actionable P0–P2 defects and independently confirmed that the missing-cache-table claim confuses temporary rebuild storage with the canonical agent database. The PR body now addresses both ClawSweeper rank-up moves with source links and a real cache-disabled CLI status/index/status proof. No code or database changes were needed for that disposition.

The maintainer explicitly waived the npm audit outage for this landing. Exact-head CI is complete; only security-fast and its aggregate CI gate are failed. The sole failing security step is the production audit's repeated bulk-advisory timeout; the other security scanners passed. Local audit and independent minimal endpoint probes also timed out. This is a waiver, not audit clearance.

The native review artifacts are retained. Because the native landing wrapper cannot express a single-check waiver, landing uses a maintainer squash pinned to the reviewed head. Check results, CI configuration, dependencies, and repository rules remain unchanged.

@steipete
steipete merged commit cbcbb00 into main Sep 4, 2026
182 of 184 checks passed
@steipete
steipete deleted the codex/memory-recovery-135347 branch September 4, 2026 07:18
@steipete

steipete commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Post-merge verification on cbcbb005fdcf4c8c38770b65957b7f8b6527a1e4: the 72 memory index/storage tests passed, including explicit diagnostics, WAL reads, data-preserving rebuilds, and manager teardown. The first combined run passed 171/173 tests; two CLI cases (real reset/rebuild and orphaned-provenance handling) hit their existing 120-second limits amid heavy cold-import overhead. The complete CLI suite was then rerun in its original order with no source, assertion, or timeout changes: all 101 tests passed in 112.82 seconds. Both previously timed-out cases passed.

The merged change has the same stable patch ID as the reviewed candidate. One DB per agent remains unchanged. The only waived CI result is the previously documented npm advisory endpoint outage.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 5, 2026
…law#137876)

Expose database/WAL bytes, reusable allocation, and retained embedding-cache payloads in explicit memory diagnostics. Guide memory reset users through the existing offline Doctor compaction workflow before rebuilding.

Keep one SQLite database per agent, with no schema, table, layout, retention, migration, or configuration changes. This completes the operator recovery flow after the cache-publication and safe-reset fixes in openclaw#135373 and openclaw#135653.

Real Linux and macOS CLI/Gateway proof preserved 43 non-index tables and schema version 19, refused compaction while the Gateway was running, reclaimed 11,096,064 bytes after stopping it, and rebuilt searchable memory. Focused tests, builds, changed checks, and independent review passed. The maintainer explicitly waived npm advisory endpoint timeouts; other applicable CI checks passed or were skipped.

Fixes openclaw#135347. Thanks @AlexisBallo2 for the report.
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 maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Forced memory reindex inflates shared agent DB; deleting it for recovery destroys sessions

1 participant