Repository navigation
fix(database): make shared-state queries portable to PostgreSQL - #170055
Conversation
|
Codex review: needs maintainer review before merge. What this changesThis PR replaces SQLite-specific shared-state queries and mutation bookkeeping with portable SQL and engine-owned JSON helpers. Example: Cron retention selects terminal receipts after the newest 64 records on PostgreSQL.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it delivers useful, maintainer-directed PostgreSQL portability work that current main still needs, with no actionable introduced defect found. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherShared-state owners compile and execute storage queries through the database adapter, returning bounded records and publishing committed mutation facts to Gateway consumers. flowchart TD
A[Shared-state consumers] --> B[Domain storage owners]
B --> C[Kysely queries and JSON helpers]
C --> D[Database engine adapter]
D --> E[SQLite default]
D --> F[Experimental PostgreSQL]
B --> G[Committed change publications]
Technical reviewBest possible solution: Land the bounded portability changes through the recorded CI exception while keeping shared-state PostgreSQL activation with its admission owner. Do we have a high-confidence way to reproduce the issue? Current-main source directly exposes PostgreSQL-incompatible LIMIT, JSON, and mutation-counter operations; this read-only review executed no target code. Is this the best way to solve the issue? The patch uses existing domain and engine owners, preserves SQL-side payload bounds and retention predicates, and removes the replaced mutation-counter path without expanding backend activation. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 04d4e9cd3fbf. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +152, Tests +51, Docs +1, Other +10. Total +214 across 20 files. Added test files: 1. View PR surface stats
Review metrics
LabelsLabel changes: No label changes. Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (5 earlier review cycles)
Reviewed October 12, 2026, 4:15 PM ET / 20:15 UTC (Revision 6). |
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
…claw#170055) Replace SQLite-specific shared-state consumer SQL with portable owner-built statements and engine-owned JSON fragments. Preserve SQLite retention, projections, publication, and update behavior. Regenerate the database worker inventory and classify the portable SQL guard boundaries. PostgreSQL activation remains behind separate admission work. Reviewed owner proof covers SQLite behavior and 20 PostgreSQL PREPARE/EXPLAIN statements. Required CI exceptions and the unverified Slack timeout comparison are documented in the PR body.
Related: #169254 and #169933.
What Problem This Solves
Shared-state consumer queries fail on PostgreSQL because they still rely on SQLite-specific SQL and connection-global mutation bookkeeping.
User Impact
SQLite remains the default with the same retention, projections, publication, and update/rollback behavior. These changes remove SQL blockers for the experimental PostgreSQL backend; shared-state activation and end-to-end PostgreSQL validation remain held behind separate admission work.
Why This Change Was Made
The seven consumer paths now use portable owner-built statements and engine-owned JSON fragments. Large JSON projections stay in SQL before payload transfer, and PostgreSQL rejects NUL plugin keys with an explicit error.
Owner changes and scope left for follow-up
No schema, retention, admission, or update migration changes. Existing SQLite data and rollback behavior are unchanged. PostgreSQL shared-state execution remains held behind the separate admission work; this PR does not claim end-to-end PostgreSQL readiness.
Scope left with its owner
Evidence
The external harness calls the actual owners against a capture-only PostgreSQL-branded connection, then PREPAREs and EXPLAINs their compiled SQL and bound parameters on PostgreSQL 17 against
pnpm db:postgres:genshared-state DDL. No SQL is rewritten by the harness. Worker mutation builders are unchanged; five representative shapes additionally pass the same proof.Scoped lint/format, madge (zero cycles), and
git diff --checkpass. Independent autoreview found no actionable P0–P2 issues. SQLite transcript proof: 3 files / 50 tests pass (426.62s Vitest duration; 683.14s total wrapper wall time including 213.34s cold bundle preparation). Cron proof: 3 files / 21 tests pass (414.77s Vitest duration). Placement grants: 14/14 pass. The new PostgreSQL-key guard test passes. Delivery/plugin-state infra proof covered 94 cases, with the observation-only correction and focused rerun described below.Focused SQLite proof covers 256 unique cases across 19 files. Worker-environment proof covers 7 files / 76 passing cases: the 5 publication cases plus 71 cases across 6 supplemental owner files (1268.30s Vitest duration; 1300.48s wrapper wall time for the supplemental run).
Changed-test timing:
pnpm test src/plugin-state/plugin-state-store.kernel.test.ts --maxWorkers=1(run in the focused batch) took 32.74s in its one-file Vitest project, including 2.41s of test execution.pnpm test src/gateway/worker-environments/store-change-events.test.ts --maxWorkers=1passed 5/5 cases: 437.31s Vitest duration, 62.66s test execution, 477.35s total wrapper wall time including cold build/setup. The existing public store/worker/session-projection composition is needed to prove commit publication, rollback, RETURNING-only changes, and no-op suppression; no sleeps or new timers were added. Cold worker bundle preparation took about 213–215s. CI seconds are pending the draft PR run.Production: +258/-106 (net +152); tests: +63/-12 (net +51). No files in the async-DB overlap list were touched. The PostgreSQL cluster was stopped and removed after proof; the harness and per-statement plans remain outside the repository.
The shrink-only dialect ratchet compares source against Git, with no editable baseline file: mechanical 1 → 0; design 0 → 0; engine-maintenance 0 → 0 in the changed-file scope. JSON calls hidden in Kysely function builders are outside that lexical census and are covered by the statement proof above.
The initial delivery suite exposed an observation mismatch: its query-plan test only located uppercase
WITH, while Kysely emits lowercasewith. The observer now matches SQL keywords case-insensitively and retains the original index-plan, namespace, and retained-row assertions. The initial infra batch had 93 passing cases and this one failure; both affected count-limit cases passed after the correction (200.26s Vitest duration, 97% transform/setup; the other 20 cases were filtered because their valid initial results were retained). Production SQL and the PostgreSQL statement proof were unchanged.The initial draft skipped broad CI. After prerequisite #170037 merged, main was merged into this branch and the PR was marked ready; final CI evidence is recorded below.
Ownership correction and refreshed proof
Head
661a90e2d661f3568ccc0520870e30a6b33e8ba5removes the transcript-specific engine leaf. GenericjsonExtractText,jsonOrderedTextArray, andjsonRemoveKeylive indatabase-engine/json-values.ts; the transcript owner supplies its field keys and ordering. All helper connection parameters useDatabaseSync | PostgresSqlConnection.The notes consumer checks payload size and then calls
JSON.parse(row.summary)rather than comparing serialized JSON bytes. The PostgreSQL key-removal branch documents that JSONB normalizes key order/whitespace and keeps the last duplicate key; parsed values agree, while serialized length/order may differ. SQLite aggregation continues to consume the transcript owner’s sorted input.Before/after capture of the actual owners proves byte-identical compiled SQLite SQL and bindings for transcript entry, latest entry, notes, and plugin batch reads (4/4). The three refreshed transcript statements pass PostgreSQL 17 PREPARE + EXPLAIN against regenerated shared-state DDL. The throwaway unix-socket cluster on port 55438 was stopped and removed.
Focused rerun:
pnpm test src/transcripts/library.test.ts src/transcripts/library.search.test.ts src/transcripts/library.query-budget.test.ts src/plugin-state/plugin-state-store.test.ts src/plugin-state/plugin-state-worker.test.ts src/plugin-state/plugin-state-store.kernel.test.ts --maxWorkers=1: 6 files / 70 cases passed, 614.76s wrapper wall time, including 122.47s cold worker preparation (unit 17.03s; infra 437.12s). This covers 27 transcript cases and 43 plugin-state cases.pnpm test test/scripts/eager-import-closure.test.ts -t "PR wrapper inventory" --maxWorkers=1: 1 case passed, 37.39s wrapper wall time. Core oxlint, oxfmt,git diff --check, and madge (zero cycles) pass. The second autoreview round is clean. The ratchet remains mechanical 1 → 0, design 0 → 0, engine-maintenance 0 → 0. This revision adds nine net production lines, bringing the full PR to +152 net production lines.Landing validation and CI exception
The single CI repair is
cfa039480e516: operation-scoped database inventory classification, regenerated inventory documentation, and SQL allow-comments placed directly on their existing expressions. SQL and runtime behavior are unchanged. Kysely guardrails, the database worker ratchet (T1 481 → 481), formatting, line-cap ratchet, and independent Codex review pass.Final CI run: 38298012289, exact head
cfa039480e516c3db987fc23f5afb68fa15af5f4. The repaired guard jobs pass; no jobs were cancelled. The authorized native admin exception covers the following remaining failures; CI is not described as green:checks-node-changed-compact-large-17checks-node-changed-compact-large-2checks-ui-e2e (6/7)session-list-row-events.e2e.test.tsexpects compact rows and receives sidebar rows. The test installs a mock Gateway; the PR does not change its UI files or execute backend SQL in this flow.checks-node-changedThe Slack timeout remains an attribution gap, not a passing test or an empirically proven inherited failure. Landing follows the delegated policy that only a proven causal-path product regression stops this campaign; none was demonstrated. The required aggregate gate fails downstream of the four jobs above.