Add derived local pending message phases

This commit is contained in:
OpenClaw committed 2026-03-07 13:21:42 +08:00
1 parent 9c006b8ed1
commit a6119aeb46
4 files changed
+46 -13

No files matched your search

@@ -47,3 +47,31 @@ data class PendingQueueStatus(
val sessionCount: Int = 0, val sessionCount: Int = 0,
val isDraining: Boolean = false, val isDraining: Boolean = false,
) )
enum class LocalMessagePhase {
Idle,
QueueProcessing,
AutoRetrying,
ManualProcessing,
Failed,
Completed,
}
fun ChatMessage.localMessagePhase(): LocalMessagePhase {
return when (status) {
"queue-draining" -> LocalMessagePhase.QueueProcessing
"retrying-auto" -> LocalMessagePhase.AutoRetrying
"queued", "uploading" -> LocalMessagePhase.ManualProcessing
"send-failed", "upload-failed" -> LocalMessagePhase.Failed
"uploaded" -> LocalMessagePhase.Completed
else -> LocalMessagePhase.Idle
}
}
fun ChatMessage.isLocalPendingActive(): Boolean {
return localMessagePhase() in setOf(
LocalMessagePhase.QueueProcessing,
LocalMessagePhase.AutoRetrying,
LocalMessagePhase.ManualProcessing,
)
}
@@ -3,6 +3,7 @@ package cn.xiaobai.openclawapp.data
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import cn.xiaobai.openclawapp.data.isLocalPendingActive
import cn.xiaobai.openclawapp.network.MobileGatewayApi import cn.xiaobai.openclawapp.network.MobileGatewayApi
import cn.xiaobai.openclawapp.network.SessionSummaryDto import cn.xiaobai.openclawapp.network.SessionSummaryDto
import cn.xiaobai.openclawapp.network.SessionStreamEvent import cn.xiaobai.openclawapp.network.SessionStreamEvent
@@ -880,7 +881,7 @@ class RemoteOpenClawRepository(
localPending: List<ChatMessage>, localPending: List<ChatMessage>,
): List<ChatMessage> { ): List<ChatMessage> {
val pendingUsers = localPending.filter { it.isRetainableLocalTextMessage() } val pendingUsers = localPending.filter { it.isRetainableLocalTextMessage() }
val activePendingUsers = pendingUsers.filter { it.status != "send-failed" } val activePendingUsers = pendingUsers.filter { it.isLocalPendingActive() }
val pendingAttachments = localPending.filter { it.isRetainableLocalAttachmentMessage() } val pendingAttachments = localPending.filter { it.isRetainableLocalAttachmentMessage() }
val pendingThinking = localPending.filter { it.id.startsWith("local-thinking-") } val pendingThinking = localPending.filter { it.id.startsWith("local-thinking-") }
@@ -901,7 +902,7 @@ class RemoteOpenClawRepository(
} }
} }
val shouldKeepThinking = pendingThinking.isNotEmpty() && ( val shouldKeepThinking = pendingThinking.isNotEmpty() && (
unmatchedPendingUsers.any { it.status != "send-failed" } || unmatchedPendingUsers.any { it.isLocalPendingActive() } ||
(hasPendingUserReachedRemote && remoteMessages.lastOrNull()?.role != MessageRole.Assistant) (hasPendingUserReachedRemote && remoteMessages.lastOrNull()?.role != MessageRole.Assistant)
) )
@@ -930,13 +931,13 @@ class RemoteOpenClawRepository(
return id.startsWith("local-") && return id.startsWith("local-") &&
role == MessageRole.User && role == MessageRole.User &&
kind == MessageKind.Text && kind == MessageKind.Text &&
status in setOf("queued", "queue-draining", "retrying-auto", "send-failed") (isLocalPendingActive() || status == "send-failed")
} }
private fun ChatMessage.isRetainableLocalAttachmentMessage(): Boolean { private fun ChatMessage.isRetainableLocalAttachmentMessage(): Boolean {
return id.startsWith("local-") && return id.startsWith("local-") &&
kind == MessageKind.Attachment && kind == MessageKind.Attachment &&
status in setOf("queue-draining", "uploading", "upload-failed") (isLocalPendingActive() || status == "upload-failed")
} }
private fun rebuildSessionSortKeysFromSnapshot(items: List<OverviewSessionSnapshot>) { private fun rebuildSessionSortKeysFromSnapshot(items: List<OverviewSessionSnapshot>) {
@@ -34,8 +34,10 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.text.style.TextOverflow
import cn.xiaobai.openclawapp.data.ChatMessage import cn.xiaobai.openclawapp.data.ChatMessage
import cn.xiaobai.openclawapp.data.LocalMessagePhase
import cn.xiaobai.openclawapp.data.MessageKind import cn.xiaobai.openclawapp.data.MessageKind
import cn.xiaobai.openclawapp.data.MessageRole import cn.xiaobai.openclawapp.data.MessageRole
import cn.xiaobai.openclawapp.data.localMessagePhase
import cn.xiaobai.openclawapp.ui.EmptyStateCard import cn.xiaobai.openclawapp.ui.EmptyStateCard
import cn.xiaobai.openclawapp.ui.StatusPill import cn.xiaobai.openclawapp.ui.StatusPill
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
@@ -325,15 +327,16 @@ private fun MessageBubble(
val isStructuredOutput = isToolResult && looksStructuredOutput(displayText) val isStructuredOutput = isToolResult && looksStructuredOutput(displayText)
val shouldCollapseToolResult = isToolResult && displayText.length > 240 val shouldCollapseToolResult = isToolResult && displayText.length > 240
val toolResultText = if (shouldCollapseToolResult && !expanded) displayText.take(240).trimEnd() + "…" else displayText val toolResultText = if (shouldCollapseToolResult && !expanded) displayText.take(240).trimEnd() + "…" else displayText
val localPhase = message.localMessagePhase()
val displayStatus = when { val displayStatus = when {
animateText && visibleChars < message.text.length -> "streaming" animateText && visibleChars < message.text.length -> "streaming"
message.kind == MessageKind.Attachment && message.status == "queue-draining" -> "队列上传中" localPhase == LocalMessagePhase.QueueProcessing && message.kind == MessageKind.Attachment -> "队列上传中"
message.status == "queue-draining" -> "队列发送中" localPhase == LocalMessagePhase.QueueProcessing -> "队列发送中"
message.status == "retrying-auto" -> "自动重试中" localPhase == LocalMessagePhase.AutoRetrying -> "自动重试中"
message.status == "queued" -> "发送中" message.status == "queued" -> "发送中"
message.status == "send-failed" -> "发送失败" message.status == "send-failed" -> "发送失败"
message.status == "uploading" -> "上传中" message.status == "uploading" -> "上传中"
message.status == "uploaded" -> "已上传" localPhase == LocalMessagePhase.Completed && message.kind == MessageKind.Attachment -> "已上传"
message.status == "upload-failed" -> "上传失败" message.status == "upload-failed" -> "上传失败"
message.status == "tool-running" -> "执行中" message.status == "tool-running" -> "执行中"
message.status == "tool-done" -> "已完成" message.status == "tool-done" -> "已完成"
@@ -433,13 +436,13 @@ private fun MessageBubble(
} }
} }
} }
if (message.status == "queue-draining") { if (localPhase == LocalMessagePhase.QueueProcessing) {
Text( Text(
text = "系统正在按本地待发队列继续上传这个附件…", text = "系统正在按本地待发队列继续上传这个附件…",
style = MaterialTheme.typography.bodySmall, style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant, color = MaterialTheme.colorScheme.onSurfaceVariant,
) )
} else if (message.status == "uploading") { } else if (localPhase == LocalMessagePhase.ManualProcessing) {
Text( Text(
text = "正在手动发起附件上传…", text = "正在手动发起附件上传…",
style = MaterialTheme.typography.bodySmall, style = MaterialTheme.typography.bodySmall,
@@ -525,21 +528,21 @@ private fun MessageBubble(
style = if (isSystemNotice) MaterialTheme.typography.bodyMedium else MaterialTheme.typography.bodyLarge, style = if (isSystemNotice) MaterialTheme.typography.bodyMedium else MaterialTheme.typography.bodyLarge,
color = if (isSystemNotice) MaterialTheme.colorScheme.onSurfaceVariant else MaterialTheme.colorScheme.onSurface, color = if (isSystemNotice) MaterialTheme.colorScheme.onSurfaceVariant else MaterialTheme.colorScheme.onSurface,
) )
if (message.status == "queue-draining") { if (localPhase == LocalMessagePhase.QueueProcessing) {
Text( Text(
text = "系统正在按本地待发队列继续发送这条消息…", text = "系统正在按本地待发队列继续发送这条消息…",
style = MaterialTheme.typography.bodySmall, style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant, color = MaterialTheme.colorScheme.onSurfaceVariant,
) )
} }
if (message.status == "retrying-auto") { if (localPhase == LocalMessagePhase.AutoRetrying) {
Text( Text(
text = "系统正在尝试恢复发送这条消息…", text = "系统正在尝试恢复发送这条消息…",
style = MaterialTheme.typography.bodySmall, style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant, color = MaterialTheme.colorScheme.onSurfaceVariant,
) )
} }
if (message.retryable && message.status == "send-failed") { if (message.retryable && localPhase == LocalMessagePhase.Failed && message.status == "send-failed") {
TextButton(onClick = { onRetryMessage(message.id) }) { TextButton(onClick = { onRetryMessage(message.id) }) {
Text("重试发送") Text("重试发送")
} }
+1
View File
@@ -202,6 +202,7 @@ Android/iOS App
- [x] 附件上传状态已开始对齐队列语义:队列自动处理中的附件会显示“队列上传中”,与手动上传中的“上传中”分开 - [x] 附件上传状态已开始对齐队列语义:队列自动处理中的附件会显示“队列上传中”,与手动上传中的“上传中”分开
- [x] 已修复 `RemoteOpenClawRepository` 的 JVM 重载撞签名:原先两个 `rebuildSessionSortKeys(List<...>)` 因泛型擦除冲突,现已拆成 `rebuildSessionSortKeysFromSnapshot(...)` / `rebuildSessionSortKeysFromSessions(...)` - [x] 已修复 `RemoteOpenClawRepository` 的 JVM 重载撞签名:原先两个 `rebuildSessionSortKeys(List<...>)` 因泛型擦除冲突,现已拆成 `rebuildSessionSortKeysFromSnapshot(...)` / `rebuildSessionSortKeysFromSessions(...)`
- [x] 已补本地 pending 保留逻辑:refresh / SSE snapshot 不再只保留 `queued` 文本;`queue-draining` / `retrying-auto` / 本地附件 pending 也会保留,避免队列处理中消息被快照冲掉 - [x] 已补本地 pending 保留逻辑:refresh / SSE snapshot 不再只保留 `queued` 文本;`queue-draining` / `retrying-auto` / 本地附件 pending 也会保留,避免队列处理中消息被快照冲掉
- [x] 已抽出本地 pending 派生状态:新增 `LocalMessagePhase` 与 `localMessagePhase()` / `isLocalPendingActive()`,开始统一 UI 与本地保留逻辑对 pending 状态的判断,减少散落的字符串分支
- [ ] 还没有完整的离线发送队列(当前已覆盖文本 + 附件,但还没有更完整的网络感知、后台 drain 与统一淘汰策略) - [ ] 还没有完整的离线发送队列(当前已覆盖文本 + 附件,但还没有更完整的网络感知、后台 drain 与统一淘汰策略)
- [ ] 还没有真正基于网络恢复信号的自动补发 - [ ] 还没有真正基于网络恢复信号的自动补发