Repository navigation
improve(startup): start the Gateway faster on the Bun runtime - #169543
Conversation
The dist-relative resolve hook (#128541) short-circuited relative ".js" imports so Node skipped package-scope format detection. #139754 then emitted core chunks as ".mjs", which already carry their format, so the hook now matches about 0.1% of resolutions (30 of 28,038 on Node for the gateway/reply import graph). The pinned Bun fork has since gained Module.registerHooks. With any resolve hook registered, Bun routes every resolution through its JS customization-hooks chain instead of its native parallel loader: 303,185 hook calls for the same graph, 140 short-circuits. In fresh Bun processes importing that graph, median wall time drops from 12.65 s to 2.54 s without the hook (9 interleaved pairs, loaded host). Remove the hook and its call sites instead of special-casing Bun; Node keeps the explicit-format chunks that replaced it.
|
🦞👀 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: needs maintainer review before merge. What this changesThis PR removes the dist-relative ESM resolver hook from both executable entry points. Example: Reported fresh-state Gateway startup with bundled Bun on an idle M4 Pro Mac mini.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this PR removes a superseded startup optimization with a concrete performance benefit, and review found no actionable correctness or security defect. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherCLI and macOS app launches enter executable bootstrap, resolve packaged modules, and start the Gateway until readiness is published. flowchart LR
A[CLI or macOS app] --> B[Executable bootstrap]
B --> C[Native runtime resolver]
C --> D[Packaged ESM modules]
D --> E[Gateway startup]
E --> F[Ready Gateway]
Technical reviewBest possible solution: Remove the obsolete hook completely and use native resolution with the existing explicit-format build output. Do we have a high-confidence way to reproduce the issue? Current main registers the hook and the pinned Bun source confirms the JavaScript resolution chain; the PR reports comparative Gateway measurements, but this read-only review did not reproduce the timing. Is this the best way to solve the issue? Complete removal fits the existing .mjs build contract, preserves user resolver hooks, and avoids retaining a redundant optimization behind a runtime-specific branch. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 83f3c3d67998. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource -136, Tests -289, Other -1. Total -426 across 6 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes: No label 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 HistoryReview history (1 earlier review cycle)
Reviewed October 11, 2026, 11:54 PM ET / October 12, 2026, 03:54 UTC (Revision 2). |
|
Merged via squash.
|
…9543) The dist-relative resolve hook (openclaw#128541) short-circuited relative ".js" imports so Node skipped package-scope format detection. openclaw#139754 then emitted core chunks as ".mjs", which already carry their format, so the hook now matches about 0.1% of resolutions (30 of 28,038 on Node for the gateway/reply import graph). The pinned Bun fork has since gained Module.registerHooks. With any resolve hook registered, Bun routes every resolution through its JS customization-hooks chain instead of its native parallel loader: 303,185 hook calls for the same graph, 140 short-circuits. In fresh Bun processes importing that graph, median wall time drops from 12.65 s to 2.54 s without the hook (9 interleaved pairs, loaded host). Remove the hook and its call sites instead of special-casing Bun; Node keeps the explicit-format chunks that replaced it.
- remove the esm loader shim wrapper: 2026.11.3 no longer has the resolve hook (openclaw/openclaw#169543), so `programs.openclaw` uses the default package. - remove the overlay that copied `discord` into the gateway: the plugin loads from `plugins.load.paths`, which overrides that copy. - stop removing the retired `checkin`, `dev-checkin` and `dev-daily-thread` jobs, which no longer exist. - remove the `webhooks` plugin entry, which 2026.11.3 dropped. - bring the check-in comments in line with the gate jobs.
What Problem This Solves
The Gateway and CLI start several seconds slower than necessary on the Bun runtime that the macOS app bundles, on both first start and every restart.
User Impact
User impact: macOS app users (and anyone running OpenClaw on the pinned Bun fork) reach a ready Gateway noticeably sooner; Node installs are unaffected.
Why This Change Was Made
A dist-relative ESM resolve hook (#128541) existed to let Node skip package-scope format detection for relative
.jsimports. #139754 later emitted core chunks as.mjs, which already declare their format, so the hook now short-circuits about 0.1% of resolutions. Meanwhile the pinned Bun fork gainedModule.registerHooks: with any resolve hook registered, Bun sends every resolution through its JS customization-hooks chain instead of its native parallel loader. The hook had become pure overhead on Node and a large serial cost on Bun, so this removes it and its two call sites rather than special-casing Bun.Evidence
Hook usage for the same gateway + reply-runtime import graph (load-independent counts):
Fresh-process import of that graph on the pinned Bun fork, staged macOS-app package layout, 9 interleaved pairs on a loaded host (load ~34): median wall 12,654 ms with the hook vs 2,544 ms without (ranges 3,471–20,239 vs 2,014–3,416 ms). On Node the same comparison is within noise (9,135 vs 7,537 ms median at the same load).
Full app-style
gateway run(fresh isolated state, token auth, random port, bundled Bun + SQLite, exactly the macOS child launch), 7 interleaved fresh/warm pairs per build. On an idle Mac mini (M4 Pro, load ~3) the fixed build was faster in all 7 fresh and all 7 warm pairs:The saving sits where resolution happens:
process.bootstrap2,024 → 1,874 ms fresh and 1,522 → 1,379 ms warm,gateway.server-start-import302 → 283 / 163 → 139 ms,sidecars.reply-runtime211 → 196 / 115 → 98 ms. Under CPU contention the effect grows because the hook serializes resolution onto one JS thread while Bun's native loader is parallel: on a shared 32-core host at load 68–97 the same A/B moved fresh readyz medians from 67.5 s to 49.6 s and warm from 57.1 s to 51.1 s (noisy; shown for direction only).CPU profiles of the baseline attribute the largest share of startup main-thread time to
runResolveHooksBun→defaultResolve→defaultResolveForHooks(about 1.8–2.6 s sampled during CLI bootstrap, and most of thesidecars.reply-runtimephase).Checks:
pnpm test src/cli/run-main.cleanup.test.ts src/entry.test.ts src/entry.run-main.test.ts src/index.entrypoint.test.ts src/index.test.ts --maxWorkers=1passed (3 Vitest shards, 134 s wall on a loaded host);pnpm check:test-mock-exportsOK;node scripts/check-changed.mjspassed every lane excepttypecheck core tests, which failed only onui/src/components/mcp-app-*.test.tsinherited from the base and already fixed on main by #169439. Autoreview (Codex) scoped-clean at P0–P2.