From ad4de3cbeb284a52b8db0824cac82d06491c431e Mon Sep 17 00:00:00 2001 From: OpenClaw Date: Sat, 7 Mar 2026 12:49:56 +0800 Subject: [PATCH] Expose pending queue status in chat --- .../kotlin/cn/xiaobai/openclawapp/App.kt | 7 ++++ .../cn/xiaobai/openclawapp/data/Models.kt | 6 +++ .../openclawapp/data/OpenClawRepository.kt | 1 + .../data/RemoteOpenClawRepository.kt | 37 ++++++++++++++----- .../openclawapp/feature/chat/ChatScreen.kt | 15 ++++++++ docs/MVP_PROGRESS.md | 1 + 6 files changed, 58 insertions(+), 9 deletions(-) diff --git a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/App.kt b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/App.kt index 111ec13..20b8e54 100644 --- a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/App.kt +++ b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/App.kt @@ -194,6 +194,13 @@ private fun OpenClawRoot(appState: OpenClawAppState) { isLoading = appState.isSyncing, errorMessage = appState.syncError, streamStatus = appState.repository.streamStatusFor(activeSession.id), + pendingQueueStatus = appState.repository.pendingQueueStatus(activeSession.id).let { queue -> + when { + queue.isDraining && queue.sessionCount > 0 -> "当前会话还有 ${queue.sessionCount} 条待发消息,系统正在按本地队列继续发送。" + queue.sessionCount > 0 -> "当前会话还有 ${queue.sessionCount} 条待发消息未完成,可继续重试或等待下一次自动处理。" + else -> null + } + }, cacheNotice = if (appState.isShowingCachedData) { "当前展示的是本地缓存${appState.cacheSavedAt?.let { "(保存于 $it)" } ?: ""},正在等待最新数据。" } else null, diff --git a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/Models.kt b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/Models.kt index adaa176..26ffbf7 100644 --- a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/Models.kt +++ b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/Models.kt @@ -41,3 +41,9 @@ data class ServerStatus( val defaultAgent: String, val updatedAt: String, ) + +data class PendingQueueStatus( + val totalCount: Int = 0, + val sessionCount: Int = 0, + val isDraining: Boolean = false, +) diff --git a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/OpenClawRepository.kt b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/OpenClawRepository.kt index 7f11794..8478cc4 100644 --- a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/OpenClawRepository.kt +++ b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/OpenClawRepository.kt @@ -11,6 +11,7 @@ interface OpenClawRepository { fun findSession(sessionId: String): SessionSummary? fun messagesFor(sessionId: String): List + fun pendingQueueStatus(sessionId: String? = null): PendingQueueStatus fun recentSession(): SessionSummary? fun pinnedCount(): Int fun markSessionOpened(sessionId: String) diff --git a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/RemoteOpenClawRepository.kt b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/RemoteOpenClawRepository.kt index 840b41c..2ae97cf 100644 --- a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/RemoteOpenClawRepository.kt +++ b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/RemoteOpenClawRepository.kt @@ -81,11 +81,21 @@ class RemoteOpenClawRepository( private val textRetryStore = mutableMapOf() private val pendingTextQueue = mutableMapOf() private val autoRetryMessageIds = mutableSetOf() + private var drainingSessionIds by mutableStateOf>(emptySet()) override fun findSession(sessionId: String): SessionSummary? = sessions.firstOrNull { it.id == sessionId } override fun messagesFor(sessionId: String): List = messageStore[sessionId].orEmpty() + override fun pendingQueueStatus(sessionId: String?): PendingQueueStatus { + val items = pendingTextQueue.values.filter { sessionId == null || it.sessionId == sessionId } + return PendingQueueStatus( + totalCount = pendingTextQueue.size, + sessionCount = items.size, + isDraining = sessionId?.let { it in drainingSessionIds } ?: drainingSessionIds.isNotEmpty(), + ) + } + override fun streamStatusFor(sessionId: String): String? = streamStatusStore[sessionId] override fun hydrateOverview(snapshot: OverviewSnapshot) { @@ -465,17 +475,26 @@ class RemoteOpenClawRepository( .map { it.messageId } if (candidates.isEmpty()) return false - var drained = false - for (messageId in candidates) { - val payload = pendingTextQueue[messageId] ?: continue - drained = true - runCatching { - retryMessageInternal(payload.sessionId, messageId, fromQueueDrain = true) - }.onFailure { - return drained + val targetSessionIds = pendingTextQueue.values + .filter { sessionId == null || it.sessionId == sessionId } + .map { it.sessionId } + .toSet() + drainingSessionIds = drainingSessionIds + targetSessionIds + try { + var drained = false + for (messageId in candidates) { + val payload = pendingTextQueue[messageId] ?: continue + drained = true + runCatching { + retryMessageInternal(payload.sessionId, messageId, fromQueueDrain = true) + }.onFailure { + return drained + } } + return drained + } finally { + drainingSessionIds = drainingSessionIds - targetSessionIds } - return drained } private fun clearPendingTextMessage(sessionId: String, text: String) { diff --git a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/feature/chat/ChatScreen.kt b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/feature/chat/ChatScreen.kt index 5d1f432..4c2bc68 100644 --- a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/feature/chat/ChatScreen.kt +++ b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/feature/chat/ChatScreen.kt @@ -49,6 +49,7 @@ fun ChatScreen( isLoading: Boolean, errorMessage: String?, streamStatus: String?, + pendingQueueStatus: String?, cacheNotice: String?, onBack: () -> Unit, onRetry: () -> Unit, @@ -133,6 +134,20 @@ fun ChatScreen( } } + if (pendingQueueStatus != null) { + Card( + modifier = Modifier.fillMaxWidth(), + colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.secondaryContainer.copy(alpha = 0.65f)), + ) { + Text( + text = pendingQueueStatus, + modifier = Modifier.padding(12.dp), + style = MaterialTheme.typography.bodySmall, + color = MaterialTheme.colorScheme.onSecondaryContainer, + ) + } + } + if (errorMessage != null) { Card( modifier = Modifier.fillMaxWidth(), diff --git a/docs/MVP_PROGRESS.md b/docs/MVP_PROGRESS.md index 5978116..63f20d7 100644 --- a/docs/MVP_PROGRESS.md +++ b/docs/MVP_PROGRESS.md @@ -195,6 +195,7 @@ Android/iOS App - [x] 聊天页已显式区分“自动重试中”和普通手动发送中状态 - [x] 已有第一版本地文本发送队列雏形:待发送文本会独立持久化,App 重启后可恢复并继续进入自动补发/手动重试链路 - [x] 已收紧文本队列自动补发语义:仅“从缓存恢复出的旧 queued 文本”保留一次自动补发资格;queue drain / 手动重试失败后会回到手动可重试,不再在同一次进入会话时被连打两次 +- [x] 聊天页已新增轻量 pending queue 状态提示:可看到当前会话剩余待发条数,以及系统是否正在按本地队列继续发送 - [x] 已有保守版 queue drain:`openSession()` 会尝试继续发送当前会话的待发文本,`syncRemoteIfNeeded()` 会顺序尝试全局待发文本,失败即停 - [x] 聊天页已显式区分 queue drain 状态:队列自动处理中的文本会显示“队列发送中” - [ ] 还没有完整的离线发送队列(目前先覆盖文本,不含附件)