Skip to content

perf(memory): batch source headers during publication - #182935

Merged
steipete merged 2 commits into
mainfrom
dbasync/nplus1b
Oct 24, 2026
Merged

steipete merged 2 commits into
mainfrom
dbasync/nplus1b

Conversation

@steipete

@steipete steipete commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

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.replaceGroup owner 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.

Sources per publication Baseline header UPSERTs Candidate header UPSERTs
1 1 1
100 100 1
129 129 2
Large UTF-8 headers with a repeated final key 3 2

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.group request 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 lacks standalone-runtime-profile.mjs. The same fixture regression was introduced on main by #182856 (4a38dbdb6b1) and is being repaired separately. A focused current-main baseline at 0f6631638b2e3b6dd5fcbc1ad94a46ed4fe5ae47 independently 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 main 219e9181aab0, 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.

@clawsweeper

clawsweeper Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts size: S labels Oct 24, 2026
@steipete steipete changed the title perf(memory): batch source headers within publication groups improve: batch memory source headers during publication Oct 24, 2026
@steipete
steipete marked this pull request as ready for review October 24, 2026 21:53
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-24T21:54:49.560978Z 64b57f9 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Oct 24, 2026
@clawsweeper

clawsweeper Bot commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR batches memory source-header upserts within the existing publication kernel.

Example: Publish 100 distinct memory sources in one group.

  • Before: The kernel issues 100 source-header upserts.
  • After: The kernel issues one source-header upsert while preserving the stored headers.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused implementation appears correct and preserves the existing storage contract, but supplied shipped-entry-point evidence does not exercise the candidate.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Multi-source memory indexing performs avoidable database statements for source headers.
Reason: The maintainer-authored direction removes deterministic database work with a focused change at the established shared owner and makes no unsupported latency claim.

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
Reviewed head: 64b57f9e221cf0e5da3505ee106a1f7d78c93811

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Candidate Gateway publication evidence is missing; the reported baseline-red/candidate-green owner tests establish statement batching but do not exercise the shipped Gateway flow.
Agent review details

How this fits together

Memory 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
Loading

Technical review

Best 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

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 3aaea79 adds extensions/memory-core/src/memory/manager-source-index-kernel.ts:172 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 3aaea79dde30; files: extensions/memory-core/src/memory/manager-source-index-kernel.ts)

PR surface

Source +30, Tests +52, Docs +97. Total +179 across 5 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 49 19 +30
Tests 3 122 70 +52
Docs 1 97 0 +97
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 268 89 +179

Review metrics

Metric Value Why it matters
Production versus test changes Production +49/-19; tests +122/-70 The production growth implements the bounded header buffer; tests extend existing storage and publication fixtures rather than introducing another harness.

Labels

Label changes:

  • add P2: This reduces repeated database work during multi-source memory publication without an established urgent user-facing failure.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: This reduces repeated database work during multi-source memory publication without an established urgent user-facing failure.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Supply candidate Gateway publication evidence matching the committed acceptance rule.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 24, 2026, 6:13 PM ET / 22:13 UTC.

@steipete steipete changed the title improve: batch memory source headers during publication perf(memory): batch source headers during publication Oct 24, 2026
@steipete
steipete merged commit a2fbd03 into main Oct 24, 2026
235 of 244 checks passed
@steipete
steipete deleted the dbasync/nplus1b branch October 24, 2026 23:02
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 25, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. scripts Repository scripts size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant