#2556·MiMo-Code

Agents/subagents spontaneously abort "as if Esc": hourly models.dev refresh disposeAll() kills instances with running background actors; #2424 cascade amplifies prompt-stream drops

Author: Nord1cWarr1orCreated Sep 27, 2026Updated Sep 27, 2026

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.

  1. 0.1.15 adds ModelsDev.startRefresh() + watchModelsCatalogReload({ reload: () => Instance.disposeAll() }) in packages/opencode/src/cli/cmd/tui/worker.ts (~lines 20–27). Neither exists in v0.1.14.
  2. provider/models-catalog.ts startRefresh() refreshes immediately and then every 60 min. publish() notifies listeners on every actual catalog change — models.dev's api.json changes several times a day, so disposeAll() fires several times a day.
  3. project/instance.ts disposeAll() skips a directory only if the active counter is raised. That counter is raised only while an HTTP request handler is inside the instance middleware's Instance.provide (server/routes/instance/middleware.ts → project/instance.ts:141–145).
  4. A running main turn holds POST /session/:id/prompt open, 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 on server.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 hourly disposeAll), 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

  1. disposeAll must consult real busy state instead of only the HTTP-request active counter: skip directories that have any busy runner (main or actors). Either a registered per-directory "has busy runners" predicate from SessionRunState, or refcount the instance open for the lifetime of actor runs (hold enter(directory) while work is in flight, not just while a request is being served).
  2. Longer term: rebuilding provider state after a models.dev publish should not require tearing down instances at all.
  3. Reconsider onClientDisconnect → full SessionPrompt.cancel while a permission ask is pending (or debounce / cancel main only); and on any turn teardown, reject pending permission asks and emit permission.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