Skip to content

feat: harden atomic replacement and output staging - #62

Merged
steipete merged 2 commits into
mainfrom
feat/hardened-replace
Jul 27, 2026
Merged

steipete merged 2 commits into
mainfrom
feat/hardened-replace

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Summary

  • add pinned-descriptor destinationHardlinks: "reject" checks to async and sync atomic replacement
  • add bounded copyFallbackRestore: "restore-original" recovery with typed restored / restore-failed cleanup receipts
  • add writeExternalFileWithinRoot({ staging: "sibling" }) for fsynced same-filesystem atomic replacement, while retaining private workspace staging as the default
  • add a sanitized fallbackFileName for both external-output staging modes

Consumers

OpenClaw's exec-approvals write path can use the restore and hardlink policies when a Windows permission fallback would otherwise risk leaving state partially written. Callers delegating output production through writeExternalFileWithinRoot() can now choose sibling staging when the destination directory is the writable boundary and atomic overwrite is required.

Safety model

The restore path snapshots and rewrites through the same pinned destination handle, enforces an explicit restore-byte budget before mutation, fsyncs both the replacement and any recovery, and reports whether recovery succeeded. Sibling output staging pins and validates the producer file, rejects symlink/hardlink/size violations, guards the target parent identity, then renames over the destination without following an existing symlink entry.

Proof

  • pnpm check — 55 files, 597 passed, 7 platform skips; build, boundary lint, file-size lint, and package check passed
  • pnpm test:security — 5 files, 59 passed
  • pnpm pack:check — passed
  • focused atomic/output suite — 35 passed
  • autoreview — clean, no accepted/actionable findings
  • packed-artifact behavior validation — 8 contract clauses passed, including torn-write restoration and sibling symlink replacement

This PR is intended for the unreleased 0.5.0 line. It does not publish or release anything.

@steipete
steipete requested a review from a team as a code owner July 27, 2026 02:41
@clawsweeper clawsweeper Bot added 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. 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. merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. labels Jul 27, 2026
@clawsweeper

clawsweeper Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 26, 2026, 10:45 PM ET / July 27, 2026, 02:45 UTC.

ClawSweeper review

What this changes

This PR adds opt-in hardlink rejection and original-content restoration to atomic replacement, and adds sibling-directory staging as an atomic-output mode for externally produced files.

Merge readiness

⛔ Blocked until real behavior proof is added - 4 items remain

Keep this PR open for targeted validation: it materially expands security-sensitive public filesystem-write behavior, while both Windows Node check jobs are failing and the PR body provides result claims rather than inspectable after-fix runtime evidence. Likely related people: steipete is the available recent area contributor signal (low confidence, based on this single implementation commit); broader current-main ownership could not be established from the available read-only inspection path.

Priority: P2
Reviewed head: 22f5862440cb51a00b88f0af6acf38e05e7eaa1a

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The patch has substantial focused implementation and test coverage, but merge-ready confidence is capped by missing inspectable real behavior proof and unresolved Windows validation failures.
Proof confidence 🧂 unranked krab (1/6) Needs real behavior proof before merge: The PR body lists successful commands and contract-clause counts, but it does not include inspectable after-fix terminal output, logs, recording, or linked artifact demonstrating the new restore and sibling-staging behavior. Please attach redacted live evidence; after updating the PR body, a maintainer can request @clawsweeper re-review if needed. 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 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The PR body lists successful commands and contract-clause counts, but it does not include inspectable after-fix terminal output, logs, recording, or linked artifact demonstrating the new restore and sibling-staging behavior. Please attach redacted live evidence; after updating the PR body, a maintainer can request @clawsweeper re-review if needed. 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 Public write-path expansion: The branch adds copyFallbackRestore, maxRestoreBytes, and destinationHardlinks to atomic replacement, and adds staging plus fallbackFileName to external output staging; these are public compatibility and filesystem-safety contracts.
New sibling staging implementation: The added sibling staging module creates, validates, and renames a producer-controlled staged file in the destination directory, making its confinement and race behavior merge-critical.
Windows validation is not yet green: The supplied PR check state reports failures for both Node 22 check (windows-latest) and Node 24 check (windows-latest), while the PR specifically changes the EPERM/EEXIST copy-fallback path intended for Windows permission behavior.
Findings None None.
Security None None.

How this fits together

replaceFileAtomic() is the package’s guarded final-write primitive, taking caller content and publishing it at a destination after temporary staging and optional durability work. writeExternalFileWithinRoot() lets an external producer write a staged file under a rooted boundary, then validates and commits it to the requested output path.

flowchart LR
  A[Caller content or external producer] --> B[Temporary staged file]
  B --> C[Identity and link checks]
  C --> D[Atomic rename or copy fallback]
  D --> E[Rooted destination]
  E --> F[Durability and cleanup receipt]
Loading

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The PR body lists successful commands and contract-clause counts, but it does not include inspectable after-fix terminal output, logs, recording, or linked artifact demonstrating the new restore and sibling-staging behavior. Please attach redacted live evidence; after updating the PR body, a maintainer can request @clawsweeper re-review if needed. 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 merge risk (P2) - The two failed Windows Node check jobs leave the intended Windows permission-fallback behavior unverified; this change can affect callers that rely on a replacement either completing safely or reporting a recoverable failure.
  • Resolve merge risk (P1) - staging: "sibling" is a new public write mode that operates in the destination directory, so a missed path-identity, symlink, or cleanup edge case could weaken root-confinement guarantees for callers selecting it.
  • Resolve merge risk (P2) - The new options alter failure receipts and fallback semantics; callers need clear upgrade and platform proof that default behavior remains unchanged when no new option is selected.
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Changed surface 13 files affected; 1,179 additions and 120 deletions The PR combines new public API options, new filesystem-write logic, tests, and four documentation surfaces in one security-sensitive change.
Platform validation 2 Windows Node check failures; 3 Windows-related checks still in progress Windows is the primary platform for the new permission-error fallback, so this validation state is material before merge.

Merge-risk options

Maintainer options:

  1. Validate the Windows fallback path before merge (recommended)
    Fix or explain both failing Windows Node checks and attach redacted runtime output showing the permission-error fallback, restoration receipt, and default non-restoring mode.
  2. Limit the initial landing scope
    If Windows restoration proof cannot be produced promptly, defer the restore-on-fallback option and land only the independently validated staging work in a narrower PR.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Re-run the failing Windows checks after a focused repair and attach redacted live output for copy-fallback restoration plus the unchanged default fallback mode.

Technical review

Best possible solution:

Resolve the Windows failures, then provide redacted after-fix terminal or runtime evidence exercising copy-fallback restoration and sibling staging on their relevant platforms, while preserving the existing default workspace-staging and non-restoring fallback contracts.

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

Not applicable: this PR adds opt-in APIs rather than reporting a pre-existing bug. The relevant validation is an after-fix platform exercise of the Windows permission fallback and sibling-directory commit path.

Is this the best way to solve the issue?

Unclear: the proposed guarded staging and pinned-handle approach is directionally appropriate, but it is not yet the best confirmed solution until the failed Windows checks and real after-fix behavior evidence support its platform-specific safety claims.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This is a significant but bounded enhancement to a public filesystem-safety primitive, without evidence of an active user-facing outage.
  • add merge-risk: 🚨 compatibility: New exported options and typed cleanup details can change caller expectations around fallback and output-staging behavior.
  • add merge-risk: 🚨 security-boundary: Sibling staging and pinned-destination recovery operate across untrusted path, link, and identity boundaries where an implementation regression could weaken confinement.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR body lists successful commands and contract-clause counts, but it does not include inspectable after-fix terminal output, logs, recording, or linked artifact demonstrating the new restore and sibling-staging behavior. Please attach redacted live evidence; after updating the PR body, a maintainer can request @clawsweeper re-review if needed. 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.

Label justifications:

  • P2: This is a significant but bounded enhancement to a public filesystem-safety primitive, without evidence of an active user-facing outage.
  • merge-risk: 🚨 compatibility: New exported options and typed cleanup details can change caller expectations around fallback and output-staging behavior.
  • merge-risk: 🚨 security-boundary: Sibling staging and pinned-destination recovery operate across untrusted path, link, and identity boundaries where an implementation regression could weaken confinement.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; 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. Needs real behavior proof before merge: The PR body lists successful commands and contract-clause counts, but it does not include inspectable after-fix terminal output, logs, recording, or linked artifact demonstrating the new restore and sibling-staging behavior. Please attach redacted live evidence; after updating the PR body, a maintainer can request @clawsweeper re-review if needed. 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

What I checked:

  • Public write-path expansion: The branch adds copyFallbackRestore, maxRestoreBytes, and destinationHardlinks to atomic replacement, and adds staging plus fallbackFileName to external output staging; these are public compatibility and filesystem-safety contracts. (src/replace-file.ts:71, 22f5862440cb)
  • New sibling staging implementation: The added sibling staging module creates, validates, and renames a producer-controlled staged file in the destination directory, making its confinement and race behavior merge-critical. (src/output-sibling.ts:1, 22f5862440cb)
  • Windows validation is not yet green: The supplied PR check state reports failures for both Node 22 check (windows-latest) and Node 24 check (windows-latest), while the PR specifically changes the EPERM/EEXIST copy-fallback path intended for Windows permission behavior. (22f5862440cb)
  • Available recent-area provenance: The branch consists of one implementation commit, authored by steipete, covering the new atomic replacement and output-staging behavior; no reliable broader current-main history could be inspected in this environment. (src/replace-file-copy-fallback.ts:1, 22f5862440cb)

Likely related people:

  • steipete: The available branch provenance shows steipete authored the single commit implementing the new atomic-replacement and output-staging paths; broader ownership history was not available for confirmation. (role: recent area contributor; confidence: low; commits: 22f5862440cb; files: src/replace-file.ts, src/replace-file-copy-fallback.ts, src/output.ts)

Rank-up moves

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

  • Resolve or explain both failing Windows Node checks with the relevant failing output.
  • Add redacted after-fix terminal or runtime proof for a torn copy-fallback restore and sibling staging replacement.
  • Show that existing callers using the default workspace staging and default non-restoring fallback retain their prior behavior.

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.

@clawsweeper

clawsweeper Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper status: review started.

I am starting a fresh review of this pull request: feat: harden atomic replacement and output staging This is item 1/1 in the current shard. Shard 0/1.

This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking.

Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted.

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. P2 Normal priority bug or improvement with limited blast radius. 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant