Skip to content

run --format json: stream ends without the last step's step_finish #59652

Closed

Description

@veyomr

Description

opencode run --format json ends its stream without a step_finish for the last step. Every earlier step has one.

  • runs: 7 of 7, from 1 to 110 steps
  • last stream line: step_start or text
  • session DB for that step: assistant message with finish: "stop", then idle with outcome: "succeeded" 2 ms later
  • exit code: 0
  • missing from the stream: the last step's finish reason, tokens and cost
  • one-step run: the stream was a single text line, with no step_start either

Related: #36413 (no terminal record in the JSON stream, V1), #48361

Plugins

None

OpenCode version

2.1.4 (@opencode/cli-linux-x64)

Steps to reproduce

opencode run --standalone --auto --format json \
  --model openrouter/minimax/minimax-m3.1-flash \
  "Reply with the single word ALPHA and nothing else."

Stream: one {"type":"text",...} line. Expected: step_start, text, step_finish.

Operating System

Ubuntu 24.04 (rootless podman container on Fedora Atomic)

Terminal

None, stdout redirected to a file

Activity

  1. opencode-agent commented on Oct 27, 2026

    @opencode-agent
    Contributor

    Thanks for the detailed report. I think this is a duplicate of #53207, which reports the same thing: the v2 opencode run --format json client leaves out the final step's step_finish, while the session has the step saved with finish: "stop". That issue traces it to packages/cli/src/run/noninteractive.ts. Once session.wait resolves, the remaining session.step.ended events are dropped, and reconcile() fills in text, reasoning and tool parts but not step boundaries. That also explains your single-step run, where the stream had no step_start either.

    Possible duplicates and related issues, ordered by likelihood:

    In the meantime, a workaround mentioned on #53208: opencode session export --standalone <sessionID> gives you .info.outcome, .info.cost and .info.tokens for the run.

    The bot will close this issue as a duplicate of #53207 in 1 day unless you reply explaining how your problem is different. It would help to add a note on #53207 that it still happens on 2.1.4 with openrouter/minimax/minimax-m3.1-flash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions