Repository navigation
fix(postgres): reopen shared-state workers after connection loss - #179128
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 SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d313fc8f2f
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (!nativeDatabase.db.isOpen && isPostgresSqlConnection(nativeDatabase.db)) { | ||
| throw new Error("Shared-state worker retained a closed PostgreSQL connection"); | ||
| } |
There was a problem hiding this comment.
Retire actors when the update writer loses PostgreSQL
When a restart or backend termination is first observed by the retained updateRunWriter while the primary nativeDatabase has not yet issued another query, this check misses the closed connection: createExistingPostgresStateWriter.assertSettled() permits db.isOpen === false, and the new condition examines only nativeDatabase.db. The actor therefore remains available with the same closed update writer, so subsequent updateRuns.* operations immediately fail with Existing-state writer is closed until the actor is otherwise retired or the Gateway restarts, breaking the recovery behavior for update bookkeeping. Make the PostgreSQL update writer's settlement check trigger actor retirement too.
AGENTS.md reference: AGENTS.md:L76-L76
Useful? React with 👍 / 👎.
|
Codex review: needs maintainer review before merge. What this changesReject closed primary PostgreSQL connections during worker settlement so subsequent requests can reopen shared state. Example: Terminate the PostgreSQL backend after writing reconnect.fixture = "before".
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it provides a focused recovery fix that current main lacks, with no introduced correctness defect found. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherShared-state operations enter a broker-managed worker, which retains database connections and returns operation results; settlement tells the broker when a failed worker must retire. flowchart LR
A[Shared-state request] --> B[Worker broker]
B --> C[Shared-state worker]
C --> D[PostgreSQL connection]
D --> E[Settlement check]
E --> F[Retire failed worker]
F --> B
Technical reviewBest possible solution: Keep closed-primary-handle rejection in the existing settlement owner, preserving failed-operation non-replay and SQLite settlement behavior. Do we have a high-confidence way to reproduce the issue? Source establishes the stuck-handle path, and the added real-PostgreSQL test supplies a concrete backend-termination reproduction; no target code was executed during this read-only review. Is this the best way to solve the issue? The three-line check is the smallest focused repair: it uses existing settlement and retirement owners without adding replay, state, or healthy-path database work. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against aeae6d1d79a3. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +3, Tests +56, Docs +2. Total +61 across 3 files. Added test files: 0. View PR surface stats
Review metrics
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 October 21, 2026, 2:32 AM ET / 06:32 UTC. |
…nclaw#179128) Reject closed PostgreSQL handles in the primary shared-state and update-bookkeeping settlement owners so the existing worker retirement path can reopen a connection for a later operation. Do not replay interrupted writes; preserve SQLite closed-wrapper behavior. Real Gateway fault replay recovers fresh turns after backend termination and fast restart without restarting the Gateway. Regressions are red before each owner correction and pass after it: 13 PostgreSQL state tests and 23 SQLite tests. All three PostgreSQL conformance shards passed on the final head. Final CI retains the inherited root-tooling TS2345 failures at ci-changed-node-test-plan.test.ts:813,891, independently reproduced on clean main 99969d3. Security, lint, and other typechecks passed; landed under the authorized inherited-failure exception.
What Problem This Solves
After a PostgreSQL backend is terminated or the server restarts, a shared-state worker can retain a closed connection and reject later operations until the Gateway restarts. Both its primary native handle and its separately retained update-bookkeeping writer accepted a closed PostgreSQL connection during settlement, so the existing worker retirement and reopen path never ran.
Reject closed PostgreSQL handles in their settlement owners. The broker retires the failed actor, and a subsequent operation opens a fresh owner; the interrupted operation is never replayed. SQLite's intentional closed-wrapper behavior is preserved. The PostgreSQL troubleshooting guide describes the recovery behavior.
Evidence
76ce4df44eb8. The additional updater regression is red on the unchanged updater owner at the earlier PR headd313fc8f2f24, withExisting-state writer is closed. It uses the production async update API, terminates only the updater backend, verifies the other idle backends stay untouched and the previous value survives, then requires a fresh write to succeed.Fresh isolated P0–P2 review is clean. Final-head CI39564974568 on
c99e5e2ce5928cef1f4c42076bfeb9ed20b7d62factually executed and passed all three PostgreSQL conformance shards. Security, lint, production types, source contracts, and the other test-type stripes passed.The CI gate remains red solely for the inherited root-tooling errors in
test/scripts/ci-changed-node-test-plan.test.ts:813,891:CompactNodeTestShardlacksconfigsrequired byChangedNodeTestShard. The exact four diagnostic lines were independently reproduced on clean main5e9c3fbfd6a2359f5980e75688c08c23a17af592withnode scripts/run-tsgo.mjs --noEmit -p test/tsconfig/tsconfig.test.root.tooling.json(exit2). This PR changes neither the planner nor those tests. Landing uses the authorized inherited-failure exception; the failed CI result is retained.Pr-simplify retains the existing lifecycle owners and one table-driven real-PG regression covering the two retained participants. No SQL, transaction, advisory-lock, schema, or durability changes. Added healthy-path requests / wire trips / SQL: 0 / 0 / 0 by source inspection, with no throughput or latency optimization claim. Production +7/−1 lines, tests +114, documentation +5/−3.