Skip to content

Conversation

@code-yeongyu
Copy link
Owner

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

Problem

oh-my-opencode run fails to receive session-scoped SSE events from the OpenCode server, causing the CLI to either hang indefinitely or exit for unrelated reasons.

Root Cause

In runner.ts, the event stream subscription was missing the directory parameter:

// Before (broken)
const events = await client.event.subscribe()

// After (fixed)
const events = await client.event.subscribe({ directory })

Without directory, the Go-based OpenCode server's SSE endpoint (GET /event) only emits global events:

  • server.heartbeat, server.connected, tui.toast.show
  • session.created, session.updated, file.watcher.updated

But does NOT emit session-scoped events:

  • session.idle, session.status
  • tool.execute, tool.result
  • message.updated, message.part.updated

This causes:

  • hasReceivedMeaningfulWork stays false forever (no message/tool events)
  • mainSessionIdle never updates (no session.idle/status events)
  • pollForCompletion either hangs or exits for unrelated reasons

Fix

  1. Primary: Pass { directory } to client.event.subscribe(), matching the pattern already used by client.session.promptAsync()
  2. Defense-in-depth: Add stabilization period (10s) after first meaningful work before checking completion conditions, preventing early exit race conditions

Changes

  • src/cli/run/runner.ts: Add directory parameter to event subscription
  • src/cli/run/poll-for-completion.ts: Add MIN_STABILIZATION_MS and firstWorkTimestamp tracking
  • src/cli/run/poll-for-completion.test.ts: Add stabilization period test + update existing tests

Testing

74 tests pass across 10 files in src/cli/run/


Summary by cubic

Fixes missing session-scoped SSE events in oh-my-opencode run by passing the working directory as a query to event.subscribe, preventing hangs and premature exits. Adds a 10s stabilization window after first meaningful work to avoid early-exit races.

  • Bug Fixes

    • Subscribe to SSE with { query: { directory } } to receive session-scoped events (session.idle/status, tool., message.).
    • Gate completion checks behind a configurable stabilization period (default 10s) after first meaningful work.
  • Dependencies

    • Bumped oh-my-opencode platform packages in bun.lock from 3.3.1 to 3.5.2.

Written for commit 9afd0d1. Summary will update on new commits.

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 4 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Requires human review: Lockfile updates dependency versions (3.3.1→3.5.2) with unknown changes; runner.ts modifies subscribe() API call; new stabilization logic adds 10s default delay. Cannot guarantee 100% no regressions

The SSE event stream subscription was missing the directory parameter,
causing the OpenCode server to only emit global events (heartbeat,
connected, toast) but not session-scoped events (session.idle,
session.status, tool.execute, message.updated, message.part.updated).

Without session events:
- hasReceivedMeaningfulWork stays false (no message/tool events)
- mainSessionIdle never updates (no session.idle/status events)
- pollForCompletion either hangs or exits for unrelated reasons

Fix: Pass { directory } to client.event.subscribe(), matching the
pattern already used by client.session.promptAsync().

Also adds a stabilization period (10s) after first meaningful work
as defense-in-depth against early exit race conditions.
@code-yeongyu code-yeongyu merged commit d358e6e into dev Feb 12, 2026
7 checks passed
@code-yeongyu code-yeongyu deleted the fix/run-event-stream branch February 12, 2026 02:55
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