Skip to content

fix(opencode): await run event loop#31389

Merged
rekram1-node merged 1 commit into
devfrom
fix/run-await-event-loop
Jun 8, 2026
Merged

fix(opencode): await run event loop#31389
rekram1-node merged 1 commit into
devfrom
fix/run-await-event-loop

Conversation

@rekram1-node

@rekram1-node rekram1-node commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Issue for this PR

Closes #26855.

Also addresses the same local premature output-consumer teardown reported in #29131 and #31365, and likely local timing variants in #29866, #31382, and #28605. Related exit-status reports include #26509, #15558, #17854, and #2489.

This differs from #29132 by preserving the immediate request-error behavior introduced for #27371 and by limiting the event-loop join to local mode.

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Local non-interactive opencode run starts an SSE event consumer alongside the synchronous prompt or command request. The request waits for session execution, but it can resolve before the separate event iterator has processed all queued events and written them to stdout. Returning from the command then disposes the in-process instance and terminates its event stream.

This change retains and awaits the event-loop promise after successful local prompt and command requests. Instance disposal therefore waits until the consumer observes session.status: idle, after the preceding text, tool, reasoning, and step_finish events have been processed.

The join is intentionally limited to local mode. In --attach mode the remote SSE connection has an independent lifecycle and can miss transient events, so this PR preserves its existing behavior rather than introducing a new completion contract.

If the prompt or command request itself returns an error, the command returns immediately without awaiting the event loop. This preserves the #27371 fix because request-level failures are not guaranteed to publish an idle event.

Loop rejections set process.exitCode instead of calling process.exit(1), allowing normal stdout flushing and cleanup.

This does not claim to fix #15267, which concerns post-idle plugin continuation, or #17516, which concerns a session that never reaches idle.

How did you verify your code works?

  • bun test test/cli/run/run-process.test.ts --rerun-each 10 from packages/opencode: 40 passed
  • bun typecheck from packages/opencode: passed
  • Manually ran local opencode run in a non-Git temporary directory with inline {"snapshot":false} config

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@rekram1-node rekram1-node force-pushed the fix/run-await-event-loop branch from 6aeaaa6 to be51ce3 Compare June 8, 2026 17:29
@rekram1-node rekram1-node merged commit 0a7cb20 into dev Jun 8, 2026
12 checks passed
@rekram1-node rekram1-node deleted the fix/run-await-event-loop branch June 8, 2026 17:47
shoootyou added a commit to shoootyou/opencode that referenced this pull request Jun 10, 2026
* test(core): cover skill directory output (anomalyco#31263)

* fix(opencode): avoid duplicate skill catalog (anomalyco#31269)

* chore(opencode): update MCP SDK to 1.29.0 (anomalyco#31268)

* chore: generate

* chore: update nix node_modules hashes

* run: make minimal mode more minimal (anomalyco#31227)

* chore: generate

* chore: update web and desktop code owners (anomalyco#31289)

* fix(desktop): few WSL bugs (anomalyco#31095)

* chore: generate

* fix(opencode): respect MCP server capabilities (anomalyco#31271)

* console: update email

* zen: fix

* fix(opencode): include acp pending tool input (anomalyco#31321)

* fix(lsp): resolve JDTLS root to topmost pom.xml in Java Maven multi-module projects (anomalyco#28761)

Co-authored-by: Shoubhit Dash <shoubhit2005@gmail.com>

* chore: generate

* fix(session): merge per-call tool rules into session permission (anomalyco#30529)

Co-authored-by: Simon Klee <hello@simonklee.dk>

* docs(go): update MiniMax M3 pricing (anomalyco#31350)

* fix: speed up fff file search (anomalyco#31366)

* chore: generate

* fix(stats): show new for leaderboard deltas

* fix: stabilize fff file results (anomalyco#31369)

* chore: generate

* fix(core): restore npm proxy agent patch (anomalyco#31373)

* chore: update nix node_modules hashes

* chore: upgrade OpenTUI to v0.3.4 (anomalyco#31326)

* chore: update nix node_modules hashes

* fix(core): disable fff trace logs (anomalyco#31380)

* fix(session): avoid sticky prompt tool overrides (anomalyco#31394)

* fix(opencode): await run event loop (anomalyco#31389)

* refactor(core): replace legacy logger with Effect logging (anomalyco#31310)

* chore: generate

* fix(tui): trim select footer action highlight (anomalyco#31411)

* fix(opencode): support MiniMax M3 thinking toggle (anomalyco#31426)

* fix: adjust item id stripping to happen prior to request signing (anomalyco#31429)

* fix(opencode): generate reasoning variants for all OpenRouter models. (anomalyco#30332)

Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com>
Co-authored-by: Aiden Cline <aidenpcline@gmail.com>

* feat(app): add draft tab support to tabs store (anomalyco#31343)

* chore: generate

* fix(opencode): paginate MCP catalogs (anomalyco#31442)

* fix(opencode): pass abort signal to MCP tool calls (anomalyco#31455)

* feat(app): draft prompt state (anomalyco#31452)

* chore: generate

* feat(app): tabs help button (anomalyco#31454)

* feat: add "reasoning" as interleaved field option for vLLM providers (anomalyco#30477)

Co-authored-by: Ben Sandbrook <1126483+delta9000@users.noreply.github.com>
Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com>

* fix(app): clip rounded session panels (anomalyco#31462)

* core: fix idle CPU use in file logger (anomalyco#31478)

* docs: add uninstall troubleshooting steps (anomalyco#31424)

Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>

* leave a breadcrumb comment about batchWindow zero (anomalyco#31508)

* chore: stats -> data

* test(core): avoid Windows worker close race (anomalyco#31532)

* refactor(tui): centralize application exit (anomalyco#31524)

* chore: generate

* feat(opencode): configure Cohere North model (anomalyco#31536)

* refactor(core): consolidate references (anomalyco#31539)

* feat(tui): show project copy in session list (anomalyco#31421)

* chore: generate

* fix(stats): use data branding assets

* drop citation_options from cohere (anomalyco#31543)

* zen: add north mini code model

* fix(data): timestamp formatting

* fix(opencode): support Claude Fable reasoning (anomalyco#31546)

* fix(mcp): log actionable connection statuses (anomalyco#31544)

* refactor(core): simplify location filesystem (anomalyco#31545)

* chore: generate

* chore: update nix node_modules hashes

* fix(opencode): restore effect error logging (anomalyco#31551)

* chore: generate

* feat(opencode): add typed application layer graph (anomalyco#31531)

* zen: add claude fable 5

* chore: generate

* refactor(mcp): simplify service helpers (anomalyco#31549)

* feat: add X-Session-Id header for proxy cache routing affinity (anomalyco#31511)

* zen: update email

* fix(desktop): update Electron stack and panel layout (anomalyco#31571)

* chore: generate

* chore: update nix node_modules hashes

---------

Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com>
Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
Co-authored-by: Simon Klee <hello@simonklee.dk>
Co-authored-by: Luke Parker <10430890+Hona@users.noreply.github.com>
Co-authored-by: Filip <34747899+neriousy@users.noreply.github.com>
Co-authored-by: Frank <frank@anoma.ly>
Co-authored-by: Shoubhit Dash <shoubhit2005@gmail.com>
Co-authored-by: huangli <areyouok@gmail.com>
Co-authored-by: Tommy D. Rossi <beats.by.morse@gmail.com>
Co-authored-by: Jack <jack@anoma.ly>
Co-authored-by: Adam <2363879+adamdotdevin@users.noreply.github.com>
Co-authored-by: Dax <mail@thdxr.com>
Co-authored-by: James Long <longster@gmail.com>
Co-authored-by: Anthony Lau <anthony.lau2000@live.com>
Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
Co-authored-by: Brendan Allan <14191578+Brendonovich@users.noreply.github.com>
Co-authored-by: Ben Sandbrook <sandbrookvt@gmail.com>
Co-authored-by: Ben Sandbrook <1126483+delta9000@users.noreply.github.com>
Co-authored-by: opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com>
Co-authored-by: Sebastian <hasta84@gmail.com>
Co-authored-by: Songchao Wang <songchaow@outlook.com>
Co-authored-by: yui-soul <yui-soul@users.noreply.github.com>
avion23 pushed a commit to avion23/opencode that referenced this pull request Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant