fix(run): prevent early exit when no todos exist yet#1757
Closed
code-yeongyu wants to merge 1 commit intodevfrom
Closed
fix(run): prevent early exit when no todos exist yet#1757code-yeongyu wants to merge 1 commit intodevfrom
code-yeongyu wants to merge 1 commit intodevfrom
Conversation
There was a problem hiding this comment.
No issues found across 3 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Requires human review: Test changes modify expected behavior (returns false instead of true for empty todos) and add new test data requirements. Cannot be 100% sure no regressions without verifying test logic matches meant:
oh-my-opencode run exits within ~1.5s of starting because pollForCompletion checks completion too early. When the agent outputs its first text but hasn't created todos yet, the empty state (0 todos, 0 children) passes all checks. Root cause timeline: 1. promptAsync fires 2. Agent outputs text (e.g. 'ULTRAWORK MODE ENABLED!') -> hasReceivedMeaningfulWork = true 3. Agent pauses before todowrite -> session briefly goes idle 4. pollForCompletion: idle=true, tool=null, work=true -> checkCompletionConditions 5. 0 todos = 'all complete', 0 children = 'all idle' -> true 6. 3 consecutive checks (1.5s) -> premature exit 0 Fix: Add a minimum stabilization period (10s) after the first meaningful work before checking completion conditions. This gives agents time to create todos and spawn child sessions. The period is configurable via PollOptions for tests. Note: todo 0 remaining 'all complete' is correct behavior — some agents don't use todos. The stabilization period is the proper fix, not changing completion semantics.
39fc3ed to
5c2a215
Compare
Owner
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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