Skip to content

opencode run --format json drops text and step-finish events in containerized environments #31435

@jangel97

Description

@jangel97

Description

opencode run --format json produces incomplete JSONL output in containerized environments. Only step_start is emitted — text and step_finish events are lost.

Root Cause

The loop() function in run.ts breaks immediately when it receives a session.status = idle event. In containerized environments (higher event delivery latency), this idle event races ahead of text and step-finish part events in the SSE pipeline, causing the loop to exit before all events are delivered.

Steps to Reproduce

Run inside a container:

OPENCODE_EXPERIMENTAL=true opencode run --format json -m "google-vertex-anthropic/claude-sonnet-4@20250514" "Say hello in one sentence"

Actual output (only step_start):

{"type":"step_start","timestamp":1780961221439,"sessionID":"ses_...","part":{"type":"step-start"}}

Expected output (all three events):

{"type":"step_start","timestamp":...,"sessionID":"ses_...","part":{"type":"step-start"}}
{"type":"text","timestamp":...,"sessionID":"ses_...","part":{"type":"text","text":"Hello! ..."}}
{"type":"step_finish","timestamp":...,"sessionID":"ses_...","part":{"type":"step-finish","tokens":{...}}}

Environment

  • OpenCode run inside a Linux container (podman/docker)
  • Provider: Vertex AI (Google Cloud), but likely affects all providers
  • The issue does not reproduce on macOS natively, where event delivery is faster

Proposed Fix

Track active step lifecycle with a counter. When idle arrives while steps are still open, defer the break and drain remaining events with a safety timeout.

See PR #31434.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions