mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-04 21:20:18 +08:00
Post-stream finalisation appended buffered events one at a time, each in its own fsync'd commit (connection open + turn lookup + MAX(seq) + INSERT + UPDATE + COMMIT per event). On slow storage this dominates turn finalisation: on a NAS with spinning disks each commit took ~0.65 s, so a 550-event turn kept the client spinner running for ~6 minutes after the answer had fully streamed, because the terminal done event is only published after the flush. Add SQLiteSessionStore.append_turn_events, which assigns seqs and inserts the whole batch inside one transaction (measured: 501 events in ~6 ms), and make _flush_buffered_events prefer it, keeping the per-event path as a fallback for stores without batch support. When the turn has vanished (session deleted mid-drain) the flush now logs one summary line instead of one warning per buffered event.