BUG-Old sessions (pre-0.1.12) unresponsive after upgrade: message ID format change breaks string-comparison ordering
Summary
After upgrading to 0.1.12, all OLD sessions (created with 0.1.10/0.1.11) stop responding: new user messages are persisted to the DB but the prompt loop never executes. Messages appear "eaten", render in the WRONG position (above older assistant replies), and TUI shows them as QUEUED even after an assistant reply exists. Sessions freshly created in 0.1.12 work fine.
Additional symptom: forced session reset
When the prompt loop repeatedly fails (classification=final exiting loop), the system may automatically reset the session context — deleting historical messages and starting fresh. On this machine:
- RailRevivalSim (438 messages → 8) — full history wiped
- Max开发 (hundreds of messages → 13) — effectively reset
- RailwayRenaissance session was also observed as a "new conversation" after reset
The reset mechanism is unclear but appears to be a safety valve triggered when the session loop detects irresolvable stuck state (possibly via compact/summarize, checkpoint-writer failure, or a distinct compaction heuristic). The original messages are physically deleted from the database (not just compressed), so recovery requires a pre-reset backup. This compounds the user impact: not only do messages get eaten, but the entire conversation history can be silently lost.
Critically, resetting the session does NOT fix the underlying ID-ordering problem — new messages in the reset session will still be eaten until the root cause is addressed.
Root Cause (confirmed with binary + DB evidence)
Message ID format changed between versions, breaking string-comparison ordering.
| Version | Message ID format | Example |
|---|---|---|
| ≤0.1.11 | msg_<hex> with 5th char a letter |
msg_fdc599680001ACBpSgkTgZzxuC |
| 0.1.12 | msg_000... with 5th char a digit |
msg_0009fd508001UqxullkteCT2Ws |
Since ASCII '0' (0x30) < 'f' (0x66), every new-format ID sorts before every old-format ID in a mixed session.
1. Server prompt loop misclassifies message order
Extracted (deobfuscated) classifier from mimo.exe 0.1.12:
function Cs(H) {
let $ = H.assistant;
if (H.parts.some(t => t.type==="tool" && !t.metadata?.providerExecuted && t.state.status!=="error")) return {type:"continue"};
if (!$.finish) return {type:"continue"};
if ($.finish==="tool-calls" && !$.error && H.lastUser.id<$.id && ...) return {type:"text-tool-call"};
if ($.finish==="tool-calls") return {type:"continue"};
if (H.phase==="existing-assistant" && !(H.lastUser.id < $.id)) return {type:"continue"};
// ^^^^^^^^^^^^^^^^^^^^^^^^^ string ID comparison!
...
if (parts have text) return {type:"final"}; // <-- affected sessions land here
}
For old sessions: "msg_0009..." < "msg_fdc5..." is ALWAYS true (string compare), so the classifier skips the continue branch and returns {type:"final"} → loop exits without calling the model. Log evidence from a real session:
INFO service=session.prompt session.id=ses_02015043dffe466a0lhrMpNGLA step=0 loop
INFO service=session.prompt session.id=ses_02015043dffe466a0lhrMpNGLA classification=final exiting loop
2. TUI renders messages ordered by ID string → mixed sessions show new messages ABOVE old replies
Users literally see their new message inserted before already-answered content, and a new reply generated in the wrong spot.
3. TUI QUEUED badge stuck
Orphan assistant messages (no time.completed) wedge the TUI pending pointer; subsequent messages stay QUEUED even after a real reply exists. Two confirmed orphan assistant rows (zero text parts, created but never completed) were found in the affected sessions.
Scope
Real-user sessions with leftover old-format IDs after the upgrade. This machine: 28 sessions, 3692 old-format message IDs (e.g. sessions created under 0.1.10/0.1.11 with hundreds/thousands of messages — Claw remote approval 1374 msgs, Fix mimo.cmd 657, AP课程 276, etc.).
Related upstream issues (MiMo Code is an opencode fork)
- anomalyco/opencode#13577 — same root cause: string ID comparison in loop termination (
lastUser.id < lastAssistant.id) - anomalyco/opencode#30809 — out-of-order message IDs → wrong parent binding in prompt loop; upstream fix direction: bind completion to parentID relationship instead of ID sort order
- anomalyco/opencode#16856 — QUEUED tag stuck on orphan assistant message (
time.completed == null) - anomalyco/opencode#21524 — idle session not woken by prompt
The upstream #30809 fix (compare via parentID/timestamp instead of ID strings) is the correct official fix.
Full investigation log (what we tried, in order)
- Hypothesis: orphaned actor state.
actor_registryshowed thousands of rows withlast_error="orphaned: process restarted",last_outcome="failure", and a few non-persistent subagent rows. Deleted 365 orphanedmainactor rows → did NOT fix (symptom persisted; also wiped a lot of legitimate actor state — lesson: don't scrub the registry before confirming the code path). - Hypothesis: config corruption.
mimocode.jsonchad an invalidmcp.githubentry (https://api.github.com/mcp, not a valid MCP endpoint) → CLI fatalConfigInvalidErroron startup. Fixed by removing the entry. Separate issue, not the root cause. - Hypothesis: stale git lock blocking checkpoint-writer.
D:\Unity Project\RailwayRenaissance\.git\index.lockexisted (leftover from a killedgitduring an orphaned run). Removed it — unblocked one background checkpoint-writer, but main-session messages still didn't execute. - Hypothesis: checkpoint-writer zombie looping. Observed
> checkpoint-writeragent responding instead of the main agent; permissions auto-rejected headless. Not the root cause. - Confirmed root cause by extracting the classifier
Csfrom the binary and matching theclassification=final exiting looplog line, then correlating with the ID format split in the DB. - Confirmed secondary effect — TUI ordering + QUEUED badge — by checking message sort order (
ORDER BY idplaces allmsg_000...before allmsg_fd...) and finding orphan assistant rows missingtime.completed.
What I did to unblock (data-level workaround, NOT a patch)
All on local DB copies (backups kept at ~/.mimocode_home/data/mimocode.db.bak_*):
- Removed invalid
mcp.githubconfig (separate startup-fatal bug). - Wiped obsolete actor rows / cleared stuck states where needed (explored, partly reverted).
- Rewrote 3692 old-format message IDs to
msg_{time:016x}{rand}in 28 real sessions, keepingpart.message_id,message.data.parentID, andsession.last_checkpoint_message_idin sync, so ID order == time order again. - Flipped the last assistant's
finishto"tool-calls"in 22 sessions so the classifier takes thecontinuebranch (temporary band-aid; no longer needed after ID rewrite). - Patched orphan assistant messages with
time.completedso TUI clears the QUEUED badge. - Restored one fully reset session (RailRevivalSim, 438 messages) from a pre-reset DB backup copy.
After the ID rewrite the sessions respond correctly and retain history (verified with mimo run -s <session> and in the TUI).
Suggested official fix
- Required: in the prompt-loop classifier (and any other message-ordering logic), compare by
time.createdor byparentIDrelationship — never by rawmessage.idstring order (align with opencode#30809). Fix both the classification branch shown above and the loop-termination condition. - Also: TUI message ordering should use
time_created, not ID strings, so mixed-format sessions render chronologically. - Defensive / migration: on load, detect sessions containing mixed ID formats and normalize, or at least sort by timestamp everywhere IDs are compared.
- TUI: make the
pending/QUEUED computation resilient to orphan assistant messages withouttime.completed(opencode#16856).
Environment
- MiMo Code 0.1.12 (@mimo-ai/cli), Windows 11
- Sessions created with 0.1.10 / 0.1.11 and continued after upgrading to 0.1.12
- DB:
~/.mimocode_home/data/mimocode.db(SQLite, WAL mode)
same problem