Skip to content

Conversation

@code-yeongyu
Copy link
Owner

@code-yeongyu code-yeongyu commented Feb 11, 2026

Problem

oh-my-opencode run exits within ~1.5 seconds of starting because pollForCompletion checks completion too early.

Root Cause

When the agent outputs its first text (e.g. "ULTRAWORK MODE ENABLED!") but hasn't called todowrite yet:

  1. hasReceivedMeaningfulWork = true (text was output)
  2. Session briefly goes idle (agent pausing between reasoning/tool calls)
  3. checkCompletionConditions: 0 todos = "all complete", 0 children = "all idle"
  4. 3 consecutive checks at 500ms = exit 0 in ~1.5s

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.

pollForCompletion loop:
  ... existing gates (idle, tool, work) ...
  NEW: if elapsed < minStabilizationMs since first work → skip completion check
  ... checkCompletionConditions ...

Changes

  • src/cli/run/poll-for-completion.ts: Add MIN_STABILIZATION_MS = 10_000 and firstWorkTimestamp tracking
  • src/cli/run/poll-for-completion.test.ts: Add stabilization period test, update existing tests with minStabilizationMs: 0 where needed

Testing

  • 74 tests pass across 10 files in src/cli/run/
  • New test: "does not check completion during stabilization period after first meaningful work"
  • Existing tests use minStabilizationMs: 0 to opt out of the delay

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@code-yeongyu
Copy link
Owner Author

Superseded by #1783 which fixes the actual root cause: missing directory parameter in client.event.subscribe(). The stabilization period from this PR is included in #1783 as defense-in-depth.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant