Skip to content

fix(startup): preserve preloaded resolver hooks - #128663

Merged
vincentkoc merged 2 commits into
openclaw:mainfrom
Leon-SK668:leon/preloaded-resolver-hooks-20260824
Aug 27, 2026
Merged

vincentkoc merged 2 commits into
openclaw:mainfrom
Leon-SK668:leon/preloaded-resolver-hooks-20260824

Conversation

@Leon-SK668

@Leon-SK668 Leon-SK668 commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Related: #128541

What Problem This Solves

Fixes an issue where operators launching OpenClaw with a Node preload, loader,
or effective config file could silently lose resolver-hook observations during
built CLI startup.

Why This Change Was Made

The dist resolver fast path registers a later LIFO hook with shortCircuit: true, so it must not install when an earlier hook may own the resolver chain.
The fix parses NODE_OPTIONS with Node's actual literal-space, double-quote,
and in-quote backslash grammar, shares that parser with gateway heap selection,
and conservatively declines the fast path for resolver-affecting options or
malformed input. Normal launches keep the optimization.

User Impact

Preloads and loaders continue observing OpenClaw's built runtime imports.
Launches without resolver-affecting Node options retain the existing startup
fast path.

Evidence

  • Red on current main b55ae89f230: built dist/entry.js exited 0, but the
    preload marker was absent for direct --import and valid split-quoted
    NODE_OPTIONS.
  • Green on exact head 11c9ef3f529: both launches recorded
    ./runtime-guard-Cx9Cuq24.js; dist/index.js --help with --loader recorded
    ./runtime-C4YU4VDg.js.
  • Shared parser matrix: 9 passed.
  • Gateway heap tests: 11 passed.
  • Entry resolver fast-path tests: 23 passed, including built sync preload,
    async loader, and split-quoted NODE_OPTIONS.
  • node --import tsx scripts/build-all.mts cliStartup, pnpm tsgo,
    node scripts/check-changed.mjs, native scripts/pr review-tests, and
    git diff --check passed.
  • Fresh branch autoreview reported no accepted or actionable findings (0.99).
  • Judged production delta: net +25 across exactly three production files.

AI Disclosure

This pull request was prepared with AI assistance.

@clawsweeper

clawsweeper Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 24, 2026
@clawsweeper

clawsweeper Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 27, 2026, 6:40 AM ET / 10:40 UTC.

ClawSweeper review

What this changes

The PR skips OpenClaw’s built ESM resolver shortcut when Node preloads, loaders, or configuration-file options may have registered a resolver hook, and centralizes the option parser shared with Gateway heap selection.

Regression provenance

Possible regression — probable (reviewed change; failure trace). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

No blocking defect found. This active, maintainer-assigned PR repairs a current-main startup compatibility gap with exact-head built-process proof; await the remaining exact-head checks and maintainer merge decision.

Priority: P2
Reviewed head: 11c9ef3f5295b07a4e5a2acc17313a2a92c85ae4

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused owner-boundary repair with strong built-process proof and no actionable correctness finding.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The PR supplies exact-head built-process terminal evidence that direct preload, quoted NODE_OPTIONS preload, and asynchronous loader hooks observe built runtime imports after the change.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR supplies exact-head built-process terminal evidence that direct preload, quoted NODE_OPTIONS preload, and asynchronous loader hooks observe built runtime imports after the change.
Evidence reviewed 5 items Current-main gap: Current main registers the dist resolver hook without considering Node startup options, while both built CLI entry points invoke that installer before runtime imports.
Single parser owner: The shared parser replaces Gateway heap selection’s existing equivalent tokenizer, avoiding a second interpretation of NODE_OPTIONS.
Node contract and proof: Installed Node 24.19.0 documentation/runtime confirmed space-only token separation, double-quote grouping, and malformed input rejection; the PR covers direct preload, loader, and quoted NODE_OPTIONS in built child processes.
Findings None None.
Security None None.

Live Verification

Command: node --import tsx scripts/build-all.mts cliStartup && node scripts/run-vitest.mjs src/entry.esm-resolve-fast-path.test.ts --reporter=verbose

Result: FAIL (failed) — step 1 expect_output built dist resolver hook chaining: expected terminal output was not visible within 30 seconds: "built dist resolver hook chaining"

[build-all] tsdown
[tsdown-build] invocation 1/2 finished in 0.6s
node_modules/playwright-core/lib/coreBundle.js (65821:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65821:29 ]
       │
 65821 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/playwright-core/lib/coreBundle.js (65828:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65828:29 ]
       │
 65828 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/web-tree-sitter/web-tree-sitter.js (2343:30) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2343:31 ]
      │
 2343 │           ASM_CONSTS[start] = eval(func);
      │                               ──┬─
      │                                 ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

node_modules/web-tree-sitter/web-tree-sitter.js (2366:32) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2366:33 ]
      │
 2366 │           moduleExports[name] = eval(func);
      │                                 ──┬─
      │                                   ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

[tsdown-build] invocation 2/2 finished in 11.6s
[build-all] tsdown done in 12.8s
[build-all] external-plugins:local-dist
[external-plugin-local-dist] built 61 plugins in 1971ms
[build-all] external-plugins:local-dist done in 2.33s
[build-all] check-cli-bootstrap-imports
CLI bootstrap import guard passed.
[build-all] check-cli-bootstrap-imports done in 16.2s
[build-all] runtime-postbuild

Assertions:

  • FAIL expect_output: built dist resolver hook chaining
  • FAIL expect_output: preserves synchronous preload resolver hooks

How this fits together

The built CLI registers an internal Node resolver optimization before loading most of OpenClaw. Managed Gateway startup separately reads NODE_OPTIONS to preserve an explicit heap limit.

flowchart LR
  A[Node startup options] --> B[Shared option parser]
  B --> C[Resolver hook decision]
  B --> D[Gateway heap selection]
  C --> E[Built CLI bootstrap]
  E --> F[Internal module loading]
Loading

Before merge

  • Resolve merge risk (P1) - NODE_OPTIONS parsing now controls whether a startup optimization activates, so exact-head CI should complete before merge to catch runtime or packaging variation beyond the covered built-process cases.
  • Complete next step (P2) - The current PR already owns the repair; let exact-head CI complete and route the merge decision to its assigned reviewer.
Agent review details

Security

None.

PR surface

Source +25, Tests +204. Total +229 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 3 79 54 +25
Tests 2 207 3 +204
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 286 57 +229

Review metrics

Metric Value Why it matters
Production vs test delta production +25; tests +204 The production increase replaces a duplicated parser and adds the compatibility gate; the added tests include built-process launch coverage.

Merge-risk options

Maintainer options:

  1. Validate the reviewed head before merge (recommended)
    Allow the remaining exact-head checks to finish, then merge the conservative compatibility gate if GitHub still reports the same clean head.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Wait for exact-head checks to complete green, then merge only if the head remains 11c9ef3f5295b07a4e5a2acc17313a2a92c85ae4.

Technical review

Best possible solution:

Keep the conservative hook gate and shared parser, then merge after exact-head CI confirms the reviewed head.

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

Yes. Current main unconditionally registers the short-circuiting hook, and the new built child-process cases observe whether prior preload and loader hooks still see OpenClaw runtime imports.

Is this the best way to solve the issue?

Yes. The shared parser removes duplicated behavior, while declining an optional optimization at the hook-registration boundary is safer than attempting to compose unknown earlier hooks.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 2abc76d1aebe.

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P2: This is a bounded repair for operators using existing Node preload, loader, or configuration startup options.
  • merge-risk: 🚨 compatibility: The PR deliberately changes when the resolver optimization activates for established Node launch configurations.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR supplies exact-head built-process terminal evidence that direct preload, quoted NODE_OPTIONS preload, and asynchronous loader hooks observe built runtime imports after the change.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR supplies exact-head built-process terminal evidence that direct preload, quoted NODE_OPTIONS preload, and asynchronous loader hooks observe built runtime imports after the change.

Evidence

What I checked:

