fix: replace non-atomic write_text() calls with atomic helpers in map_step_runner - #457
Conversation
…_step_runner Replace 13 remaining Path.write_text() calls in map_step_runner.py.jinja with the _write_json_file() and _write_text_file() atomic helpers that go through atomic_write_text() (tempfile.mkstemp + os.replace). Path.write_text() truncates then writes, so a process crash between those two operations leaves a corrupted/empty file. The atomic helpers write to a PID-unique sibling temp file first, then rename into place so readers never see a partial write. Functions fixed: - generate_implementer_readiness (implementation-readiness.md) - build_verification_summary (verification summary file) - write_pr_draft (pr-draft.md) - write_plan_review (plan review .md) - update_review_verdict_ledger (review-verdict-ledger.md) - replace_active_issues (active-issues.json) — HIGH criticality - stage_pending_review_ordering (pending ordering JSON) — HIGH criticality - build_learning_handoff (learning handoff .md) - add_known_issue (known-issues.json) — HIGH criticality - update_plan_status (task_plan_<branch>.md) — HIGH criticality - save_research_artifact (research artifact .md) - acknowledge_diagnostic (diagnostics ledger JSON) — HIGH criticality - discard_worktree (.patch file) Five write_text() calls are intentionally kept (create-only guards and a snapshot backup in try/except OSError:pass). Closes #456 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UgHmPwdEWm3dhsNK4D4KzY
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe runner and its Jinja template now route text artifacts through ChangesAtomic artifact writes
Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix · Severity of issue fixed: High Suggested reviewers: ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. A rabbit sees the writers align, Comment |
Summary
Fixes #456 — replaces 13 remaining
Path.write_text()calls inmap_step_runner.py.jinjawith the_write_json_file()/_write_text_file()atomic helpers that route throughatomic_write_text()(tempfile.mkstemp + os.replace).Path.write_text()truncates the destination file before writing, so a process crash between those two operations leaves a corrupted or zero-byte file. The atomic helpers write to a PID-unique sibling temp file first, then atomically rename into place — readers always see either the old complete file or the new complete file, never a partial write.Functions fixed
generate_implementer_readinessimplementation-readiness.mdbuild_verification_summarywrite_pr_draftpr-draft.mdwrite_plan_review.mdupdate_review_verdict_ledgerreview-verdict-ledger.mdreplace_active_issuesactive-issues.jsonstage_pending_review_orderingbuild_learning_handoff.mdadd_known_issueknown-issues.jsonupdate_plan_statustask_plan_<branch>.mdsave_research_artifact.mdacknowledge_diagnosticdiscard_worktree.patchfileFive
write_text()calls are intentionally retained:if path.exists(): continue/if not gitignore.exists())ensure_*_filecreate-only helperstry/except OSError: passTesting
ruff checkcleanpyright0 errors / 0 warnings / 0 informationsmake check-renderpasses (generated trees match templates_src)🤖 Generated with Claude Code
https://claude.ai/code/session_01UgHmPwdEWm3dhsNK4D4KzY
Generated by Claude Code
Summary by CodeRabbit