Skip to content

chore(postgres): verify final-delivery crash recovery - #196781

Merged
vincentkoc merged 5 commits into
mainfrom
test/postgres-receipt-crash-recovery-20261111
Nov 10, 2026
Merged

vincentkoc merged 5 commits into
mainfrom
test/postgres-receipt-crash-recovery-20261111

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

PostgreSQL recovery lacked whole-Gateway crash coverage between a committed final-delivery receipt and queue acknowledgement.

User Impact

No production behavior, SQLite schema/version, migrations, persisted formats, or runtime config/defaults change. This qualifies queued-output recovery; it does not establish end-to-end agent RPC delivery or remote exactly-once acceptance.

Why This Change Was Made

Use real Gateway processes and workers, a synthetic transport, and independent PostgreSQL reads to hold ACK before execution, verify the durable receipt, SIGKILL the Gateway, and require successful ACK after cold restart without another send. Existing startup preflight prepares the empty store; an independent native PostgreSQL query requires its webhook migration completion before seeding. Parent workers drain before ownership passes to each real Gateway. Restart advances only the Gateway clock past the queue lease, so platform lease reclaim is outside this proof.

Extends worker ACK-response-loss coverage to a full Gateway crash before ACK executes. Move the existing 20 safety cases into canonical SQLite/PostgreSQL conformance instead of duplicating them. Production LOC delta is zero; the allocation grants exactly the +298 test LF bytes.

Evidence

Earlier qualification of the same delivery/crash/recovery boundary, with an additional empty Gateway process used for preparation:

Backend Recovery safety matrix Gateway crash recovery
SQLite 20 passed PostgreSQL-only process test
PostgreSQL 16.15 20 passed New crash case passed
PostgreSQL 17.11 20 passed 8 Gateway tests passed, including the new crash case
PostgreSQL 18.6 20 passed New crash case passed

That task-owned Testbox qualification also passed catalog/schema parity, targeted formatting, lint and affected Gateway/infra test type graphs. Canonical discovery selects the new matrix exactly once.

CI at the earlier head exposed a PR-caused 90-second timeout in the new three-boot case under concurrent PG17 infra load; its subsequent isolated PG16 Gateway module passed all eight cases. The exact stalled phase remains unknown. Auto-merge was retired before repair.

An intermediate preparation variant entered the full parent-side bootstrap helper and failed on PG17 and PG16: runtime secrets discovery attempted a synchronous PostgreSQL metadata read. The helper had not adopted the preflight plugin cache as the real CLI does; this establishes fixture caller-contract misuse, not a demonstrated production defect.

Latest repair 7209846fe5dbbfda03381db0ecb83445cd43529d prepares only through the real migration preflight, awaits its transferred plugin-cache disposal, drains parent resources, independently verifies persisted completion, and installs both the returned snapshot and engine selection before seeding. Both real delivery/recovery processes and every receipt, queue, SIGKILL, ACK, no-resend assertion and deadline remain. An attempted registry transfer exposed overlapping CLI/infra ownership in watch/full-suite checks; those routing/planner changes are fully reverted in the final diff.

Fresh independent review of the latest correction reports zero actionable findings (0.90 confidence); primary and bounded lifecycle review checked preflight ownership, cache disposal, engine handoff and resource drains directly. Exact-head ClawSweeper review also reports zero findings. Its rank-up item is completed PostgreSQL qualification and affected static checks.

Current-head formatting, lint/types, privacy and diff checks pass. The test-line ratchet fails on 128 inherited lines: exact CI base 0c5c4754c33dd9a9e7f4eb4493d4472d458a4609 contains 6,635,176 test LF against a 6,635,048 ceiling. This PR adds 298 LF with an exact 298 grant, producing 6,635,474 / 6,635,346 and preserving the same 128 debt. Independent direct base counting and the CI merge arithmetic agree. The checker and scalar baseline are unchanged; the fetched tested merge 71ceb29ef658841dd1aaffcc59693b928138932d has the expected parents and matches a recomputed merge tree. This is attributed inherited debt, not a green check; no extra grant or global ratchet change is included.

