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
opencode run --format json --session hangs after final answer is persisted #32506
opencode run --format json --session <session_id> can hang even after the model has completed and the final assistant answer has been persisted to OpenCode’s session DB.
In our repro, the process stayed alive, stdout remained empty, but the SQLite session DB contained both the completed tool result and final answer.
What We Tried
We tested PR #31505, which flushes missed parts after the stream loop finishes:
That did not fix our case because finish() itself can hang waiting for the event stream to observe session.status: idle. Since flushParts() runs after finish(), the fallback is never reached.
Custom Patch
We changed JSON mode to flush returned prompt/command parts before waiting for stream completion:
Once client.session.prompt() or client.session.command() returns, result.data.parts contains the completed assistant parts. For --format json, emitting those parts immediately avoids depending on the event stream’s idle signal.
The stream is still given a short best-effort drain window, but output delivery no longer blocks forever on it.
Issue #32506 is more specific to the --format json --session path where finish() blocks on session.status: idle, which may be a distinct root cause or a manifestation of the same underlying problem. It may be worth cross-referencing these when investigating a fix.
Activity
github-actions commentedon Jun 16, 2026
This issue might be a duplicate of existing issues. Please check:
opencode runhangs after completing tool calls — process never exits #17516:opencode runhangs after completing tool calls — process never exits (similar symptom: process hangs after model finishes, never exits)opencode runprocesses don't exit after completing scheduled work (related: event loop keeps process alive after work completes)Issue #32506 is more specific to the
--format json --sessionpath wherefinish()blocks onsession.status: idle, which may be a distinct root cause or a manifestation of the same underlying problem. It may be worth cross-referencing these when investigating a fix.taagarwa-rh commentedon Jun 18, 2026
I'm encountering the same issue on v1.17.8
github-actions commentedon Aug 18, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.