Skip to content

fix(injected-deps-syncer): identify a file by its device as well as its inode - #13847

Merged
zkochan merged 2 commits into
mainfrom
fix/injected-syncer-volume-identity
Aug 12, 2026
Merged

zkochan merged 2 commits into
mainfrom
fix/injected-syncer-volume-identity

Conversation

@zkochan

@zkochan zkochan commented Aug 12, 2026 •

Copy link
Copy Markdown
Member

Summary

extendFilesMap identified a file by its inode number alone. An inode number is only unique within one filesystem, so an unrelated file on another device could collide with the one being synced — the diff reads the two as the same file, skips the replacement, and leaves that path stale in the injected copy.

A file's identity is now <device>:<inode>. dev comes from the same stat that already supplied ino, so this costs no extra syscall, and the identity stays a primitive — the property the inode map is built around, per the note above File:

symbols and strings are used instead of discriminated union because it's faster and simpler to compare primitives than to deep compare objects

so the comparison is still a === rather than a structural one. The cost is one short string per file instead of a number; a template literal was chosen over packing both halves into a single number because dev and ino are each up to 64-bit and would not survive the 53-bit safe-integer range.

Scope of the behavior change is narrow, and worth being explicit about. An injected copy is materialized with fs.link, which cannot cross a filesystem, so in any configuration where the feature works at all the device is equal on both sides and <device>:<inode> and bare <inode> are the same comparison. This only bites in the already-broken cross-device case, where a coincidental inode collision previously caused a silent skip and a stale file; now the file is scheduled and fs.link surfaces a clear EXDEV. That is a better failure rather than a fix to a working setup.

Rust: already correct. pacquet took FileId { device, inode } in #13834 — this is the TypeScript half, called out as a follow-up in that PR's review, and closes the divergence.

Tests: a new case in extendFilesMap.test.ts drives two files that share an inode number on different devices through the injected-stats seam and asserts their identities differ; it fails when the device is dropped from the identity. The existing fixtures across extendFilesMap, diffDir, applyPatch, and DirPatcher now carry a device. The pnpm/test/syncInjectedDepsAfterScripts end-to-end suite still passes against a rebuilt bundle.

No cross-device fixture: a test would have to mount a second filesystem, which the suite cannot do portably, and the only assertion available to it (fs.link rejects with EXDEV) is the platform's behavior rather than this package's.

Squash Commit Body

An inode number is only unique within one filesystem, so comparing bare
inode numbers lets an unrelated file on another device collide with the
one being synced. The diff then reads the two as the same file, skips
the replacement, and leaves that path stale in the injected copy.

Carry the device alongside it, as a `<device>:<inode>` string. The
identity stays a primitive, so the comparison the inode map is built
around is still a `===` rather than a structural one; `dev` comes from
the same stat that already supplied `ino`, so this costs no extra
syscall.

Nothing changes where injection works at all: a hardlink cannot cross a
filesystem, so the device is equal on both sides and the comparison is
the one it was before. It only affects the broken cross-device case,
which now reaches a clear EXDEV from `fs.link` instead of silently
skipping the file.

Matches pacquet, which took the same identity in pnpm/pnpm#13834.

Checklist

  • The change is implemented in both the TypeScript CLI and the Rust
    pnpm/ port, or the description notes what still needs porting.
  • Added a changeset (pnpm changeset) if this PR changes any published
    package. Keep it short and written for pnpm users — it becomes a release note.
  • Added or updated tests.

Written by an agent (Claude Code, claude-opus-5[1m]).


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Summary by CodeRabbit

  • Bug Fixes

    • Improved synchronization of injected dependencies across multiple filesystems.
    • Prevented files on different devices from being incorrectly treated as the same file when they share an inode number.
    • Preserved accurate handling of hard links and special file types during synchronization.
  • Tests

    • Added regression coverage for files with matching inode numbers on different devices.
  • Documentation

    • Included patch release notes for the affected packages.

…ts inode

An inode number is only unique within one filesystem, so comparing bare
inode numbers lets an unrelated file on another device collide with the
one being synced. The diff then reads the two as the same file, skips
the replacement, and leaves that path stale in the injected copy.

Carry the device alongside it, as a `<device>:<inode>` string. The
identity stays a primitive, so the comparison the inode map is built
around is still a `===` rather than a structural one; `dev` comes from
the same stat that already supplied `ino`, so this costs no extra
syscall.

Nothing changes where injection works at all: a hardlink cannot cross a
filesystem, so the device is equal on both sides and the comparison is
the one it was before. It only affects the broken cross-device case,
which now reaches a clear EXDEV from `fs.link` instead of silently
skipping the file.

Matches pacquet, which took the same identity in #13834.
Copilot AI lite review requested due to automatic review settings August 12, 2026 04:59

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: d156a048-3417-400d-833b-4b78744f8e27

📥 Commits

Reviewing files that changed from the base of the PR and between 7bee7da and 1a26052.

📒 Files selected for processing (6)
  • .changeset/injected-syncer-volume-identity.md
  • pnpm11/workspace/injected-deps-syncer/src/DirPatcher.ts
  • pnpm11/workspace/injected-deps-syncer/test/DirPatcher.test.ts
  • pnpm11/workspace/injected-deps-syncer/test/applyPatch.test.ts
  • pnpm11/workspace/injected-deps-syncer/test/diffDir.test.ts
  • pnpm11/workspace/injected-deps-syncer/test/extendFilesMap.test.ts

📝 Walkthrough

Walkthrough

The injected-dependency syncer now identifies files with device and inode numbers. Tests and patch release metadata use the new dev:ino string format.

Changes

Injected syncer identity

Layer / File(s) Summary
Device-and-inode identity implementation
pnpm11/workspace/injected-deps-syncer/src/DirPatcher.ts, .changeset/injected-syncer-volume-identity.md
DirPatcher stores file identities as dev:ino strings and updates file-value handling and statistics. The changeset records patch releases.
Identity and patching validation
pnpm11/workspace/injected-deps-syncer/test/*
Tests update directory maps, patch assertions, mocked statistics, FIFO cases, and cross-device inode coverage for combined identities.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • pnpm/pnpm#13663: Both changes modify DirPatcher and injected-dependency syncer tests, but address different file-identity issues.
  • pnpm/pnpm#13834: This change refines the injected-dependency syncer identity logic from inode-only values to device-and-inode identifiers.

Suggested labels: product: pnpm@11

Suggested reviewers: greptile-apps

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/injected-syncer-volume-identity

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


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.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Fix injected-deps-syncer file identity to use : (avoid cross-device inode collisions)

🐞 Bug fix 🧪 Tests ⚙️ Configuration changes 🕐 20-40 Minutes

Grey Divider

AI Description

• Identify files by : to avoid cross-filesystem inode collisions.
• Propagate the new file identity type through patching/diffing code paths.
• Update fixtures and add a regression test covering same-inode/different-device cases.
Diagram

graph TD
  src["Source tree"] --> stat["stat(): dev+ino"] --> id["FileId '<dev>:<ino>'"] --> map[("InodeMap")] --> diff["diffDir()"] --> patch["DirPatcher.applyPatch()"] --> link{{"fs.link"}}
  tgt["Target tree"] --> patch
  subgraph Legend
    direction LR
    _io["Process/Module"] ~~~ _map[("Map")] ~~~ _ext{{"Node fs"}}
  end
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Use structured identity object (e.g., {dev, ino})
  • ➕ More explicit typing and avoids string formatting/parsing concerns
  • ➕ Can be extended later without changing representation
  • ➖ Requires deep/structural comparisons or custom hashing to keep lookups fast
  • ➖ Higher allocation/GC overhead versus a primitive identity
2. Pack dev+ino into a single numeric representation (BigInt)
  • ➕ Keeps identity primitive and avoids string allocation
  • ➕ No delimiter formatting concerns
  • ➖ BigInt may have higher runtime cost and ecosystem friction than string/number
  • ➖ Not always desirable if the codebase expects JSON-serializable primitives; also requires careful handling across platforms

Recommendation: Keep the PR’s approach: represent file identity as the primitive string :. It preserves the existing performance property (primitive === comparisons) while correctly disambiguating cross-device inode collisions, and it avoids unsafe 53-bit-number packing pitfalls. The alternatives either add comparison/alloc overhead (object identity) or introduce BigInt complexity with unclear benefit for this narrow bugfix.

Files changed (6) +99 / -42

Bug fix (1) +13 / -5
DirPatcher.tsSwitch file identity from inode number to '<dev>:<ino>' string +13/-5

Switch file identity from inode number to '<dev>:<ino>' string

• Changes the 'File' identity type from 'number' (inode only) to 'string' ('<device>:<inode>'), and updates 'extendFilesMap' to compute and store this identity. Updates the injected-stats seam ('ExtendFilesMapStats') to include 'dev' and adjusts runtime checks accordingly.

pnpm11/workspace/injected-deps-syncer/src/DirPatcher.ts

Tests (4) +80 / -37
DirPatcher.test.tsUpdate DirPatcher integration test to compare file IDs (dev+ino) +8/-5

Update DirPatcher integration test to compare file IDs (dev+ino)

• Replaces inode-only assertions with a helper that combines 'stats.dev' and 'stats.ino'. Keeps the test intent (hardlinks converge identities after syncing) while matching the new identity representation.

pnpm11/workspace/injected-deps-syncer/test/DirPatcher.test.ts

applyPatch.test.tsUpdate applyPatch fixtures to use file IDs (dev+ino) +12/-9

Update applyPatch fixtures to use file IDs (dev+ino)

• Updates patch fixtures and expectations to carry '<dev>:<ino>' values instead of bare inode numbers. Ensures modified/added/removed file entries are compared using the new identity type.

pnpm11/workspace/injected-deps-syncer/test/applyPatch.test.ts

diffDir.test.tsUpdate diffDir fixtures to use '<dev>:<ino>' identities +13/-13

Update diffDir fixtures to use '<dev>:<ino>' identities

• Converts all hardcoded inode fixture values to include a device prefix. This keeps diff expectations stable while exercising the string-based identity comparisons.

pnpm11/workspace/injected-deps-syncer/test/diffDir.test.ts

extendFilesMap.test.tsAdd regression test for same-inode/different-device disambiguation +47/-10

Add regression test for same-inode/different-device disambiguation

• Extends mocked stat fixtures to include 'dev', updates existing expectations to store '<dev>:<ino>', and adds a new test ensuring two files with the same inode but different devices produce different identities. Maintains existing FIFO-skipping coverage with the updated identity format.

pnpm11/workspace/injected-deps-syncer/test/extendFilesMap.test.ts

Other (1) +6 / -0
injected-syncer-volume-identity.mdAdd changeset documenting injected syncer file identity fix +6/-0

Add changeset documenting injected syncer file identity fix

• Introduces a patch changeset for '@pnpm/workspace.injected-deps-syncer' and 'pnpm'. Documents the behavior change: file identity now includes device to avoid inode collisions across filesystems.

.changeset/injected-syncer-volume-identity.md

@greptile-apps

greptile-apps Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

The PR appears safe to merge, with the file-identity representation updated consistently across production code and tests.

The changed runtime path always constructs device-qualified string identities, all internal consumers accept that representation, and focused coverage verifies the cross-device inode-collision case without exposing an incompatible public or persisted boundary.

Reviews (1): Last reviewed commit: "test(injected-deps-syncer): carry the de..." | Re-trigger Greptile

@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Aug 12, 2026
@qodo-code-review

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Lossy dev/ino identity 🐞 Bug ☼ Reliability
Description
fileId() stringifies number-based Stats.dev/ino, so on platforms/filesystems where these are 64-bit
or unreliable (e.g. 0), distinct files can collapse to the same identity and diffDir() will treat
them as unchanged. That can skip relinking in applyPatch() and leave stale injected files even
though source contents changed.
Code

pnpm11/workspace/injected-deps-syncer/src/DirPatcher.ts[R200-201]

+const fileId = (stats: Pick<ExtendFilesMapStats, 'dev' | 'ino'>): File => `${stats.dev}:${stats.ino}`
+
Relevance

●●● Strong

Repo precedent hardens inode/dev comparisons: use { bigint: true } and avoid matching on
unreliable zero identities.

PR-#12284
PR-#13810

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The PR change introduces a <dev>:<ino> identity, but both dev and ino still come from
number-based stat() results. diffDir() decides a file is modified only when the stored identity
values differ, so any collision (precision loss or unreliable zeros) will cause updates to be
skipped. The repo already has established patterns using { bigint: true } and non-zero checks
specifically to avoid these identity reliability issues.

pnpm11/workspace/injected-deps-syncer/src/DirPatcher.ts[64-79]
pnpm11/workspace/injected-deps-syncer/src/DirPatcher.ts[186-201]
pnpm11/fetching/directory-fetcher/src/index.ts[134-140]
pnpm11/bins/linker/src/index.ts[378-391]
pnpm11/fs/indexed-pkg-importer/src/importIndexedDir.ts[349-358]
PR-#12284
PR-#13810

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`fileId()` builds the per-file identity from `stats.dev` and `stats.ino` as JavaScript numbers. On platforms where these identifiers are 64-bit (or reported as 0/unreliable), the numeric representation can be precision-lost or collide, causing `diffDir()`'s `oldIndex[path] !== newIndex[path]` comparison to incorrectly treat different files as “same” and skip updates.

### Issue Context
- `extendFilesMap()` gets stats either from `filesStats` (produced upstream by `fetchFromDir`) or from `fs.promises.stat(realPath)`.
- Both sources currently use the default number-based stat APIs.
- Elsewhere in this repo, identity comparisons use `{ bigint: true }` and guard against zero identities before trusting inode/device equality.

### Fix Focus Areas
- pnpm11/workspace/injected-deps-syncer/src/DirPatcher.ts[64-79]
- pnpm11/workspace/injected-deps-syncer/src/DirPatcher.ts[186-201]
- pnpm11/fetching/directory-fetcher/src/index.ts[134-140]

### Implementation sketch
1. Prefer BigInt stats for identity where available:
  - For the internal stat path, call `fs.promises.stat(realPath, { bigint: true })`.
  - Update `ExtendFilesMapStats` (and `filesStats` typing) to accept `fs.BigIntStats` (or a minimal structural type carrying `dev`, `ino`, `isFile`, `isDirectory`).
2. Ensure the provided `filesStats` path also supplies BigInt identities, otherwise you still get lossy numbers:
  - Either update `fetchFromDir`/directory-fetcher to populate `filesStats` using `{ bigint: true }`, or
  - In `extendFilesMap`, detect “unreliable identity” from the provided stats (e.g. `ino/dev` are 0 or not safe integers) and re-stat just those files with `{ bigint: true }`.
3. Only trust inode/device identity when it’s non-zero (mirroring repo practice); if identity is unreliable, fall back to a conservative comparison key (e.g. size+mtime) or treat as modified to avoid stale injected copies.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Context
✅ Compliance rules (platform): 18 rules

Grey Divider

Tip of the day
💡 Did you know, you can enable the Remediation agent and Qodo fixes findings in a dedicated fix PR

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

@zkochan
zkochan merged commit 7891f89 into main Aug 12, 2026
31 checks passed
@zkochan
zkochan deleted the fix/injected-syncer-volume-identity branch August 12, 2026 06:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product: pnpm@11 reviewed: coderabbit CodeRabbit submitted an approving review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants