Skip to content

fix(native): fall back for no-replace moves when RENAME_NOREPLACE is unsupported - #838

Merged
steipete merged 4 commits into
mainfrom
fix/noreplace-move-fallback
Oct 6, 2026
Merged

steipete merged 4 commits into
mainfrom
fix/noreplace-move-fallback

Conversation

@steipete

@steipete steipete commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Linux filesystems that reject renameat2(RENAME_NOREPLACE) can now complete Root.move() in native auto mode through the already-retained, identity-checked parents. This addresses the native move failure in openclaw/openclaw#165617 and completes the move fallback deliberately left fail-closed by #834 (related: #828). Thanks @StarGazer1995 and original QNAP reporter @bbs2i58 for the reports, and @MertBasar0 for tracing the consumer error-classification gap.

Files publish with linkat without AT_SYMLINK_FOLLOW, verify the exact two-link source/target inode pair, then recheck and unlink the source. Admission and final publication require one link. Collisions cannot overwrite the target. Denied or unsupported links fail closed naming both capabilities; EPERM may be a per-file restriction, not filesystem-wide lack of hard links. Post-publication errors preserve the target and expose details.publication and details.sourceRemoval, including target-published/source-still-linked and source-removed/final-verification-failed states.

Directories recheck the source and target absence, then use plain renameat through the retained parents. Non-empty directories and non-directory competitors reject as already-exists; a concurrently created empty directory can be replaced. A trailing slash enforces directory type at syscall time, preventing a substituted file or symlink from clobbering a file. Identity checks and the syscall remain separate; this is not source-name compare-and-swap. Native require never takes either fallback.

The existing per-binding cache remains bounded to 128 devices. Only distinct sibling rejections populate it; cross-parent directory-ancestry EINVAL cannot poison it. isNoReplaceUnsupported(error), exported from @openclaw/fs-safe and /errors, recognizes helper-unavailable with details.capability === "rename-noreplace". Consumers no longer need internal native cause-code matching. Docs, API snapshot, and method benchmark coverage are updated.

Caller Unsupported-capability behavior
Root no-replace file/directory moves New retained-parent fallback in Linux auto; require refuses.
movePathWithCopyFallback() Existing guarded replacing rename and cross-device copy contract; no no-replace flag dependency.
Archive file publication, private producer/temp promotion Keep #834's existing owner-specific auto fallbacks.
Native-only staged/retained-entry/symlink publication, directory replacement, explicit rename-noreplace publication Continue to fail closed under their stricter recovery contracts.

Isolated seccomp tests cover file/directory success, collision races, the empty-directory edge, source file/symlink substitution, changed target, third links, link-denial/unsupported errnos, failed source unlink, failed final target inspection, and strict mode. Public Root and standalone move integration covers both modes and capability/partial-state classification. The original native move path failed before fallback admission was added.

Real-filesystem proof used an AWS Crabbox lease and a FUSE passthrough filesystem whose rename callback rejects nonzero flags. Actual absent-target renameat2 returned EINVAL for files and directories. A separately built fresh-main baseline (c237b390) refused the file move and still disallowed no-replace directory moves. The fixed public Root API preserved inode and payload in auto; require refused both. strace showed the actual fallback syscalls:

renameat2(..., RENAME_NOREPLACE) = -1 EINVAL
linkat(..., 0) = 0
unlinkat(..., 0) = 0
renameat(..., "source/", ..., "target") = 0

The AWS lease has been released. This is Linux/FUSE evidence, not a claim to have tested QNAP or OpenZFS. The reporter subsequently confirmed absent-target EINVAL for both files and directories in all five tested locations: Public, Container, media, Docker data, and container-local overlay /tmp, on kernel 5.10.60-qnap. This corrects the original share-specific diagnosis: the rejection is host-wide in the reported environment. Successful plugin installs took ClawPack and made no renameat2 calls. The patched build has not yet been tested on that QNAP. Current OpenClaw npm staging calls movePathWithCopyFallback(), which already uses ordinary replacing rename; the reporter's older-state plugin installation still needs end-to-end confirmation.

Validation passed: cargo test --workspace --locked, cargo clippy --workspace --all-targets --locked, native/package builds, focused tests, pnpm check (17,225 passing tests, 731 platform/feature skips, plus installed-package validation), and independent Codex P0–P2 review. Local method smoke passed in off (996 cases / 322 callable exports and methods) and require (1,030 / 335) modes. CI caught and prompted fixes for ARM's 32-bit link count, mandatory benchmark registration, and filtered-child cleanup on ARM; no assertions or syscall denials were weakened. Final head 8ef4593c06d420d5e96c7e385403c232aa4dd48a has 41 successful checks and six intentional skips, including every applicable Linux/macOS/Windows lane, ARM64, musl, and glibc 2.28: CI, CodeQL, and coverage. No admin bypass or CodeQL retry was needed.

After the OpenClaw bump, remove the unsupported-native-rename branch and raw/internal errno matching in moveLegacyMigrationFileNoReplace() (src/infra/state-migrations.no-replace-move.ts, from openclaw/openclaw#164748). Keep exact two-link inspection/recovery for interrupted moves. Missing-addon/native-off fallback compatibility is a separate contract; removing that path requires an explicit policy decision. Use the public classifier and fallback details for capability diagnostics and deferral.

No release or package publication is included.

…unsupported

Keep auto-mode file and directory moves through retained parents, preserve inode and collision checks, and expose a stable unsupported-capability classifier with partial-state receipts. Require mode stays fail-closed.

Refs openclaw/openclaw#165617; related to #828 and #834. Thanks @StarGazer1995, @bbs2i58, and @MertBasar0 for the reports and trace.
@steipete
steipete requested a review from a team as a code owner October 6, 2026 06:34
@clawsweeper

clawsweeper Bot commented Oct 6, 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: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 6, 2026
@clawsweeper

clawsweeper Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed October 6, 2026, 3:33 AM ET / 07:33 UTC (Revision 3).

ClawSweeper review

What this changes

The PR adds Linux file and directory move fallbacks through retained parent directories, capability-error classification, partial-state reporting, documentation, and regression coverage.

Merge readiness

⛔ Blocked before merge - 4 items remain

The move fallback remains useful and is not implemented on current main. The latest test-cleanup correction introduces no identified defect, but the previously raised directory collision-contract decision remains unresolved.

Priority: P2
Reviewed head: 8ef4593c06d420d5e96c7e385403c232aa4dd48a
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Focused implementation with real filesystem proof and extensive recovery coverage; the deliberate directory-contract choice remains separate from patch quality.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): Captured AWS Linux/FUSE observations exercise the changed public Root move path after actual unsupported renameat2 results: auto preserves inode and payload through file and directory fallbacks, while require refuses. No stored-data format changes are introduced; QNAP/OpenZFS coverage is not claimed.
Patch quality 🐚 platinum hermit (4/6) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): Captured AWS Linux/FUSE observations exercise the changed public Root move path after actual unsupported renameat2 results: auto preserves inode and payload through file and directory fallbacks, while require refuses. No stored-data format changes are introduced; QNAP/OpenZFS coverage is not claimed.
Evidence reviewed 9 items Applicable repository policy: Read the full root AGENTS.md. No nested AGENTS.md or maintainer-notes directory was found. Filesystem boundaries, explicit bounded fallbacks, public contracts, and regression guidance informed the review; target autoreview helpers were not run.
Pinned introduced changes: Inspected the pinned main-to-head production, documentation, test, fixture, and benchmark changes. Host evidence verifies the test merge's main/head parents and identifies no base-only changes.
Still necessary on main: Current main rejects no-clobber directory moves and reports unsupported file rename capability without a move fallback. GitHub verifies #834 merged; its explicitly documented Root move refusal does not supersede this work. The latest release is v0.23.1, and no released move fallback was established.
Findings None None.
Security Needs attention Resolve the directory collision contract: Plain renameat can replace a concurrently created empty destination despite the default no-clobber request. This documented behavior requires an explicit safety-contract decision.

How this fits together

fs-safe gives Node.js applications guarded filesystem roots for untrusted paths. Root moves admit source and destination parents, perform native filesystem operations, and verify identities and outcomes.

flowchart TD
 A[Root move request] --> B[Path and mutation admission]
 B --> C[Retained parent directories]
 C --> D[Atomic no-replace rename]
 D --> E[Unsupported capability]
 E --> F[Strict mode refusal]
 E --> G[Auto file or directory fallback]
 G --> H[Identity checks and outcome]
Loading

Decision needed

Question Recommendation
Should default no-clobber directory moves permit replacing a racing empty directory when Linux lacks RENAME_NOREPLACE? Keep directories atomic: Land the file fallback and supported atomic directory moves while keeping unsupported directory moves fail-closed.

Why: Documentation and deterministic coverage establish the behavior, but do not establish acceptance of the weaker filesystem-safety contract.

Before merge

  • Resolve security concern: Resolve the directory collision contract - Plain renameat can replace a concurrently created empty destination despite the default no-clobber request. This documented behavior requires an explicit safety-contract decision.
  • Resolve merge risk (P2) - Default no-clobber directory moves gain a fallback that can replace a concurrently created empty destination; acceptance of this weaker collision guarantee has not been recorded.
  • Complete next step (P1) - Explicitly approve the directory fallback's racing empty-directory replacement behavior, or keep unsupported directory moves fail-closed.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.

Findings

  • [medium] Resolve the directory collision contract — native/src/move_noreplace.rs:64
Agent review details

Security

Needs attention: No supply-chain regression was found; the deliberate weakening of directory collision protection still needs explicit acceptance.

Review metrics

Metric Value Why it matters
Production and test changes production +203/-24; tests and fixtures +418/-28 Production growth implements native fallback and error contracts with substantial race and partial-state coverage.

Merge-risk options

Maintainer options:

  1. Preserve directory collision guarantees (recommended)
    Keep unsupported directory moves fail-closed while retaining the file fallback and atomic directory path.
  2. Approve the bounded fallback
    Record explicit acceptance of racing empty-directory replacement before landing the documented auto-mode behavior.

Technical review

Best possible solution:

Keep the identity-checked file fallback and atomic directory moves, with unsupported directory moves remaining fail-closed unless maintainers explicitly approve the documented collision tradeoff.

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

Yes: current main source establishes unsupported-move refusal, and supplied Linux/FUSE baseline and after-fix observations exercise that path. This reviewer did not execute it.

Is this the best way to solve the issue?

Partly: retained-parent file link/unlink is focused and preserves collisions; directory fallback introduces a safety-policy choice that can be narrowed to atomic no-replace behavior.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded filesystem compatibility improvement without demonstrated emergency impact in the target package.
  • merge-risk: 🚨 compatibility: Previously rejected directory requests gain default behavior whose fallback permits racing empty-directory replacement.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (terminal): Captured AWS Linux/FUSE observations exercise the changed public Root move path after actual unsupported renameat2 results: auto preserves inode and payload through file and directory fallbacks, while require refuses. No stored-data format changes are introduced; QNAP/OpenZFS coverage is not claimed.
  • proof: sufficient: Contributor real behavior proof is sufficient. Captured AWS Linux/FUSE observations exercise the changed public Root move path after actual unsupported renameat2 results: auto preserves inode and payload through file and directory fallbacks, while require refuses. No stored-data format changes are introduced; QNAP/OpenZFS coverage is not claimed.

Evidence

Security concerns:

  • [medium] Resolve the directory collision contract — native/src/move_noreplace.rs:64
    Plain renameat can replace a concurrently created empty destination despite the default no-clobber request. This documented behavior requires an explicit safety-contract decision.
    Confidence: 0.99

What I checked:

  • Applicable repository policy: Read the full root AGENTS.md. No nested AGENTS.md or maintainer-notes directory was found. Filesystem boundaries, explicit bounded fallbacks, public contracts, and regression guidance informed the review; target autoreview helpers were not run. (AGENTS.md:18, 8ef4593c06d4)
  • Pinned introduced changes: Inspected the pinned main-to-head production, documentation, test, fixture, and benchmark changes. Host evidence verifies the test merge's main/head parents and identifies no base-only changes. (src/native-move-fallback.ts:30, 8ef4593c06d4)
  • Still necessary on main: Current main rejects no-clobber directory moves and reports unsupported file rename capability without a move fallback. GitHub verifies fix(native): fall back when renameat2 RENAME_NOREPLACE is unsupported #834 merged; its explicitly documented Root move refusal does not supersede this work. The latest release is v0.23.1, and no released move fallback was established. (src/root-move-noreplace.ts:80, c237b390ffe7)
  • Release boundary: GitHub's latest release endpoint reports v0.23.1, published October 5, 2026. The branch changelog places the move fallback under Unreleased. (CHANGELOG.md:3, 8ef4593c06d4)
  • File recovery contract: File fallback uses non-following linkat, verifies the exact two-link inode pair before unlink, preserves the destination on errors, and retains published/removed details when final target inspection fails. Strict mode does not enter fallback. (native/src/move_noreplace.rs:75, 8ef4593c06d4)
  • Directory contract remains unresolved: Plain renameat can replace an empty destination created after the absence check. The writing documentation and deterministic empty-race case acknowledge this behavior. Live reviews are empty and discussion contains only bot comments, with no subsequent acceptance of the earlier safety-contract concern. (native/src/move_noreplace.rs:64, 8ef4593c06d4)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

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

  • Resolve whether unsupported directory moves remain fail-closed or intentionally permit racing empty-directory replacement.

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 (2 earlier review cycles)
  • reviewed 2026-10-06T06:46:27.813Z sha 3447cec :: blocked before merge. :: none
  • reviewed 2026-10-06T07:17:39.974Z sha 55fa303 :: blocked before merge. :: none

@steipete
steipete merged commit 47fc598 into main Oct 6, 2026
48 checks passed
@steipete
steipete deleted the fix/noreplace-move-fallback branch October 6, 2026 07:40
steipete added a commit that referenced this pull request Oct 6, 2026
Add copyRootFileSync to the advanced surface for synchronous plugin captures. Retain the admitted source, create an exclusive guarded destination, reuse the bounded native clone/copy-range/byte engine, and return the owned destination descriptor for hashes and receipts.

Refs openclaw/openclaw#161739.

Validated with Rust workspace tests and Clippy, native and TypeScript builds, focused race/bounds/clone tests, package and declaration checks, the full serial check, Codex review at P0-P2, and exact-head all-OS CI, coverage, and CodeQL. Rebased onto #838; no release.
steipete added a commit that referenced this pull request Oct 8, 2026
…E_NOREPLACE is unsupported (#876)

Use descriptor-relative, identity-checked directory rename after definitive Linux no-replace rejection. Preserve non-empty directories and file targets; document that a concurrently created empty directory can be replaced. Verify both file links at nlink=2 before source removal and preserve ambiguous create staging.

Reported in openclaw/openclaw#167231; follows the native design in #838. Thanks @valkyriweb for the report and gVisor diagnosis.

Verified failing-main regressions, 42 focused tests, pnpm check, actual runsc release-20260928.0 shared-gofer-volume baseline/fix proof, and exact-head multi-OS CI, CodeQL, coverage, benchmarks, and Codex P0-P2 review. No release is included.
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. P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant