Skip to content

[code-review] wailskit chat.go: text/hidden runs never bump runGeneration (#504 guard defeated) + SendHiddenText missing turn reset (#514 residue) #522

Description

@topcheer

[code-review] wailskit chat.go: 文本/隐藏运行不递增 runGeneration(#504 守卫失效)+ SendHiddenText 缺 turn 重置(#514 残留)

独立复核:ver-6(全部写点/读点 grep 核验,代码级推演闭合)。

Bug A(中)— runGeneration 只在 SendContent 路径递增,#504 emitIfCurrent 守卫对文本运行失效

文件: desktop/wailskit/chat.go L563/568(sendMessageData)、L3279/3281(SendHiddenText)、L4100/4112(SendContent,唯一正确路径)

问题: runGeneration 写点仅 3 处:setRunPersistSnapshot L676(唯一调用点 SendContent L4100)、clearRunPersistSnapshot L686(全仓零调用,死代码)、ClearCurrentSession L723。文本/隐藏运行只读不增。

触发场景: ① SendMessage 启动运行 gen=N → ② 用户取消:Cancel() L583-615 调 cancel 后立即置 b.cancel=nil,不 bump generation → ③ RunStream 回调仍在排空尾部事件(L570-574 注释自认的窗口)→ ④ 用户重发文本:busy 检查通过,新运行 gen 仍=N → ⑤ 旧运行迟到回调 emitIfCurrent(N, ev) 判非 stale → 旧运行事件写入新会话 liveHistory/前端流。

预期 vs 实际: emitIfCurrent 自身文档(L698-700)声称 "or a newer run started" 会使旧运行事件自弃——对文本路径该不变量被违反。#504 只覆盖会话清除与新多模态运行两种 bump 来源。

附带: persistGeneration 字段只写不读(L677),同为死代码。

Bug C(中)— SendHiddenText 缺 startDesktopTurnLocked,run_done 携带上一轮 turn_id

文件: desktop/wailskit/chat.go L3225-3285

问题: SendHiddenText 安装 cancel、重置 finished——全程无 startDesktopTurnLocked(对比 sendMessageData L453、SendContent L4015 的 #514 修复)。放大器:emit 的 default 分支 L2216 调 desktopTurnSnapshot(),L243-245 只要 desktopTurnID != "" 就复用旧值并继续递增 seq——隐藏运行的回复文本事件全部挂到上一轮 turn_id/assistant_id 上。

触发场景: defer 排空路径 L476-477/L4034-4035:可见运行刚结束(desktopTurnID=刚结束那轮),排空的隐藏消息走 SendHiddenText,其回复在 liveHistory 追加到上一轮 assistant 消息上。启动后首次 SendHiddenText(LAN chat 注入)则发空 turn_id。与 #514 修复注释描述的症状逐字吻合。

严重度: 均为中(显示层污染/消息归属错乱;磁盘 JSONL 不受影响)。修复模式现成:A=在 sendMessageData/SendHiddenText 运行启动时 bump runGeneration;C=照抄 L4015 一行加 startDesktopTurnLocked。

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions