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
Bug: opencode run exits before background tasks (explore/librarian) complete #16380
opencode run terminates the process as soon as the LLM emits a text response, even when background tasks (explore agents, librarian agents) are still running. This means any one-shot invocation that triggers background agents returns incomplete results.
Steps to Reproduce
Run a one-shot query that triggers background agents:
opencode run "did I leave any loose ends in my conversations this week?"
The LLM launches multiple background explore agents + direct tool calls
Direct tool calls complete, LLM emits text like "Let me wait for them to complete"
opencode run treats the text emission as session completion and exits
Background agents never get collected; output is incomplete
Expected Behavior
opencode run should wait until all pending background tasks have completed (or been cancelled) before considering the session done and exiting.
Actual Behavior
The process exits immediately after the LLM produces a text response, regardless of pending background tasks. The terminal shows the explore agents were launched and some completed, but the LLM never gets to collect their results or produce a final synthesis.
Workaround
Instructing the LLM (via AGENTS.md) to poll/collect all background task results before emitting any final text. This keeps the session alive because opencode run doesn't see a "complete" response until everything is collected. This is fragile — it depends on the LLM obeying the instruction.
Environment
macOS (Apple Silicon)
opencode latest (installed via bun)
One-shot mode via opencode run
TUI mode is unaffected (user can wait and interact)
Not an opencode bug. The session correctly exits when the LLM produces a text-only step (finish reason != tool-calls). The issue is that the LLM non-deterministically emits bare text instead of including a background_output tool call in the same step. Workaround: instruct the LLM to suppress all text until background tasks are collected.
Activity
one27001 commentedon Mar 6, 2026
Closing — filed prematurely, haven't confirmed the root cause is in opencode yet.
one27001 commentedon Mar 6, 2026
Not an opencode bug. The session correctly exits when the LLM produces a text-only step (finish reason != tool-calls). The issue is that the LLM non-deterministically emits bare text instead of including a background_output tool call in the same step. Workaround: instruct the LLM to suppress all text until background tasks are collected.