prodigy 0.4.4

Turn ad-hoc Claude sessions into reproducible development pipelines with parallel AI agents
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
//! Workflow resume executor
//!
//! Handles resuming interrupted workflows from checkpoints.

use crate::config::WorkflowConfig;
use crate::cook::execution::ClaudeExecutor;
use crate::cook::interaction::UserInteraction;
use crate::cook::orchestrator::ExecutionEnvironment;
use crate::cook::session::SessionManager;
use crate::cook::workflow::checkpoint::{
    self, CheckpointManager, ResumeOptions, WorkflowCheckpoint,
};
use crate::cook::workflow::checkpoint_errors::CheckpointError;
use crate::cook::workflow::error_recovery::{
    on_failure_to_error_handler, RecoveryAction, ResumeError, ResumeErrorRecovery,
};
use crate::cook::workflow::executor::{
    WorkflowContext, WorkflowExecutor as WorkflowExecutorImpl, WorkflowStep,
};
use crate::cook::workflow::normalized::NormalizedWorkflow;
use crate::cook::workflow::progress::{ExecutionPhase, ProgressDisplay, SequentialProgressTracker};
use anyhow::{anyhow, Context, Result};
use serde_json::Value;
use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::Arc;
use tracing::{error, info, warn};

/// Result of resuming a workflow
#[derive(Debug)]
pub struct ResumeResult {
    /// Whether resume was successful
    pub success: bool,
    /// Total steps executed (including resumed)
    pub total_steps_executed: usize,
    /// Steps that were skipped (already completed)
    pub skipped_steps: usize,
    /// Steps executed in this resume
    pub new_steps_executed: usize,
    /// Final workflow context
    pub final_context: WorkflowContext,
}

/// Executor for resuming workflows from checkpoints
pub struct ResumeExecutor {
    /// Checkpoint manager for loading/saving
    checkpoint_manager: Arc<CheckpointManager>,
    /// Claude executor for commands
    claude_executor: Option<Arc<dyn ClaudeExecutor>>,
    /// Session manager
    session_manager: Option<Arc<dyn SessionManager>>,
    /// User interaction
    user_interaction: Option<Arc<dyn UserInteraction>>,
    /// Error recovery manager
    error_recovery: ResumeErrorRecovery,
}

impl ResumeExecutor {
    /// Create a new resume executor
    pub fn new(checkpoint_manager: Arc<CheckpointManager>) -> Self {
        Self {
            checkpoint_manager,
            claude_executor: None,
            session_manager: None,
            user_interaction: None,
            error_recovery: ResumeErrorRecovery::new(),
        }
    }

    /// Set the executors for workflow execution
    pub fn with_executors(
        mut self,
        claude_executor: Arc<dyn ClaudeExecutor>,
        session_manager: Arc<dyn SessionManager>,
        user_interaction: Arc<dyn UserInteraction>,
    ) -> Self {
        self.claude_executor = Some(claude_executor);
        self.session_manager = Some(session_manager);
        self.user_interaction = Some(user_interaction);
        self
    }

    /// Resume a workflow from checkpoint
    pub async fn resume(
        &mut self,
        workflow_id: &str,
        options: ResumeOptions,
    ) -> Result<ResumeResult> {
        info!("Resuming workflow {}", workflow_id);

        // Load checkpoint to get workflow path
        let checkpoint = self
            .checkpoint_manager
            .load_checkpoint(workflow_id)
            .await
            .context("Failed to load checkpoint")?;

        // Get workflow path from checkpoint or error if not available
        let workflow_path = checkpoint.workflow_path
            .clone()
            .ok_or_else(|| anyhow!(
                "Workflow path not stored in checkpoint. Please use resume_with_path() with explicit path."
            ))?;

        // Check if the workflow file exists
        if !workflow_path.exists() {
            return Err(CheckpointError::workflow_file_not_found(
                workflow_path,
                workflow_id.to_string(),
                Some(checkpoint.timestamp),
            )
            .into());
        }

        // Delegate to execute_from_checkpoint for full execution
        self.execute_from_checkpoint(workflow_id, &workflow_path, options)
            .await
    }

    /// Resume a workflow from checkpoint with explicit workflow path
    /// Use this when the checkpoint doesn't have the workflow path stored (legacy checkpoints)
    pub async fn resume_with_path(
        &mut self,
        workflow_id: &str,
        workflow_path: &PathBuf,
        options: ResumeOptions,
    ) -> Result<ResumeResult> {
        info!(
            "Resuming workflow {} with explicit path {:?}",
            workflow_id, workflow_path
        );

        // Verify the workflow file exists
        if !workflow_path.exists() {
            // Load checkpoint to get timestamp for error message
            let checkpoint = self
                .checkpoint_manager
                .load_checkpoint(workflow_id)
                .await
                .context("Failed to load checkpoint")?;

            return Err(CheckpointError::workflow_file_not_found(
                workflow_path.clone(),
                workflow_id.to_string(),
                Some(checkpoint.timestamp),
            )
            .into());
        }

        // Delegate to execute_from_checkpoint for full execution
        self.execute_from_checkpoint(workflow_id, workflow_path, options)
            .await
    }

    /// Validate checkpoint integrity and compatibility
    fn validate_checkpoint(&self, checkpoint: &WorkflowCheckpoint) -> Result<()> {
        // Check checkpoint version compatibility
        if checkpoint.version > checkpoint::CHECKPOINT_VERSION {
            let checkpoint_path = checkpoint
                .workflow_path
                .clone()
                .unwrap_or_else(|| PathBuf::from("unknown"));

            return Err(CheckpointError::version_mismatch(
                checkpoint.version,
                checkpoint::CHECKPOINT_VERSION,
                checkpoint_path,
                Some(checkpoint.timestamp),
            )
            .into());
        }

        // Validate workflow hash to detect modifications (spec 184 FR6)
        if let Some(ref workflow_path) = checkpoint.workflow_path {
            if workflow_path.exists() {
                // Compute current workflow hash
                let current_workflow_content = std::fs::read_to_string(workflow_path)
                    .context("Failed to read workflow file for hash validation")?;

                use sha2::{Digest, Sha256};
                let current_hash =
                    format!("{:x}", Sha256::digest(current_workflow_content.as_bytes()));

                // Compare with checkpoint hash
                if checkpoint.workflow_hash != current_hash {
                    return Err(CheckpointError::workflow_hash_mismatch(
                        checkpoint.workflow_hash.clone(),
                        current_hash,
                        checkpoint.total_steps,
                        checkpoint.execution_state.total_steps,
                        checkpoint.workflow_id.clone(),
                        workflow_path.clone(),
                        Some(checkpoint.timestamp),
                    )
                    .into());
                }
            } else {
                warn!(
                    "Workflow file not found, skipping hash validation: {:?}",
                    workflow_path
                );
            }
        } else {
            warn!("No workflow path in checkpoint, skipping hash validation");
        }

        // Validate execution state consistency
        if checkpoint.execution_state.current_step_index > checkpoint.execution_state.total_steps {
            return Err(CheckpointError::InvalidCheckpoint {
                reason: format!(
                    "Step index {} exceeds total steps {}",
                    checkpoint.execution_state.current_step_index,
                    checkpoint.execution_state.total_steps
                ),
                session_id: checkpoint.workflow_id.clone(),
            }
            .into());
        }

        // Validate completed steps match current index
        if checkpoint.completed_steps.len() > checkpoint.execution_state.current_step_index {
            return Err(CheckpointError::InvalidCheckpoint {
                reason: format!(
                    "Completed steps count {} exceeds current step index {}",
                    checkpoint.completed_steps.len(),
                    checkpoint.execution_state.current_step_index
                ),
                session_id: checkpoint.workflow_id.clone(),
            }
            .into());
        }

        Ok(())
    }

    /// Restore workflow context from checkpoint
    pub fn restore_workflow_context(
        &self,
        checkpoint: &WorkflowCheckpoint,
    ) -> Result<WorkflowContext> {
        use crate::cook::workflow::variable_checkpoint::VariableResumeManager;

        let mut context = WorkflowContext::default();
        let manager = VariableResumeManager::new();

        // Attempt to restore from enhanced checkpoint state, with automatic migration from legacy
        match self.restore_variables_unified(&manager, &mut context, checkpoint) {
            Ok(()) => {
                info!("Variables restored successfully from checkpoint");
            }
            Err(e) => {
                warn!("Failed to restore variables from checkpoint: {}", e);
                // If unified restoration fails, try to recover with minimal state
                context = WorkflowContext::default();
            }
        }

        Ok(context)
    }

    /// Unified variable restoration that handles both enhanced and legacy checkpoints
    fn restore_variables_unified(
        &self,
        manager: &crate::cook::workflow::variable_checkpoint::VariableResumeManager,
        context: &mut WorkflowContext,
        checkpoint: &WorkflowCheckpoint,
    ) -> Result<()> {
        // Try enhanced checkpoint state first
        if let Some(var_checkpoint_state) = &checkpoint.variable_checkpoint_state {
            info!("Restoring from enhanced checkpoint format");

            // Restore variables from enhanced checkpoint
            let (mut variables, captured_outputs, iteration_vars) = manager
                .restore_from_checkpoint(var_checkpoint_state)
                .context("Failed to restore from enhanced checkpoint")?;

            context.variables = variables.clone();
            context.captured_outputs = captured_outputs;
            context.iteration_vars = iteration_vars;

            // Validate environment compatibility
            if let Ok(compatibility) =
                manager.validate_environment(&var_checkpoint_state.environment_snapshot)
            {
                if !compatibility.is_compatible {
                    warn!("Environment has changed since checkpoint creation");
                    if !compatibility.missing_variables.is_empty() {
                        warn!(
                            "Missing environment variables: {:?}",
                            compatibility.missing_variables.keys().collect::<Vec<_>>()
                        );
                    }
                    if !compatibility.changed_variables.is_empty() {
                        warn!(
                            "Changed environment variables: {:?}",
                            compatibility.changed_variables.keys().collect::<Vec<_>>()
                        );
                    }
                }
            }

            // Restore/recalculate MapReduce variables if applicable
            self.restore_mapreduce_variables(manager, &mut variables, context, checkpoint)?;

            info!(
                "Restored {} variables from enhanced checkpoint",
                context.variables.len()
            );
        } else {
            // Migrate from legacy format
            info!("Migrating from legacy checkpoint format");
            self.migrate_from_legacy_checkpoint(context, checkpoint)?;
        }

        Ok(())
    }

    /// Restore MapReduce variables from checkpoint state
    fn restore_mapreduce_variables(
        &self,
        manager: &crate::cook::workflow::variable_checkpoint::VariableResumeManager,
        variables: &mut HashMap<String, String>,
        context: &mut WorkflowContext,
        checkpoint: &WorkflowCheckpoint,
    ) -> Result<()> {
        if let Some(ref mapreduce_state) = checkpoint.mapreduce_state {
            let total_items = mapreduce_state.total_items;
            let successful_items = mapreduce_state.completed_items.len();
            let failed_items = mapreduce_state.failed_items.len();

            // Recalculate MapReduce aggregate variables
            let mapreduce_vars = manager.recalculate_mapreduce_variables(
                total_items,
                successful_items,
                failed_items,
            );

            // Merge MapReduce variables into context
            for (key, value) in mapreduce_vars {
                variables.insert(key.clone(), value.clone());
                context.variables.insert(key, value);
            }

            // Also restore any saved aggregate variables to ensure consistency
            for (key, value) in &mapreduce_state.aggregate_variables {
                context.variables.insert(key.clone(), value.clone());
            }

            info!(
                "Restored MapReduce variables: total={}, successful={}, failed={}",
                total_items, successful_items, failed_items
            );
        }

        Ok(())
    }

