Skip to content

fix: treat zero win32 inodes as unknown file identity - #129

Merged
steipete merged 2 commits into
mainfrom
fix/win32-zero-ino-unknown-identity
Aug 12, 2026
Merged

steipete merged 2 commits into
mainfrom
fix/win32-zero-ino-unknown-identity

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where Windows consumers performing legitimate reads could nondeterministically receive FsSafeError("path-mismatch", "File changed during read") when antivirus or indexer contention prevented libuv from opening the path for stat.

This was observed in openclaw/openclaw Windows CI after the 0.5.4 bump at commit 5295f2578e1be1: checks-windows-node-test intermittently failed in src/media/local-media-path.windows.test.ts with ManagedImageAttachmentError after verifyStableReadTarget rejected an unchanged file.

Why This Change Was Made

On Windows, libuv falls back to FindFirstFile data when GetFileInformationByHandle cannot open the file. That fallback reports both dev=0 and ino=0. sameFileIdentity already treated either-side zero device identity as unknown on Win32, but compared inode identity strictly, so a path stat with ino=0 mismatched an fd stat containing the real nonzero inode.

The comparison now uses one symmetric per-field rule: a field differs only when both values are known and unequal. Win32 zero device serials and inodes are unknown; non-Windows comparisons remain strict.

Platform Left (dev, ino) Right (dev, ino) Same identity
win32 (1, 0) (1, 5) yes
win32 (1, 5) (1, 0n) yes
win32 (0, 0) (2, 5) yes
win32 (1, 0) (2, 5) no
win32 (1, 4) (1, 5) no
linux (1, 0) (1, 5) no

User Impact

Windows reads no longer fail spuriously with path-mismatch when a transient libuv path-stat fallback cannot provide file identity. Known unequal device or inode values still fail closed, and every non-Windows comparison retains the existing strict behavior.

Evidence

  • pnpm test test/coverage-more.test.ts test/regular-file-failure.test.ts test/rename-identity-policy.test.ts

    • 3 test files passed
    • 39 tests passed
  • pnpm check

    • file-size and filesystem-boundary lint passed
    • TypeScript build passed
    • documentation examples matched the built package
    • 101 test files passed, 2 skipped
    • 1,039 tests passed, 61 skipped
    • package validation passed
  • git diff --check passed

  • Structured autoreview reported no accepted or actionable findings.

  • Tests added or updated when behavior changed

  • Security and compatibility impact considered

  • CHANGELOG.md updated when release-relevant

  • No credentials, private paths, private hosts, or sensitive contents included

@clawsweeper

clawsweeper Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete
steipete marked this pull request as ready for review August 11, 2026 16:24
@steipete
steipete requested a review from a team as a code owner August 11, 2026 16:24
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. P1 Urgent regression or broken agent/channel workflow affecting real users now. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 11, 2026
@clawsweeper

clawsweeper Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 12, 2026, 12:01 AM ET / 04:01 UTC.

ClawSweeper review

What this changes

The PR treats zero Windows device and inode values as unknown during file-identity comparison to avoid intermittent read failures after path-stat fallback.

Regression provenance

Possible regression — probable (reviewed change; reproduction). No predecessor PR is attributed.

Merge readiness

⛔ Blocked until real behavior proof from a real setup is added - 7 items remain

Keep this PR open: its revised test still makes an unknown Win32 inode satisfy a security identity guard, weakening the package’s documented fail-closed TOCTOU protection.

Priority: P1
Reviewed head: 1871e065a8145f60642f37fc9e51bf1071f1eb8c
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The patch has a concrete security-boundary defect and lacks real Windows behavior proof.
Proof confidence 🧂 unranked krab (1/6) Needs real behavior proof before merge: The PR reports unit tests and CI checks but provides no redacted after-fix Windows run showing both fallback recovery and preserved swap rejection. 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.
Patch quality 🦪 silver shellfish (2/6) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The PR reports unit tests and CI checks but provides no redacted after-fix Windows run showing both fallback recovery and preserved swap rejection. 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.
Evidence reviewed 4 items Changed guard accepts unknown inode: The proposed comparator returns true when either differing Win32 field is zero; its own test explicitly accepts (dev: 1, ino: 0) against (dev: 1, ino: 5).
Identity checks fence sensitive operations: Current read and archive paths reject path-mismatch whenever pathname and descriptor identities differ; accepting an unknown field removes that proof of equality.
Documented security contract: The security model says the opened descriptor and resolved path must refer to the same inode so swaps fail at the identity check.
Findings 1 actionable finding [P1] Reject unknown Win32 identity fields
Security Needs attention Unknown identity authorizes guarded operations: A zero Win32 inode or device causes unequal identities to compare as equal, so the guard can no longer establish that the pathname and opened descriptor are the same file.

How this fits together

Filesystem operations compare pre-open and post-open pathname metadata with the opened descriptor to detect swaps before reading, extracting, or modifying a file. The shared identity comparator feeds those guards across regular reads, secure files, and archive staging.

flowchart LR
  A[Caller path] --> B[Pre-open and post-open path stats]
  A --> C[Opened file descriptor stat]
  B --> D[File identity comparison]
  C --> D
  D -->|same identity| E[Read extract or modify]
  D -->|mismatch| F[path-mismatch rejection]
Loading

Decision needed

Question Recommendation
Should Windows identity gaps remain fail-closed while the package pursues a bounded retry, rather than allowing unknown identity fields to authorize the operation? Preserve fail-closed identity: Replace unknown-equals-match behavior with a bounded retry that only continues when a known pathname identity matches the opened descriptor.

Why: The shared helper is a security boundary used by many operations, so choosing availability over unproven file identity requires explicit owner confirmation.

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The PR reports unit tests and CI checks but provides no redacted after-fix Windows run showing both fallback recovery and preserved swap rejection. 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.
  • Reject unknown Win32 identity fields (P1) - This returns true whenever either unequal Win32 field is zero, including the explicitly tested (1, 0) versus (1, 5) case. sameFileIdentity is the proof used by read, secret, and archive swap guards, so a fallback zero after a pathname replacement can authorize an operation without proving it still targets the opened file. Keep unknown identity fail-closed and retry/re-stat before proceeding. This is the prior P1 blocker and remains in the current head.
  • Resolve security concern: Unknown identity authorizes guarded operations - A zero Win32 inode or device causes unequal identities to compare as equal, so the guard can no longer establish that the pathname and opened descriptor are the same file.
  • Resolve merge risk (P1) - Merging would let an ambiguous Win32 pathname identity pass checks that protect reads, secret handling, and archive staging from a path swap.
  • Improve patch quality - Retain fail-closed identity semantics and add a bounded retry or re-stat path for transient Win32 fallback data.
  • Improve patch quality - Add redacted real Windows evidence showing successful recovery and rejection of a known pathname swap.

Findings

  • [P1] Reject unknown Win32 identity fields — src/file-identity.ts:42-43
  • [high] Unknown identity authorizes guarded operations — src/file-identity.ts:42
Agent review details

Security

Needs attention: The patch weakens a shared post-open identity boundary by treating unavailable identity data as successful verification.

Review metrics

Metric Value Why it matters
Patch surface 4 files: +45, -18 One shared identity helper changes the outcome of many filesystem safety guards.
Production vs test delta production +19/-10, tests +22/-8 The new tests intentionally encode the security-sensitive acceptance rule under review.

Merge-risk options

Maintainer options:

  1. Restore fail-closed verification (recommended)
    Use a bounded Win32 retry or equivalent evidence-gathering path, and reject the operation when identity remains unknown.
  2. Pause ambiguous-identity support
    Leave the current strict comparison in place if the fallback cannot prove the pathname and descriptor refer to the same file.

Technical review

Best possible solution:

Keep identity equality fail-closed and add a narrowly bounded Windows re-stat or retry path that proceeds only after known identities match; otherwise retain path-mismatch.

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

Yes at source level: the proposed table directly reproduces acceptance of an unknown inode against a known unequal inode. No real Windows fallback run is provided for the claimed intermittent-read symptom.

Is this the best way to solve the issue?

No. Treating unknown identity as equality conflicts with the documented and repository-required fail-closed identity contract; a bounded retry before rejection is the safer path.

Full review comments:

  • [P1] Reject unknown Win32 identity fields — src/file-identity.ts:42-43
    This returns true whenever either unequal Win32 field is zero, including the explicitly tested (1, 0) versus (1, 5) case. sameFileIdentity is the proof used by read, secret, and archive swap guards, so a fallback zero after a pathname replacement can authorize an operation without proving it still targets the opened file. Keep unknown identity fail-closed and retry/re-stat before proceeding. This is the prior P1 blocker and remains in the current head.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 7a0d57ef5948.

Labels

Label changes:

  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🧂 unranked krab, so this older rating label is no longer current.

Label justifications:

  • P1: The proposed shared guard change can weaken active filesystem-safety checks on Windows.
  • merge-risk: 🚨 security-boundary: Unknown file identity can authorize reads or staging operations without proving the pathname still names the opened file.
  • merge-risk: 🚨 compatibility: The public sameFileIdentity behavior changes from strict inode comparison to accepting certain unequal identities.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR reports unit tests and CI checks but provides no redacted after-fix Windows run showing both fallback recovery and preserved swap rejection. 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.

Evidence

Security concerns:

  • [high] Unknown identity authorizes guarded operations — src/file-identity.ts:42
    A zero Win32 inode or device causes unequal identities to compare as equal, so the guard can no longer establish that the pathname and opened descriptor are the same file.
    Confidence: 0.98

What I checked:

  • Changed guard accepts unknown inode: The proposed comparator returns true when either differing Win32 field is zero; its own test explicitly accepts (dev: 1, ino: 0) against (dev: 1, ino: 5). (src/file-identity.ts:42, 1871e065a814)
  • Identity checks fence sensitive operations: Current read and archive paths reject path-mismatch whenever pathname and descriptor identities differ; accepting an unknown field removes that proof of equality. (src/regular-file.ts:157, 7a0d57ef5948)
  • Documented security contract: The security model says the opened descriptor and resolved path must refer to the same inode so swaps fail at the identity check. (docs/security-model.md:52, 7a0d57ef5948)
  • Current-main provenance: The current identity-helper lines trace to the v0.5.4 release preparation commit by Peter Steinberger; the PR head is not contained in main or a release tag. (src/file-identity.ts:21, f223c134936b)

Likely related people:

  • Peter Steinberger: Current-main blame attributes the identity helper to the v0.5.4 release-preparation commit, and the PR history shows continued work on this same behavior. (role: recent identity-helper contributor; confidence: high; commits: f223c134936b, 5494a918b99b, 1871e065a814; files: src/file-identity.ts, test/coverage-more.test.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-08-11T16:28:20.441Z sha 5494a91 :: needs real behavior proof before merge. :: [P1] Keep unknown Win32 inodes fail-closed

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 12, 2026
@steipete
steipete merged commit ee747c5 into main Aug 12, 2026
27 checks passed
@steipete
steipete deleted the fix/win32-zero-ino-unknown-identity branch August 12, 2026 04:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. P1 Urgent regression or broken agent/channel workflow affecting real users now. 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