Skip to content

fix(identity): never accept rounded Windows file IDs as a match - #949

Closed
steipete wants to merge 4 commits into
mainfrom
fix/identity-number-precision-work
Closed

steipete wants to merge 4 commits into
mainfrom
fix/identity-number-precision-work

Conversation

@steipete

@steipete steipete commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Fix a Windows correctness/hardening bug where distinct NTFS file IDs round to the same JavaScript Number and an expected-source identity fence accepts the wrong file. The deterministic regression uses 2^54 and 2^54 + 1; on main the injected publication call incorrectly resolves with method: "hardlink".

Unsafe Number components now cannot match. Publication snapshots and validates caller expectations, rejects unsafe Numbers with FsSafeError("path-mismatch") and bigint-stat guidance, and compares accepted expectations with exact bigint descriptor stats. Safe integer Number inputs remain supported. The existing Windows zero-component fallback is preserved; cleanup keeps its stricter unknown-value policy.

Internal staged writes, trash fences and legacy native Windows admission retain exact identities. Numeric directory metadata keeps an exact private snapshot when its IDs cannot be represented safely. Public metadata shapes stay unchanged. Copy and staged-file docs explain bigint caller identities and unsafe-Number rejection.

Validation

Final head aca02707: all 56 checks green (51 passed, 5 skipped), including CI and coverage. Labeled campaign-ready for the batch lander.

  • Deterministic tests on unmodified main: 9 failures, including incorrect hardlink publication.
  • Fixed native-enabled local focused suite: 126 passed, 3 platform skips.
  • P0–P2 isolated Codex autoreview: clean. TypeScript, boundary lint, file-size lint and git diff --check pass.
  • AWS Windows Server 2022, Node 24.19.0, native addon built: 240 focused tests passed, 79 platform/route skips. Baseline on the same OS failed the 9 deterministic regression cases as expected.
  • Real NTFS loop: 4,096 consecutive file pairs, 4,038 unsafe Number IDs, zero false identity matches, 32 successful exact-identity publications and successful fallback staged overwrite. The real sample had no rounded-ID collisions; deterministic injection covers that case.
  • AWS Linux full pnpm check after rebasing: 17,926 tests passed, 766 platform skips, plus build, docs, boundary/file-size lint, archive allocator and package/declaration checks. The fresh image needed the repository-pinned .NET SDK before the package check could pass.
  • Initial Windows CI exposed a copied-guard fixture that expected rounded numeric metadata to retain authority. The fixture now expects rejection and deterministic coverage asserts that original guards retain their exact private identity. A simulated Linux procfs fixture also now refuses unsafe numeric descriptor identities on Windows. Product code is unchanged from the full Linux/Windows proofs. The branch has been rebased onto current main and its filesystem-call budget passes.

Identity-fence audit

Site Before After Why safe / availability
file-identity.ts: sameFileIdentity Equal unsafe Numbers counted as the same identity; mixed conversion could throw Snapshot components once; reject unsafe Numbers before comparison Rounding cannot authorize sameness; preserves safe mixed values and Windows zero fallback
publish-file.ts: expectedSourceIdentity Numeric expectation selected numeric fstat Validate snapshot, compare with existing bigint fstat; remove numeric fence stat Typed pre-publication refusal; exact valid Windows IDs still work
publish-file.ts: openNativeParent Bigint pathname and descriptor Unchanged exact observations Uses existing zero fallback
publish-file.ts: assertPinnedSourceCurrent Bigint source/path revalidation Unchanged Exact source fences before/after publication
publish-file.ts: assertPublishedTargetCurrent Bigint target against exact receipt Unchanged Exact published name fencing
publish-file.ts: copyPinnedSource Bigint created/path/open target checks Unchanged Exact native and JS copy ownership
publish-file.ts: cleanup Bigint current name; strict cleanup comparator Unchanged Unsafe or unknown values cannot authorize deletion
publish-file.ts: finishPublication Numeric result Stats Unchanged metadata only Result is not reused internally as authority
directory-guard.ts: capture/assert Default guards retained numeric IDs and compared fresh numeric lstat Unsafe numeric captures privately retain a bigint observation; later fence reads bigint Public/internal metadata shape and realpath ordering retained; default-guard Windows zero fallback retained; existing explicit-bigint strict retries unchanged
guarded-mutation.ts: rename/rm Default numeric directory guards Shared guard exact provenance for large IDs Covers async/sync rename and removal without rejecting legitimate large IDs
sibling-temp.ts / default nearest-existing move guard Numeric directory guard Shared guard exact provenance Same capture/assert lifecycle; no new strict unknown-ID requirement
pinned-write-staged.ts: post-write temp fence Numeric descriptor and pathname stats Both bigint Adjacent rounded IDs cannot match
pinned-write-staged.ts: post-rename target fence Numeric target against numeric temp Both bigint Content-verification fallback remains explicit and bounded
pinned-write-staged.ts: returned identity Numeric, including content-verified destination Exact identity Internal helper avoids passing rounded facts downstream
pinned-write.ts: exclusive fallback result Numeric final fstat result Bigint final result Internal identity remains exact; metadata modes still use explicit conversions
trash.ts: admission/revalidation Numeric lstat pair Bigint lstat pair Windows IDs remain usable; shared unknown fallback unchanged
native-parent-admission.ts: legacy Windows root Numeric native fstatIdentity compared to optional numeric expectation Bigint fd observation; safe mixed equality Rejects unsafe caller expectation; preserves strict native component equality
native-parent-admission.ts: legacy parent Numeric pathname/native identity comparison Bigint pathname and descriptor comparison Avoids rounded matches; existing exact-root inspection/retry remains unchanged
native-pinned-write-windows.ts: returned identity Numeric native result Existing exact verified target stat Removes rounded internal return without new IO
opened-realpath.ts: fd path, IO path, parent candidates Chooses bigint for every production caller's exact descriptor identity Unchanged root-impl, root-write-verification, and handle resolver already supply bigint; numeric internal overload now fails closed if given unsafe inputs
copy-path-admission.ts: parent comparison/cache Explicit bigint directory guards Unchanged No rounded values enter parent comparisons or BigInt conversions
sidecar-lock-reclaim.ts: async/sync snapshots Bigint pre/open/post stats Unchanged Shared comparator tightened without changing valid observations
root-write-verification.ts: published fd/path Bigint expected/fresh observations Unchanged Existing Windows fallback still applies
root-impl.ts: replacement admission/prepublication Bigint publication/admission identities Unchanged Numeric public metadata is not the identity receipt
copy-root-file-sync.ts Bigint expectation type and strict fd admission; exact source/destination receipts Unchanged Runtime rejects even safe numeric expectations; no conversion of rounded IDs
directory-receipt.ts / directory-durability.ts Private exact provenance or safe caller-number validation; bigint live stats Unchanged Original numeric receipt cannot retarget authority; copied unsafe receipts reject
staged-directory.ts / staged file & symlink lifecycle Bigint receipts; safe-number check in exactIdentityMatches Unchanged Native and JS staged ownership already exact
strict-file-identity.ts / stat-observation.ts Exact-only inspection with bounded Windows retry; safe-number fast path falls back to bigint Unchanged Known components retained; unsafe numbers never converted into authority
pinned-open.ts, local-file-descriptor.ts, secure-file.ts, regular-file.ts, atomic-io.ts Numeric metadata alongside separate bigint identity observations Unchanged Numeric stats feed type/size/mode/public results; fences use bigint
root-* removal/list/stat/context, file-store directory/write/cleanup, copy-source/transfer, archive staging/merge, retained-directory and private producer paths Bigint or safe-number-to-exact observation receipts at identity fences Unchanged Audited direct dev/ino comparisons and numeric stat sources; metadata-only type/size probes remain numeric
temp cleanup/target/workspace ownership and sidecar retained ownership Bigint snapshots or validated safe numbers; strict cleanup comparator Unchanged Cleanup never treats rounded or unknown identity as owned
watch snapshots/hints/rescan Exact bigint directory and leaf observations Unchanged No numeric identity enters direct snapshot comparisons

Changelog

Windows identity checks no longer accept rounded file IDs as a match; pass bigint stats for caller-supplied identities.

@steipete
steipete requested a review from a team as a code owner October 11, 2026 10:28
@clawsweeper

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

@clawsweeper clawsweeper Bot added P2 Normal priority bug or improvement with limited blast radius. merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 11, 2026
@clawsweeper

clawsweeper Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

This PR rejects rounded numeric filesystem identities and preserves exact bigint identities through publication, directory guards, writes, and trash checks.

Example: File IDs 18014398509481984 and 18014398509481985 become the same JavaScript Number.

  • Before: A rounded expected-source identity can match a different file and allow hardlink publication.
  • After: Publication rejects the unsafe Number with path-mismatch and directs callers to bigint stats.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused repair has no discrete finding, but the changed filesystem authority boundaries lack inspectable final-effect evidence.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦐 gold shrimp (3/6) Security review found an item that needs attention.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A caller's expected source can match a different file when Windows file IDs round to the same Number.
Reason: The maintainer-authored direction repairs a concrete identity contract failure, documents unsafe-input refusal, and adds no API or option.

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep this PR open: current main and v0.26.0 retain the identity precision defect, and no introduced correctness defect was found.

Priority: P2
Reviewed head: aca02707ab2c7eaac7d71665c58864c58245b929

Before merge

  • Add real behavior proof - Authority-chain proof required: the full body reports Windows Server 2022, Node 24.19.0 NTFS sampling, exact publications, and fallback overwrite, but provides no captured changed-boundary rejection output. Supply redacted public-API logs or terminal screenshots showing valid exact-input publication, unsafe or stale-source refusal with no target created, and replacement-directory refusal before rename or removal; redact IPs, keys, and non-public endpoints. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve security review attention item - No concrete introduced bypass or supply-chain regression was found; the changed authority boundaries remain subject to final-effect proof.

Findings

None.

Tests

  • Missing end-to-end proof: Captured public-API output is needed for exact-input success, rounded or stale-source rejection before target creation, and replacement-directory rejection before mutation.
Agent review details

How this fits together

The identity layer compares caller expectations, retained descriptors, and current path observations before filesystem operations, returning metadata or typed errors.

flowchart TD
  A[Caller paths and identities] --> B[Identity admission]
  B --> C[Exact filesystem observations]
  C --> D[Directory and descriptor fences]
  D --> E[Publication and mutation]
  E --> F[Verification and guarded cleanup]
  F --> G[Metadata or errors]
Loading

Technical review

Best possible solution:

Retain exact bigint authority internally, reject rounded caller expectations, and preserve numeric public metadata and documented compatibility fallbacks.

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

Main's numeric expectation branch and comparator establish rounded-ID acceptance, and the added publication regression checks refusal without target creation; this review ran no target code.

Is this the best way to solve the issue?

The shared comparator and exact internal observations address the root cause while preserving safe Number inputs, numeric public results, strict cleanup ownership, and explicit FUSE compatibility.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

Needs attention: No concrete introduced bypass or supply-chain regression was found; the changed authority boundaries remain subject to final-effect proof.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit ee747c5 adds src/file-identity.ts:16 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: ee747c56b0cb; files: src/file-identity.ts)
  • Vincent Koc: Raw commit dc0ea4e adds src/file-identity.ts:10 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: dc0ea4e269b3; files: src/file-identity.ts)
  • Jeremy Lautman: Raw commit 09614f4 adds src/file-identity.ts:16 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 09614f41d3a2; files: src/file-identity.ts)

Review metrics

Metric Value Why it matters
Introduced scope Production +58/-41; tests +99/-16; documentation and changelog +20/-1. The growth supports one precision repair through exact observations, focused regressions, and caller guidance.

Root-cause cluster

Relationship: canonical
Canonical: #949
Summary: The original repair is carried by an open campaign landing PR.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Large filesystem IDs expose an owned identity defect, without evidence of an urgent deployed incident.
  • merge-risk: 🚨 security-boundary: Caller and retained directory identities authorize publication, rename, and removal, requiring final-effect authority evidence.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Add final-effect proof for valid exact identities and substituted sources, and show that directory replacement invalidates retained authority before mutation.

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 need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (4 earlier review cycles)
  • reviewed 2026-10-11T10:31:49.877Z sha 53c41bd :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-11T11:00:01.800Z sha 090e69a :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-11T11:25:30.755Z sha 2f66b1f :: needs real behavior proof before merge. :: [P2] Update the root-descriptor observer in the Windows alias fixture
  • reviewed 2026-10-11T11:54:17.828Z sha aca0270 :: needs real behavior proof before merge. :: none

Reviewed October 11, 2026, 8:19 AM ET / 12:19 UTC (Revision 5).

@steipete steipete added the campaign-ready Campaign PR: reviewed, CI green, ready for the serial lander label Oct 11, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Landed on main as e26eff5 through campaign batch #951 (rebase merge keeps this PR as its own commit).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

campaign-ready Campaign PR: reviewed, CI green, ready for the serial lander merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. P2 Normal priority bug or improvement with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant