Skip to content

perf(crabbox): warm the node runtime at boot on warm-image forks - #169886

Merged
steipete merged 2 commits into
mainfrom
steipete/crabbox-boot-runtime-prefetch
Oct 13, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/crabbox-boot-runtime-prefetch

Conversation

@steipete

@steipete steipete commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: a cloud worker forked from a warm image spends about 30–40 s starting its node before it first contacts the Gateway, because every first read of the forked disk loads its block lazily from the snapshot.

User Impact

User impact: warm cloud-session starts should become active up to about 30 s sooner on AWS, once the profile's warm image has been captured with this build. Cold starts are unchanged. Images without cron keep today's behavior.

Why This Change Was Made

A live trace of warm AWS starts showed node launch to first Gateway contact taking 37–44 s, and one lucky run took 8.7 s. On a kept box, the node used little CPU, while the disk had spent 132 s waiting on reads since boot. A/B on two fresh forks of the same image:

Cold After a parallel read of the runtime
openclaw --version 4.1 s 0.07 s
openclaw node --help 26.5 s 0.85 s
Parallel prefetch of the 551 MB runtime plus the Node binary — 23.6 s

Prefetching inside the enrollment script would only move that time around. Instead, the enrollment script now writes a small Linux-only boot hook into the machine-level cache, which the image scrub already keeps:

  • ~/.openclaw-worker/node-runtimes/.prefetch lists the current runtime and Node install directories.
  • .prefetch.sh reads them with 64 parallel readers and records start and end times.
  • An idempotent @reboot crontab entry runs it.

Every later fork starts warming its disk the moment it boots. That overlaps the roughly 24 s SSH-readiness wait and the Crabbox run setup that come before the node launches.

Best effort throughout. Any failure is swallowed, non-Linux targets skip the hook, unrelated crontab entries are preserved, and the files contain only paths and timestamps.

Evidence

  • pnpm test extensions/crabbox/src/crabbox-worker-node-enrollment.test.ts --maxWorkers=1: 26/26 pass. These tests execute the generated script.
  • The generated script passes a syntax check (node --check).
  • Codex autoreview: clean.
  • Live AWS proof on this branch: one dispatch captured an image containing the hook, then three warm forks of it.
    • On a kept box: boot at T, prefetch started at T+17 s (cron @reboot), finished at T+44.6 s, and the node launched at T+42 s.
    • Node launch to first Gateway contact fell from 37–44 s before this change to 2–3 s.
    • Warm time to active was 70.9 s, 98.2 s and 73.9 s, against 111–135 s for recent warm runs. The 98 s sample had a slow 57.9 s EC2 fork. All three turns passed, including the workspace file check.

Forks of a warm image load EBS blocks lazily on first read, so a cold node start spent ~30 s on serial reads (fresh fork: openclaw --version 4.1 s, node --help 26.5 s; after a parallel read of the 551 MB runtime both are under 1 s). The enrollment script now records the current runtime and Node install directories and installs an idempotent @reboot crontab entry that reads them in parallel, so later forks warm the runtime while SSH readiness and Crabbox run setup are still pending. Linux only and best effort: images without cron keep the cold start.
@clawsweeper

clawsweeper Bot commented Oct 12, 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.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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. labels Oct 12, 2026
@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR installs a Linux reboot hook that warms cached worker-runtime files while a cloud worker boots.

Example: An AWS worker boots from an image captured with the hook.

  • Before: The author reports 37–44 seconds from node launch to first Gateway contact.
  • After: The author reports 2–3 seconds after prefetch overlaps boot and SSH readiness.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) Useful owner-directed optimization with passing current-head CI, but one verified correctness finding remains.
Proof confidence 🌊 off-meta tidepool Not applicable: The maintainer-authored exemption applies to ordinary proof; the body reports capture-to-fork AWS execution and successful worker turns, without attached raw artifacts.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Warm cloud workers can spend tens of seconds loading snapshot-backed runtime files before contacting the Gateway.
Reason: The maintainer-authored direction addresses measured startup latency with a small plugin-local optimization.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep this PR open: the startup optimization has clear value, and the lease check resolves two earlier findings, but the system-wide prefetch defect still needs repair.

Priority: P2
Reviewed head: f695bdfcde88ce394a77f82687199d5f634892df

Before merge

  • Prefetch the Node executable instead of its entire system prefix (P2) - On a Linux worker whose resolved Node executable is /usr/bin/node, taking dirname twice records /usr. The reboot hook then recursively reads every regular file beneath /usr with up to 64 concurrent cat processes, including unrelated applications and libraries. This supported installation shape occurs on Crabbox's non-amd64 package-install path and can add substantial disk contention while enrollment starts. Record the resolved executable itself, which find can read directly, or a verified dedicated Node installation directory. The lease check does not resolve this earlier finding.

Findings

  • [P2] Prefetch the Node executable instead of its entire system prefix — extensions/crabbox/src/crabbox-worker-node-enrollment.ts:155-157
Agent review details

How this fits together

The Crabbox plugin turns Gateway provisioning requests into remote runtime preparation, image capture, and fresh node enrollment.

flowchart LR
 A[Gateway provisioning] --> B[Crabbox setup script]
 B --> C[Verified runtime cache]
 B --> D[Linux reboot hook]
 C --> E[Captured image]
 D --> E
 E --> F[Boot and prefetch]
 F --> G[Node enrollment]
Loading

Technical review

Best possible solution:

Keep the boot-time overlap, but prefetch only the verified worker runtime and resolved Node executable.

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

Source deterministically establishes the /usr traversal for system-installed Node, supported by Crabbox's non-amd64 installation path; the reported AWS timings were not rerun.

Is this the best way to solve the issue?

Overlapping runtime reads with boot addresses the measured disk bottleneck in the existing plugin owner, but traversing a system installation prefix adds unrelated I/O.

Full review comments:

  • [P2] Prefetch the Node executable instead of its entire system prefix — extensions/crabbox/src/crabbox-worker-node-enrollment.ts:155-157
    On a Linux worker whose resolved Node executable is /usr/bin/node, taking dirname twice records /usr. The reboot hook then recursively reads every regular file beneath /usr with up to 64 concurrent cat processes, including unrelated applications and libraries. This supported installation shape occurs on Crabbox's non-amd64 package-install path and can add substantial disk contention while enrollment starts. Record the resolved executable itself, which find can read directly, or a verified dedicated Node installation directory. The lease check does not resolve this earlier finding.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.99

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Runtime preparation before image capture keeps the original intent (c753bbd: Prepare reusable runtime bytes before capture while keeping fresh enrollment identity and credentials outside the snapshot.)
  • Machine-level runtime cache retention keeps the original intent (6f32f8d: Retain verified immutable runtime and worker archives for reuse by fresh enrollments.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test extensions/crabbox/src/crabbox-worker-node-enrollment.test.ts --maxWorkers=1
  • pnpm test extensions/crabbox/src/crabbox-worker-node-install.test.ts --maxWorkers=1
  • git diff --check

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit c753bbd adds extensions/crabbox/src/crabbox-worker-node-enrollment.ts:25 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: c753bbd1ced5; files: extensions/crabbox/src/crabbox-worker-node-enrollment.ts)
  • Galin Iliev: Raw commit db01f6d adds extensions/crabbox/src/crabbox-worker-node-enrollment.ts:114 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: db01f6d520b8; files: extensions/crabbox/src/crabbox-worker-node-enrollment.ts)

PR surface

Source +17. Total +17 across 1 file. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 17 0 +17
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 17 0 +17

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a measured cloud-worker startup improvement with a focused prefetch-scope defect.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🌊 off-meta tidepool 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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-12T12:39:24.921Z sha a009e48 :: needs changes before merge. :: [P2] Prefetch the Node executable instead of its entire system prefix | [P2] Update the Linux runtime-cache assertion for the added hook files | [P2] Isolate crontab writes in the generated-script integration tests
  • reviewed 2026-10-12T13:14:12.249Z sha a009e48 :: needs changes before merge. :: [P2] Prefetch the Node executable instead of its entire system prefix | [P2] Update the Linux cache assertion for the intended hook artifacts | [P2] Isolate crontab writes in generated-script integration tests

Reviewed October 12, 2026, 9:53 AM ET / 13:53 UTC (Revision 3).

…ox lease

Linux CI ran the enrollment script locally, so the hook wrote prefetch files beside the runtime and edited the runner's crontab. Gate it on Crabbox's reserved CRABBOX_LEASE_ID matching the script's lease (set by crabbox run since v0.41.1).
@steipete
steipete merged commit c2aad8e into main Oct 13, 2026
90 checks passed
@steipete
steipete deleted the steipete/crabbox-boot-runtime-prefetch branch October 13, 2026 06:39
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 14, 2026
…nclaw#169886)

Forks of a warm image load EBS blocks lazily on first read, so a cold node start spent ~30-40 s on serial reads before first contacting the Gateway (fresh fork: openclaw --version 4.1 s, node --help 26.5 s; under 1 s after a parallel read). Inside its Crabbox lease (CRABBOX_LEASE_ID matches), the Linux enrollment script now records the current runtime and Node install directories and installs an idempotent @reboot crontab entry that reads them with 64 parallel readers, so later forks warm the runtime while SSH readiness and Crabbox run setup are still pending. Best effort; images without cron keep the cold start; local executions such as tests never touch the crontab.

Live AWS: node launch to first Gateway contact 37-44 s -> 2-3 s; warm time to active 70.9 / 98.2 / 73.9 s (was 111-135 s; the 98 s sample had a 57.9 s EC2 fork).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: crabbox P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: XS 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