Skip to content

fix(database): allow PostgreSQL reads during anchor writes - #175389

Merged
steipete merged 1 commit into
mainfrom
fix/postgres-anchor-read-admission-20261017
Oct 17, 2026
Merged

steipete merged 1 commit into
mainfrom
fix/postgres-anchor-read-admission-20261017

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes PostgreSQL-backed Gateway reads failing with database is locked when cold anchor admission overlaps another writer.

User Impact

Existing PostgreSQL stores can open for reads while another handle holds write admission. Anchor creation remains transactional; missing or malformed anchors, schema drift, identity mismatches, and revoked authority keep their existing refusals. No migration, configuration change, or timeout increase is required.

Why This Change Was Made

Existing-only opens reused the anchor-creation path and unnecessarily requested BEGIN IMMEDIATE before reading an immutable identity. The opener now runs the same validation without that writer transaction for existing-only admission. The new regression uses a real PostgreSQL store and two SQLite handles with cold admission and a held writer lock.

This follows main hourly 39017848352. The original Gateway file passes on both main and a local reversal of #175295; the unforced CI timing has not been reproduced locally. The controlled regression fails at BEGIN IMMEDIATE even with #175295 reversed. That lock-taking path dates to #169933. This repairs the demonstrated owner defect without claiming a recent commit conclusively caused the CI timing.

The related publication/queue failure is fixed by landed commit 598e446.

Evidence

  • Before fix: real two-handle cold-anchor test fails with SQLite error 5 at BEGIN IMMEDIATE, including with fix(state): retain schema and disposal refusals during cold admission #175295 reversed (27.47 s command wall).
  • After fix on main containing 598e446: 18/18 PostgreSQL schema/Gateway tests pass through the native conformance runner (--maxWorkers=1, 187.50 s command wall); new regression 344 ms. Retained opener proof adds 4/4 tests. Earlier complete three-file run: 22/22, 75.33 s.
  • Full publication file on landed helper: 25/25 on CI's Node 24.19 (--maxWorkers=1, 198.16 s command wall). During investigation all 22 helper consumers passed, 337 tests in 537.12 s; the helper repair itself is already on main.
  • Targeted infra test type graph, source-backed core type-aware lint, boundary lint, formatting, whitespace checks, and independent P2 review pass. Final PostgreSQL files match the reviewed source byte-for-byte.
  • A refreshed proof launch initially ran before the disposable PostgreSQL container finished initialization; it reached no tests. After checking readiness, the run above completed. No CI rerun or dispatch.

No assertions were weakened, cases removed, retries added, or timeouts changed. The production diff extracts the existing validation body and selects its non-writing path for existing-only admission; no new owner, API, imports, schema, dependency, or configuration. PR CI supplies broad proof.

Existing-only opens validate the immutable anchor without BEGIN IMMEDIATE. Creation retains its transaction and all identity, schema, and admission refusals remain.

A real two-handle cold-admission regression fails before the fix even with #175295 reversed. Native PostgreSQL schema and Gateway tests pass 18/18 on the refreshed base (187.50s command wall; regression 344ms), plus retained opener proof 4/4. Targeted types, core/boundary lint, format, and P2 review pass.
@clawsweeper

clawsweeper Bot commented Oct 17, 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 17, 2026 09:34
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 17, 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-17T09:36:45.750680Z a9e733f Draft marked ready
ℹ️ 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. 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 17, 2026
@clawsweeper

clawsweeper Bot commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR validates existing PostgreSQL anchors without acquiring a SQLite writer lock while preserving transactional anchor creation.

Example: A cold PostgreSQL reader opens an existing anchor while another SQLite handle holds BEGIN IMMEDIATE.

  • Before: Opening the reader fails with database is locked before it can query PostgreSQL.
  • After: The reader validates the existing identity and reads the PostgreSQL row successfully.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, source-correct repair with a meaningful real-database regression; supplied behavioral evidence remains conformance-harness based.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; supplied evidence reports real PostgreSQL conformance execution through the changed opener, with no shipped Gateway capture supplied.
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-backed Gateway reads can fail with database is locked while opening an existing local anchor.
Reason: The maintainer-authored change restores useful concurrent reads through the shared owner without adding configuration or changing stored formats.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR fixes a concrete lock-contention defect still present on current main. No introduced correctness or security defect was found; CI remains unresolved.

