Skip to content

fix(bun): close late runtime review races - #3551

Merged
kojiwakayama merged 5 commits into
mainfrom
fix/cross-runtime-late-review-comments
Aug 10, 2026
Merged

fix(bun): close late runtime review races#3551
kojiwakayama merged 5 commits into
mainfrom
fix/cross-runtime-late-review-comments

Conversation

@kojiwakayama

@kojiwakayama kojiwakayama commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes the three late review findings posted while #3543 was entering the merge queue.

  • make Bun preload rewrite coverage separator-neutral for POSIX and Windows-style paths
  • convert the runner file URL with fileURLToPath()
  • serialize stale workspace-lock reclamation with generation-scoped atomic tombstones
  • prove concurrent reclaimers cannot remove a fresh live lock

This supersedes #3548. The replacement uses permanent generation tombstones so a crashed reclaimer cannot wedge future generations and a delayed reader cannot move a later live lock.

Verification

  • deno task test:bun: 16 harness tests and 1297 Bun test files passed
  • focused Deno preload regression: 1 test, 3 steps passed
  • deno task typecheck: passed
  • deno task lint:test-typecheck: 0 new failures
  • deno task lint: passed
  • targeted deno fmt --check, deno lint, and deno check: passed
  • mutation checks proved every new regression guard fails against the prior behavior
  • git diff --check: passed

Review lineage

Follow-up to #3543. Supersedes the interim implementation in #3548.

Summary by CodeRabbit

  • Bug Fixes

    • Improved Bun preload handling across POSIX and Windows-style paths.
    • Normalized npm protocol imports in test preload sources.
    • Improved runner path handling for reliable test execution.
    • Strengthened workspace package lock recovery during stale or concurrent lock scenarios.
  • Tests

    • Added coverage for preload rewriting, path handling, and concurrent lock recovery.

Late review exposed Bun harness gaps that could let CI miss real failures or race live workspace setup: preload rewriting depended on platform-specific paths, the empty-selection runner used URL pathname decoding, and stale lock reclamation could disturb a newer owner. The change keeps the Bun gate fail-closed while making lock reclamation generation-aware.

Constraint: Bun gate coverage must stay portable across POSIX and Windows-style paths.
Constraint: Workspace package locks can be observed between directory creation and marker publication.
Constraint: Validation is already green in the handoff lane; this commit records that evidence without rerunning or changing source.
Rejected: Keep URL.pathname for runner self-spawns | breaks paths that need file URL decoding.
Rejected: Reclaim markerless or malformed locks | races live lock initialization and erases indeterminate ownership.
Rejected: Rewrite extension imports from test-file preload paths | conflates two distinct preload rewrite rules.
Confidence: high
Scope-risk: moderate
Directive: Keep Bun empty-selection, preload rewriting, and workspace lock cleanup fail-closed across OS path spellings.
Tested: deno task test:bun (16 harness tests plus 1297 files, 0 failed).
Tested: Targeted Deno coverage for the late review changes.
Tested: deno fmt --check.
Tested: deno task lint:ci.
Tested: deno check / typecheck suites.
Tested: git diff --check.
Tested: Mutation checks for each new regression guard.
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@kojiwakayama, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 25 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 228ee5b6-8239-47f4-badb-c571388402a7

📥 Commits

Reviewing files that changed from the base of the PR and between 0a5fb19 and addefcf.

📒 Files selected for processing (4)
  • tests/bun/npm-protocol-resolution.test.ts
  • tests/bun/preload-rewrite.ts
  • tests/bun/workspace-packages.mjs
  • tests/bun/workspace-packages.test.mjs
📝 Walkthrough

Walkthrough

The PR centralizes Bun preload rewriting, fixes Bun runner filesystem path handling, and hardens workspace preparation lock recovery with generation markers, atomic reclamation, tombstones, and concurrency tests.

Changes

Bun preload rewriting

Layer / File(s) Summary
Preload rewrite pipeline
tests/bun/preload-rewrite.ts, tests/bun/preload.ts, tests/bun/npm-protocol-resolution.test.ts
Adds shared filtering and rewriting for extension and test preload sources. Tests cover POSIX and Windows-style paths, extension imports, and npm: normalization.

Bun runner path handling

Layer / File(s) Summary
Runner filesystem path regression
tests/bun/runner-args.test.mjs
Uses fileURLToPath for the runner script and verifies that URL.pathname is not used.

Workspace lock recovery

