Retry pending queue after SSE recovery

This commit is contained in:
OpenClaw committed 2026-03-07 13:40:38 +08:00
1 parent 50601996af
commit c5e85f1857
2 files changed
+11 -1

No files matched your search

@@ -92,6 +92,7 @@ class RemoteOpenClawRepository(
private var messageStore by mutableStateOf<Map<String, List<ChatMessage>>>(emptyMap()) private var messageStore by mutableStateOf<Map<String, List<ChatMessage>>>(emptyMap())
private var streamStatusStore by mutableStateOf<Map<String, String>>(emptyMap()) private var streamStatusStore by mutableStateOf<Map<String, String>>(emptyMap())
private val sessionSortKeyStore = mutableMapOf<String, Long>() private val sessionSortKeyStore = mutableMapOf<String, Long>()
private val streamRecoveryQueueDrainPending = mutableSetOf<String>()
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>()
@@ -628,6 +629,11 @@ class RemoteOpenClawRepository(
try { try {
streamStatusStore = streamStatusStore + (sessionId to "live") streamStatusStore = streamStatusStore + (sessionId to "live")
syncSessionStreamStatus(sessionId) syncSessionStreamStatus(sessionId)
if (streamRecoveryQueueDrainPending.remove(sessionId)) {
runCatching { retryAutoRecoverableMessages(sessionId) }
runCatching { drainPendingTextQueue(sessionId) }
runCatching { drainPendingAttachmentQueue(sessionId) }
}
sseStream.connect(sessionId).collect { event -> sseStream.connect(sessionId).collect { event ->
when (event) { when (event) {
is SessionStreamEvent.Snapshot -> { is SessionStreamEvent.Snapshot -> {
@@ -722,6 +728,7 @@ class RemoteOpenClawRepository(
is SessionStreamEvent.Failed -> { is SessionStreamEvent.Failed -> {
val dto = event.payload val dto = event.payload
if (!dto.recoverable) { if (!dto.recoverable) {
streamRecoveryQueueDrainPending.remove(sessionId)
streamStatusStore = streamStatusStore + (sessionId to "failed") streamStatusStore = streamStatusStore + (sessionId to "failed")
syncSessionStreamStatus(sessionId) syncSessionStreamStatus(sessionId)
messageStore = messageStore + ( messageStore = messageStore + (
@@ -737,6 +744,7 @@ class RemoteOpenClawRepository(
updateSessionPreview(sessionId, previewMessage(messageStore[sessionId].orEmpty())) updateSessionPreview(sessionId, previewMessage(messageStore[sessionId].orEmpty()))
return@collect return@collect
} }
streamRecoveryQueueDrainPending.add(sessionId)
streamStatusStore = streamStatusStore + (sessionId to "reconnecting") streamStatusStore = streamStatusStore + (sessionId to "reconnecting")
syncSessionStreamStatus(sessionId) syncSessionStreamStatus(sessionId)
// recoverable: will retry via outer while loop // recoverable: will retry via outer while loop
@@ -746,6 +754,7 @@ class RemoteOpenClawRepository(
} catch (e: CancellationException) { } catch (e: CancellationException) {
throw e throw e
} catch (_: Throwable) { } catch (_: Throwable) {
streamRecoveryQueueDrainPending.add(sessionId)
streamStatusStore = streamStatusStore + (sessionId to "reconnecting") streamStatusStore = streamStatusStore + (sessionId to "reconnecting")
syncSessionStreamStatus(sessionId) syncSessionStreamStatus(sessionId)
delay(1500) delay(1500)
+2 -1
View File
@@ -207,7 +207,8 @@ Android/iOS App
- [x] Repository 的核心写状态入口已开始复用派生状态映射:新增 `textStatusForLocalPhase()` / `attachmentStatusForLocalPhase()`,用于统一写入手动处理中、队列处理中、失败态、完成态,减少散落的状态字符串 - [x] Repository 的核心写状态入口已开始复用派生状态映射:新增 `textStatusForLocalPhase()` / `attachmentStatusForLocalPhase()`,用于统一写入手动处理中、队列处理中、失败态、完成态,减少散落的状态字符串
- [x] 又收了一轮边角判断:文本入队去重、auto-retry 候选过滤、本地 retainable/failure 判定开始复用派生状态辅助函数,继续减少裸 `status == ...` 分支 - [x] 又收了一轮边角判断:文本入队去重、auto-retry 候选过滤、本地 retainable/failure 判定开始复用派生状态辅助函数,继续减少裸 `status == ...` 分支
- [ ] 还没有完整的离线发送队列(当前已覆盖文本 + 附件,但还没有更完整的网络感知、后台 drain 与统一淘汰策略) - [ ] 还没有完整的离线发送队列(当前已覆盖文本 + 附件,但还没有更完整的网络感知、后台 drain 与统一淘汰策略)
- [ ] 还没有真正基于网络恢复信号的自动补发 - [x] 已补第一版“网络恢复后继续处理待发队列”:当会话 SSE 从 recoverable failed / reconnecting 回到 live 时,会顺手尝试 auto-retry + drain 当前会话的文本/附件 pending
- [ ] 还没有更完整的网络恢复策略(目前先基于会话 SSE 恢复触发,不含更底层网络监听或全局后台队列调度)
### 4.2 附件后端主链路 ### 4.2 附件后端主链路