Auto-retry restored queued messages on open
This commit is contained in:
1 parent
946249d994
commit
8762e2c805
3 files changed
+27
-1
No files matched your search
@@ -125,7 +125,11 @@ class OpenClawAppState(
|
|||||||
isSyncing = true
|
isSyncing = true
|
||||||
runCatching {
|
runCatching {
|
||||||
remote.refreshMessages(sessionId)
|
remote.refreshMessages(sessionId)
|
||||||
|
val autoRetried = remote.retryAutoRecoverableMessages(sessionId)
|
||||||
persistRecentMessageCache(remote, preferredSessionId = sessionId)
|
persistRecentMessageCache(remote, preferredSessionId = sessionId)
|
||||||
|
if (autoRetried) {
|
||||||
|
feedbackMessage = "已自动重试恢复的待发消息"
|
||||||
|
}
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
syncError = it.message ?: "会话消息加载失败"
|
syncError = it.message ?: "会话消息加载失败"
|
||||||
feedbackMessage = "消息加载失败"
|
feedbackMessage = "消息加载失败"
|
||||||
|
|||||||
+20
@@ -70,6 +70,7 @@ class RemoteOpenClawRepository(
|
|||||||
private val attachmentRetryStore = mutableMapOf<String, AttachmentRetryPayload>()
|
private val attachmentRetryStore = mutableMapOf<String, AttachmentRetryPayload>()
|
||||||
private val attachmentOpenStore = mutableMapOf<String, AttachmentOpenPayload>()
|
private val attachmentOpenStore = mutableMapOf<String, AttachmentOpenPayload>()
|
||||||
private val textRetryStore = mutableMapOf<String, TextRetryPayload>()
|
private val textRetryStore = mutableMapOf<String, TextRetryPayload>()
|
||||||
|
private val autoRetryMessageIds = mutableSetOf<String>()
|
||||||
|
|
||||||
override fun findSession(sessionId: String): SessionSummary? = sessions.firstOrNull { it.id == sessionId }
|
override fun findSession(sessionId: String): SessionSummary? = sessions.firstOrNull { it.id == sessionId }
|
||||||
|
|
||||||
@@ -331,6 +332,23 @@ class RemoteOpenClawRepository(
|
|||||||
updateSessionPreview(sessionId, merged.lastOrNull())
|
updateSessionPreview(sessionId, merged.lastOrNull())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun retryAutoRecoverableMessages(sessionId: String): Boolean {
|
||||||
|
val candidates = messageStore[sessionId].orEmpty()
|
||||||
|
.filter { it.id in autoRetryMessageIds && it.role == MessageRole.User && it.kind == MessageKind.Text && it.status == "send-failed" }
|
||||||
|
.map { it.id }
|
||||||
|
if (candidates.isEmpty()) return false
|
||||||
|
|
||||||
|
var attempted = false
|
||||||
|
for (messageId in candidates) {
|
||||||
|
attempted = true
|
||||||
|
autoRetryMessageIds.remove(messageId)
|
||||||
|
runCatching {
|
||||||
|
retryMessage(sessionId, messageId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return attempted
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun sendMessageRemote(sessionId: String, text: String) {
|
suspend fun sendMessageRemote(sessionId: String, text: String) {
|
||||||
sendMessage(sessionId, text)
|
sendMessage(sessionId, text)
|
||||||
runCatching {
|
runCatching {
|
||||||
@@ -347,6 +365,7 @@ class RemoteOpenClawRepository(
|
|||||||
val retried = current.map { msg ->
|
val retried = current.map { msg ->
|
||||||
if (msg.id == messageId) msg.copy(status = "queued", retryable = false, createdAt = "现在") else msg
|
if (msg.id == messageId) msg.copy(status = "queued", retryable = false, createdAt = "现在") else msg
|
||||||
}
|
}
|
||||||
|
autoRetryMessageIds.remove(messageId)
|
||||||
val withThinking = if (retried.none { it.id.startsWith("local-thinking-") }) {
|
val withThinking = if (retried.none { it.id.startsWith("local-thinking-") }) {
|
||||||
retried + ChatMessage(
|
retried + ChatMessage(
|
||||||
id = "local-thinking-$sessionId-${retried.size + 1}",
|
id = "local-thinking-$sessionId-${retried.size + 1}",
|
||||||
@@ -533,6 +552,7 @@ class RemoteOpenClawRepository(
|
|||||||
return when {
|
return when {
|
||||||
domain.role == MessageRole.User && domain.kind == MessageKind.Text && domain.status == "queued" -> {
|
domain.role == MessageRole.User && domain.kind == MessageKind.Text && domain.status == "queued" -> {
|
||||||
textRetryStore[domain.id] = TextRetryPayload(sessionId, domain.text)
|
textRetryStore[domain.id] = TextRetryPayload(sessionId, domain.text)
|
||||||
|
autoRetryMessageIds.add(domain.id)
|
||||||
domain.copy(status = "send-failed", retryable = true)
|
domain.copy(status = "send-failed", retryable = true)
|
||||||
}
|
}
|
||||||
domain.role == MessageRole.User && domain.kind == MessageKind.Text && domain.status == "send-failed" -> {
|
domain.role == MessageRole.User && domain.kind == MessageKind.Text && domain.status == "send-failed" -> {
|
||||||
|
|||||||
@@ -184,8 +184,9 @@ Android/iOS App
|
|||||||
- [x] App 重启后,缓存里的 `queued` 文本会恢复成可重试的 `send-failed`
|
- [x] App 重启后,缓存里的 `queued` 文本会恢复成可重试的 `send-failed`
|
||||||
- [x] App 重启后,缓存里的 `uploading` 附件会恢复成明确失败态,避免假性卡死
|
- [x] App 重启后,缓存里的 `uploading` 附件会恢复成明确失败态,避免假性卡死
|
||||||
- [x] 手动刷新/重新进入会话时,会保留本地尚未被远端确认的失败消息,避免刷新后直接消失
|
- [x] 手动刷新/重新进入会话时,会保留本地尚未被远端确认的失败消息,避免刷新后直接消失
|
||||||
|
- [x] 从缓存恢复出来的 `queued` 文本,在重新进入会话时会自动尝试补发一次
|
||||||
- [ ] 还没有离线发送队列
|
- [ ] 还没有离线发送队列
|
||||||
- [ ] 还没有网络恢复后的自动补发
|
- [ ] 还没有真正基于网络恢复信号的自动补发
|
||||||
|
|
||||||
### 4.2 附件后端主链路
|
### 4.2 附件后端主链路
|
||||||
|
|
||||||
@@ -374,3 +375,4 @@ Android/iOS App
|
|||||||
- 2026-03-07:修复了 cached-data 相关编译错误:补回 `OpenClawAppState` 中缺失的 `isShowingCachedData` / `cacheSavedAt` 状态字段,并移除了 `MobileGatewayApi` 中未使用且不兼容的 `decodeBase64Bytes` import。
|
- 2026-03-07:修复了 cached-data 相关编译错误:补回 `OpenClawAppState` 中缺失的 `isShowingCachedData` / `cacheSavedAt` 状态字段,并移除了 `MobileGatewayApi` 中未使用且不兼容的 `decodeBase64Bytes` import。
|
||||||
- 2026-03-07:补强发送失败状态缓存:发送/重试消息、上传/重试附件后会及时刷新最近消息缓存;App 重启后,缓存中的 `queued` 文本会转成可重试失败态,缓存中的 `uploading` 附件会转成明确失败态,避免 UI 长时间停留在假性发送中。
|
- 2026-03-07:补强发送失败状态缓存:发送/重试消息、上传/重试附件后会及时刷新最近消息缓存;App 重启后,缓存中的 `queued` 文本会转成可重试失败态,缓存中的 `uploading` 附件会转成明确失败态,避免 UI 长时间停留在假性发送中。
|
||||||
- 2026-03-07:补强消息刷新合并逻辑:手动刷新或重新进入会话时,若某条本地失败消息尚未被远端 history 确认,不会被 `refreshMessages()` 直接覆盖掉,而是继续保留在时间线里供用户重试。
|
- 2026-03-07:补强消息刷新合并逻辑:手动刷新或重新进入会话时,若某条本地失败消息尚未被远端 history 确认,不会被 `refreshMessages()` 直接覆盖掉,而是继续保留在时间线里供用户重试。
|
||||||
|
- 2026-03-07:新增第一版自动恢复补发:仅针对“从缓存恢复出来、原本处于 `queued` 的文本消息”,在重新进入会话时自动尝试补发一次;若仍失败,则继续保留为可手动重试状态。
|
||||||
Reference in new issue
Block a user