Skip to content

fix(config): reject reserved PostgreSQL schema prefixes - #202097

Merged
VACInc merged 1 commit into
openclaw:mainfrom
VACInc:fix-postgres-schema-prefix
Nov 20, 2026
Merged

VACInc merged 1 commit into
openclaw:mainfrom
VACInc:fix-postgres-schema-prefix

Conversation

@VACInc

@VACInc VACInc commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Summary

High Level TLDR

OpenClaw could accept a PostgreSQL schema prefix that made a new Gateway fail at startup. Config validation now points to database.postgres.schemaPrefix and explains which values to avoid.

What Problem This Solves

Using pg or pg_openclaw as the prefix passes config validation on the base commit. A fresh PostgreSQL-backed state store then fails to start because PostgreSQL reserves schema names beginning with pg_.

User Impact

Operators get an actionable error during config validation. Choose a prefix such as openclaw. Existing store anchors retain their recorded schema when the configured prefix changes.

Why This Change Was Made

The config schema applies the restriction in its existing regex so CLI validation and the exported JSON Schema share one rule. The field help and PostgreSQL guides explain the restriction.

Root Cause

The config validator checked characters and length. The store owner adds an underscore after the prefix, so both bare pg and prefixes already starting with pg_ create names PostgreSQL refuses with SQLSTATE 42939. PostgreSQL documents the reserved names in its CREATE SCHEMA reference. https://www.postgresql.org/docs/17/sql-createschema.html

Evidence

  • Regression on main: two cases failed because config validation returned ok: true.
  • Candidate: all 35 config tests passed. The exported JSON Schema rejected the same two reserved prefixes and accepted pgopenclaw.
  • Local autoreview did not produce a report. The isolated reviewer could not initialize through the local Codex launcher.

Real behavior proof

In a fresh state directory with PostgreSQL 17.12, configure the state family to use PostgreSQL and set database.postgres.schemaPrefix to pg or pg_openclaw. Run node openclaw.mjs config validate --json, then node openclaw.mjs gateway run --bind loopback --port "$PORT" with a free loopback port.

  • Base: validation returned "valid": true with exit 0 for both prefixes. Gateway startup exited 1 with unacceptable schema name "pg_state_<id>" or unacceptable schema name "pg_openclaw_state_<id>". A direct PostgreSQL check returned SQLSTATE 42939.

  • Candidate: validation exited 1 and Gateway startup exited 78 with the database.postgres.schemaPrefix error for both values. No reserved schema was created.

  • Valid control: pgopenclaw passed config validation and created a real PostgreSQL state schema, and the isolated Gateway returned HTTP 200 from /ready.

  • Published stable 2026.11.6 accepted all three prefixes. Reading the same config file with the candidate accepted pgopenclaw and rejected the two reserved prefixes. Neither CLI rewrote the config during validation. https://github.com/openclaw/openclaw/releases/tag/v2026.11.6

  • Populated-store handoff: started the published 2026.11.6 Gateway with PostgreSQL state and ran cron add --disabled --name "Prefix compatibility control" --every 24h --session isolated --message "Retained PostgreSQL cron message" --no-deliver --json --port "$PORT". After stopping that Gateway, started the candidate over the same config, anchor, and PostgreSQL database. The schema advanced from v36 to v40. cron list --all --json --port "$PORT" returned the same disabled job ID and payload. Config bytes, anchor store ID, and recorded namespace matched. Changing the valid configured prefix to pgother and restarting the candidate kept the original namespace and row. All three Gateway runs returned HTTP 200 from /ready.

The populated-store handoff addresses the advisory review's compatibility proof request. The review found no code defects. #202097 (comment)

What was not tested

The published-to-candidate handoff used a manual switch between binaries. The installed updater, live services, and paid models were outside this check. Each Gateway used a local mock model and PostgreSQL 17 over a private Unix socket.

Verification

@clawsweeper

clawsweeper Bot commented Nov 19, 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 size: XS labels Nov 19, 2026
@VACInc
VACInc marked this pull request as ready for review November 19, 2026 22:32
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug 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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 19, 2026
@clawsweeper

clawsweeper Bot commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

This PR rejects PostgreSQL schema prefixes that produce reserved schema names and updates the validation help and operator guides.

Example: Configure database.postgres.schemaPrefix as pg_openclaw for a new PostgreSQL state store.

  • Before: Config validation succeeds, then Gateway startup fails when PostgreSQL rejects the generated schema name.
  • After: Config validation rejects the value at database.postgres.schemaPrefix and explains the naming restriction.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused implementation and regression coverage are sound, but the stricter validation still needs existing-installation upgrade evidence.
Proof confidence 🦐 gold shrimp (3/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A prefix accepted by config validation can make a new PostgreSQL-backed Gateway fail during schema creation.
Reason: Earlier actionable validation has clear value, and the maintainer-authored direction needs no additional product approval.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep this PR open: it fixes a source-confirmed validation bug still present on main, with no discrete code defect found.

Priority: P2
Reviewed head: 6e12045b8b121a2a91ed077bd4608c7efce286d7

Before merge

  • 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

None.

Tests

  • Missing end-to-end proof: Provide redacted CLI/Gateway output from upgrading a populated v2026.11.6 PostgreSQL installation to the candidate, showing its settings, recorded namespace, and data remain intact; redact credentials and non-public endpoints.
Agent review details

How this fits together

CLI and Gateway config loading consume the shared Zod schema; PostgreSQL store creation combines the validated prefix with the store name and identity.

flowchart LR
  A[User configuration] --> B[Shared config validator]
  B --> C[CLI validation result]
  B --> D[Gateway database selection]
  D --> E[Store namespace builder]
  E --> F[PostgreSQL schema creation]
Loading

Technical review

Best possible solution:

Keep the restriction in the shared config validator so CLI validation, exported schema, and Gateway startup enforce the same PostgreSQL naming contract.

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

The main validator accepts both reserved forms, and the namespace builder deterministically produces pg_-prefixed names; the supplied PostgreSQL startup results match that path, although this review executed no target code.

Is this the best way to solve the issue?

The patch is the smallest complete validation fix: it strengthens the existing owner, preserves the valid pgopenclaw control, and introduces no parallel runtime policy.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • PostgreSQL schema-prefix validation keeps the original intent (5e78ec6: The original PostgreSQL pilot constrained identifier characters and length while retaining anchor-recorded namespaces.)
  • PostgreSQL field help and operator guidance keeps the original intent (docs(database): PostgreSQL operator guide #174642: The operator guide provides source-backed provisioning and recovery guidance; this clarification preserves its existing namespace-retention contract.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Focused introduced change: The introduced diff adds the reserved-prefix restriction to the existing regex, reuses its explanation in field help, and adds focused rejection and acceptance cases. (src/config/zod-schema.database.ts:49, 6e12045b8b12)
  • Current-main bug: Main still accepts pg and pg_openclaw; the namespace builder appends an underscore, making both produce names beginning with pg_. (src/config/zod-schema.database.ts:46, f91bc9900e81)
  • Existing anchor ownership: Existing stores use the namespace recorded in openclaw_engine_anchor; only fresh anchors use postgresStoreNamespace. The earlier naming repair at fix(database): port honors retained tables and the configured schema prefix #181882 explicitly preserved recorded namespaces. (src/infra/database-engine/open.ts:149, 6e12045b8b12)
  • Supplied behavior evidence: The PR reports real CLI validation and Gateway startup against PostgreSQL 17.12: reserved prefixes fail early on the candidate, while pgopenclaw creates a schema and reaches HTTP 200 readiness. (6e12045b8b12)
  • Authoritative naming contract: PostgreSQL 17's CREATE SCHEMA reference confirms that names beginning with pg_ are reserved; this contract directly governs the schema names OpenClaw creates. (doc/src/sgml/ref/create_schema.sgml)
  • History and repository policy: Feature history identifies the original PostgreSQL validator and subsequent family-selection, help, and ownership work. Root and applicable docs instructions were read; no maintainer-notes directory exists. Historical content lookup encountered unavailable promisor blobs, while the relevant original validator blob remained readable. (src/config/zod-schema.database.ts:46, 5e78ec6881c2)

Likely related people:

  • Mitchell Etzel: Raw commit c886f82 adds src/config/zod-schema.database.ts:57 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: c886f82c7793; files: src/config/zod-schema.database.ts)

PR surface

Source +3, Tests +16, Docs +5, Generated 0. Total +24 across 5 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 5 2 +3
Tests 1 16 0 +16
Docs 2 7 2 +5
Config 0 0 0 0
Generated 1 2 2 0
Other 0 0 0 0
Total 5 30 6 +24

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add P2: This is a focused validation improvement for explicitly configured PostgreSQL prefixes in an operator workflow.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.

Label justifications:

  • P2: This is a focused validation improvement for explicitly configured PostgreSQL prefixes in an operator workflow.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.

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 November 19, 2026, 5:55 PM ET / 22:55 UTC.

@VACInc
VACInc force-pushed the fix-postgres-schema-prefix branch from 6e12045 to 4eeed31 Compare November 20, 2026 17:48
@VACInc
VACInc merged commit 3d91af2 into openclaw:main Nov 20, 2026
117 checks passed
@VACInc

VACInc commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Merged via squash.

@VACInc
VACInc deleted the fix-postgres-schema-prefix branch November 20, 2026 18:18
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 21, 2026
tideclaw-bot pushed a commit that referenced this pull request Nov 24, 2026
(cherry picked from commit 3d91af2)

Release adaptation: regenerate config docs hashes for this stable tree using config:docs:gen; config:docs:check passed. No config migration or anchor rename.

Companions: no later PR or SHA mentions. Later same-path overlaps are unrelated config baseline regeneration, PostgreSQL operations/docs, or qualification tooling; #202109 is independent upgrade coverage, #202704 is a restore guide, and #202654 is a Session Share feature. Existing anchor selection and numeric aggregate fix #202629 are unchanged.

Co-authored-by: VACInc <[email protected]>

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit abc82993e59c1632ddfcaece8a02ce15c432e990)
maplel pushed a commit to maplel/openclaw that referenced this pull request Nov 24, 2026
…law#194384)

* docs: clarify PostgreSQL conformance coverage

* fix(cron): keep one-shot finalization working on PostgreSQL 16

* test(database): reuse cron conformance for JSON conversion regression

* test(postgres): accept fractional explain row counts

(cherry picked from commit 7ab0143)

Release adaptation: Only engine-owned jsonValue and retained cron enabled JSON replacement; preserve native boolean type with PG16 explicit ::json and SQLite json(). Omit unrelated PG docs/EXPLAIN test edits; retained one-shot enabled-transition caller present on baseline.

Follow-up dispositions: e029e18 docs: document isolated PostgreSQL restore drills (openclaw#202704); 49f0740 fix(database): report disabled memory after a port (openclaw#202630); a80b564 fix: keep database workers healthy after silent connection loss (openclaw#201856); 3d91af2 fix(config): reject reserved PostgreSQL schema prefixes (openclaw#202097); 835d722 fix: catch incompatible ownership before porting to SQLite (openclaw#202101); 67796a6 fix: keep scheduled Git backups current on PostgreSQL (openclaw#201870); cc849dd fix: recover lease heartbeats after a PostgreSQL connection loss (openclaw#201858); 6594caf fix: prepare macOS runtime pins without the PostgreSQL secret (openclaw#202102); 6ca56cd docs: clarify PostgreSQL storage and backup coverage (openclaw#202086); a079190 fix(postgres): chat history slows under concurrent reads (openclaw#190129); 2ff4256 feat(database): keep PostgreSQL rollback captures in PostgreSQL (openclaw#196236); 96c685b feat(backup): restore PostgreSQL stores into a staging database for restore drills (openclaw#194808); fb83d65 fix: reduce transcript allocation when preparing native context seeds; 71ec4d2 fix(config): keep Workboard PostgreSQL upgrades readable (openclaw#194648); b6ed907 perf(sessions): persist active transcript facts for hydration (openclaw#193682)

Validation: Baseline cron generated json(bound text) on PostgreSQL where json(text) is unavailable; helper and focused boolean regression retained. Exact PostgreSQL16 server proof unavailable; focused SQLite/helper tests queued. diff check passed.

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 38fdd9b52704d588d9ca24ef8e391d644961c985)
(cherry picked from commit fb935e6912388314851b05cb698ef038b83bbd07)
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 gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant