Refresh session preview on local pending states

This commit is contained in:
OpenClaw committed 2026-03-07 11:33:02 +08:00
1 parent 7d7e0718f6
commit 439c0a4a7b
2 files changed
+10 -4

No files matched your search

@@ -144,8 +144,7 @@ class RemoteOpenClawRepository(
val withoutThinking = currentMessages.filterNot { it.id.startsWith("local-thinking-") }
val localUserId = "local-user-$sessionId-${withoutThinking.size + 1}"
textRetryStore[localUserId] = TextRetryPayload(sessionId, text)
messageStore = messageStore + (
sessionId to (withoutThinking + listOf(
val next = withoutThinking + listOf(
ChatMessage(
id = localUserId,
role = MessageRole.User,
@@ -160,8 +159,9 @@ class RemoteOpenClawRepository(
createdAt = "现在",
status = "thinking",
),
))
)
messageStore = messageStore + (sessionId to next)
updateSessionPreview(sessionId, previewMessage(next))
}
override suspend fun updateDefaultAgent(agent: String) {
@@ -427,6 +427,7 @@ class RemoteOpenClawRepository(
toolCallId = dto.toolCallId,
)
messageStore = messageStore + (sessionId to next)
updateSessionPreview(sessionId, previewMessage(next))
}
}
@@ -519,6 +520,10 @@ class RemoteOpenClawRepository(
streamScope.cancel()
}
private fun previewMessage(messages: List<ChatMessage>): ChatMessage? {
return messages.lastOrNull { !it.id.startsWith("local-thinking-") } ?: messages.lastOrNull()
}
private fun updateSessionPreview(sessionId: String, lastMessage: ChatMessage?) {
val preview = lastMessage?.toSessionPreview().orEmpty()
val existing = sessions.firstOrNull { it.id == sessionId }
+2 -1
View File
@@ -152,7 +152,7 @@ Android/iOS App
结论:**可用,但后面还要继续稳固。**
补充:BFF 已开始补 diff 细节稳定性。当前已修一类典型误判——当同一条消息在一次轮询里既发生文本增长、又发生状态/类型元数据变化时,BFF 现在会同时补发 `message.completed`,避免前端只收到 delta 后停留在半完成状态。并且,BFF 也开始收敛“新消息一次性出现”的事件噪音:不再对所有新消息都连发 `started + completed`,而是仅对明显仍在进行中的消息发 `started`,其余直接发 `completed`。另外,消息消失时已不再默认整包 `session.snapshot` 重刷,而是优先发精确的 `message.removed` 事件,由 App 按 id 删除对应消息;同时 App 的 session 列表摘要也会随精确删除同步回退,不再顽固保留已被删掉的最后一条消息摘要。
补充:BFF 已开始补 diff 细节稳定性。当前已修一类典型误判——当同一条消息在一次轮询里既发生文本增长、又发生状态/类型元数据变化时,BFF 现在会同时补发 `message.completed`,避免前端只收到 delta 后停留在半完成状态。并且,BFF 也开始收敛“新消息一次性出现”的事件噪音:不再对所有新消息都连发 `started + completed`,而是仅对明显仍在进行中的消息发 `started`,其余直接发 `completed`。另外,消息消失时已不再默认整包 `session.snapshot` 重刷,而是优先发精确的 `message.removed` 事件,由 App 按 id 删除对应消息;同时 App 的 session 列表摘要也会随精确删除同步回退,不再顽固保留已被删掉的最后一条消息摘要。并且,App 现在会在本地 queued / thinking 占位写入和 SSE `message.started` 首帧到达时,同步刷新 session 列表摘要,减少“聊天页已变但列表还停在旧内容”的延迟。
### 3.2 附件能力
@@ -392,3 +392,4 @@ Android/iOS App
- 2026-03-07:BFF 收敛 SSE 新消息噪音:对于“一次 poll 才第一次看到”的新消息,不再默认连发 `message.started + message.completed`;现在仅对明显仍在进行中的 thinking/tool-running 等消息发 `started`,其余直接发 `completed`,减少前端不必要的瞬时状态抖动。
- 2026-03-07:BFF/App 联动补 `message.removed`:当某条消息在新一轮 history 中消失时,BFF 优先发精确删除事件,App 按 id 从当前时间线里移除对应消息;只有极端场景(如整个会话消息清空)才再补空 snapshot。这样比“消息一消失就整包 snapshot”更细、更稳,也更像真实事件流。
- 2026-03-07:App 补 session 摘要一致性:当 SSE 精确删除命中最后一条消息时,会话列表摘要不再保留旧值,而是同步清空/回退到当前真实最后一条,避免“聊天删了但列表还显示旧摘要”。
- 2026-03-07:继续补 session 摘要一致性:本地发送插入 queued/thinking 占位,以及 SSE `message.started` 首帧到达时,会话列表摘要现在会立即同步刷新;同时摘要优先忽略 `local-thinking-*` 占位,尽量展示真实最后一条可读消息。