Skip to content

feat: experimental PostgreSQL engine for the workboard store - #169214

Merged
steipete merged 10 commits into
mainfrom
pgprep/postgres-engine-workboard
Oct 12, 2026
Merged

steipete merged 10 commits into
mainfrom
pgprep/postgres-engine-workboard

Conversation

@steipete

@steipete steipete commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Adds an experimental, opt-in PostgreSQL engine for the workboard pilot, tracked in #169254. The existing workboard kernels retain one store owner through a structural SQL connection boundary; a dedicated worker owns the pinned PostgreSQL client. Kysely compiles PostgreSQL for that connection, with identity-marked string-set expressions and buffered iteration.

Configure database.engine: "postgres", database.postgres.connection (a SecretInput DSN; prefer a SecretRef), and optionally database.postgres.schemaPrefix (default openclaw). The host resolves the secret and supplies it through worker input, without a DSN environment handoff or silent SQLite fallback. The default remains SQLite, so existing installations keep their engine and update behavior.

The pilot refuses switching an existing populated SQLite workboard store. An existing PostgreSQL anchor opened with SQLite selected also refuses and names the schema/settings to restore. The SQLite anchor retains the store UUID, schema identity, and shared cache receipts; backups must retain it together with its PostgreSQL schema. Data porting and future PostgreSQL schema migrations remain follow-ups. PostgreSQL uses synchronous_commit=off, matching the existing SQLite NORMAL acknowledgment tradeoff: a crash can lose recent acknowledged commits.

Writers obtain host admission before the combined BEGIN/advisory-lock request. Read snapshots use REPEATABLE READ READ ONLY. Confirmed writes publish through the existing anchor receipt owner. Connection loss during COMMIT or autocommit reports outcome unknown without replaying the operation. The shared loss owner now advances the anchor token once because the write may have committed; definite mid-transaction rollback does not advance it. The regression covers both outcomes and prevents repeated failure from advancing the token again.

Rebase and review

Preserved #169430's consolidation, including both ../record-fields.js imports, and reapplied only the engine seam. Regenerated the config-documentation checksum through its generator after resolving the newer main conflict. No workboard store design change.

The coordinator's Codex autoreview was clean on e2d365922fa3cec4e7b97efb3fd42f66d399323f. The Database access async conversion session approved the PostgreSQL branch in runSqliteSingleStatementSync, admission before BEGIN/lock, and the zero-cost string-set marker. The follow-up repair changes the PostgreSQL dispatch boundary: a private brand and minimal interface in sql-connection.ts identify the handle, and its runTransaction method delegates to the existing PostgreSQL transaction owner. Neither shared SQLite module imports the concrete connection; SQLite also no longer imports the PostgreSQL transaction module. This cuts both PR-added cycle edges without moving unrelated worktree types. The original SQLite function bodies remain identical to current main apart from PostgreSQL dispatch/types and the two approved string-set markers.

The cycle repair adds 38 net production lines, excluding tests and the wrapper inventory. It retains the assertPostgresTransactionUsable export rename and the PostgreSQL, SQL-connection, and database-schema wrapper entries. No re-review was requested under the delegated landing instructions.

Evidence

The token regression failed for the intended reason before the fix. All focused tests and both full workboard suites run with --maxWorkers=1. PostgreSQL uses a throwaway Homebrew PostgreSQL 17 cluster over a Unix socket; the test connection travels through the existing worker environment-data mechanism. The cluster is stopped and removed after the run. No Docker or remote lease is used.

Local proof Result CLI wall time
oxfmt / core oxlint / diff check Passed —
Madge / runtime import cycles / export collisions All passed —
Wrapper inventory closure 1 passed, 16 unselected 24.19 s
PostgreSQL connection regression 5 passed 154.45 s
SQLite transactions 31 passed 28.97 s
Kysely sync 35 passed 116.89 s
PostgreSQL transactions 12 passed 92.13 s
Workboard PostgreSQL 364 passed / 47 skipped / 0 failed 1357.39 s
Workboard SQLite 400 passed / 11 skipped / 0 failed 1164.71 s

Static closure proof: sqlite-transaction.ts static import closure (including types): postgres-sync/connection.ts ABSENT. A source-body comparison checked 36 native SQLite functions against current origin/main, excluding PostgreSQL dispatch and type-only substitutions; the two previously approved string-set markers remain.

