Skip to content

Fix TLA sibling import running before shared dep settles (#30259) - #30262

Merged
dylan-conway merged 2 commits into
mainfrom
claude/fix-30259-tla-sibling-tests
May 7, 2026
Merged

dylan-conway merged 2 commits into
mainfrom
claude/fix-30259-tla-sibling-tests

Conversation

@sosukesuzuki

@sosukesuzuki sosukesuzuki commented May 5, 2026 •

Copy link
Copy Markdown
Member

Fixes #30259. Bumps WebKit to 88b2f7a2159c913f7dd0d73c0e88d66138cd67ba (oven-sh/WebKit#215, merged).

What

A static import that re-imports a TLA dep already visited by a sibling earlier in the same Evaluate() pass was skipping the spec-mandated wait and running with the dep's post-await bindings still in TDZ:

// root.ts
import { foo } from "./await.ts"; // await.ts → EvaluatingAsync, suspended at `await 0`
import "./child.ts";              // child.ts visits await.ts, skips wait, runs too early

// await.ts
await 0;
export const foo = 123;

// child.ts
import { foo } from "./await.ts";
console.log(foo); // ReferenceError: Cannot access 'foo' before initialization

Why

The Bun-specific skip at innerModuleEvaluation 11.c.v (which avoids self-deadlock when require(esm) / dynamic import re-enters a TLA module from inside its own suspension) used pendingAsyncDependencies == 0 as the discriminator for "body already entered". A TLA dep with no async deps of its own also has count 0 after suspending at its first await within the same DFS, so the discriminator matched the sibling case.

How (oven-sh/WebKit#215)

Snapshot vm.moduleAsyncEvaluationCount() at the start of each Evaluate() and thread it through innerModuleEvaluation as asyncOrderWatermark. Only skip the wait when the cycle root's asyncEvaluationOrder() predates the watermark (i.e. it became EvaluatingAsync in a prior Evaluate() — the re-entrant deadlock case). Siblings that transition during the current DFS get order >= watermark and keep the spec wait.

Tests

Two regression tests in test/js/bun/resolve/dynamic-import-tla-cycle.test.ts:

  • direct sibling re-import (the issue repro)
  • indirectly-shared TLA dep through different parents (guards against discriminating by "asyncParentModule on stack")

Existing re-entrancy / deadlock-avoidance tests in the same file continue to pass.

@robobun

robobun commented May 5, 2026 •

Copy link
Copy Markdown
Collaborator
Updated 6:47 PM PT - May 6th, 2026

❌ @sosukesuzuki, your commit 812e833 has 2 failures in Build #52302 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 30262

That installs a local version of the PR into your bun-30262 executable, so you can run:

bun-30262 --bun

@coderabbitai

coderabbitai Bot commented May 5, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 4645f14e-ba9f-40ab-9fbc-8e182ea83d6e

📥 Commits

Reviewing files that changed from the base of the PR and between dc64adc and 812e833.

📒 Files selected for processing (2)
  • scripts/build/deps/webkit.ts
  • test/js/bun/resolve/dynamic-import-tla-cycle.test.ts

Walkthrough

Updates the exported WEBKIT_VERSION used for prebuilt WebKit selection and adds two tests verifying static sibling import behavior with top-level await in the module resolver.

Changes

WebKit version bump + TLA static-sibling tests

Layer / File(s) Summary
Build artifact identity
scripts/build/deps/webkit.ts
WEBKIT_VERSION value changed from 39862040be27e0b6e1d103aaa5dc6796f21a581f to autobuild-preview-pr-215-df660a83, altering which prebuilt WebKit tarball/tag is selected.
Tests
test/js/bun/resolve/dynamic-import-tla-cycle.test.ts
Adds two tests: one for a direct sibling where a module with a top-level await suspends before exporting a binding and a sibling reads it; one for an indirectly-shared TLA dep where two parents import the same TLA module and a later subtree reads the exported binding. Each asserts empty stderr, exact stdout, and exit code 0.

Possibly related PRs

  • oven-sh/bun#29770: Related change touching the same test area and WebKit autobuild version.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main fix: resolving a TLA sibling import ordering issue where imports execute before dependencies settle.
Description check ✅ Passed The description comprehensively addresses the template requirements with detailed explanations of what the PR does, why the bug occurred, and how it was fixed, plus verification through test cases.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🤖 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 `@scripts/build/deps/webkit.ts`:
- Line 6: The WEBKIT_VERSION string produces non-discriminating slices; derive a
short, unique identifier by extracting the commit-hash suffix from
WEBKIT_VERSION (e.g., take the substring after the last '-' or match
/([0-9a-f]{7,})$/) into a new variable like webkitVersionHash (falling back to
WEBKIT_VERSION if no hash found), then replace uses that currently call slice(…)
on WEBKIT_VERSION for cache keys and log identifiers with this webkitVersionHash
(or the full WEBKIT_VERSION where you prefer full uniqueness) so cache keys and
logs become discriminative.
- Line 6: The comparison in sync-webkit-source.ts currently does
checkedOutCommit == expectedCommit where checkedOutCommit is a 40-char SHA (from
git rev-parse HEAD) and expectedCommit is now a tag string like
WEBKIT_VERSION/autobuild-preview-pr-215-df660a83, so update the logic in the
function that performs the checkout check (variables checkedOutCommit and
expectedCommit) to either resolve the tag to its full SHA via git rev-parse
<tag> and compare SHAs, or detect if HEAD points to that tag by checking git
describe --exact-match HEAD or git name-rev --name-only HEAD and comparing
names; also update the cache key generation (the code that uses slice(0, 16) on
the WEBKIT_VERSION/tag string) to use a longer slice such as slice(0, 25) so
preview builds including the PR number produce distinct cache keys.
🪄 Autofix (Beta)

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: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: df105d9e-4476-413d-a33f-a4b54431a8c2

📥 Commits

Reviewing files that changed from the base of the PR and between 0a7bed5 and dc64adc.

📒 Files selected for processing (2)
  • scripts/build/deps/webkit.ts
  • test/js/bun/resolve/dynamic-import-tla-cycle.test.ts

Comment thread scripts/build/deps/webkit.ts Outdated
* From https://github.com/oven-sh/WebKit releases.
*/
export const WEBKIT_VERSION = "39862040be27e0b6e1d103aaa5dc6796f21a581f";
export const WEBKIT_VERSION = "autobuild-preview-pr-215-df660a83";

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.

🧹 Nitpick | 🔵 Trivial | ⚡ Quick win

Consider improving cache key and logging discriminability.

The version format "autobuild-preview-pr-215-df660a83" will produce non-discriminating substrings when sliced:

  • Line 86: slice(0, 16) → "autobuild-previe" (same for all autobuild-preview-pr-* builds)
  • Context snippet 3: slice(0, 10) → "autobuild-" (same for all autobuild variants)

These slices are used in cache keys and build logs. Consider either:

  1. Using the full version string for cache keys (line 86), or
  2. Extracting and using the commit hash suffix (df660a83) for shorter identifiers
♻️ Proposed fix to use the hash suffix for cache keys

At line 86, extract the hash suffix instead of a fixed-length slice:

 function prebuiltDestDir(cfg: Config): string {
-  const version16 = cfg.webkitVersion.slice(0, 16);
+  // Extract hash suffix for autobuild-* tags, or use first 16 chars for plain hashes
+  const match = cfg.webkitVersion.match(/-([0-9a-f]{8,})$/);
+  const versionKey = match ? match[1].slice(0, 8) : cfg.webkitVersion.slice(0, 16);
   // Cross-compiled targets share a host (and cache dir) with native builds,

And at line 92, use the extracted key:

-  return resolve(cfg.cacheDir, `webkit-${version16}${osKey}${archKey}${prebuiltSuffix(cfg)}`);
+  return resolve(cfg.cacheDir, `webkit-${versionKey}${osKey}${archKey}${prebuiltSuffix(cfg)}`);
🤖 Prompt for 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.

In `@scripts/build/deps/webkit.ts` at line 6, The WEBKIT_VERSION string produces
non-discriminating slices; derive a short, unique identifier by extracting the
commit-hash suffix from WEBKIT_VERSION (e.g., take the substring after the last
'-' or match /([0-9a-f]{7,})$/) into a new variable like webkitVersionHash
(falling back to WEBKIT_VERSION if no hash found), then replace uses that
currently call slice(…) on WEBKIT_VERSION for cache keys and log identifiers
with this webkitVersionHash (or the full WEBKIT_VERSION where you prefer full
uniqueness) so cache keys and logs become discriminative.

⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Verify WEBKIT_VERSION usage and potential format mismatches

# Check sync-webkit-source.ts comparison logic
echo "=== sync-webkit-source.ts comparison logic ==="
rg -nA2 -B2 'WEBKIT_VERSION.*expectedCommit|checkedOutCommit.*WEBKIT_VERSION' scripts/

# Check all slice operations on webkitVersion/WEBKIT_VERSION
echo -e "\n=== All slice operations on webkit version ==="
rg -nP '(webkitVersion|WEBKIT_VERSION)\.slice\(' scripts/

# Check if there are any git checkout commands using WEBKIT_VERSION
echo -e "\n=== Git checkout usage ==="
rg -n 'git checkout.*WEBKIT_VERSION|git checkout.*expectedCommit' scripts/

Repository: oven-sh/bun

Length of output: 834


Fix git checkout comparison to handle tag-based versions.

The new format "autobuild-preview-pr-215-df660a83" is a git tag name, not a commit SHA. In sync-webkit-source.ts line 17, the comparison checkedOutCommit == expectedCommit will always fail—checkedOutCommit is a full 40-character SHA from git rev-parse HEAD, while expectedCommit is now a tag name string. This causes unnecessary git checkout attempts even when already at the correct commit. Update the comparison logic to either resolve the tag to a full SHA or check if the current HEAD matches the tag name.

Additionally, the cache key at line 86 using slice(0, 16) produces "autobuild-previe" for all "autobuild-preview-pr-*" versions, causing cache collisions between different preview builds. Increase the slice length to distinguish between builds (e.g., slice(0, 25) to include the PR number).

🤖 Prompt for 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.

In `@scripts/build/deps/webkit.ts` at line 6, The comparison in
sync-webkit-source.ts currently does checkedOutCommit == expectedCommit where
checkedOutCommit is a 40-char SHA (from git rev-parse HEAD) and expectedCommit
is now a tag string like WEBKIT_VERSION/autobuild-preview-pr-215-df660a83, so
update the logic in the function that performs the checkout check (variables
checkedOutCommit and expectedCommit) to either resolve the tag to its full SHA
via git rev-parse <tag> and compare SHAs, or detect if HEAD points to that tag
by checking git describe --exact-match HEAD or git name-rev --name-only HEAD and
comparing names; also update the cache key generation (the code that uses
slice(0, 16) on the WEBKIT_VERSION/tag string) to use a longer slice such as
slice(0, 25) so preview builds including the PR number produce distinct cache
keys.

@github-actions

github-actions Bot commented May 5, 2026

Copy link
Copy Markdown
Contributor

Found 2 issues this PR may fix:

  1. ReferenceError: Cannot access uninitialized variable #2927 - Reports ReferenceError: Cannot access uninitialized variable on ESM imports, linked to WebKit bug #242740 and WebKit PR Add --catalog flag to bun add for catalog-based dependency management #24122 — the exact TDZ violation caused by skipping the spec-mandated wait in sibling TLA evaluation
  2. Incorrect module import behaviour (probably JSC bug?) #7342 - Incorrect module import behaviour with TLA shared deps; Jarred noted it is "Likely fixed by [JSC] ReferenceError when multiple modules are simultaneously importing a module containing a top-level await WebKit/WebKit#24122" — the same WebKit fix this PR merges

If this is helpful, copy the block below into the PR description to auto-close these issues on merge.

Fixes #2927
Fixes #7342

🤖 Generated with Claude Code

Comment thread scripts/build/deps/webkit.ts Resolved
@sosukesuzuki
sosukesuzuki force-pushed the claude/fix-30259-tla-sibling-tests branch from dc64adc to 812e833 Compare May 7, 2026 00:18

@claude claude 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.

LGTM — thanks for swapping to the merged commit SHA; that resolves my earlier concern about the preview-PR tag.

Extended reasoning...

Overview

On the Bun side this PR is now just two things: a one-line WEBKIT_VERSION bump from 39862040… to 88b2f7a2… (the merged commit for oven-sh/WebKit#215), and two new regression tests in test/js/bun/resolve/dynamic-import-tla-cycle.test.ts that exercise the #30259 repro and an indirect-parent variant. The actual behavioural fix lives in the WebKit fork and was reviewed/merged there.

What changed since my last review

Previously WEBKIT_VERSION was set to the ephemeral autobuild-preview-pr-215-df660a83 tag, which I flagged for artifact-GC and cache-key-collision risk. The author has replaced it with the stable 40-char merged SHA exactly as requested, which also moots CodeRabbit's slice(0,16) cache-key concern (88b2f7a2159c913f is unique). Nothing else changed.

Security risks

None. This is a dependency pin bump within Bun's own WebKit fork plus added test fixtures that spawn bunExe() in a temp dir. No auth, crypto, network, or user-input handling is touched.

Level of scrutiny

Low-to-moderate. WebKit bumps are a routine, well-trodden path in this repo and CI runs the full suite against the new build. The new tests are copy-pattern siblings of the three existing tests in the same file (same tempDir/Bun.spawn/expect(stderr).toBe("") structure) — straightforward to verify by inspection.

Other factors

The bug-hunting system found no issues in the current revision. The added tests directly encode the issue repro and a guard against an alternative (incorrect) discriminator, and the pre-existing deadlock-avoidance tests in the same file remain to catch regressions in the other direction.

@dylan-conway
dylan-conway merged commit 79c3d4d into main May 7, 2026
75 of 77 checks passed
@dylan-conway
dylan-conway deleted the claude/fix-30259-tla-sibling-tests branch May 7, 2026 18:17
alii added a commit that referenced this pull request May 12, 2026
… module no longer hangs (#30537)

A second `await import()` of a path whose first import threw used to
hang forever instead of re-throwing. Two reported variants:

- **#23139**: same path twice
- **#22743**: path X, then a *different* error path Y, then X again
(true regression, 1.2.20 → 1.2.21)

While verifying #30527 I checked whether oven-sh/WebKit#225 covered
these — turns out both were **already fixed** before that bump (main +
WebKit `88b2f7a2` doesn't hang either). The fix landed somewhere in the
module-loader rewrite window (#29393 → #30262); the issues just never
got re-tested.

| build | #23139 | #22743 |
|---|---|---|
| 1.3.13 | hangs | hangs |
| main + WebKit `88b2f7a2` (pre-#30527) | ✅ | ✅ |
| main + WebKit `5488984d` | ✅ | ✅ |

Both tests fail on `USE_SYSTEM_BUN=1` (stdout missing the post-hang
lines, killed by spawn timeout) and pass on `bun bd test`.

Fixes #23139
Fixes #22743
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.

regression: when importing a module with top-level await multiple times, all but the first import throw ReferenceError

3 participants