Skip to content

Commit 0e64cb2

Browse files
committed
refactor(workflows): improve step resume logic with fallback priority
Add fallback to resume after last completed step when no incomplete chains or notCompletedSteps exist
1 parent ae1495b commit 0e64cb2

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/shared/workflows/steps.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ export async function clearNotCompletedSteps(cmRoot: string): Promise<void> {
296296

297297
/**
298298
* Gets the resume starting index.
299-
* First checks for incomplete chains, then falls back to notCompletedSteps.
299+
* Priority: incomplete chains > notCompletedSteps > after last completed step > 0
300300
*/
301301
export async function getResumeStartIndex(cmRoot: string): Promise<number> {
302302
const { data } = await readTrackingData(cmRoot);
@@ -312,10 +312,23 @@ export async function getResumeStartIndex(cmRoot: string): Promise<number> {
312312
return chainResumeInfo.stepIndex;
313313
}
314314

315-
// Fall back to notCompletedSteps
315+
// Check notCompletedSteps (crash recovery)
316316
if (data.notCompletedSteps && data.notCompletedSteps.length > 0) {
317317
return Math.min(...data.notCompletedSteps);
318318
}
319319

320+
// Check completedSteps - if all steps done, start after the last one
321+
const completedSteps = data.completedSteps as Record<string, StepData>;
322+
if (completedSteps && typeof completedSteps === 'object') {
323+
const completedIndices = Object.entries(completedSteps)
324+
.filter(([, stepData]) => stepData.completedAt !== undefined)
325+
.map(([key]) => parseInt(key, 10));
326+
327+
if (completedIndices.length > 0) {
328+
// Return index after the highest completed step
329+
return Math.max(...completedIndices) + 1;
330+
}
331+
}
332+
320333
return 0;
321334
}

0 commit comments

Comments
 (0)