The workboard suite has 411 cases rather than the earlier 412 because main consolidated a two-case sessions-board in-flight-read test into one source-invalidation test. The applicable PostgreSQL count is therefore 364 cases plus 47 SQLite-only skips. The SQLite count is 400 plus 11 PostgreSQL-only skips.

The first full-suite invocation was invalidated by the harness because a type-import correction changed a source stamp during compilation; both suites were restarted on unchanged final sources. The broad lint invocation hit a plugin-SDK declaration-generation timeout. The repository's matching source-backed core lint configuration passed; no lint rule or diagnostic was suppressed. PR CI owns broad builds, types, and cross-platform suites. Exact-head CI results will be recorded before landing.

Release-note context: experimental PostgreSQL workboard support behind database.engine; SQLite remains the default. No CHANGELOG edit (release-owned).

Landing CI disposition

CI run 38224917403 was rerun once after fail-fast cancelled the first attempt. Attempt 2 completed with 133 successful jobs, 18 skipped jobs, and 11 failed jobs; no cancelled jobs remain. Both Android jobs completed successfully.

Failure Classification and disposition
Declaration fixtures: write-unified-entry-dts (5), write-plugin-sdk-entry-dts (11), dist-artifact-ownership (2), tsdown-declaration-resolution (22) Inherited: the same cases fail in main CI run 38220958692 because the fixture omits control-ui-public-session-card-render.ts. The PR does not change these test files or the asset plugin.
SQLite query-plan test type errors PR-caused test typing issue. Fixed in 7fcf90d43680776fcd422cb5fa2592ce66514366 by checking the native SQLite handle before using prepare. All 32 tests in the affected file passed; wrapper wall time 855.91 seconds (700.38 seconds reported by Vitest). Independent review is clean; formatting and diff checks pass.
Two session-entry-patch.authority.test.ts type errors Present in the tested main parent b82b033920ee7a4df6323e3ee2b04ac8c6037fe0. Current main replaces the unsafe f.read().label assertions; its matching type job passes in run 38226928416. The merge incorporates that existing main fix.
QA: node worker launch reconciliation, paired worker lifecycle, native worker slot, reconnect deduplication timeout, transcript cursor generation mismatch Unqualified against main: no matching main reproduction was established. No PR-head-fails/main-passes product regression was established either. These remain explicit verification gaps under the operator's instruction that only a proven product regression stops this landing.
openclaw/ci-gate Aggregate of the above failures, not an independent failure.

The only fix push adds the three-line SQLite test guard; production code is unchanged from the coordinator-reviewed head. The prior focused, SQLite workboard, PostgreSQL workboard, cycle, wrapper-inventory, and import-closure proof is reused. Full CI on the final fix head is not claimed green.

Native admission cannot resume because a predecessor's orphaned operation lock remains. No lock was recovered. After the native stall exceeded ten minutes, the operator-authorized, exact-head REST squash fallback was selected. This records the exception and verification gaps; it does not label unqualified QA failures as inherited.

@clawsweeper

clawsweeper Bot commented Oct 11, 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 scripts Repository scripts plugin: workboard size: XL labels Oct 11, 2026
@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. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 11, 2026
@clawsweeper

clawsweeper Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

This PR adds an optional experimental PostgreSQL backend for Workboard while retaining SQLite as the default.

Example: A new Workboard installation selects database.engine="postgres" and schemaPrefix="team".

  • Before: Workboard stores boards, cards, and attachments in SQLite.
  • After: Workboard stores them in a PostgreSQL schema named team_workboard_<store-id-prefix>, with a local SQLite identity anchor.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The approved architecture has substantial reported conformance coverage, but a reply-boundary defect and mandatory authority and upgrade verification prevent readiness.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦐 gold shrimp (3/6) Security review found an item that needs attention.

Product

Kind: Feature · Worth it: Yes · Fix scope: Complete
User problem: Operators cannot use PostgreSQL for Workboard persistence.
Reason: The maintainer explicitly owns the experimental direction and its limits; the implementation retains one Workboard kernel and preserves SQLite as the default.

Merge readiness

⛔ Blocked before merge - 5 items remain

Keep this PR open: it delivers a maintainer-approved PostgreSQL pilot, but uncertain-write classification still breaks across Workboard replies.

