fix: replace non-atomic write_text() with atomic helpers in map_step_runner (#454) - #455
Conversation
…_step_runner Eight functions used Path.write_text() directly, which truncates the file before writing — leaving corrupted state if the process crashes mid-write. Replace all occurrences with the existing atomic helpers: - _write_json_file(path, payload) for JSON writes - _write_text_file(path, content) for text writes Both helpers use tempfile.mkstemp + os.replace, making writes crash-safe. Functions fixed: - refresh_blueprint_affected_files (blueprint.json — critical state file) - record_diagnostics_baseline (diagnostics_baseline.json) - record_test_baseline (4 early-return paths in test_baseline.json) - record_subtask_baseline (subtask_baseline_<id>.json) - build_escalation_outcome (escalation artifact .md) - create_approval_hold (approval_hold_<id>.md) - decide_approval_hold (approval_hold_<id>.md) Fixes #454. Related: #448 #450 #452. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01H5N7oWn43kXwk2N8vyEvNe
|
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 map step runner replaces direct JSON and text writes with 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 hops where state files lie, Comment |
Summary
Fixes #454 — eight functions in
map_step_runner.py.jinjausedPath.write_text()directly, which truncates the file before writing. A process crash between truncation and the final write leaves the file permanently corrupted with no recovery path.Changes
Replace all non-atomic
write_text()calls with the existing crash-safe helpers:_write_json_file(path, payload)—tempfile.mkstemp+os.replace_write_text_file(path, content)— same mechanism viaatomic_write_textFunctions fixed
refresh_blueprint_affected_filesblueprint.jsonrecord_diagnostics_baselinediagnostics_baseline.jsonrecord_test_baseline(4 paths)test_baseline.jsonrecord_subtask_baselinesubtask_baseline_<id>.jsonbuild_escalation_outcome.mdartifactcreate_approval_holdapproval_hold_<id>.mddecide_approval_holdapproval_hold_<id>.mdThe corresponding JSON store writes in the last three functions already used
_write_json_file()correctly; only the human-readable.mdreports were missing atomic protection.Verification
make render-templates— propagated to all generated treespytest tests/— 5544 passed, 4 skipped, 12 deselectedatomic_write_textOSError), Bug: _write_retry_quarantine in map_orchestrator uses non-atomic non-PID-unique temp file (missed in #446) #450 and Bug: non-atomic writes in finalize_plan and _write_feedback_file (missed in #446/#450 batch fix) #452 (fixedmap_orchestratornon-atomic writes)🤖 Generated with Claude Code
https://claude.ai/code/session_01H5N7oWn43kXwk2N8vyEvNe
Generated by Claude Code
Summary by CodeRabbit