Tighten pending message merge matching
This commit is contained in:
1 parent
472bdef2a7
commit
39f16a8119
2 files changed
+21
-16
No files matched your search
+20
-16
@@ -656,7 +656,8 @@ class RemoteOpenClawRepository(
|
||||
private fun clearPendingTextMessage(sessionId: String, text: String) {
|
||||
val targetId = pendingTextQueue.values
|
||||
.filter { it.sessionId == sessionId && it.text == text }
|
||||
.minByOrNull { it.createdAt }
|
||||
.sortedBy { it.createdAt }
|
||||
.firstOrNull()
|
||||
?.messageId
|
||||
?: return
|
||||
pendingTextQueue.remove(targetId)
|
||||
@@ -664,6 +665,19 @@ class RemoteOpenClawRepository(
|
||||
autoRetryMessageIds.remove(targetId)
|
||||
}
|
||||
|
||||
private fun matchesPendingLocalText(local: ChatMessage, remote: ChatMessage): Boolean {
|
||||
return remote.role == MessageRole.User &&
|
||||
remote.kind == MessageKind.Text &&
|
||||
remote.text == local.text
|
||||
}
|
||||
|
||||
private fun matchesPendingLocalAttachment(local: ChatMessage, remote: ChatMessage): Boolean {
|
||||
return remote.kind == MessageKind.Attachment &&
|
||||
remote.text == local.text &&
|
||||
(local.contentType == null || remote.contentType == local.contentType) &&
|
||||
(local.sizeBytes == null || remote.sizeBytes == local.sizeBytes)
|
||||
}
|
||||
|
||||
private fun subscribeSessionStream(sessionId: String) {
|
||||
streamJob?.cancel()
|
||||
streamStatusStore = streamStatusStore + (sessionId to "connecting")
|
||||
@@ -933,14 +947,10 @@ class RemoteOpenClawRepository(
|
||||
when {
|
||||
local.isRetainableLocalTextMessage() -> {
|
||||
textRetryStore.putIfAbsent(local.id, TextRetryPayload(sessionId, local.text))
|
||||
remoteMessages.none { remote ->
|
||||
remote.role == MessageRole.User && remote.text == local.text
|
||||
}
|
||||
remoteMessages.none { remote -> matchesPendingLocalText(local, remote) }
|
||||
}
|
||||
local.isRetainableLocalAttachmentMessage() -> {
|
||||
remoteMessages.none { remote ->
|
||||
remote.kind == MessageKind.Attachment && remote.text == local.text
|
||||
}
|
||||
remoteMessages.none { remote -> matchesPendingLocalAttachment(local, remote) }
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
@@ -957,20 +967,14 @@ class RemoteOpenClawRepository(
|
||||
val pendingThinking = localPending.filter { it.id.startsWith("local-thinking-") }
|
||||
|
||||
val unmatchedPendingUsers = pendingUsers.filter { pending ->
|
||||
remoteMessages.none { remote ->
|
||||
remote.role == MessageRole.User && remote.text == pending.text
|
||||
}
|
||||
remoteMessages.none { remote -> matchesPendingLocalText(pending, remote) }
|
||||
}
|
||||
val unmatchedPendingAttachments = pendingAttachments.filter { pending ->
|
||||
remoteMessages.none { remote ->
|
||||
remote.kind == MessageKind.Attachment && remote.text == pending.text
|
||||
}
|
||||
remoteMessages.none { remote -> matchesPendingLocalAttachment(pending, remote) }
|
||||
}
|
||||
|
||||
val hasPendingUserReachedRemote = activePendingUsers.any { pending ->
|
||||
remoteMessages.any { remote ->
|
||||
remote.role == MessageRole.User && remote.text == pending.text
|
||||
}
|
||||
remoteMessages.any { remote -> matchesPendingLocalText(pending, remote) }
|
||||
}
|
||||
val shouldKeepThinking = pendingThinking.isNotEmpty() && (
|
||||
unmatchedPendingUsers.any { it.isLocalPendingActive() } ||
|
||||
|
||||
Reference in new issue
Block a user