Skip to content

fix(atomic): retain parent preparation errors when close fails - #820

Merged
steipete merged 2 commits into
mainfrom
fix/atomic-parent-close-errors-20261001
Oct 1, 2026
Merged

steipete merged 2 commits into
mainfrom
fix/atomic-parent-close-errors-20261001

Conversation

@steipete

@steipete steipete commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

When atomic replacement encounters a parent-directory preparation failure and closing that directory also fails, both APIs currently discard the preparation error. For example, an injected EIO from the parent descriptor's stat followed by EPERM from close reports only EPERM.

Preserve both failures in an AggregateError, with the operation error first and close error second. This covers async admission, async mode application, and sync preparation, including falsy thrown values. A close failure on its own remains unchanged. Preparation failure still prevents temporary-file creation and publication, and each descriptor is closed once.

Validation:

  • Regression fails on main 8b6c276b for both sync and async APIs.
  • Focused atomic suites: 101 tests passed, including stat/chmod plus close failures, cleanup, and public settlement behavior.
  • Codex autoreview: clean at P0–P2.
  • Build and allocator artifact build passed. The full local check encountered unrelated native-watch and timing failures under host load; exact-head cross-platform CI and CodeQL are required before merge.

Includes atomic-write documentation and an Unreleased Fixes entry. No release or publication.

@steipete
steipete requested a review from a team as a code owner October 1, 2026 19:47
@clawsweeper

clawsweeper Bot commented Oct 1, 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. 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 1, 2026
@clawsweeper

clawsweeper Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 1, 2026, 4:32 PM ET / 20:32 UTC (Revision 2).

ClawSweeper review

What this changes

Atomic file replacement now reports parent-directory preparation and close failures together, with regression coverage and updated documentation.

Merge readiness

✅ Ready for maintainer review

The fix remains necessary: current main and v0.22.0 still replace preparation failures with close failures. The introduced patch has no actionable correctness findings.

Priority: P2
Reviewed head: 999af02e959b28a893337e494cfa05329942f8e5

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with matching regression coverage and documentation, with no blocking defect found.
Proof confidence 🌊 off-meta tidepool Not applicable: Repository State identifies a MEMBER author, so ordinary contributor proof is exempt. The changed parent-preparation owner has public-API fault regression coverage; the patch changes neither authority nor a stored-data contract.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Repository State identifies a MEMBER author, so ordinary contributor proof is exempt. The changed parent-preparation owner has public-API fault regression coverage; the patch changes neither authority nor a stored-data contract.
Evidence reviewed 8 items Introduced error handling: The pinned introduction adds aggregation at async admission, async mode application, and sync preparation. Error presence uses an object wrapper, preserving undefined and false; a close-only failure remains unchanged.
Still needed on main: Current main closes directly in the admission catch and application finally blocks, allowing close failures to supersede preparation failures.
Latest release also retains the defect: The v0.22.0 source contains the same direct-close error precedence; this change is not already present in the supplied latest release.
Findings None None.
Security None None.

How this fits together

Atomic replacement prepares and verifies the destination’s parent directory before creating a temporary file and publishing its contents. Preparation failures stop publication and are returned to the caller after descriptor cleanup.

flowchart TD
 A[Replacement request] --> B[Verify parent directory]
 B --> C[Apply directory mode]
 C --> D[Close parent descriptor]
 D --> E{Preparation succeeded?}
 E -->|Yes| F[Stage and publish replacement]
 E -->|No| G[Report preparation and close errors]
Loading

Before merge

None.

Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production and regression growth production +15 net lines, tests +48 lines The bounded production growth preserves dual failures across three existing preparation paths.

Technical review

Best possible solution:

Retain operation-first error aggregation while preserving fail-closed parent admission, descriptor lifetime, and publication ordering.

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

Yes, source establishes the trigger: a parent stat or chmod failure followed by a close failure causes current main to report only the latter. The added public-API regression covers that path; this review did not execute it.

Is this the best way to solve the issue?

Yes, aggregating only simultaneous failures is a narrow repair consistent with existing atomic temporary-file error handling.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This repairs diagnostic error loss during a limited dual-failure scenario without changing successful publication.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Repository State identifies a MEMBER author, so ordinary contributor proof is exempt. The changed parent-preparation owner has public-API fault regression coverage; the patch changes neither authority nor a stored-data contract.

Evidence

What I checked:

Likely related people:

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

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-10-01T19:49:58.714Z sha 9467e70 :: needs maintainer review before merge. :: none

@steipete
steipete merged commit b4c0815 into main Oct 1, 2026
44 checks passed
@steipete
steipete deleted the fix/atomic-parent-close-errors-20261001 branch October 1, 2026 20:44
@steipete

steipete commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Merged as b4c0815 after verifying and pinning head 999af02 in the squash-merge API call.

The regression fails on main for both sync and async replacement: parent stat/chmod throws, close throws, and the preparation error was discarded. The fix retains the errors in operation-first order, including falsy primary values, closes once, and prevents temp creation/publication after failed preparation.

Validation: 101 focused atomic tests passed; Codex autoreview clean through P2; 38 exact-head checks passed with only intentionally skipped jobs. CI: https://github.com/openclaw/fs-safe/actions/runs/36921637485 . CodeQL: https://github.com/openclaw/fs-safe/actions/runs/36921637676 . The first green head required an ordinary base update because strict branch protection required current main; the updated head was fully revalidated. No admin bypass, tag, release, or publication.

steipete added a commit that referenced this pull request Oct 2, 2026
Add bounded transition checks for small pending-hint budgets, missing descendants, case and Unicode aliases, undecodable names, exclusions, directory lifecycle, scope replacement and subscription isolation. Verify invalidation-only cache convergence and calibrate failure cleanup and four-pass polling bounds.

Add seeded TypeScript reference properties, 65,536 Rust Pending operations, and sync/async atomic fault-injection coverage. Include the finite corpus in the nightly five-runner stress workflow. No new dependency or test-only restructuring.

Validated with 500 poll and 500 event seeds on Linux, APFS macOS and NTFS Windows, focused properties and Rust checks on each OS, plus exact-head all-OS CI and CodeQL. Parent-close precedence and Windows dangling-leaf creation were fixed separately in #820 and #823.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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