Skip to content

fix(write): add renameIdentity option for FUSE mounts with unstable inode numbers - #33

Merged
steipete merged 4 commits into
openclaw:mainfrom
jlautman:fix/fuse-unstable-inode-rename
Jul 1, 2026
Merged

steipete merged 4 commits into
openclaw:mainfrom
jlautman:fix/fuse-unstable-inode-rename

Conversation

@jlautman

@jlautman jlautman commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add explicit renameIdentity: "verify-content-with-lock" compatibility writes for rclone-style FUSE mounts whose destination inode changes across rename.
  • Keep strict (dev, ino) verification as the unchanged default.
  • Verify matching content under a cooperative lock only for the rename boundary; keep subsequent path identity checks strict.

Closes #32.

Security contract

This is an explicit weaker opt-in for trusted/cooperating writers. It does not prove that the destination still names the temp-file object, retain the Python helper's fd-relative parent pinning, or stop a same-UID writer that ignores the advisory lock.

The compatibility lock is a per-target, SHA-256-keyed sidecar stored in the already-canonical root. That avoids creating a lock through a missing or raced target parent. Stale locks fail closed and are never reclaimed from host-local PID evidence. The stricter Python helper is deliberately bypassed only in this mode because it requires rename to preserve inode identity.

Implementation

  • Export RenameIdentityPolicy through the root API.
  • Add SHA-256 verification when the source temp fd and renamed destination report different identities.
  • Preserve strict defaults, already-exists, mkdir: false, stale-lock, and post-write identity behavior.
  • Document the compatibility boundary and add an 0.4.1 - Unreleased changelog entry thanking @jlautman.
  • Add deterministic regressions for strict/compatible identity behavior, content replacement, per-call overrides, required-Python routing, create semantics, missing parents, stale locks, and normal POSIX cleanup.

Validation

  • pnpm check: 38 test files passed; 423 tests passed, 3 skipped.
  • pnpm audit --prod --json: 0 vulnerabilities.
  • Autoreview: no accepted/actionable findings after fixing the no-mkdir contract and lock-parent boundary findings.
  • Live packaged-consumer proof on AWS Crabbox, Ubuntu 26.04, kernel 7.0, Node 24.18.0, pnpm 11.9.0, rclone 1.74.3: run run_b2ca73c0818e, lease cbx_dfc891eea183.
    • rclone rename identity changed from 55:13142417776620928161 to 55:13160412383924634112.
    • Strict mode returned path-mismatch.
    • Compatibility mode wrote and read compatible-content.
    • Root-level compatibility lock was absent after completion.

Exact validated head: 46e6cc26cba0f4f2b6e1ea5217cb35a6d34e1bd9.

@clawsweeper

clawsweeper Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 1, 2026, 12:38 AM ET / 04:38 UTC.

Summary
The PR adds a public renameIdentity: "verify-content-with-lock" write option that uses sidecar locking and SHA-256 content verification for unstable-inode FUSE rename paths, with docs, exports, and tests.

Reproducibility: yes. for the PR defects: source inspection shows the opt-in still reaches the default Python helper path, while every new behavioral test forces Python mode off. I did not run a live rclone mount in this checkout.

Review metrics: 3 noteworthy metrics.

  • Changed surface: 8 files, +448/-25. The PR changes public types, write-path security code, docs, exports, and adds a new test file.
  • Public option added: 1 new rename identity policy. The new root/write option is public API and changes how an opted-in write verifies its destination.
  • Helper coverage gap: 7 tests force Python mode off. The new behavior is covered only in the Node fallback path, not the default helper-enabled POSIX path.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #32
Summary: This PR explicitly closes the open rclone FUSE path-mismatch report, which remains the canonical issue until this PR is reviewed and merged or rejected.

Members:

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

Merge readiness
Overall: 🧂 unranked krab
Proof: 🧂 unranked krab
Patch quality: 🧂 unranked krab
Result: blocked until real behavior proof is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P1] Add redacted terminal output, logs, screenshot, recording, or linked artifact showing strict mode failing and renameIdentity: "verify-content-with-lock" succeeding on the rclone mount.
  • [P1] Fix the helper-enabled path so the opt-in works in normal Python helper mode or is deliberately routed around it with coverage.
  • Resolve the stale-lock security contract and align the docs with the chosen lock timing.

