Skip to content

fix(test): reduce focused Bun test startup latency - #172967

Merged
steipete merged 2 commits into
mainfrom
steipete/bunfix-inner-1014
Oct 15, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/bunfix-inner-1014

Conversation

@steipete

@steipete steipete commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Focused pnpm test <file> runs on Bun paid for a whole-repository file inventory and discarded Bun's compiler cache when the test HOME was cleaned up.

User Impact

The measured small-file runs start faster on both runtimes while keeping the same setup and test coverage. Bun remains slower than Node in that comparison; this change does not claim runtime parity or eliminate loaded-host variance.

Why This Change Was Made

  • Harness defect (bucket 1): the process owner now preserves Bun's content-addressed transpiler cache in the checkout's .cache/bun-transpiler directory before isolating HOME. Explicit paths, empty values, and 0 remain unchanged. The cache ownership regression exercises real child processes.
  • Harness defect (bucket 1): exact-file routing now requests literal, bounded Git inventories. UI ownership reuses directory-scoped Git inventories, including indexed owners in sparse checkouts, without per-file filesystem probes. Broad discovery, ignored/untracked files, missing owners, and TS/TSX renames retain their existing contracts.

There are no product-code changes, dependency changes, new runtime skips, or timeout increases. Net LOC: product 0; harness +32; tests +16; documentation +4.

Evidence

Pinned Bun: 1.4.3-canary.1+65d94e715. Same shared macOS host, alternating Node/Bun order, --maxWorkers=1, short TMPDIR, first pair excluded. p90 uses nearest rank. Host contention varied substantially, so the timings quantify the observed runs rather than establish a stable speed ratio.

Small file: packages/markdown-core/src/fences.test.ts. Nine warm baseline samples and five warm final-candidate samples per runtime. Each cell is median / p90 seconds.

Runtime Version Wall Shard Vitest
Node Before 10.254 / 20.888 5.460 / 11.160 0.915 / 1.240
Node After 4.305 / 8.114 2.650 / 6.280 0.603 / 0.772
Bun Before 26.013 / 76.052 22.980 / 71.650 8.320 / 51.190
Bun After 6.748 / 14.599 5.020 / 12.300 2.580 / 4.990

Heavier file: src/config/schema.test.ts (26 tests). Two warm samples per runtime/version, first pair excluded. Each cell is median / p90 seconds.

Runtime Version Wall Shard Vitest
Node Before 137.088 / 197.919 121.505 / 176.530 90.480 / 142.450
Node After 130.630 / 155.004 128.100 / 152.490 90.960 / 107.630
Bun Before 202.522 / 254.510 182.155 / 230.730 121.920 / 137.120
Bun After 91.829 / 101.912 89.125 / 99.310 65.325 / 70.090

The final candidate uses directory-scoped Git inventories for UI ownership. Timings from the superseded per-file filesystem-probe implementation are excluded from the after columns. The baseline heavy cold pair is excluded because it overlapped auxiliary cache tracing/review work. session-actor.test.ts passed its baseline runs, but its candidate Node attempt was interrupted after about eight minutes; the completed schema comparison replaces it.

Both runtimes passed all 34 applicable tests in the three-file harness proof. One existing Windows-only test remains skipped on macOS:

export PATH=/private/tmp/oc-bun-fork/bin:$PATH
export TMPDIR=/private/tmp/oc-inner
OPENCLAW_VITEST_RUNTIME=node pnpm test test/scripts/vitest-process-cache.test.ts test/vitest-unit-fast-config.test.ts test/scripts/ui-tsx-discovery.test.ts --maxWorkers=1 --pool=forks
OPENCLAW_VITEST_RUNTIME=bun pnpm test test/scripts/vitest-process-cache.test.ts test/vitest-unit-fast-config.test.ts test/scripts/ui-tsx-discovery.test.ts --maxWorkers=1 --pool=forks

The initial PR CI found that resolving UI owners through existsSync violated the planner's zero-probe contract. The final correction retains the original assertion and passes all 29 selected routing/TSX/no-scan tests on both runtimes:

OPENCLAW_VITEST_RUNTIME=node pnpm test test/vitest-unit-fast-config.test.ts test/scripts/ui-tsx-discovery.test.ts test/scripts/ci-node-test-plan.test.ts --maxWorkers=1 --pool=forks -t 'unit-fast vitest lane|TSX discovery|creates split shards without walking test roots'
OPENCLAW_VITEST_RUNTIME=bun pnpm test test/vitest-unit-fast-config.test.ts test/scripts/ui-tsx-discovery.test.ts test/scripts/ci-node-test-plan.test.ts --maxWorkers=1 --pool=forks -t 'unit-fast vitest lane|TSX discovery|creates split shards without walking test roots'

The other CI failure, keeps selected Gateway and embedded-agent work within its runner capacity, reproduces on unchanged base 39bad21f1fad (expected one concurrent job, got zero). It is inherited and left unchanged. The failed-CI helper initially classified it as unknown because no matching main job was available; the local baseline run proves attribution.

Two default-thread attempts were interrupted after long pre-test waits; the complete proof above uses Vitest's supported fork pool. The latency benchmarks use the unchanged default pool. The new regression assertions fail against the original implementation: missing persistent Bun cache in two HOME modes and an unwanted broad inventory scan.

Formatting, scoped script/test lint, pnpm tsgo:scripts, root tooling/root other test typechecks, and git diff --check pass. Codex autoreview is clean through P2.

Investigation

  • Whole-repository Git inventory took 1.7–76.5 s in standalone interleaved probes; the literal selected-file query took 0.03 s. Median overhead outside the shard fell from 4.45 to 1.83 s on Node and 4.06 to 1.77 s on Bun.
  • Two consecutive warm Bun DEBUG=vitest:cache:fs runs each recorded 37 reads, zero writes, zero misses, and zero cache clears. The checkout/config cache slot is stable; Vitest filesystem-cache misses are not the remaining slowdown. Bun's separate native transpiler cache previously lived under the disposable HOME. In the earlier cache-location probe (two warm samples each), shard medians were 46.84 s at the disposable default, 29.14 s at a persistent path, and 50.98 s with that cache disabled; changing host load limits causal timing claims.
  • Actual compile-cache enablement requires the variable to be absent: 0 and 1 both disable it on Node and Bun. Three alternating absent/present pairs gave median wall 16.58/19.46 s, but p90 29.03/20.06 s; later warm pairs were inconsistent. The existing disable setting stays. The earlier 1 versus 0 comparison is not used as evidence of enablement.
  • Raw Vitest import medians were 0.47 s on Node, 0.49 s on Bun with transpiler cache disabled, and 0.64 s with a persistent cache. Removing the resolver override increased Bun's median to 1.36 s, so it stays. In the earlier cache-location probes, warm per-file preparation medians were 7–99 ms, setup 0.24–0.64 s, and test bodies 4–7 ms; most elapsed time occurred before collection/execution.
  • The default and runner config loaders had essentially equal warm shard times (11.94 vs 11.88 s in the probe); the loader stays unchanged.
  • SQLite capability admission remains intact. An isolated probe measured 2.66 s import + 15.09 s admission initially, then 0.14 s + 1.42 s warm. Both decisions were successful.
  • No evidence established GC as the cause of outliers. Native samples showed file I/O/waiting, and standalone Git reproduced large variance. No Bun API conformance defect was established.

Follow-up: Bun still has a measurable transform/setup gap after these two harness fixes. Further runtime profiling is warranted before claiming Node parity. No new runtime-only skip or fork workaround is introduced.

@steipete
steipete marked this pull request as ready for review October 15, 2026 08:57
@clawsweeper

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

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation scripts Repository scripts labels Oct 15, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-15T09:53:40.644181Z 551e8c2 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1146b11f08

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread test/vitest/vitest.ui-paths.mjs Outdated
Comment on lines 55 to 56
if (existsSync(resolve(cwd, file))) {
return file;

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.

P2 Badge Keep ignored files out of UI owner resolution

When a tracked UI test is renamed from .ts to .tsx while an ignored stale .ts remains on disk (for example via .git/info/exclude), this filesystem check selects the ignored file before consulting the Git inventory. The previous --exclude-standard inventory instead selected the tracked .tsx; now timing or node-driven ownership can execute stale local code and misroute or omit the tracked test. Keep the repository inventory authoritative when it is available, using filesystem checks only as its fallback.

AGENTS.md reference: AGENTS.md:L19-L19

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. 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 15, 2026
@clawsweeper

clawsweeper Bot commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR preserves Bun’s transpiler cache across isolated test homes and narrows exact-file test discovery.

Example: Run pnpm test packages/markdown-core/src/fences.test.ts repeatedly with Bun.

  • Before: Routing inventories the repository, and HOME cleanup discards the default transpiler cache.
  • After: Routing requests a literal selected-file inventory, and the transpiler cache survives in .cache/bun-transpiler.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) Useful measured tooling work with shipped-command evidence, held back by two concrete UI discovery regressions.
Proof confidence 🐚 platinum hermit (4/6) Maintainer-authored PR is outside the contributor proof gate; supplied macOS Node/Bun pnpm test benchmarks exercise focused routing and persistent caching, with completed small-file and schema runs and explicit variance limits.
Patch quality 🦪 silver shellfish (2/6) 2 actionable review findings remain.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Developers wait disproportionately long for focused Bun test runs because discovery and disposable compiler caches add startup work.
Reason: The maintainer-authored direction targets measured overhead without adding configuration or changing test assertions.

Merge readiness

⛔ Needs changes before merge - 2 items remain

Keep open: the measured startup improvement is worthwhile, but the UI ownership shortcut admits ignored files and breaks the planner’s filesystem-probe contract.

Priority: P2
Reviewed head: 1146b11f08d6a2cf5d9ff84670ad6315fb118a7f

Before merge

  • Keep Git membership authoritative for renamed UI owners (P2) - If ui/src/app/bootstrap.test.ts is renamed to tracked bootstrap.test.tsx while an ignored stale .ts remains, this early return chooses the ignored file. Previously the exclude-standard inventory selected the .tsx owner. uiIsolatedTestFiles then contains the stale path, so the tracked replacement loses its isolated execution ownership; E2E owner selection can likewise omit the replacement. Consult Git membership before accepting either filesystem path, preserving fallback when Git is unavailable. This also confirms the existing Codex discussion.
  • Preserve scan-free planner imports (P2) - Every UI owner resolution now performs existsSync before consulting the shared snapshot, including repeated resolutions during planner imports. The exact-head CI job records 843 probes and fails the existing creates split shards without walking test roots contract at test/scripts/ci-node-test-plan.test.ts:2322. This replaces cached set membership with repeated synchronous filesystem work on the planning path and violates the repository's lifecycle-owned metadata reuse guidance. Reuse cached inventory facts for broad planning rather than weakening the assertion.

Findings

  • [P2] Keep Git membership authoritative for renamed UI owners — test/vitest/vitest.ui-paths.mjs:55-60
  • [P2] Preserve scan-free planner imports — test/vitest/vitest.ui-paths.mjs:55-59

Tests

  • Missing end-to-end proof: Existing proof does not cover an ignored stale TS file beside its tracked TSX replacement.
Agent review details

How this fits together

Repository test tooling converts selected paths into Vitest projects, resolves UI execution owners, and launches children with isolated homes and owned caches.

flowchart TD
  A[Selected test paths] --> B[Test project router]
  B --> C[Git inventory and UI ownership]
  C --> D[Vitest project selection]
  D --> E[Owned child process]
  E --> F[Isolated HOME]
  E --> G[Bun transpiler cache]
Loading

Technical review

Best possible solution:

Keep persistent Bun caching and bounded exact-file inventories while restoring authoritative, cached Git membership for UI ownership.

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

Baseline source performs broad inventory discovery and removes isolated HOME; supplied CLI benchmarks exercise that overhead, while exact-head CI confirms the introduced planner-probe regression.

Is this the best way to solve the issue?

The cache and bounded-inventory changes address the measured causes, but filesystem-first UI resolution weakens an existing ownership contract and should be repaired.

Full review comments:

  • [P2] Keep Git membership authoritative for renamed UI owners — test/vitest/vitest.ui-paths.mjs:55-60
    If ui/src/app/bootstrap.test.ts is renamed to tracked bootstrap.test.tsx while an ignored stale .ts remains, this early return chooses the ignored file. Previously the exclude-standard inventory selected the .tsx owner. uiIsolatedTestFiles then contains the stale path, so the tracked replacement loses its isolated execution ownership; E2E owner selection can likewise omit the replacement. Consult Git membership before accepting either filesystem path, preserving fallback when Git is unavailable. This also confirms the existing Codex discussion.
    Confidence: 0.99
  • [P2] Preserve scan-free planner imports — test/vitest/vitest.ui-paths.mjs:55-59
    Every UI owner resolution now performs existsSync before consulting the shared snapshot, including repeated resolutions during planner imports. The exact-head CI job records 843 probes and fails the existing creates split shards without walking test roots contract at test/scripts/ci-node-test-plan.test.ts:2322. This replaces cached set membership with repeated synchronous filesystem work on the planning path and violates the repository's lifecycle-owned metadata reuse guidance. Reuse cached inventory facts for broad planning rather than weakening the assertion.
    Confidence: 1

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • UI ownership and shared inventory changes intended behavior with a stated reason (4519033: Share one working-tree snapshot while preserving renamed and sparse owners without per-owner filesystem probes.)
  • Scoped fast-lane discovery keeps the original intent (bd9b1b4: Scope unit-fast discovery to selected work; subsequent shared-inventory history retained ignored-file and forced-owner rules.)
  • Owned child cache environment keeps the original intent (762063f: Allow source subprocess transform reuse inside the owned temporary namespace while preserving tooling isolation.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test test/scripts/ui-tsx-discovery.test.ts test/vitest-unit-fast-config.test.ts test/scripts/vitest-process-cache.test.ts --maxWorkers=1 --pool=forks
  • pnpm test test/scripts/ci-node-test-plan.test.ts --maxWorkers=1
  • pnpm tsgo:scripts
  • git diff --check

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 235df0b adds test/vitest/vitest.ui-paths.mjs:39 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 235df0bd2196; files: test/vitest/vitest.ui-paths.mjs)
  • Vincent Koc: Raw commit 8d1ab6c adds scripts/lib/vitest-process.mts:23 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 8d1ab6c88f17; files: scripts/lib/vitest-process.mts)

PR surface

Tests +39, Docs +4, Other +7. Total +50 across 7 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 5 72 33 +39
Docs 1 4 0 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 1 7 0 +7
Total 7 83 33 +50

Labels

Label changes:

  • add P2: Useful developer-tooling performance work with focused discovery regressions and limited runtime impact.
  • add merge-risk: 🚨 automation: Changed UI ownership can misroute test coverage and introduces a verified planner CI failure.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🐚 platinum hermit and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: Useful developer-tooling performance work with focused discovery regressions and limited runtime impact.
  • merge-risk: 🚨 automation: Changed UI ownership can misroute test coverage and introduces a verified planner CI failure.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🐚 platinum hermit 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.

Reviewed October 15, 2026, 5:14 AM ET / 09:14 UTC.

Keep Bun transpiler caches across isolated test homes and avoid whole-repository Git inventories for exact-file test routing. Preserve sparse checkout and rename ownership, broad discovery, and explicit cache overrides.
Resolve UI owners through cached directory-scoped Git inventories and reuse a full snapshot when one is already available. This preserves sparse checkouts and TS/TSX renames without probing every owner during CI plan imports.
@steipete
steipete force-pushed the steipete/bunfix-inner-1014 branch from ca98363 to 551e8c2 Compare October 15, 2026 09:49
@steipete
steipete merged commit 4049dc4 into main Oct 15, 2026
121 checks passed
@steipete
steipete deleted the steipete/bunfix-inner-1014 branch October 15, 2026 10:05
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 16, 2026
* fix(test): reduce focused Bun test startup latency

Keep Bun transpiler caches across isolated test homes and avoid whole-repository Git inventories for exact-file test routing. Preserve sparse checkout and rename ownership, broad discovery, and explicit cache overrides.

* fix(test): keep CI planning free of filesystem probes

Resolve UI owners through cached directory-scoped Git inventories and reuse a full snapshot when one is already available. This preserves sparse checkouts and TS/TSX renames without probing every owner during CI plan imports.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. scripts Repository scripts size: S 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