Repository navigation
fix(gui): prevent message flicker and data loss from race conditions - #59
Merged
Merged
Conversation
Add a generation counter (messagesGenRef) shared across concurrent message writers to protect against overwrites between: - Cache background refresh (direct replacement) vs streaming upserts (useRunReattach functional updater) — preserves live bubbles via merge instead of clobbering them, then skips the full projection+merge when the raw entry count is unchanged. - First load / reloadMessagesQuiet (direct replacement) vs real-time user-message events (future:agent-event functional updater) — bumps gen after each event write so in-flight loads see the change and discard their stale snapshot. - reloadMessagesQuiet settle path (useRunReattach settle effect) uses force=true to skip gen checks since the streaming interval has stopped and the persisted reply is authoritative. Also filters mid-run partial snapshots (save_callback entries without a runId) from the restored array when a streaming bubble is active, preventing duplicate rendering of the same assistant turn.
huichen
force-pushed
the
fix/gui-message-race-condition
branch
2 times, most recently
from
July 28, 2026 05:39
699afdb to
af7f9b6
Compare
huichen
added a commit
that referenced
this pull request
Sep 27, 2026
…0) (#879) #877 (coverage) carried a stale gitlink and reverted the pin #872 had just moved, so `main` pointed at 1ece355 while the skills repo had moved on. Restore the pin to 23925fc (future-skills main), which is the same content #872 shipped. Skills repo commits covered by the range 1ece355..23925fc: - #57 document task write scopes and safe dependency wiring - #59 repair builtin lookup/design helpers, retire unsafe review generator - #58 future-slides defaults to editable decks with native validation - light-weight code-development skill (future-code) - #60 coalesced supervisor delivery for future-loop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
setMessages(restored)直接替换,覆盖了 useRunReattach 插入的流式气泡,导致最后一条 AI 消息消失-出现-消失-出现。改动
1. Generation counter (messagesGenRef)
在所有 messages 写入方之间共享版本号:
2. 后台刷新 merge 改为函数式更新器
缓存命中后台刷新不再用 setMessages(restored) 直接替换,改为:
stream_<runId>且其 runId 未出现在 restored 中),追加在持久化历史之后3. Entry count 跳过投影
ThreadCacheEntry 记录 raw entry 数量。后台刷新时若 entryCount 未变,跳过整个投影+merge — 流式气泡已由 useRunReattach 正常渲染。
4. 过滤 mid-run partial snapshot
dropInFlightSnapshot() — 定位最后一条 user 消息之后、无 runId 且非 compaction divider 的 assistant 消息并剔除。
文件