Proof guidance:

  • [P1] Needs real behavior proof before merge: Missing: the PR body claims live rclone validation, but no inspectable terminal output, logs, screenshot, recording, or linked artifact shows strict failure and opt-in success; add redacted proof and update the PR body for re-review.

Risk before merge

  • [P1] Default helper-enabled POSIX installs can still throw path-mismatch after users opt into renameIdentity: "verify-content-with-lock" because the Python helper never receives the new policy.
  • [P1] PID-only stale-lock reclamation can remove an active lock from another host or PID namespace on a shared mount, undermining the advisory exclusion used to justify content verification.
  • [P1] The PR body claims live rclone validation, but no inspectable artifact demonstrates strict failure and after-fix success.
  • [P1] The new compatibility mode replaces object-identity proof with content equality under an advisory lock, so maintainers should explicitly approve that weaker security contract before merge.

Maintainer options:

  1. Repair helper path and stale-lock semantics (recommended)
    Teach the Python helper the new policy or deliberately route this opt-in around it, add helper-enabled coverage, and keep stale-lock removal fail-closed unless the holder is proven unreachable in the shared-lock domain.
  2. Accept the weaker compatibility contract explicitly
    Maintainers may choose to accept content verification under an advisory lock for this opt-in, but that approval should be visible because it changes the write safety model.
  3. Pause behind the canonical issue
    If the security boundary is not settled, keep this PR paused while Post-rename identity check (sameFileIdentity) always fails on rclone FUSE mounts, even with zero concurrency #32 records the product decision and desired compatibility contract.

Next step before merge

  • [P1] Manual review is needed because the PR adds a public security-sensitive compatibility mode and the remaining blockers include code defects, missing contributor proof, and maintainer contract decisions.

Security
Needs attention: The diff adds a weaker opt-in write-verification mode and PID-based stale-lock reclamation, both of which affect fs-safe's write safety boundary.

Review findings

  • [P1] Route the opt-in around the Python helper — src/root-impl.ts:1138-1140
  • [P1] Fail closed for unproven lock owners — src/root-impl.ts:1132-1134
  • [P2] Preserve already-exists in the locked path — src/root-impl.ts:1142-1143
Review details

Best possible solution:

Keep strict dev/ino identity as the default, then land an explicit compatibility mode only after it works consistently across helper-enabled and helper-off paths, preserves fail-closed lock semantics unless maintainers approve otherwise, and has matching docs plus redacted live proof.

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

Yes for the PR defects: source inspection shows the opt-in still reaches the default Python helper path, while every new behavioral test forces Python mode off. I did not run a live rclone mount in this checkout.

Is this the best way to solve the issue?

No: the compatibility direction may be viable, but this patch is not the narrowest safe implementation until it handles the helper path, preserves the existing error contract, resolves stale-lock security semantics, and aligns the docs.

Full review comments:

  • [P1] Route the opt-in around the Python helper — src/root-impl.ts:1138-1140
    With renameIdentity: "verify-content-with-lock", this still calls runPinnedWriteHelper, which uses the Python worker whenever Python mode is not off. The worker never receives the new policy and still rejects the rclone case by comparing post-rename dev/ino, so the advertised fix fails on the default POSIX setup; either teach the helper the policy or bypass it for this opt-in and add helper-enabled coverage.
    Confidence: 0.92
  • [P1] Fail closed for unproven lock owners — src/root-impl.ts:1132-1134
    These callbacks treat any locally-dead PID as removable, but PIDs are host- and namespace-local while the sidecar may live on a shared FUSE mount. An active writer from another host or PID namespace can look dead locally, letting this code delete its lock and enter the supposedly exclusive section; preserve fail-closed behavior unless the payload proves the holder cannot still write.
    Confidence: 0.84
  • [P2] Preserve already-exists in the locked path — src/root-impl.ts:1142-1143
    The new locked branch normalizes runPinnedWriteHelper errors without the strict branch's overwrite === false mapping. In helper-off fallback mode, an existing target can now surface as invalid-path instead of the documented already-exists for create() or write(..., { overwrite: false }); apply the same mapping in the locked path or share the catch logic.
    Confidence: 0.8
  • [P3] Match the docs to the actual lock timing — docs/writing.md:249
    This says the write first runs strict and then retries under the lock, but the implementation acquires the sidecar lock before the write whenever the option is set. That mismatch matters for reviewers and users reasoning about double writes and lock cost, so the docs should describe the actual flow.
    Confidence: 0.9

Overall correctness: patch is incorrect
Overall confidence: 0.9

AGENTS.md: not found in the target repository.

Codex review notes: model internal, reasoning high; reviewed against 3d34569bba9c.

Label changes

Label justifications:

  • P2: The PR addresses a real but bounded filesystem compatibility failure and adds a security-sensitive opt-in mode.
  • merge-risk: 🚨 security-boundary: Merging this PR would allow an opted-in write path to replace strict inode identity proof with content equality under an advisory sidecar lock.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🧂 unranked krab.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: Missing: the PR body claims live rclone validation, but no inspectable terminal output, logs, screenshot, recording, or linked artifact shows strict failure and opt-in success; add redacted proof and update the PR body for re-review.
Evidence reviewed

Security concerns:

  • [medium] PID-only stale reclaim can break mutual exclusion — src/root-impl.ts:1132
    The new lock callbacks remove sidecar locks when the recorded PID is not alive in the local process table; on shared mounts or across PID namespaces, that is not proof the holder stopped writing.
    Confidence: 0.84
  • [medium] Content verification needs approved security contract — src/pinned-write.ts:316
    The fallback accepts matching content instead of proving the target path still names the temp file object; that may be acceptable as an explicit compatibility mode, but it needs maintainer-approved documentation for the weaker same-UID race boundary.
    Confidence: 0.86

What I checked:

  • Target AGENTS.md absent: No AGENTS.md is present inside the fs-safe git root; a parent ClawSweeper AGENTS.md was outside the target repository and was not applied as target policy.
  • Current main remains strict: Current main still lstat()s the target after rename and throws path-mismatch unless the target identity matches the temp file identity. (src/pinned-write.ts:297, 3d34569bba9c)
  • Latest release remains strict: The v0.4.0 tag has the same post-rename sameFileIdentity check, so the requested behavior is not already shipped. (src/pinned-write.ts:290, 6c868d2a0a31)
  • PR helper path still calls Python first: The PR passes onRenameIdentityMismatch into runPinnedWriteHelper, but that helper still uses the Python worker unless Python mode is off; the worker payload does not carry the new policy. (src/pinned-write.ts:118, 2dbd7de7979d)
  • Python helper stays dev/ino-only: On the PR branch, verify_committed_temp still accepts the committed target only when post-rename st_dev and st_ino match the temp fd identity. (src/pinned-python.ts:148, 2dbd7de7979d)
  • Tests cover helper-off only: All seven new rename-identity behavior tests force configureFsSafePython({ mode: "off" }), leaving the default helper-enabled path untested. (test/rename-identity-policy.test.ts:91, 2dbd7de7979d)

Likely related people:

  • steipete: Git blame attributes the current pinned write fallback, Python helper identity checks, sidecar lock API, and original same-file identity surface to Peter Steinberger's fs-safe release/import history; git log -S also ties the check to the earlier deepsec hardening commit mapped to this handle by GitHub metadata. (role: introduced behavior and feature-history owner; confidence: high; commits: 66bf772e4014, 6c868d2a0a31; files: src/pinned-write.ts, src/pinned-python.ts, src/file-identity.ts)
  • vincentkoc: A recent current-main hardening commit touched sameFileIdentity and pinned-write input handling near the affected write/identity path. (role: recent adjacent contributor; confidence: medium; commits: dc0ea4e269b3; files: src/file-identity.ts, src/pinned-write.ts, test/coverage-more.test.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.

@clawsweeper clawsweeper Bot added 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. 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. labels Jul 1, 2026
@jlautman
jlautman marked this pull request as draft July 1, 2026 04:33
jlautman and others added 4 commits July 1, 2026 07:21
…node numbers

On filesystems like rclone FUSE mounts, rename(2) causes every subsequent
path-based lookup on the destination to return a freshly-minted inode number,
making the post-rename (dev,ino) identity check always fail even with a single
process and zero concurrency. This manifests as a deterministic
FsSafeError("path-mismatch") on every overwrite-mode write through
writeFileInRoot/runPinnedWriteFallback.

Adds renameIdentity: "verify-content-with-lock" to RootDefaults and
RootWriteOptions. When set, the write acquires an exclusive sidecar lock for
the target path, performs the write under that lock, and verifies by comparing
the SHA-256 of the written bytes against the bytes re-read from the target
(using an fd-based stat for the returned identity to stay consistent across all
subsequent lookups). Stale locks from crashed holders are detected via
PID-liveness check and removed automatically. Default behavior is unchanged.

Closes openclaw#32
@steipete
steipete force-pushed the fix/fuse-unstable-inode-rename branch from 2dbd7de to 46e6cc2 Compare July 1, 2026 06:31
@steipete
steipete marked this pull request as ready for review July 1, 2026 06:32
@steipete

steipete commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

The branch now deliberately routes the opt-in around the Python helper, fails closed on stale locks, preserves already-exists and mkdir: false, corrects the lock timing docs, keeps per-target locks inside the canonical root, and links exact rclone FUSE proof in the PR body. Please review exact head 46e6cc26cba0f4f2b6e1ea5217cb35a6d34e1bd9.

@clawsweeper

clawsweeper Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@steipete steipete removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Jul 1, 2026
@steipete
steipete merged commit 7c2cfa1 into openclaw:main Jul 1, 2026
11 of 12 checks passed
@steipete

steipete commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Landed via rebase on main as 09614f41d3a2d0467a7227da827e5cae8b76cdb8 through 7c2cfa1b6517153be141d1771bf81dc231f73bec.

Proof:

  • Local pnpm check: 38 test files passed; 423 tests passed, 3 skipped.
  • Local pnpm audit --prod --json: 0 vulnerabilities.
  • Autoreview completed with no accepted/actionable findings after the lock-parent and mkdir: false regressions were fixed.
  • Live packaged-consumer rclone FUSE proof: AWS Crabbox run run_b2ca73c0818e, lease cbx_dfc891eea183. Strict mode returned path-mismatch; the explicit compatibility mode wrote and read the expected content; its root-level lock was removed.
  • Exact-head GitHub checks passed: CI, coverage, and benchmarks.

Caveat: verify-content-with-lock is intentionally weaker than strict object-identity verification and is limited to trusted/cooperating writers; strict identity remains the default. Thanks @jlautman for the report and contribution.

@jlautman

jlautman commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the improvements since we opened this. Three things came up in review that you may want to address or dismiss before merging.

Stream input with verify-content-with-lock throws on FUSE

In runPinnedWriteFallback, when inode churn fires and the content-hash branch runs, a stream input hits:

if (params.input.kind !== "buffer") {
  throw new FsSafeError("path-mismatch", "fallback target changed during write");
}

The stream was consumed writing to the temp file, so there's nothing to hash. But the write succeeded, and the lock means no cooperating writer could have interleaved. Throwing path-mismatch with "changed during write" is wrong here: the file is fine, the error is misleading, and a caller that retries on path-mismatch will attempt a double-write with an already-consumed stream. A safer behavior would be to open the target by fd, take the fd-based stat as the stable identity, and return without content verification, since the lock already provides the mutual exclusion that makes that safe.

O_NOFOLLOW flag computed twice in the same function

runPinnedWriteFallback has the same three-line platform check inline twice: once for the temp file open flags and once for the read handle. Other files in the repo define a module-level SUPPORTS_NOFOLLOW constant instead. A single constant would remove the duplication.

Dead "throw" variant in RenameIdentityMismatchPolicy

type RenameIdentityMismatchPolicy = "throw" | "verify-content";

"throw" is never passed at any call site. The runtime check (!== "verify-content") treats it identically to undefined. Narrowing the type to just "verify-content" removes the implication that the two variants do different things.


Happy to send a patch for any of these, but didn't want to push more commits without checking first.

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

Labels

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Post-rename identity check (sameFileIdentity) always fails on rclone FUSE mounts, even with zero concurrency

2 participants