Repository navigation
fix: keep PostgreSQL leases alive during lock contention - #201853
Conversation
|
🦞👀 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. |
|
Codex review: needs maintainer review before merge. What this changesThis PR classifies PostgreSQL lock, deadlock, and serialization failures as BUSY errors so existing contention handlers can recover. Example: A 210-second PostgreSQL-backed lease encounters the default 60-second lock timeout during renewal.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this PR repairs a current PostgreSQL contention-classification bug with a focused change and meaningful regression coverage; no actionable patch defect was found. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe PostgreSQL adapter translates server errors into the shared SQL contract consumed by transaction, heartbeat, and cleanup owners. flowchart TD
A[Lease operation] --> B[PostgreSQL transaction owner]
B --> C[PostgreSQL server]
C --> D[Error decoder]
D --> E[Shared BUSY classification]
E --> F[Existing lease contention handling]
Technical reviewBest possible solution: Retain the narrow decoder mapping and let the existing transaction and lease owners handle rollback, expiry checks, and retries. Do we have a high-confidence way to reproduce the issue? The decoder and heartbeat source establish the failure path, corroborated by the author's real PostgreSQL before-and-after worker run; this review executed no target code. Is this the best way to solve the issue? The patch fixes classification at its existing producer, preserves SQLSTATE diagnostics, and introduces no competing retry owner or transaction replay. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 82e7c3d5ac6a. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +8, Tests +76. Total +84 across 3 files. Added test files: 1. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel 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 Reviewed November 19, 2026, 8:56 AM ET / 13:56 UTC. |
|
Merged via squash.
|
…1853) Co-authored-by: VACInc <[email protected]>
Co-authored-by: VACInc <[email protected]> (cherry picked from commit db7d0db) Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit a5597470207a37e1c934f3a627988201824ec992)
Summary
High Level TLDR
A PostgreSQL lock timeout can stop a healthy lease heartbeat while its stored lease is still valid. Translate lock, deadlock, and serialization errors into the adapter's existing BUSY error shape so lease and transaction owners use their contention handling.
Root Cause
decodePostgresErrortranslates constraint failures but leaves SQLSTATEs55P03,40P01, and40001unclassified. Existing contention handlers recognize SQLite BUSY/LOCKED result codes. Consequently, the heartbeat reportsoperation-errorand loses ownership; lease cleanup does not schedule its retry.The change is confined to the PostgreSQL decoder. It retains the server error and SQLSTATE in
cause, consistent with constraint translation. Cancellation (57014), connection-loss handling, persisted expiry checks, and timeout settings are unchanged. This adds no retry loop or transaction replay inside the adapter.Real behavior proof
RAN on Node 26.13.1 and a disposable PostgreSQL 18 server with a private Unix socket:
withOpenClawStateLeaserun uses a worker heartbeat, a 210-second lease, and the default 60-second server lock timeout. Hold the store advisory lock before its first scheduled renewal, wait 132 seconds, then release it. Before:lease aborted after contention: true, withOPENCLAW_STATE_LEASE_LOSTand SQLSTATE55P03. After:lease aborted after contention: false; automatic renewal advances the persisted expiry after lock release, and ownership verification succeeds.Focused command, with the repository database-conformance preload selecting the disposable connection:
Result: 121 tests passed across four files. New integration test body: 109 ms; protocol suite: 187 ms. Full invocation: 95.19 s, including 75.55 s of cold worker-artifact preparation.
A decoder/classifier benchmark used 1,000 warmup errors, then five samples of 10,000 errors each, on the same machine. Median lock-error handling was 1.34 microseconds before and 3.24 microseconds after. This measures the extra error wrapper, not healthy transaction throughput.
What was not tested
Verification
git diff --check.Evidence
RAN: local autoreview of the complete three-file change against
3587df70a233dc639b733b9169797d3abd138301, including the untracked regression before commit. P0-P2 coverage;scoped-clean, no actionable findings. The unchanged reviewed snapshot is committed as7045cdfafdabd9b7248d45bf0ad40e790cc1d09a. Local ClawSweeper was unavailable. The hosted review completed on the same head with no findings: #201853 (comment)Exact-head CI completed successfully, including all five PostgreSQL conformance jobs: https://github.com/openclaw/openclaw/actions/runs/44535887329
Final check snapshot: 68 passing checks, 67 skipped, none pending or failed;
openclaw/ci-gatepassed. Independent maintainer review is still required before merge. No merge or auto-merge was requested.