[Bug] Huge session /message HTTP 500; unsafe part truncate caused blank ThreadView; schema_safe DB fix
[Bug] Huge session /message returns HTTP 500; bad truncation caused blank ThreadView; schema_safe DB repair fixed load
English title (for labels/search):
GET /session/{id}/message HTTP 500 on ~845MB session parts; frontend white-screen after aggressive part truncation; schema-safe attachment URL shortening resolved open-loop.
Summary
On MiMo Desktop (domestic) 26.914.142245 / Windows 11 x64, opening the long-running session 「校内2」 (ses_01f0db20cffeWgFFD05BByQuE3) never finished loading. Logs showed repeated:
GET /session/ses_01f0db20cffeWgFFD05BByQuE3/message -> HTTP 500
Root cause: the session (and its fork) stored ~845MB of part.data, almost entirely from read tool results embedding images in state.attachments (~16–18MB each) plus large type=file parts (base64 url). The engine serialized the whole history in one response and failed.
A second, related product issue: after an unsafe local truncation (replacing attachments with {_truncated:…}), the UI showed 「loads then goes blank」 even when /message returned 200. A schema-safe truncation (keep type/mime/url/id/sessionID/messageID, only shorten data: URLs) restored normal open.
Environment
| Item | Value |
|---|---|
| App | MiMo Desktop (国内版) |
| Version | 26.914.142245 (also observed 26.909.91205 pre-update) |
| OS | Windows 11 / Windows_NT 10.0.26300 x64 |
| RAM | 32GB |
| Data dir | %USERPROFILE%\.mimocode_home\data\mimocode.db |
| Engine logs | %USERPROFILE%\.mimocode_home\data\log\ |
| Desktop logs | %APPDATA%\Xiaomi MiMo\logs\ |
Session IDs
| Purpose | ID |
|---|---|
| 校内2 (primary) | ses_01f0db20cffeWgFFD05BByQuE3 |
| 校内 (fork #1) | ses_ffe5f466da181ffeOcUnsWua3A |
| Other 500s | e.g. ses_-ffe5f465f8e4fffe2pMUxiorx, ses_-ffe5f465f83bcffec1X009fT7 |
Expected vs actual
Expected
- Opening any historical conversation loads messages (or shows a clear error).
- Session compact/summarize reduces stored part payload and sets
time_compacting. history_ftsmigrations keep table schema in sync with code (kindcolumn).- If
/messageis huge, paginate/stream or cap tool output; never silent 500 + infinite spinner. - If messages load (HTTP 200) but render fails, show error/empty placeholder instead of pure blank.
Actual
- 校内2 / fork / siblings:
/message→ HTTP 500 (1.5–9.7s), while/task,/recovery→ 200 → infinite loading. - Built-in compact on fork1 completed (
session.compacted) butcompaction prefix snapshot missing,time_compactingstayed NULL, part bytes unchanged (~845MB); DB grew ~3GB → ~6.5GB. - Every engine boot:
history.backfill ... SQLiteError: table history_fts has no column named kind
andhistory.writerwrite failed (same error). - After wrong local repair: HTTP 200 + ThreadView blank (
white-screenscrollHeight: 4900 → 859). - After schema_safe repair: live DB ~802MB, 校内2
/message200 (~136ms), no further 500s in 2026-09-20 logs.
Reproduction (original bug)
- Open MiMo Desktop 26.914.142245 on Windows.
- Open conversation 校内2.
- Observe perpetual loading.
- Check
%APPDATA%\Xiaomi MiMo\logs\*.log→ repeated
GET /session/ses_01f0db20.../message -> HTTP 500.
(With the schema_safe DB installed, step 3 succeeds — keep a 6.5GB sample backup if you need to repro on stock data.)
Full timeline of our attempts
| # | Action | Result |
|---|---|---|
| 1 | Diagnosed logs | Only /message 500; meta endpoints 200 |
| 2 | Read-only SQLite | 校内2: 2842 msgs / 9582 parts / ~886MB part bytes; 79 parts >1MB; whole DB ~3GB then ~6.1GB after compact |
| 3 | Part type breakdown | tool ~792MB (almost all read); file ~50MB; text/reasoning negligible |
| 4 | Structure probe | Huge bytes were in state.attachments (list, ~17MB) not state.output (output was short string "Image read successfully") |
| 5 | Built-in compact on fork1 | summarize OK (~175s) + session.compacted, but prefix snapshot missing, no size drop, still 500 |
| 6 | Engine history_fts |
Columns: part_id, session_id, message_id, project_id, tool_name, body, time_created — missing kind |
| 7 | Full DB backup (never touched original until swap) | SQLite online backup + SHA256 under session workspace db_backup\ |
| 8 | Unsafe repair #1 (work copy) | Truncated only state.output → no size change |
| 9 | Unsafe repair #2 | Replaced state.attachments / file parts with {_truncated} objects → DB shrank (845MB→17MB/session) but attachments lost url |
| 10 | First replace-db.ps1 |
Partial: process check OK; Python -c quoting SyntaxError on backup/verify; move+install still ran (PS native errors didn’t stop script). Rollback name in script never created. |
| 11 | Observed UI after unsafe install | /message 200 but blank timeline; white-screen scrollHeight 4900→859; loadEngineSessions reconcile racing ThreadView height clear |
| 12 | Frontend analysis (from app.asar) |
streaming || finished || msgs.length>0 → xe="content" without empty placeholder; Lve(old, []) can wipe store; loadConvoMessages has silent catch {} / early return on race |
| 13 | API proof | Engine GET /session/{id}/message 200, ~3.7MB, 73–74 items; transform keeps 73/73; not an empty API |
| 14 | Schema-safe repair | Keep attachment keys type/mime/url/id/sessionID/messageID; only shorten data: URL; add history_fts.kind; VACUUM |
| 15 | Install schema_safe | Live DB ~802MB, quick_check=ok, 校内2 part ~15MB, msgs 2851 intact |
| 16 | Verify | 2026-09-20 logs: 校内2 /message 200 (~136ms); recent 500s only from 2026-09-19 22:31 (bad truncation era) |
Do not use for install: mimocode.db.current_839mb, mimocode.db.current_20260919_222019 (broken attachment shape).
Rollback large DB (if needed): E:\NMDX\NMDX-User Workspace\mimocode.db.original_20260919_205057 (~6.55GB) — note: restores 500 risk.
Evidence (logs)
# Infinite load
engineFetch GET /session/ses_01f0db20cffeWgFFD05BByQuE3/message -> HTTP 500 elapsed=3401ms
engineFetch GET /session/ses_ffe5f466da181ffeOcUnsWua3A/message -> HTTP 500 elapsed=4471ms
# history_fts migration broken
WARN service=history.backfill session=ses_01f0db20... cause=SQLiteError: table history_fts has no column named kind
WARN service=history.writer cause=SQLiteError: table history_fts has no column named kind write failed
# compact ineffective
INFO service=session.checkpoint ... deltaApproxBytes=13063663
WARN compaction prefix snapshot missing
# After schema_safe install (success)
engineFetch GET /session/ses_01f0db20cffeWgFFD05BByQuE3/message -> HTTP 200 elapsed=136ms
White-screen pattern (after unsafe truncate / session switch):
white-screen-up scrollHeight: 4900 → 859
GET .../message -> HTTP 200
# xe=content but msgs effectively empty / height cleared → pure blank
Data mass (before repair)
| Metric | 校内2 | fork #1 |
|---|---|---|
| messages | 2842–2851 | 2838 |
| parts | 9582+ | 9563 |
| part bytes | ~845–886 MB | ~845 MB |
| largest single part | ~17.9 MB | ~17.9 MB |
| tool parts >100KB | 230 | ~209 oversized tools |
Largest parts were type=tool tool=read with path like ...\Downloads\XiaoAi\相机\MVIMG_*.jpg and bulk in state.attachments.
Related issues (product)
A. /message payload / 500
- One-shot JSON of full history with embedded media is not bounded.
- Need: pagination, cursor, strip/externalize
attachments[].url(file refs), or hard cap per response.
B. Compact does not reclaim space
session.compacted+ missing prefix snapshot +time_compactingstill NULL.- Users cannot recover from oversized sessions via official compact.
C. history_fts schema drift
- Code expects
kind; table has nokind→ every backfill/writer fails. - Blocks search/history index; noisy WARN on every boot.
D. Frontend blank timeline (independent of DB health)
ThreadView: when status iscontentbutmsgs=[](or height reset to viewport 859), no empty state → looks like data loss.loadConvoMessages: silent failure / race does not write store;Lve(prev, [])can clear messages.loadEngineSessionsreconcile (~30s) can clear height in same tick as successful/message.
E. Compaction / share side noise
share-next ... status=503 failed to sync share(secondary).- Fork from huge session:
fork failed ... aborted due to timeout.
Suggested fixes (priority)
P0 – Engine
- Bound
/session/{id}/message(page/stream/limit; never unbounded 500). - Fix
history_ftsmigration: addkind(or align code to schema) and re-run backfill cleanly. - Compact must: update
time_compacting, persist prefix snapshot, delete or externalize oversizedstate.attachments/filepayloads; fail loudly if not.
P0 – Desktop UI
4. If xe==="content" and msgs.length===0, show loading/error/empty — never blank.
5. loadConvoMessages: no silent catch {}; do not apply empty payload over non-empty store without explicit clear reason; surface fetch errors.
6. Don’t clear scroll height on session reconcile when same convo is active.
P1
7. When ingesting read on binary/image, store file reference not full base64 in part forever (or GC old attachments).
8. Share sync 503 / fork timeout: clear user-visible errors.
What fixed it for us (local workaround, not a product feature)
- Backup original DB (SQLite online backup + copies on
E:\NMDX\NMDX-User Workspace\). - schema_safe truncation: for parts >64KB:
state.attachments[]: keeptype, mime, url, id, sessionID, messageID; shortenurlifdata:and huge.type=fileparts: same key preservation; shortenurl.- Optionally add
history_fts.kind. VACUUM.
- Fully quit Desktop → install repaired file as
mimocode.db→ restart. - Verify
/message200 and attachment objects still haveurl.
Never install truncation that replaces whole attachments with a non-schema object — that causes blank UI even with HTTP 200.
Acceptance criteria for fix
- [ ] Session with ≥800MB part bytes loads (or pages) without HTTP 500.
- [ ] Compact reduces
SUM(LENGTH(part.data))and setstime_compacting. - [ ] No
history_fts has no column named kindon startup after upgrade. - [ ]
/message200 + empty store never renders pure white; shows placeholder or error. - [ ] Image/file attachments still render when present (
urlintact).
Labels (suggested)
bug desktop engine history performance ui
Contact / attachments
Local evidence retained by reporter: Desktop + engine logs for 2026-09-19/20, SQLite backups, export markdown of affected chats. Can attach redacted log excerpts on request.
Follow-up (2026-09-20): post-repair "network error" / AI_DownloadError
After installing the schema_safe (~802MB) DB to fix /message HTTP 500, old conversations failed on the next turn with UI 网络错误 / reconnecting, even though outbound HTTPS was fine (GitHub 200, model host probe 200).
Root cause
Aggressive local truncation left undownloadable image placeholders in part JSON url / attachments[].url fields, e.g.:
- Invalid/truncated 1x1 PNG data URLs
data:image/png;base64,TRUNCATED/data:image/jpeg;base64,TRUNCATED_BY_REPAIR- Empty/
xxx/data:image/...;base64,...placeholders
On each prompt, engine convertToLanguageModelPrompt → downloadAssets → download() does fetch() on those URLs → AI_DownloadError: Failed to download data:image/...: TypeError: fetch failed (hundreds of times). UI surfaces this as network failure / reconnect loop.
ERROR service=llm ... error={"error":{"name":"AI_DownloadError","url":"data:image/png;base64,TRUNCATED_BY_REPAIR"}} stream error
ERROR service=session.processor ... Failed to download data:image/png;base64,TRUNCATED_BY_REPAIR: TypeError: fetch failed
at download (.../app.asar/out/main/node.mjs)
at downloadAssets
at convertToLanguageModelPrompt
at streamStep
Local mitigation (Desktop left running)
- SQLite online backup while Desktop stayed open:
mimocode.db.pre_fix_broken_img_20260920_124537(~908MB,quick_check=ok). - Replaced broken
url/ attachment URLs with a valid 1x1 PNG data URL (decoded\x89PNGheader verified). - Did not rewrite free-text in message bodies that merely mentioned those strings.
- Post-check: 0 bad tokens left in
urlfields; sample PNGs 100/100 decodable;quick_check=ok. - Last
AI_DownloadErrorburst was before this URL fix; no restart required.
Why write without quitting Desktop: history is SQLite with WAL + busy_timeout. Readers (UI/engine) and one writer can coexist; we opened a connection with a long busy timeout, UPDATE + COMMIT. Swapping the main DB file still requires the process closed — in-place row updates do not.
Expected product fixes (add to P0)
downloadAssetsmust tolerate baddata:URLs: skip undecodable/placeholder images instead of failing the wholestreamStep(or replace with a text stub). One broken history image must not abort the turn as "network error".- Repair/compaction tools that write placeholder URLs must keep them fetchable (valid PNG) or strip them from the prompt pipeline.
- Surface
AI_DownloadErrordistinctly from true network connectivity errors in the Desktop UI.
Acceptance (updated)
- [ ] Old session with placeholder/invalid
data:imagehistory can send/receive withoutAI_DownloadErroror UI 网络错误 - [ ] Broken image URL is skipped or substituted; turn continues
- [ ] Still:
/messageno 500; compact reclaims bytes;history_fts.kindpresent; ThreadView never blank on 200+empty store