Skip to content

perf(node-host): return settled turn from journal owner - #183172

Merged
steipete merged 3 commits into
mainfrom
dbasync/ownerredesign2-item6
Oct 25, 2026
Merged

steipete merged 3 commits into
mainfrom
dbasync/ownerredesign2-item6

Conversation

@steipete

@steipete steipete commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Node-worker turn settlement fails on PostgreSQL with error 42883 because the owner uses SQLite’s scalar three-argument max(), which PostgreSQL treats as an aggregate-only function. The owner now selects greatest on PostgreSQL and retains max on SQLite through the existing connection discriminator. The timestamp columns are NOT NULL, so both preserve the timestamp clamp.

Receipt recovery also selects the turn immediately after settling it. Return the settlement owner’s native postimage instead, removing one SQL statement from every recovered receipt (120 → 100 SQL for twenty recoveries). Both initial reads remain: a predecessor can update only the physical launch, so its current state must still be observed.

The existing unique partial index permits only one running turn per physical owner. The existing synchronous write transaction and PostgreSQL eager advisory lock therefore already protect this result. The private result option adds RETURNING * only to receipt recovery; ordinary launch finish/cancel still perform their original non-returning update. No schema, cache, generation, transaction ordering, permission, or retention changes.

Evidence

Acceptance was published in this PR before the first run: twenty synthetic launches, ended offline by a predecessor (five each completed, failed, interrupted, cancelled), then twenty recovered and twenty warm receipts through the real journal worker transport under an isolated Gateway. Require exactly one fewer turn SELECT per recovery, unchanged target warm work/requests/MAIN, and preserved result/error/state, timestamp clamp, immutable completed siblings and durable replay. Frozen sqlharness v3.1.4 was verified (36/36 hashes). Host load selected the preregistered one-pair count fallback; no latency or CPU-time improvement is claimed. Per-thread CPU profiles were captured for both arms (29 observed threads each). This proves Gateway ownership and worker transport, not remote node WebSocket or model-turn latency.

Target work (20 receipts per phase) Base SQL / requests / MAIN Candidate SQL / requests / MAIN
Recovery 120 / 20 / 0 100 / 20 / 0
Warm replay 80 / 20 / 0 80 / 20 / 0

Recovery turn SELECTs fall 40 → 20; settlement updates remain 20 → 20. No work moved onto the main thread. Single-pair medians and min/max are the listed values; one sample does not support a useful p95.

Entire observed phase Base SQL / requests / MAIN Candidate SQL / requests / MAIN
Startup 275 / 77 / 77 272 / 77 / 76
Recovery 137 / 33 / 0 100 / 20 / 0
Warm 84 / 21 / 0 101 / 34 / 0
Shutdown 9 / 2 / 7 9 / 2 / 7

The raw warm cell rises 20.24% SQL and 61.90% requests, so the campaign’s stop rule was invoked. Exact shape attribution finds the same 17 statements / 13 requests from background maintenance in base recovery and candidate warm: session event/watch-cursor maintenance, delivery queue readers, restart sentinel, deletion journal, and three config reads. Combined recovery + warm falls 221 → 201 SQL with 54 → 54 requests and MAIN 0. The touched owner’s warm work is unchanged. The coordinator explicitly accepted this phase placement on October 25: the same background work shifted phases, while combined work fell and target warm work stayed unchanged.