Priority: P2
Reviewed head: 741fd94fb226118eb51013f90a76d0064711cbd0

Before merge

  • Add real behavior proof - Authority-chain proof required: provide redacted terminal output or logs through a Workboard tool or Gateway method, storage worker, and real PostgreSQL client showing an allowed upload persists and an upload revoked during queueing or advisory-lock waiting is rejected before COMMIT; query physical blob and metadata rows to confirm the forbidden upload is absent. The reported conformance and connection-termination suites do not exercise this scenario. Also show a v2026.10.2 upgrade retaining populated SQLite Workboard data and settings. Redact credentials, IPs, phone numbers, and non-public endpoints. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Preserve uncertain-outcome classification through Workboard replies (P2) - When PostgreSQL loses its connection during COMMIT, the new write path throws a canonical SqliteWorkerError and this backend catches it into encodeWorkboardSqliteFailure. The outer worker then V8-serializes the envelope. The codec restores name and code but omits the private retainedWorkerErrorCode marker, so hasSqliteWorkerOutcomeUnknown on the host returns false even though the write may have committed. Preserve canonical classification explicitly across this envelope and cover a failure returned through createWorkboardSqliteStores, rather than only a direct PostgresSyncConnection call. This previously reported finding remains unresolved.
  • Resolve security concern: Verify revoked upload authority before PostgreSQL publication - The new backend admits writes before advisory-lock waiting and requests host authority again before COMMIT. Existing upload tests skip PostgreSQL, so they do not establish rejection of a disabled upload at this final effect boundary or confirm physical blob and metadata cleanup.
  • Resolve merge risk - Establish that upload authority revoked during Workboard queueing or PostgreSQL advisory-lock waiting prevents durable blob and metadata publication.
  • 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

  • [P2] Preserve uncertain-outcome classification through Workboard replies — extensions/workboard/src/sqlite-store.worker.ts:158-159
  • [medium] Verify revoked upload authority before PostgreSQL publication — src/infra/postgres-sync/transaction.ts:59

Tests

  • Missing end-to-end proof: Supply a Workboard upload trace proving allowed persistence and rejection after revocation during queueing or PostgreSQL lock waiting, plus a v2026.10.2 upgrade preserving populated SQLite data and settings.
Agent review details

How this fits together

Workboard tools and Gateway methods submit storage operations to a worker; the selected SQL connection persists boards, cards, attachments, and session placements and publishes cache-invalidating receipts.

flowchart TD
A[Workboard tools and Gateway] --> B[Workboard store]
B --> C[Storage worker]
C --> D[Shared Workboard kernel]
D --> E[SQLite connection]
D --> F[PostgreSQL bridge worker]
F --> G[PostgreSQL schema]
F --> H[SQLite identity anchor]
Loading

Technical review

Best possible solution:

Preserve canonical uncertain-write errors through Workboard replies and verify the approved backend through upload-authority and stable-release upgrade scenarios.

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

Source establishes the lost-marker path through Workboard's serialized error envelope; no runtime reproduction or target-code execution was performed.

Is this the best way to solve the issue?

The shared Workboard kernel and worker-owned PostgreSQL client fit the approved pilot, but connection-level tests do not validate error classification across the Workboard reply boundary.

Full review comments:

  • [P2] Preserve uncertain-outcome classification through Workboard replies — extensions/workboard/src/sqlite-store.worker.ts:158-159
    When PostgreSQL loses its connection during COMMIT, the new write path throws a canonical SqliteWorkerError and this backend catches it into encodeWorkboardSqliteFailure. The outer worker then V8-serializes the envelope. The codec restores name and code but omits the private retainedWorkerErrorCode marker, so hasSqliteWorkerOutcomeUnknown on the host returns false even though the write may have committed. Preserve canonical classification explicitly across this envelope and cover a failure returned through createWorkboardSqliteStores, rather than only a direct PostgresSyncConnection call. This previously reported finding remains unresolved.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

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

Merge-risk options

Maintainer options:

  1. Hold for final-effect authority verification (recommended)
    Keep this PR open until allowed uploads and uploads revoked during queueing or lock waiting are exercised through Workboard and the real PostgreSQL client, with physical persistence observations.

Provenance checked

  • Workboard storage and worker lifecycle keeps the original intent (38fb08d: Move database work off the Gateway event loop while retaining data format, logical leases, draining, and retryable cleanup.)
  • Transaction recovery keeps the original intent (3d0254a: Retain terminal failures and refuse continuation after failed rollback; the new backend retires failed connections through its own connection owner.)
  • PostgreSQL schema generation changes intended behavior with a stated reason (4575155: Generate a deterministic PostgreSQL projection from canonical SQLite schemas before runtime conformance; this maintainer-authored PR deliberately advances to a Workboard-only runtime pilot.)
  • SQLite dialect ratchet keeps the original intent (a1c1610: Prevent SQLite-specific SQL debt growth; the patch distinguishes portable savepoints and table column lists from engine-specific constructs.)

Testing

Proof path: in-process harness.

Security

Needs attention: Upload revocation across the new PostgreSQL persistence boundary remains unverified; no concrete authorization bypass was established.

Evidence

Security concerns:

  • [medium] Verify revoked upload authority before PostgreSQL publication — src/infra/postgres-sync/transaction.ts:59
    The new backend admits writes before advisory-lock waiting and requests host authority again before COMMIT. Existing upload tests skip PostgreSQL, so they do not establish rejection of a disabled upload at this final effect boundary or confirm physical blob and metadata cleanup.
    Confidence: 0.92

What I checked:

  • Approved direction and accepted pilot limits: The maintainer-authored body explicitly selects an experimental Workboard-only backend, keeps SQLite as default, refuses engine switching for existing SQLite stores, requires paired backups, and accepts synchronous_commit=off. These choices do not require another product approval. (741fd94fb226)
  • Current main remains SQLite-only: Fetched main opens the native SQLite database and installs the Workboard SQLite schema without PostgreSQL selection. (extensions/workboard/src/sqlite-store-schema.ts:335, 438e06c68838)
  • Uncertain errors lose canonical classification: PostgreSQL connection loss creates a branded SqliteWorkerError. Workboard catches it inside its result envelope, serializes that envelope through V8, and restores ordinary error fields without restoring the private classification marker. (extensions/workboard/src/sqlite-store-errors.ts:25, 741fd94fb226)
  • Canonical checker requires the private marker: hasSqliteWorkerOutcomeUnknown checks the retained symbol, including through causes and aggregates; an error's name and public code are insufficient. (src/infra/sqlite-worker-contract.ts:217, 741fd94fb226)
  • Prior findings reassessed: The new head adds the previously missing wrapper inventory entries. Transaction dispatch now uses a lightweight branded interface and delegates to the PostgreSQL transaction owner; the remaining duplicate validator has no established failing behavior and is not re-raised as a correctness defect. The Workboard uncertain-error codec is unchanged. (scripts/pr-lib/wrapper-components.txt:348, 741fd94fb226)
  • Authority coverage does not reach PostgreSQL upload persistence: Existing upload-policy cases inspect physical SQLite rows and are skipped for PostgreSQL. The added PostgreSQL termination tests operate directly on the connection rather than through Workboard uploads and their host authority. (extensions/workboard/src/tools.upload-policy.test.ts:44, 741fd94fb226)

Likely related people:

  • Peter Steinberger: Raw commit 4575155 adds scripts/generate-postgres-schema.mts:14 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 457515502e84; files: scripts/generate-postgres-schema.mts)

PR surface

Source +1412, Tests +1522, Docs +33, Config +3, Generated 0, Other +192. Total +3162 across 76 files. Added test files: 14.

View PR surface stats
Area Files Added Removed Net
Source 31 1724 312 +1412
Tests 32 1630 108 +1522
Docs 1 33 0 +33
Config 1 4 1 +3
Generated 2 3 3 0
Other 9 212 20 +192
Total 76 3606 444 +3162

Review metrics

Metric Value Why it matters
New configuration fields 3 Adds database.engine, database.postgres.connection, and database.postgres.schemaPrefix; engine selection is optional and SQLite remains the default.

Labels

Label changes:

  • remove merge-risk: 🚨 automation: Current PR review merge-risk labels are merge-risk: 🚨 compatibility, merge-risk: 🚨 security-boundary.