Layer / File(s) Summary
Lock marker acquisition
tests/bun/workspace-packages.mjs
Adds atomic lock markers containing owner, PID, and generation token data.
Stale lock reclamation
tests/bun/workspace-packages.mjs
Validates lock ownership, atomically claims stale generations, handles races, and preserves tombstone guards.
Lock recovery validation
tests/bun/workspace-packages.test.mjs
Tests dead-owner recovery, concurrent reclaimers, orphaned guards, and cleanup behavior.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant BunOnLoad
  participant rewriteBunPreloadSource
  participant rewriteModuleSpecifiers
  BunOnLoad->>rewriteBunPreloadSource: path and source
  rewriteBunPreloadSource->>rewriteModuleSpecifiers: extension source imports
  rewriteBunPreloadSource-->>BunOnLoad: rewritten source
Loading
sequenceDiagram
  participant PreparationProcessA
  participant PreparationProcessB
  participant reclaimStalePreparationLock
  PreparationProcessA->>reclaimStalePreparationLock: claim stale lock generation
  PreparationProcessB->>reclaimStalePreparationLock: claim stale lock generation
  reclaimStalePreparationLock-->>PreparationProcessA: reclaimed generation tombstone
  reclaimStalePreparationLock-->>PreparationProcessB: active-lock conflict
Loading

Possibly related PRs

Suggested reviewers: kwakayama

🚥 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the Bun fixes for late runtime review races addressed by the changeset.
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.
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/cross-runtime-late-review-comments

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

@kojiwakayama

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 0a5fb19d10

ℹ️ 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".

@kojiwakayama

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@kojiwakayama

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/bun/preload-rewrite.ts`:
- Around line 16-18: Align the rewrite condition in the preload contents flow
with the filter’s extension-source predicate, limiting rewriting to paths
matching extensions/ext-*/src/* rather than every path containing /extensions/.
First add a focused regression test covering a .test.ts path under another
extensions subdirectory, then update the condition using the existing predicate
or equivalent shared logic.

In `@tests/bun/workspace-packages.mjs`:
- Around line 65-68: Update createPreparationLock so it creates and writes the
marker in a unique sibling temporary directory before publishing it via
renameSync to lockPath, making directory creation and marker presence atomic to
acquirers. If the final rename fails, remove the temporary directory and
propagate the rename error.

In `@tests/bun/workspace-packages.test.mjs`:
- Around line 224-227: Add a synchronization barrier to the two
runWorkspacePreparationChild flows after their liveness checks and before
renameSync, tracking both child arrivals and releasing them only once the parent
observes both have reached the barrier. Replace the fixed pause with this
coordination so the test deterministically exercises the delayed
stale-generation reader case.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 71fed29e-1556-4184-a970-d5a6a95bbd5a

📥 Commits

Reviewing files that changed from the base of the PR and between 80fb3a0 and 0a5fb19.

📒 Files selected for processing (6)
  • tests/bun/npm-protocol-resolution.test.ts
  • tests/bun/preload-rewrite.ts
  • tests/bun/preload.ts
  • tests/bun/runner-args.test.mjs
  • tests/bun/workspace-packages.mjs
  • tests/bun/workspace-packages.test.mjs

Comment thread tests/bun/preload-rewrite.ts Outdated
Comment thread tests/bun/workspace-packages.mjs Outdated
Comment thread tests/bun/workspace-packages.test.mjs Outdated
CI exposed that the lock-race child process inherits process.execPath from Deno during integration coverage, where Node's --input-type flag is not valid. The harness now follows the existing runtime-specific eval-args pattern so the child exercises the active runtime instead of assuming Node-style process flags.

Constraint: Deno integration can execute this Bun harness with process.execPath pointing at Deno.

Constraint: Node-compatible child evals still require the existing --input-type=module path.

Rejected: Always spawn with Node-only --input-type flags | fails under Deno with a SyntaxError before the race guard runs.

Rejected: Skip the race child outside Node | would leave the late Bun lock cleanup path unverified in Deno integration.

Confidence: high

Scope-risk: narrow

Directive: Keep workspace lock race children aligned with the active runtime's eval argument shape.

Tested: Full file Deno run, 10/10 passed sequentially.

Tested: Full file Node run, 10/10 passed sequentially.

Tested: Targeted Deno final green.

Tested: Mutation check fails with the exact SyntaxError.

Tested: deno fmt --check.

Tested: deno task lint:ci.

Tested: deno check / typecheck suites.

Tested: git diff --check.
@kojiwakayama

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

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: b4b1ecba2c

ℹ️ 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 tests/bun/workspace-packages.mjs Outdated
@kojiwakayama

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: addefcfa8e

ℹ️ 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".

@kojiwakayama
kojiwakayama added this pull request to the merge queue Aug 10, 2026
Merged via the queue into main with commit 8d14243 Aug 10, 2026
33 checks passed
@kojiwakayama
kojiwakayama deleted the fix/cross-runtime-late-review-comments branch August 10, 2026 19:04
@kwakayama kwakayama mentioned this pull request Aug 10, 2026
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