Likely related people:

  • steipete: Introduced the merged dist resolver fast-path feature underlying this compatibility repair. (role: feature owner; confidence: high; commits: 74af7163e153; files: src/entry.esm-resolve-fast-path.ts, src/entry.ts, src/index.ts)
  • vincentkoc: Authored the current head and supplied the maintainer re-review context for the shared-parser revision. (role: recent area contributor; confidence: high; commits: 11c9ef3f5295; files: src/entry.esm-resolve-fast-path.ts, src/infra/node-options.ts, src/daemon/gateway-heap.ts)
  • xydt-tanshanshan: Introduced the Gateway heap owner whose tokenizer is consolidated by this PR. (role: adjacent owner; confidence: medium; commits: a3e526a9d02b; files: src/daemon/gateway-heap.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 (4 earlier review cycles)
  • reviewed 2026-08-24T10:13:22.883Z sha 6e5540d6f02afc9c295abf333348b424b1c382b2 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-24T10:28:38.003Z sha 6e5540d6f02afc9c295abf333348b424b1c382b2 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-24T11:20:52.342Z sha 44b3b41 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-24T12:04:36.273Z sha 44b3b41 :: needs maintainer review before merge. :: none

@Leon-SK668
Leon-SK668 force-pushed the leon/preloaded-resolver-hooks-20260824 branch from 6e5540d to 44b3b41 Compare August 24, 2026 11:14
@Leon-SK668

Copy link
Copy Markdown
Contributor Author

Exact-head after-fix built-process proof for 44b3b4108eb96cea0bfc6851017ad1622f7d69b6 (Node 24.15.0):

  1. node --import tsx scripts/build-all.mts cliStartup completed successfully. The build ran both tsdown invocations, verified 48 built plugin control-plane modules, and completed all 11 runtime postbuild phases.
  2. node scripts/run-vitest.mjs src/entry.esm-resolve-fast-path.test.ts --reporter=verbose passed 32/32. The terminal showed each real built-dist child-process case passing:
built dist resolver hook chaining > preserves 'synchronous preload' resolver hooks
built dist resolver hook chaining > preserves 'asynchronous loader' resolver hooks
built dist resolver hook chaining > preserves 'quoted NODE_OPTIONS synchronous preload' resolver hooks
built dist resolver hook chaining > preserves 'underscore asynchronous loader' resolver hooks
built dist resolver hook chaining > preserves 'configuration-file synchronous preload' resolver hooks
Test Files  1 passed (1)
Tests  32 passed (32)

These cases launch process.execPath against the freshly built dist/entry.js, not an in-process mock. Each preload/loader writes every observed ./runtime-guard-*.js resolution to an isolated marker file; the test requires child exit status 0, at least one observed marker, and rejects any marker outside that runtime-guard shape. This demonstrates that the user-supplied resolver hook remains active through real OpenClaw built startup across CLI, NODE_OPTIONS, and Node config-file launch forms.

The branch was rebased only after the canonical frozen-lockfile repair #128671 landed; focused install/build/test now reach the touched source normally.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 24, 2026
@openclaw-barnacle openclaw-barnacle Bot added the gateway Gateway runtime label Aug 27, 2026
@vincentkoc vincentkoc self-assigned this Aug 27, 2026
@vincentkoc

Copy link
Copy Markdown
Member

@clawsweeper re-review

The completed review predates rewritten head 11c9ef3f5295b07a4e5a2acc17313a2a92c85ae4.

Rank-up moves:

  • Resolve merge risk: addressed. The raw classifier was replaced by one shared
    Node-compatible NODE_OPTIONS parser used by the resolver gate and gateway
    heap owner. Judged production delta is net +25 across exactly three files,
    down from the reviewed +41.
  • Complete next step: addressed for local proof. Native review tests and
    artifacts pass at the exact hosted head; exact-head CI and Testbox prepare
    remain the landing gates.

Current-main red proof: direct --import and valid split-quoted NODE_OPTIONS
both exited 0 while the preload marker was absent. Exact-head green proof:
those launches recorded ./runtime-guard-Cx9Cuq24.js, and the async loader
recorded ./runtime-C4YU4VDg.js.

@clawsweeper

clawsweeper Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 27, 2026
@vincentkoc
vincentkoc merged commit 88c684c into openclaw:main Aug 27, 2026
459 of 461 checks passed
@vincentkoc

Copy link
Copy Markdown
Member

Merged via squash.

steipete added a commit that referenced this pull request Aug 27, 2026
…ports (#131181)

The startup-memory CI gate injected its RSS hook via --import, which since
#128663 declines the dist ESM resolve fast path, so the gate measured a
non-default slow-resolution configuration (~400 MB on Blacksmith) instead of
what plain invocations pay (~243 MB). The bench now runs the launcher
in-process from a wrapper with a clean execArgv and self-reports max RSS at
exit.

CLI bootstrap also imported proxy-capture/runtime and coverage on every
non-help invocation even though capture init, finalize, and coverage warnings
all no-op unless OPENCLAW_DEBUG_PROXY_ENABLED/REQUIRE is set; the import graph
(sqlite capture store, proxyline, undici) now loads only when the env requests
capture. Config reads import the gateway-startup metadata module directly
instead of the facade that also re-exports the startup loader.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 28, 2026
* fix(startup): preserve preloaded resolver hooks

* fix(startup): preserve preloaded resolver hooks

---------

Co-authored-by: Vincent Koc <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 28, 2026
…ports (openclaw#131181)

The startup-memory CI gate injected its RSS hook via --import, which since
openclaw#128663 declines the dist ESM resolve fast path, so the gate measured a
non-default slow-resolution configuration (~400 MB on Blacksmith) instead of
what plain invocations pay (~243 MB). The bench now runs the launcher
in-process from a wrapper with a clean execArgv and self-reports max RSS at
exit.

CLI bootstrap also imported proxy-capture/runtime and coverage on every
non-help invocation even though capture init, finalize, and coverage warnings
all no-op unless OPENCLAW_DEBUG_PROXY_ENABLED/REQUIRE is set; the import graph
(sqlite capture store, proxyline, undici) now loads only when the env requests
capture. Config reads import the gateway-startup metadata module directly
instead of the facade that also re-exports the startup loader.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. 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.

2 participants