From 3bf5a1f0c38d50cd053d1f912fddc4e24cd8a6e8 Mon Sep 17 00:00:00 2001 From: AndyMik90 Date: Tue, 17 Feb 2026 15:34:26 +0100 Subject: [PATCH] fix: use write_json_atomic for implementation_plan.json in recovery Replace raw json.dump with write_json_atomic when writing implementation_plan.json in mark_subtask_stuck() to prevent file corruption, consistent with 8+ other call sites in the codebase. Co-Authored-By: Claude Opus 4.6 --- apps/backend/services/recovery.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/backend/services/recovery.py b/apps/backend/services/recovery.py index ea153b59..d23af5cc 100644 --- a/apps/backend/services/recovery.py +++ b/apps/backend/services/recovery.py @@ -21,6 +21,8 @@ from datetime import datetime, timedelta, timezone from enum import Enum from pathlib import Path +from core.file_utils import write_json_atomic + # Recovery manager configuration ATTEMPT_WINDOW_SECONDS = 7200 # Only count attempts within last 2 hours MAX_ATTEMPT_HISTORY_PER_SUBTASK = 50 # Cap stored attempts per subtask @@ -538,8 +540,7 @@ class RecoveryManager: break if updated: - with open(plan_file, "w", encoding="utf-8") as f: - json.dump(plan, f, indent=2) + write_json_atomic(plan_file, plan, indent=2) except (OSError, json.JSONDecodeError, UnicodeDecodeError) as e: logger.warning( f"Failed to update implementation_plan.json for stuck subtask {subtask_id}: {e}"