fix(run): prevent early exit when no todos exist yet #1757
Closed
+59
−14
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
oh-my-opencode runexits within ~1.5 seconds of starting becausepollForCompletionchecks completion too early.Root Cause
When the agent outputs its first text (e.g. "ULTRAWORK MODE ENABLED!") but hasn't called
todowriteyet:hasReceivedMeaningfulWork= true (text was output)checkCompletionConditions: 0 todos = "all complete", 0 children = "all idle"Note: Todo 0 = "all complete" is correct behavior — some agents don't use todos. The issue is timing, not completion semantics.
Fix
Add a minimum stabilization period (10 seconds, configurable) after the first meaningful work before checking completion conditions. This gives agents time to create todos and spawn child sessions without changing what "complete" means.
Changes
src/cli/run/poll-for-completion.ts: AddMIN_STABILIZATION_MS = 10_000andfirstWorkTimestamptrackingsrc/cli/run/poll-for-completion.test.ts: Add stabilization period test, update existing tests withminStabilizationMs: 0where neededTesting
src/cli/run/minStabilizationMs: 0to opt out of the delay