Skip to content

refactor(memory): own temporary connections in the reindex context - #138145

Merged
steipete merged 1 commit into
mainfrom
codex/db-prep-memory-shadow
Sep 4, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/db-prep-memory-shadow

Conversation

@steipete

@steipete steipete commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor
Additional instructions

Keep Allow edits from maintainers enabled for this PR.

What Problem This Solves

Forced memory rebuilds create a temporary SQLite index before publishing it into the agent database. Managing that connection across separate success, error, and cleanup branches makes the rebuild lifecycle harder to maintain.

Why This Change Was Made

The existing reindex database context now closes its temporary connection before returning to the publisher. This removes the orchestration's separate temporary-handle and closed-state bookkeeping while retaining the callback's original escaped-continuation fence, publication revision checks, workspace and generation leases, and final temporary-file cleanup.

User Impact

There is no intended user-visible change. Memory search keeps using the published index during a rebuild; failed rebuilds leave that index intact. This is a bounded preparation refactor with no database schema, configuration, or public API changes.

Evidence

  • Four focused native SQLite suites passed: 74 tests, covering failed rebuild recovery, stale publication, concurrent search generations, vector publication, and session-purge races.
  • The changed gate passed, including extension production/test typechecks, typed lint, five doctor-contract tests, dead-export checks, and zero runtime import cycles.
  • The selected memory-core runtime build passed in 45.3 seconds, including CLI bootstrap validation and native loading of the built plugin control-plane module. No ineffective dynamic import warning was reported.
  • Fresh independent P2 review was scoped-clean.
  • Production delta is +17/-20 (net -3); no tests or schemas changed.

Focused command:

OPENCLAW_VITEST_MAX_WORKERS=2 node scripts/run-vitest.mjs extensions/memory-core/src/memory/manager.reindex-recovery.test.ts extensions/memory-core/src/memory/manager-db.test.ts extensions/memory-core/src/memory/manager-search-orchestration.test.ts extensions/memory-core/src/memory/manager-session-update-race.test.ts

Changed gate:

OPENCLAW_VITEST_MAX_WORKERS=2 node scripts/check-changed.mjs -- extensions/memory-core/src/memory/manager-database-context.ts extensions/memory-core/src/memory/manager-sync-ops.ts

Live native validation passed on commit 5dc28ac064c142da809cb105272815d3a29c268d: two real memory index --force rebuilds, search before/after corpus replacement, two isolated Gateway starts/stops, preserved unrelated transcript, zero leftover shadow files, and SQLite integrity/foreign-key checks. The materialized source tree 36264b0d2812dd0845f81dfe6e7fe12116145cc1 matched before and after building and running. Failed publication and stale-generation behavior are covered by the focused SQLite suites above.

ClawSweeper's data-model compatibility request is addressed by source comparison: no schema, migration, table definition, row codec, vector/embedding metadata representation, or publication SQL changed. The existing schema and publisher are byte-identical to the base; the live flow opened and reused the same agent database (schema 19) and preserved unrelated canonical state. A migration or new data-model approval is therefore not applicable to this lifetime-only change.

Validation environment: a queued Testbox was stopped without running code; the same actual native flow ran locally in isolated synthetic state. macOS system Bash was used after the installed Homebrew Bash stalled in here-document setup. Follow-up: investigate that local Bash tooling issue separately.

@clawsweeper

clawsweeper Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@steipete
steipete marked this pull request as ready for review September 4, 2026 09:43
@openclaw-barnacle openclaw-barnacle Bot added extensions: memory-core Extension: memory-core size: XS maintainer Maintainer-authored PR labels Sep 4, 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 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 4, 2026, 5:52 AM ET / 09:52 UTC.

ClawSweeper review

What this changes

The PR moves temporary Memory Core reindex SQLite connection cleanup into the reindex context and removes duplicate close-state tracking from synchronization.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep open for normal maintainer handling. The refactor preserves the required close-before-publish ordering and failure cleanup while removing duplicated temporary-handle bookkeeping; current main still uses the older orchestration-owned lifetime.

Priority: P3
Reviewed head: 5dc28ac064c142da809cb105272815d3a29c268d

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused net-negative refactor that preserves the caller-to-publisher lifecycle boundary with no actionable correctness finding.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-owned, behavior-neutral SQLite lifecycle refactor is outside the external-contributor proof gate; the PR body records focused native SQLite validation as supplemental evidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-owned, behavior-neutral SQLite lifecycle refactor is outside the external-contributor proof gate; the PR body records focused native SQLite validation as supplemental evidence.
Evidence reviewed 5 items Introduced lifetime owner: The PR-head context awaits all rebuild work, closes the temporary connection before returning, and retains a guarded finally cleanup attempt.
Caller and publisher ordering: The sole caller awaits the reindex context before acquiring publication leases and attaching the temporary file, so the close completes before publishing; outer temporary-file removal remains in its finalizer.
Close contract: The shared close helper removes read-only tracking where applicable, otherwise performs WAL maintenance and closes the DatabaseSync handle; the shadow is a writable temporary database.
Findings None None.
Security None None.

How this fits together

Memory Core builds a temporary SQLite index during a forced rebuild while the published index continues serving searches. The temporary writer must close before its database file is attached and copied into the published agent database.

flowchart LR
  A[Forced memory rebuild] --> B[Temporary SQLite index]
  B --> C[Reindex context]
  C --> D[Close temporary writer]
  D --> E[Publish index tables]
  E --> F[Published memory search]
  C --> G[Failure cleanup]
Loading

Before merge

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

Security

None.

PR surface

Source -3. Total -3 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 2 17 20 -3
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 17 20 -3

Review metrics

Metric Value Why it matters
Production versus test delta production -3 net (17 added, 20 removed); tests unchanged The ownership consolidation is net-negative production cleanup and does not add test-only seams.

Stored data model

Persistent data-model change detected: unknown-data-model-change: extensions/memory-core/src/memory/manager-sync-ops.ts, vector/embedding metadata: extensions/memory-core/src/memory/manager-database-context.ts, vector/embedding metadata: extensions/memory-core/src/memory/manager-sync-ops.ts. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best possible solution:

Keep the temporary connection lifecycle inside the reindex context, with close completion before publication and a single failure cleanup owner.

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

Not applicable: this PR is a behavior-preserving ownership refactor, and existing integration coverage exercises the relevant rebuild/search ordering.

Is this the best way to solve the issue?

Yes. Moving close responsibility to the reindex context gives the temporary writer one lifetime owner while preserving the caller's publication and file-cleanup responsibilities.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 6d228342bdf5.

Labels

Label changes:

  • add P3: This is a small internal lifecycle refactor with no intended user-visible or compatibility change.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-owned, behavior-neutral SQLite lifecycle refactor is outside the external-contributor proof gate; the PR body records focused native SQLite validation as supplemental evidence.

Label justifications:

  • P3: This is a small internal lifecycle refactor with no intended user-visible or compatibility change.
  • 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: This maintainer-owned, behavior-neutral SQLite lifecycle refactor is outside the external-contributor proof gate; the PR body records focused native SQLite validation as supplemental evidence.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • JC: 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.

@steipete
steipete merged commit 984f493 into main Sep 4, 2026
156 of 165 checks passed
@steipete
steipete deleted the codex/db-prep-memory-shadow branch September 4, 2026 10:27
@steipete

steipete commented Sep 4, 2026

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: XS 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