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.
Description
opencode run --format jsonproduces incomplete JSONL output in containerized environments. Onlystep_startis emitted —textandstep_finishevents are lost.Root Cause
The
loop()function inrun.tsbreaks immediately when it receives asession.status = idleevent. In containerized environments (higher event delivery latency), this idle event races ahead oftextandstep-finishpart events in the SSE pipeline, causing the loop to exit before all events are delivered.Steps to Reproduce
Run inside a container:
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
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.