GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(opencode): await run event loop by rekram1-node · Pull Request #31389 · anomalyco/opencode

Conversation

@rekram1-node

@rekram1-node rekram1-node commented Jun 8, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

DanielAGW and kenxu95 reacted with heart emoji
All reactions
  • ❤️ 2 reactions
@rekram1-node
fix(opencode): await local run event loop
be51ce3
@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

Uh oh!

There was an error while loading. Please reload this page.

@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
@shoootyou @rekram1-node
@opencode-agent @simonklee @Hona @neriousy @fwang @nexxeln @areyouok @remorses @MrMushrooooom @adamdotdevin @thdxr @jlongster @AnthonyMLau @Brendonovich @delta9000 @kommander @songchaow @yui-soul
chore: sync fork with upstream anomalyco/opencode (#4)
4e89d72
* 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 <[email protected]>

* chore: generate

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

Co-authored-by: Simon Klee <[email protected]>

* 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 <[email protected]>
Co-authored-by: Aiden Cline <[email protected]>

* 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 <[email protected]>
Co-authored-by: Aiden Cline <[email protected]>

* 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 <[email protected]>
Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
Co-authored-by: Simon Klee <[email protected]>
Co-authored-by: Luke Parker <[email protected]>
Co-authored-by: Filip <[email protected]>
Co-authored-by: Frank <[email protected]>
Co-authored-by: Shoubhit Dash <[email protected]>
Co-authored-by: huangli <[email protected]>
Co-authored-by: Tommy D. Rossi <[email protected]>
Co-authored-by: Jack <[email protected]>
Co-authored-by: Adam <[email protected]>
Co-authored-by: Dax <[email protected]>
Co-authored-by: James Long <[email protected]>
Co-authored-by: Anthony Lau <[email protected]>
Co-authored-by: Aiden Cline <[email protected]>
Co-authored-by: Brendan Allan <[email protected]>
Co-authored-by: Ben Sandbrook <[email protected]>
Co-authored-by: Ben Sandbrook <[email protected]>
Co-authored-by: opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com>
Co-authored-by: Sebastian <[email protected]>
Co-authored-by: Songchao Wang <[email protected]>
Co-authored-by: yui-soul <[email protected]>
@abdullaharif99 abdullaharif99 mentioned this pull request Jun 12, 2026
fix(opencode): keep the final assistant turn when it has no step_finish harbor-framework/harbor#1780
Closed
@hardes11 hardes11 mentioned this pull request Jun 14, 2026
fix: await event loop in non-interactive opencode run #29132
Closed
3 of 6 tasks
isaacfinnegan pushed a commit to isaacfinnegan/whispercode that referenced this pull request Jun 15, 2026
@rekram1-node
fix(opencode): await run event loop (anomalyco#31389)
3462525
leduyphuc1702 pushed a commit to leduyphuc1702/opencode-workflow that referenced this pull request Jun 16, 2026
@rekram1-node Phuc Le
fix(opencode): await run event loop (anomalyco#31389)
6b5f960
(cherry picked from commit 0a7cb20)
BenGu3 pushed a commit to BenGu3/opencode that referenced this pull request Jun 27, 2026
@rekram1-node @BenGu3
fix(opencode): await run event loop (anomalyco#31389)
1cfadff
@heimoshuiyu heimoshuiyu mentioned this pull request Jul 24, 2026
fix(cli): await event loop in run --attach mode #38679
Closed
3 of 6 tasks
@mattrossman mattrossman mentioned this pull request Jul 24, 2026
feat: add OpenCode harness running Kimi K3 through the Vercel AI Gateway supabase/evals#126
Merged
mattrossman added a commit to supabase/evals that referenced this pull request Jul 28, 2026
@mattrossman @github-actions
feat: add OpenCode harness running Kimi K3 through the Vercel AI Gate…
80ec7ac
…way (#126)

Adds `opencode` as a CLI agent harness plus two experiments running Kimi
K3 through the [Vercel AI Gateway](https://vercel.com/ai-gateway):
`opencode-kimi-k3` and `opencode-kimi-k3-no-skills`. Consolidates parts
of #56, #120, and #124 per [this
thread](https://supabase.slack.com/archives/C0BAGJBL49E/p1784919389986449?thread_ts=1784890581.560609&cid=C0BAGJBL49E).
AI gateway is used only for OpenCode w/ the new experiments. Uses
OpenCode's [native `vercel`
provider](https://vercel.com/docs/ai-gateway/coding-agents/opencode), so
the only credential is `AI_GATEWAY_API_KEY` which is already configured
in repo secrets.

The CLI is pinned to 1.18.5 and must stay >= 1.17.0. Older versions
don't await the run event loop
([opencode#31389](anomalyco/opencode#31389)) and
intermittently exit mid-step with no final report, which was failing
about half of sandbox runs regardless of model.

Failures like that used to be invisible: results JSON just showed an
empty transcript with `stoppedReason: "error"`. Running with `--debug`
now prints opencode's actual errors, which is how this was diagnosed:

```
OpenCode error event: {"name":"UnknownError","data":{"message":"Unexpected server error. Check server logs for details.","ref":"err_1ffd1f34"}}
```

Incidental fix: eval refresh jobs now fail when the experiment writes no
result instead of green-skipping (surfaced by a missing
`AI_GATEWAY_API_KEY` in the workflow env, now also wired up).

To test locally, add `AI_GATEWAY_API_KEY` to `.env` (create one in the
[evals Vercel project](https://vercel.com/supabase/evals) under AI
Gateway → API keys), then:

```sh
pnpm eval -- --experiment opencode-kimi-k3 --eval investigate-db-001-table-row-counts
```

Closes AI-967, AI-964, AI-965

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
MarsQiu007 referenced this pull request in MarsQiu007/openNovel Jul 31, 2026
@rekram1-node
fix(opencode): await run event loop (#31389)
0c472f4
@rekram1-node rekram1-node mentioned this pull request Sep 2, 2026
fix(cli): preserve attached run output #46896
Closed
3 of 6 tasks
@brentyates-swx brentyates-swx mentioned this pull request Sep 26, 2026
fix(cli): non-interactive run can exit before printing its turn in two cases swxtchio/swx-opencode-archive#50
Closed
brentyates-swx added a commit to swxtchio/swx-opencode-archive that referenced this pull request Sep 26, 2026
@brentyates-swx
fix(cli): address round 3 of cross-model review on --effort
146209d
- Hydration skipped restoring a resumed session's effort whenever
  --effort was active, even for a model that does not declare it, so that
  model fell back to the default instead of the session's effort. It now
  restores through variant.restore(), which records the effort without
  counting as the user's choice: --effort still wins wherever the model
  declares it, and the session's effort applies everywhere else. (Sol)
- The "could not connect to the event stream" failure bypassed
  --format json; it now emits an error record like every other failure.
  (GLM)
- Filed #50 for two existing `run` completion races Sol found (attach
  mode not awaiting the event loop, per upstream anomalyco#31389; --session
  breaking on an earlier turn's idle). Both are upstream behavior this PR
  does not change.

Claude-Session: https://claude.ai/code/session_01BUBanXuSck62cxd3dpZ1oA
@brentyates-swx brentyates-swx mentioned this pull request Sep 26, 2026
fix(cli): make --effort work and fail loudly everywhere swxtchio/swx-opencode-archive#49
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

run --format json can exit before emitting final step_finish event opencode run teardown race after session.idle can create empty continuation assistant turn ("parts": [])

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@rekram1-node
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.