Skip to content

Memory v2 PR-3: built-in postgres plugin server + schema migrations - #2733

Merged
HongmingWang-Rabbit merged 1 commit into
stagingfrom
feat/memory-v2-pr3-postgres-plugin
May 4, 2026
Merged

Memory v2 PR-3: built-in postgres plugin server + schema migrations#2733
HongmingWang-Rabbit merged 1 commit into
stagingfrom
feat/memory-v2-pr3-postgres-plugin

Conversation

@HongmingWang-Rabbit

Copy link
Copy Markdown
Contributor

Builds on merged PR-1 (#2729). Independent of PR-2/PR-4.

Tracking issue: #2728
Task: #277

Summary

  • New binary cmd/memory-plugin-postgres/ implementing every endpoint of the v1 plugin contract
  • Plugin owns its own postgres tables (memory_namespaces, memory_records) under the plugin's migrations directory — NOT workspace-server's
  • pgvector for semantic search, FTS via tsvector, ILIKE fallback, TTL filter applied uniformly

What this is NOT

  • No workspace-server caller yet — integration is PR-5
  • No backfill/cutover — that's PR-7 + PR-8
  • Plugin schema is operator-owned: when swapping plugins, tables become orphaned (no auto-drop). Documented in PR-10.

Coverage

100.0% of statements in pgplugin package.

Test plan

  • go test ./internal/memory/pgplugin/ -cover reports 100.0%
  • go build ./cmd/memory-plugin-postgres/ clean
  • go vet clean
  • All 7 endpoints exercised happy + every error path
  • All 4 search paths (semantic / FTS / ILIKE / recent) exercised
  • Store helper functions (marshalMetadata, nullTime, vectorString, scanNamespace, scanMemory) exercised on both happy + error branches
  • Routing edge cases (unknown path, method-not-allowed, empty namespace, unknown sub) all return correct status

🤖 Generated with Claude Code

Builds on merged PR-1 (#2729), independent of PR-2/PR-4.

Implements every endpoint of the v1 plugin contract behind an HTTP
server (cmd/memory-plugin-postgres/) backed by postgres. Operators
run this binary next to workspace-server; it's the default
implementation MEMORY_PLUGIN_URL points at.

What ships:
  - cmd/memory-plugin-postgres/main.go: boot, signal-driven shutdown,
    boot-time migrations, configurable LISTEN/DATABASE/MIGRATION_DIR
  - cmd/memory-plugin-postgres/migrations/001_memory_v2.up.sql:
      memory_namespaces (PK on name, kind CHECK, expires_at, metadata)
      memory_records (FK to namespaces with CASCADE, kind+source CHECK,
                      pgvector embedding, FTS tsvector, ivfflat partial
                      index on embedding, partial index on expires_at)
  - internal/memory/pgplugin/store.go: storage layer using lib/pq
  - internal/memory/pgplugin/handlers.go: HTTP layer (no router dep —
    a switch on URL.Path keeps the binary's dep surface tiny)
  - 100% statement coverage on store.go + handlers.go

Schema notes:
  - These tables live next to the plugin binary, NOT in workspace-
    server/migrations/. When operators swap the plugin, these tables
    become orphaned (operator drops manually). Documented in PR-10.
  - Search supports semantic (pgvector cosine) → FTS (>=2 char query)
    → ILIKE (1-char query) → recent-listing (no query), with a TTL
    filter applied uniformly across all paths.
  - DELETE on namespace cascades to memory_records (FK ON DELETE
    CASCADE) — a deleted namespace immediately frees its memories.

Coverage corner cases pinned:
  - Health: ok, degraded (db ping fails), no-ping fn
  - Every CRUD endpoint: happy path, bad name, bad JSON, bad body,
    not-found, store errors, exec/scan/marshal errors
  - Search: FTS, semantic, short-query (ILIKE), no-query (recent),
    kinds filter, store errors, scan errors, mid-iteration row error
  - Routing edge cases: unknown path, empty namespace, unknown sub,
    method-not-allowed, GET on /v1/health (allowed), POST on /v1/health
    (404), GET on /v1/search (404)
  - Helper internals: marshalMetadata (nil/happy/unmarshalable),
    nullTime (nil/non-nil), vectorString (empty/format),
    nullVectorString (empty/non-empty), scanNamespace +
    scanMemory metadata-decode errors

No callers in workspace-server yet; integration starts in PR-5
(MCP handlers wire the plugin client through to MCP tools).
Comment thread workspace-server/internal/memory/pgplugin/store.go
@HongmingWang-Rabbit
HongmingWang-Rabbit added this pull request to the merge queue May 4, 2026
Merged via the queue into staging with commit f2397bf May 4, 2026
22 checks passed
@HongmingWang-Rabbit
HongmingWang-Rabbit deleted the feat/memory-v2-pr3-postgres-plugin branch May 4, 2026 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant