Skip to content

fix(database): preserve shared-state PostgreSQL schema constraints - #170059

Merged
steipete merged 3 commits into
mainfrom
pgprep/p33-pr3-pg-schema
Oct 12, 2026
Merged

steipete merged 3 commits into
mainfrom
pgprep/p33-pr3-pg-schema

Conversation

@steipete

@steipete steipete commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Shared-state PostgreSQL generation succeeded while dropping 30 CHECKs, two ACP expression indexes, and the background-image foreign key, and eagerly created privacy-sensitive feature tables.

User Impact

The generated shared-state schema now retains all CHECKs and foreign keys and exposes named feature fragments with dependencies. The detailed JSON diagnostics remain in memory and are exported only with explicit --out; the repository tracks SQL, the manifest, and the Markdown summary. SQLite remains the default; its statement bytes, first-use timing, and schema version 21 are unchanged. This prepares the shared-state PostgreSQL open path without enabling it.

Why This Change Was Made

One declaration owner supplies both SQLite ensures and PostgreSQL generation. All 41 named fragments declare their dependencies; 28 first-use and 13 version-additive fragments remain distinct. The background-image fragment depends on profiles and retains its cascading foreign key. The existing ensure wrapper is separated from the pure declarations to keep database/runtime imports out of the generator.

Unsupported shared-state constructs fail with their exact source and reason. The two ACP indexes are explicitly pending the v22 promoted-column follow-up (PR4b), rather than represented by a lossy JSON expression translation. Ten pure NUL subpredicates are enforced intrinsically by PostgreSQL text; every surrounding CHECK remains present. PostgreSQL 16+ is required for IS JSON. Future engine schema versions and migrations move in lockstep, with JSON remaining canonical.

Evidence

  • Real PostgreSQL 17 catalog comparison: 134 tables, 1,386 columns, 293 CHECKs, 297 physical indexes, and 32 FKs; zero unexplained differences across columns/types/nullability/defaults, primary/unique keys, CHECK/index counts, and FK actions/deferrability. The two pending ACP indexes are reported explicitly; the index total accounts for PostgreSQL identity PK indexes.
  • Direct SQLite/PostgreSQL predicate boundary matrix: 23/23 outcomes identical for UTF-8 byte and character limits, trim behavior, NULL-safe comparisons, substrings, coalesce, and intrinsic NUL rejection.
  • Actual profile first-use statement capture: four statements before and after, byte-identical (SHA-256 60302ba0df2d063171c3f864540db9adc7f663ed7e7c57d6bacc11e5423e6ed4); no early table creation, version change, or repeat-ensure DDL.
  • pnpm db:postgres:check: 14 generator tests passed; generated shared-state artifacts and workboard artifact current. Generator rerun: Vitest 29.67s (test body 25.88s; wrapper 56.61s). Explicit --out JSON export and verification also passed.
  • Two independent Codex review rounds completed with no actionable P0–P2 findings: the implementation/artifacts and a follow-up using the existing formatter to preserve generated Markdown freshness through commit hooks. Import-cycle check: zero runtime value cycles.
  • Supplemental owner tests: 55 passed across 6 files (unit project: 6 tests, 141.30s; database-worker project: 49 tests, 457.08s). The unrun remainder was stopped at a project boundary to prioritize the required profile-schema and cron-authority gates.
  • Scoped core/script/test lint, formatting, artifact freshness, and git diff --check passed. The isolated PostgreSQL cluster was stopped and removed.
  • Required profile-schema suite: 6/6 passed (71.48s suite). Required cron-authority persistence case: 1/1 passed, 17 intentionally unselected (337.12s suite; 5.992s test body).
  • Exact-head PostgreSQL conformance passed on fabe85a1b8e0c5f70e78603bd7310af2351520f1: 134 tables, 1,386 columns, 293 CHECKs, 297 indexes, 32 FKs; zero unexplained differences. Existing suites: 379 tests passed, 38 skipped, across 31 passed and 4 skipped files (three shards, 183.65s; complete job 4m38s). The path filter selected the job automatically through the existing exact-head CI dispatch; the PR remained draft.
  • Handwritten production delta: net +382 lines; the declaration extension is approximately 73 net lines. Tracked generated output: 45 files, 4,346 lines; the 37,631-line JSON diagnostic report is no longer committed.

Related: #169254, #169933, #169952.

Follow-up: added the existing feature-schema ensure module to the PR wrapper inventory after the requested inventory check exposed the missing path. The focused inventory test passed after correction (34.93s suite; 58.55s wrapper).

The follow-up independently passed Codex review with no actionable P0–P2 findings. The PR is ready; its broad CI result and landing attribution are recorded below.

Landing CI attribution

Exact head fabe85a1b8e0c5f70e78603bd7310af2351520f1, CI run 38291976017, attempt 1. PostgreSQL conformance, security, lint, types, builds, docs, and inventory checks passed. The run has 38 failed Node jobs and one Node job cancelled at its one-hour deadline; the aggregate CI gate is red.

Nine failed jobs contain unchanged test files also failing in scheduled main run 38292584060. The other failures are in untouched runtime-config, transcript/session, plugin-schema, or workspace fixtures. Causal inspection found no PostgreSQL-generation path involved: runtime-config failures originate at the unchanged config snapshot owner; plugin-schema assertions concern separate plugin databases; transcript normalization, session-key cold reads, and workspace manifest refresh are unchanged owners. The Codex timeout cascade starts at the same unprepared-runtime-config boundary and reaches the one-hour job deadline. No PR-caused product regression was found. These failures are retained under the explicitly authorized inherited/unrelated-failure admin exception, not reported as green. No fix push or test rerun was made.

Failed-job attribution
Job Attribution Evidence
checks-node-changed-extensions-bundle-21 Unrelated unchanged runtime-config / plugin fixture job; failing files and responsible owners are outside this PR’s changed behavior
checks-node-changed-extensions-bundle-3 Unrelated plugin-database schema-admission fixture job; failing files and responsible owners are outside this PR’s changed behavior
checks-node-changed-extensions-bundle-26 Unrelated unchanged runtime-config / plugin fixture job; failing files and responsible owners are outside this PR’s changed behavior
checks-node-changed-extensions-bundle-32 Unrelated unchanged runtime-config / plugin fixture job; failing files and responsible owners are outside this PR’s changed behavior
checks-node-changed-extensions-bundle-25 Unrelated plugin-database schema-admission fixture job; failing files and responsible owners are outside this PR’s changed behavior
checks-node-changed-extensions-bundle-20 Unrelated unchanged runtime-config / plugin fixture job; failing files and responsible owners are outside this PR’s changed behavior
checks-node-changed-extensions-bundle-7 Unrelated unchanged runtime-config / plugin fixture job; failing files and responsible owners are outside this PR’s changed behavior
checks-node-changed-extensions-bundle-27 Unrelated unchanged runtime-config / plugin fixture job; failing files and responsible owners are outside this PR’s changed behavior
checks-node-changed-extensions-bundle-10 Unrelated unchanged runtime-config / plugin fixture job; failing files and responsible owners are outside this PR’s changed behavior
checks-node-changed-extensions-bundle-24 Unrelated unchanged runtime-config / plugin fixture job; failing files and responsible owners are outside this PR’s changed behavior
checks-node-changed-extensions-bundle-22 Unrelated unchanged runtime-config / plugin fixture job; failing files and responsible owners are outside this PR’s changed behavior
checks-node-changed-compact-large-21 Unrelated historical transcript normalization fixture job; failing files and responsible owners are outside this PR’s changed behavior
checks-node-changed-extensions-bundle-8 Unrelated unchanged runtime-config / plugin fixture job; failing files and responsible owners are outside this PR’s changed behavior
checks-node-changed-extensions-bundle-9 Unrelated unchanged runtime-config / plugin fixture job; failing files and responsible owners are outside this PR’s changed behavior
checks-node-changed-extensions-bundle-23 Unrelated unchanged runtime-config / plugin fixture job; failing files and responsible owners are outside this PR’s changed behavior
checks-node-changed-extensions-bundle-1 Unrelated unchanged runtime-config / plugin fixture job; failing files and responsible owners are outside this PR’s changed behavior
checks-node-changed-extensions-bundle-17 Unrelated unchanged runtime-config / plugin fixture job; failing files and responsible owners are outside this PR’s changed behavior
checks-node-changed-extensions-bundle-2 Unrelated unchanged runtime-config / plugin fixture job; failing files and responsible owners are outside this PR’s changed behavior
checks-node-changed-extensions-bundle-12 Unrelated unchanged runtime-config / plugin fixture job; failing files and responsible owners are outside this PR’s changed behavior
checks-node-changed-extensions-bundle-15 Unrelated unchanged runtime-config / plugin fixture job; failing files and responsible owners are outside this PR’s changed behavior
checks-node-changed-compact-large-3 Inherited: same untouched failing files on main main job 114956275029
checks-node-changed-extensions-bundle-13 Unrelated runtime-config timeout cascade; one-hour deadline job; failing files and responsible owners are outside this PR’s changed behavior
checks-node-changed-compact-small-23 Inherited: same untouched failing files on main main job 114956275453
checks-node-changed-extensions-bundle-14 Unrelated unchanged runtime-config / plugin fixture job; failing files and responsible owners are outside this PR’s changed behavior
checks-node-changed-compact-small-1 Inherited: same untouched failing files on main main job 114956274893, main job 114956275108, main job 114956275127
checks-node-changed-compact-small-10 Unrelated cold session-key read-budget fixture job; failing files and responsible owners are outside this PR’s changed behavior
checks-node-changed-extensions-bundle-6 Unrelated unchanged runtime-config / plugin fixture job; failing files and responsible owners are outside this PR’s changed behavior
checks-node-changed-compact-large-1 Inherited: same untouched failing files on main main job 114956275275
checks-node-changed-compact-large-13 Inherited: same untouched failing files on main main job 114956275064
checks-node-changed-extensions-bundle-11 Unrelated unchanged runtime-config / plugin fixture job; failing files and responsible owners are outside this PR’s changed behavior
checks-node-changed-compact-small-11 Inherited: same untouched failing files on main main job 114956274893
checks-node-changed-10 Unrelated unchanged runtime-config / plugin fixture job; failing files and responsible owners are outside this PR’s changed behavior
checks-node-changed-extensions-bundle-5 Unrelated Codex attachment-retention fixture job; failing files and responsible owners are outside this PR’s changed behavior
checks-node-changed-18 Unrelated workspace manifest refresh fixture job; failing files and responsible owners are outside this PR’s changed behavior
checks-node-changed-2 Unrelated Telegram fixture timeout job; failing files and responsible owners are outside this PR’s changed behavior
checks-node-changed-compact-small-28 Inherited: same untouched failing files on main main job 114956275427
checks-node-changed-extensions-config-117 Unrelated unchanged runtime-config / plugin fixture job; failing files and responsible owners are outside this PR’s changed behavior
checks-node-changed-compact-large-10 Inherited: same untouched failing files on main main job 114956275127
checks-node-changed-compact-small-3 Inherited: same untouched failing files on main main job 114956274802

Native landing note: the native review and prepare sequence passed without a push. Admin merge admission refused duplicate same-name GitHub Actions gates from the earlier conformance dispatch and the ready-PR workflow, although the selected gate and exact head match. The required security clearance was independently revalidated through the native security owner. The operator-authorized head-pinned REST squash fallback is used after the native landing exceeds ten minutes.

@steipete
steipete marked this pull request as ready for review October 12, 2026 17:55
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime scripts Repository scripts agents Agent runtime and tooling size: XL labels Oct 12, 2026
@steipete
steipete marked this pull request as draft October 12, 2026 18:03
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 12, 2026
@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR preserves shared-state PostgreSQL constraints, separates lazy feature fragments, and exports detailed diagnostics only on request.

Example: Generate PostgreSQL DDL for background images belonging to profile 'profile-demo'.

  • Before: The generated schema omitted the foreign key to user profiles.
  • After: The background-image fragment depends on profiles and retains its cascading foreign key.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A useful, focused repair with real PostgreSQL validation, preserved SQLite contracts, and no identified introduced defect.
Proof confidence 🐚 platinum hermit (4/6) The ordinary contributor-proof gate does not apply to this maintainer-authored PR; supplied PostgreSQL 17 catalog and SQLite first-use results are supported by exact-head conformance metadata, although raw log access was blocked.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Developers could generate apparently successful shared-state PostgreSQL DDL that omitted constraints and eagerly included optional feature tables.
Reason: The maintainer-authored change repairs a concrete preparation contract while retaining explicit, accepted exclusions and existing runtime behavior.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR repairs concrete PostgreSQL schema-generation losses, and no actionable introduced defect was found.

Priority: P2
Reviewed head: fabe85a1b8e0c5f70e78603bd7310af2351520f1

Before merge

None.

Findings

None.

Agent review details

How this fits together

Canonical SQLite schemas and feature declarations feed SQLite initialization and PostgreSQL generation, which produces SQL fragments, dependency metadata, and catalog diagnostics.

flowchart TD
  A[Canonical SQLite schemas] --> B[Feature declarations]
  B --> C[SQLite feature initialization]
  A --> D[PostgreSQL generator]
  B --> D
  D --> E[SQL fragments and manifest]
  E --> F[PostgreSQL catalog comparison]
Loading

Technical review

Best possible solution:

Land the constraint-preserving generator while keeping shared-state runtime activation and ACP column promotion in their separately scoped work.

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

Current-main source exposes the missing feature declarations and permissive omission path; this review ran no target code.

Is this the best way to solve the issue?

Sharing declarations with existing SQLite owners and refusing unexplained PostgreSQL omissions addresses the generator boundary without activating an unfinished runtime backend.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • PostgreSQL generation and diagnostics changes intended behavior with a stated reason (4575155: Provide reproducible PostgreSQL-readiness projections with explicit omissions rather than a production migration.)
  • Shared lazy SQLite initialization keeps the original intent (d234f9d: Share canonical SQL initialization while retaining feature-local caches, transaction owners, and lazy call sites.)
  • Avoid redundant schema setup keeps the original intent (5a0baa0: Avoid revoking prepared integrity facts when existing schema objects require no DDL.)
  • Worker-owned standing-grant schema keeps the original intent (8d86209: Keep approval persistence in its worker owner and retain authorization checks at effects.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

PR surface statistics unavailable: the file list is incomplete.

Review metrics

Metric Value Why it matters
Generator interface 1 new CLI flag --check-connection runs catalog verification against an explicitly supplied disposable PostgreSQL connection.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This corrects database-readiness tooling without changing the default runtime store or establishing an urgent production outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-12T18:12:31.760Z sha 0c91f8a :: needs maintainer review before merge. :: none
  • reviewed 2026-10-12T18:35:41.425Z sha fabe85a :: needs maintainer review before merge. :: none

Reviewed October 12, 2026, 3:53 PM ET / 19:53 UTC (Revision 3).

@steipete
steipete marked this pull request as ready for review October 12, 2026 18:35
@steipete
steipete merged commit 050e315 into main Oct 12, 2026
457 of 518 checks passed
@steipete
steipete deleted the pgprep/p33-pr3-pg-schema branch October 12, 2026 20:10
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 13, 2026
…penclaw#170059)

Preserve shared-state PostgreSQL CHECKs, indexes, and foreign keys; declare feature fragments through the existing schema owner; and validate catalog equivalence in CI. SQLite first-use statements and schema version remain unchanged.

PostgreSQL conformance passed. Inherited and unrelated Node test failures are retained under the documented maintainer exception.

Refs openclaw#169254, openclaw#169933, openclaw#169952.
steipete added a commit that referenced this pull request Oct 13, 2026
* fix(database): preserve agent PostgreSQL schema contracts

Generate owner-scoped agent runtime DDL with faithful relational indexes and checks, ten canonical non-search triggers, and explicit pending search capabilities. Verify the agent catalog and paired SQLite/PostgreSQL behavior in conformance. Keep runtime enablement and schema versions unchanged.

Related: #169254, #170059, #170266

* fix(ci): exclude generated PostgreSQL from SQLite ratchet

The generated PostgreSQL schema uses JSON function and operator names shared with SQLite. Keep the canonical PostgreSQL artifacts outside the SQLite debt inventory while retaining checks on SQLite source.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 14, 2026
…71350)

* fix(database): preserve agent PostgreSQL schema contracts

Generate owner-scoped agent runtime DDL with faithful relational indexes and checks, ten canonical non-search triggers, and explicit pending search capabilities. Verify the agent catalog and paired SQLite/PostgreSQL behavior in conformance. Keep runtime enablement and schema versions unchanged.

Related: openclaw#169254, openclaw#170059, openclaw#170266

* fix(ci): exclude generated PostgreSQL from SQLite ratchet

The generated PostgreSQL schema uses JSON function and operator names shared with SQLite. Keep the canonical PostgreSQL artifacts outside the SQLite debt inventory while retaining checks on SQLite source.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant