Skip to content

opencode run --format json --session writes assistant text to DB but emits empty stdout for an existing session #31482

Closed as not planned

Description

@maojindao55

Description

Summary

opencode run --format json --session <sessionID> can complete successfully and persist the assistant response into ~/.local/share/opencode/opencode.db,
but emit no JSON events to stdout.

This only happens for a specific existing session that has prior tool-call / multi-step history. A fresh session and a simple resumed session both stream JSON
correctly.

Environment

  • OpenCode version: 1.16.2
  • OS: macOS 15.5, arm64
  • Model: volcengine-plan/kimi-k2.6
  • Command mode: opencode run --format json

Working Case

Fresh session works:

opencode -m volcengine-plan/kimi-k2.6 run --format json "只输出 OK"

stdout includes step_start, text, and step_finish.

Resuming that fresh session also works:

opencode -m volcengine-plan/kimi-k2.6 run --format json \
  --session ses_154ab1ebdfferuLfjWKE1REEOy \
  "只输出 OK111"

stdout includes:

{"type":"text", "...": "...", "part":{"type":"text","text":"OK111"}}

## Failing Case

For an existing session with prior tool calls and multiple assistant steps:

opencode -m volcengine-plan/kimi-k2.6 run --format json \
  --dir /Users/www/dev-task-20260609-1023 \
  --dangerously-skip-permissions \
  --session ses_154eb250dffe9uo50Bn1S51wOu \
  "只输出 OK_BAD"

Actual behavior:

- stdout is empty
- process exits successfully
- OpenCode DB contains the assistant response and step finish

DB evidence:

select id, message_id, json_extract(data,'$.type') as type, json_extract(data,'$.text') as text
from part
where session_id='ses_154eb250dffe9uo50Bn1S51wOu'
order by time_created desc
limit 4;

Result includes:

step-finish
text         OK_BAD
step-start
text         "只输出 OK_BAD"

So the model ran, OpenCode persisted the result, but run --format json did not emit the expected stdout JSON events.

## Expected Behavior

opencode run --format json --session ... should emit the new run's JSON events to stdout, at minimum:

- step_start
- text
- step_finish

This should be consistent with fresh sessions and simple resumed sessions.

## Additional Context

The failing session has prior tool-call history and several assistant steps. Earlier integrations that spawned the same command also saw only step_start or
empty stdout, while the same final assistant text appeared in OpenCode DB.

This looks related to existing opencode run non-interactive / tool-call session issues, but I could not find an exact duplicate where the result is written to
DB while stdout is empty.

### Plugins

_No response_

### OpenCode version

_No response_

### Steps to reproduce

_No response_

### Screenshot and/or share link

_No response_

### Operating System

_No response_

### Terminal

_No response_

Activity

  1. github-actions commented on Jun 9, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    If your issue is specifically triggered by sessions with prior tool-call history (rather than container latency or buffering), it may be a distinct root cause — please mention this in your issue if so.

  2. github-actions commented on Aug 9, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions