Repository navigation
perf(memory): batch chunk writes across indexed sources - #174874
Merged
Merged
Conversation
Contributor
|
🦞👀 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. |
Contributor
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Contributor
Author
|
Merged via squash.
|
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Oct 17, 2026
This was referenced Oct 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Problem This Solves
Transcript memory indexing groups several sources in one worker transaction but still executes three relational INSERTs separately for every small source. SQLite also probes vectors and rereads old embeddings before applying publication-owned replacements.
User Impact
Reduces memory-indexing SQL while preserving indexed text, metadata, provenance, FTS and vector results. Recall keeps the existing freshness policy: indexing after 30 seconds quiet, or the next idle gap after five minutes pending; search reads the last committed index and does not force a flush. No configuration or migration is required.
Design
The existing publication kernel combines final partial chunk batches across distinct sources, carrying source context on each row and bounding batches at 128 rows. Full batches, intermediate removal flushes and repeated-source boundaries publish in order within the existing transaction. Individual-source writes use the same kernel. Ordinary memory files retain their individual path when remote embedding batches are disabled; grouped transcript publication benefits from the batching.
SQLite consumes supplied embeddings without per-vector existence probes or old-embedding comparisons. The final supplied embedding for each ID wins, including changed and empty vectors. PostgreSQL skips manual-vector candidate work because its projection is trigger-owned. Old IDs remain available for deleting rows and vectors removed by full replacement; metadata-only retained rows preserve their vectors. Shadow-to-live publication and transaction boundaries are unchanged.
Removed checks and accepted edge cases:
Session-forget tombstones and vector-repair state remain because they protect deleted user data and actual failed cleanup. The batching tradeoff is retaining at most one 128-row partial relational batch until the existing group commits. No schema, SDK, watcher, scheduling, generic-staging or PostgreSQL engine implementation changes.
Measurements
Exact baseline
2a42cf8ae96897a847364cd084c77ac21197c95dversus candidate9e1a9f67169821a8766eae730069b9f30fe4919d. Three alternating memory-enabled pairs (M,C,M,C,M,C), followed by one standard-v3 non-regression pair, reuse pinned builds and the same Node/SQLite runtime. The private shared-v3 adapter uses three synthetic agents, 24 notebooks per agent, 24 seeded sessions / 576 messages, deterministic loopback embeddings, normal memory-search activation, and edits to eight notebooks per agent. No real data or external model service.Workload totals and normalized costs below are median [min–max] across three runs per arm. All runs submit 590 chunks. Each has ten chunk-producing passes; there are seven zero-chunk passes except C3, which has six. Per-pass rows summarize each run's mean, not the distribution of individual passes.
The memory-pass SQL median falls 2.83%; this change does not establish a worker-request reduction. The changed operations are exact in every arm:
source.replace.group594→520 SQL with 5 commands / 5 transactions, andsource.replace.inline1,998→1,926 SQL with 104 commands / 104 transactions. That is 146 fewer statements with unchanged command/transaction counts. Shadow-to-livedatabase.publishremains 159 SQL / 3 commands / 6 transactions in every arm. Other work varies, includingvector.ensure(11–12 baseline commands versus 12 candidate) and no-op passes. Whole-Gateway totals include unrelated boot, turn and background work.Incremental SQL falls 8.79% with requests unchanged. Initial activation is selected by phase and chunk-producing work, regardless of trigger: C3's main-agent pass was triggered by
watch, while the other initial passes weresearch-bootstrap.Warmed rows below are pooled individual-turn median [min–max], separately from the three-run summaries above.
Memory-enabled causal warmed work is 78 SQL / 23.1 requests per turn in every run (run mean), with 0 MAIN. C3's final raw warmed window includes 9 background statements / 5 background requests; causal turn work is unchanged. Standard-v3 causal warmed distributions are identical: 64 [64–65] SQL / 19 [19–20] requests / 0 MAIN. Nonzero raw MAIN samples are background work; the lower standard raw medians are not claimed as patch savings. No memory SQL overlaps these warmed windows, so this proves non-regression, not concurrent-indexing savings. Changed-owner T1 call sites remain 0→0.
Rows, bytes, FTS and vector work
Each arm submits 590 chunk, metadata and provenance rows, 710,049 UTF-8 text bytes, and 18,880 binary64 chunk-embedding bytes. Successful native
run().changestotals are 3,267 [3,267–3,267] baseline versus 3,267 [3,267–3,291] candidate; C2's extra 24 changes are cache bookkeeping (eight deletes, sixteen inserts). These are logical submissions/observed changes, not disk or WAL bytes.run().changesomits exec DML, shadow-to-live copies and trigger-internal changes. Actual indexed-message counts are unavailable; the 576 seeded messages are not used as that denominator.FTS/vector figures count explicit top-level SQL; trigger-internal FTS VM work is unmeasured. Final FTS/vector rows and ordered keyword/vector search output are byte-identical in the owner capture. All six workloads have five session-source group commands, up to eight sources per group; 538 JSON staging steps and zero worker staging commands per run. Generic staging inserts were not changed, so no generic-staging PostgreSQL rerun is requested.
Observed timing (overlapping intervals; no latency claim)
These are milliseconds per pass, summarized as three-run median [min–max]. The shared 32-core host was busy (recorded one-minute load 37.375–109.08 across run start/end samples). SQL, embedding, publication, serialization and staging intervals overlap, may run concurrently, and include instrumentation overhead; they are not additive exclusive timing buckets and do not establish latency improvement or regression. Worker staging handlers were not exercised; JSON fragment construction was.
Proof and Limitations
Owner capture passed exact stored-row and ordered keyword/vector-search equality, obsolete-vector deletion, changed same-ID vector bytes, delta/full replacement equivalence, trigger-abort rollback, and an actual child SIGKILL after native chunk INSERT but before COMMIT followed by reopen recovery. Eight one-chunk sources cost 91→70 SQL; repeated publication 99→78; each remains one transaction with identical successful direct row counts and bound-write bytes (40 rows / 4,416 bytes initially; 56 / 4,928 on repeat). The capture starts without a clean vector marker, so these savings establish batching; committed clean-index regressions cover removed probes, replacement, retention and cleanup.
Final-head CI 38990924116 passed changed-extension suites, production/test types, type-aware lint, source contracts/export collisions, architecture/Madge, T1/dialect ratchets and PostgreSQL conformance. Both allowed independent Codex autoreview rounds found no actionable P0–P2 defects. Changed-file formatting, direct lint and diff checks passed. Knip has no new findings: 28 production findings match integrated main
2a42cf8ae968, 22 full-tree findings match main86abec416118, scripts are clean, and no finding is in the changed owners. This is an inherited-finding qualification, not a clean whole-repository Knip result. A local type-aware wrapper timed out preparing SDK declarations; final-head CI passed. SDK API diff and published-driver update cell do not apply.Failed attempts are excluded, not counted as passes. Early fixture issues were repaired (SQLite row-prototype assertion, missing seeder runtime-config preparation, and tool-receipt/observer parsing). One C3 attempt closed WebSocket 1006 during activation; its cause remains unestablished, and the successful replay does not prove a fix. Two later attempts timed out before Gateway launch, during synthetic account setup and transcript seeding. The private adapter allows account setup 300s instead of 120s and C3 seeding 600s instead of 180s; both standard arms use the same account adjustment. Exact source normalization/hashes verify only these unmeasured deadlines changed. Shared harness files and measured workload/observer inputs remain untouched by those adjustments. All failed-attempt children exited.
Production +94/−79 (net +15); tests +231/−54 (net +177). The production growth carries per-row source context through one bounded implementation; superseded checks and obsolete assertions are removed. Follow-up for the engine owner: at the candidate head, the removed
prepareExistscaller leaves only engine-contract tests; retire that unused capability in the engine-owned scope.