Skip to content

improve(node-host): reduce worker turn receipt reads - #154564

Merged
steipete merged 1 commit into
mainfrom
codex/node-worker-turn-read-reuse
Sep 21, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/node-worker-turn-read-reuse

Conversation

@steipete

@steipete steipete commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Worker turn claims and settlements reread the turn and its physical owner after writing the turn within the same transaction.

User Impact

Claiming or finishing a worker turn uses two receipt reads instead of four. Receipt contents, immutable outcomes, process ownership checks, recovery, and retention remain unchanged.

Why This Change Was Made

The turn INSERT/UPDATE now returns its stored row. The existing receipt mapper combines it with physical-owner facts already read in the same synchronous transaction; turn writes and pruning do not change that owner. There is no schema, configuration, upgrade, admission, or retention change.

Evidence

  • 40 selected tests passed across the turn journal, supervisor settlement, and uncertain-outcome suites. The original code fails both new query budgets with four reads; the candidate uses two. Query instrumentation isolates the storage kernel with synthetic admission; existing worker tests continue to cover actual admission and receipt behavior.
  • Real file-backed kernel benchmark: claim plus finish fell from 0.759 ms to 0.573 ms (24.4%) across seven alternating rounds of 200 operations after 30 warmups, Node 26.8.2. The measurement includes coordinator and transaction commits with synthetic synchronous admission; it excludes worker messaging and platform I/O. Before/after receipts matched.
  • Full changed-code validation passed: production and test types, typed lint, dead exports, schema and repository guards (2,855.32 seconds).
  • Standalone turn-store run: node scripts/run-vitest.mjs src/node-host/node-worker-turn-store.test.ts --maxWorkers=1 passed all 18 tests in 54.55 seconds wall time (Vitest: 51.18 seconds; Node 26.8.2).
  • Refreshed onto main 93be68b967506f7e7c157fa671e09b62e2d41a6b, including 9247701e7ae (fixture-owned admission clock and explicit relay-listener retirement), which addresses the unrelated hosted native hook relay not found failure. The optimization commit is patch-identical after rebase (git range-diff); new-head CI remains required.

@clawsweeper

clawsweeper Bot commented Sep 21, 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.

@steipete
steipete marked this pull request as ready for review September 21, 2026 07:24
@openclaw-barnacle openclaw-barnacle Bot added size: S maintainer Maintainer-authored PR labels Sep 21, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 21, 2026
@clawsweeper

clawsweeper Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 21, 2026, 5:43 AM ET / 09:43 UTC (Revision 3).

ClawSweeper review

What this changes

Reduces database reads when claiming and finishing worker turns by building receipts from returned write rows and ownership facts already read in the transaction.

Merge readiness

✅ Ready for maintainer review

The optimization remains useful on current main, and the reviewed diff introduces no actionable correctness defect. The transaction retains the ownership checks and receipt semantics needed to safely reuse previously read facts.

Priority: P2
Reviewed head: a1012027970bff2b0ddd1e50505ee55ba44303f6

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused optimization with relevant regression coverage and clearly bounded benchmark evidence; no actionable patch defect found.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: The ordinary external-contributor gate does not apply to this maintainer PR, and the diff does not materially change authority. Its reported file-backed kernel benchmark exercises claim and finish with matching receipts, while explicitly excluding real admission, worker messaging, and platform I/O.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The ordinary external-contributor gate does not apply to this maintainer PR, and the diff does not materially change authority. Its reported file-backed kernel benchmark exercises claim and finish with matching receipts, while explicitly excluding real admission, worker messaging, and platform I/O.
Evidence reviewed 7 items Pinned introduced change: The merge-base-to-head diff changes receipt construction and adds a query-budget regression. Admission, identity predicates, pruning policy, and stored schema are unchanged.
Receipt equivalence: Claim and finish remain inside the existing synchronous write transaction. Pruning deletes other terminal turns without changing the physical owner. The mapper replaces every turn-specific field, including ownerLaunchId from the stored foreign key, so passing the existing turn receipt during finish preserves physical-owner facts.
Regression coverage: The new test bounds receipt SELECTs to two for each operation and compares returned receipts against reads through the journal worker. Existing cases cover wrong ownership, immutable outcomes, replay, pruning, and predecessor-shaped storage. The admission mock is limited to query measurement and does not replace existing worker-boundary coverage.
Findings None None.
Security None None.

How this fits together

The node-host turn journal records individual requests handled by a worker process. Its SQLite worker validates ownership, stores outcomes, and returns receipts used by the supervisor for completion, replay, and recovery.

flowchart TD
  A[Worker supervisor] --> B[Journal worker admission]
  B --> C[Synchronous database transaction]
  C --> D[Read turn and physical owner]
  D --> E[Validate identity and state]
  E --> F[Write turn and return stored row]
  F --> G[Map receipt using ownership facts]
  G --> A
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +9, Tests +46. Total +55 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 29 20 +9
Tests 1 47 1 +46
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 76 21 +55

Review metrics

Metric Value Why it matters
Receipt read budget 4 → 2 SELECTs per claim or finish The regression bounds redundant receipt reads while checking returned receipts against persisted results.

Technical review

Best possible solution:

Keep receipt construction within the existing journal owner and reuse transaction-local facts without adding caches, storage changes, or parallel APIs.

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

Not applicable as a correctness bug: this is a performance optimization, and current-main source directly shows the redundant post-write reads.

Is this the best way to solve the issue?

Yes. Returning the written row and reusing unchanged ownership facts inside the same transaction is a narrow solution that preserves the existing storage and admission owners.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 99e7d3e7a5b3.

Labels

Label justifications:

  • P2: This is a bounded journal performance improvement with no demonstrated urgent user-facing failure.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The ordinary external-contributor gate does not apply to this maintainer PR, and the diff does not materially change authority. Its reported file-backed kernel benchmark exercises claim and finish with matching receipts, while explicitly excluding real admission, worker messaging, and platform I/O.

Evidence

What I checked:

  • Pinned introduced change: The merge-base-to-head diff changes receipt construction and adds a query-budget regression. Admission, identity predicates, pruning policy, and stored schema are unchanged. (src/node-host/node-worker-turn-store.kernel.ts:212, a1012027970b)
  • Receipt equivalence: Claim and finish remain inside the existing synchronous write transaction. Pruning deletes other terminal turns without changing the physical owner. The mapper replaces every turn-specific field, including ownerLaunchId from the stored foreign key, so passing the existing turn receipt during finish preserves physical-owner facts. (src/node-host/node-worker-turn-store.kernel.ts:79, a1012027970b)
  • Regression coverage: The new test bounds receipt SELECTs to two for each operation and compares returned receipts against reads through the journal worker. Existing cases cover wrong ownership, immutable outcomes, replay, pruning, and predecessor-shaped storage. The admission mock is limited to query measurement and does not replace existing worker-boundary coverage. (src/node-host/node-worker-turn-store.test.ts:103, a1012027970b)
  • Current-main necessity: Fetched main still performs post-write readReceipt calls in claim and finish. Its kernel has no differences from the pinned merge base, so this optimization is not already implemented there. (src/node-host/node-worker-turn-store.kernel.ts:224, 99e7d3e7a5b3)
  • Reported scoped validation: The captured PR body reports 40 selected passing tests, a standalone 18-test run taking 54.55 seconds wall time, and a file-backed kernel benchmark improving claim-plus-finish from 0.759 ms to 0.573 ms with matching receipts. The benchmark explicitly uses synthetic admission and excludes worker messaging and platform I/O; these are contributor-reported results, not reviewer execution. (a1012027970b)
  • Merged area history: Current-main history connects the journal worker refactor to refactor(node-host): move launch and turn journal SQL off the event loop #149517. Blame identifies its merged commit on the transaction-admission lines; raw commit inspection records parent fdce973, whose tree lacks this kernel path. (src/node-host/node-worker-turn-store.kernel.ts:149, ac638483c780)

Likely related people:

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

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-09-21T07:31:05.876Z sha 91ff2b9 :: needs changes before merge. :: none
  • reviewed 2026-09-21T07:48:09.320Z sha 91ff2b9 :: needs maintainer review before merge. :: none

@steipete
steipete force-pushed the codex/node-worker-turn-read-reuse branch from 91ff2b9 to a101202 Compare September 21, 2026 09:35
@steipete
steipete enabled auto-merge (squash) September 21, 2026 09:53
@steipete
steipete merged commit 19ff46f into main Sep 21, 2026
212 of 213 checks passed
@steipete
steipete deleted the codex/node-worker-turn-read-reuse branch September 21, 2026 10:01
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash auto-merge.

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

Labels

maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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