Skip to content

fix(output): publish report and pilot outputs atomically (#4542) - #4589

Merged
EffortlessSteven merged 8 commits into
mainfrom
claude/project-thread-2rk3d2-atomic-out
Sep 29, 2026
Merged

EffortlessSteven merged 8 commits into
mainfrom
claude/project-thread-2rk3d2-atomic-out

Conversation

@EffortlessSteven

@EffortlessSteven EffortlessSteven commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

Requested by Steven · project thread

Summary

Before: every --out / --out-md report writer (through output::file_write::write and cli::commands::write_text_file) truncated the destination and then wrote it; ripr pilot used plain fs::write. If the process died mid-write (Ctrl-C, a cancelled CI step, SIGXFSZ) or the disk filled, the previous complete report was replaced by an empty or half-written file. Receipt: reports gap-ledger under ulimit -f 1 left 1024 bytes of unparseable JSON where a good 1989-byte ledger had been. A concurrent reader such as ripr lsp could read a torn file.

After: report and pilot outputs are published through the existing owner, crate::atomic_file: an exclusively created (create_new) temporary file with a short fixed-shape name beside the destination, the old file's permissions carried over, fsync, rename. Readers see the old file or the complete new one. Symlinked, non-regular and read-only destinations are refused before anything is written, as the old in-place write refused them.

How: atomic_file has one core, replace_with, behind write, write_cache and the new streaming replace_streamed. file_write::write_with is validate_destination plus replace_streamed, and pilot's repo-exposure.json streams through it.

Fixes #4542.

Swarm / Source Boundary

  • ordinary feature, analyzer, editor, docs, spec, fixture, badge, dependency, or repo-ops development for ripr-swarm

Source-of-truth Links

Proposal: n/a
Spec: n/a
ADR: n/a
Plan item: 0.11 shared-state hunt
Governing issue or accepted claim: #4542
Acceptance delta (one sentence): an interrupted or failed report or pilot write leaves the previous complete file in place.

Candidate Relationships

Candidate branch: claude/project-thread-2rk3d2-atomic-out
Stack parent or prerequisite PR: none
Proposed replacement of PR: none

Scope

  • crates/ripr/src/atomic_file.rs: shared replace_with core, replace_streamed, create_new temp.
  • crates/ripr/src/output/file_write.rs: delegates; refuses read-only destinations; tests.
  • crates/ripr/src/cli/commands/pilot.rs: pilot artifacts go through file_write.
  • crates/ripr/tests/cli_smoke.rs: end-to-end interrupted-write test.

Scope Classification

  • One production behavior

Non-goals:

  • app/pr_summary, app/impacted_evidence, app/annotations and cli/rerun still use fs::write; follow-up.
  • A process ended by SIGKILL can leave a hidden .ripr-atomic-*.tmp beside the destination; the destination is intact.
  • review_comments_receipt keeps its own publish path; it shares validate_destination, so it now also refuses read-only destinations.

Support-tier Impact

  • none

Policy Impact

  • none

Proof

cargo test -p ripr --lib -- file_write atomic_file check_artifact review_comments_receipt   # 52 passed
cargo test -p ripr --test cli_smoke -- interrupted_report_write                            # 1 passed
cargo clippy -p ripr --all-targets -- -D warnings                                          # exit 0
cargo xtask precommit                                                                      # exit 0
# negative: restoring truncate-in-place fails the CLI test with
#   "an interrupted write replaced the previous report with 512 bytes"

Tests: output::file_write::tests::{replaces_a_longer_file_completely_and_leaves_no_temp, a_destination_name_near_the_filename_limit_is_still_written, a_read_only_destination_is_refused_and_left_untouched, a_refused_destination_is_left_untouched, ...}, cli_smoke::interrupted_report_write_keeps_the_previous_complete_report, existing atomic_file and check_artifact tests (error texts unchanged).

Windows was not run locally; hosted Windows CI covers fs::rename replace semantics.

Claim Boundary

  • Claimable: readers never see a torn report or pilot artifact from these writers.
  • Not claimable: that the pilot artifact set is updated together across files. Each file is atomic on its own.

Rollback

Revert the commit.

Static Language Check

  • Static output avoids killed, survived, untested, proven, and adequate.

Engineering Check

  • No new panic, unwrap, expect, todo, or unimplemented.
  • Public JSON/schema changes are documented. (None.)

Gates

  • cargo fmt --check
  • cargo xtask precommit
  • cargo clippy -p ripr --all-targets -- -D warnings

Review

Codex P2 and the Devin findings are addressed and resolved. CodeRabbit (rate limit), Gemini (quota) and droid-review (queued) reviews are missing, not clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_014WDSj54AyARNwy6oUuYXnx

file_write::write truncated the destination and then wrote it, so an
interrupted run, a full disk or a cancelled CI step left a torn report where
the previous complete one was, and ripr pilot used plain fs::write. Write
to an exclusively created temporary file beside the destination, keep the
old file's permissions, fsync, then rename over it; non-regular and
symlinked destinations are still refused. write_with streams pilot's
repo-exposure.json the same way. create_new alone makes the temporary
file safe, so targets without known no-follow flag values no longer
refuse output writes.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014WDSj54AyARNwy6oUuYXnx
@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@coderabbitai

coderabbitai Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 53 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: a0a98699-3e8f-4d6d-b1b7-a6cbb196cfb5

📥 Commits

Reviewing files that changed from the base of the PR and between 3911480 and 5a3fb0a.

📒 Files selected for processing (5)
  • CHANGELOG.md
  • crates/ripr/src/atomic_file.rs
  • crates/ripr/src/cli/commands/pilot.rs
  • crates/ripr/src/output/file_write.rs
  • crates/ripr/tests/cli_smoke.rs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@EffortlessSteven EffortlessSteven self-assigned this Sep 29, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-29T01:35:28.892153Z e0fe494 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 5 potential issues.

Devin Review

Comment thread crates/ripr/src/output/file_write.rs Resolved
Comment thread crates/ripr/src/output/file_write.rs Resolved
Comment thread crates/ripr/src/output/file_write.rs Resolved
Comment thread crates/ripr/src/output/file_write.rs Resolved
Comment thread crates/ripr/src/output/file_write.rs Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e0fe494b76

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/ripr/src/output/file_write.rs Resolved
file_write no longer carries its own temp-and-rename copy. atomic_file
gains replace_streamed, sharing one core with write/write_cache: an
exclusively created temp file with a short fixed-shape name, so a
destination name near the 255-byte limit still writes. A read-only
destination is refused with PermissionDenied, as the old in-place
write was, instead of being replaced by the rename.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014WDSj54AyARNwy6oUuYXnx
…-2rk3d2-atomic-out

# Conflicts:
#	CHANGELOG.md

@EffortlessSteven EffortlessSteven left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exact-head review of 44cee16: REVIEW_READY.

What I inspected

  • The full diff (5 files).
  • atomic_file::replace_with:
    • Error stages keep every existing message text for write and write_cache, and the existing tests cover them.
    • The temp file is created with create_new under a short name.
    • Permissions are copied after the fill; fsync happens before the rename.
    • The temp file is removed on every error path.
  • file_write::validate_destination: refuses non-regular and read-only destinations. review_comments_receipt is the other caller, and it now also refuses read-only destinations.
  • Pilot: every artifact goes through write_artifact, and repo-exposure.json streams with its render error preserved.
  • The symlink race is answered on its thread: rename replaces the link and never writes through it.

Oracle grip

  • The CLI ulimit -f test fails when truncate-in-place is restored.
  • The read-only, long-name, directory and symlink cases are asserted with no leftover temp files.

CI and review

  • CI is green on this head: GitHub-hosted Rust gates, Rust-only lane, ub-review, cargo-deny.
  • The last change is a main merge that touched only CHANGELOG, as a union of the entries.
  • All Codex and Devin threads are resolved.
  • CodeRabbit, Gemini and droid-review reviews are missing, not clean.

Generated by Claude Code

@EffortlessSteven
EffortlessSteven enabled auto-merge (squash) September 29, 2026 03:07
…-2rk3d2-atomic-out

# Conflicts:
#	CHANGELOG.md
…-2rk3d2-atomic-out

# Conflicts:
#	CHANGELOG.md
#	crates/ripr/tests/cli_smoke.rs

@EffortlessSteven EffortlessSteven left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exact-head note for b170eec, two merges of origin/main.

  • CHANGELOG is a union.
  • tests/cli_smoke.rs: both sides appended tests at the end of the file. I kept both, this PR's interrupted_report_write_keeps_the_previous_complete_report and main's #4480 input-limit tests, and each has its own closing.
  • cargo check -p ripr exits 0.
  • cli_smoke -- interrupted_report_write input_limit dev_zero: 4 passed.
  • --lib -- file_write atomic_file: 11 passed.

Production code is unchanged since the last review. The CodeRabbit, Gemini and droid-review reviews are still missing, which is not the same as clean.


Generated by Claude Code

…-2rk3d2-atomic-out

# Conflicts:
#	CHANGELOG.md
#	crates/ripr/src/cli/commands/pilot.rs
#	crates/ripr/src/output/file_write.rs
…-2rk3d2-atomic-out

# Conflicts:
#	CHANGELOG.md
…c writes)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014WDSj54AyARNwy6oUuYXnx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(output): report --out/--out-md writes truncate in place, so an interrupted or failed write destroys the old file

2 participants