Skip to content

fix(database): rebuild memory indexes before agent ports return - #182008

Merged
steipete merged 1 commit into
mainfrom
fix/pgportmem-rebuild
Oct 23, 2026
Merged

steipete merged 1 commit into
mainfrom
fix/pgportmem-rebuild

Conversation

@steipete

@steipete steipete commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes #181859. Porting an agent store discarded its embedding cache and left the memory index empty, so the first search rebuilt the corpus and repeated embedding calls. Thanks @etzelm for the report.

User Impact

Agent-family ports preserve cached embeddings and rebuild memory before returning, while the Gateway remains stopped. Text output and --json report each agent's result. A failed rebuild warns with openclaw memory index --agent <id> and leaves the published port successful. Unchanged cached chunks need no embedding calls; new or uncached content retains normal indexing behavior.

Why This Change Was Made

The existing docs explicitly reserved this post-port hook. The port now retains the cache's provider/model/provider_key/hash identities and binary payload, then releases port custody before acquiring a fresh configured memory.cli owner. The selected memory plugin owns indexing. Fresh config loading avoids the pre-port runtime snapshot, and per-agent secret resolution prevents an unavailable peer credential from blocking healthy agents. Retained stores outside active configuration receive recovery guidance rather than opening a different store.

No new CLI options, configuration, SDK contract, schema, or Gateway-startup rebuild is introduced. Both pending-hook documentation passages are updated.

Evidence

Baseline pin: ddbf65c9215087e7e1d10164021d8bcad7514cad, including #181860 and #181957. The local deterministic provider uses no paid API. The fixture contains 4,857 chunks (1,000 memory / 3,857 sessions), 60 sources and a full 1,536-dimensional embedding cache.

On main, the first PostgreSQL search took 23.778s and embedded 4,857 corpus chunks plus its query; the next search took 3.634s and embedded only its query. Both port directions dropped the cache; rebuilding reproduced identical cache identities and bytes. A cached full PostgreSQL rebuild still took 20.158s with zero embedding calls and 4,001 top-level statements / 12.984s server execution. This does not reproduce or partition the reporter's historical 1,376.9s latency.

The cache round-trip regression is red under main's omission policy and green with this fix. All 15 focused command tests, source and touched-test TSRS checks, lint, the native line-cap guard, docs sanity, and independent P0–P3 review pass. Tests cover fresh post-port ownership/configuration, custody through close, isolated rebuild/close/dirty-state failures, retained-path selection and per-agent SecretRefs.

Clean-tree real CLI replay passes the pre-registered acceptance rule on cf88eb38a3637f2af4198ae8d1c52ddb96ec6d7c:

Local command Main Candidate Corpus embedding inputs, main → candidate
SQLite → PostgreSQL port 20.963s 35.039s 0 → 0
First PostgreSQL search 23.778s 3.932s 4,857 → 0
Warm PostgreSQL search 3.634s 3.654s 0 → 0

Searches additionally embed one query. The candidate port reports a 17.171s automatic rebuild, 60 files / 4,857 chunks, and preserves the exact cache digest. PostgreSQL → SQLite also rebuilds before returning (18.908s, zero embedding calls); its first search is 4.496s versus 4.067s warm, with no corpus embeddings. Unchanged manual indexing makes zero provider calls on both engines. SQLite → SQLite remains a no-op. The longer port deliberately pays rebuild cost while offline instead of delaying first recall.

All three PostgreSQL conformance shards actually ran and passed on cf88eb38a3637f2af4198ae8d1c52ddb96ec6d7c: 1,143 tests passed, 37 existing skips, with 163 files passed and 3 skipped. Exact-head CI is green; no CI exception or rerun was needed. Both GitHub Codex review and ClawSweeper found no actionable defects. The requested Testbox allocation queued and was stopped under the campaign policy (allocation); no remote timing result is claimed.

The frozen general warm-turn controls were attempted unchanged (63/63 hashes verified), but both baselines failed before any turns: SQLite rejected the retired heartbeat fixture setting; PostgreSQL rejected main-thread connection admission. No R/T/S or C64 numbers are claimed from failed setup.

Preserve reusable embedding-cache rows across engine ports and run the selected memory owner after port custody releases. Keep published ports successful when rebuilding fails, with per-agent retry guidance.

Fixes #181859. Thanks to @etzelm for the report.
@clawsweeper

