Skip to content

fix: replace non-atomic write_text() calls with atomic helpers in map_step_runner - #457

Merged
azalio merged 1 commit into
mainfrom
claude/compassionate-cerf-he3i8x
Sep 14, 2026
Merged

azalio merged 1 commit into
mainfrom
claude/compassionate-cerf-he3i8x

Conversation

@azalio

@azalio azalio commented Sep 14, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes #456 — replaces 13 remaining Path.write_text() calls in map_step_runner.py.jinja with the _write_json_file() / _write_text_file() atomic helpers that route through atomic_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

Function File written Criticality
generate_implementer_readiness implementation-readiness.md medium
build_verification_summary verification summary medium
write_pr_draft pr-draft.md medium
write_plan_review plan review .md medium
update_review_verdict_ledger review-verdict-ledger.md medium
replace_active_issues active-issues.json HIGH
stage_pending_review_ordering pending ordering JSON HIGH
build_learning_handoff learning handoff .md medium
add_known_issue known-issues.json HIGH
update_plan_status task_plan_<branch>.md HIGH
save_research_artifact research artifact .md medium
acknowledge_diagnostic diagnostics ledger JSON HIGH
discard_worktree .patch file low

Five write_text() calls are intentionally retained:

  • Two create-only guards (if path.exists(): continue / if not gitignore.exists())
  • Two ensure_*_file create-only helpers
  • One snapshot backup inside try/except OSError: pass

Testing

  • All 834 existing pytest tests pass
  • ruff check clean
  • pyright 0 errors / 0 warnings / 0 informations
  • make check-render passes (generated trees match templates_src)

🤖 Generated with Claude Code

https://claude.ai/code/session_01UgHmPwdEWm3dhsNK4D4KzY


Generated by Claude Code

Summary by CodeRabbit

  • Refactor
    • Standardized how generated reports, plans, patches, review files, and other text artifacts are saved.
    • Standardized JSON output handling while preserving existing formatting.
    • Existing write-error handling and processing behavior remain unchanged.

…_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
@azalio
azalio merged commit 0b267e6 into main Sep 14, 2026
1 check passed
@coderabbitai

coderabbitai Bot commented Sep 14, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 2aaa8ebb-d415-4e35-b6c7-e1d657e61497

📥 Commits

Reviewing files that changed from the base of the PR and between 64d2c36 and a84d69c.

📒 Files selected for processing (3)
  • .map/scripts/map_step_runner.py
  • src/mapify_cli/templates/map/scripts/map_step_runner.py
  • src/mapify_cli/templates_src/map/scripts/map_step_runner.py.jinja

📝 Walkthrough

Walkthrough

The runner and its Jinja template now route text artifacts through _write_text_file and JSON artifacts through _write_json_file. Existing serialization and error handling remain unchanged.

Changes

Atomic artifact writes

Layer / File(s) Summary
Report and review artifacts
.map/scripts/map_step_runner.py, src/mapify_cli/templates/map/scripts/map_step_runner.py, src/mapify_cli/templates_src/map/scripts/map_step_runner.py.jinja
Readiness, summary, pull-request, review, and verdict files now use _write_text_file.
State and plan artifacts
.map/scripts/map_step_runner.py, src/mapify_cli/templates/map/scripts/map_step_runner.py, src/mapify_cli/templates_src/map/scripts/map_step_runner.py.jinja
Issue and pending-ordering JSON files use _write_json_file. Learning and plan files use _write_text_file.
Snapshots, ledgers, and patches
.map/scripts/map_step_runner.py, src/mapify_cli/templates/map/scripts/map_step_runner.py, src/mapify_cli/templates_src/map/scripts/map_step_runner.py.jinja
Snapshot, ledger, and worktree patch writes use _write_text_file.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: High

Suggested reviewers: yvasiyarov

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/compassionate-cerf-he3i8x

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

A rabbit sees the writers align,
Text hops safely through one line.
JSON keeps its ordered trail,
No torn files disturb the tale.
The runner thumps a steady beat.
Atomic paws make work complete.

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

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.

bug: 13 remaining non-atomic write_text() calls in map_step_runner — missed by #454 batch

2 participants