Skip to content

fix: Fix non-deterministic hashOfExternalDependencies with Bun lockfiles - #12279

Merged
anthonyshew merged 1 commit into
mainfrom
shew/investigate-12252
Mar 13, 2026
Merged

fix: Fix non-deterministic hashOfExternalDependencies with Bun lockfiles#12279
anthonyshew merged 1 commit into
mainfrom
shew/investigate-12252

Conversation

@anthonyshew

Copy link
Copy Markdown
Contributor

Summary

Fixes #12252

  • The transitive dependency resolve cache in all_transitive_closures() omitted workspace_path from cache keys, assuming resolution is workspace-independent. This is false for Bun lockfiles where workspace-scoped resolution (workspace_name/package_name entries) can produce different results per workspace.
  • Combined with non-deterministic parallel iteration via HashMap::into_par_iter(), whichever workspace populated the cache first would poison the results for other workspaces — causing hashOfExternalDependencies to flip between values across runs.

How it works

Always include workspace_path in the resolve cache key so each workspace gets correctly isolated cache entries. This is a no-op for pnpm/npm/yarn (where transitive deps are already fully resolved keys), but critical for Bun where all_dependencies() can return raw semver ranges that require workspace-scoped resolution.

How to verify

The new test test_all_transitive_closures_deterministic_with_workspace_scoped_packages constructs a Bun lockfile where two workspaces resolve the same transitive dependency to different versions via workspace-scoped entries, then runs all_transitive_closures 50 times asserting consistent, correct results. This test would fail without the fix due to cache poisoning from the parallel workspace processing.

cargo test -p turborepo-lockfiles test_all_transitive_closures_deterministic

A check-lockfiles fixture from the reproduction repo is also included at lockfile-tests/fixtures/bun-v1-issue-12252/.

The resolve cache in all_transitive_closures() omitted workspace_path
from cache keys for transitive dependencies, assuming resolution is
workspace-independent. This is false for Bun lockfiles where
workspace-scoped resolution produces different results per workspace.
Combined with non-deterministic parallel iteration order, this caused
hashOfExternalDependencies to vary across runs.

Always include workspace_path in resolve cache keys so each workspace
gets correctly isolated cache entries.

Closes #12252
@anthonyshew
anthonyshew requested a review from a team as a code owner March 13, 2026 12:51
@anthonyshew
anthonyshew requested review from tknickman and removed request for a team March 13, 2026 12:51
@vercel

vercel Bot commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
examples-basic-web Ready Ready Preview, Comment, Open in v0 Mar 13, 2026 0:51am
examples-designsystem-docs Ready Ready Preview, Comment, Open in v0 Mar 13, 2026 0:51am
examples-gatsby-web Ready Ready Preview, Comment, Open in v0 Mar 13, 2026 0:51am
examples-kitchensink-blog Ready Ready Preview, Comment, Open in v0 Mar 13, 2026 0:51am
examples-nonmonorepo Ready Ready Preview, Comment, Open in v0 Mar 13, 2026 0:51am
examples-svelte-web Ready Ready Preview, Comment, Open in v0 Mar 13, 2026 0:51am
examples-tailwind-web Ready Ready Preview, Comment, Open in v0 Mar 13, 2026 0:51am
examples-vite-web Ready Ready Preview, Comment, Open in v0 Mar 13, 2026 0:51am
turbo-site Ready Ready Preview, Comment, Open in v0 Mar 13, 2026 0:51am
turborepo-agents Ready Ready Preview, Comment, Open in v0 Mar 13, 2026 0:51am

@anthonyshew
anthonyshew enabled auto-merge (squash) March 13, 2026 12:53
@anthonyshew
anthonyshew merged commit bb1e1da into main Mar 13, 2026
58 checks passed
@anthonyshew
anthonyshew deleted the shew/investigate-12252 branch March 13, 2026 13:02
github-actions Bot added a commit that referenced this pull request Mar 13, 2026
## Release v2.8.17-canary.15

Versioned docs: https://v2-8-17-canary-15.turborepo.dev

### Changes

- release(turborepo): 2.8.17-canary.14 (#12278) (`85719d6`)
- fix: Fix non-deterministic hashOfExternalDependencies with Bun
lockfiles (#12279) (`bb1e1da`)

Co-authored-by: Turbobot <turbobot@vercel.com>
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.

Non-deterministic hashOfExternalDependencies with pnpm lockfile v9

1 participant