fix: prevent message loss on abort by deferring DB writes to flush (#591)

Defer all non-user message DB writes until response completion or
abort, instead of writing tool calls immediately during streaming.
This ensures correct message ordering and prevents the abort handler
from overwriting displayed messages with incomplete DB data.

- Remove immediate addMessage() calls from response.output_item.done
- Remove immediate addMessage() from insertResponseTextOnce
- Add flushResponseRunToDb() to batch-write all run messages on
  both normal completion (markCompleted) and abort (handleAbort)
- Skip user messages in flush (already written in handleRun)
- Remove refreshActiveSession() from abort.completed frontend handler

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
ekko
2026-05-10 04:10:01 +08:00
committed by GitHub
parent 50122c5ff8
commit fc02348ebd
2 changed files with 33 additions and 33 deletions
@@ -827,9 +827,6 @@ export const useChatStore = defineStore('chat', () => {
}
})
cleanup()
if (sid === activeSessionId.value) {
void refreshActiveSession()
}
setAbortState(null)
break
}
@@ -1268,9 +1265,6 @@ export const useChatStore = defineStore('chat', () => {
}
})
cleanup()
if (sid === activeSessionId.value) {
void refreshActiveSession()
}
setAbortState(null)
break
}