Chat UI: accept canonical main session key alias

This commit is contained in:
Mariano Belinky
2026-02-18 19:17:08 +00:00
committed by mbelinky
parent 6e7f1a6a1b
commit 2c22b2c3c3
2 changed files with 69 additions and 1 deletions

View File

@@ -447,7 +447,10 @@ public final class OpenClawChatViewModel {
// even when this view currently uses an alias key (for example "main").
// Never drop events for our own pending run on key mismatch, or the UI can stay
// stuck at "thinking" until the user reopens and forces a history reload.
if let sessionKey = chat.sessionKey, sessionKey != self.sessionKey, !isOurRun {
if let sessionKey = chat.sessionKey,
!Self.matchesCurrentSessionKey(incoming: sessionKey, current: self.sessionKey),
!isOurRun
{
return
}
if !isOurRun {
@@ -481,6 +484,21 @@ public final class OpenClawChatViewModel {
}
}
private static func matchesCurrentSessionKey(incoming: String, current: String) -> Bool {
let incomingNormalized = incoming.trimmingCharacters(in: .whitespacesAndNewlines).lowercased()
let currentNormalized = current.trimmingCharacters(in: .whitespacesAndNewlines).lowercased()
if incomingNormalized == currentNormalized {
return true
}
// Common alias pair in operator clients: UI uses "main" while gateway emits canonical.
if (incomingNormalized == "agent:main:main" && currentNormalized == "main") ||
(incomingNormalized == "main" && currentNormalized == "agent:main:main")
{
return true
}
return false
}
private func handleAgentEvent(_ evt: OpenClawAgentEventPayload) {
if let sessionId, evt.runId != sessionId {
return