Skip to content

feat(memory): index and publish memory on PostgreSQL - #174183

Merged
steipete merged 4 commits into
mainfrom
pgprep/r7b-memory-runtime
Oct 16, 2026
Merged

steipete merged 4 commits into
mainfrom
pgprep/r7b-memory-runtime

Conversation

@steipete

@steipete steipete commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

PostgreSQL agent stores can admit search extensions, but memory publication still depends on SQLite shadow files and native vector writes.

User Impact

This adds the PostgreSQL memory indexing/publication foundation. Public memory search on PostgreSQL remains refused until the search and forget/status lifecycle is enabled together. SQLite statements, bindings, and results remain unchanged.

Why This Change Was Made

The agent owner admits memory's prepared text/vector definitions with the configured embedding dimensions. PostgreSQL stages bounded transfer fragments on the existing worker connection, releases the writer queue between batches, and publishes canonical rows plus engine-owned vector/text projections in one transaction. Revision and commit-authority checks preserve the previous index on failure. Internal indexing reads also use the publication worker, without enabling the public retrieval path. No PostgreSQL shadow file or ATTACH is used.

Embedding-cache inserts retain the 128-row batches (896 binds), and vector reuse retains bounded IN-lists. PostgreSQL eviction uses the canonical composite cache key; SQLite keeps its existing statements.

This is the first publication stage after #174085; search and lifecycle activation remain separate changes. No agent schema or Doctor import changes are included.

Evidence

  • Local PostgreSQL 17.11 with pgvector 0.8.7, without Docker: admission/restart, indexing/reuse, publication/restart, refused-commit rollback, stale-revision rejection, streamed cache staging, and cache batch/eviction conformance passed.
  • SQLite: 58 focused tests across six suites passed; 12 dialect-ratchet tests passed. A baseline/current capture preserved all 573 SQL statements, ordered bindings, and result snapshots, including native shadow publication and rollback.
  • SQLite SQL SHA-256: ff0bd32e4451425028caba7ec84b9b55dffac030181b46a1ac2cae817af598ad.
  • One independent Codex autoreview completed with no actionable P0–P2 findings. Conformance failures found during implementation were fixed and rerun.
  • Core/extension and focused PostgreSQL test typechecks, scoped lint, pnpm build strictSmoke, formatting, diff checks, and changed-file line-cap, dialect, worker, and Kysely checks passed. The worker ratchet remains 222 → 222 live main-thread calls.

The whole-tree maximum-lines suppression check reports three unchanged files already present at the branch base: ui/src/pages/chat/components/chat-message.test.tsx, ui/src/pages/config/config-page-state.ts, and ui/src/pages/sessions/sessions-page-state.ts. This change adds no suppression or baseline entry.

Size against the branch base: +641 net production lines, +1,075 test lines, +22 tooling/docs lines across 31 files. The retained growth is the PostgreSQL publication adapter and its conformance proof.

CI repair: added the four required cast invariants without changing runtime behavior. The gateway lookup fixture now queues its deliberate malformed-row write through agent write admission; CI had hit database is locked before the intended rejection assertion. The same assertion passes locally after the repair (one selected case, 7.2 seconds; 244 seconds including worker compilation). No retries or weakened assertions were added.

Final head 886c78d4b058bdb0faa003d75a8125597588ae2a: CI run 38900610159 passed, including PostgreSQL conformance (15m10s), baseline ratchets, the repaired gateway shard, and the overall CI gate. Applicable security review requirements passed. The PR is ready and remains unmerged.

@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: XL labels Oct 16, 2026
@steipete
steipete marked this pull request as ready for review October 16, 2026 12:07
@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-16T12:33:11.900747Z 886c78d 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: f15737feec

ℹ️ 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 +244 to +246
if (bindingStageId === command.input.stageId) {
retainState = false;
}

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 Reset the dropped spool before returning it to normal use

After a full PostgreSQL reindex is published, the long-lived published backend has bindingStageId set to this stage, so this branch runs after dropping the retained temp table but leaves the closure's created flag true. The next streamed source or embedding-cache write calls stage.start; ensureSpool() then skips recreating the table and the following DELETE FROM memory_stage_* fails because that table was dropped. Reset the current binding's spool state (and preferably its binding ID) when discarding it so post-reindex publications continue working.

Useful? React with 👍 / 👎.

@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

This PR adds PostgreSQL memory indexing and atomic publication through the existing agent database worker.

Example: Index memory/orchid.md into a fresh PostgreSQL agent store.

  • Before: The publication backend rejects source-index writes.
  • After: Internal indexing can publish canonical chunks and derived search projections; public memory search remains disabled.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch has a coherent owner boundary and no established production defect; evidence is strongest at the real-database conformance layer.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; its PostgreSQL 17.11 and pgvector 0.8.7 conformance report covers indexing, restart, rollback, stale revisions, and cache staging through in-process production backends.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Feature · Worth it: Yes · Fix scope: Complete
User problem: PostgreSQL agent stores cannot yet index and publish memory through the existing memory owner.
Reason: The maintainer-directed foundation completes its stated publication scope and explicitly defers public retrieval and lifecycle activation.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep open as a useful, maintainer-directed PostgreSQL publication foundation; no definite introduced production defect was established.

Priority: P2
Reviewed head: f15737feec5816bd92447932389fea19e5907f74

Before merge

  • Complete next step - Classify the failed SQLite session-lookup and baseline-ratchet checks using base or comparative evidence, assigning repairs only where this diff causes the failure.

Findings

None.

Tests

  • Missing end-to-end proof: Supplied conformance coverage does not exercise full reindex followed by streamed publication through the production worker-store dispatch.
Agent review details

How this fits together

Memory Core prepares source chunks and embeddings, then the agent database worker stages and commits them to canonical tables and engine-owned search projections.

flowchart TD
A[Memory files and sessions] --> B[Memory Core indexing]
B --> C[Agent database worker]
C --> D[PostgreSQL temporary staging]
D --> E[Atomic publication]
E --> F[Canonical memory tables]
F --> G[Text and vector projections]
Loading

Technical review

Best possible solution:

Land the publication foundation once CI failures are classified, retaining the public-search refusal until the coordinated lifecycle implementation is ready.

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

This is a foundation feature; current-main source confirms the missing PostgreSQL publication path, and no target code was executed during this review.

Is this the best way to solve the issue?

The implementation fits the existing agent worker and engine-owned projections, with connection-local staging instead of a competing persistent publication owner.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • PostgreSQL memory admission and refusal changes intended behavior with a stated reason (a5d66c5: Admit owner-registered search definitions first, leaving memory indexing and retrieval to later stages.)
  • Worker-owned publication and shadow rebuilds keeps the original intent (91eff27: Keep writable memory operations off the Gateway thread and preserve publication and cleanup custody.)
  • Canonical PostgreSQL vector projections keeps the original intent (bf46379: Derive native vector search rows transactionally from authoritative binary64 embeddings.)
  • Batched chunk writes, cache operations, and source reads keeps the original intent (a00f582: Bound database work and preserve existing indexing results while reducing repeated writes.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 483b0d3 adds extensions/memory-core/src/memory/manager-sync-ops.ts:510 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 483b0d3cbaf2; files: extensions/memory-core/src/memory/manager-sync-ops.ts)

PR surface

Source +640, Tests +1073, Docs +7, Other +14. Total +1734 across 30 files. Added test files: 4.

View PR surface stats
Area Files Added Removed Net
Source 18 751 111 +640
Tests 7 1073 0 +1073
Docs 1 7 0 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 4 14 0 +14
Total 30 1845 111 +1734

Review metrics

Metric Value Why it matters
Production versus test growth Production +640 net lines; tests +1,072 net lines Growth primarily supplies the PostgreSQL publication adapter and real-database conformance coverage while reusing the existing worker owner.

Labels

Label changes:

  • add P2: This is an experimental storage capability with limited current user exposure, rather than an urgent released regression.
  • 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 an experimental storage capability with limited current user exposure, rather than an urgent released regression.
  • 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.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Exercise full reindex and subsequent streamed publication through the actual agent worker-store dispatch.

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, 8:25 AM ET / 12:25 UTC.

@openclaw-barnacle openclaw-barnacle Bot added the gateway Gateway runtime label Oct 16, 2026

@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: 886c78d4b0

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

};
}
if (command.type === "vector.ensure") {
admitSearch({ "memory.vector": memoryVectorSearchSchema(command.input.dimensions) });

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.

P2 Badge Handle changed PostgreSQL search definitions during reindex

After a PostgreSQL index admits one embedding dimension, changing to a provider with different dimensions makes this call present a different definition under the existing memory.vector name. admitStoreSearchExtension rejects that with SearchExtensionDefinitionChangedError, while this handler ignores currentDimensions, so the full-reindex path cannot perform the required derived-index replacement and every subsequent indexing attempt fails. Add an owner-controlled replacement/rebuild path for changed dimensions; the same issue applies to changed FTS tokenizer definitions.

AGENTS.md reference: AGENTS.md:L65-L65

Useful? React with 👍 / 👎.

},
},
);
return { ok: true, value, facts: rebuilding ?? readMemoryDatabaseFacts(db) };

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.

P2 Badge Skip canonical fact reads for spool-only writes

For an ordinary streamed publication, stage.start and every stage.append invoke write(), but their handlers discard the returned facts. This line nevertheless runs readMemoryDatabaseFacts(db) after every 512 KiB transfer batch, including its table-existence/catalog check and several canonical-state queries, before the actual source replacement occurs. Large sources therefore incur redundant synchronous database work proportional to transfer batches; only compute facts for commands whose callers install or return them.

AGENTS.md reference: AGENTS.md:L72-L72

Useful? React with 👍 / 👎.

@steipete
steipete merged commit 163e18f into main Oct 16, 2026
198 of 199 checks passed
@steipete
steipete deleted the pgprep/r7b-memory-runtime branch October 16, 2026 13:00
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 17, 2026
* feat(memory): index and publish memory on PostgreSQL

* fix(memory): route PostgreSQL indexing reads through publication

* test(memory): preserve PostgreSQL fixture command types

* fix(memory): satisfy publication gates and order fixture writes
etzelm added a commit to etzelm/openclaw that referenced this pull request Oct 18, 2026
- Resolved by taking main's version of every file this branch touched; main's
  cache owner (openclaw#174183, openclaw#175224, openclaw#175566) replaced the helper the branch edited.
- The eviction preference is re-applied on top in the next commit.
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 gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: XL 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