xonecas.io
62159
Sy

symb / commit 5dd96bb

fix: history bug investigation

xonecas2026-02-16 5dd96bb69588a8000e1c6f9047df42362acd0425 parent a131b27

2 files changed

TODO.md+34−3
@@ -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)
cmd/symb/main.go+1−18
@@ -361,22 +361,5 @@ func loadHistory(sessionID string, db *store.Cache) []provider.Message {
361361 fmt.Printf("Warning: failed to load session history: %v\n", err)
362362 return nil
363363 }
364- msgs := storedToMessages(stored)
365- return trimIncomplete(msgs)
366-}
367-
368-// trimIncomplete removes trailing messages that form an incomplete turn.
369-// A valid history ends with an assistant message (finished response) or
370-// a system message (empty session). Trailing user/tool messages from a
371-// session killed mid-turn are dropped so the next user input doesn't
372-// create consecutive user messages which the API rejects.
373-func trimIncomplete(msgs []provider.Message) []provider.Message {
374- for len(msgs) > 0 {
375- last := msgs[len(msgs)-1]
376- if last.Role == "assistant" || last.Role == "system" {
377- break
378- }
379- msgs = msgs[:len(msgs)-1]
380- }
381- return msgs
364+ return storedToMessages(stored)
382365 }