open-webui/backend/open_webui/socket
Claude 06f4656f5e
fix(stream): sort replay by seq, skip log in REALTIME mode, strict flush order
Critical: INCR and XADD are separate calls, so with overlapping
emitters the stream's append order can diverge from seq order (a
concurrent emitter can win INCR for seq N+1 yet lose XADD and land
ahead of seq N in the stream). Replay returned entries in append
order, which meant the later-seq-but-earlier-in-stream frame would
advance lastSeq, permanently dropping the earlier-seq-but-later-in-
stream frame via the client dedupe guard. Fix: _stream_log_read now
sorts envelopes by seq before returning, making replay order
independent of append order.

Warning: loadChat now unconditionally triggers resume for unfinished
assistants with last_seq=0, which in ENABLE_REALTIME_CHAT_SAVE mode
(DB is kept up-to-date per token) would replay content already
loaded from the DB and produce duplicates. Gate _stream_seq_allocate
on `not ENABLE_REALTIME_CHAT_SAVE` — in realtime mode frames emit
without a seq, nothing is logged, client bypasses dedupe/resume, DB
stays authoritative for refresh recovery.

Suggestion: fence flush sort comparator returned 0 for mixed
seq/no-seq pairs, which is not strict ordering. Replaced with a
partition (seq-bearing vs. seq-less) + sort the seq-bearing subset +
concat. Deterministic regardless of engine sort stability.
2026-04-14 22:31:02 +00:00
..
main.py fix(stream): sort replay by seq, skip log in REALTIME mode, strict flush order 2026-04-14 22:31:02 +00:00
utils.py refac 2026-03-22 05:48:05 -05:00