Skip to content

Commit 146dbef

Browse files
committed
fix(workflow): correct token calculation and step completion logic
fix incorrect token calculation by removing cached token subtraction ensure proper step completion handling in loop and checkpoint scenarios
1 parent a2ff046 commit 146dbef

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/cli/tui/routes/workflow/components/output/telemetry-bar.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,13 @@ export function TelemetryBar(props: TelemetryBarProps) {
3838

3939
const totalText = () => {
4040
const cached = props.total.cached ?? 0
41-
const newTokensIn = props.total.tokensIn - cached
42-
const base = formatTokens(newTokensIn, props.total.tokensOut)
41+
const base = formatTokens(props.total.tokensIn, props.total.tokensOut)
4342
return cached > 0 ? `${base} (${formatNumber(cached)} cached)` : base
4443
}
4544

4645
// Compact token display - no "cached" info
4746
const compactTokenText = () => {
48-
const cached = props.total.cached ?? 0
49-
const newTokensIn = props.total.tokensIn - cached
50-
return formatTokens(newTokensIn, props.total.tokensOut)
47+
return formatTokens(props.total.tokensIn, props.total.tokensOut)
5148
}
5249

5350
const showStatus = () => props.status === "awaiting" || props.status === "paused" || props.status === "stopped"

src/workflows/step/run.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,17 +192,20 @@ export async function runStepFresh(ctx: RunnerContext): Promise<RunStepResult |
192192
const targetIndex = postResult.newIndex + 1;
193193
if (targetIndex >= 0 && targetIndex <= stepIndex) {
194194
debug('[step/run] Loop directive: rewinding to step %d', targetIndex);
195+
ctx.emitter.updateAgentStatus(uniqueAgentId, 'completed');
196+
await ctx.indexManager.stepCompleted(stepIndex);
195197
machineCtx.currentStepIndex = targetIndex;
196198
return { output: stepOutput, newIndex: targetIndex };
197199
}
198200
}
199201

200-
// Checkpoint continued - skip chained prompts
202+
// Checkpoint continued - skip chained prompts and go directly to next step
201203
if (postResult.checkpointContinued) {
202204
debug('[step/run] Checkpoint continued, advancing to next step');
203205
ctx.emitter.updateAgentStatus(uniqueAgentId, 'completed');
204206
ctx.indexManager.resetQueue();
205-
ctx.machine.send({ type: 'STEP_COMPLETE', output: stepOutput });
207+
await ctx.indexManager.stepCompleted(stepIndex);
208+
ctx.machine.send({ type: 'SKIP' });
206209
return { output: stepOutput, checkpointContinued: true };
207210
}
208211

0 commit comments

Comments
 (0)