Repository navigation
Description
Summary
When a ServerProcess starts, OpenCode drains pending/interrupted sessions before the
custom-agent registry (agents/*.md from config directories) is ready. Sessions whose
agent is a custom .md agent fail to drain with Session.AgentNotFoundError, and
subagent dispatches issued in this window fail with Agent not found: "<custom-agent>".
Built-in agents (e.g. general) resolve fine in the same window.
Environment
- opencode version: 2.1.4 (update check reports current == latest)
- OS: Windows_NT 10.0.19045 (win32 x64)
- Terminal: VS Code integrated terminal (TERM_PROGRAM=vscode, TERM=xterm-256color)
- Shell: cmd.exe host; agents run PowerShell via the shell tool
- Install/channel: release (npm @opencode/cli)
- Active plugins: one local plugin at ~/.config/opencode/plugin/memory.js (loads OK; unrelated)
Reproduction
- Define custom agents in ~/.config/opencode/agent/ (e.g.
backend-dev.md, mode: subagent)
plus a custom primary agent set asdefault_agent. - Trigger a new ServerProcess start while sessions hold pending steps. Observed triggers:
service restart; a subagent session killed by a provider error (free-quota exhaustion)
leaving pending state; dispatching a subagent right after such an interruption. - Dispatch the custom subagent immediately.
- Dispatch fails:
Subagent failed (sessionID: ses_***): Agent not found: "backend-dev". - Server log at the same moment (UTC):
Failed to drain Sessioncause=Session.AgentNotFoundError: Agent not found: "backend-dev"
at SessionContext.select <- SessionRunner.prepareContext <- SessionRunner.drain <- ServerProcess.start- a second identical error ~40-60 ms later for the parent session's custom agent
(Agent not found: "nemesis"; earlier days:"fullstack-lead") - only AFTER those errors:
watcher stopped/watcher startedlines for the config/agent
directories - i.e. the agent registry loads after the drain has already run.
- Retry the same dispatch after the process is warm -> succeeds.
Expected Behavior
Drain at ServerProcess.start should wait for (or defer until) the custom agent registry
is loaded; custom agents should resolve like built-ins during drain.
Actual Behavior
Paired Session.AgentNotFoundError for every mid-flight session whose agent is a custom
.md agent; the subagent dispatch fails and the child session never runs a step. The parent
session recovers on new turns, but in-flight subagent work is lost.
Additional Context
- Intermittent: 5 failure bursts over 5 days (Oct 22 x2, Oct 24, Oct 27 x3), stack identical
every time (always ServerProcess.start -> drain). - Custom-agent dispatches succeed whenever the ServerProcess is warm; failures cluster right
after service interruptions/idle-unload windows and after quota-killed subagent sessions. - Built-in
generalsubagent succeeded in the same window in which custom agents failed -
points at registry load ordering, not session corruption. - All agent definition files were present and parseable throughout (frontmatter verified).
- Workarounds: retry after warm-up; route work to built-in
general; set
experimental.location_idle_timeout: falseto reduce cold starts (just applied, unverified).
Activity
opencode-agent commentedon Oct 27, 2026
Thanks for the detailed report. I tried to reproduce this on 2.1.4 but couldn't get the error.
What I tried, with a simulated model:
backend-devset asdefault_agent, defined in the global config dir (bothagents/andagent/).After the restart the session continued on
backend-dev("Continuing after restart"), and the server log had noFailed to drain SessionorSession.AgentNotFoundError. I also added a local plugin with a slowsetupto make the startup window longer, and still saw no drain errors. Those runs show less, though: the simulated model wasn't available after the restart, so I couldn't confirm the resumed turn actually ran.These would help narrow it down:
Failed to drain Session, including anyloading pluginlines and thedirectory/ location values on the session and watcher lines. I'd like to see whether the failing sessions belong to a different project directory than the one whose config was loading.opencodeper terminal? How many projects or directories does it usually have open?~/.config/opencode/agent/(singular) oragents/? Isdefault_agentset in the global config or in a project config? Does the project have its own.opencode/directory?You can reply here or edit the issue. If you edit it, please also leave a comment so we know you're done. Related issues, in case one matches what you see:
Agent not founderror during a plugin reload. That one is fixed in 2.2.0, which waits for plugin reloads before each step.Session.AgentNotFoundError) #53500: what happens to a session after its drain fails because the agent is missing.opencode plugin listprints "No plugins found" on the first call per cold location #54654: another first-use problem in a not-yet-loaded project (plugin listis empty on the first call).Tarquinen commentedon Nov 2, 2026
Thanks for the report! We couldn't reproduce this and haven't heard back, so I'm closing this issue. If it still happens on the latest version, please open a new issue with your logs and steps to reproduce.
— from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