Repository navigation
fix(memory): session memory sync fails with too many SQL variables on large session stores - #164336
Conversation
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…eter Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🦞👀 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. Reviewed October 3, 2026, 10:02 AM ET / 14:02 UTC. ClawSweeper reviewWhat this changesMemory Core replaces per-ID SQL bindings in session-exclusion and memory-origin queries with bounded JSON selections and adds regression coverage for large stores. Merge readiness✅ Ready for maintainer review This PR remains necessary: current main and v2026.9.8 retain the oversized-selection failure. The focused repair has relevant production-worker proof, and no introduced correctness defect was found. Priority: P1 Review scores
Verification
How this fits togetherMemory Core turns session transcripts into searchable memory. Its SQLite workers read session exclusions and memory lineage so indexing skips forgotten sessions and cleanup targets the correct entries. flowchart TD
A[Session transcripts] --> B[Memory corpus selection]
B --> C[SQLite memory worker]
D[Forgotten session records] --> C
E[Selected session and entry IDs] --> C
C --> F[Bounded JSON selection]
F --> G[Eligible sessions and matching origins]
G --> H[Memory indexing and cleanup]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +4, Tests +59. Total +63 across 5 files. View PR surface stats
Review metricsNone. Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Technical reviewBest possible solution: Keep one bounded-selection implementation across the memory-origin query paths while preserving forgotten-session exclusion and admitted deletion semantics. Do we have a high-confidence way to reproduce the issue? Yes: with an existing tombstone table, corpus selection exceeding SQLite's bind ceiling reaches the unbounded worker query on current main. The supplied before/after probe corroborates this path; this reviewer did not execute it. Is this the best way to solve the issue? Yes: reusing the established string-set helper repairs all affected query siblings without introducing chunking, another owner, or a changed storage contract. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against e39c8734eda9. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Landed as 21f9fae. Thanks @jayzhou2309! |
… large session stores (openclaw#164336) Fixes openclaw#164283. memory-core session-memory sync bound one SQL variable per session, so on installs with many sessions the startup catch-up and session update failed repeatedly with `too many SQL variables` and were retried. The affected queries now pass the session set as a single bound value instead of one variable per session. No schema changes, and the same rows sync. Proof: on a real isolated Gateway seeded with 32,768 sessions and local stub embeddings, base reproduced the catch-up and update errors. This change completed catch-up with exactly 32,768 sources and chunks, published an update without changing those counts, and `memory_search` returned session content. A small 3-session control is unchanged. The regression test fails on base and passes here. A live gpt-5-mini call passed. Thanks @nkarkare for the report. Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
Closes #164283
What Problem This Solves
Fixes: memory-core session sync fails with
too many SQL variableson every startup catch-up and session update when an agent has more sessions than SQLite's bind-parameter limit (32766 in the bundled build) and a forget tombstone table exists.User Impact
User impact: session memory on large installs indexes again instead of retrying and failing every few minutes. Forgotten sessions stay excluded, and results are unchanged for small selections.
Why This Change Was Made
Session catch-up and update pass every corpus session ID to
listMemorySessionTombstones. That worker query, and three sibling origin queries, bound each ID as its own SQLite parameter in anIN (...)list. Once the selection passed the limit, the query failed before the sync could finish.All four now bind the selection as one JSON parameter through the existing
sqliteStringSethelper, as the session and forget kernels already do:readMemoryEntryOriginsInDatabaseinpackages/memory-host-sdk/src/memory-entry-origins.ts(session and entry-key filters). The SDK's kysely bridge now re-exportssqliteStringSet.origin-existsandsession-tombstonesreads inextensions/memory-core/src/memory-entry-origin-reads.ts.deleteMemoryEntryOriginsInDatabaseinextensions/memory-core/src/memory-entry-origins-delete.ts.Agent filtering, ordering, and the delete's admitted transaction are unchanged.
Evidence
extensions/memory-core/src/memory-entry-origins.test.ts. It sizes each selection atMAX_VARIABLE_NUMBER + 1fromPRAGMA compile_optionsand covers origin reads by session and by entry key, the tombstone read, prune (existence preflight plus delete by entry key), and delete by session. On upstream/main ad3762e it fails withWorkerTaskError: too many SQL variables. On the fix a2148d8 it passes in about 1.1s.pnpm test:extension memory-core: 153 files, 1714 passed, 4 skipped. That includes the startup catch-up, session-update race, and forget concurrent-origin tests.packages/memory-host-sdkandextension-package-project-boundaries.test.ts: 63/63.pnpm tsgo:core,tsgo:extensions, andtsgo:extensions:testexit 0.scripts/run-oxlint.mjsexit 0,oxfmt --checkclean, andpnpm lint:kyselyOK on the changed files.upsertSessionEntryandappendSessionTranscriptMessageByIdentity, forgets one, and lists the session corpus through the startup catch-up harness, so the tombstone read runs in the real memory worker:Not verified: the reporter's Linux gateway on 2026.9.8, or the RSS pressure they saw during the retries.
AI disclosure: an AI agent (Claude Code) reproduced the failure, wrote the test and the fix, and ran the gates above:
pnpm test extensions/memory-core/src/memory-entry-origins.test.ts --maxWorkers=1,pnpm test:extension memory-core,pnpm test packages/memory-host-sdk src/plugins/contracts/extension-package-project-boundaries.test.ts,pnpm tsgo:core,pnpm tsgo:extensions,pnpm tsgo:extensions:test,scripts/run-oxlint.mjs,oxfmt --check,pnpm lint:kysely, the corpus probe above, and the repo'sautoreviewskill.🤖 Written and posted by an AI agent (Claude Code) on behalf of @jayzhou2309.
Maintainer verification
Verified exact head
a2148d8cea32a08bff8872db289655d4d69b9d53in secretless Docker. Thanks @jayzhou2309 for the complete fix and @nkarkare for reporting it.b12b4b98bb39f34ebdd907af49e3ad8fec771cb2failed startup catch-up and a realchat.injectupdate; SQL tracing identified the unboundedmemory_session_tombstonesselection. This PR head completed catch-up with exactly 32,768 session sources and 32,768 chunks.chat.injectcall published its unique new text in exactly one transcript chunk; both total counts remained 32,768. Gatewaymemory_searchreturned session content after catch-up and again after the update. No SQL-variable, startup-catch-up, or session-update errors appeared in the completed candidate log.bbfbb073f913ea7b460fe315cb0970ce351cd0cd: it failed withWorkerTaskError: too many SQL variables. On the exact PR head, the origin, startup-catch-up, and session-update-race files passed 70 tests across 3 files (--maxWorkers=1, 108.41 seconds wrapper wall time).gpt-5-minirequest on this head through a passive proxy, reasoninglow, output budget 4096; HTTP 200 and the expected response. Utility routing and scheduled jobs were disabled; no paid embeddings were used.No overlap with Pash/Sarah changes.