fix: resolve Windows gateway reconnect race condition and translate comments (#787)
This commit is contained in:
committed by
GitHub
Unverified
parent
d8750e135b
commit
c3a735a49c
@@ -154,9 +154,10 @@ export function createSessionActions(
|
||||
|
||||
switchSession: (key: string) => {
|
||||
const { currentSessionKey, messages, sessionLastActivity, sessionLabels } = get();
|
||||
// 仅将没有任何历史记录且无活动时间的会话视为空会话。
|
||||
// 单纯依赖 messages.length 是不可靠的,因为 switchSession 会在真正调用 loadHistory 前抢先清空当前 messages,
|
||||
// 造成竞争条件,使得带有真实历史的会话被判定为空并从侧边栏移除。
|
||||
// Only treat sessions with no history records and no activity timestamp as empty.
|
||||
// Relying solely on messages.length is unreliable because switchSession clears
|
||||
// the current messages before loadHistory runs, creating a race condition that
|
||||
// could cause sessions with real history to be incorrectly removed from the sidebar.
|
||||
const leavingEmpty = !currentSessionKey.endsWith(':main')
|
||||
&& messages.length === 0
|
||||
&& !sessionLastActivity[currentSessionKey]
|
||||
@@ -253,7 +254,7 @@ export function createSessionActions(
|
||||
// sessions.reset archives (renames) the session JSONL file, making old
|
||||
// conversation history inaccessible when the user switches back to it.
|
||||
const { currentSessionKey, messages, sessionLastActivity, sessionLabels } = get();
|
||||
// 仅将没有任何历史记录且无活动时间的会话视为空会话
|
||||
// Only treat sessions with no history records and no activity timestamp as empty
|
||||
const leavingEmpty = !currentSessionKey.endsWith(':main')
|
||||
&& messages.length === 0
|
||||
&& !sessionLastActivity[currentSessionKey]
|
||||
@@ -294,8 +295,8 @@ export function createSessionActions(
|
||||
// This mirrors the "leavingEmpty" logic in switchSession so that creating
|
||||
// a new session and immediately navigating away doesn't leave a ghost entry
|
||||
// in the sidebar.
|
||||
// 同样需要综合检查 sessionLastActivity 和 sessionLabels,
|
||||
// 防止因为 switchSession 抢先清空 messages 而误判有历史的会话为空。
|
||||
// Also check sessionLastActivity and sessionLabels comprehensively to prevent
|
||||
// falsely treating sessions with history as empty due to switchSession clearing messages early.
|
||||
const isEmptyNonMain = !currentSessionKey.endsWith(':main')
|
||||
&& messages.length === 0
|
||||
&& !sessionLastActivity[currentSessionKey]
|
||||
|
||||
Reference in New Issue
Block a user