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 --attach exits 0 after first tool-call step_finish, drops final text event (1.17.20 + 1.18.4) #38661
opencode run --attach <url> --format json exits 0 after the first step_finish (reason: "tool-calls") and never emits the second step's text event — even though the server completes the full agentic loop.
Confirmed via server-side SQLite: the --attach session has all 9 parts stored (including the final text from step 2), but the CLI only output 4 events (step 1 only) before exiting.
This makes --attach unusable for any agent that uses tools.
Plugins
None
OpenCode version
1.17.20 (also reproduced on 1.18.4)
Steps to reproduce
1. Start a server with an agent that calls a tool first:
opencode serve --hostname 0.0.0.0 --port 4096
Agent (~/.config/opencode/agents/hello-world.md) — must call a tool then reply:
---name: hello-worldmode: primarymodel: zai-coding-plan/glm-5.2 # any OpenAI-compatible provider reproduces thistools:
mcp__my-mcp__get_info: true---
First call `mcp__my-mcp__get_info`, then reply to the user. Two steps required.
2. Local opencode run works (full 2-step loop, 6 events):
Reproduces on loopback (127.0.0.1:4096 from inside the same container) — not a networking issue.
Server-side proof (the key evidence)
After the --attach call above, querying the session in the server's SQLite DB (opencode.db) shows all 9 parts including the final text:
parts stored for attach session:
[0] text "hi" (user)
[1] step-start (step 1)
[2] reasoning
[3] tool my-mcp__get_info
[4] step-finish
[5] step-start (step 2 ← server started it)
[6] reasoning
[7] text "Here is the info..." ← final response EXISTS in DB
[8] step-finish
The server completed step 2 and stored the text, but the CLI exited before consuming those events.
Session token counts confirm: output: 66 tokens (attach) vs output: 65 (local baseline) — the model generated similar output in both cases.
Suspected code location
packages/opencode/src/cli/cmd/run.ts, the event loop break condition (~line 789):
if(event.type==="session.status"&&event.properties.status.type==="idle"){break// ← exits before step 2 events arrive}
In --attach mode the server appears to emit session.status: idle between step 1 and step 2; the CLI treats it as turn-complete and exits. Local mode doesn't hit this (in-process event timing differs).
Operating System
Linux x86_64 (Docker containers, node:20-slim based)
Terminal
Non-interactive (--format json piped to stdout, no TTY)
This issue might be a duplicate of existing issues. Please check:
opencode run --format json drops text and step-finish events in containerized environments #31435: Same root cause — session.status: idle in run.ts causes the CLI event loop to exit before all step events are delivered in multi-step agentic scenarios. That issue describes the same race (idle arriving ahead of text/step_finish events) and even references the same break condition in run.ts. The context there is containerized environments vs. --attach mode, but the underlying bug appears identical.
looks like the same root cause as #31435 (same idle-break race in run.ts). posted server-side db evidence over there since that's the older tracking issue — short version is the attach session has all 9 parts in opencode.db including the step 2 text, so it's purely a CLI consumption bug.
@jangel97 had a fix in #31446 but it got caught by the automated cleanup. happy to open a refresh if a maintainer wants.
Activity
github-actions commentedon Jul 24, 2026
This issue might be a duplicate of existing issues. Please check:
session.status: idleinrun.tscauses the CLI event loop to exit before all step events are delivered in multi-step agentic scenarios. That issue describes the same race (idle arriving ahead oftext/step_finishevents) and even references the same break condition inrun.ts. The context there is containerized environments vs.--attachmode, but the underlying bug appears identical.chenw521 commentedon Jul 24, 2026
looks like the same root cause as #31435 (same idle-break race in run.ts). posted server-side db evidence over there since that's the older tracking issue — short version is the attach session has all 9 parts in opencode.db including the step 2 text, so it's purely a CLI consumption bug.
@jangel97 had a fix in #31446 but it got caught by the automated cleanup. happy to open a refresh if a maintainer wants.
github-actions commentedon Sep 24, 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.