[Bug]: OpenCode thread unloaded while a background shell runs: the turn OpenCode starts when it finishes is never shown and has no T3 tools #31307
Before submitting#
- I searched existing issues and did not find a duplicate.
- I included enough detail to reproduce or investigate the problem.
Area#
Server: OpenCode provider (packages/provider-opencode, v2 adapter)
Steps to reproduce#
- In an OpenCode thread, have the agent start a long shell command in the background (it returns at once; when the shell finishes, a synthetic
source: "shell"message is enqueued in the OpenCode session and OpenCode starts a turn by itself). - Let the T3 turn end and leave the thread alone for more than 30 minutes while the shell keeps running.
- Let the shell finish.
Expected behavior#
The turn OpenCode starts for the finished shell shows up in the thread, as it does when the shell finishes within 30 minutes (onWake: "OpenCode started a turn on its own; asking for a continuation"), and the thread's T3 MCP tools are available in it.
Actual behavior#
After 30 idle minutes ProviderSessionManager unloads the thread. unloadThread in v2/adapter.ts keeps a thread only for state.active or hasBackground(state), and owesWork counts wakes, reports, busy subagents and background subagent calls, not a background shell inside the OpenCode session. So the thread is deleted from threads and its MCP server is removed (client.mcp.remove).
When the shell finishes, OpenCode runs the turn anyway, but no thread owns the session any more: nothing of the turn reaches T3's projection, and the turn's tool list has no t3-code-… tools.
Observed on one thread (times UTC):
| Time | Event |
|---|---|
| 02:08:30 | last T3 turn item; a background shell is still running |
| 02:38:30 | DELETE /api/experimental/mcp/t3-code-mcp_<thread> from T3 (30 min later) |
| 03:30:30 | the shell finishes; OpenCode starts a turn (9 steps, ~3 min): it merges a branch, deletes it, edits a file |
| 03:32:14 | the agent calls link_pull_request by its T3 tool name, as in earlier turns; the provider refuses it because the tool isn't in the turn's tool list (186 tools at 00:51 on the same session, 118 now, none from T3) |
| 03:33:20 | the agent ends with "the tools for messaging its thread and linking the PR weren't available this turn" |
The thread in T3 still ends at 02:08:30; the work done at 03:30 is only in OpenCode's database. The code on main (67eebaca23) is the same.
Impact#
Work the agent does after a long background command is invisible in T3, and it can't use T3's tools (thread messages, PR links, delegation), so follow-ups it would send are dropped. In 24 h on one server: 1 of 468 OpenCode turns in top-level threads (it needs a background command that outlives 30 idle minutes).
Version or commit#
0.1.7-nightly.20261103.4119; same code on main 67eebaca23. OpenCode 2.2.5.
Environment#
Linux (NixOS), T3 server as a user service, one shared OpenCode server, Cursor models through an OpenCode provider plugin.
Logs or stack traces#
T3 trace: PUT …/api/experimental/mcp/t3-code-mcp_<thread> at 00:51:24, DELETE of the same at 02:38:30, no spans for the thread after that until the next user message. OpenCode: synthetic message {"source":"shell","state":"completed"} at 03:30:30, assistant steps until idle at 03:33:24.
Workaround#
None in T3. Sending any message to the thread re-adds the MCP server, but the unseen turn stays unseen.
Possible fixes: re-load the thread when an unowned OpenCode session starts executing (handle it like onWake), or don't unload while the OpenCode session has a pending background shell.
Found and written up by Claude Opus 5.5 (Cursor) in OpenCode, running in T3, during a review of our T3 server logs.
juliusmarminge closed this
Sign in to join this conversation.
Thanks for the detailed timeline. This is the same bug as #18880 ("OpenCode threads lose background shell results after the 30-minute idle release"), which is open and accepted.
On current
main(67eebaca23),owesWorkinpackages/provider-opencode/src/server/v2/adapter.tsstill counts only wakes, reports, busy subagents and background subagent calls. A background shell doesn't keep the thread loaded, so the idle release removes it and itst3-code-…MCP server, and the turn OpenCode starts when the shell finishes never reaches T3. A comment on https://git.cafe/pingdotgg/t3code/issues/18880 already covers the missing T3 tools in that turn.Closing as a duplicate so the work stays in one place. Please add any further observations to https://git.cafe/pingdotgg/t3code/issues/18880.