Skip to content

feat(memory): memory search on PostgreSQL - #174242

Merged
steipete merged 3 commits into
mainfrom
pgprep/r7b2-memory-search
Oct 16, 2026
Merged

steipete merged 3 commits into
mainfrom
pgprep/r7b2-memory-search

Conversation

@steipete

@steipete steipete commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Adds the PostgreSQL memory search query path on top of #174085 and #174183, so admitted memory projections can be exercised through the existing search worker before public activation.

User Impact

No public behavior change. PostgreSQL memory search still refuses at public admission; only the internal conformance entry explicitly activates these queries. SQLite search and the shared hybrid merge remain unchanged.

Why This Change Was Made

The memory worker uses the engine's exact pgvector cosine query with model, source, and candidate eligibility before ordering and limit. Text and path queries use native full text or literal trigram predicates, with bounded result payloads and no per-query corpus transfer to JavaScript. Trigram candidates rank by native word similarity before limiting; multi-term queries average their term scores. Hybrid merging retains the default 0.7 vector / 0.3 text weights; PostgreSQL text scores stay engine-local.

A keyword-only store needs no pgvector extension. Missing vector admission raises DATABASE_SEARCH_CAPABILITY_UNAVAILABLE, including a semantic request against a keyword-only store. The remaining public search/status/forget lifecycle activation belongs to the next stage. No agent schema files or dependencies change.

Evidence

  • Six PostgreSQL conformance cases pass on an isolated PostgreSQL 17.11 cluster with pgvector 0.8.7, using in-process, suite-level fixtures: vector/text/hybrid, pre-limit eligibility, trigram, keyword-only and missing-vector refusal, public refusal, restart re-admission and search.
  • Three SQLite capture tests pass: frozen pre-change SHA-256 captures match all four text/path statements, three binary64 fallback statements, and the native vec0 KNN statement. The numerical fixture also distinguishes exact binary64 scoring from float32 rounding.
  • All 36 existing SQLite search/vector/KNN child tests pass. SQLite search implementations and hybrid merging compare byte-identically with the base.
  • Final local conformance execution: 76.15 seconds total, including 57.04 seconds of worker-bundle preparation; each case took 11–70 milliseconds. SQLite capture: 23.82 seconds total / 58 milliseconds test execution. Existing SQLite siblings: 29.00 seconds total / 24.46 seconds reported by Vitest.

No local Docker was used. The test cluster and all data were task-owned and synthetic.

The requested independent review found one P2 trigram-ranking defect. It is fixed with native word-similarity ranking and a competing-candidate regression; the public refusal and SQLite paths remain unchanged. The simplification pass retained one query adapter, without a new persistence owner or compatibility layer.

Local static gates pass: core and memory-package typechecks, targeted production/test/tooling lint, formatting, diff whitespace, database worker inventory (222 → 222 main-thread calls), and database dialect ratchet (no growth). The worker-only PG query adapter is recorded in the existing inventory with its sole runtime caller.

Change size: 985 insertions, 25 deletions, net +960 across 12 files (including 566 new test lines). No agent schema files are touched.

The first CI architecture pass found a type-only cycle between the PostgreSQL helper and worker. Shared query types now live in a leaf module and all consumers import them there; the failed Madge check rerun reports zero cycles, and the package typecheck and targeted lint pass. Query SQL and runtime behavior are unchanged by this correction.

Final-head CI

At fc1398c29f777db4f8e52ab7f96200bc0ce77d26, PostgreSQL conformance passed in 16m29s. The architecture guard, build, typechecks, lint, database ratchets, and changed-extension tests also passed.

The only failed test job is Control UI E2E shard 5/7: Control UI mobile widget scrolling > keeps touch flings continuous through widgets and preserves the reader during streaming measured 115px at release against a >120px assertion. The failed aggregate openclaw/ci-gate is downstream of that single job; there are no cancelled jobs.

Landing uses the operator-authorized native admin exception for this unrelated flake. None of the 12 changed paths are UI or browser-harness files. The failing test installs a mocked Gateway and exercises touch scrolling, widget rendering, and streaming; its execution path is disjoint from the PostgreSQL memory search changes. The public PostgreSQL memory-search refusal remains in place.

Main comparison: scheduled main run 38908699969, at 086990922132bbc68bdc6503b95c81598a655f6b, reports every UI E2E shard successful. The preceding completed main run 38902471699 also passed every UI shard. There is no matching failure on those main runs; this exception relies on the expressly authorized disjoint causal path, not a matching-signature claim. One isolated exact-head macOS replay previously passed. The original Linux failure remains unreproduced, with no threshold edits or CI retries.

Route internal memory search through admitted PostgreSQL vector and text capabilities while preserving the public refusal and SQLite query paths. Rank trigram matches before limiting, and cover worker conformance, restart admission, and SQLite statement compatibility.
@clawsweeper

clawsweeper Bot commented Oct 16, 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 extensions: memory-core Extension: memory-core scripts Repository scripts size: L labels Oct 16, 2026
@steipete
steipete marked this pull request as ready for review October 16, 2026 13:19
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 16, 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-16T13:33:58.137780Z fc1398c New commits
ℹ️ 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: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Oct 16, 2026
@clawsweeper

clawsweeper Bot commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

Adds internal PostgreSQL memory vector, keyword, and path queries while preserving public refusal and SQLite behavior.

Example: An internal conformance query searches PostgreSQL memory for "cafe".

  • Before: The memory search entry rejects the PostgreSQL connection.
  • After: Explicit test activation returns the indexed "café" note; public memory search still rejects PostgreSQL.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The implementation is coherent and has focused conformance coverage, but supplied execution evidence remains at the internal harness boundary.
Proof confidence 🦐 gold shrimp (3/6) The ordinary contributor proof gate does not apply to this maintainer-authored PR; reported PostgreSQL 17.11 conformance exercises the internal adapter, while no public activation is claimed.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Feature · Worth it: Yes · Fix scope: Complete
User problem: PostgreSQL memory projections cannot yet be queried through Memory Core's internal retrieval entry.
Reason: The maintainer-authored direction supplies a useful, explicitly bounded stage of the existing PostgreSQL integration.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep open: this PR supplies a coherent, maintainer-approved stage of PostgreSQL memory support, with no definite introduced defect found; CI remains unresolved.

Priority: P2
Reviewed head: fc1398c29f777db4f8e52ab7f96200bc0ce77d26

Before merge

  • Complete next step - Determine whether the UI scroll assertion failure is caused by this PR or also occurs on its base, without assigning unrelated repair to the author.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied execution evidence covers internal conformance rather than a shipped public search flow, which remains intentionally disabled.
Agent review details

How this fits together

Memory Core sends retrieval requests to its search worker, which uses admitted engine search capabilities and returns bounded ranked chunks for shared result merging.

flowchart TD
A[Memory search caller] --> B[Search worker]
B --> C[Public admission guard]
B --> D[Explicit internal activation]
C --> E[SQLite retrieval]
D --> F[PostgreSQL query adapter]
F --> G[Admitted text and vector indexes]
E --> H[Ranked chunk results]
G --> H
Loading

Technical review

Best possible solution:

Retain the staged engine-backed query adapter and preserve public refusal until the complete search, status, and forget lifecycle is ready.

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

This is staged feature work rather than a bug report; source confirms that current main refuses PostgreSQL memory search.

Is this the best way to solve the issue?

The adapter uses existing engine capabilities and shared query planning without adding a persistence owner or changing SQLite retrieval.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 05bac14d1d45.

Provenance checked

  • Memory worker dispatch and query types keeps the original intent (e14b3dd: Move retrieval off the Gateway thread while retaining existing publication and forgotten-result safeguards; the patch keeps the SQLite helpers and surrounding enrichment.)
  • Keyword fallback dispatch keeps the original intent (4668613: Relax body matching only after body and path searches both return no hits; the PostgreSQL adapter follows the same condition.)
  • PostgreSQL search admission and ranking keeps the original intent (bf46379: Keep native search engine-owned behind explicit admission; the patch adds native contains ranking and preserves admission while making its failure typed.)
  • PostgreSQL namespace qualification keeps the original intent (3c4be0e: Keep independent installations isolated through qualified search objects; word_similarity uses the admitted extension schema.)
  • Public PostgreSQL memory refusal keeps the original intent (163e18f: Defer public activation until retrieval and the remaining lifecycle are enabled together; this PR retains that boundary explicitly.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit bf46379 adds src/infra/database-engine/postgres-search.ts:31 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: bf4637941b40; files: src/infra/database-engine/postgres-search.ts)

PR surface

Source +379, Tests +566, Docs +13, Other +2. Total +960 across 12 files. Added test files: 2.

View PR surface stats
Area Files Added Removed Net
Source 7 403 24 +379
Tests 2 566 0 +566
Docs 1 14 1 +13
Config 0 0 0 0
Generated 0 0 0 0
Other 2 2 0 +2
Total 12 985 25 +960

Review metrics

Metric Value Why it matters
Production versus test LOC Production +403/−24; tests +566/−0 Production growth is concentrated in the PostgreSQL query adapter; tests cover native retrieval, refusal, restart, and SQLite compatibility.

Labels

Label changes:

  • add P2: This is a bounded experimental storage improvement with public activation deliberately deferred.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: This is a bounded experimental storage improvement with public activation deliberately deferred.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

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 16, 2026, 9:45 AM ET / 13:45 UTC.

@steipete
steipete merged commit f3d3c30 into main Oct 16, 2026
156 of 160 checks passed
@steipete
steipete deleted the pgprep/r7b2-memory-search branch October 16, 2026 14:18
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 17, 2026
* feat(memory): add PostgreSQL worker search

Route internal memory search through admitted PostgreSQL vector and text capabilities while preserving the public refusal and SQLite query paths. Rank trigram matches before limiting, and cover worker conformance, restart admission, and SQLite statement compatibility.

* chore(memory): record PostgreSQL search worker ownership

* fix(memory): decouple worker search query types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation extensions: memory-core Extension: memory-core P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: L status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant