@@ -2,6 +2,37 @@
22 # TODO write cancels assistant message
33
44 - Session: 017549ac3301e35884ed78aa7063ead8
5-- Assistant completed work, called the todo message without content to clear and got an error
6-- session is currupted after resume.
7-- Expected: Assistant reply after calling todo tool, even if it errored. Session to not be corrupted after resume
5+
6+```
7+Error: LLM stream failed: stream request status 400:
8+{"type":"error","error":{"type":"invalid_request_error","message":"messages.38.content.1: unexpected `tool_use_id` found in `tool_result`
9+blocks: toolu_01Mq8eCePrJUNK7eQJU2MopD. Each `tool_result` block must have a corresponding `tool_use` block in the previous
10+message."},"request_id":"req_011CYArEN9fedd36dxC3Mr8i"}event: ping
11+data: {"type":"ping","cost":"0"}
12+```
13+
14+Error flow:
15+
16+Do some work, a few messages all good.
17+When work is done, last assistant message is blank, last action was a tool call to TodoWrite that returned an error.
18+
19+User sends another message, all works.
20+
21+**User exits and resumes**
22+
23+Can't send new messages, see's the error above.
24+
25+FACTS:
26+
27+- Happened after a tool call with no assistant message as the last message. (this is a bug alone).
28+- Same symptoms as the other "no assistant message at the end" scenarios as:
29+ - `ESC` (adds a syntetic message "User interrupted") to avoid this issue
30+ - and CTRL+c which is un-addressed(but not the cause here, not used in this error flow)
31+- Before restoring, the session resumes gracefully, message ordering is correct. (in memory?)
32+- After restoring from the db, the session is broken and the error complains about missing tool calls.
33+
34+Conclusion: DB message order and "live" session message order are not a match, they aren't the same.
35+
36+Fix: Need to investigate the assistent reply with no content, what happened?, And could empty content messages with only tool calls being filtered out?
37+ This same symptom was/is present when the assistant response is interrupted or the app exists with CTRL+C, maybe it's the same bug. causing the mismatch between db and live session?
38+ Audit the code so the db is the source of truth, in memory only to render the TUI (with a cap as it is today)