clawsweeper Bot commented Oct 23, 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 docs Improvements or additions to documentation gateway Gateway runtime cli CLI command changes commands Command implementations size: L labels Oct 23, 2026
@steipete
steipete marked this pull request as ready for review October 23, 2026 23:20
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 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-23T23:22:34.507073Z cf88eb3 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:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 23, 2026
@clawsweeper

clawsweeper Bot commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Preserve embedding caches across agent database ports and rebuild memory indexes before the command returns.

Example: Port an agent with 4,857 cached chunks from SQLite to PostgreSQL.

  • Before: The reported first search rebuilt 4,857 corpus embeddings and took 23.778 seconds.
  • After: The reported port rebuilds offline without corpus embedding calls, and the first search takes 3.932 seconds.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A useful, focused integration with reported real CLI coverage, unchanged cache format, and no identified introduced defect; required PostgreSQL CI is still running.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The exact-head PR evidence reports real database-port CLI runs in both directions, automatic selected-owner rebuilding, subsequent searches without corpus embedding calls, matching cache digests, and a same-engine no-op; these supplied results were inspected rather than independently rerun.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Feature · Worth it: Yes · Fix scope: Complete
User problem: After an agent database port, first recall must rebuild memory and may repeat costly corpus embedding calls.
Reason: The deferred integration has a concrete reported cost, and the maintainer-authored PR settles automatic offline rebuilding without adding configuration.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR addresses a demonstrated post-port recall delay through existing owners, and I found no actionable introduced defect.

Priority: P2
Reviewed head: cf88eb38a3637f2af4198ae8d1c52ddb96ec6d7c

Before merge

None.

Findings

None.

Agent review details

How this fits together

The offline database-port command publishes converted stores, releases port custody, then invokes the selected memory plugin under fresh configured ownership and returns per-agent results.

flowchart TD
  A[Database port CLI] --> B[Convert and publish stores]
  B --> C[Release port custody]
  C --> D[Acquire configured memory owner]
  D --> E[Selected memory plugin rebuilds]
  E --> F[Per-agent results and retry guidance]
Loading

Technical review

Best possible solution:

Preserve cached embeddings and complete the deferred offline rebuild through the selected memory owner, with nonfatal per-agent recovery guidance.

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

Current-main projection policy establishes cache omission and empty indexes; the reporter and PR provide real CLI observations, while this read-only review ran no target code.

Is this the best way to solve the issue?

The change completes the documented pending hook using existing publication, custody, credential, and plugin owners without introducing a competing indexing implementation.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 335c0ccf04e6.

Provenance checked

  • Agent-port memory projection omission changes intended behavior with a stated reason (835dc1e: The original port deliberately omitted rebuildable memory projections and reserved rebuilding for the memory owner's future entry point.)
  • Port completion and CLI reporting keeps the original intent (ddd9e83: The offline port publishes and verifies stores before returning completion; the new nonfatal hook preserves that publication outcome after custody releases.)
  • PostgreSQL operator guidance changes intended behavior with a stated reason (1e78ee6: The guide documented manual indexing because automatic rebuilding was pending; both changed passages now describe the implemented hook.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 835dc1e adds src/infra/database-engine/agent-port-projections.ts:12 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 835dc1e854be; files: src/infra/database-engine/agent-port-projections.ts)

PR surface

Source +194, Tests +300, Docs +9. Total +503 across 8 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 4 205 11 +194
Tests 2 300 0 +300
Docs 2 18 9 +9
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 523 20 +503

Review metrics

Metric Value Why it matters
Production versus regression coverage Production +205/-11 lines; tests +300/-0 lines The production growth integrates fresh ownership and per-agent outcomes; the tests cover distinct lifecycle, failure, credential, selection, and persistence boundaries.

Labels

Label changes:

  • add P2: This improves an advanced offline database-port workflow with a manual workaround and potentially substantial first-recall delays.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit 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 improves an advanced offline database-port workflow with a manual workaround and potentially substantial first-recall delays.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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 23, 2026, 7:36 PM ET / 23:36 UTC.

@steipete
steipete merged commit 215cb73 into main Oct 23, 2026
235 of 240 checks passed
@steipete
steipete deleted the fix/pgportmem-rebuild branch October 23, 2026 23:44
@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

cli CLI command changes commands Command implementations docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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.

[Feature]: rebuild memory indexes as part of the agent database port

1 participant