Repository navigation
perf(memory): batch source headers during publication - #182935
Conversation
|
🦞👀 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 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. |
|
Codex review: needs maintainer review before merge. What this changesThis PR batches memory source-header upserts within the existing publication kernel. Example: Publish 100 distinct memory sources in one group.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this useful, maintainer-directed optimization is absent from current main, and source review found no concrete introduced defect. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherMemory publication workers pass admitted source headers and chunk rows to the shared kernel, which updates SQLite or PostgreSQL inside the caller-owned transaction. flowchart TD
A[Memory indexing] --> B[Publication worker]
B --> C[Transaction and source checks]
C --> D[Source index kernel]
D --> E[Bounded header upserts]
D --> F[Chunk and search writes]
E --> G[Commit and revision publication]
F --> G
Technical reviewBest possible solution: Retain bounded header batching in replaceGroup while preserving the existing transaction, source-check, and publication owners. Do we have a high-confidence way to reproduce the issue? Current main visibly issues one header upsert per source, and the reported corrected baseline tests reproduce the redundant statement counts; no target code was executed during this read-only review. Is this the best way to solve the issue? The change uses the existing shared owner, removes the scalar path, bounds buffering, and preserves last-header-wins semantics without adding a schema, configuration option, or competing publication path. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 4c3bf18daa6c. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +30, Tests +52, Docs +97. Total +179 across 5 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
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 Reviewed October 24, 2026, 6:13 PM ET / 22:13 UTC. |
…w#182935) Batch source metadata at the existing publication owner instead of issuing one UPSERT per source. Bound statements to 128 distinct keys and about 64 KiB, deduplicate repeated keys with final-header semantics, and preserve the existing transaction, tombstone checks, and chunk/vector ordering. Source-header statements fall from 100 to 1 and from 129 to 2. SQLite owner tests and native PostgreSQL owner/publication tests pass. Exact-head CI type, lint, contract, and architecture jobs pass; seven unrelated onboarding fixture failures are attributed to openclaw#182856 and owned separately. No latency improvement is claimed.
What Problem This Solves
Memory index publication writes each source header separately even when the same publication already batches its chunk, recall, and provenance rows.
User Impact
Multi-source indexing performs fewer SQL statements. Stored content, search results, rollback, tombstones, revision publication, and the worker request contract stay unchanged. No migration or configuration change is required; latency improvement is not claimed.
Why This Change Was Made
Batch source headers at the existing
MemorySourceIndexKernel.replaceGroupowner and remove the per-source UPSERT. Each statement carries at most 128 distinct(path, source)keys and an estimated 64 KiB of UTF-8 header data. Deduplicate pending keys so the final header wins and PostgreSQL never updates the same conflict key twice in one statement. A single oversized header retains its existing single-row behavior.The existing transaction, source checks, chunk/vector ordering, and mutable vector-rebuild reads remain authoritative. No cache, generation, schema, extra request, or additional main-thread work is introduced. Production changes are +49/-19 lines (net +30): the bounded, deduplicated batch replaces the scalar writer. Tests are +122/-70 lines, primarily extending existing fixtures.
Evidence
Acceptance was published in d86e145 before new measurements. The committed acceptance and workload instructions are in
scripts/perf/memory-source-header-batching.md.All 33 SQLite owner tests pass, covering stored/searchable rows, vectors, ordering, rollback, duplicate keys, and byte bounds. The corrected baseline fails the 100/129-source assertions with actual counts 100/129 versus expected 1/2; the one-source case passes. An initial enlarged fixture exceeded the allowed importance value; those setup failures were discarded and the corrected fixture was rerun on both revisions. Other chunk/recall/provenance insert counts remain unchanged.
Two retained synthetic Gateway runs each recorded three header UPSERTs inside one
source.replace.grouprequest and zero target MAIN SQL. The later run used 3f7b776; the kernel, worker, PostgreSQL adapter, and transfer modules are byte-identical at production base 90d9772. This is source-attributed baseline evidence under the campaign's busy-host exception: the new baseline build was canceled before execution with load above 80 and six jobs queued ahead. No fresh-head Gateway A/B, latency, CPU, p95, or whole-workload saving is claimed. The frozen observer's retired causal labels are not used; attribution uses phase/request identity.PostgreSQL review approved head
64b57f9e221c; both native PostgreSQL owner/publication suites now pass (22 tests), satisfying that review condition. The temporary PostgreSQL server stopped cleanly. Basic lint, formatting, and diff checks pass. Exact-head CI run 40136165351 has 36 successful jobs, including production/test types, lint, source contracts, architecture/ratchets, and PostgreSQL shards 1 and 3. Shard 2 fails seven untouched onboarding/setup cases because their synthetic runtime lacksstandalone-runtime-profile.mjs. The same fixture regression was introduced on main by #182856 (4a38dbdb6b1) and is being repaired separately. A focused current-main baseline at0f6631638b2e3b6dd5fcbc1ad94a46ed4fe5ae47independently reproduced the same seven failures (one other case passed). Failure evidence: run 40136165351, job 120998363809, with aggregate gate job 121002882499. No all-green CI claim is made. Local type-aware preflight rejects the required out-of-checkout dependency store; no containment guard was bypassed. Local check:changed completed: its runnable guards and 10 contract tests passed; only the two typecheck lanes and type-aware lint refused the required out-of-checkout dependency declarations. Their exact-head CI counterparts passed. Madge reports zero cycles. Canonical Knip baseline/candidate scans match exactly: 69 production, 81 full-tree, and 1,136 script findings; no new findings in any scan. Both allowed independent Codex reviews found no actionable findings.Final open-PR conflict census: 2,680 other open PRs targeting main, 47 changed/new heads refreshed. The only overlap is #180741 (
aee9834743b7) in the shared publication test helper. Against main219e9181aab0, base-only and base-plus-candidate merge-tree comparisons both have zero conflicts. The patch adds no merge conflicts. None of the four changed owner/test modules changed on main since the production base.