[Bug] mimo run silently waits for checkpoint-writer after final answer
Description
In a long session, mimo run printed its complete answer (PING_OK) and a step_finish event, but the command stayed open. There were no more JSON/stdout events or user-facing status updates. I interrupted it about 82 seconds after the answer. To someone waiting for the command to finish, it looked stuck even though the main task was done.
The debug log shows why the process was still running: it was waiting for a background checkpoint-writer to finish. The code limits that shutdown wait to 120 seconds. I am reporting a silent wait after the answer, not an infinite loop.
Evidence
This happened on 2026-09-23 UTC. The run forked a private session with about 208k tokens of history and asked for a one-word reply without tools. Its JSON output had exactly three events: step_start, text: PING_OK, and step_finish.
02:43:51 checkpoint-writer child started
02:44:07 stdout: PING_OK, then step_finish(reason=stop)
02:44:07 session.prompt: classification=final exiting loop
02:44:07 session.idle published
02:44:07 session.checkpoint: count=1 timeoutMs=120000 draining checkpoint writers before shutdown
02:45:27 child still emitted internal debug events; no further JSON/stdout event
~02:45:29 I interrupted the run (about 100 seconds after launch)
As a control, I repeated the fork and prompt with MIMOCODE_DISABLE_CHECKPOINT=1. It returned PING_OK and exited normally (status 0) in 25.7 seconds, with no checkpoint drain.
Steps to reproduce
-
Use a long session whose next turn starts a checkpoint writer. A short new session may not trigger one; the observed fork had about 208k tokens of history.
-
Run a short prompt that finishes before the writer. This is the command shape I used, with the private session ID removed:
mimo run --pure --session <long-session-id> --fork \ --model xiaomi/mimo-v2.6-pro --agent plan \ --format json --print-logs --log-level DEBUG \ '请不要调用任何工具,只回复 PING_OK。这是诊断请求,不要继续原任务。' -
The answer and
step_finisharrive, but the process remains open without another JSON event. The debug log saysdraining checkpoint writers before shutdown.
This depends on checkpoint timing, so it may not reproduce on every run.
Expected behavior
After the main answer, either exit promptly or tell the caller that mimo run is waiting for a checkpoint writer and show the wait limit. In JSON mode, a structured wait event would let scripts distinguish background maintenance from a hung foreground request.
Relevant code
cli/bootstrap.ts awaits checkpoint writers during shutdown. session/checkpoint.ts sets the 120-second default. cli/cmd/run.ts filters child message events from primary output. These files match upstream main in my local build; my local patch changes unrelated tool-batch handling.
Environment
- MiMoCode:
0.1.14-local.mimo-batch.20260922 - Model:
xiaomi/mimo-v2.6-pro - OS: Fedora Linux 44, x86-64
- Terminal: headless, non-interactive
mimo run - Plugins: ran with
--pure; no plugin behavior appears in the relevant trace
Related: #1896 reports a TUI /rebuild spinner. #1867 reports a checkpoint writer that repeatedly calls the model without tools; the writer here did execute a read tool.
Confirmed on a clean checkout of 1579e7d, and I think the wait is less timing-dependent than the report assumes: any headless mimo run that still has a writer registered when execute() returns pays this wait, and the shutdown budget is smaller than the duration the code itself expects a writer to need.
Anchors, upstream 1579e7d, no local patches:
$ git rev-parse HEAD
1579e7d9ee5fca87b707c3892dc725316674a9d6
$ grep -nE "return await cb\(\)|drainWriters|Instance\.dispose" packages/opencode/src/cli/bootstrap.ts
15: return await cb()
27: SessionCheckpoint.Service.use((svc) => svc.drainWriters()),
29: await Instance.dispose()
$ grep -nE "120_000|60-180s|300_000" packages/opencode/src/session/checkpoint.ts
1121: // v2 writers manage 3 file types and frequently take 60-180s, so the
1138: Effect.timeout(300_000),
1170: const timeoutMs = input?.timeoutMs ?? 120_000
$ grep -n "if (printing) process.stderr.write" packages/opencode/src/util/log.ts
120: if (printing) process.stderr.write(msg)
Two consequences that seem to matter more than the 82s you measured.
The budget contradicts itself. checkpoint.ts:1121 says v2 writers "frequently take 60-180s", and waitForWriterSettlement bounds on that at 300s (:1138). The shutdown drain caps at 120s (:1170). So for any writer in the 120-180s band the run pays the full 120 seconds of silence and still loses the checkpoint: bootstrap.ts:22-25 says outright that writers which do not settle in time "are abandoned - the runtime teardown will kill them anyway". That band is not an edge case if 60-180s is the normal spread.
Nothing can be printed from where the wait happens. The drain is in bootstrap's finally, i.e. after execute() returned (run.ts:721), so the SDK event stream your JSON printer consumes is already closed; a structured wait event cannot originate there without moving the drain. And the one notice that does exist, log.info("draining checkpoint writers before shutdown"), reaches a terminal only when printing is set, which is --print-logs (log.ts:120). That is exactly why you saw it under --print-logs --log-level DEBUG and a plain run shows nothing at all.
To isolate the ordering from checkpoint timing I lifted the drain body verbatim from checkpoint.ts:1169-1196 onto [email protected] (the catalog version at root package.json:56), drove it through bootstrap.ts's try/finally, and varied only when the writer settles:
=== A: writer would settle at 150s (inside the 60-180s band), drain cap 120s ===
1.5s stdout | {"type":"text","text":"PING_OK"}
1.5s stdout | {"type":"step_finish","reason":"stop"}
121.5s EXIT | process exits here (drain result {"drained":0,"timedOut":1})
=== B: writer settles at 95s, drain cap 120s ===
1.5s stdout | {"type":"text","text":"PING_OK"}
1.5s stdout | {"type":"step_finish","reason":"stop"}
95.0s EXIT | process exits here (drain result {"drained":1,"timedOut":0})
B is your run. A is the one worth fixing first: 120 seconds of silence, timedOut: 1, and no checkpoint written.
Fix, cheapest first:
bootstrap.tsalready computes the number it needs and throws it away -drainWriters()returns{drained, timedOut}and the result is discarded at:27. Whenpending > 0, write one line to stderr before the wait ("waiting up to 120s for 1 checkpoint writer") and one after with the result. stderr keeps--format jsonstdout clean, and both TUI and JSON callers stop looking hung. Small, no architecture change.- For a structured JSON event, the drain has to move inside
execute()while the stream is still open, not sit inbootstrap'sfinally. - Pick one number. 120s shutdown vs 300s settlement bound vs a 60-180s expected duration guarantees a band where the caller waits the maximum and gets nothing for it. Either raise the drain cap to 300s, or detach the writer so
mimo runnever blocks on it.
The operational shape here is generic: a process that is alive, has emitted its last output, and is neither progressing nor exiting - a caller cannot tell that from wedged. We hit this class often enough to keep a check that reports process state and log staleness together rather than either alone (ours): https://github.com/aron-intframe/agent-guards/blob/main/guards/is-running.sh