Session permanently broken with `Invalid prompt: The messages do not match the ModelMessage[] schema.` after interrupting during post-tool snapshot finalization
Description
Environment
- Kilo CLI: 7.5.6 (VS Code extension / Agent Manager)
- OS: Windows 11 (win32)
- Provider: custom provider (
llm.runtime=ai-sdk)
Summary
After stopping a session in the window between a tool call completing and the step finishing (while the ⠙ Initializing snapshot… spinner is shown), the session's persisted transcript ends in a state that fails AI SDK prompt validation. Every subsequent prompt in that session — regardless of content — is rejected before reaching the model:
Invalid prompt: The messages do not match the ModelMessage[] schema.
{
"name": "UnknownError",
"data": {
"message": "Invalid prompt: The messages do not match the ModelMessage[] schema."
}
}
The error is recorded on a new assistant message with zero parts, and retrying only appends more empty failed messages. The session is unrecoverable from the UI (no revert point excludes the corrupt tail, since the corruption sits directly before the last user message).
Steps to reproduce
According to inspection of kilo.db of the actual broken transcript (see "Repro findings" below):
- In a session, have the agent run a
bashtool call that produces filesystem changes (so a snapshot/patch is triggered afterward). - Interrupt/stop the session immediately after the tool returns, during the post-step finalization — i.e. while the
⠙ Initializing snapshot…spinner is displayed. Do not interrupt during tool execution; that path is safe. - The transcript tail is now persisted in the corrupt shape:
- the
toolpart isstatus: "completed"(the tool itself finished), - a transient UI spinner is persisted as a real synthetic text part:
prt_05bc16a15001d170i4yPHKnxND={"type":"text","text":"⠙ Initializing snapshot…","synthetic":true,"metadata":{"kilocode.lifecycle":"transient"}} - the containing assistant message has no
step-finishpart.
- the
- Send any further prompt (e.g.
continue).
Actual result
AI_InvalidPromptError: Invalid prompt: The messages do not match the ModelMessage[] schema.thrown from the AI SDK before the request is sent (streamnever produces output).- A new empty assistant message (
msg_05bc2dc040014Y1x0pXCv8Xxd3, 0 parts) is persisted with the error. - All retries fail identically; the session is permanently dead.
Log evidence (%USERPROFILE%\.local\share\kilo\log\opencode.log):
timestamp=2026-09-01T06:58:13.218Z level=ERROR run=14934dfb message=process
session.id=ses_fa7d13eacffe1hxg9jon8ObuHv messageID=msg_05bc2dc040014Y1x0pXCv8Xxd3
error="Invalid prompt: The messages do not match the ModelMessage[] schema."
stack="AI_InvalidPromptError: ... at YOL (B:/~BUN/root/src/index.js:526:61846)"
Expected result
Either:
- the history converter sanitizes interrupted transcripts before building
ModelMessage[](drop transient lifecycle parts, finalize/repair aborted tool parts and unterminated steps), or - the invalid prompt is rejected with an actionable message and the session remains usable.
Suspected causes (from kilo.db inspection, read-only)
- Transient spinner text parts persisted into the transcript — this is the actual poison. Parts tagged
metadata["kilocode.lifecycle"] = "transient"(e.g.⠙ Initializing snapshot…) are stored inpartand are fed into the model message history. They should never leave the UI layer. Confirmed still present in the broken session after retries. - Unterminated assistant step after interrupt in the snapshot window: the assistant message ends with a
completedtoolpart followed by the transient text part and nostep-finish. The interrupt lands after the tool resolves but before the step is finalized. - Once broken, the empty error assistant message (0 parts,
error.name = "UnknownError") is itself appended to the history, compounding the invalid state.
Note: the original version of this report blamed a tool part persisted with status: "error" / "Tool execution aborted". DB inspection contradicts that: in the broken session the final tool part is status: "completed". Aborted-tool parts are not the trigger (see below).
Repro findings: why interrupting a long-running tool does NOT corrupt
Attempted repro in a fresh session (ses_fa42febe1ffeLR23p9BlBbze1j, "Start sleep 60 in bash"), 2026-09-01 07:13Z:
- Started
sleep 60via thebackground_processtool, then stopped it. - Ran
sleep 60as a foregroundbashcall and aborted it mid-execution.
Result: no corruption; subsequent prompts worked normally. Inspected transcript:
- The aborted foreground call finalized cleanly — the abort surfaced as tool output (
<shell_metadata>User aborted the command</shell_metadata>) withstate.status = "completed", not asstatus: "error". - The step still received its
step-finishpart, and nokilocode.lifecycle=transientpart was written.
So the two interrupt windows differ decisively:
| Interrupt window | Tool part state | step-finish | Transient part persisted | Session usable |
|---|---|---|---|---|
| During tool execution | completed (abort in output) |
present | no | yes |
| After tool return, during snapshot/patch finalization | completed |
missing | yes | no — permanently dead |
This narrows the fix to the post-tool finalization path: it must be atomic with respect to abort, and transient parts must never be written as real transcript parts.
Suggested fix
- Filter
kilocode.lifecycle=transientparts in the prompt/history builder (and don't persist them at all). - On interrupt/abort, write a well-formed terminal state for in-flight tool parts (
output-error) and astep-finishfor the partial step. - Exclude assistant messages that contain only an error (0 parts) from the outbound
ModelMessage[].
Workaround
Revert the last message and fork conversation
Plugins
No response
Kilo version
7.5.6
Steps to reproduce
No response
Screenshot and/or share link
No response
Operating System
Windows 11
Terminal
No response
The Invalid prompt: messages do not match ModelMessage[] deadlock is the persisted synthetic snapshot part (kilocode.lifecycle=transient) being replayed into the outbound request, the AI SDK rejects it before anything is sent so retries just append more dead messages. What got you unstuck, revert last message and fork, is the right move. To stop it recurring, those transient parts should never be written to the store at all, and a 0-part error assistant message shouldn't go into the outbound array either. oh also, btw, I keep a portable Hermes OTG around for exactly these wedged-agent moments, https://github.com/MilkyWay008/Hermes-OTG, imo it'll help you diagnose faster.