Repository navigation
fix(memory): avoid loading unrelated tombstones on session updates - #168098
Conversation
Filter targeted session sync before checking forgotten-session membership. Query bounded pages of candidate identities and return only matching positions, preserving all exclusions without transferring stored tombstone records. Remove the obsolete complete-row reader and migrate startup, dreaming, backfill, and recall callers. Related: #167838. The separate SQL-variable repair already exists on main; release inclusion remains open.
|
🦞👀 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 checks forgotten-session membership only for selected sessions using bounded pages of integer results. Example: Update one eligible session among 1,000 sessions with 998 forgotten sessions.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR addresses a distinct memory-query cost still present on current main. The earlier findings are resolved, and no actionable defects remain. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherMemory Core consumes transcript updates and corpus selections, checks durable forget tombstones in its retrieval worker, and passes eligible sources to indexing, dreaming, backfill, and recall. flowchart TD
A[Transcript updates and corpus scans] --> B[Select sessions and retain counterparts]
B --> C[Page candidate session IDs]
C --> D[Retrieval worker tombstone query]
D --> E[Matching integer positions]
E --> F[Eligible memory sources]
F --> G[Publication with live tombstone checks]
Technical reviewBest possible solution: Land the bounded membership queries with the preserved counterpart snapshot, while keeping release inclusion tracked separately. Do we have a high-confidence way to reproduce the issue? Current-main source exposes the whole-corpus, full-record query path, and the supplied pinned Gateway comparison demonstrates its allocation cost; this review ran no target code. Is this the best way to solve the issue? The patch repairs selection and projection at their existing owners, migrates all consumers, and removes the obsolete full-row reader while preserving publication-time exclusions. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 77bbc865a05b. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +16, Tests +131, Docs +4. Total +151 across 19 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 (4 earlier review cycles)
Reviewed October 10, 2026, 1:15 AM ET / 05:15 UTC (Revision 5). |
|
Merged via squash.
|
…penclaw#168098) * fix(memory): bound forgotten-session queries during updates Filter targeted session sync before checking forgotten-session membership. Query bounded pages of candidate identities and return only matching positions, preserving all exclusions without transferring stored tombstone records. Remove the obsolete complete-row reader and migrate startup, dreaming, backfill, and recall callers. Related: openclaw#167838. The separate SQL-variable repair already exists on main; release inclusion remains open. * refactor(memory): simplify ingestion candidate collection * test(memory): inspect persisted tombstones after recovery * fix(memory): preserve live counterparts during archive sync
Related: #167838
What Problem This Solves
Fixes: updating one session reloads forgotten-session records for the entire session corpus, copying unrelated data into the Gateway and occupying its memory-search worker.
User Impact
Session-memory updates check only their selected sessions. Forgotten sessions remain excluded from startup catch-up, updates, dreaming, backfill, and recall across every query page.
The SQL-variable repair from #164336 (
21f9fae8ad9d319c5d3b956a71ddff61315a6a15) is already on main but absent from the verified 2026.9.9 package. This PR addresses the separate recurring rows/bytes cost. The linked issue remains open until a release containing its repair is published.Why This Change Was Made
Targeted sync resolves its session/archive selection before checking forgotten-session membership, retaining admitted active/archive counterparts for selected session IDs from the same discovery snapshot. The owning query processes 256 candidate IDs per page and returns matching integer positions, bounding result rows and bytes independently of stored record sizes. Full scans process every page; no exclusions are truncated. The obsolete full-row reader/type and redundant caller conversions are removed. Publication-time tombstone checks remain authoritative.
No configuration, public SDK, schema, retained-data, or migration changes. Full canonical session inventory discovery remains linear; explicit forget and scheduled promotion still return complete origin arrays on their cold paths. Paging adds round trips to full scans. This does not establish an atomic snapshot across pages or constant total corpus memory.
Evidence
Head
797a6e39b787d3834d1d5e71111c5d0b57fab75apassed all required types, lint/format, and 1,741 tests (four existing skips) on Node 24.19.0: the complete memory-core module plus eight dependent test files, 165 files passed/one skipped, eight shards, 1,387.91 s wrapper wall time. The complete origin suite also passed on Node 24.16.0 and 24.21.0 (12 tests each; 42.69 s and 41.61 s wrapper wall time). The three local changed suites passed all 51 tests in 360.95 s cold wrapper time. Regression cases took 271 ms (row/byte budget), 1,597 ms (target selection), and 8,727 ms (real-manager archive cleanup); final hosted CI passed run 38025936762, with 14 test jobs totaling 1,797 job-seconds (209 s parallel wall span; whole job costs, not marginal regression cost).ClawSweeper’s exact-head review confirms no actionable findings and sufficient live proof. Both prior P2 findings are addressed: archive-only sync now preserves its active counterpart, and the budget observer covers both native
all()anditerate()without weakening its row/byte assertions. The archive regression fails with production unchanged at the previous PR head; the query regression still fails with only its production owner reverted.Fresh real Gateway proof compared this head with merged main
1f861ef5f85ed16d7fb0cdcf39e025f5a7adb170on AWS Crabboxcbx_98e783cb102e.The credential-free
r7a.xlargehad 32 GB RAM and Node 24.19.0. AWS was the authorized fallback after Blacksmith source staging stalled. Both revisions used isolated state and ephemeral loopback ports with actualpnpm openclaw gateway run, WebSocketchat.inject, and HTTPmemory_searchin FTS-only mode.Large fixture: 1,000 canonical sessions, 100,000 origin rows, 100,000 tombstones; 998 canonical sessions forgotten with synthetic 8 KiB reasons. Exactly two sessions remain eligible.
Both revisions produced exactly one updated chunk, returned the new text in search, excluded forgotten text, passed every health probe, and shut down gracefully. All observed tombstone SQL ran in workers. The earlier small-store control (three canonical sessions/100 rows) also preserved results on both revisions. Timings and query heap deltas include instrumentation (including serialization on the iterator path); total Gateway heap/RSS varied with GC, and end-to-end publication time did not materially improve. The demonstrated bound is on query results and allocations.
Archive-only live proof: actual Gateway
sessions.deletepublished an archive notification; a warmed fixture writer restored the same canonical SID in 1.777 s (main: 1.805 s), before the existing five-second debounce. After archive publication and graceful manager drain, the original active source, hash, and chunks were unchanged before any search could rebuild them. A restarted Gateway returned the live transcript in search. The same small-store flow on previous head56d40dba1e75failed withArchive-only sync deleted or changed a still-active SQLite counterpart, after restoration in 1.685 s and a graceful shutdown. This proves the live observation catches the reviewed cleanup defect.The first two follow-up live attempts were fixture failures, not product verdicts: readiness initially preceded agent inspection (
/startupzfixes the probe), then the restoration acknowledgement incorrectly included a cold corpus-verification read. V3 warms the reader and records mutation/verification separately; no product timing or assertions were weakened.unrelated-thread; reverting only the query owner made the budget regression return 513 rows against a 256-row limit. The tests stayed intact and candidate source was restored afterward.06fdd8ef42c5fbcfc3d8251c4469edd6a0ce9493: scoped-clean, no actionable P0–P2 findings. Deslop removed the superseded reader and redundant conversions.Commands, provenance, and investigation details
Final full-module/version gates:
run_4e870ccf0123510ceccb4fd9b47df4ba, 2,412.358 s total setup/check time, oncbx_98e783cb102e. Final live comparison and archive negative control:run_a51e75d07eb9a11f590dc296cccc0a6con that same lease, 535.972 s total. Metrics collection:run_b96519b7077ef8412371b2f9e6faaabb. Source was delivered as a 2,128-byte incremental Git bundle with a public prerequisite; exact HEAD/tree were verified before canonical secretless bootstrap and isolated dependency install. No operator state, credentials, or ports were used.Prior-head evidence retained: the wider memory-core/memory-host-sdk/dependent run passed 2,207 tests on
56d40dba1e75/Node 24.21.0 (run_c658d8f7bc66feb09f78391dc5e93183,cbx_df9d573f0a8b). Earlier small/large comparison:run_7c74f9083f53c882b7a5135d81cc694aoncbx_fcf1be08794f, 364.205 s. Both earlier leases were stopped and list-verified.The final local focused command was
node scripts/run-vitest.mjs extensions/memory-core/src/memory/manager-reads.test.ts extensions/memory-core/src/memory-entry-origins.test.ts extensions/memory-core/src/memory/manager-sync-ops.startup-catchup.test.ts --maxWorkers=1: 51 tests passed, 360.95 s cold wrapper wall including worker preparation. The archive test against unchanged production failed for the intended missing live source (291.03 s cold wrapper).Constant-width owner probes showed complete tombstone results growing from 88,001 B / 5.43 ms at 1k rows, to 880,001 B / 62.56 ms at 10k, and 8,800,001 B / 465.05 ms at 100k. The 100k origin reader returned 15.9 MB in 589 ms. Candidate full tombstone membership took 1,098 ms / 1.9 MB serialized ID-array output, documenting the full-scan paging tradeoff. Origin full-row readers serve explicit forget/scheduled promotion, not ordinary per-search membership.
The first full-module run exposed a test observer error: it consulted cached schema-admission facts after a worker created the optional tombstone table. The helper now checks the actual schema before independently reading persisted rows; assertions and recovery behavior are unchanged. The full suites now pass. One test-only unbound-method exception is source-verified:
Reflect.applyexplicitly supplies the intercepted SQLite statement receiver. Production keeps the expression-builder receiver without suppression. The portable observer retains the native iterator and its cleanup while counting yielded rows and serialized bytes; full origin-suite passes on three supported Node patch levels and the Node 24.16 negative control verify both execution paths.ClawSweeper's existing issue finding concerns release inclusion. Official tarball integrity and embedded release commit
bcfc88812a35243893585dbeca87ca41b48272cawere independently verified, and the coordinator-requested issue comment records the remaining release work. This PR does not publish that release or close its issue.Exact change size against the merged main baseline
Production: +118/-102 (net +16); tests/support: +198/-67; docs: +4/-0. The production LOC exception is needed for page coordination, integer result projection, and preserving active/archive counterpart facts for cleanup. The obsolete full-row contract and redundant conversions are deleted; no compressed or unrelated edits offset the increase.