[Bug]: OpenCode delegated task marked failed on context overflow, but the OpenCode session compacts and keeps running unsupervised#26674
What happened
I started a child agent with delegate_task on the OpenCode provider (local OpenAI-compatible model, 131,070-token server limit; worktree isolation). About 3 minutes in, one step's request was 140,049 tokens and the model server rejected it:
This model's maximum context length is 131070 tokens. However, your messages resulted in 140049 tokens.
T3 recorded the run as failed and delivered that error to the parent as the final result.
OpenCode treated the same error as recoverable. It auto-compacted the session (a 12.5K-token summary message at the same second), then kept working for another ~32 minutes, making tool calls and editing files in the child's worktree. None of this appeared in the T3 thread, which still showed the task as failed. T3 also never aborted the session.
The opencode serve process T3 started for that task kept running after the task "failed", hosting the orphaned session. I finally stopped the session by hand through OpenCode's POST /session/:id/abort. The server process was still alive ~45 minutes after T3 recorded the failure, while the servers for earlier delegated tasks that completed normally had already exited.
Side effect: I had already launched a retry of the same task, so the orphaned session and the retry both ran on the same single-GPU local model. Each one evicted the other's prompt cache, so the retry got 0 cached tokens and re-processed ~100K tokens per step: about 10 steps in 33 minutes.
Expected
Either of these:
- treat a context-overflow provider error as non-terminal while OpenCode is compacting/retrying, and keep following the session until it is really idle; or
- when T3 decides the task has failed, abort the OpenCode session (and stop the
opencode serveit started for the task), so nothing keeps running or editing the worktree after T3 reports a result.
Timeline (local time, from OpenCode's session DB and the T3 thread)
- 15:54:57 task started (fresh
opencode serveon its own port) - 15:57:47 provider error (140,049 > 131,070); T3 run →
failed - 15:57:47 OpenCode writes the compaction summary message (
finish: stop) - 15:58:02 OpenCode continues the session after compaction (new user/summary turn)
- 15:58–16:29 continued tool calls; uncommitted edits to 3 files in the worktree
- 16:31 session aborted manually via
/session/:id/abort - 16:42 that task's
opencode servestill running
Version / environment
- T3 server
v0.1.3, Linux 6.17 x86_64 - OpenCode
1.19.4(opencode servespawned by T3, one per delegated task) - Provider:
@ai-sdk/openai-compatibleto a local model,limit.context: 131072,limit.output: 8192
Related
- #26193: OpenCode compaction events are discarded, so the thread never shows compacting context. Possibly the same root cause, if T3 never sees the compaction start and so treats the overflow error as terminal.
- #5241, #18788: orphaned
opencode serveprocesses (closed; those were about backend crash/restart, not a task ending normally).