Repository navigation
fix: keep database workers healthy after silent connection loss - #201856
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 adds TCP keepalive and request-budget-aware connection cutoffs so silent PostgreSQL transport loss does not reset healthy peer connections. Example: A proxy forwards COMMIT but silently discards its reply.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR addresses a real PostgreSQL failure boundary that remains on current main; the reviewed changes preserve uncertain-write handling, and no actionable correctness or security findings remain. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe synchronous PostgreSQL adapter sends database operations over message ports to four shared I/O workers, which execute them through node-postgres and return results or transport failures. flowchart LR
A[Database store owner] --> B[Synchronous connection]
B --> C[Request with deadline]
C --> D[Shared I O worker]
D --> E[PostgreSQL client]
E --> F[PostgreSQL server]
D --> G[Connection result or failure]
G --> B
Technical reviewBest possible solution: Land the connection-local cutoff through the existing bridge owner, then integrate the documented maintenance-budget resolution in #201869. Do we have a high-confidence way to reproduce the issue? Source shows that a lost reply can reach the service-wide watchdog; supplied base-red and head-green transport traces corroborate the path, without reviewer execution. Is this the best way to solve the issue? The patch places the cutoff in the existing transport owner, derives its budget from the host, and preserves reconnect-before-SQL and no-replay boundaries without adding another recovery layer. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 31ce94f0ad89. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +28, Tests +172, Docs +9. Total +209 across 7 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: 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 (1 earlier review cycle)
Reviewed November 20, 2026, 1:17 PM ET / 18:17 UTC (Revision 2). |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…claw#201856) * fix: keep database workers healthy after silent connection loss * fix: bound silent PostgreSQL requests by the host deadline --------- Co-authored-by: VACInc <[email protected]>
) Baseline adaptation: Keep one worker per connection; bound startup and transport failure without adding shared services, idle borrowing, or write replay. Preserve existing outcome-unknown classification. (cherry picked from commit a80b564) Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit a9832c21d032063a55ff697d959448233683f3b3)
…law#194384) * docs: clarify PostgreSQL conformance coverage * fix(cron): keep one-shot finalization working on PostgreSQL 16 * test(database): reuse cron conformance for JSON conversion regression * test(postgres): accept fractional explain row counts (cherry picked from commit 7ab0143) Release adaptation: Only engine-owned jsonValue and retained cron enabled JSON replacement; preserve native boolean type with PG16 explicit ::json and SQLite json(). Omit unrelated PG docs/EXPLAIN test edits; retained one-shot enabled-transition caller present on baseline. Follow-up dispositions: e029e18 docs: document isolated PostgreSQL restore drills (openclaw#202704); 49f0740 fix(database): report disabled memory after a port (openclaw#202630); a80b564 fix: keep database workers healthy after silent connection loss (openclaw#201856); 3d91af2 fix(config): reject reserved PostgreSQL schema prefixes (openclaw#202097); 835d722 fix: catch incompatible ownership before porting to SQLite (openclaw#202101); 67796a6 fix: keep scheduled Git backups current on PostgreSQL (openclaw#201870); cc849dd fix: recover lease heartbeats after a PostgreSQL connection loss (openclaw#201858); 6594caf fix: prepare macOS runtime pins without the PostgreSQL secret (openclaw#202102); 6ca56cd docs: clarify PostgreSQL storage and backup coverage (openclaw#202086); a079190 fix(postgres): chat history slows under concurrent reads (openclaw#190129); 2ff4256 feat(database): keep PostgreSQL rollback captures in PostgreSQL (openclaw#196236); 96c685b feat(backup): restore PostgreSQL stores into a staging database for restore drills (openclaw#194808); fb83d65 fix: reduce transcript allocation when preparing native context seeds; 71ec4d2 fix(config): keep Workboard PostgreSQL upgrades readable (openclaw#194648); b6ed907 perf(sessions): persist active transcript facts for hydration (openclaw#193682) Validation: Baseline cron generated json(bound text) on PostgreSQL where json(text) is unavailable; helper and focused boolean regression retained. Exact PostgreSQL16 server proof unavailable; focused SQLite/helper tests queued. diff check passed. Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit 38fdd9b52704d588d9ca24ef8e391d644961c985) (cherry picked from commit fb935e6912388314851b05cb698ef038b83bbd07)
Summary
High Level TLDR
A silent database connection could block a worker for two minutes and then reset healthy connections on the same I/O service. Enable TCP keepalive and retire the silent connection before the host watchdog fires, so ordinary transport loss fails only the affected connection. The worker's cutoff now follows the deadline the host sends with each request, so longer maintenance requests from #201869 are not cut at the ordinary 100 seconds. Idle validation can reconnect before caller SQL; a lost commit reply remains uncertain and is never replayed.
deadlineMs, the time left before the host resets the I/O service. For query and recovery-generation requests, the worker ends that request's client 20 seconds before the deadline. With runtime defaults: deadline 120 s, cutoff 100 s, server statement timeout 90 s (unchanged).Root Cause
The data bridge configured a connection timeout and server statement timeout, but no client query timeout or TCP keepalive. A server timeout cannot deliver an error through a black-holed return path. The host's 120-second watchdog therefore became the first effective bound and retired the entire assigned service.
The regression reaches the real synchronous connection through a socket proxy. It forwards a transaction's COMMIT to a disposable server and discards the reply. On the base, the call took 120001 ms, failing the under-20-second assertion.
The first revision of this PR fixed that with a fixed client
query_timeoutof statement timeout + 10 s. That bound is set once per connection and cannot see a longer request budget. #201869 gives maintenance transactions (migrations, search rebuilds, search-extension admission) a one-hour transaction-local statement timeout and a one-hour-plus-30-second host deadline. Combined with the fixed client bound, every maintenance statement over the ordinary cutoff would be killed on the client. On a scratch merge of the two earlier heads, a maintenancepg_sleep(12)on a connection with a 1-second runtime statement budget failed after 11078 ms withPostgreSQL connection lost; transaction rolled back.This revision makes the host the single owner of the request budget. The host deadline is now the connection's statement timeout plus 30 seconds (still 120 s in production, where the statement timeout is always 90 s), it is sent with each request, and the worker's per-request timer ends the client 20 seconds early. Ending the client fails the pending query without an SQLSTATE, which the host already classifies as connection loss with the existing outcome-unknown rules.
Real behavior proof
RAN on Linux against a disposable PostgreSQL 17 server (loopback and Unix socket only), through
node scripts/test-database-conformance.mjs --engine postgres --connection <disposable DSN> -- <files>.This PR alone at the exact pushed head,
src/infra/postgres-sync(all 11 files):SELECT pg_sleep(12)underSET LOCAL statement_timeout = '1h'. With the previous worker it failed after 11067 ms (PostgreSQL connection lost; transaction rolled back); with this worker it returns after 12 s.Combined with #201869 (local scratch merge, not pushed; the only conflict is the deadline line in
connection.ts, resolved as below),src/infra/postgres-syncplussrc/infra/database-engine:A second scratch merge against #201869's current head (which merged
mainfor an unrelated conflict) passedsrc/infra/postgres-sync, the schema-admission, search-extension, search-conformance, search-admission and port-command PostgreSQL suites, and the memory search-rebuild suite: 45 + 160 + 2 passed, including the lost-commit-reply port case. The numbers above are from that run except the 156 ms admission case (first run).The maintenance case is a real
runTransaction(..., { maintenance: true })on a connection with a 1-second runtime budget; it ran past the old 11-second cutoff, andSHOW statement_timeoutreturned1safterward. The combined database-engine run had 15 local failures, all environmental and rechecked: 14 from this host's group-writable temp directories (passed after rerunning withumask 022) and 1 lost-reply proxy case that needs a TCP listener (failed the same way on the base revision; passed on the combined branch once the disposable server listened on loopback).Combined resolution of the deadline line:
Landing order
Land this PR first. #201869 then needs
mainmerged with the resolution above (code conflict only in that line and its import; docs merge cleanly). Either PR alone is safe: this one alone keeps production at 100 s / 120 s, and #201869 alone has no client cutoff.What was not tested
Verification
node scripts/run-tsgo.mjs -p tsconfig.core.jsonand-p test/tsconfig/tsconfig.core.test.infra.json: passed.node scripts/run-oxlint.mjson changed files,oxfmt --check,git diff --check: passed.connection.test.ts,protocol.test.ts,bridge-prestart.test.ts: passed (message expectations now includedeadlineMs).3587df70a23: scoped-clean, no actionable findings.8430fc80d91: SUCCESS, including all four PostgreSQL conformance shards and the PostgreSQL 16 smoke.