Priority: P2
Reviewed head: a9e733f3d100775109c5fcb0414bd79053f6e6b3

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied execution evidence covers the real database owner through conformance tests rather than a shipped Gateway read under anchor contention.
Agent review details

How this fits together

The shared database-engine opener receives a store schema, engine configuration, and local SQLite anchor, then returns an admitted SQLite or PostgreSQL connection to state, agent, and plugin owners.

flowchart TD
  A[Store owner] --> B[Shared engine opener]
  B --> C[Existing anchor validation]
  B --> D[Transactional anchor creation]
  C --> E[PostgreSQL admission]
  D --> E
  E --> F[Store queries]
Loading

Technical review

Best possible solution:

Use the existing opener's read-only anchor validation for existing-only admission and retain its transaction for creation.

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

The main-source path requests a conflicting writer lock during existing-only admission, and the supplied regression establishes the corresponding two-handle trigger; the PR reports before/after execution, which this read-only review did not independently run.

Is this the best way to solve the issue?

The change repairs the shared admission owner directly, preserves all existing validation, and avoids retries, timeout increases, or a competing opening path.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Cold PostgreSQL anchor admission changes intended behavior with a stated reason (9dc6466: The merged adapter extraction centralized engine selection, anchor identity, bootstrap, and admission; its immediate transaction protected anchor creation.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Focused introduced change: The pinned introduction diff extracts the existing validation unchanged and bypasses the immediate transaction only when existingOnly is true; creation retains the transaction. (src/infra/database-engine/open.ts:178, a9e733f3d100)
  • Current main still contains the defect: Current main unconditionally requests an immediate SQLite transaction for cold PostgreSQL anchor admission, including existing-only opens. (src/infra/database-engine/open.ts:138, 354a9cc009c8)
  • Meaningful production-owner regression: The added test revokes warm admissions, holds a writer transaction on one real SQLite handle, opens the existing anchor through another handle, and checks an independently expected PostgreSQL value of 1. (src/infra/database-engine/schema-admission.postgres.test.ts:77, a9e733f3d100)
  • Real caller and retained safeguards: Existing-state PostgreSQL connections already request existingOnly, and the patch leaves metadata identity, schema admission, migration custody, and caller-owned access checks unchanged. (src/state/openclaw-state-db-engine.ts:244, a9e733f3d100)
  • Original intent and feature history: The shared opener's transaction is present in the merged adapter extraction, whose purpose was common engine ownership and safe admission: feat(database): share experimental database engine adapters #169933. Subsequent merged opener and schema-admission history consistently identifies steipete as the area contributor. (src/infra/database-engine/open.ts:138, 9dc64662f16e)
  • Supplied validation and current CI: The complete PR body reports controlled before-fix failure and after-fix PostgreSQL schema/Gateway passes. Live exact-head checks still show four failed mocked-UI jobs and pending PostgreSQL infra conformance; annotations concern deferred mock responses, rendering budgets, row presentation, and model display. Matching base failures were not established, so these are not attributed to the patch or declared inherited. (a9e733f3d100)

PR surface

Source +3, Tests +37. Total +40 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 46 43 +3
Tests 1 37 0 +37
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 83 43 +40

Labels

Label changes:

  • add P2: A concrete contention failure affects cold reads on PostgreSQL-backed stores, with a narrow repair and limited engine-specific blast radius.
  • 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: A concrete contention failure affects cold reads on PostgreSQL-backed stores, with a narrow repair and limited engine-specific blast radius.
  • 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 17, 2026, 5:50 AM ET / 09:50 UTC.

@steipete
steipete merged commit 79151aa into main Oct 17, 2026
206 of 213 checks passed
@steipete
steipete deleted the fix/postgres-anchor-read-admission-20261017 branch October 17, 2026 09:55
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 18, 2026
…175389)

Existing-only opens validate the immutable anchor without BEGIN IMMEDIATE. Creation retains its transaction and all identity, schema, and admission refusals remain.

A real two-handle cold-admission regression fails before the fix even with openclaw#175295 reversed. Native PostgreSQL schema and Gateway tests pass 18/18 on the refreshed base (187.50s command wall; regression 344ms), plus retained opener proof 4/4. Targeted types, core/boundary lint, format, and P2 review pass.
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: S 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