Skip to content

fix(bench): resolve dynamically imported sources as file URLs - #25237

Closed
paoValle wants to merge 1 commit into
stablyai:mainfrom
paoValle:fix/windows-source-import-file-urls
Closed

paoValle wants to merge 1 commit into
stablyai:mainfrom
paoValle:fix/windows-source-import-file-urls

Conversation

@paoValle

@paoValle paoValle commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Author: @paolovalletta_

ELI5

Two of this repo's benchmark scripts hand Node a Windows file path (C:\...) where Node expects a URL. Node reads the C: as a URL scheme and refuses to load the file, so both scripts crash on Windows before doing any measuring — while working fine on macOS and Linux.

What Changed

Before, on Windows:

$ node config/scripts/session-write-hot-path-benchmark.mjs
Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data, and node are supported by
the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:'
    at throwIfUnsupportedUrlScheme (node:internal/modules/esm/load:184:11)

$ node config/scripts/agent-inspection-cadence-batching-benchmark.mjs
# same failure

After, both run and print their tables:

Session-write hot path — 8 retained scrollback leaves, 2000 accumulated pane keys
1. scrollback UTF-8 budget scan (16 calls/write @ 512 KB)  before 71.933 ms → after 0.607 ms  (118.5x)
2. pane-key remap (3 maps/write @ 2000 keys)                before 6.770 ms → after 4.114 ms  (1.6x)

Agent-completion cadence — whole-host `ps` captures over 60s at the idle tier (2000ms)
| visible panes | before | after | reduction |
| 8 | 80 | 32 | 60% |

Mechanism. Each script computed its specifier with path.join(ROOT, '...ts') and passed it straight to import(). On Windows that value starts with C:, which the ESM loader parses as the scheme c:. On macOS and Linux the same value is an absolute POSIX path, which the loader accepts, so the failure was invisible to CI. The specifier is now pathToFileURL(path.join(...)).href, the form other benchmark scripts in this directory already use for the same job (e.g. renderer-quadratic-scan-benchmark.mjs:65,200).

Three files, one line each plus the node:url import:

  • config/scripts/session-write-hot-path-benchmark.mjs — 5 specifiers
  • config/scripts/agent-inspection-cadence-batching-benchmark.mjs — 3 specifiers
  • tests/tools/fish-mode2031-repro/capture-fish-mode2031-trace.mjs — 1 specifier

I scanned config/scripts, tests/tools and src for computed import() specifiers; these three are all of them that are not already wrapped or bare module names.

Why

These scripts are how the repo produces evidence for exactly the kind of Windows work tracked in #9300, and Windows performance work cannot cite a benchmark that cannot start. pathToFileURL is already the established idiom here rather than a new dependency or abstraction, so this is the smallest change that makes the scripts run on all three platforms; the alternative (spawning a shell so C:\... resolves) would change how the scripts are invoked and is not needed.

Linked Issue

Fixes #25235

(That issue also covers the bench:idle-cpu Windows gaps, which are a separate PR.)

Visual Proof

N/A

No UI, no user-facing behaviour: only how a benchmark script forms a module specifier.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

No new tests: the fix is one expression per import site, and the scripts themselves are the reproduction — they fail loudly before and print their tables after.

Check Command (Windows, Node 22.19) Result
bench:session-write-hot-path node config/scripts/session-write-hot-path-benchmark.mjs before: ERR_UNSUPPORTED_ESM_URL_SCHEME; after: table printed, exit 0
bench:agent-inspection-cadence node config/scripts/agent-inspection-cadence-batching-benchmark.mjs before: same error; after: table printed, exit 0
fish repro import node tests/tools/fish-mode2031-repro/capture-fish-mode2031-trace.mjs before: same error; after: import resolves and the harness starts (it then stops because its fish path is macOS-only — see Limitations)
Lint on changed files node node_modules/oxlint/bin/oxlint <3 files> pass
Changed-code gate node config/scripts/check-changed-code-quality.mjs pass, 0 findings across 3 files

Platforms tested: Windows only, which is the platform that failed. The change is platform-neutral (pathToFileURL yields file:///… everywhere) and macOS/Linux already worked, so no regression is expected there; I did not run them.

AI Disclosure

Written with an AI coding agent, session model deepseek-v4.1-flash (provider opencode-go). All commands and outputs above were produced on this machine.

Review

  • Cross-platform: the fix is the cross-platform one; it is what makes Windows match macOS/Linux. No process.platform branching added.
  • SSH / remote / local: not applicable — these scripts run locally in Node and touch no host, wire or provider path.
  • Agent and integration compatibility: no agent, provider or skill surface touched.
  • Performance risk: none to the app. The scripts do the same work; only the specifier form changed.
  • UI quality: not applicable.
  • Security: no new subprocess, network, filesystem or credential path; pathToFileURL only converts a path that was already being imported.

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Limitations: the fish mode-2031 harness is macOS/Linux-targeted (it defaults to /opt/homebrew/bin/fish), so on Windows I could only verify that its import now resolves; it still cannot complete there for unrelated reasons.
  • Backwards compatibility: no API, wire format, persisted state or build output changes.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass — lint on changed files and the changed-code gate pass; typecheck/test/build are unrelated to these scripts and could not run end to end here (no MSVC); CI will cover

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • session-write-hot-path-benchmark.mjs — wrapped 5 computed dynamic-import specifiers in pathToFileURL(...).href and imported pathToFileURL.
  • agent-inspection-cadence-batching-benchmark.mjs — wrapped 3 computed dynamic-import specifiers.
  • capture-fish-mode2031-trace.mjs — wrapped its 1 computed dynamic-import specifier.

These fix ERR_UNSUPPORTED_ESM_URL_SCHEME on Windows, where path.join(ROOT, '...ts') starts with C: and the ESM loader reads it as a URL scheme. pathToFileURL is platform-neutral and already the idiom used by sibling benchmarks.

I verified node --check passes on all three files and ran both benchmarks end to end on Linux (Node 24.19) — tables print, exit 0, so the file-URL specifiers still resolve on POSIX. I also spot-checked the completeness claim that these are the only un-wrapped computed import() sites in config/scripts/tests/tools: the rest use data: URLs, new URL(..., import.meta.url).href, or a source() helper that already returns pathToFileURL(...).href. Nothing missed.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@coderabbitai

coderabbitai Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 311c03a4-19b8-40a2-bd38-349ce278fb15
📥 Commits

Reviewing files that changed from the base of the PR and between b4d39d1c036d8541689a5345bf72558cb7368e3f and 07fae64.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c2ea0980-8838-448d-987d-65fdfd1ee6f2
📥 Commits

Reviewing files that changed from the base of the PR and between 87bc51d and b4d39d1c036d8541689a5345bf72558cb7368e3f.

📒 Files selected for processing (3)
  • config/scripts/agent-inspection-cadence-batching-benchmark.mjs
  • config/scripts/session-write-hot-path-benchmark.mjs
  • tests/tools/fish-mode2031-repro/capture-fish-mode2031-trace.mjs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

The cadence batching benchmark, session write benchmark, and fish-mode trace harness now convert filesystem paths to file URLs before dynamically importing source modules. The benchmarks retain their existing fileURLToPath imports. The trace harness keeps its node-pty loading and scanner bindings unchanged.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to b4d39

The scripts now pass file URLs for the same source modules, addressing Windows path resolution without changing their targets. No merge-blocking risk is evident.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning For #25235 Finding 1, all nine dynamic imports in the three named scripts now convert paths with pathToFileURL(...).href. However, #25235 also requires fixing the idle-CPU build and Windows CPU repo… Use the Windows-safe Electron build runner for the idle-CPU benchmark. Read Windows process CPU times and provide them to the sampler so the reported CPU values are not always zero.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: resolving dynamically imported source files as file URLs.
Description check ✅ Passed The description covers the required sections and explains the problem, change, rationale, linked issue, testing, platform limitations, and review considerations. It also explains why full lint, typech…
Out of Scope Changes check ✅ Passed All changes support #25235 Finding 1. The two benchmark scripts and the fish trace-capture harness fix the Windows dynamic-import path failure described in the issue. No unrelated changes are present.
Full details: Linked Issues check

Explanation

For #25235 Finding 1, all nine dynamic imports in the three named scripts now convert paths with pathToFileURL(...).href. However, #25235 also requires fixing the idle-CPU build and Windows CPU reporting. At the reviewed head, run-idle-cpu-benchmark.mjs still runs npx through execFileSync, and idle-cpu-process-sampling.mjs still reports Windows percentCpu: 0 and cpuTimeSeconds: null.

  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@paoValle

paoValle commented Oct 4, 2026

Copy link
Copy Markdown
Contributor Author

No actionable findings from either reviewer, so there is nothing to change here. Recording what was verified, since the only real risk in this change is a POSIX regression (the failure it fixes is Windows-only, so CI would not have caught it either way).

Analysis. The fix replaces the argument handed to import(); on macOS and Linux the previous value was an absolute POSIX path that the ESM loader accepted, so the only way this change could break is if the replacement specifier did not resolve there. pathToFileURL(...).href produces file:///… on every platform, and the targets are unchanged, so the modules resolve to the same files.

Results

check before after
bench:session-write-hot-path (Windows, Node 22.19) ERR_UNSUPPORTED_ESM_URL_SCHEME … Received protocol 'c:' table printed, exit 0
bench:agent-inspection-cadence (Windows) same error table printed, exit 0
capture-fish-mode2031-trace.mjs import same error import resolves; harness then stops because its fish path is macOS-only
node --check on all three — clean (verified by the reviewer)
macOS/Linux run of both benchmarks — tables print, exit 0 (verified by the reviewer)

Completeness. An AST-level scan of computed import() specifiers across config/scripts, tests/tools and src — argument extracted with balanced parentheses, then filtered to those that build a path and do not already call pathToFileURL — returns 5 flagged sites in exactly these 3 files. Everything else uses a literal specifier, a data: URL, new URL(..., import.meta.url), or a helper that already returns pathToFileURL(...).href, which matches the reviewer's spot check.

oxlint on the three files and the changed-code quality gate both report 0 findings.

`await import(path.join(ROOT, '...ts'))` hands Node a bare Windows path
(`C:\...`), which the ESM loader rejects as an unsupported URL scheme
("Received protocol 'c:'"). The two benchmarks that load production
modules this way crashed on Windows before running a single scenario,
while working on macOS and Linux where an absolute path is a valid
specifier.

Wrap each computed specifier in `pathToFileURL(...).href`, the form the
other benchmark scripts already use for the same purpose.

Verified on Windows: bench:session-write-hot-path and
bench:agent-inspection-cadence now run and print their measurement
tables. The fish mode-2031 trace capture resolves its import too, but its
harness targets macOS/Linux shells and cannot complete on Windows.

Fixes stablyai#25235
@paoValle
paoValle force-pushed the fix/windows-source-import-file-urls branch from b4d39d1 to 07fae64 Compare October 5, 2026 07:30
@paoValle

paoValle commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (63 commits). Nothing changed beyond the rebase; no open findings from either reviewer.

Re-ran the script this PR unblocks, on macOS / Node 24, to check that the rebase did not disturb the imports it touches:

$ node config/scripts/session-write-hot-path-benchmark.mjs
Session-write hot path — 8 retained scrollback leaves, 2000 accumulated pane keys

1. scrollback UTF-8 budget scan (16 calls/write @ 512 KB)
  before 19.997 ms → after 0.187 ms  (106.7x)
2. pane-key remap (3 maps/write @ 2000 keys)
  before 1.359 ms → after 0.563 ms  (2.4x)  — and 3 discarded objects/write become 0

That is the POSIX path, which already worked — the Windows reproduction in the body is the one that matters and I have no Windows machine to repeat it on.

Ready for review whenever there is a slot — @nwparker.

@paoValle

paoValle commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Closing this rather than letting it age. It fixes the benchmark harness on a Windows checkout, not anything a user hits, and I had seven small PRs open here at once — four fewer is a better trade for this repo than seven. #25235 stays open and this change is described in it, so it is still actionable for anyone closer to a Windows setup. Nothing in the diff is wrong; it just should not compete for your review time with the others.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Perf] Windows: two benchmarks crash on import and bench:idle-cpu cannot build or sample, so Windows KPIs are unmeasurable

1 participant