fc02348ebd
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>