    /// Migrate variables from legacy checkpoint format
    fn migrate_from_legacy_checkpoint(
        &self,
        context: &mut WorkflowContext,
        checkpoint: &WorkflowCheckpoint,
    ) -> Result<()> {
        // Restore variables from legacy format
        for (key, value) in &checkpoint.variable_state {
            match value {
                Value::String(s) => {
                    context.variables.insert(key.clone(), s.clone());
                }
                Value::Number(n) => {
                    context.variables.insert(key.clone(), n.to_string());
                }
                Value::Bool(b) => {
                    context.variables.insert(key.clone(), b.to_string());
                }
                _ => {
                    // For complex values, store as JSON
                    context
                        .variables
                        .insert(key.clone(), serde_json::to_string(value)?);
                }
            }
        }

        // Restore captured outputs from completed steps
        for step in &checkpoint.completed_steps {
            if let Some(ref output) = step.output {
                context
                    .captured_outputs
                    .insert(format!("step_{}", step.step_index), output.clone());

                // Also restore step-specific variables
                for (var_key, var_value) in &step.captured_variables {
                    context.variables.insert(var_key.clone(), var_value.clone());
                }
            }
        }

        info!(
            "Migrated {} variables from legacy checkpoint format",
            context.variables.len()
        );

        Ok(())
    }

    /// Load workflow file from path
    async fn load_workflow_file(workflow_path: &PathBuf) -> Result<WorkflowConfig> {
        let workflow_content = tokio::fs::read_to_string(workflow_path)
            .await
            .context("Failed to read workflow file")?;

        // Parse workflow based on file extension
        let workflow_config: WorkflowConfig = if workflow_path.extension().and_then(|s| s.to_str())
            == Some("yml")
            || workflow_path.extension().and_then(|s| s.to_str()) == Some("yaml")
        {
            serde_yaml::from_str(&workflow_content)?
        } else if workflow_path.extension().and_then(|s| s.to_str()) == Some("json") {
            serde_json::from_str(&workflow_content)?
        } else {
            return Err(anyhow!("Unsupported workflow file format"));
        };

        Ok(workflow_config)
    }

    /// Convert WorkflowCommands to WorkflowSteps
    fn convert_commands_to_steps(
        commands: Vec<crate::config::WorkflowCommand>,
    ) -> Vec<WorkflowStep> {
        commands
            .into_iter()
            .map(|cmd| {
                let mut step = WorkflowStep {
                    name: None,
                    claude: None,
                    shell: None,
                    test: None,
                    foreach: None,
                    write_file: None,
                    command: None,
                    handler: None,
                    capture: None,
                    capture_format: None,
                    capture_streams: Default::default(),
                    output_file: None,
                    capture_output: crate::cook::workflow::executor::CaptureOutput::Disabled,
                    timeout: None,
                    working_dir: None,
                    env: std::collections::HashMap::new(),
                    on_failure: None,
                    retry: None,
                    on_success: None,
                    on_exit_code: std::collections::HashMap::new(),
                    auto_commit: false,
                    commit_config: None,
                    commit_required: false,
                    validate: None,
                    step_validate: None,
                    skip_validation: false,
                    validation_timeout: None,
                    ignore_validation_failure: false,
                    when: None,
                };

                // Parse command based on enum variant
                match cmd {
                    crate::config::WorkflowCommand::Simple(cmd_str) => {
                        if cmd_str.starts_with("claude:") {
                            step.claude =
                                Some(cmd_str.strip_prefix("claude:").unwrap().trim().to_string());
                        } else if cmd_str.starts_with("shell:") {
                            step.shell =
                                Some(cmd_str.strip_prefix("shell:").unwrap().trim().to_string());
                        } else if !cmd_str.contains(':') {
                            // Default to shell if no prefix
                            step.shell = Some(cmd_str);
                        } else {
                            // Treat as legacy command
                            step.command = Some(cmd_str);
                        }
                    }
                    crate::config::WorkflowCommand::WorkflowStep(wf_step) => {
                        step.claude = wf_step.claude;
                        step.shell = wf_step.shell;
                        // Convert TestDebugConfig to OnFailureConfig
                        if let Some(test_debug) = wf_step.on_failure {
                            // Create a HandlerCommand from the TestDebugConfig
                            let handler_cmd = crate::cook::workflow::on_failure::HandlerCommand {
                                claude: Some(test_debug.claude),
                                shell: None,
                                continue_on_error: false,
                            };

                            step.on_failure = Some(crate::cook::workflow::on_failure::OnFailureConfig::Detailed(
                                crate::cook::workflow::on_failure::FailureHandlerConfig {
                                    commands: vec![handler_cmd],
                                    strategy: crate::cook::workflow::on_failure::HandlerStrategy::default(),
                                    timeout: None,
                                    capture: std::collections::HashMap::new(),
                                    fail_workflow: test_debug.fail_workflow,
                                    handler_failure_fatal: false,
                                }
                            ));
                        }
                        // Copy other fields if they exist
                    }
                    _ => {
                        // For other variants, try to convert to a command string
                        step.command = Some(format!("{:?}", cmd));
                    }
                }

                step
            })
            .collect()
    }

    /// Build ExtendedWorkflowConfig from checkpoint and steps
    fn build_extended_workflow(
        checkpoint: &WorkflowCheckpoint,
        steps: Vec<WorkflowStep>,
    ) -> crate::cook::workflow::executor::ExtendedWorkflowConfig {
        crate::cook::workflow::executor::ExtendedWorkflowConfig {
            name: checkpoint
                .workflow_name
                .clone()
                .unwrap_or_else(|| "resumed".to_string()),
            steps,
            mode: crate::cook::workflow::executor::WorkflowMode::Sequential,
            max_iterations: 1,
            iterate: false,
            setup_phase: None,    // Not a MapReduce workflow
            map_phase: None,      // Not a MapReduce workflow
            reduce_phase: None,   // Not a MapReduce workflow
            retry_defaults: None, // Would need to be loaded from checkpoint
            environment: None,    // Would need to be loaded from checkpoint
        }
    }

    /// Create progress tracker for resume
    fn create_progress_tracker(
        checkpoint: &WorkflowCheckpoint,
        workflow_id: &str,
    ) -> SequentialProgressTracker {
        let total_steps = checkpoint.total_steps;
        let skipped_steps = checkpoint.completed_steps.len();
        let current_iteration = checkpoint.execution_state.current_iteration.unwrap_or(1);
        let max_iterations = checkpoint.execution_state.total_iterations.unwrap_or(1);

        SequentialProgressTracker::for_resume(
            workflow_id.to_string(),
            checkpoint
                .workflow_name
                .clone()
                .unwrap_or_else(|| workflow_id.to_string()),
            total_steps,
            max_iterations,
            skipped_steps,
            current_iteration,
        )
    }

    /// Initialize progress display with initial phase
    async fn initialize_progress_display(
        progress_tracker: &mut SequentialProgressTracker,
        progress_display: &mut ProgressDisplay,
        workflow_id: &str,
    ) {
        progress_tracker
            .update_phase(ExecutionPhase::LoadingCheckpoint)
            .await;
        progress_display.force_update(&format!("Loading checkpoint for workflow {}", workflow_id));
    }

    /// Build execution environment for workflow
    fn build_execution_environment(
        workflow_path: &std::path::Path,
        workflow_id: &str,
    ) -> ExecutionEnvironment {
        ExecutionEnvironment {
            working_dir: Arc::new(
                workflow_path
                    .parent()
                    .unwrap_or_else(|| std::path::Path::new("."))
                    .to_path_buf(),
            ),
            project_dir: Arc::new(
                workflow_path
                    .parent()
                    .unwrap_or_else(|| std::path::Path::new("."))
                    .to_path_buf(),
            ),
            worktree_name: None,
            session_id: Arc::from(format!("resume-{}", workflow_id)),
        }
    }

    /// Check if workflow is already completed
    fn check_already_completed(
        checkpoint: &WorkflowCheckpoint,
        options: &ResumeOptions,
        workflow_id: &str,
    ) -> Result<Option<ResumeResult>> {
        if checkpoint.execution_state.status == checkpoint::WorkflowStatus::Completed
            && !options.force
        {
            println!(
                "Workflow {} is already completed - nothing to resume",
                workflow_id
            );
            return Ok(Some(ResumeResult {
                success: true,
                total_steps_executed: checkpoint.execution_state.current_step_index,
                skipped_steps: checkpoint.execution_state.current_step_index,
                new_steps_executed: 0,
                final_context: WorkflowContext::default(),
            }));
        }
        Ok(None)
    }

    /// Display completion summary
    fn display_completion_summary(
        total_steps: usize,
        skipped_steps: usize,
        steps_executed: usize,
        start_time: std::time::Instant,
    ) {
        let total_duration = start_time.elapsed();
        println!("\n✅ Workflow Resume Complete!");
        println!("   Total steps: {}", total_steps);
        println!("   Steps skipped (already completed): {}", skipped_steps);
        println!("   Steps executed in this session: {}", steps_executed);
        println!("   Total duration: {:.2}s", total_duration.as_secs_f64());
        if steps_executed > 0 {
            let avg_step_time = total_duration.as_secs_f64() / steps_executed as f64;
            println!("   Average step time: {:.2}s", avg_step_time);
        }
    }

    /// Process a recovery action and return the outcome
    ///
    /// Handles all recovery action types: Retry, Continue, SafeAbort, Fallback,
    /// PartialResume, and RequestIntervention.
    #[allow(clippy::too_many_arguments)]
    async fn process_recovery_action(
        &mut self,
        recovery_action: RecoveryAction,
        step: &WorkflowStep,
        step_index: usize,
        executor: &mut WorkflowExecutorImpl,
        env: &ExecutionEnvironment,
        workflow_context: &mut WorkflowContext,
        progress_tracker: &mut SequentialProgressTracker,
        workflow_id: &str,
    ) -> Result<RecoveryOutcome> {
        match recovery_action {
            RecoveryAction::Retry { delay, .. } => {
                warn!("Retrying step {} after {:?}", step_index + 1, delay);
                tokio::time::sleep(delay).await;
                Ok(RecoveryOutcome::Retry(Box::new(step.clone())))
            }
            RecoveryAction::Continue => {
                warn!("Continuing despite error in step {}", step_index + 1);
                Ok(RecoveryOutcome::Continue)
            }
            RecoveryAction::SafeAbort { cleanup_actions } => {
                error!("Aborting workflow due to unrecoverable error");

                // Execute cleanup actions if any
                if !cleanup_actions.is_empty() {
                    info!(
                        "Executing {} cleanup actions before abort",
                        cleanup_actions.len()
                    );
                    for action in cleanup_actions {
                        let cleanup_step = build_cleanup_step(&action);
                        let _ = executor
                            .execute_step(&cleanup_step, env, workflow_context)
                            .await;
                    }
                }

                Ok(RecoveryOutcome::Abort(anyhow!(
                    "Workflow aborted due to unrecoverable error"
                )))
            }
            RecoveryAction::Fallback { alternative_path } => {
                warn!("Attempting fallback path: {}", alternative_path);
                // Load alternative workflow configuration from file
                let alt_path = std::path::Path::new(&alternative_path);
                let content = tokio::fs::read_to_string(&alt_path)
                    .await
                    .map_err(|err| anyhow!("Failed to read fallback workflow file: {}", err))?;

                let alt_config: WorkflowConfig = serde_yaml::from_str(&content)
                    .map_err(|err| anyhow!("Failed to parse fallback workflow: {}", err))?;

                // Convert to normalized workflow
                let _alt_workflow = NormalizedWorkflow::from_workflow_config(
                    &alt_config,
                    crate::cook::workflow::normalized::ExecutionMode::Sequential,
                )?;

                // Execute the fallback workflow from the current step
                info!("Executing fallback workflow from step {}", step_index);
                // Note: This would need more implementation to properly merge contexts
                // For now, we'll just continue with the current workflow
                warn!("Fallback workflow execution not fully implemented, continuing with current workflow");
                Ok(RecoveryOutcome::Continue)
            }
            RecoveryAction::PartialResume { from_step } => {
                warn!("Performing partial resume from step {}", from_step);
                // Jump to the specified step
                if from_step < step_index {
                    // We've already passed this step, continue normally
                    Ok(RecoveryOutcome::Continue)
                } else if from_step > step_index {
                    // Skip ahead to the specified step
                    for i in step_index..from_step {
                        progress_tracker
                            .skip_step(i, "Skipping to recovery point".to_string())
                            .await;
                    }
                    Ok(RecoveryOutcome::Continue)
                } else {
                    // If from_step == step_index, just continue normally
                    Ok(RecoveryOutcome::Continue)
                }
            }
            RecoveryAction::RequestIntervention { message } => {
                error!("Manual intervention required: {}", message);

                // Save checkpoint with intervention request
                self.checkpoint_manager
                    .save_intervention_request(workflow_id, &message)
                    .await?;

                Ok(RecoveryOutcome::RequiresIntervention(message))
            }
        }
    }

    /// Execute a single workflow step with progress tracking
    ///
    /// Handles progress display updates and timing for step execution.
    #[allow(clippy::too_many_arguments)]
    async fn execute_single_step(
        executor: &mut WorkflowExecutorImpl,
        step: &WorkflowStep,
        step_index: usize,
        total_steps: usize,
        env: &ExecutionEnvironment,
        workflow_context: &mut WorkflowContext,
        progress_tracker: &mut SequentialProgressTracker,
        progress_display: &mut ProgressDisplay,
    ) -> Result<StepExecutionResult> {
        // Get step name for progress display
        let step_name = get_step_name(step);

        info!(
            "Executing step {}/{}: {}",
            step_index + 1,
            total_steps,
            step_name
        );

        // Start step in progress tracker
        progress_tracker
            .start_step(step_index, step_name.clone())
            .await;

        // Update progress display
        let progress_msg = progress_tracker.format_progress().await;
        progress_display.update(&progress_msg);

        // Execute the step with timing
        let step_start = std::time::Instant::now();
        let result = executor.execute_step(step, env, workflow_context).await;
        let duration = step_start.elapsed();

        // Update progress tracker based on result
        match &result {
            Ok(_) => {
                info!("Step {} completed successfully", step_index + 1);
                progress_tracker.complete_step(step_index, duration).await;
                Ok(StepExecutionResult {
                    success: true,
                    duration,
                })
            }
            Err(e) => {
                warn!("Step {} failed: {}", step_index + 1, e);
                progress_tracker.fail_step(step_index, e.to_string()).await;
                result.map(|_| StepExecutionResult {
                    success: false,
                    duration,
                })
            }
        }
    }

    /// Execute error handler for a failed step
    ///
    /// Returns the outcome of error handler execution:
    /// - Recovered: Handler succeeded, workflow can continue
    /// - Failed: Handler failed but workflow may continue based on configuration
    /// - NoHandler: No handler was configured
    async fn execute_step_error_handler(
        &mut self,
        step: &WorkflowStep,
        step_index: usize,
        error_msg: &str,
        workflow_context: &mut WorkflowContext,
    ) -> Result<ErrorHandlerOutcome> {
        // Check if step has error handler
        if let Some(ref on_failure) = step.on_failure {
            info!("Executing error handler for step {}", step_index + 1);

            // Convert OnFailureConfig to ErrorHandler
            if let Some(handler) = on_failure_to_error_handler(on_failure, step_index) {
                // Execute error handler with resume context
                match self
                    .error_recovery
                    .execute_error_handler_with_resume_context(
                        &handler,
                        error_msg,
                        workflow_context,
                    )
                    .await
                {
                    Ok(true) => {
                        info!("Error handler succeeded, continuing workflow");
                        return Ok(ErrorHandlerOutcome::Recovered);
                    }
                    Ok(false) => {
                        warn!("Error handler failed for step {}", step_index + 1);
                        if !on_failure.should_fail_workflow() {
                            warn!("Continuing despite handler failure");
                            return Ok(ErrorHandlerOutcome::Failed);
                        }
                    }
                    Err(handler_err) => {
                        error!("Error executing handler: {}", handler_err);
                    }
                }
            }
        }

        Ok(ErrorHandlerOutcome::NoHandler)
    }

    /// Execute remaining workflow steps from checkpoint
    #[allow(clippy::too_many_arguments)]
    async fn execute_remaining_steps(
        &mut self,
        executor: &mut WorkflowExecutorImpl,
        extended_workflow: &crate::cook::workflow::executor::ExtendedWorkflowConfig,
        start_from: usize,
        env: &ExecutionEnvironment,
        workflow_context: &mut WorkflowContext,
        progress_tracker: &mut SequentialProgressTracker,
        progress_display: &mut ProgressDisplay,
        checkpoint: &WorkflowCheckpoint,
        workflow_id: &str,
    ) -> Result<usize> {
        let total_steps = extended_workflow.steps.len();
        let skipped_steps = checkpoint.completed_steps.len();
        let current_iteration = checkpoint.execution_state.current_iteration.unwrap_or(1);
        let mut steps_executed = 0;

        info!(
            "Resuming execution from step {} of {}",
            start_from + 1,
            total_steps
        );

        // Update progress to executing phase
        progress_tracker
            .update_phase(ExecutionPhase::ExecutingSteps)
            .await;
        progress_display.force_update(&format!(
            "Resuming from step {}/{}. {} steps already completed.",
            start_from + 1,
            total_steps,
            skipped_steps
        ));

        // Set progress callback to display updates
        progress_tracker.set_callback(move |update| {
            if let Some(ref msg) = update.message {
                println!("📊 {}", msg);
            }
        });

        // Start iteration tracking if needed
        if current_iteration > 0 {
            progress_tracker.start_iteration(current_iteration).await;
        }

        // Skip completed steps and execute remaining ones
        for (step_index, step) in extended_workflow.steps.iter().enumerate() {
            if step_index < start_from {
                info!("Skipping completed step {}: {:?}", step_index + 1, step);
                progress_tracker
                    .skip_step(step_index, "Already completed from checkpoint".to_string())
                    .await;
                continue;
            }

            // Execute the step with progress tracking
            match Self::execute_single_step(
                executor,
                step,
                step_index,
                total_steps,
                env,
                workflow_context,
                progress_tracker,
                progress_display,
            )
            .await
            {
                Ok(_result) => {
                    steps_executed += 1;
                    continue;
                }
                Err(e) => {
                    // Execute error handler if configured
                    match self
                        .execute_step_error_handler(
                            step,
                            step_index,
                            &e.to_string(),
                            workflow_context,
                        )
                        .await?
                    {
                        ErrorHandlerOutcome::Recovered => {
                            steps_executed += 1;
                            continue; // Continue to next step
                        }
                        ErrorHandlerOutcome::Failed => {
                            continue; // Continue despite handler failure
                        }
                        ErrorHandlerOutcome::NoHandler => {
                            // No handler, proceed to recovery action
                        }
                    }

                    // No handler or handler failed - attempt recovery
                    let recovery_action = self
                        .error_recovery
                        .handle_resume_error(&ResumeError::Other(anyhow!("{}", e)), checkpoint)
                        .await?;

                    // Process the recovery action
                    match self
                        .process_recovery_action(
                            recovery_action,
                            step,
                            step_index,
                            executor,
                            env,
                            workflow_context,
                            progress_tracker,
                            workflow_id,
                        )
                        .await?
                    {
                        RecoveryOutcome::Retry(retry_step) => {
                            // Retry the step
                            match executor
                                .execute_step(&retry_step, env, workflow_context)
                                .await
                            {
                                Ok(_) => {
                                    info!("Retry succeeded for step {}", step_index + 1);
                                    steps_executed += 1;
                                    continue;
                                }
                                Err(retry_err) => {
                                    error!(
                                        "Retry failed for step {}: {}",
                                        step_index + 1,
                                        retry_err
                                    );
                                    return Err(retry_err);
                                }
                            }
                        }
                        RecoveryOutcome::Continue => {
                            continue;
                        }
                        RecoveryOutcome::Abort(abort_err) => {
                            return Err(abort_err);
                        }
                        RecoveryOutcome::RequiresIntervention(message) => {
                            return Err(anyhow!(
                                "Workflow suspended for manual intervention: {}. Resume with 'prodigy resume {}' after resolving.",
                                message,
                                workflow_id
                            ));
                        }
                    }
                }
            }
        }

        Ok(steps_executed)
    }

    /// Execute workflow from checkpoint with full execution support
    pub async fn execute_from_checkpoint(
        &mut self,
        workflow_id: &str,
        workflow_path: &PathBuf,
        options: ResumeOptions,
    ) -> Result<ResumeResult> {
        // Ensure we have executors
        let claude_executor = self
            .claude_executor
            .as_ref()
            .ok_or_else(|| anyhow!("Claude executor not configured for resume"))?;
        let session_manager = self
            .session_manager
            .as_ref()
            .ok_or_else(|| anyhow!("Session manager not configured for resume"))?;
        let user_interaction = self
            .user_interaction
            .as_ref()
            .ok_or_else(|| anyhow!("User interaction not configured for resume"))?;

        info!("Executing workflow {} from checkpoint", workflow_id);

        // Load checkpoint
        let checkpoint = self
            .checkpoint_manager
            .load_checkpoint(workflow_id)
            .await
            .context("Failed to load checkpoint")?;

        // Validate checkpoint
        if !options.skip_validation {
            self.validate_checkpoint(&checkpoint)?;
        }

        // Check if already completed
        if let Some(result) = Self::check_already_completed(&checkpoint, &options, workflow_id)? {
            return Ok(result);
        }

        // Create progress tracker and display
        let mut progress_tracker = Self::create_progress_tracker(&checkpoint, workflow_id);
        let mut progress_display = ProgressDisplay::new();
        Self::initialize_progress_display(
            &mut progress_tracker,
            &mut progress_display,
            workflow_id,
        )
        .await;

        // Load the workflow file
        progress_tracker
            .update_phase(ExecutionPhase::RestoringState)
            .await;
        progress_display.force_update("Loading workflow file and restoring state...");

        let workflow_config = Self::load_workflow_file(workflow_path).await?;
        let steps = Self::convert_commands_to_steps(workflow_config.commands);
        let extended_workflow = Self::build_extended_workflow(&checkpoint, steps);
        let env = Self::build_execution_environment(workflow_path, workflow_id);

        // Restore workflow context
        let mut workflow_context = self.restore_workflow_context(&checkpoint)?;

        // Create workflow executor with checkpoint support
        let mut executor = WorkflowExecutorImpl::new(
            claude_executor.clone(),
            session_manager.clone(),
            user_interaction.clone(),
        )
        .with_workflow_path(workflow_path.clone())
        .with_checkpoint_manager(self.checkpoint_manager.clone(), workflow_id.to_string());

        // Execute remaining steps
        let start_from = checkpoint.execution_state.current_step_index;
        let total_steps = extended_workflow.steps.len();
        let steps_executed = self
            .execute_remaining_steps(
                &mut executor,
                &extended_workflow,
                start_from,
                &env,
                &mut workflow_context,
                &mut progress_tracker,
                &mut progress_display,
                &checkpoint,
                workflow_id,
            )
            .await?;

        // Update progress to completed
        progress_tracker
            .update_phase(ExecutionPhase::Completed)
            .await;
        let final_progress = progress_tracker.format_progress().await;
        progress_display.force_update(&final_progress);

        // Show final summary
        Self::display_completion_summary(
            total_steps,
            start_from,
            steps_executed,
            progress_tracker.start_time,
        );

        // Delete checkpoint on successful completion
        self.checkpoint_manager
            .delete_checkpoint(workflow_id)
            .await?;

        info!(
            "Workflow {} completed successfully. Executed {} new steps.",
            workflow_id, steps_executed
        );

        Ok(ResumeResult {
            success: true,
            total_steps_executed: total_steps,
            skipped_steps: start_from,
            new_steps_executed: steps_executed,
            final_context: workflow_context,
        })
    }
}

/// List all resumable workflows
pub async fn list_resumable_workflows(checkpoint_dir: PathBuf) -> Result<Vec<ResumableWorkflow>> {
    use crate::cook::workflow::checkpoint_path::CheckpointStorage;

    #[allow(deprecated)]
    let manager = CheckpointManager::with_storage(CheckpointStorage::Local(checkpoint_dir));
    let workflow_ids = manager.list_checkpoints().await?;

    let mut resumable = Vec::new();
    for workflow_id in workflow_ids {
        if let Ok(checkpoint) = manager.load_checkpoint(&workflow_id).await {
            resumable.push(ResumableWorkflow {
                workflow_id,
                status: format!("{:?}", checkpoint.execution_state.status),
                progress: format!(
                    "{}/{}",
                    checkpoint.execution_state.current_step_index,
                    checkpoint.execution_state.total_steps
                ),
                last_checkpoint: checkpoint.timestamp,
                can_resume: checkpoint.execution_state.status
                    != checkpoint::WorkflowStatus::Completed,
            });
        }
    }

    Ok(resumable)
}

/// Information about a resumable workflow
#[derive(Debug)]
pub struct ResumableWorkflow {
    pub workflow_id: String,
    pub status: String,
    pub progress: String,
    pub last_checkpoint: chrono::DateTime<chrono::Utc>,
    pub can_resume: bool,
}

/// Result of executing an error handler
#[derive(Debug)]
enum ErrorHandlerOutcome {
    /// Handler succeeded, workflow can continue
    Recovered,
    /// Handler failed but workflow should continue anyway
    Failed,
    /// No handler was configured
    NoHandler,
}

/// Result of processing a recovery action
#[derive(Debug)]
enum RecoveryOutcome {
    /// Retry the current step
    Retry(Box<WorkflowStep>),
    /// Continue to next step
    Continue,
    /// Abort workflow with error
    Abort(anyhow::Error),
    /// Requires manual intervention
    RequiresIntervention(String),
}

/// Result of executing a single workflow step
#[derive(Debug)]
#[allow(dead_code)]
struct StepExecutionResult {
    /// Whether the step succeeded
    success: bool,
    /// How long the step took to execute
    duration: std::time::Duration,
}

/// Helper function to get a display name for a workflow step
fn get_step_name(step: &crate::cook::workflow::executor::WorkflowStep) -> String {
    if let Some(ref name) = step.name {
        name.clone()
    } else if let Some(ref claude) = step.claude {
        format!("claude: {}", claude)
    } else if let Some(ref shell) = step.shell {
        format!("shell: {}", shell)
    } else if let Some(ref cmd) = step.command {
        cmd.clone()
    } else {
        "unnamed step".to_string()
    }
}

