Skip to content

fix(memory): avoid rereading indexed chunks during provenance checks - #146494

Merged
steipete merged 2 commits into
mainfrom
codex/swarm-memory-provenance
Sep 12, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/swarm-memory-provenance

Conversation

@steipete

@steipete steipete commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

TLS prerequisite: #146412 (landed on main).

Related: #130741

What Problem This Solves

Reopening a populated memory index rereads chunk payloads while ensuring provenance, even when every chunk already has provenance.

User Impact

Repeated memory index opens do less SQLite work. Existing provenance, source invalidation, and rollback behavior remain intact; no schema migration or configuration change is required.

Why This Change Was Made

Find missing provenance through the existing key indexes before reading chunk payloads, and backfill only those missing rows. This keeps the existing transaction and source-matching semantics. The first backfill of an entirely legacy index does more VM work; subsequent ensures benefit from the smaller query.

Evidence

  • 52 focused tests passed across provenance, memory schema, legacy migration, agent schema, and memory index publication.
  • A fixed native SQLite comparison with 20,000 chunks, 1,000 sources, and 4 KiB chunk payloads reduced complete-provenance work from 1,432,030 to 332,059 VM steps and page-cache misses from 25,399 to 223. Sparse and entirely legacy backfills preserved the checked row and revision results. These are query measurements, not end-to-end Swarm latency claims.
  • The full canonical two-file gate passed on eab7e706645cd39065c56a9e961851f5259bb899, including core and test types, lint, all three dead-export scans, and runtime guards. Independent isolated P1 review completed with no actionable findings.

@clawsweeper

clawsweeper Bot commented Sep 12, 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 gateway Gateway runtime size: S maintainer Maintainer-authored PR labels Sep 12, 2026
@steipete
steipete marked this pull request as ready for review September 12, 2026 21:28
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 12, 2026
@clawsweeper

clawsweeper Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 12, 2026, 5:53 PM ET / 21:53 UTC (Revision 2).

ClawSweeper review

What this changes

The branch limits memory provenance backfills to chunks missing metadata, adds compatibility coverage, and includes the separately landed TLS shutdown registration correction.

Warning

SQLite table change

This PR modifies persisted SQLite tables in packages/memory-host-sdk/src/host/memory-schema-provenance.ts. Prefer a design that avoids changing persisted SQLite tables. If the change is necessary, verify migration and upgrade compatibility against an existing database before merge.

Merge readiness

⛔ Blocked before merge - 1 item remains

The optimization remains useful and has no identified blocking defect. The previous migration-proof blocker is unwarranted: this preserves the existing storage contract and fits the documented query-plan maintenance exception.

Priority: P2
Reviewed head: eab7e706645cd39065c56a9e961851f5259bb899

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused optimization with useful compatibility coverage and appropriately bounded performance claims; no blocking defect was found.
Proof confidence 🌊 off-meta tidepool Not applicable: The maintainer-authored PR is exempt from the external-contributor proof gate; its reported native SQLite comparison targets the changed provenance queries, while focused tests support semantic preservation.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The maintainer-authored PR is exempt from the external-contributor proof gate; its reported native SQLite comparison targets the changed provenance queries, while focused tests support semantic preservation.
Evidence reviewed 7 items Storage semantics preserved: The complete production owner retains its table definition, conservative untrusted/unknown values, source matching, existing-row preservation, and transaction boundary. Only missing-row selection and payload lookup change.
Compatibility coverage: The added tests check source tables without an ID, WITHOUT ROWID tables, shadowed rowid columns, NULL source matching, chunk-side collation, retained provenance, idempotence, and failure rollback with and without a caller transaction. Existing schema tests also exercise legacy imports through ensureMemoryIndexSchema. Tests were inspected, not executed during this read-only review.
Prior blocker reassessed: The storage checkpoint explicitly exempts bounded query-plan improvements without material write/disk tradeoffs. No persisted representation, schema version, migration outcome, or transaction ownership changes here; the earlier generic migration-proof request does not establish a remaining blocker.
Findings None None.
Security None None.

How this fits together

OpenClaw checks memory chunk provenance when opening or publishing its local search index. This check invalidates affected source hashes and supplies conservative metadata for legacy chunks before subsequent indexing and recall.

flowchart TD
  A[Open or publish memory index] --> B[Compare chunk and provenance keys]
  B --> C{Missing metadata?}
  C -->|No| D[Preserve existing rows]
  C -->|Yes| E[Read affected chunk metadata]
  E --> F[Invalidate matching source hashes]
  F --> G[Insert conservative provenance]
  D --> H[Continue memory processing]
  G --> H
Loading

Before merge

  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +16, Tests +139. Total +155 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 2 24 8 +16
Tests 1 139 0 +139
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 163 8 +155

Review metrics

Metric Value Why it matters
Reported complete-index query work VM steps: 1,432,030 → 332,059; cache misses: 25,399 → 223 The fixed SQLite comparison supports less work on repeat checks without implying a universal application speedup.

Stored data model

Persistent data-model change detected: unknown-data-model-change: packages/memory-host-sdk/src/host/memory-schema-provenance.ts, vector/embedding metadata: packages/memory-host-sdk/src/host/memory-schema-provenance.ts. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best possible solution:

Keep provenance repair with the existing memory schema owner, using indexed missing-row selection while preserving stored values and rollback behavior.

Do we have a high-confidence way to reproduce the issue?

Yes, at source level: populated-index initialization reaches the existing provenance owner, whose main-branch insertion reads every chunk even when provenance is complete. No runtime reproduction was executed in this read-only review.

Is this the best way to solve the issue?

Yes. The patch optimizes the existing owner without adding a cache, schema, API, or alternate repair path, and its compatibility tests protect the semantics most exposed by the SQL rewrite.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 5270db64d8d0.

Labels

Label justifications:

  • P2: This is a bounded memory-index performance improvement without evidence of an urgent user-facing outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The maintainer-authored PR is exempt from the external-contributor proof gate; its reported native SQLite comparison targets the changed provenance queries, while focused tests support semantic preservation.

Evidence

What I checked:

  • Storage semantics preserved: The complete production owner retains its table definition, conservative untrusted/unknown values, source matching, existing-row preservation, and transaction boundary. Only missing-row selection and payload lookup change. (packages/memory-host-sdk/src/host/memory-schema-provenance.ts:18, eab7e706645c)
  • Compatibility coverage: The added tests check source tables without an ID, WITHOUT ROWID tables, shadowed rowid columns, NULL source matching, chunk-side collation, retained provenance, idempotence, and failure rollback with and without a caller transaction. Existing schema tests also exercise legacy imports through ensureMemoryIndexSchema. Tests were inspected, not executed during this read-only review. (packages/memory-host-sdk/src/host/memory-schema-provenance.test.ts:32, eab7e706645c)
  • Prior blocker reassessed: The storage checkpoint explicitly exempts bounded query-plan improvements without material write/disk tradeoffs. No persisted representation, schema version, migration outcome, or transaction ownership changes here; the earlier generic migration-proof request does not establish a remaining blocker. Public docs: docs/reference/database-schemas/storage-changes.md. (docs/reference/database-schemas/storage-changes.md:228, eab7e706645c)
  • Still needed on main and latest release: Inspected fetched main and v2026.9.4: both still select every chunk for INSERT OR IGNORE and retain the original correlated invalidation query. Neither contains this missing-ID optimization. (packages/memory-host-sdk/src/host/memory-schema-provenance.ts:25, 5270db64d8d0)
  • Verified merge scope: Raw test-merge parents match the pinned base followed by the exact PR head. Its base-relative result changes only the memory implementation and tests. The TLS correction is already covered by merged fix(gateway): register TLS renewal with sidecar owner #146412 and introduces no additional merge delta. (84e49c12318e)
  • Reported validation and measurement scope: The captured PR body reports 52 focused passing tests and exact-head validation. Its native SQLite comparison uses 20,000 chunks, 1,000 sources, and 4 KiB payloads: complete-provenance VM steps fall from 1,432,030 to 332,059 and cache misses from 25,399 to 223. Sparse and legacy cases reportedly preserve checked rows and revisions; entirely legacy backfill costs more VM work. These are query measurements, not end-to-end latency proof. Related Swarm media was not used to substantiate this optimization. (eab7e706645c)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-09-12T21:37:05.293Z sha eab7e70 :: blocked before merge. :: none

@steipete
steipete merged commit 9717a76 into main Sep 12, 2026
220 checks passed
@steipete
steipete deleted the codex/swarm-memory-provenance branch September 12, 2026 22:34
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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