Skip to content

fix(orchestrator): use atomic_write_text in _write_feedback_file and finalize_plan (#452) - #453

Merged
azalio merged 1 commit into
mainfrom
claude/compassionate-cerf-1etylv
Sep 11, 2026
Merged

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

Conversation

@azalio

@azalio azalio commented Sep 11, 2026

Copy link
Copy Markdown
Owner

Summary

  • _write_feedback_file used write_text on .map/<branch>/<filename> feedback artifacts — a torn write leaves a partial markdown file
  • finalize_plan used write_text on artifact_manifest.json — a critical state file read by multiple tools; a torn write can corrupt the manifest and stall every downstream gate

Same bug class as #446, #448, #450. Both functions already import atomic_write_text from map_utils; the fix is a one-line swap in each.

Changes

  • Replace write_text with atomic_write_text in _write_feedback_file and finalize_plan in map_orchestrator.py.jinja
  • Propagated to generated trees via make render-templates
  • Added two regression tests (test_write_feedback_file_uses_atomic_write, test_finalize_plan_uses_atomic_write) that record Path.replace call sites and assert distinct temp paths per invocation, no temp residue, and correct content

Test plan

  • uv run pytest tests/test_map_orchestrator.py::test_write_feedback_file_uses_atomic_write tests/test_map_orchestrator.py::test_finalize_plan_uses_atomic_write — 2 passed
  • uv run ruff check src/ tests/ — All checks passed
  • uv run python -m pyright src/ — 0 errors, 0 warnings, 0 informations
  • make check-render — Generated trees match templates_src
  • Full suite: 5542 passed, 4 skipped

🤖 Generated with Claude Code

https://claude.ai/code/session_01EnSmZxuMDE9BZCCh2kn8Mm


Generated by Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Improved the reliability of monitor feedback and plan manifest file updates by using safer atomic writes, helping prevent incomplete or corrupted files.
  • Tests

    • Added coverage to verify atomic file replacement, correct file contents, and cleanup of temporary files.

…finalize_plan (#452)

Both functions used plain write_text on files that must survive concurrent
access or process death without corruption — the same bug class fixed in
#446 and #450.

_write_feedback_file wrote .map/<branch>/<filename> feedback artifacts with
write_text; a torn write leaves a partial markdown file.

finalize_plan wrote artifact_manifest.json — a critical state file read by
multiple tools — with write_text; a torn write can corrupt the manifest and
stall every downstream gate that reads it.

Replace both calls with atomic_write_text (already imported from map_utils),
which uses tempfile.mkstemp for a process-unique temp and os.replace for an
atomic rename, matching the pattern already applied to StepState.save,
_write_retry_quarantine (#450), and _append_restored_subtask_to_plan (#446).

Add regression tests that record Path.replace call sites and assert:
- distinct temp paths per invocation (no shared .tmp collision)
- no temp residue after a successful write
- correct content written atomically

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EnSmZxuMDE9BZCCh2kn8Mm
@azalio
azalio merged commit 35619a3 into main Sep 11, 2026
1 of 2 checks passed
@coderabbitai

coderabbitai Bot commented Sep 11, 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: c91b289f-6a9f-45bc-ae4b-4a118dc210d3

📥 Commits

Reviewing files that changed from the base of the PR and between 6e1ad6f and 9278f5a.

📒 Files selected for processing (4)
  • .map/scripts/map_orchestrator.py
  • src/mapify_cli/templates/map/scripts/map_orchestrator.py
  • src/mapify_cli/templates_src/map/scripts/map_orchestrator.py.jinja
  • tests/test_map_orchestrator.py

📝 Walkthrough

Walkthrough

The orchestrator now uses atomic_write_text for monitor feedback and artifact manifest writes. Regression tests verify atomic replacement, unique temporary files, content preservation, and cleanup.

Changes

Atomic orchestrator writes

Layer / File(s) Summary
Atomic write paths
.map/scripts/map_orchestrator.py, src/mapify_cli/templates/map/scripts/map_orchestrator.py, src/mapify_cli/templates_src/map/scripts/map_orchestrator.py.jinja
Feedback files and artifact manifests now use atomic_write_text instead of direct write_text calls.
Atomic write regression tests
tests/test_map_orchestrator.py
Tests verify atomic replacement, distinct temporary files, correct content, manifest updates, and removal of temporary files.

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

Change: Bug fix

✨ 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-1etylv

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 checked each file with care
Atomic writes now guard the pair
Feedback lands without a tear
Manifests finish clean and clear
No stray temp files hide anywhere

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.

2 participants