You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
opencode run --format json can stop reading the event stream when the session reaches idle, before the final assistant parts are emitted to stdout.
This change tracks which parts were already emitted from the event stream. After session.prompt or session.command finishes, it flushes any missing parts from that call's returned assistant message. This keeps JSON output consistent without replaying older session history.
How did you verify your code works?
Ran git diff --check
Built the CLI with npm exec --yes bun@1.3.14 -- run --cwd packages/opencode build --single --skip-install --skip-embed-web-ui
Verified the built binary smoke test passed with version 0.0.0-fix/run-json-flush-parts-v2-202606091119
Ran the built binary against a real model:
new run --format json session emitted step_start, text, and step_finish
resumed run --format json --session ... emitted step_start, text, and step_finish
This PR appears to address the same issue as #31505 (the current PR). Both are fixing problems with the opencode run --format json command stopping prematurely when the session reaches idle, before all assistant parts are emitted to stdout. The approach differs (draining events vs flushing parts), but they target the same root problem with JSON stream output in CLI.
Re: the bot note about #31446, this fixes the same symptom but uses a different fallback.
#31446 keeps draining SSE after idle with a timeout. This PR flushes only the parts returned by the current session.prompt / session.command call after the stream loop finishes, so it does not depend on a timer and does not replay older session history.
The repro in #31482 was an existing session with prior tool history where the assistant result was persisted but stdout was empty.
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
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.
Issue for this PR
Fixes #31482
Type of change
What does this PR do?
opencode run --format jsoncan stop reading the event stream when the session reachesidle, before the final assistant parts are emitted to stdout.This change tracks which parts were already emitted from the event stream. After
session.promptorsession.commandfinishes, it flushes any missing parts from that call's returned assistant message. This keeps JSON output consistent without replaying older session history.How did you verify your code works?
git diff --checknpm exec --yes bun@1.3.14 -- run --cwd packages/opencode build --single --skip-install --skip-embed-web-ui0.0.0-fix/run-json-flush-parts-v2-202606091119run --format jsonsession emittedstep_start,text, andstep_finishrun --format json --session ...emittedstep_start,text, andstep_finishScreenshots / recordings
N/A, CLI-only change.
Checklist