Repository navigation
feat(memory): reset derived indexes without deleting sessions - #135653
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed September 1, 2026, 9:21 PM ET / September 2, 2026, 01:21 UTC. ClawSweeper reviewWhat this changesAdds Merge readinessNo blocking source finding: reset is limited to schema-owned derived memory tables and now serializes with all memory sync generations. Keep this PR open until the failed exact-head CI gate is resolved and maintainer merge handling completes. Priority: P2 Review scores
Verification
How this fits togetherMemory Core stores rebuildable search data alongside canonical agent sessions in the per-agent SQLite database. This command coordinates with indexing, clears only derived memory tables, and leaves the session owner intact. flowchart LR
A[Operator] --> B[Memory reset CLI]
B --> C[Agent database validation]
C --> D[Maintenance leases]
D --> E[Derived memory index]
C --> F[Sessions and transcripts]
E --> G[Memory index rebuild]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +171, Tests +220, Docs +51. Total +442 across 19 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Land the schema-owned reset operation only after exact-head CI is green, while keeping the broader derived-index database split in #135347. Do we have a high-confidence way to reproduce the issue? Not applicable: this PR adds a CLI capability rather than repairing an existing command; supplied Gateway/CLI evidence exercises its intended preservation behavior. Is this the best way to solve the issue? Yes. A schema-owned derived-table registry guarded by existing maintenance leases is safer than deleting the shared agent database. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against bd24c98c330e. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles)
|
|
ClawSweeper follow-through: the sole Rank-up move is complete. Exact-head CI is green for Proceeding under the explicit maintainer-approved reset/docs scope in #135347 (comment). The intentional deletion is limited to the schema owner's derived-table registry, behind default-no confirmation or explicit The final isolated Gateway/CLI rerun passed: 2 indexed chunks and the synthetic cached embedding were cleared; 3 transcript rows and all 44 non-memory tables stayed byte-identical; a repeat reset was a no-op; normal indexing rebuilt the index; and the running Gateway could still read sessions and append a transcript. All Gateway/CLI proof processes exited cleanly. No code changes or review skips were needed for the ClawSweeper feedback. The dedicated derived-index database split remains deferred to the next natural schema bump. #135347 will stay open as its tracker. |
Hold the existing reindex lease at the concrete sync owner through embeddings, writes, and cleanup, so reset uses the established busy refusal instead of being overtaken by an in-flight incremental write. Remove duplicate full-reindex and cleanup lease ownership. Add the paused-embedding regression and narrow docs to canonical table and memory-source preservation. No schema, configuration, or new lock.
|
Both findings in the latest ClawSweeper review are addressed in the final head The incremental race was reproduced on the earlier runtime: reset returned success while an embedding request remained paused. The repair moves the existing reindex lease to the concrete sync-generation owner, covering full and incremental indexing through final writes and cleanup, and deletes the duplicate lower-level acquisitions. Under the approved maintenance convention, reset refuses while that sync is active and succeeds after it drains. A per-write revision comparison would incorrectly reject the generation's own revision-changing writes. The paused-embedding regression passed after repair, followed by 195 focused/sibling tests. The final export cleanup passed 28 database/recovery tests and all unused-export scans. The exact final-head real Gateway/CLI race proof also passed: busy refusal preserved the published index/cache, later reset cleared them, ordinary indexing rebuilt two chunks, and three canonical transcript rows plus all 44 non-memory tables remained byte-identical. The Testbox lease stopped and no owned processes remained. The docs now promise preservation of non-memory database tables and memory source files, not coordination files. Both rank-up moves are covered; the suggested “reset completes before releasing the old write” ordering is intentionally replaced by the existing busy/refuse contract. No schema/config/version/protocol changes or new lock were introduced. The dedicated derived-index database split remains deferred to the next natural schema bump, tracked by #135347, which will stay open. No additional review request is needed under the repository's under-12-hour rule: the subsequent commits address these findings plus mechanical export cleanup. Exact-head CI is now green on attempt 2; native prepare/merge remain required independently. |
|
Merged via squash.
|
…aw#135653) * feat(memory): reset derived indexes without deleting sessions * fix(memory): serialize reset with incremental indexing Hold the existing reindex lease at the concrete sync owner through embeddings, writes, and cleanup, so reset uses the established busy refusal instead of being overtaken by an in-flight incremental write. Remove duplicate full-reindex and cleanup lease ownership. Add the paused-embedding regression and narrow docs to canonical table and memory-source preservation. No schema, configuration, or new lock. * refactor(memory): keep reindex acquisition helper private
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 #135373 and #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 #135347. Thanks @AlexisBallo2 for the report.
…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.
…reset for 8.35-C Backport OpenClaw PRs openclaw#168400, openclaw#169728, openclaw#166782 and openclaw#135653 onto the existing 2026.8.35 custom release. Preserve the 8.35 UI, locked dependencies, schema versions, bundled Codex and previous A/B maintenance repairs. Canonical build source: 06aadf04949b9aaa0d2665c952124df700ccc191 Verified complete source tree: 4d9e205 Upstream base: 713ba57 Runtime checks run inside the single resource-bounded Docker build. Memory reset is an explicit operator command and is not executed during build or deployment.
Related: #135347 (leave open for the dedicated derived-index database split)
What Problem This Solves
Resolves a problem where operators have no explicit way to discard the builtin memory index and embedding cache without risking canonical session history. The per-agent
openclaw-agent.sqliteis not a disposable memory cache: deleting it or its SQLite sidecars also deletes canonical sessions, transcripts, and other durable state. Reported by Alexis Ballo (@AlexisBallo2); scope approved in #135347 (comment).Why This Change Was Made
openclaw memory reset [--agent <id>] [--yes]clears only the schema owner's registry of derived memory tables. It reuses the existing reindex lock, workspace lock, and index-publication generation lease, then drops and recreates the existing table/index/trigger definitions in one SQLite transaction. Empty metadata requests the normal rebuild path, while a monotonically increasing revision fences stale generations. Retaining identical empty definitions keeps the shared agent database valid and already-open FTS/vector handles usable.The CLI validates ownership/schema without invoking the normal schema initializer, which can repair unrelated session tables. It needs no embedding credentials and reuses the existing memory agent-selection policy. Durable origins/tombstones and every non-memory table stay outside the reset registry. No schema change, schema-version bump, new configuration/environment option, dependency override, or new lock is introduced.
The concrete sync-generation owner now holds the existing reindex lease through both full and incremental indexing, including awaited embeddings, final writes, and cache cleanup. Reset therefore waits or reports the existing busy error instead of being overtaken by an already-admitted incremental write. The old full-reindex-only acquisition and the cleanup helper's duplicate acquisition are removed; shadow cleanup remains full-reindex-only under the caller-owned lease.
#135373 already bounds the shadow embedding cache before atomic publication. Moving derived memory tables into a dedicated disposable per-agent database is explicitly out of scope here and scheduled for the next natural schema bump, with a reviewed Doctor migration. #135347 remains that tracker.
User Impact
Operators can reset one agent or, following existing memory commands, all configured agents. Interactive confirmation defaults to no; non-interactive use requires
--yes. A missing or empty index is a successful no-op. The command prints the normal rebuild command. The Gateway need not restart and can repopulate retained sources afterward.The memory CLI/reference recovery docs explicitly warn never to delete the shared agent database or its sidecars to reset the index. Reset does not shrink the database file, recover previously deleted sessions, or act as a privacy purge;
memory forgetremains the targeted removal operation.Evidence
Current head is
2eb3f665703baaf09884ae0faf7cc7d9f32b1045; its exact-head CI is green on attempt 2 (native watcher exit 0). The first attempt had one unrelated Gateway-help post-parse shutdown hang; the exact failed job passed unchanged on retry, without increasing any timeout or weakening assertions. Final branch Codex autoreview completed with no accepted findings at its requested P0 threshold. A source-hash-verified regression failed before the lease repair: reset returnedtruewhile incremental embedding remained paused. The same regression then passed, followed by 195 tests across 10 focused/sibling files. After CI caught the now-test-onlytryAcquireMemoryReindexLockexport, the final cleanup made it private and moved tests to the existing public wait helper; 28 database/recovery tests and all three exact dead-export scans passed. No runtime function bodies changed in that cleanup.The final exact-commit built Gateway race proof passed, using a clean checkout at the full head above and tree
f8e8d6a5c88b34d939232d74bcee754d4ee3c3d7. Provider:blacksmith-testbox; leasetbx_01m1ftdvnbpx47tjpdkent1g09; command: frozen install, supportedqaRuntimebuild, then the isolated real Gateway/CLI scenario. Wrapper exit 0, lease stopped, zero owned processes remained. This is real Gateway behavior with a synthetic loopback embedding service, not external-provider proof. The final focused changed-files gate passed on the verified final source tree: both extension TypeScript lanes, formatting, all unused-export scans, lint, database-first and runtime import-cycle guards. Providerblacksmith-testbox, leasetbx_01m1fv5rqncp7wvvf5x0pzdfhh, exit 0, stopped cleanly. Its first attempt stopped before tests because the transport bundle lacked the original commit object; the successful retry fetched that immutable object and verified the same tree. Native review was reinitialized after the final push, artifacts validated, andOPENCLAW_TESTBOX=1 scripts/pr prepare-run 135653completed without changing or pushing the reviewed head.An obsolete broad snapshot was stopped after the export cleanup superseded it. Its late result passed core/extension production typechecks but failed starting extension-test typechecking with
spawn corepack ENOENT; it is not counted as a pass or a source-code regression.The earlier head
73fd83a515bdd59f6e4dfd57c4c8cb26722de56ahad green CI, a clean full local changed-files gate, 112 committed-head CLI/database tests, quiescent built Gateway proof, and native prepare. Those results are historical evidence, not a claim that the revised head's remaining gates have finished.Regression coverage uses real SQLite/FTS/sqlite-vec tables and real canonical session rows. It checks exact schema preservation, empty derived tables, byte-identical unrelated rows, monotonic revision, repeated/missing-index no-ops, non-interactive confirmation, and reset followed by the ordinary index rebuild. The new reset tests failed before implementation. A second red/green regression caught the first implementation's unrelated session-schema repair: normal opening added
session_pending_inputs.consumed_event_id; the validation-only reset opener leaves it unchanged.Focused verification:
node scripts/run-vitest.mjspassed 119 CLI/database/generation-lease tests, and a separate original-order recovery-suite run passed all 16 tests (135 total). The existing shadow-cache test timed out during two earlier heavier runs; it then passed in isolation and the entire recovery file passed unchanged in its original order. No timeout or assertion was weakened. Both documentation pages passed MDX checks, and all 7,206 documentation links validated. Codex autoreview found no actionable findings.The initial full build compiled JavaScript and declaration chunks but refused final declaration publication when the compilation snapshot changed. After freezing production inputs, the supported
qaRuntimebuild passed, including CLI bootstrap, plugin/runtime assets, and postbuild validation; that artifact was used for the first live proof. During the final refresh, the existing control-plane probe timed out while local I/O was slow; the postbuild retry passed all 12 phases and verified all 53 modules, then the final live proof and 112-test rerun passed. No limits were increased.Live proof used the built CLI and an isolated running Gateway, a fresh
OPENCLAW_STATE_DIR, a free loopback port other than 18789, synthetic memory files, and synthetic sessions created/appended through Gateway RPC. No operator state or external embedding service was used. The FTS-only live run also seeded one synthetic cached embedding; sqlite-vec clearing and exact virtual-table schema preservation are covered by the real SQLite regression test.Final-head concurrency transcript:
Production LOC: +249/-78 (net +171); tests: +254/-34 (net +220); docs: +60/-9 (net +51). Production growth implements the explicitly approved destructive CLI capability, its schema-owned allowlist, and atomic same-schema reset with existing coordination. Reusing agent selection, locks, schema validation, and normal indexing avoids a second recovery path. The concurrency repair itself reduces production code by moving lease ownership and deleting duplicate acquisitions.
NO-FOLLOW-UP: the worthwhile owner-boundary cleanup is included by centralizing the derived-table registry and reusing agent selection; the remaining shared-file blast-radius repair is the explicitly deferred database split tracked in #135347.
Landing Status
Merged through native
merge-runas9e45fd9db7192ba82186f8115feeeacb0603eb24, verified as an ancestor of fetchedorigin/main. Exact-head CI, final focused changed-files gate, branch autoreview, final-head live Gateway proof, and native preparation all passed. Both findings in the refreshed ClawSweeper review are addressed: the reproduced in-flight incremental race is coordinated at the existing sync lease owner, and both docs now promise preservation of non-memory tables and memory source files rather than arbitrary coordination files.Rank-up moves: the paused-embedding regression and final-head Gateway/CLI proof are complete. The suggested ordering “complete reset before releasing the older write” is deliberately replaced by the approved existing-maintenance contract: reset refuses while the older sync owns the lease, then succeeds after it drains. The red run proves the earlier implementation incorrectly completed reset in that interleaving. A fresh reviewer request is skipped under the repository's under-12-hour rule: subsequent changes address these findings plus mechanical export cleanup; the latest durable review covers the findings, and exact-head CI remains required.
Separately, replacement main CI is green, and all four queue-edit E2E tests passed on a clean current-main checkout at
c4b8d42bd42cdf4ef447bd48dc96abc1fa33c27f, including the previously failing reconnect case. The Testbox wrapper exited 0 and cleanup was confirmed. Earlier manual retries tested separate auth-branch targets despite main workflow SHAs, so they are excluded from current-main claims. The original queue failure's root cause remains unproven; this is current-main revalidation, not a claimed repair. No unrelated code repair is included here.Native preparation initially stopped on a transient GitHub wrapper string-rewrite-policy read failure. After confirming no operation processes remained, its exact emitted lock token was recovered and the same protected preparation succeeded. No policy bypass was used. Named diagnostic follow-up only if the unrelated help hang recurs: CLI help post-parse teardown stage/active-handle evidence; no speculative code change is included.
Final ClawSweeper refresh (01:21 UTC) reviewed the exact final head with no actionable source findings; its only rank-up request was exact-head CI, satisfied by attempt 2. Landed-parent LOC is production +249/-78 (net +171), tests +251/-32 (net +219), docs +60/-9 (net +51); the earlier reviewed-branch test delta differs because main already contained the fixture isolation cleanup. The task checkout is clean at the verified main revision.