Repository navigation
fix(memory): session sync deletes and re-embeds every indexed chunk as transcripts grow - #103201
Conversation
|
Codex review: needs maintainer review before merge. What this changesThis PR retains unchanged session chunks and embeds and publishes only new or changed chunks. Example: Append two turns to the supplied 100-turn session with embedding caching disabled.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: current main still replaces unchanged session chunks, and this focused repair has sufficient runtime proof, passing exact-head CI, and no actionable findings. Priority: P1 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherMemory Core prepares session transcripts, requests embeddings, and publishes searchable chunks through its existing SQLite worker. flowchart LR
A[Session transcript] --> B[Memory Core preparation]
B --> C[Worker index read]
C --> D[Session delta planner]
D --> E[Embedding provider]
D --> F[Publication worker]
E --> F
F --> G[SQLite chunks and search indexes]
Technical reviewBest possible solution: Land the session-only delta through the existing publication worker while keeping full rebuilds as complete replacements. Do we have a high-confidence way to reproduce the issue? Yes: append to an indexed session with caching disabled and sync again; current main routes the changed transcript to complete source replacement, matching the supplied CLI comparison and affected-user report. Is this the best way to solve the issue? This is an appropriate owner-level repair: content-addressed row retention removes embedding and publication amplification without adding offsets, rotation policy, configuration, or another writer. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against dd036a4b1d85. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +253, Tests +308, Docs +3, Other -1. Total +563 across 16 files. Added test files: 1. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. 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 (14 earlier review cycles; latest 8 shown)
Reviewed October 10, 2026, 6:20 AM ET / 10:20 UTC (Revision 15). |
|
This pull request has been automatically marked as stale due to inactivity. |
c073fe1 to
6800327
Compare
6800327 to
53fd0f9
Compare
53fd0f9 to
05e4875
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Reproduced on Windows, and the growth rate makes this a daily-restart problem rather than a slow leak. Host: OpenClaw 2026.9.5 ( Measured growth after a clean restartThe gateway was restarted at 12:02Z specifically to clear a stalled WAL. Measured 2.5 h later, with no unusual workload — one long-running interactive session:
The WAL reached the size of the database itself within three hours of a clean start. An earlier measurement on this host (2026-09-26) put sustained growth at ~1,100 MB/h while the session index was actively catching up. Checkpoint cannot drain itFrame-level readings from the WAL index (
Write distribution, matching this PR's premiseMeasured on this host on 2026-09-26, rows written per hour:
Factor ~120 between indexed chunks and actual transcript events. Of those 3,201 chunk writes, 2,898 belonged to the single growing session JSONL — which was also its total chunk count at the time, i.e. 100% of the file rewritten in one wave per sync. Not duplicated writes (checked: 0 exact duplicate Practical impactWithout the fix the only mitigation here is restarting the gateway every two to three days, which terminates any running session. The secondary effect is worse than the disk usage: with a multi-GB WAL, This PR has been open since 2026-07-10 with CI green, no failing checks and no review. If a second affected host with numbers helps move it, I'm glad to run any specific before/after measurement on Windows. |
Resolve the worker-publication conflict by taking main's memory-core publication owner; the branch-side manager writer is replaced by the worker-kernel session delta in the following commit.
Growing session transcripts were republished with a whole-source replacement on every dirty sync, so DB/FTS/vector churn and embedding work scaled with the full transcript instead of its new tail. Session publication now keeps rows whose content-addressed chunk ids are unchanged. The manager only plans: it reads indexed ids through the publication worker and embeds new chunks. The worker kernel, inside its write transaction, verifies retained rows, writes new rows, deletes ids the publication omits, and refreshes provenance only when it changed. If a retained row vanished before the write lock, nothing is written and the manager immediately republishes the source in full. Full reindexes into a shadow keep the existing whole-source path. No schema, config, or search-result changes. Closes openclaw#40919
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
Related: #40919
What Problem This Solves
Growing session transcripts rewrite every indexed chunk on each sync. With the embedding cache disabled, they also send unchanged text to the embedding provider again, spending local CPU/GPU time on repeated work.
User Impact
Session appends retain unchanged chunk rows and embeddings. Only new or changed chunks are embedded and published, including when caching is disabled. Truncation and provenance changes still take effect; full rebuilds retain complete replacement.
No user configuration, database schema, row encoding, chunk identity, or migration changes. Existing indexes remain usable. Full transcript preparation still occurs; this fixes embedding and publication amplification.
Why This Change Was Made
Delta publication stays inside the existing SQLite worker. Retained rows are staged first and validated transactionally before indexed writes. Missing rows cause one full-source retry after releasing the workspace lock. Both indexing paths share preparation and recovery. The existing lazy chunk writer owns provenance updates, and vector cleanup/rebuild debt retain their existing owner. Empty sources preserve the optimization from #146150.
Main was merged without rebasing or replacing @wr-web's commits. The branch consumes main's timeout, batch-retry, embedding-format, and admitted-table helpers. The latest conflict resolution moves the kernel to the shared SQLite
tableExistshelper; its delta logic is unchanged. The canonical test fixture now honorscacheEnabled: false, which previously fell back to enabled caching and masked provider work.Production: +376/-123 (net +253, down from the original +326). Tests/support: +310/-2. Docs: +3/-0. Tooling: one stale max-lines exemption removed. Neutral production would require unrelated deletion or dropping staged transfer, drift recovery, or publication safeguards.
Evidence
Final head:
2bb17071d149f380cdb10ceee516994c9d74d928. Integrated main:51e7ca28cb945c522ad7e1ca994790fba5eeed12. Runtime proof uses3b60992c552e23017e87b99b2b967cabc6cdb4c9; the sole later change removes the stale baseline entry.Real CLI → Memory Core → publication worker → Ollama
nomic-embed-text, behind a loopback logging proxy on macOS/Node 26.11.1. Synthetic 100-turn session, then two appended turns. The candidate used a copy of main's existing index; cache disabled for this comparison:c75ff3cbf56e)All embedding requests succeeded. The default-cache control on main sent one input, showing that caching hides provider work but not row churn. Current main still clears/replaces the source rows. The candidate index completed in 37.42s; early/latest searches took 20.90s/25.36s and returned the correct retained and updated ranges without stale warnings. The latest top-result range 198–205 contains the appended turns.
The corrected replay preserves the baseline config byte for byte, including the proxy address. An earlier fixture restart changed that address, correctly invalidated the endpoint-scoped provider key, and forced a full rebuild. That run is excluded from delta proof; no product code was changed for the fixture error.
# OPENCLAW_STATE_DIR and OPENCLAW_CONFIG_PATH point to isolated synthetic state. pnpm openclaw --profile memory-sync memory index --verbose pnpm openclaw --profile memory-sync memory search topic-001 --max-results 5 --min-score 0 --json pnpm openclaw --profile memory-sync memory search topic-102 --max-results 5 --min-score 0 --jsonValidation:
node scripts/run-vitest.mjs <files> --maxWorkers=1, 777.40s command wall (720.70s Vitest). Test callback totals: session-delta 12.054s, publication-transfer 13.572s, source-kernel 0.679s, vector-state 0.046s, targeted-sync 0.029s, index-retention 17.632s, existing reindex-recovery 197.377s and startup-catchup 95.225s. The owning-boundary regression exercises real manager preparation, native session storage, worker publication, and provider-input exclusion. The earlier nine-file 170/170 run remains evidence for unchanged probe, timeout-policy, and shadow-owner behavior.pnpm build: pass, 2338.01s. Production/test types: pass, 57.38s/54.16s. Scoped oxlint: pass, 934.44s including declaration preparation under the supported budget. Formatting andgit diff --checkpass.38042571477passed, includingopenclaw/ci-gate. Its three changed-extension test bundles took 242–255s each, 742 aggregate job-seconds including setup and sibling tests; this is not isolated regression cost. ClawSweeper reviewed this exact head: 5/6, proof sufficient, no findings or Before merge items.Builds and tests were serialized after an earlier attempt collided with generated package artifacts. Proof files and logs distinguish that tooling failure, the changed-route fixture, and the passing runs.