Label justifications:

  • P2: This is an optional experimental backend with a limited Workboard blast radius and a source-established error-classification defect.
  • merge-risk: 🚨 compatibility: Adds configuration and SDK connection capabilities plus a persistent anchor/schema contract; stable-release upgrade preservation remains unproved.
  • merge-risk: 🚨 security-boundary: Upload publication crosses PostgreSQL transport and lock waiting, requiring verification that revoked authority cannot reach durable persistence.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rank-up moves

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

  • Prove allowed and revoked uploads through the final PostgreSQL persistence boundary.
  • Demonstrate a stable-release upgrade with existing SQLite Workboard data and settings intact.

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 (8 earlier review cycles)
  • reviewed 2026-10-11T16:38:42.007Z sha d047283 :: needs real behavior proof before merge. :: [P2] Preserve unknown-outcome classification across Workboard worker replies
  • reviewed 2026-10-11T18:38:54.812Z sha 46a406a :: needs real behavior proof before merge. :: [P2] Preserve unknown-outcome classification across Workboard replies
  • reviewed 2026-10-11T19:01:09.208Z sha 251d732 :: needs real behavior proof before merge. :: [P2] Preserve unknown-outcome classification across Workboard replies
  • reviewed 2026-10-11T23:29:55.621Z sha 9a8c7da :: needs real behavior proof before merge. :: [P2] Preserve unknown-outcome classification across Workboard replies
  • reviewed 2026-10-12T04:34:58.173Z sha e2d3659 :: needs real behavior proof before merge. :: [P2] Preserve unknown-outcome classification across Workboard replies
  • reviewed 2026-10-12T04:54:09.567Z sha e2d3659 :: needs real behavior proof before merge. :: [P2] Preserve unknown-outcome classification across Workboard replies
  • reviewed 2026-10-12T05:11:41.490Z sha e2d3659 :: needs real behavior proof before merge. :: [P2] Preserve unknown-outcome classification across Workboard replies
  • reviewed 2026-10-12T07:04:09.433Z sha 02be1c2 :: needs real behavior proof before merge. :: [P2] Preserve uncertain-outcome classification through Workboard replies | [P1] Include the new imports in the trusted wrapper source inventory | [P2] Use one owner for transaction-usability validation

Reviewed October 12, 2026, 4:50 AM ET / 08:50 UTC (Revision 9).

@steipete
steipete force-pushed the pgprep/postgres-engine-workboard branch from d047283 to 46a406a Compare October 11, 2026 18:30
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Oct 11, 2026
@steipete
steipete force-pushed the pgprep/postgres-engine-workboard branch from 9a8c7da to e2d3659 Compare October 12, 2026 04:26
@steipete
steipete force-pushed the pgprep/postgres-engine-workboard branch from e2d3659 to 02be1c2 Compare October 12, 2026 06:47
@steipete
steipete marked this pull request as ready for review October 12, 2026 06:48
@github-actions github-actions Bot added the dependencies-changed PR changes dependency-related files label Oct 12, 2026
@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Dependency graph changes

This maintainer PR changes the dependency graph.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: 7fcf90d43680776fcd422cb5fa2592ce66514366
  • Maintainer: @steipete
  • Repository role: admin

These dependency graph changes were made:

  • pnpm-lock.yaml
  • package.json

Carefully review these changes before merging.

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. label Oct 12, 2026
Keep the SQLite query-plan assertion typed to its native handle after adding the PostgreSQL connection variant.
@steipete
steipete merged commit 5e78ec6 into main Oct 12, 2026
218 of 226 checks passed
@steipete
steipete deleted the pgprep/postgres-engine-workboard branch October 12, 2026 09:22
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 13, 2026
…w#169214)

Add an experimental opt-in PostgreSQL engine for the workboard pilot through the existing SQL connection and store owners. SQLite remains the default; PostgreSQL transaction outcomes invalidate the anchor receipts without replaying uncertain writes.

Preserve the leaf dispatch boundary so shared SQLite modules do not import the PostgreSQL implementation. Narrow the SQLite-only query-plan test to its native handle.

Refs openclaw#169254. Focused and both workboard suites passed; the final test correction passed all 32 affected-file tests and independent review. The operator-authorized CI and REST fallback disposition, including unqualified QA cases and final-head CI coverage, is recorded in the PR body.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies-changed PR changes dependency-related files docs Improvements or additions to documentation merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. plugin: workboard rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. scripts Repository scripts size: XL status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant