diff --git a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/app/OpenClawAppState.kt b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/app/OpenClawAppState.kt index 51a6162..d20f481 100644 --- a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/app/OpenClawAppState.kt +++ b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/app/OpenClawAppState.kt @@ -96,9 +96,13 @@ class OpenClawAppState( remote.refreshStatus() remote.refreshAgents() remote.refreshSessions() + val drained = remote.drainPendingTextQueue() preferences.saveOverviewSnapshot(remote.exportOverviewSnapshot()) persistRecentMessageCache(remote) persistPendingSendQueue(remote) + if (drained) { + feedbackMessage = "已尝试继续发送待发消息" + } isShowingCachedData = false }.onFailure { syncError = it.message ?: "远程同步失败" @@ -131,10 +135,13 @@ class OpenClawAppState( runCatching { remote.refreshMessages(sessionId) val autoRetried = remote.retryAutoRecoverableMessages(sessionId) + val drained = remote.drainPendingTextQueue(sessionId) persistRecentMessageCache(remote, preferredSessionId = sessionId) persistPendingSendQueue(remote) if (autoRetried) { feedbackMessage = "已自动重试恢复的待发消息" + } else if (drained) { + feedbackMessage = "已尝试继续发送当前会话的待发消息" } }.onFailure { syncError = it.message ?: "会话消息加载失败" 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 4d43d7a..7f11794 100644 --- a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/OpenClawRepository.kt +++ b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/OpenClawRepository.kt @@ -17,6 +17,7 @@ interface OpenClawRepository { fun togglePinned(sessionId: String): Boolean fun sendMessage(sessionId: String, text: String) suspend fun retryMessage(sessionId: String, messageId: String) + suspend fun drainPendingTextQueue(sessionId: String? = null): Boolean suspend fun updateDefaultAgent(agent: String) suspend fun uploadAttachmentStub( 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 242ba37..8b44146 100644 --- a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/RemoteOpenClawRepository.kt +++ b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/RemoteOpenClawRepository.kt @@ -443,6 +443,26 @@ class RemoteOpenClawRepository( } } + override suspend fun drainPendingTextQueue(sessionId: String?): Boolean { + val candidates = pendingTextQueue.values + .filter { sessionId == null || it.sessionId == sessionId } + .sortedBy { it.createdAt } + .map { it.messageId } + if (candidates.isEmpty()) return false + + var drained = false + for (messageId in candidates) { + val payload = pendingTextQueue[messageId] ?: continue + drained = true + runCatching { + retryMessage(payload.sessionId, messageId) + }.onFailure { + return drained + } + } + return drained + } + private fun clearPendingTextMessage(sessionId: String, text: String) { val targetId = pendingTextQueue.values .filter { it.sessionId == sessionId && it.text == text } diff --git a/docs/MVP_PROGRESS.md b/docs/MVP_PROGRESS.md index e08df36..7c20214 100644 --- a/docs/MVP_PROGRESS.md +++ b/docs/MVP_PROGRESS.md @@ -194,6 +194,7 @@ Android/iOS App - [x] 从缓存恢复出来的 `queued` 文本,在重新进入会话时会自动尝试补发一次 - [x] 聊天页已显式区分“自动重试中”和普通手动发送中状态 - [x] 已有第一版本地文本发送队列雏形:待发送文本会独立持久化,App 重启后可恢复并继续进入自动补发/手动重试链路 +- [x] 已有保守版 queue drain:`openSession()` 会尝试继续发送当前会话的待发文本,`syncRemoteIfNeeded()` 会顺序尝试全局待发文本,失败即停 - [ ] 还没有完整的离线发送队列(目前先覆盖文本,不含附件) - [ ] 还没有真正基于网络恢复信号的自动补发 @@ -398,6 +399,7 @@ Android/iOS App - 2026-03-07:补齐 session sort key 持久化:overview snapshot 现在会把每个 session 的 sort key 一并保存并在 hydrate 时恢复,减少冷启动缓存态和热态之间的排序跳变。 - 2026-03-07:继续统一 session 摘要选择逻辑:更多 preview 更新路径改为复用 `previewMessage()`,避免在 retry / snapshot merge / SSE completed / stream failed 等场景下直接拿 `lastOrNull()` 导致摘要被 thinking 占位或瞬时系统消息抢走。 - 2026-03-07:开始补真正的本地发送队列雏形:新增独立的 `PendingSendQueue` 持久化结构,与 recent message cache 分离;文本待发送项现在会单独入队、在 hydrate 时恢复,并在发送成功/失败/重试后同步维护,减少“只有界面缓存、没有真实队列语义”的不一致。 +- 2026-03-07:补上第一版 queue drain:App 现在会在 `openSession()` 时尝试继续发送当前会话的待发文本,在 `syncRemoteIfNeeded()` 时顺序尝试全局待发文本;一旦某条失败就停止,避免激进乱冲。 - 2026-03-07:继续补 SSE 顺序一致性:当消息集合未变、只是顺序发生变化时,BFF / App 现已改为通过 `message.reordered` 精确纠正顺序,避免因为 diff 只看 id/内容变化而静默漏掉重排,也避免为单纯重排走整包 snapshot。 - 2026-03-07:继续收缩 SSE 重刷范围:在消息通过 `message.removed` 逐条删空时,BFF 不再额外补发重复的空 `session.snapshot`,减少无意义整包刷新。 - 2026-03-07:补强 BFF 会话摘要语义:session 列表里的 lastMessage 预览现在会按消息类型生成前缀与截断文案(附件/工具/工具结果/思考中/系统/断流),不再只是返回裸 `text`,让附件 overlay、工具消息和聊天页预览语义更一致。