Skip to content

Bug: opencode run exits before background tasks (explore/librarian) complete #16380

Closed

Description

@one27001

Description

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

  1. Run a one-shot query that triggers background agents:
    opencode run "did I leave any loose ends in my conversations this week?"
  2. The LLM launches multiple background explore agents + direct tool calls
  3. Direct tool calls complete, LLM emits text like "Let me wait for them to complete"
  4. opencode run treats the text emission as session completion and exits
  5. 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)

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Mar 6, 2026
  2. one27001 commented on Mar 6, 2026

    @one27001
    Author

    Closing — filed prematurely, haven't confirmed the root cause is in opencode yet.

  3. one27001 commented on Mar 6, 2026

    @one27001
    Author

    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.

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

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions