Skip to content

fix(cli): keep the existing config when ripr init cannot finish writing (#4883) - #4887

Merged
EffortlessSteven merged 4 commits into
mainfrom
claude/project-thread-2rk3d2-atomic-rest
Oct 1, 2026
Merged

EffortlessSteven merged 4 commits into
mainfrom
claude/project-thread-2rk3d2-atomic-rest

Conversation

@EffortlessSteven

@EffortlessSteven EffortlessSteven commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

Summary

Before: ripr init --force deleted the existing ripr.toml before writing the new one, and printed Overwrote existing … before the write ran. With a full disk or a file-size limit, the user's config was replaced by a 512-byte fragment. A rerun then refused to replace the fragment without --force, and the fragment could still parse as a config missing its later sections. A plain ripr init left the same fragment behind.

After:

  • --force replaces the config atomically through atomic_file::write, so the old file stays until the rename.
  • A plain init stages the config in a same-directory temp file and publishes it with a no-replace hard link, so a failed write leaves no ripr.toml and never touches a file another process created.
  • A replaced symlink no longer passes its target's permissions to the new config.
  • Wrote and Overwrote existing … print only after the publish succeeds.

How:

Fixes #4883.

Swarm / Source Boundary

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

Source-of-truth Links

Plan item: 0.11 shared-state hunt
Governing issue or accepted claim: #4883
Acceptance delta (one sentence): a failed ripr init write leaves the previous config, or no file, never a fragment.

Candidate Relationships

Candidate branch: claude/project-thread-2rk3d2-atomic-rest
Stack parent or prerequisite PR: none

Scope

  • crates/ripr/src/atomic_file.rs: create_new, CreateNewError, and the symlink-safe permission copy.
  • crates/ripr/src/cli/commands/init.rs: write_init_target and apply_init_plan.
  • crates/ripr/tests/cli_smoke.rs: two unix tests.
  • CHANGELOG.md.

Scope Classification

  • One production behavior

Non-goals:

  • A concurrent writer racing --force is overwritten; --force means replace.
  • On a filesystem without hard links, a SIGKILL during a fresh init can still leave a partial file.

Support-tier Impact

  • none

Policy Impact

  • none

Proof

cargo test -p ripr --test cli_smoke -- init_            # 14 passed
cargo test -p ripr --lib -- atomic_file                  # passed
cargo xtask precommit                                    # exit 0
cargo clippy -p ripr --all-targets --locked -- -D warnings   # exit 0
  • init_that_cannot_finish_writing_keeps_the_previous_config runs init under trap '' XFSZ; ulimit -f 1.
    • For --force, it checks the previous config is intact, no .tmp is left, and no Overwrote line prints.
    • For a fresh init, it checks no file and no staged temp remain, and a rerun succeeds.
    • With the old init.rs restored, it fails.
  • init_force_replaces_a_symlinked_config_without_writing_its_target: the link target is untouched, and the target's 0o604 mode is not inherited.
  • Unit tests cover create-new refusal, a dangling symlink, and symlink permissions.

Claim Boundary

  • Claimable: ripr init never leaves a truncated config after a write error.
  • Not claimable: that a concurrent --force preserves another writer's save.

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.

Gates

  • cargo fmt --check
  • cargo xtask precommit

🤖 Generated with Claude Code

https://claude.ai/code/session_014WDSj54AyARNwy6oUuYXnx

…ng (#4883)

--force removed ripr.toml before writing the replacement, so a full disk
left a truncated fragment and printed "Overwrote existing" first. Replace
through atomic_file (rename, no symlink follow) and remove a partial
create_new file on a failed write.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014WDSj54AyARNwy6oUuYXnx
@EffortlessSteven
EffortlessSteven marked this pull request as ready for review September 29, 2026 07:37
@coderabbitai

coderabbitai Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

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

Next included review available in 23 minutes.

Check out review usage here.

View limit details

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

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 870daf6e-7751-4bd0-afeb-19822d37d9bd

📥 Commits

Reviewing files that changed from the base of the PR and between 35fa4be and b4975d2.

📒 Files selected for processing (4)
  • CHANGELOG.md
  • crates/ripr/src/atomic_file.rs
  • crates/ripr/src/cli/commands/init.rs
  • crates/ripr/tests/cli_smoke.rs
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


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 enabled auto-merge (squash) September 29, 2026 07:38
@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-29T07:40:32.656439Z 3e2f814 Draft marked ready
ℹ️ 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.

@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 self-review of 3e2f814. No blocking findings.

  • Owner. The publish step goes through the existing atomic_file::write: a create_new temp file, the old file's permissions, fsync, rename. No parallel writer is added.
  • Symlink safety (#1948/#2101). Overwrite renames over the directory entry, and the new symlink test confirms the link's target is untouched. Create keeps create_new and only removes a file it created itself, after a failed write_all.
  • --ci github. An existing workflow file takes the same Overwrite path, so it is protected the same way.
  • Output. Overwrote existing now prints after the write, and the duplicate Wrote line on overwrite is gone. No test depended on either line.
  • Oracle. The size-limit test fails on the old code (receipt in the PR body).

CodeRabbit (rate limit), Gemini (quota) and droid-review reviews are missing, not clean. Hosted CI is pending.


Generated by Claude Code

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request improves the robustness of the ripr init command by ensuring that --force replaces the configuration file atomically, preventing truncated files in case of write failures like a full disk. Additionally, a plain ripr init now cleans up and removes any partially written configuration files if the write fails. The review feedback suggests explicitly calling sync_all() on the file handle in write_init_target to ensure that asynchronous writeback errors are caught and handled before the file is closed.

Comment thread crates/ripr/src/cli/commands/init.rs Resolved

@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/cli/commands/init.rs Resolved
Comment thread crates/ripr/src/cli/commands/init.rs Resolved
Comment thread crates/ripr/src/cli/commands/init.rs Resolved
Comment thread crates/ripr/tests/cli_smoke.rs Resolved
Comment thread crates/ripr/src/cli/commands/init.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: 3e2f814411

ℹ️ 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/cli/commands/init.rs Resolved

@github-actions github-actions 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.

Confirmed findings

  • Codex flag: atomic_file::write copies old entry's permissions, but uses std::fs::metadata which follows symlinks; world-readable symlink target yields perms into the generated file. Public route change.
  • Cleanup unlinks by path; if a concurrent writer replaces ripr.toml between create_new and the error-cleanup remove, the user's replacement is deleted. Real risk under the new diff.
  • Both new tests are cfg(unix). The Overwrite path is shared across platforms and rename behavior on Windows differs (ReplaceFile vs rename). Architecture does not block, but cross-platform parity of the fragment-leaves-previous guarantee is unverified.

Verification questions

  • Confirm cHANGELOG entry claims 'a plain ripr init removes a file it could not finish writing'; but if remove_file itself fails, partial file stays and only the write error is reported.
  • Confirm create branch in write_init_target still opens with create_new, preserving #1948 invariant, but on partial write removes file by path not inode; concurrent replacement is lost.
  • Confirm new unix-only tests do not exercise Windows behavior for the shared Overwrite path; rename semantics and open-handle behavior differ.
  • Confirm both new tests are #[cfg(unix)]; shared Overwrite path runs on Windows but rename/open-handle semantics differ; no Windows regression coverage.
  • Confirm eNOSPC/EFBIG can surface on close()/sync_all() rather than write_all. Code only checks write_all then drops the handle, leaving a truncated file when the OS only fails at writeback.

Refuted

  • Concurrent writer race makes --force unsafe: rename discards another process's save between plan and rename.; refuted because: The new code is the same atomic-publish pattern already used elsewhere in the codebase; introducing a lock or version check here would expand the diff beyond a smallest-complete fix for #4883 and is a policy/scope decision, not a boundary error. Not a blocker for this PR's claimed behavior.
  • sync_all needed to catch async writeback errors per gemini-code-assist suggestion; refuted because: Out of tests-red-green lane scope; this is a correctness/architecture point about ENOSPC visibility, not a red/green test weakness.
  • Overwrite path lost the duplicate Wrote line and may break callers that grep it.; refuted because: Diff removes the println!("Wrote ...") only from the Overwrite branch's write_init_target return path; Overwrite now prints Overwrote existing ... post-write and no Wrote. No seeded review or test depends on the duplicate line; owner self-review explicitly notes 'No test depended on either line'.

Evidence gaps

  • Model proof intent was rejected by deterministic validation.

…missions (#4883 review)

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

@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 ad4da01. Disposition: no blocking findings; merge waits on required CI.

What I inspected (4 files, +341/-31):

  • atomic_file::publish_with:
    • Replace renames over the destination. It copies permissions only when symlink_metadata reports a regular file.
    • NoReplace publishes with hard_link and then removes the temp file. CreateNewError separates a staging failure from a publish failure.
  • init:
    • --force goes through atomic_file::write.
    • A fresh config goes through create_new. AlreadyExists is reported and never overwrites.
    • Filesystems without hard links fall back to create_new + write_all + sync_all, and the error names a cleanup failure.
    • "Wrote" and "Overwrote" print only after the publish succeeds.
  • Oracles:
    • The size-limited init tests use EFBIG as a stand-in for ENOSPC.
    • For --force they check the previous config is kept byte for byte, with no .tmp and no "Overwrote" line. For a fresh init they check no file and no staged temp remain, and that a rerun succeeds.
    • The symlink test checks that the target is untouched and that its 0o604 mode is not inherited.
    • Unit tests cover create-new refusal, a dangling symlink, and symlink permissions.

Local results:

  • cargo clippy -p ripr --all-targets --locked -D warnings: 0.
  • cargo xtask precommit: 0.
  • cli_smoke init_: 14/14 passed.
  • atomic_file/file_write unit tests: all passed except output_dir_tests::unwritable_parent_create_names_the_flag, a known root-container chmod failure from main's #4774 test.

Review threads: all 7 answered. Devin's --force race is declined with the reason given in the thread.

Review providers: CodeRabbit is missing (rate-limited) and droid-review is missing (queued). Neither counts as a clean review.


Generated by Claude Code

@EffortlessSteven
EffortlessSteven enabled auto-merge (squash) September 29, 2026 08:51
…-2rk3d2-atomic-rest

# Conflicts:
#	CHANGELOG.md
@EffortlessSteven
EffortlessSteven merged commit 1eb54ee into main Oct 1, 2026
33 of 34 checks passed
@EffortlessSteven
EffortlessSteven deleted the claude/project-thread-2rk3d2-atomic-rest branch October 1, 2026 07:57
EffortlessSteven added a commit that referenced this pull request Oct 4, 2026
…rofiles (#4978) (#5170)

`init_that_cannot_finish_writing_keeps_the_previous_config` (#4887) runs
`ripr init` twice under `trap '' XFSZ; ulimit -f 1`. With SIGXFSZ ignored
the child exits normally and its LLVM profile write at exit is cut to 512
bytes inside target/llvm-cov-target. `llvm-profdata merge` (default
failure mode `any`) then rejects the whole set: two consecutive-PID
"file header is corrupt" warnings and "no profile can be merged", the
rust-coverage signature on every main push since #4887 merged.

Route both `ulimit -f` children through one helper that points the
child's LLVM_PROFILE_FILE at /dev/null. That profile can never be complete
under the cap; every other process keeps its profile.


Claude-Session: https://claude.ai/code/session_01S5D7B2JxJ754s1p6ktir1Y

Co-authored-by: Claude <noreply@anthropic.com>
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(cli): a failed ripr init write leaves a truncated ripr.toml, and --force destroys the old config first

2 participants