Skip to content

refactor(memory): own source indexing on its database - #145207

Merged
steipete merged 2 commits into
mainfrom
codex/memory-source-index-kernel
Sep 11, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/memory-source-index-kernel

Conversation

@steipete

@steipete steipete commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

One memory source update currently spreads its SQL across embedding and synchronization code. That makes it difficult to move database execution while preserving the complete chunk, source, recall, provenance, FTS, and vector mutation.

Why This Change Was Made

Give the existing memory database owner a connection-bound source-index kernel for complete replacement and conditional deletion. Ordinary source writes use Kysely, existing prepared chunk writers remain shared, and FTS insertion is prepared once per nonempty file. The native tombstone reader and its unchanged schema guard now live apart from database-opening code.

The existing admission loop still validates filesystem content after every failed BEGIN attempt. Session writes consult the explicit canonical authority connection while updating a shadow. Native transaction callbacks, retry marking, vector rebuild markers, and cleanup behavior remain intact.

User Impact

Memory indexing keeps its current SQLite data and publication behavior, with fewer FTS statement preparations for multi-chunk files. This prepares a complete native operation for the future shared database worker owner; physical execution remains on the current owner.

Evidence

  • Manager, source-race, session-forget, origins, reindex recovery, and native kernel tests passed: 84 initial cases, the added real SQLite contention case, and final affected/native reruns.
  • Native rollback proof covers all index representations after a late source upsert failure. Conditional deletion preserves siblings, and canonical tombstones refuse shadow writes before mutation.
  • A real manager retry after a SQLite BEGIN collision revalidates changed filesystem content before indexing it.
  • A standalone writer performed 20 ten-chunk source replacements; a fresh process reopened exact source, chunk, recall, provenance, FTS, and vector data and passed integrity checks.
  • Full node scripts/check-changed.mjs, git diff --check, and fresh isolated Codex review through P2 passed.

Measured on the loaded local host: 20 synthetic ten-chunk replacements had a 7.01 ms median and 13.48 ms p95. These describe the candidate workload; they are not a before/after speedup claim.

CI on the original feature head exposed Vitest 5's eager deep-equality diagnostics in expect(replacement).not.toBe(first): the diagnostic traversal inspected the revoked native handle. The assertion now uses the adjacent strict boolean-identity pattern. Its original shared-handle, old-release, replacement sync, and search assertions remain intact. The complete borrowed-connection file and native/publication/reindex/search owners passed all 60 tests; the full repaired candidate gate and fresh P2 review passed.

Both commits were rebased onto 21b105c0f33f567e433ab700c8e3e00404d5db32, which includes the upstream CI fixture repair and awaited memory lease cleanup. The authored patch and all 12 file hashes are unchanged by that rebase.

On the rebased candidate, all 43 coupling tests passed across borrowed connections, native source mutations, generation admission/release, cancellation, and manager teardown.

Storage compatibility: the memory_session_tombstones DDL literal is byte-identical between pre-change 3ac42154d14a98ab2393e68bb3285df77c512b14 and this candidate. A synthetic database created from that prior definition, closed, and reopened with the candidate helper preserved its existing row and schema, retained agent-scoped tombstone lookup, and passed SQLite integrity checking. This verifies the relocated table contract; the refactor introduces no migration.

@clawsweeper

clawsweeper Bot commented Sep 11, 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 extensions: memory-core Extension: memory-core size: L maintainer Maintainer-authored PR labels Sep 11, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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 11, 2026
@clawsweeper

clawsweeper Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 11, 2026, 5:50 PM ET / 21:50 UTC (Revision 4).

ClawSweeper review

What this changes

Memory Core moves source replacement and deletion into its database owner, reuses full-text insertion statements per file, and adds rollback, contention, and isolation coverage.

Warning

SQLite table change

This PR modifies persisted SQLite tables in extensions/memory-core/src/memory-entry-origins.ts, extensions/memory-core/src/memory-session-tombstones.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

No blocking findings. The updated compatibility evidence resolves the previous review’s blocker, and current main still lacks this distinct refactor. This maintainer-owned PR remains a valid landing candidate.

Priority: P3
Reviewed head: 39fcb38255dae8275c98bf633783adba18e5fecc

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, maintainable extraction with meaningful preservation coverage and no remaining blocking findings.
Proof confidence 🌊 off-meta tidepool Not applicable: The maintainer-author exemption applies. The body additionally reports native source replacement/readback, contention recovery, and prior-schema reopen checks matching the changed database owner; this review verified source preservation without rerunning those scenarios.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The maintainer-author exemption applies. The body additionally reports native source replacement/readback, contention recovery, and prior-schema reopen checks matching the changed database owner; this review verified source preservation without rerunning those scenarios.
Evidence reviewed 9 items Pinned implementation and preserved transaction boundary: The introduced diff delegates replacement and conditional deletion to the connection-bound kernel while retaining filesystem validation, transaction admission, retry marking, canonical tombstone selection, and vector rebuild behavior.
Unchanged tombstone storage contract: The relocated CREATE TABLE literal matches the inspected prior definition, including primary key, columns, and STRICT mode. Agent-scoped lookup and first-use creation remain unchanged; no migration or new persisted representation is introduced.
Prior schema definition: The pre-change source already creates the same memory_session_tombstones table before recording tombstones.
Findings None None.
Security None None.

How this fits together

Memory Core turns workspace files and session transcripts into searchable SQLite indexes. Its database owner coordinates source records, text chunks, metadata, full-text search, and vectors while keeping rebuilt indexes separate until publication.

flowchart TD
  A[Memory files and session transcripts] --> B[Prepare chunks and embeddings]
  B --> C[Validate source and admit transaction]
  D[Canonical session tombstones] --> E[Database-owned source operation]
  C --> E
  E --> F[Source records and search indexes]
  F --> G[Memory search]
Loading

Before merge

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

Security

None.

PR surface

Source +114, Tests +235. Total +349 across 12 files.

View PR surface stats
Area Files Added Removed Net
Source 8 278 164 +114
Tests 4 240 5 +235
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 12 518 169 +349

Review metrics

Metric Value Why it matters
Production versus test growth Production +114 net lines; tests +235 net lines Production growth establishes the connection-bound operation; added tests cover rollback, contention, and isolation.
Full-text statement preparation Per chunk → once per nonempty source replacement The implementation and extended preparation-count test support this bounded reduction without claiming an overall speedup.

Stored data model

Persistent data-model change detected: database schema: extensions/memory-core/src/memory-entry-origins.ts, database schema: extensions/memory-core/src/memory-session-tombstones.ts, unknown-data-model-change: extensions/memory-core/src/memory-entry-origins.ts, unknown-data-model-change: extensions/memory-core/src/memory/manager-embedding-ops.ts, unknown-data-model-change: extensions/memory-core/src/memory/manager-source-index-kernel.ts, unknown-data-model-change: extensions/memory-core/src/memory/manager-source-sync-ops.ts, and 6 more. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best possible solution:

Keep source mutations on the existing database owner with the current storage format, admission loop, and publication safeguards intact.

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

Not applicable: this PR reorganizes existing indexing behavior rather than reporting a new defect; its preservation scenarios are concrete, but were not executed during this read-only review.

Is this the best way to solve the issue?

Yes: the extraction reuses existing writers and database state without adding a parallel implementation, public API, schema, or transaction boundary.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 95a7ec0ac2ed.

Labels

Label justifications:

  • P3: This is a bounded internal refactor and statement-reuse improvement without a demonstrated urgent user-facing defect.
  • 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-author exemption applies. The body additionally reports native source replacement/readback, contention recovery, and prior-schema reopen checks matching the changed database owner; this review verified source preservation without rerunning those scenarios.

Evidence

What I checked:

  • Pinned implementation and preserved transaction boundary: The introduced diff delegates replacement and conditional deletion to the connection-bound kernel while retaining filesystem validation, transaction admission, retry marking, canonical tombstone selection, and vector rebuild behavior. (extensions/memory-core/src/memory/manager-embedding-ops.ts:946, 39fcb38255da)
  • Unchanged tombstone storage contract: The relocated CREATE TABLE literal matches the inspected prior definition, including primary key, columns, and STRICT mode. Agent-scoped lookup and first-use creation remain unchanged; no migration or new persisted representation is introduced. (extensions/memory-core/src/memory-session-tombstones.ts:22, 39fcb38255da)
  • Prior schema definition: The pre-change source already creates the same memory_session_tombstones table before recording tombstones. (extensions/memory-core/src/memory-entry-origins.ts:157, 3ac42154d14a)
  • Previous blocker addressed: The supplied completed review had no findings and requested storage compatibility evidence. The captured updated body reports creating a database from the prior schema, closing and reopening it with the candidate helper, preserving its row and schema, checking agent-scoped lookup, and passing integrity checking. It also reports fresh-process index readback and 43 rebased coupling tests. These are contributor-reported results, not executions performed during this review. (39fcb38255da)
  • Meaningful native regression coverage: Reviewed tests cover rollback across index representations after a late source-upsert failure, stale-hash deletion refusal, sibling preservation, canonical tombstone refusal before shadow mutation, and filesystem revalidation following a real SQLite BEGIN collision. (extensions/memory-core/src/memory/manager-source-index-kernel.test.ts:86, 39fcb38255da)
  • Still distinct from current main and release: Current main retains source upsert and chunk publication inside the embedding manager. Tree inspection found no source-index kernel at fetched main or v2026.9.4; no verified merged replacement was established. (extensions/memory-core/src/memory/manager-embedding-ops.ts:924, 95a7ec0ac2ed)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • jalehman: 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 (3 earlier review cycles)
  • reviewed 2026-09-11T19:35:05.299Z sha 56620af :: blocked before merge. :: none
  • reviewed 2026-09-11T19:43:05.413Z sha 56620af :: blocked before merge. :: none
  • reviewed 2026-09-11T21:39:08.765Z sha 39fcb38 :: blocked before merge. :: none

@steipete
steipete marked this pull request as ready for review September 11, 2026 19:39
@steipete steipete self-assigned this Sep 11, 2026
@steipete
steipete force-pushed the codex/memory-source-index-kernel branch from 56620af to 39fcb38 Compare September 11, 2026 21:32
@steipete

Copy link
Copy Markdown
Contributor Author

Compatibility disposition for the remaining generic stored-data-model checklist: this refactor moves the existing tombstone helper and its byte-identical CREATE TABLE definition; it adds no schema, migration, row encoding, or retention change. Existing transaction admission, canonical tombstone checks, conditional deletion, and rollback remain with their current owners. The PR Evidence section records reopening a database created from the prior DDL, preserving its row/schema and agent isolation, with SQLite integrity intact. The current review also confirms that this evidence resolves the previous compatibility blocker and reports no actionable findings. The stored-data compatibility requirement is satisfied for head 39fcb38.

@steipete
steipete merged commit f7a2f1c into main Sep 11, 2026
98 of 99 checks passed
@steipete
steipete deleted the codex/memory-source-index-kernel branch September 11, 2026 22:19
@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

extensions: memory-core Extension: memory-core maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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