Agents/subagents spontaneously abort "as if Esc": hourly models.dev refresh disposeAll() kills instances with running background actors; #2424 cascade amplifies prompt-stream drops
Description
Since 0.1.15, agents and sub-agents spontaneously abort as if the user pressed Esc — but nobody touched the keyboard. This happens with background actors running after the main turn has ended (the standard subagent workflow), and occasionally to whole sessions at once. On 0.1.14 this never happened over weeks of the same unattended usage.
Root cause (source-level, tag v0.1.15 = 14dfe68)
Trigger 1 — new in 0.1.15: hourly models.dev refresh disposes instances that have running actors.
- 0.1.15 adds
ModelsDev.startRefresh()+watchModelsCatalogReload({ reload: () => Instance.disposeAll() })inpackages/opencode/src/cli/cmd/tui/worker.ts(~lines 20–27). Neither exists inv0.1.14. provider/models-catalog.tsstartRefresh()refreshes immediately and then every 60 min.publish()notifies listeners on every actual catalog change — models.dev'sapi.jsonchanges several times a day, sodisposeAll()fires several times a day.project/instance.tsdisposeAll()skips a directory only if theactivecounter is raised. That counter is raised only while an HTTP request handler is inside the instance middleware'sInstance.provide(server/routes/instance/middleware.ts→project/instance.ts:141–145).- A running main turn holds
POST /session/:id/promptopen, so it is protected. But background actors/subagents hold no HTTP request →active == 0→ the directory is disposed while they run:disposeInstance→ScopedCache.invalidate(effect/instance-state.ts:51) closes the run-state scope → the run-state finalizer (session/run-state.ts:61–69) cancels every runner of every session in that directory → all background subagents are interrupted mid-run, status forced idle, TUI silently re-bootstraps onserver.instance.disposed. The processor stamps abort markers (Tool execution aborted/interrupted) — indistinguishable from a user Esc.
Trigger 2 — amplified by #2424: prompt-stream drop now kills the whole session's actors.
server/routes/instance/session.ts:1303–1311 calls SessionPrompt.cancel (full session abort) whenever the prompt HTTP stream's client disconnects. In 0.1.14, SessionRunState.cancel targeted only runnerKey(sessionID, "main") (session/run-state.ts:101), so a stream drop killed only main and background actors finished their work. #2424 (merged 2026-09-18, in 0.1.15) made cancel cascade to every runner of the session, so any spurious disconnect (network flap, socket stall after resume, driver-side timeout) now wipes main + all subagents at once — again looking exactly like Esc.
Regression
- 0.1.14: no
startRefresh/watchModelsCatalogReload(no hourlydisposeAll), and cancel did not cascade to actors. Weeks of unattended subagent usage — zero phantom interrupts. - 0.1.15: both mechanisms landed; phantom interrupts reproduce within days of normal use.
Related: #2502 documents a downstream casualty — a bash_delete permission prompt orphaned when its turn was auto-interrupted (nothing rejects pending asks on teardown, and the TUI has no defense; the client half is analyzed there).
Suggested fix
disposeAllmust consult real busy state instead of only the HTTP-requestactivecounter: skip directories that have any busy runner (main or actors). Either a registered per-directory "has busy runners" predicate fromSessionRunState, or refcount the instance open for the lifetime of actor runs (holdenter(directory)while work is in flight, not just while a request is being served).- Longer term: rebuilding provider state after a models.dev publish should not require tearing down instances at all.
- Reconsider
onClientDisconnect→ fullSessionPrompt.cancelwhile a permission ask is pending (or debounce / cancel main only); and on any turn teardown, reject pending permission asks and emitpermission.replied(#2502's server half).
Workaround (until fixed)
MIMOCODE_DISABLE_MODELS_FETCH=1 makes startRefresh() a no-op (flag/flag.ts:175, checked in startRefresh), removing the hourly disposeAll bursts. Cost: the model catalog stays frozen at snapshot/cache.
Environment
- MiMoCode 0.1.15 (regression; not present on 0.1.14)
- Linux (Arch-based), TUI
Source: XiaomiMiMo/MiMo-Code