fix: reconcile the running state when the app returns

A turn that starts or ends while the app is in the background leaves no
event behind, so the activity strip kept its old state (stayed visible
after the turn ended) and the sidebar's running marks went stale too.

- on return, read the server's active set and the transcript tail once
  and settle both the open chat's strip and the sidebar from them
- do the same on the first event after the stream reconnects, since a
  silent drop loses the same events without leaving the app
- opening a chat whose turn is already under way asks once, so the strip
  is right from the first frame
- when the server cannot answer, the tail decides (an assistant message
  without a completion time is a live turn); a failed request is never
  read as "everything is idle"
This commit is contained in:
blumia committed 2026-11-25 00:23:50 +08:00
1 parent 9564019a91
commit 00564fe94b
5 files changed
+139 -10

No files matched your search

+15
View File
@@ -5,6 +5,21 @@
---
## 0.4.16 回到前台后重新对账运行状态(分支 `flutter`)
| 项 | 结果 |
| --- | --- |
| 问题 | 会话进行到一半把应用切到后台,期间这一轮结束了:回到前台时对话区会刷新出新内容,但输入框上方的运行状态条还停在切走时的样子(该消失却没消失)。侧栏的运行标记同样只看事件流,漏掉结束事件后也会一直转 |
| 会话状态条 | 回前台时不再只重载转录,还会读一次 `GET /api/session/active`,再按服务器答复重新算「这一轮是否在跑」:在跑就显示、结束就收起。服务器没答上来时退回转录尾部(最新一条 assistant 消息还没有 `completed` 时间就是在跑),不会把一次失败的请求当成「全部空闲」 |
| 侧栏 | 回前台时刷新活动会话集合(`refreshActive`),侧栏的运行标记与后台会话的嵌套标记随之更新;服务器明确答复后才覆盖本地集合,请求失败保留原状态 |
| 事件流重连 | 同一套对账也挂在事件流恢复后的第一个事件上:socket 静默断过(不一定切过后台)而漏掉「这一轮结束」时,状态条和侧栏同样会自愈 |
| 打开会话 | 打开一个已经在中途的会话时也问一次服务器,状态条从第一帧就是对的(以前要等下一批事件才知道在跑) |
| 测试 | 新增 `test/running_state_test.dart`:服务器说空闲/在跑、服务器无答复时按转录尾部判断(有未完成的 assistant 消息算在跑,全部完成则不算);83 项全过 |
| 验证 | 模拟器:另一个会话里跑一轮长命令 → 切到后台 → 等这一轮结束 → 回到前台:状态条不再出现,侧栏该会话的运行标记消失;再验回前台时仍在进行的一轮保持显示 |
| 版本 | **0.4.16(code 416)** |
---
## 0.4.15 后台任务条细节:外观一致、停止移到弹层、宠物站位(分支 `flutter`)
| 项 | 结果 |