fix(cli/run): move error check before idle/tool gates in pollForCompletion

This commit is contained in:
YeonGyu-Kim
2026-02-09 21:11:48 +09:00
parent 096233b23f
commit 564bb20f6a
2 changed files with 58 additions and 10 deletions
+11 -10
View File
@@ -25,16 +25,7 @@ export async function pollForCompletion(
while (!abortController.signal.aborted) {
await new Promise((resolve) => setTimeout(resolve, pollIntervalMs))
if (!eventState.mainSessionIdle) {
consecutiveCompleteChecks = 0
continue
}
if (eventState.currentTool !== null) {
consecutiveCompleteChecks = 0
continue
}
// ERROR CHECK FIRST — errors must not be masked by other gates
if (eventState.mainSessionError) {
console.error(
pc.red(`\n\nSession ended with error: ${eventState.lastError}`)
@@ -45,6 +36,16 @@ export async function pollForCompletion(
return 1
}
if (!eventState.mainSessionIdle) {
consecutiveCompleteChecks = 0
continue
}
if (eventState.currentTool !== null) {
consecutiveCompleteChecks = 0
continue
}
if (!eventState.hasReceivedMeaningfulWork) {
consecutiveCompleteChecks = 0
continue