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
{{ message }}
Repository navigation
cli: opencode run --format json drops the final step_finish event #53207
opencode run --format json usually exits without printing the final step_finish event, even though the session completed and stored that step. Scripts that read tokens and cost from step_finish lose usage for the final step.
With OpenCode Go, 9 of 9 completed runs ended like this:
step_start tool_use step_finish step_start text
The final step_finish is missing. opencode session export shows the final assistant message with finish: "stop" and the expected text. The same thing happens with no tool call (step_start text, no step_finish).
In packages/cli/src/run/noninteractive.ts, session.wait resolves when the session goes idle. The client then sets finalizing = true, which drops every queued event except session.execution.*. reconcile() fills in missing text, reasoning and tool parts from the saved messages, but never emits step_start or step_finish. If idle arrives before the final session.step.ended is processed, that event is lost. The existing test uses session.wait then reconciles projected output without a terminal event expects only text in this case.
Older reports of this symptom (#31435, #38661, #26855) were for the v1 run.ts and were closed. This is the v2 client.
Plugins
None relevant (local opencode-sync and tapas plugins installed)
OpenCode version
v2.0.22, also reproduced from source on v2 at 0a46301
Steps to reproduce
foriin 1 2 3 4 5;do
opencode run --auto --format json -m opencode-go/deepseek-v4-flash \
"Use the bash tool to run: echo tool-ok, then reply with exactly the command's output" \
| jq -r .type | tr '\n''';echodone
Expected: each line ends with step_start text step_finish.
Actual: the final step_finish is missing (5/5 with deepseek-v4-flash, 4/4 completed with glm-5.3-flash).
changed the title [-]`opencode run --format json` drops the final `step_finish` event[/-][+]opencode run --format json drops the final step_finish event[/+]on Oct 5, 2026
changed the title [-]opencode run --format json drops the final step_finish event[/-][+]cli: opencode run --format json drops the final step_finish event[/+]on Oct 5, 2026
Still reproduces on v2.0.26 (9b4ec57), Linux x86_64, deepseek/deepseek-v4-flash: 8/8 --format json runs ended on text with no final step_finish (intermediate steps do get step_finish with tool-calls). Filed #54661 before finding this one — closing it as a duplicate.
Still on 2.1.4 (@opencode/cli-linux-x64) with openrouter/minimax/minimax-m3.1-flash, run --standalone --format json: final step_finish missing in 7 of 7 runs, 1 to 110 steps. Details in #59652.
Thanks for the detailed report and for pointing to the code. I reproduced this without a real provider, using a local mock OpenAI-compatible model that first asks to run bash and then replies with text, with token usage on every response.
On v2.0.22, opencode run --standalone --auto --format json -m mock/m "..." | jq -r .type printed step_start tool_use step_finish step_start text in every run, with no final step_finish. Text-only replies printed just step_start text.
It still happens on the latest dev (fd8268ea5), run from source: the same output in every run, with and without a tool call.
This matches your analysis. Once session.wait resolves, the client stops handling queued step events, and reconcile() only fills in text, reasoning and tool output. So the final step's finish reason, tokens and cost never reach the stream.
The script below reproduces it, with the mock server included. #54661 and #59652 report the same problem, and the open PR #53208 targets this issue.
Activity
github-actions commentedon Oct 4, 2026
This issue might be related to earlier reports. Please check:
opencode run --format jsoncompleted without emitting the finalstep_finishevent (older v1 report; same observable symptom).opencode run --format jsondropped text andstep-finishevents when event delivery raced with idle status (older v1 report).opencode run --attachexited after the initial tool-call step and dropped later output (related v1 event-loss behavior).These reports were for v1; this issue describes the v2 client.
[-]`opencode run --format json` drops the final `step_finish` event[/-][+]opencode run --format json drops the final step_finish event[/+][-]opencode run --format json drops the final step_finish event[/-][+]cli: opencode run --format json drops the final step_finish event[/+]Anchor the opencode usage tests to a tool step under the v2 defect
oldantique commentedon Oct 12, 2026
Still reproduces on v2.0.26 (9b4ec57), Linux x86_64,
deepseek/deepseek-v4-flash: 8/8--format jsonruns ended ontextwith no finalstep_finish(intermediate steps do getstep_finishwithtool-calls). Filed #54661 before finding this one — closing it as a duplicate.fix(agent/opencode): accept clean-exit runs when OpenCode v2 omits st…
mp-grind commentedon Oct 22, 2026
Just ran into this as well. Thanks for digging into it for the PR. Looking forward to seeing it get merged.
veyomr commentedon Oct 27, 2026
Still on 2.1.4 (
@opencode/cli-linux-x64) withopenrouter/minimax/minimax-m3.1-flash,run --standalone --format json: finalstep_finishmissing in 7 of 7 runs, 1 to 110 steps. Details in #59652.opencodejr commentedon Oct 27, 2026
Thanks for the detailed report and for pointing to the code. I reproduced this without a real provider, using a local mock OpenAI-compatible model that first asks to run
bashand then replies with text, with token usage on every response.opencode run --standalone --auto --format json -m mock/m "..." | jq -r .typeprintedstep_start tool_use step_finish step_start textin every run, with no finalstep_finish. Text-only replies printed juststep_start text.dev(fd8268ea5), run from source: the same output in every run, with and without a tool call.This matches your analysis. Once
session.waitresolves, the client stops handling queued step events, andreconcile()only fills in text, reasoning and tool output. So the final step's finish reason, tokens and cost never reach the stream.The script below reproduces it, with the mock server included. #54661 and #59652 report the same problem, and the open PR #53208 targets this issue.
Reproduction script (repro.sh)
Run it:
bash repro.shfreshen(opencode-ci-harness): final step events are fixed in v2.2.3; …