Validation: the four-outcome count regression is red on base solely at 3 → 2 SELECTs; candidate owner suites passed 54 tests, and all four count cases passed again on the final source. Actual PostgreSQL17 replay fails on the base with scalar-max error 42883 and passes on the candidate (both engine arms, including zero-row and one-row non-returning settlements). Two independent Codex rounds completed; the final round’s sole finding concerned the deliberately red preparation commit lacking the unstaged implementation, resolved by committing the reviewed implementation with it. No additional P0–P2 defects were reported in the combined candidate. Initial CI identified TS7030 / consistent-return because two no-result paths lacked explicit returns. Commit d07d02e adds only return undefined on those paths; runtime values and SQL are unchanged. Formatting, basic lint, the commit hook, and diff checks pass. Exact-head CI 40160229397 passed, including all three PostgreSQL shards, production/test types, typed lint, source contracts, architecture, and worker/dialect ratchets. Local Madge passed with zero cycles. Canonical Knip baseline/candidate sets match exactly: 14 production, 22 full-tree, and 14 script findings, zero new findings and zero resolution errors. The local check:changed run completed with its type setup blocked by the mandated virtual store location and its Knip findings verified against the base; normal-install CI supplies the successful type-aware gates. The initial PR-context failure was corrected by adding the required body sections; edited-event run 40160678154 passed on the same head. pgprep approved this exact head on October 25 (REVIEW-OK OWNERREDESIGN2 item 6 #183172 d07d02e48b46), including the PostgreSQL function repair and bounded postimage.

The simplification removes the trailing turn SELECT and keeps settlement policy in its existing owner. Production delta is +7 lines (native result selection and the PostgreSQL function repair); test/workload growth provides the committed reproduction and affected-engine proof. No forwarding owner, duplicate state calculation, or retained result cache.

Rerun instructions and the original acceptance contract: scripts/perf/node-worker-journal-measure.md. Final open-main overlap audit: the refreshed, complete 2,657-PR index (completed 2026-10-25T05:00:13Z) matches only this PR across all six files. There are no other overlapping heads to compare, zero new merge conflicts, and the approved head merges cleanly with current main.

PostgreSQL review checklist:

  1. The existing journal write transaction takes its eager advisory lock before both authoritative reads. There is no writable CTE, string-batched SQL, conflict-target change, or cross-store commit change.
  2. The new UPDATE RETURNING result is bounded to one row by idx_node_worker_turns_active_owner. No iterator, larger scan, or unbounded buffered result is introduced.
  3. No state is retained across operations. Both initial reads still observe the physical predecessor; the returned postimage belongs only to this transaction. Later external writes remain visible on the next operation.
  4. Schema admission and its bounded retry path are unchanged. No PRAGMA or equivalent PostgreSQL freshness probe is added or removed.
  5. The operation stays in the existing journal worker. Runtime MAIN SQL remains zero; no synchronous-admission exception is widened.
  6. Final-head CI 40160229397 executed and passed all three PostgreSQL conformance shards. Local PostgreSQL17 also passes recovery and zero/one-row ordinary settlement; the base reproduces error 42883.

@clawsweeper

clawsweeper Bot commented Oct 25, 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 scripts Repository scripts size: M labels Oct 25, 2026
@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: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 25, 2026
@clawsweeper

clawsweeper Bot commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR adds a predecessor-recovery measurement workload and regression coverage without changing production behavior.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) Useful experimental preparation, but the implementation is deliberately absent and the new regression remains source-demonstrably red.
Proof confidence 🦪 silver shellfish (2/6) This maintainer-authored preregistration changes no shipped runtime behavior and claims no completed after-fix measurement.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Product

Kind: Performance · Worth it: Yes · Fix scope: Partial
User problem: Recovering a turn left unfinished by a predecessor performs an avoidable database read.
Reason: The maintainer-authored direction is narrow and consistent with the earlier owner-postimage optimization; the present contribution is preparation for that change.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep this useful maintainer-authored draft open; it preregisters a focused optimization, but its new read-budget assertion cannot pass with the unchanged implementation.

Priority: P3
Reviewed head: 0773d8eeb1c8eb3a5185423d6c676f8daf51824d

Before merge

  • Complete the recovery optimization before enforcing its read budget (P2) - For each added predecessor-state case, kernel.get reads the turn, reads its physical owner, and rereads the turn after settlement. The new assertion therefore receives three rather than two with this head's unchanged production code. Preregistering the failing regression is reasonable in a draft, but merging it would introduce four failing cases; include the settlement-postimage implementation before making this merge-ready rather than weakening the budget.

Findings

  • [P2] Complete the recovery optimization before enforcing its read budget — src/node-host/node-worker-turn-store.test.ts:199

Tests

  • Missing end-to-end proof: The planned Gateway recovery/warm workload has no supplied execution results, and the added regression has no demonstrated red/green run.
Agent review details

How this fits together

Node-host supervisors request durable turn receipts through the shared journal worker, whose database kernel reconciles unfinished turns with their physical launch owners.

flowchart LR
  A[Receipt caller] --> B[Turn store]
  B --> C[Journal worker transport]
  C --> D[Turn kernel]
  D --> E[Physical launch receipt]
  D --> F[Turn settlement owner]
  F --> G[Durable turn receipt]
Loading

Technical review

Best possible solution:

Return the native updated turn from the existing settlement owner and consume it in readReceipt while preserving terminal receipts and other settlement callers.

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

Source inspection establishes three receipt SELECTs for predecessor recovery and a new expectation of two; no target code or tests were executed.

Is this the best way to solve the issue?

The proposed owner-returned postimage follows the prior receipt optimization and needs no new cache or owner, but this draft has not implemented it.

Full review comments:

  • [P2] Complete the recovery optimization before enforcing its read budget — src/node-host/node-worker-turn-store.test.ts:199
    For each added predecessor-state case, kernel.get reads the turn, reads its physical owner, and rereads the turn after settlement. The new assertion therefore receives three rather than two with this head's unchanged production code. Preregistering the failing regression is reasonable in a draft, but merging it would introduce four failing cases; include the settlement-postimage implementation before making this merge-ready rather than weakening the budget.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 2a82eb7795d8.

Provenance checked

  • Receipt-read regression coverage keeps the original intent (19ff46f: Reduce claim and finish reads using stored write postimages without changing receipt contents or ownership checks.)

Testing

Proof path: none.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 19ff46f adds src/node-host/node-worker-turn-store.test.ts:103 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 19ff46fde21a; files: src/node-host/node-worker-turn-store.test.ts)

PR surface

Tests +61, Docs +34, Other +140. Total +235 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 1 61 0 +61
Docs 1 34 0 +34
Config 0 0 0 0
Generated 0 0 0 0
Other 1 140 0 +140
Total 3 235 0 +235

Labels

Label changes:

  • add P3: This draft targets a bounded recovery-query optimization and currently changes only measurement tooling and tests.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P3: This draft targets a bounded recovery-query optimization and currently changes only measurement tooling and tests.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

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 24, 2026, 11:05 PM ET / October 25, 2026, 03:05 UTC.

Remove the follow-up turn SELECT after predecessor recovery while retaining both initial authoritative reads. Ordinary physical launch settlement remains non-returning. Use PostgreSQL greatest for the existing timestamp clamp; SQLite keeps max. Synthetic recovery removes one SQL statement per receipt without changing requests or MAIN work.
@steipete
steipete marked this pull request as ready for review October 25, 2026 03:46
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 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-25T03:48:33.335749Z df70863 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.

@steipete
steipete merged commit a0b170f into main Oct 25, 2026
172 of 175 checks passed
@steipete
steipete deleted the dbasync/ownerredesign2-item6 branch October 25, 2026 05:01
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 26, 2026
)

Fix PostgreSQL node-worker turn settlement by using greatest for the timestamp clamp, while retaining SQLite scalar max. Return the transaction-local settled postimage for receipt recovery instead of selecting the turn again. Preserve both initial external-writer reads and ordinary non-returning settlement.

Twenty synthetic recoveries fall from 120 to 100 SQL statements with 20 worker requests and zero MAIN SQL; warm target work is unchanged. Native and PostgreSQL regression proof and exact-head CI 40160229397 pass.

PR openclaw#183172.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. scripts Repository scripts size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant