fix: atomic writes and error recovery in ensure_*_issues_file and add_known_issue (#464) - #465
Conversation
…_known_issue (#464) Four non-atomic writes and a bare json.loads() in map_step_runner could leave the MAP Framework in a broken state after a crash mid-write: - ensure_active_issues_file: replace write_text() with _write_json_file() (atomic) - ensure_known_issues_file: same fix - add_known_issue: replace bare json.loads() with _read_json_file(); on corrupt/missing file fall back to KNOWN_ISSUES_DEFAULT instead of raising; type annotation changed from dict[str, object] to dict[str, Any] to satisfy Pyright downstream operations - ensure_human_artifacts: replace write_text() with _write_text_file() (atomic) Three regression tests added: - test_corrupt_file_is_not_written_partially (active-issues.json) - test_new_file_write_is_valid_json (known-issues.json) - test_add_known_issue_recovers_from_corrupt_file Full suite: 5805 passed, 4 skipped. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014U8hzu49WSe2TXQqPmnD82
|
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 (4)
📝 WalkthroughWalkthroughThe change routes map-step file writes and JSON reads through shared helpers. Known-issue appends now recover from corrupt files. Tests cover atomic file preservation, valid JSON creation, and corrupt-file recovery. ChangesIssue file I/O
Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix · Severity of issue fixed: Medium 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 checks the issue file bright Comment |
Summary
Fixes four non-atomic writes and a bare
json.loads()inmap_step_runner.py.jinjathat could leave the MAP Framework in a permanently broken state after a crash or OOM kill mid-write.Changes
ensure_active_issues_file: replacedpath.write_text()with_write_json_file()(atomic tempfile +os.replace)ensure_known_issues_file: same fixadd_known_issue: replaced barejson.loads()with safe_read_json_file(); on corrupt or missing file now falls back toKNOWN_ISSUES_DEFAULTinstead of raising; type annotation widened fromdict[str, object]todict[str, Any]to satisfy Pyright for downstream.append()andlen()callsensure_human_artifacts: replacedpath.write_text()with_write_text_file()(atomic)All four helpers (
_write_json_file,_write_text_file,_read_json_file,atomic_write_text) were already present in the codebase; this PR wires the threeensure_*andadd_known_issuefunctions up to them consistently with the rest of the file.Tests
Three regression tests added to
tests/test_map_step_runner.py:TestEnsureActiveIssuesFile.test_corrupt_file_is_not_written_partiallyTestEnsureKnownIssuesFile.test_new_file_write_is_valid_jsonTestAddKnownIssue.test_add_known_issue_recovers_from_corrupt_fileVerification
Closes #464
🤖 Generated with Claude Code
https://claude.ai/code/session_014U8hzu49WSe2TXQqPmnD82
Generated by Claude Code
Summary by CodeRabbit
Bug Fixes
Tests