Skip to content

Commit cfc1ef2

Browse files
committed
fix(workflows): handle step completion states correctly
Ensure proper state transitions when completing steps with chained prompts or when skipping steps. Add missing state machine events and index manager updates for all completion scenarios.
1 parent 146dbef commit cfc1ef2

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/workflows/step/run.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,25 +216,37 @@ export async function runStepFresh(ctx: RunnerContext): Promise<RunStepResult |
216216
session.setOutput(stepOutput);
217217
const loaded = session.loadChainedPrompts(output.chainedPrompts);
218218
if (loaded) {
219+
// Has chained prompts - go to awaiting state
219220
session.markAwaiting();
220221
if (!machineCtx.autoMode) {
221222
ctx.emitter.updateAgentStatus(uniqueAgentId, 'awaiting');
222223
}
224+
ctx.machine.send({ type: 'STEP_COMPLETE', output: stepOutput });
225+
return { output: stepOutput };
223226
} else if (session.promptQueue.length === 0) {
224-
// Truly no prompts - complete the session
227+
// No prompts - complete and go directly to next step
225228
await session.complete();
226229
ctx.emitter.updateAgentStatus(uniqueAgentId, 'completed');
230+
await ctx.indexManager.stepCompleted(stepIndex);
231+
ctx.machine.send({ type: 'SKIP' });
232+
return { output: stepOutput };
227233
}
228-
// If prompts exist but already loaded, no action needed - indexManager has the state
234+
// If prompts exist but already loaded, fall through to STEP_COMPLETE
229235
} else if (output.chainedPrompts && output.chainedPrompts.length > 0) {
230-
// No session - use indexManager directly
236+
// No session but has chained prompts - go to awaiting state
231237
ctx.indexManager.initQueue(output.chainedPrompts, 0);
232238
if (!machineCtx.autoMode) {
233239
ctx.emitter.updateAgentStatus(uniqueAgentId, 'awaiting');
234240
}
241+
ctx.machine.send({ type: 'STEP_COMPLETE', output: stepOutput });
242+
return { output: stepOutput };
235243
} else {
244+
// No session, no chained prompts - go directly to next step
236245
ctx.emitter.updateAgentStatus(uniqueAgentId, 'completed');
237246
ctx.indexManager.resetQueue();
247+
await ctx.indexManager.stepCompleted(stepIndex);
248+
ctx.machine.send({ type: 'SKIP' });
249+
return { output: stepOutput };
238250
}
239251

240252
ctx.machine.send({ type: 'STEP_COMPLETE', output: stepOutput });

0 commit comments

Comments
 (0)