/// Build a cleanup workflow step from a handler command
///
/// This is a pure function that constructs a WorkflowStep for cleanup actions,
/// typically used during SafeAbort recovery actions.
fn build_cleanup_step(action: &crate::cook::workflow::on_failure::HandlerCommand) -> WorkflowStep {
    WorkflowStep {
        name: Some("cleanup".to_string()),
        shell: action.shell.clone(),
        claude: action.claude.clone(),
        test: None,
        foreach: None,
        write_file: None,
        command: None,
        handler: None,
        capture: None,
        capture_format: None,
        capture_streams: Default::default(),
        output_file: None,
        timeout: None,
        capture_output: crate::cook::workflow::executor::CaptureOutput::Disabled,
        on_failure: None,
        retry: None,
        on_success: None,
        on_exit_code: Default::default(),
        commit_required: false,
        auto_commit: false,
        commit_config: None,
        working_dir: None,
        env: Default::default(),
        validate: None,
        step_validate: None,
        skip_validation: false,
        validation_timeout: None,
        ignore_validation_failure: false,
        when: None,
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use tempfile::TempDir;
    use tokio;

    #[tokio::test]
    async fn test_resume_with_workflow_path_in_checkpoint() {
        let temp_dir = TempDir::new().unwrap();
        let checkpoint_dir = temp_dir.path().join("checkpoints");
        tokio::fs::create_dir_all(&checkpoint_dir).await.unwrap();

        // Create a test workflow file
        let workflow_path = temp_dir.path().join("test.yml");
        tokio::fs::write(&workflow_path, "name: test\nsteps:\n  - shell: echo test")
            .await
            .unwrap();

        // Create a checkpoint with workflow path
        let checkpoint = WorkflowCheckpoint {
            workflow_id: "test-workflow".to_string(),
            workflow_path: Some(workflow_path.clone()),
            execution_state: checkpoint::ExecutionState {
                current_step_index: 0,
                total_steps: 1,
                status: checkpoint::WorkflowStatus::Interrupted,
                start_time: chrono::Utc::now(),
                last_checkpoint: chrono::Utc::now(),
                current_iteration: None,
                total_iterations: None,
            },
            completed_steps: Vec::new(),
            variable_state: HashMap::new(),
            mapreduce_state: None,
            timestamp: chrono::Utc::now(),
            variable_checkpoint_state: None,
            version: checkpoint::CHECKPOINT_VERSION,
            workflow_hash: "test-hash".to_string(),
            total_steps: 1,
            workflow_name: Some("test".to_string()),
            error_recovery_state: None,
            retry_checkpoint_state: None,
        };

        // Save checkpoint
        #[allow(deprecated)]
        let checkpoint_manager = Arc::new(CheckpointManager::new(checkpoint_dir));
        checkpoint_manager
            .save_checkpoint(&checkpoint)
            .await
            .unwrap();

        // Create resume executor
        let mut executor = ResumeExecutor::new(checkpoint_manager.clone());

        // Test resume - should succeed with workflow path from checkpoint
        let options = ResumeOptions::default();
        let result = executor.resume("test-workflow", options).await;

        // Should fail because we don't have executors set up, but it should get past the workflow path check
        assert!(result.is_err());
        let error_msg = result.unwrap_err().to_string();
        assert!(
            error_msg.contains("executor not configured")
                || error_msg.contains("not configured for resume")
        );
    }

    #[tokio::test]
    async fn test_resume_without_workflow_path_in_checkpoint() {
        let temp_dir = TempDir::new().unwrap();
        let checkpoint_dir = temp_dir.path().join("checkpoints");
        tokio::fs::create_dir_all(&checkpoint_dir).await.unwrap();

        // Create a checkpoint WITHOUT workflow path (legacy checkpoint)
        let checkpoint = WorkflowCheckpoint {
            workflow_id: "legacy-workflow".to_string(),
            workflow_path: None, // No workflow path stored
            execution_state: checkpoint::ExecutionState {
                current_step_index: 0,
                total_steps: 1,
                status: checkpoint::WorkflowStatus::Interrupted,
                start_time: chrono::Utc::now(),
                last_checkpoint: chrono::Utc::now(),
                current_iteration: None,
                total_iterations: None,
            },
            completed_steps: Vec::new(),
            variable_state: HashMap::new(),
            mapreduce_state: None,
            timestamp: chrono::Utc::now(),
            variable_checkpoint_state: None,
            version: checkpoint::CHECKPOINT_VERSION,
            workflow_hash: "test-hash".to_string(),
            total_steps: 1,
            workflow_name: Some("test".to_string()),
            error_recovery_state: None,
            retry_checkpoint_state: None,
        };

        // Save checkpoint
        #[allow(deprecated)]
        let checkpoint_manager = Arc::new(CheckpointManager::new(checkpoint_dir));
        checkpoint_manager
            .save_checkpoint(&checkpoint)
            .await
            .unwrap();

        // Create resume executor
        let mut executor = ResumeExecutor::new(checkpoint_manager.clone());

        // Test resume without path - should fail with helpful error
        let options = ResumeOptions::default();
        let result = executor.resume("legacy-workflow", options).await;

        assert!(result.is_err());
        let error_msg = result.unwrap_err().to_string();
        assert!(error_msg.contains("resume_with_path"));
    }

    #[tokio::test]
    async fn test_resume_with_path_explicit() {
        let temp_dir = TempDir::new().unwrap();
        let checkpoint_dir = temp_dir.path().join("checkpoints");
        tokio::fs::create_dir_all(&checkpoint_dir).await.unwrap();

        // Create a test workflow file
        let workflow_path = temp_dir.path().join("test.yml");
        tokio::fs::write(&workflow_path, "name: test\nsteps:\n  - shell: echo test")
            .await
            .unwrap();

        // Create a checkpoint WITHOUT workflow path
        let checkpoint = WorkflowCheckpoint {
            workflow_id: "explicit-path-workflow".to_string(),
            workflow_path: None,
            execution_state: checkpoint::ExecutionState {
                current_step_index: 0,
                total_steps: 1,
                status: checkpoint::WorkflowStatus::Interrupted,
                start_time: chrono::Utc::now(),
                last_checkpoint: chrono::Utc::now(),
                current_iteration: None,
                total_iterations: None,
            },
            completed_steps: Vec::new(),
            variable_state: HashMap::new(),
            mapreduce_state: None,
            timestamp: chrono::Utc::now(),
            variable_checkpoint_state: None,
            version: checkpoint::CHECKPOINT_VERSION,
            workflow_hash: "test-hash".to_string(),
            total_steps: 1,
            workflow_name: Some("test".to_string()),
            error_recovery_state: None,
            retry_checkpoint_state: None,
        };

        // Save checkpoint
        #[allow(deprecated)]
        let checkpoint_manager = Arc::new(CheckpointManager::new(checkpoint_dir));
        checkpoint_manager
            .save_checkpoint(&checkpoint)
            .await
            .unwrap();

        // Create resume executor
        let mut executor = ResumeExecutor::new(checkpoint_manager.clone());

        // Test resume_with_path - should work with explicit path
        let options = ResumeOptions::default();
        let result = executor
            .resume_with_path("explicit-path-workflow", &workflow_path, options)
            .await;

        // Should fail because we don't have executors set up, but it should get past the workflow path check
        assert!(result.is_err());
        let error_msg = result.unwrap_err().to_string();
        assert!(
            error_msg.contains("executor not configured")
                || error_msg.contains("not configured for resume")
        );
    }
}