Skip to content

fix(database): preserve session JSON semantics on PostgreSQL - #183560

Merged
steipete merged 2 commits into
mainfrom
pgprep/pgportguard-phase2
Oct 25, 2026
Merged

steipete merged 2 commits into
mainfrom
pgprep/pgportguard-phase2

Conversation

@steipete

@steipete steipete commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes PostgreSQL query failures when assigning session owners, reading worktree facts, checking active transcript inputs, rebasing prepared replies, repairing suffix idempotency, and navigating unindexed history.

User Impact

PostgreSQL-readiness preparation with preserved SQLite behavior. No schema, configuration, dependency, retention, transaction, or locking changes.

Why This Change Was Made

These readers still used SQLite-only JSON functions and non-NULL IS comparisons. Shared JSON dialect helpers now project the consumed fields, preserving first-versus-last duplicate-member behavior, raw revision tokens, malformed/deep JSON handling, and nullable scalar comparisons. The existing lexical scanner gains additive exact duplicate-key metadata. Transcript timestamps use the existing shared greatest helper.

Hot transcript reads retain compact native projections. Exceptional JSON that native decoding cannot preserve uses the existing scanner. Cold owner/worktree reads scan original text to preserve validation without constructing unrelated objects.

This is the owner-fix follow-up to #183296. The static portability guard will be a separate follow-up after the separately owned cron repair in #183508 lands; no guard, exemption marker, or baseline change is included here.

Evidence

  • New registered owner conformance tests: SQLite 8/8 passed on the base; PostgreSQL failed 7/8 with actual missing-function/syntax errors. Final SQLite + PostgreSQL 17 run: 16/16 passed (82.07 seconds Vitest, 431.77 seconds including worker build and verification).
  • A further SQLite regression caught a 41,311-character hot-row projection; the corrected helper returns under 100 characters and preserves NUL-suffixed labels. Numeric-affinity and deep-document regressions also failed before their corrections.
  • Existing owner/scanner tests: 46 passed on Blacksmith; core and infra-test typechecks passed. Wrapper source closure: 3 passed. Assertion-safety and line-cap checks passed without baseline growth.
  • pnpm test src/infra/database-engine/session-owner-portability.conformance.test.ts --maxWorkers=1: 4 SQLite passed, 4 PostgreSQL skipped in the default single-engine run; 3.23 seconds Vitest / 30.72 seconds wrapper. The explicit two-engine run above executes PostgreSQL.
  • pnpm test src/infra/database-engine/session-transcript-portability.conformance.test.ts --maxWorkers=1: 4 SQLite passed, 4 PostgreSQL skipped by default; 3.17 seconds Vitest / 30.59 seconds wrapper.
  • pnpm test src/state/json-predicate-fields.test.ts --maxWorkers=1: 19 passed, 2.17 seconds Vitest / 4.98 seconds wrapper.
  • Author simplification pass completed; final isolated Codex P0–P2 review is clean. Formatting, diff checks, and final narrow production lint passed (0 errors/warnings).

Table functions and aliases use Kysely expressions and typed column references in the shared JSON owner; no guard, baseline, or classification was changed. The full Kysely guard passes, and the dialect ratchet improves mechanical occurrences from 4 to 2 (design 22 to 15). Scoped typecheck and lint pass. A fresh isolated Codex P0–P2 review of the correction is clean.

Final-head CI 40191097468 passed: 52 successful jobs, 26 skipped jobs, zero failures. All three PostgreSQL conformance shards executed and passed (1/3: 20m43s; 2/3: 14m58s; 3/3: 16m51s). The single effective openclaw/ci-gate check passed on this head. No manual workflow was dispatched and no CI rerun was needed. The static portability guard remains a separate follow-up after #183508 lands.

@clawsweeper

clawsweeper Bot commented Oct 25, 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.

@steipete
steipete marked this pull request as ready for review October 25, 2026 11:31
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-25T12:00:59.328786Z 507105b New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 25, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 25, 2026
@clawsweeper

clawsweeper Bot commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR makes session ownership and transcript queries portable to PostgreSQL while preserving SQLite JSON semantics.

Example: Assign agent research as owner of session portable-owner with lifecycle revision owner-revision on PostgreSQL.

  • Before: The owner update fails because its RETURNING expression calls SQLite's json_extract function.
  • After: The update returns stored metadata, extracts the lifecycle revision through the existing scanner, and publishes the assignment.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, coherent repair with substantive real-engine regression coverage and no definite finding; evidence remains at the in-process owner boundary.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; supplied evidence covers the changed session owners on SQLite and PostgreSQL 17 through conformance tests, without a shipped-entry-point artifact.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: PostgreSQL session operations can fail instead of assigning owners, reading cleanup facts, navigating history, or validating continuation.
Reason: The maintainer-authored direction repairs demonstrated owned SQL failures while retaining existing SQLite behavior and public contracts.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR repairs concrete PostgreSQL failures still present on main, and the reviewed diff has no definite introduced defect.

Priority: P2
Reviewed head: 507105b8dce16bf86340344c939ec02bd829b88b

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied conformance runs exercise real database owners in process rather than a shipped CLI or Gateway session flow.
Agent review details

How this fits together

Session accessors read and update agent databases for ownership, worktree cleanup, transcript navigation, continuation, and replay protection; shared dialect helpers translate their JSON operations into SQLite or PostgreSQL SQL.

flowchart TD
  A[Session operations] --> B[Existing session accessors]
  B --> C[Shared JSON dialect helpers]
  C --> D[SQLite or PostgreSQL]
  D --> E[Selected JSON facts]
  E --> F[Lexical scanner]
  F --> G[Session decisions and publications]
Loading

Technical review

Best possible solution:

Retain the focused repair in the existing session and dialect owners, preserving exact JSON behavior and normal CI gates.

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

Current-main SQL exposes the PostgreSQL failure directly, and the PR records failing real-engine conformance runs; this read-only review executed no target code.

Is this the best way to solve the issue?

The repair uses existing owners and preserves first-versus-last member semantics through compact projections and the existing scanner, avoiding JSONB duplicate-key loss.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 2eb3b60 adds src/infra/database-engine/json-values.ts:19 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 2eb3b60d0bb7; files: src/infra/database-engine/json-values.ts)
  • Josh Lehman: Raw commit 68be5fd adds src/config/sessions/session-accessor.sqlite-transcript-suffix-idempotency.ts:19 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 68be5fdcd14b; files: src/config/sessions/session-accessor.sqlite-transcript-suffix-idempotency.ts)
  • Ayaan Zaidi: Raw commit 813b505 adds src/config/sessions/session-accessor.sqlite-transcript-parent.ts:121 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 813b5052fb05; files: src/config/sessions/session-accessor.sqlite-transcript-parent.ts)

PR surface

Source +313, Tests +686. Total +999 across 13 files. Added test files: 2.

View PR surface stats
Area Files Added Removed Net
Source 9 475 162 +313
Tests 4 686 0 +686
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 13 1161 162 +999

Review metrics

Metric Value Why it matters
Production versus regression coverage Production +475/-162 lines; tests and registration +686/-0 lines Growth primarily supplies shared duplicate-preserving projections and distinct real-engine regressions; no new state owner, schema, cache, or runtime option is introduced.

Labels

Label changes:

  • add P2: Concrete session-query failures affect PostgreSQL readiness, with a focused repair and no evidence of an urgent default-SQLite regression.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: Concrete session-query failures affect PostgreSQL readiness, with a focused repair and no evidence of an urgent default-SQLite regression.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp 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.

Reviewed October 25, 2026, 8:15 AM ET / 12:15 UTC.

@steipete
steipete merged commit 90fa9d5 into main Oct 25, 2026
161 checks passed
@steipete
steipete deleted the pgprep/pgportguard-phase2 branch October 25, 2026 12:43
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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