The runtime rank-up item is complete in exact-head CI: all three PG17 conformance shards passed, and the entire PG16 Gateway module passed all eight tests. The new crash case took 55.541 seconds under concurrent PG17 load and 36.914 seconds on PG16, within the unchanged 90-second deadline. The completed attempt has 31 successful jobs, 28 skipped jobs, and only the inherited ratchet failure plus its downstream aggregate. Native inherited-failure admission retains that red result and its exact baseline attribution; no unrelated budget grant is added. The final preflight preparation variant was not separately run on PG18. Focused Testbox allocations queued and were stopped before executing, contributing no new runtime proof.

Separate audit findings remain for subsequent review:

  • Agent RPC captures writer identity before embedded execution claims the session; final marking can reject that stale identity. Carry the authoritative claimed-writer fact into finalization while retaining successor rejection.
  • First Gateway boot with existing PostgreSQL state and incomplete webhook migration can fail the main-thread admission guard. Source tracing points to synchronous metadata discovery during async webhook setup; the exact throwing stack remains unobserved.
  • Earlier remote-acceptance/pre-receipt crash windows need distinct reconciliation and unknown/owed-notice tests. Persisted receipt and durability-policy changes remain embargoed.
  • Team Reports port recovery rejects canonical hyphenated namespaces in its underscore-only manifest grammar (src/infra/database-port-recovery.ts:21). Source confirms rejection before initial manifest publication; live command reproduction is pending. Accepting those values changes the recovery-format contract and remains embargoed even without a SQLite schema bump.

@vincentkoc vincentkoc self-assigned this Nov 10, 2026
@clawsweeper

clawsweeper Bot commented Nov 10, 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.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: M labels Nov 10, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review November 10, 2026 17:58
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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-repro Preliminary submission classification; full source review pending. labels Nov 10, 2026
@clawsweeper

clawsweeper Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Adds PostgreSQL Gateway crash-before-ACK coverage and moves existing final-receipt safety cases into SQLite/PostgreSQL conformance.

Example: The Gateway records receipt accepted-final, then dies before acknowledging its queued delivery.

  • Before: Existing coverage loses an ACK response after its commit but does not kill the whole Gateway before ACK execution.
  • After: The new test kills the Gateway, restarts it, and checks successful queue removal with exactly one transport send.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, focused coverage with preserved invariants and no identified defect; execution confidence remains limited for the latest fixture correction.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored test-only PR is outside the contributor proof gate; earlier real-Gateway qualification used different preparation, and exact-head runtime CI remains pending.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Test only · Worth it: Yes · Fix scope: Complete
User problem: A regression could resend queued final output after a Gateway crash despite an already persisted delivery receipt.
Reason: The maintainer-approved direction adds a distinct lifecycle boundary while preserving existing receipt-safety coverage and production contracts.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR adds distinct crash-recovery coverage, and the reviewed head has no actionable source findings.

Priority: P3
Reviewed head: 7209846fe5dbbfda03381db0ecb83445cd43529d

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The final preflight preparation variant has not yet completed the original concurrent PostgreSQL 17 shard and PostgreSQL 16 Gateway module.
Agent review details

How this fits together

Outbound recovery consumes queued payloads and persisted session receipts, invokes the transport when necessary, and acknowledges completed queue custody through database workers.

flowchart TD
  A[Seed queued final output] --> B[Gateway recovery]
  B --> C[Synthetic HTTP transport]
  C --> D[Persist PostgreSQL receipt]
  D --> E[Hold ACK and kill Gateway]
  E --> F[Cold Gateway restart]
  F --> G[ACK without another send]
Loading

Technical review

Best possible solution:

Retain the focused crash test and shared safety matrix, with successful exact-head conformance establishing acceptance.

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

This PR addresses a coverage gap rather than claiming a reproduced production defect; no target code was executed during this read-only review.

Is this the best way to solve the issue?

The smallest complete approach is to extend the existing Gateway suite and reuse the safety matrix through canonical engine fixtures, which this diff does.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 0c5c4754c33d.

Provenance checked

  • Final-receipt safety matrix keeps the original intent (70ed04a: Preserve admitted receipt ownership and require complete, correctly routed physical delivery evidence; the later restart refactor retained these checks for ordinary pending-final delivery.)
  • Gateway PostgreSQL fixture keeps the original intent (6b36172: Carry one configured database-engine selection through startup and workers without SQLite fallback; subsequent qualification added real Gateway process coverage.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Tests +298, Other +4. Total +302 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 2 324 26 +298
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 4 0 +4
Total 3 328 26 +302

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

No label changes.

Label justifications:

  • P3: This is test qualification with no production behavior, configuration, or persisted-format change.
  • 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.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Confirm successful exact-head PostgreSQL conformance, including the concurrent PostgreSQL 17 shard, PostgreSQL 16 Gateway module, and affected static checks.

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.

History

Review history (3 earlier review cycles)
  • reviewed 2026-11-10T18:25:51.304Z sha 1d8bb86 :: needs maintainer review before merge. :: none
  • reviewed 2026-11-10T19:03:27.073Z sha 8ae4800 :: needs changes before merge. :: [P2] Preserve the process project in Gateway watch selections | [P2] Reconcile infra inventories with the new process owner
  • reviewed 2026-11-10T19:12:20.071Z sha 8d3292a :: needs maintainer review before merge. :: none

Reviewed November 10, 2026, 2:40 PM ET / 19:40 UTC (Revision 4).

@vincentkoc
vincentkoc enabled auto-merge (squash) November 10, 2026 18:30
@vincentkoc
vincentkoc disabled auto-merge November 10, 2026 18:44
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Please review exact head 8ae480060d35e7402747bca17d583bab8d208a16, especially canonical serial CLI-process ownership, focused/broad selection without omission or duplication, and the five-line planner expectation update. The old head hit a 90-second PG17 concurrent infra timeout; this repair preserves every Gateway boot, assertion and deadline. Current-head runtime CI is pending. Production and SQLite schema/version delta remain zero.

@clawsweeper

clawsweeper Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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. merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed 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. 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 Nov 10, 2026
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Please review exact head 8d3292a5b9f0e0fb3cf4ee65674b2b678b9706cd. Final diff restores all routing/planner bytes: the sole fixture repair replaces a redundant empty CLI boot with the existing production startup/bootstrap helper, independently asserts native PostgreSQL migration completion, drains parent workers, then seeds via unchanged APIs. Both real delivery/recovery processes, SIGKILL, receipt/queue/ACK/no-resend assertions and the90s deadline remain. Current-head concurrent PG17 proof is pending; earlier results do not establish final setup qualification. No production or SQLite schema/version change.

@clawsweeper

clawsweeper Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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. 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 rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. 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 Nov 10, 2026
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Please review exact head 7209846fe5dbbfda03381db0ecb83445cd43529d. The preceding fixture entered full in-process runtime bootstrap without the CLI's plugin-cache adoption and failed PG17/16 secrets metadata admission. The latest correction calls only canonical migration preflight, awaits its transferred cache disposal, drains parent agents/state, retains the independent native PostgreSQL completion assertion, and installs both returned snapshot and engine selection. Both real Gateway processes, SIGKILL, receipt/queue/ACK/no-resend assertions and the 90-second deadline are unchanged. Fresh independent review is clean. Current-head concurrent PG17 and PG16 proof remain pending; earlier results do not qualify this preparation variant. Allocation is exactly +298 test LF. No routing, production or SQLite schema/version change.

@clawsweeper

clawsweeper Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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. 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 Nov 10, 2026
@vincentkoc
vincentkoc merged commit 9d770ec into main Nov 10, 2026
145 of 148 checks passed
@vincentkoc
vincentkoc deleted the test/postgres-receipt-crash-recovery-20261111 branch November 10, 2026 20:19
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 11, 2026
* chore(postgres): verify final-delivery crash recovery

* chore(postgres): match crash recovery allocation to added tests

* fix(test): serialize PostgreSQL Gateway process recovery proof

* fix(test): prepare PostgreSQL crash fixture without an extra Gateway

* fix(test): prepare crash recovery through startup preflight
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M 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