@@ -251,6 +251,45 @@ def _output_files(output_dir: Path) -> list[str]:
251251 )
252252
253253
254+ def _has_resume_artifacts (output_dir : Path ) -> bool :
255+ """Return whether deleting output_dir would lose resumable long-run work."""
256+ if not output_dir .exists ():
257+ return False
258+ progress_patterns = (
259+ "*.h5" ,
260+ "*.h5.metadata.json" ,
261+ "calibration_manifest.json" ,
262+ "long_run_production_manifest.json" ,
263+ ".parallel_tmp/*/*.h5" ,
264+ ".parallel_tmp/*/*.h5.metadata.json" ,
265+ ".parallel_tmp/*/calibration_manifest.json" ,
266+ ".parallel_logs/*.log" ,
267+ )
268+ return any (
269+ next (output_dir .glob (pattern ), None ) is not None
270+ for pattern in progress_patterns
271+ )
272+
273+
274+ def _prepare_output_dir (
275+ output_dir : Path ,
276+ * ,
277+ clear_output : bool ,
278+ ) -> None :
279+ if clear_output and output_dir .exists ():
280+ if _has_resume_artifacts (output_dir ):
281+ print (
282+ "clear_output requested, but existing long-run artifacts were "
283+ f"found in { output_dir } ; preserving them for resumable execution. "
284+ "Use a separate explicit Modal volume removal command for an "
285+ "intentional destructive restart." ,
286+ flush = True ,
287+ )
288+ else :
289+ shutil .rmtree (output_dir )
290+ output_dir .mkdir (parents = True , exist_ok = True )
291+
292+
254293def _commit_output_volume (* , suppress_errors : bool = False ) -> None :
255294 try :
256295 output_volume .commit ()
@@ -286,7 +325,7 @@ def build_long_term_projection(
286325 upload_to_hf_staging : bool = False ,
287326 allow_validation_failures : bool = False ,
288327 keep_temp : bool = False ,
289- clear_output : bool = True ,
328+ clear_output : bool = False ,
290329 support_augmentation_profile : str = "" ,
291330 support_augmentation_target_year : int | None = None ,
292331 support_augmentation_align_to_run_year : bool = False ,
@@ -306,9 +345,10 @@ def build_long_term_projection(
306345
307346 run_id = sanitize_run_id (run_id )
308347 output_dir = _OUTPUT_MOUNT / run_id
309- if clear_output and output_dir .exists ():
310- shutil .rmtree (output_dir )
311- output_dir .mkdir (parents = True , exist_ok = True )
348+ _prepare_output_dir (
349+ output_dir ,
350+ clear_output = clear_output ,
351+ )
312352
313353 command = _build_command (
314354 years = years ,
@@ -384,7 +424,7 @@ def main(
384424 upload_to_hf_staging : bool = False ,
385425 allow_validation_failures : bool = False ,
386426 keep_temp : bool = False ,
387- clear_output : bool = True ,
427+ clear_output : bool = False ,
388428 support_augmentation_profile : str = "" ,
389429 support_augmentation_target_year : int | None = None ,
390430 support_augmentation_align_to_run_year : bool = False ,
0 commit comments