Skip to content

fix(bench): load benchmark modules under test through jiti - #23482

Merged
nwparker merged 1 commit into
mainfrom
fix/bench-terminal-partial-escape-tail-jiti
Sep 27, 2026
Merged

nwparker merged 1 commit into
mainfrom
fix/bench-terminal-partial-escape-tail-jiti

Conversation

@nwparker

@nwparker nwparker commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 0 0 0 0
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​17 $\color{#cf222e}{\Huge{\mathbf{−}}}$​7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​10

ELI5

Two of our performance measuring scripts were broken and crashed the moment you ran them. They tried to load some of the app's own code, and the way they asked for it didn't work. This teaches them to ask a different way. Nothing about the app itself changes — only the scripts a developer runs by hand.

What Changed

Before: pnpm run bench:terminal-partial-escape-tail and pnpm run bench:worktree-refresh-churn both exited immediately with ERR_MODULE_NOT_FOUND and printed no measurements at all.

After: both run and print their result tables.

The mechanism: each script is a plain .mjs file that node runs directly, and each static-imported a TypeScript module out of src/ using an explicit .ts extension. That part was fine. The failure was one level deeper — plain node's TypeScript type-stripping does no extension guessing, so the extensionless relative imports inside the loaded module's own graph could not resolve:

  • src/shared/terminal-partial-escape-tail.ts → './terminal-escape-introducer'
  • src/renderer/src/store/slices/worktree-catalog-reconciliation.ts → '../../../../shared/structural-value-equality'

Both scripts now load those modules through jiti, which resolves extensionless TypeScript specifiers across the whole graph. Only the two script files changed.

Why

Two ways to fix this were considered.

Add the missing extensions at each import site — rejected. config/tsconfig.node.json includes src/shared/**/* and does not set allowImportingTsExtensions, so a .ts specifier there fails typecheck:

error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled.

Enabling that flag is a repo-wide compiler change, and no file under src/ uses an explicit .ts relative import today — so this fix would have edited production shared code to a shape the repo does not otherwise use, in order to repair a dev script.

Load through jiti — chosen. This is the pattern four benchmarks already use for exactly this job: pty-source-ack-boundary-benchmark.mjs, locale-collator-sort-benchmark.mjs, worktree-base-pending-marker-benchmark.mjs, and wsl-hook-relay-reattach-benchmark.mjs. jiti is already resolvable in the tree (2.7.0) and no dependency was added. It keeps the fix entirely inside config/scripts/ and leaves production code untouched.

I also swept every bench:* entrypoint for this same failure shape. Exactly these two were affected; the rest either import no src/ TypeScript or already go through jiti/esbuild. One unwired script, config/scripts/terminal-reattach-payload-scan-benchmark.mjs, has the same shape but is not referenced by any package.json script, so I left it alone rather than widen the diff — noting it here as a follow-up.

Linked Issue

No pre-existing issue; internal developer-tooling fix found while running the benchmark.

Visual Proof

N/A — there is no UI, rendering, or user-visible behavior in this change. It only affects two developer benchmark scripts invoked from the command line; the app's runtime code is byte-for-byte unchanged.

Testing

Platform tested: macOS (arm64). The change is pure module resolution in Node with no platform-dependent code, so no Linux/Windows/SSH-specific paths are involved.

Reproduced the failure first on origin/main (0547b322), then verified the fix:

$ pnpm run bench:terminal-partial-escape-tail
Partial-escape-tail fold: 640 x 16 KB chunks (10.0 MB), 256 equivalence cases verified

| stream shape | before | after | |
| --- | --- | --- | --- |
| ESC-free (build logs, `cat`, piped output) | 0.19 ms | 0.18 ms | 1.1x |
| SGR-coloured output (gate does not apply) | 9.51 ms | 9.65 ms | 1.0x |

$ pnpm run bench:worktree-refresh-churn
Worktree refresh churn: 655 worktrees, 1895 tabs, 10 refreshes
Before: 5.303 ms, 10 catalog publications, 6550 rank writes
After:  4.321 ms, 0 catalog publications, 0 rank writes
Reduction: 18.5% CPU, 100% feedback publications

Both ran to completion. The escape-tail benchmark self-checks 256 equivalence cases before timing, so its run also confirms the module loaded through jiti behaves identically.

Gates run locally, all passing:

  • pnpm test on the four covering suites — src/shared/terminal-partial-escape-tail.test.ts, terminal-partial-escape-tail-ground-scan.test.ts, terminal-partial-escape-tail.fuzz.test.ts, terminal-escape-introducer.test.ts — 4 files, 29 tests passed

  • pnpm run check:code-quality:changed — 0 new findings across 2 changed files

  • oxlint — clean (exit 0)

  • oxfmt --check — all matched files correctly formatted

  • pnpm tc:node — clean (exit 0)

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

No new automated test: the fix is that two hand-run benchmark scripts start at all, and the repo does not execute bench:* scripts in CI. The existing suites listed above cover the modules being loaded and confirm nothing about them changed.

Review

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

  • Security: none — no new dependency, no network, no process spawning, no input handling.
  • Cross-platform (Linux / Windows / macOS): no platform-dependent code. jiti resolution is platform-neutral and the four existing jiti benchmarks already run on all three.
  • Remote SSH: not touched; these are local developer scripts with no execution-host involvement.
  • Mobile: not touched.
  • Backwards compatibility: no wire format, IPC channel, or persisted data involved. Production shared code is unchanged, so nothing a client or host exchanges is affected.
  • Performance: no runtime impact on the app. jiti adds a small transform cost to benchmark startup only; both benchmarks warm up and discard their first sample, so reported numbers are unaffected.

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 (or CI will cover; local preferred)

Co-authored-by: Claude [email protected]

`pnpm run bench:terminal-partial-escape-tail` and
`pnpm run bench:worktree-refresh-churn` both died at startup with
ERR_MODULE_NOT_FOUND. Each entrypoint static-imported a `src/` module with an
explicit `.ts` extension, but bare `node` type-stripping cannot resolve the
extensionless relative specifiers *inside* that module's graph
(`terminal-partial-escape-tail.ts` -> `./terminal-escape-introducer`,
`worktree-catalog-reconciliation.ts` -> `../../../../shared/structural-value-equality`).

Routes both through jiti, matching the four benchmarks that already load `src/`
TypeScript that way (`pty-source-ack-boundary`, `locale-collator-sort`,
`worktree-base-pending-marker`, `wsl-git-shell`). Adding the extension at each
import site was the alternative, but `config/tsconfig.node.json` does not set
`allowImportingTsExtensions`, so a `.ts` specifier in `src/shared` fails
typecheck with TS5097 -- and no file under `src/` uses that shape today.

Developer tooling only; no production code changed.

Co-authored-by: Claude <[email protected]>

@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

  • terminal-partial-escape-tail-benchmark.mjs — replaced the static .ts import with createJiti(import.meta.url) + await jiti.import('../../src/shared/terminal-partial-escape-tail.ts'), destructuring the three named exports.
  • worktree-refresh-churn-benchmark.mjs — same treatment for planWorktreeSortOrderUpdates and reuseEqualCatalogRows.

Both changes match the pattern already used by pty-source-ack-boundary-benchmark.mjs, locale-collator-sort-benchmark.mjs, worktree-base-pending-marker-benchmark.mjs, and wsl-hook-relay-reattach-benchmark.mjs. The diagnosis is correct: plain node type-stripping resolves the explicit .ts entrypoint but not the extensionless relative imports inside the loaded graph, and jiti is resolvable through the repo's shamefullyHoist: true install. No production code is touched, and the loaded graphs contain no @-alias imports that would need additional jiti config.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@coderabbitai

coderabbitai Bot commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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

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: 35cea6fb-930c-4a7e-83ab-0f456b3f7b42

📥 Commits

Reviewing files that changed from the base of the PR and between f72079b and 600295e.

📒 Files selected for processing (2)
  • config/scripts/terminal-partial-escape-tail-benchmark.mjs
  • config/scripts/worktree-refresh-churn-benchmark.mjs

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


📝 Walkthrough

Walkthrough

Both benchmark scripts replace direct TypeScript imports with asynchronous imports through jiti. One script loads three exports from the terminal-tail module. The other loads two exports from TypeScript modules and adds a comment about extensionless relative imports.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 60029

The benchmark-loading change is mergeable after normal checks; no unresolved issue is established.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
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 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: benchmark modules now load through jiti.
Description check ✅ Passed The description covers the required sections, explains the failure and solution, documents testing, and addresses cross-platform and compatibility considerations. The lack of a linked issue is justifi…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

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.

@nwparker
nwparker merged commit 161bdf9 into main Sep 27, 2026
34 checks passed
@nwparker
nwparker deleted the fix/bench-terminal-partial-escape-tail-jiti branch September 27, 2026 22:34
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.

1 participant