Skip to content

fix(guest): fall back for directory no-replace publication when RENAME_NOREPLACE is unsupported - #876

Merged
steipete merged 2 commits into
mainfrom
fix/guest-noreplace-directory-fallback
Oct 8, 2026
Merged

steipete merged 2 commits into
mainfrom
fix/guest-noreplace-directory-fallback

Conversation

@steipete

@steipete steipete commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Linux guest workspace publication failed when a filesystem rejected renameat2(RENAME_NOREPLACE): the embedded Python helper fell back to a hard link even for directory sources. This fixes the guest-helper path reported in openclaw/openclaw#167231. Thanks @valkyriweb for the report and gVisor diagnosis.

After a definitive unsupported-operation rejection, directories recheck source identity and target absence, then rename through the same admitted directory descriptors. A trailing slash enforces directory source type at the syscall. Non-empty directories and non-directory targets are refused as EEXIST; an empty directory created concurrently after the absence check can be replaced, matching the bounded native design in #838. No empty claim directory becomes visible before the completed workspace is published. Identity checks are separate from the syscall, with a post-publication identity check.

Regular files use the existing no-follow link fallback, now verifying both names against the admitted inode at exactly two links before unlinking the source, then verifying the one-link destination. Exclusive-create cleanup preserves changed payloads and ambiguous link pairs. The guest has no strict/require mode and is independent of host native policy; macOS and other error paths remain fail-closed.

Validation: the new regression suite failed against fresh main 71e0d679 before the fix (including directory publication with forced EINVAL); all 42 focused tests now pass. Tests exercise the exported guest fragment with the existing Python process fault-injection approach and real descriptor-relative filesystem operations, including collisions and identity races. git diff --check and independent Codex P0–P2 autoreview passed. pnpm check passed: 13,586 tests, 4,185 platform/native-feature skips, both WASM builds, documentation checks, boundary/file-size checks, and installed-package checks. The first local build selected Homebrew Rust without the WASM target; using the already-installed rustup toolchain resolved it. Final committed-branch Codex P0–P2 review, including the embedding helper context, is also clean. Rust is unchanged.

Real-filesystem proof passed on an AWS Crabbox Linux lease with runsc release-20260928.0, systrap, and --file-access-mounts=shared. The guest helper ran against an actual gofer bind volume. A direct syscall probe returned EINVAL with source intact; main reproduced EPERM from hard-linking the directory. The fixed fragment preserved directory identity and complete payload, published files with one final link and no source name, and refused existing non-empty-directory, file, and empty-directory targets without changing them. The first proof attempt stopped at a fixture volume-permission error before publication; correcting the isolated fixture permissions produced the successful run.

The gVisor syscall trace confirmed:

baseline: renameat2(..., RENAME_NOREPLACE) = EINVAL; linkat(directory, ...) = EPERM
fixed directory: renameat2(..., RENAME_NOREPLACE) = EINVAL; renameat(..., "source/", ...) = 0
fixed file: renameat2(..., RENAME_NOREPLACE) = EINVAL; linkat(..., 0) = 0; unlinkat(source, ...) = 0

No release or OpenClaw dependency bump is included. The OpenClaw issue remains open until the fs-safe release and consumer bump.

The task-owned AWS lease has been released after the proof.

Final head 425dd078b4bbd3d67916400466fd08222eb865b3 passed all applicable Linux/macOS/Windows CI lanes, ARM64, musl, both glibc 2.28 compatibility lanes, native checks, and Clippy/audit: CI, CodeQL, coverage, and benchmarks. No CI failures, retries, or bypasses were needed.

@steipete
steipete requested a review from a team as a code owner October 8, 2026 17:34
@clawsweeper

clawsweeper Bot commented Oct 8, 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: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 8, 2026
@clawsweeper

clawsweeper Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 8, 2026, 1:43 PM ET / 17:43 UTC.

ClawSweeper review

What this changes

Add checked Linux directory-rename and file-link publication fallbacks when guest filesystems reject no-replace rename.

Example: Publish a prepared workspace on a gVisor gofer bind volume

  • Before: RENAME_NOREPLACE returns EINVAL, then hard-linking the directory fails with EPERM.
  • After: The helper publishes the complete directory through descriptor-relative rename and verifies its identity.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A useful, focused repair with real gVisor proof, meaningful race coverage, and no open finding.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The exported guest publication fragment ran on an actual gVisor shared gofer volume: unsupported rename reproduced the baseline directory-link failure, while the fixed path preserved directory identity and payload, consumed file sources with one final link, and refused existing targets. Copied syscall output supports the changed production path; no persisted format or migration changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A prepared guest workspace cannot be published on filesystems that reject Linux no-replace rename.
Reason: The failure has a concrete filesystem mechanism and real before-and-after evidence. The established guest-area owner proposes and explains the bounded public-contract changes.

Merge readiness

✅ Ready for maintainer review

This PR remains necessary: current main still attempts to hard-link directory sources after unsupported no-replace rename. The supplied gVisor proof exercises the repair, and no actionable patch defect was found.

Priority: P2
Reviewed head: 425dd078b4bbd3d67916400466fd08222eb865b3

Before merge

None.

Findings

None.

Agent review details

How this fits together

The package exports Python filesystem code for container and SSH guests, including a fragment used to publish prepared workspaces. Callers provide admitted directory descriptors and names; the fragment publishes the source or reports failure.

flowchart TD
 A[Admitted directories and names] --> B[Guest publication helper]
 B --> C[Native no-replace rename]
 C -->|Success| G[Published destination]
 C -->|Unsupported on Linux| D[Verify source and target absence]
 D --> E[Directory rename]
 D --> F[File link and checked source removal]
 E --> G
 F --> G
Loading

Technical review

Best possible solution:

Keep publication in the shared guest fragment with the documented bounded fallback, then release the package and update the consuming application separately.

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

Yes: current-main source clearly reaches directory hard-linking after unsupported rename, and the contributor's real gVisor trace records EINVAL followed by EPERM. The reviewer did not execute the failure.

Is this the best way to solve the issue?

Yes: the repair belongs in the shared guest publication fragment, retains admitted descriptors, and documents the fallback's limits rather than duplicating workspace logic in a consumer.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: shipped entry point. Added test files: 2.

Security

None.

Evidence

What I checked:

  • Current-main defect remains: Main routes unsupported Linux no-replace rename directly to os.link, with no directory publication path; directories cannot be hard-linked. (src/guest-native-python.ts:66, 71e0d67988c5)
  • Introduced production behavior: The pinned delta adds descriptor-relative directory rename with source-type enforcement and post-publication identity verification, plus checked file-link consumption and conservative exclusive-create cleanup. (src/guest-native-python.ts:76, 425dd078b4bb)
  • Real gVisor before-and-after proof: The fully read PR body reports AWS Crabbox Linux with runsc release-20260928.0, systrap, and shared gofer mounts. Its copied syscall trace shows baseline EINVAL followed by directory-link EPERM, fixed directory rename success, and fixed file link/unlink success. Observed results include preserved directory identity and payload, one-link file publication, and unchanged existing targets. Captured body source identity: 47ca288529295dd019ff1b6025633e05c16e6e25998e1fe1614bc5da85f1f88c. No reviewer execution is claimed. (425dd078b4bb)
  • Owner-supported bounded tradeoff: The area owner's PR explicitly accepts replacement of an empty directory created after the absence check and documents file-source consumption and partial-publication reconciliation. The merged native precedent fix(native): fall back for no-replace moves when RENAME_NOREPLACE is unsupported #838 describes the same directory race limit; it fixes a separate native owner, not this guest fragment. (docs/guest.md:51, 425dd078b4bb)
  • Feature history and routing: History identifies Peter Steinberger as the guest extraction author and repeated contributor to the publication path. The introducing commit API resolves the account to steipete and shows the fragment added in feat(guest): share the Python guest filesystem engine #333. Raw commit data records parent 31d2a93. (src/guest-native-python.ts:35, aad0142f5030)
  • Regression coverage: Two test files exercise complete directory publication, file-source consumption, existing and raced targets, source substitution, third links, and preservation of ambiguous staging payloads using real filesystem operations with injected syscall behavior. (test/guest-noreplace-fallback.test.ts:33, 425dd078b4bb)

Likely related people:

  • Peter Steinberger: Raw commit aad0142 adds src/guest-native-python.ts:35 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: aad0142f5030; files: src/guest-native-python.ts)

Review metrics

Metric Value Why it matters
Production and test growth production +52/-5 lines; tests +204/-0 lines The added production code implements the two bounded publication paths, while most growth covers filesystem collisions and identity interference.

Labels

Label changes:

  • add P2: This repairs guest workspace publication on Linux filesystems that reject no-replace rename.
  • add merge-risk: 🚨 compatibility: The exported fragment now consumes successful file-fallback sources and permits a raced empty-directory replacement; the area owner explicitly documents and accepts these contract changes.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: This repairs guest workspace publication on Linux filesystems that reject no-replace rename.
  • merge-risk: 🚨 compatibility: The exported fragment now consumes successful file-fallback sources and permits a raced empty-directory replacement; the area owner explicitly documents and accepts these contract changes.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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.

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: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant