Skip to content

feat(database): admitted search extensions for PostgreSQL stores - #174085

Merged
steipete merged 3 commits into
mainfrom
pgprep/r7-memory-pg
Oct 16, 2026
Merged

steipete merged 3 commits into
mainfrom
pgprep/r7-memory-pg

Conversation

@steipete

@steipete steipete commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

PostgreSQL stores can currently bind only the search definitions supplied by their canonical schema. Plugins cannot safely add derived search indexes and retain exact schema validation across restart.

User Impact

Adds an experimental admitted-store API for owner-registered search extensions. This prepares memory's PostgreSQL integration; memory indexing, retrieval, and Doctor import remain separate follow-ups.

Why This Change Was Made

The engine installs each extension in the owning writer transaction, persists its definition with the existing schema metadata, and includes PostgreSQL's deparsed derived objects in the catalog seal. Reopening compares the persisted fingerprint without scratch DDL. Failed installs and outer transaction rollbacks leave no partial indexes or published admission facts.

Changed definitions, including vector dimensions, raise SearchExtensionDefinitionChangedError with guidance to restore the prior definition until the owning component can rebuild the derived index. Canonical binary64 embeddings remain authoritative. SQLite registration issues no SQL and retains its existing FTS5/vec0 mechanics.

Memory registers text and dimension-specific vector definitions through its existing admitted publication worker; the agent opener re-admits the persisted extensions. No agent schema files change. Builds on #173625.

Evidence

  • Local PostgreSQL 17: keyword-only installation, multiple extensions, cold re-admission with no scratch DDL, index drift rejection, failed-install rollback, and outer owner-transaction rollback passed.
  • SQLite: zero-statement registration capture and existing search tests passed.
  • PostgreSQL CI passed all five R7a cases, including exact cosine, independent dimensions, changed-dimension refusal, and source-byte preservation. Local Homebrew PostgreSQL has no pgvector.
  • Local format, core/extension lint and typechecks (including test types), production Knip, worker and dialect ratchets, and SDK surface validation passed. Independent review found no actionable P0–P2 findings.
  • The broad changed-file wrapper also reports existing max-lines suppression failures in three unchanged UI files (chat-message.test.tsx, config-page-state.ts, and sessions-page-state.ts), plus unused exports in unchanged src/gateway/session-utils-row.ts and ui/src/pages/chat/components/chat-message-group.test-support.ts. No baseline was changed.
  • Initial CI exposed the missing new module in the PR wrapper's explicit source inventory. The inventory correction passed independent review. Focused local rerun: 36 passed, one platform skip, and one timeout in the unchanged macOS multi-checkout fixture (materializes full cold/warm PR siblings, then preserves native sparse transitions; 432s elapsed, 120s limit). All previously failing CI cases passed locally; the final-head CI run is 38886232299.

Reviewed pre-rebase head: 93f5e707b5b4574f7a6187f44045d67d00727506.

Mechanical rebase head: 49a7700bb13e446988e103f47e034cb03e04cb59. The only conflict was the wrapper inventory: retained both main’s registry.ts and this PR’s search-extension.ts. All 17 files retain identical added/removed patch content. The focused PR wrapper inventory test passed after rebase. Current-head CI 38889887303 passed: 62 successful jobs, 24 skipped, zero failures. PostgreSQL conformance, search/engine tests, and all typechecks passed. No CI rerun or fix push was needed.

CI Result
Rebased-head CI Passed: 62 successful jobs, 24 skipped, no failures
PostgreSQL conformance Passed, including all five R7a cases and SQLite capture
Previously failing wrapper shards Passed
Security Review Passed

Production delta: 285 net lines, including the one-line wrapper inventory correction; tests +388, docs +11. Agent schema sources and generated artifacts are unchanged.

@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 size: L labels Oct 16, 2026
@steipete
steipete marked this pull request as ready for review October 16, 2026 10:05
@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-16T10:51:35.359214Z 49a7700 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f8a800c72f

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +87 to +89
db.prepare("UPDATE openclaw_schema_meta SET search_extensions = ? WHERE store = ?").run(
JSON.stringify(next.searchExtensions),
base.id,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve persisted extensions during PostgreSQL migrations

When a PostgreSQL store with a registered extension is opened by a later schema version, databaseEngineAdapters.postgres.schema.migrate verifies both the pre-migration and destination schemas using store.schema, which does not contain the definitions persisted here; withPostgresSearchExtensions is only applied afterward in physical admission. Because the live fingerprint includes the derived extension objects while the scratch DDL omits them, the pre-migration verification reports schema drift and prevents the update. Load search_extensions into both migration schema descriptors before either verification.

AGENTS.md reference: AGENTS.md:L82-L82

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot added the clawsweeper:intake:feature Preliminary submission classification; full source review pending. label Oct 16, 2026
@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Oct 16, 2026
@steipete
steipete force-pushed the pgprep/r7-memory-pg branch from 93f5e70 to 49a7700 Compare October 16, 2026 10:48
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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: blocked before merge.

What this changes

Adds owner-registered PostgreSQL search definitions that persist alongside schema metadata and participate in exact catalog validation.

Example: A plugin registers keyword search over a notes table using extension name notes-search.

  • Before: Only search definitions declared by the canonical store schema can be admitted.
  • After: The plugin can install the derived index transactionally and retain its definition for later admission.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) Useful owner-approved capability with meaningful real-database integration coverage, but migration and shared-handle admission defects block merge and existing-state compatibility is not established.
Proof confidence 🦐 gold shrimp (3/6) The ordinary contributor-proof gate does not apply to this maintainer-authored PR; supplied evidence exercises the production engine through PostgreSQL integration tests, with memory product flows explicitly deferred.
Patch quality 🦪 silver shellfish (2/6) 2 actionable review findings remain.

Product

Kind: Feature · Worth it: Yes · Fix scope: Complete
User problem: Plugin owners cannot add derived PostgreSQL search indexes while retaining exact schema validation across reopening.
Reason: The maintainer-authored direction extends the existing engine owner with a concrete memory consumer; full memory indexing and retrieval are explicitly separate work.

Merge readiness

⛔ Blocked before merge - 3 items remain

Keep this PR open: the maintainer-approved capability is useful, but persisted extensions break schema migrations and registration fails on handles that reuse shared admission facts.

Priority: P2
Reviewed head: 49a7700bb13e446988e103f47e034cb03e04cb59

Before merge

  • Preserve persisted extensions in both migration descriptors (P1) - After registering notes-search on a version-1 store, opening a version-2 descriptor with an otherwise valid forward migration fails before migration SQL runs. The registration seals the derived objects, but adapters.ts constructs both migration descriptors from store.schema without loading persisted search_extensions. Its predecessor DDL hash therefore differs, and scratch validation reports schema drift because the generated schema omits the extension objects. Load the persisted definitions into both predecessor and destination descriptors. This confirms the existing review discussion and remains present at the reviewed head.
  • Retain search schemas when reusing shared physical admission (P2) - Open the same physical store through a second SQLite anchor handle while its admission facts remain retained, then call admitStoreSearch with an extension. Physical admission returns those shared facts at physical-facts.ts:114 before retainPostgresSchema runs, while this new WeakMap is keyed by the original anchor object. The second handle therefore has valid physical admission but no admitted schema, and registration throws 'Search extensions require an admitted PostgreSQL store'. A worker inheriting admission has the same problem. Carry the schema and persisted definitions through the shared admission owner so reused handles can register extensions without repeating catalog validation.
  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.

Findings

  • [P1] Preserve persisted extensions in both migration descriptors — src/infra/database-engine/search-extension.ts:87-91
  • [P2] Retain search schemas when reusing shared physical admission — src/infra/database-engine/postgres-schema.ts:26-30

Tests

  • Missing end-to-end proof: The supplied scenarios do not exercise a registered store through a schema-version migration or through another anchor handle or worker inheriting admission.
Agent review details

How this fits together

The database engine receives schema and search declarations from store owners, installs PostgreSQL derived objects, and returns admitted text and vector capabilities to worker callers.

flowchart TD
  A[Store owner] --> B[Admitted worker connection]
  B --> C[Search extension admission]
  C --> D[PostgreSQL derived indexes]
  C --> E[Persisted definitions and catalog seal]
  E --> F[Store reopen and migration]
  F --> B
Loading

Technical review

Best possible solution:

Carry persisted search definitions through the existing migration and shared physical-admission owners.

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

Source establishes both triggers: migrate a registered version-1 store to version 2, or register an extension through a second anchor handle that inherits physical admission; no target code was executed during this read-only review.

Is this the best way to solve the issue?

Extending engine-owned search admission is appropriate, but its persisted definitions must follow the same migration and cross-handle lifecycle as the physical admission facts.

Full review comments:

  • [P1] Preserve persisted extensions in both migration descriptors — src/infra/database-engine/search-extension.ts:87-91
    After registering notes-search on a version-1 store, opening a version-2 descriptor with an otherwise valid forward migration fails before migration SQL runs. The registration seals the derived objects, but adapters.ts constructs both migration descriptors from store.schema without loading persisted search_extensions. Its predecessor DDL hash therefore differs, and scratch validation reports schema drift because the generated schema omits the extension objects. Load the persisted definitions into both predecessor and destination descriptors. This confirms the existing review discussion and remains present at the reviewed head.
    Confidence: 0.99
  • [P2] Retain search schemas when reusing shared physical admission — src/infra/database-engine/postgres-schema.ts:26-30
    Open the same physical store through a second SQLite anchor handle while its admission facts remain retained, then call admitStoreSearch with an extension. Physical admission returns those shared facts at physical-facts.ts:114 before retainPostgresSchema runs, while this new WeakMap is keyed by the original anchor object. The second handle therefore has valid physical admission but no admitted schema, and registration throws 'Search extensions require an admitted PostgreSQL store'. A worker inheriting admission has the same problem. Carry the schema and persisted definitions through the shared admission owner so reused handles can register extensions without repeating catalog validation.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 7982ee6c0246.

Provenance checked

  • Engine-owned search binding and derived DDL keeps the original intent (20b5969: Centralize search primitives behind admitted engine capabilities while preserving caller-owned retrieval policy.)
  • PostgreSQL exact schema validation keeps the original intent (e3b8a28: Validate generated predecessor and destination schemas during atomic forward migration and publish admission after commit.)
  • PostgreSQL search objects and namespace isolation keeps the original intent (bf46379: Keep derived search objects inside the schema seal while canonical embeddings remain authoritative; subsequent namespace isolation qualified store-local search configuration.)
  • Memory publication worker keeps the original intent (91eff27: Keep schema and publication writes in the existing worker and retain committed facts through the owner lifecycle.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • node scripts/test-database-conformance.mjs --engine postgres --connection postgresql://[email protected]:5432/postgres
  • pnpm test src/infra/database-engine/search-extension.test.ts extensions/memory-core/src/memory/manager-publication-admission.test.ts --maxWorkers=1
  • git diff --check

What I checked:

Likely related people:

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

PR surface

Source +284, Tests +388, Docs +11, Other +1. Total +684 across 17 files. Added test files: 2.

View PR surface stats
Area Files Added Removed Net
Source 11 304 20 +284
Tests 4 389 1 +388
Docs 1 11 0 +11
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 0 +1
Total 17 705 21 +684

Labels

Label changes:

  • add P2: This is an experimental storage capability with concrete, focused lifecycle defects rather than an established release-wide outage.
  • add merge-risk: 🚨 compatibility: The additive SDK API persists search definitions that the existing migration path cannot preserve during validation.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: This is an experimental storage capability with concrete, focused lifecycle defects rather than an established release-wide outage.
  • merge-risk: 🚨 compatibility: The additive SDK API persists search definitions that the existing migration path cannot preserve during validation.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp and patch quality is 🦪 silver shellfish.
  • 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, 7:05 AM ET / 11:05 UTC.

@steipete
steipete merged commit a5d66c5 into main Oct 16, 2026
160 checks passed
@steipete
steipete deleted the pgprep/r7-memory-pg branch October 16, 2026 11:09
@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

docs Improvements or additions to documentation extensions: memory-core Extension: memory-core merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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