Skip to content

Commit ff74edb

Browse files
authored
fix(ios): preserve pre-upgrade Watch replies
Bind shipped notification prompts without routing metadata to the current Gateway once, while keeping explicit and persisted Gateway owners fail-closed.
1 parent 725615a commit ff74edb

2 files changed

Lines changed: 43 additions & 3 deletions

File tree

apps/ios/Sources/Model/NodeAppModel.swift

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3293,10 +3293,23 @@ extension NodeAppModel {
32933293
return
32943294
}
32953295
let payloadGatewayID = event.gatewayStableID?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
3296-
let sourceGatewayID = payloadGatewayID.isEmpty
3297-
? (self.watchMessageOutbox.gatewayStableID(forPromptID: event.promptId) ?? "")
3298-
: payloadGatewayID
32993296
let currentGatewayID = self.currentWatchChatGatewayStableID()
3297+
let routedGatewayID = self.watchMessageOutbox.gatewayStableID(forPromptID: event.promptId) ?? ""
3298+
let sourceGatewayID: String
3299+
if !payloadGatewayID.isEmpty {
3300+
sourceGatewayID = payloadGatewayID
3301+
} else if !routedGatewayID.isEmpty {
3302+
sourceGatewayID = routedGatewayID
3303+
} else if let currentGatewayID {
3304+
// Shipped prompts predate gateway routing metadata and cannot be migrated after delivery.
3305+
// Bind that prompt once; explicit or persisted owners never use this fallback.
3306+
sourceGatewayID = currentGatewayID
3307+
self.watchMessageOutbox.recordPromptRoute(
3308+
promptID: event.promptId,
3309+
gatewayStableID: currentGatewayID)
3310+
} else {
3311+
sourceGatewayID = ""
3312+
}
33003313
if !sourceGatewayID.isEmpty, let currentGatewayID, currentGatewayID != sourceGatewayID {
33013314
self.watchReplyLogger.info("watch reply dropped: stale gateway target")
33023315
return

apps/ios/Tests/NodeAppModelInvokeTests.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2124,6 +2124,33 @@ private final class MockBootstrapNotificationCenter: NotificationCentering, @unc
21242124
#expect(appModel._test_queuedWatchReplyCount() == 0)
21252125
}
21262126

2127+
@Test @MainActor func watchReplyBindsLegacyPromptToCurrentGateway() async {
2128+
NodeAppModel._test_resetPersistedWatchReplyQueueState()
2129+
defer { NodeAppModel._test_resetPersistedWatchReplyQueueState() }
2130+
let watchService = MockWatchMessagingService()
2131+
let appModel = NodeAppModel(watchMessagingService: watchService)
2132+
appModel.enterAppleReviewDemoMode()
2133+
let initialOpenChatRequestID = appModel.openChatRequestID
2134+
let event = WatchQuickReplyEvent(
2135+
replyId: "reply-legacy-prompt",
2136+
promptId: "prompt-from-previous-release",
2137+
actionId: "approve",
2138+
actionLabel: "Approve",
2139+
sessionKey: "main",
2140+
gatewayStableID: nil,
2141+
note: nil,
2142+
sentAtMs: 1238,
2143+
transport: "sendMessage")
2144+
2145+
watchService.emitReply(event)
2146+
await Task.yield()
2147+
watchService.emitReply(event)
2148+
await Task.yield()
2149+
2150+
#expect(appModel.openChatRequestID == initialOpenChatRequestID + 1)
2151+
#expect(appModel._test_queuedWatchReplyCount() == 0)
2152+
}
2153+
21272154
@Test @MainActor func handleDeepLinkSetsErrorWhenNotConnected() async throws {
21282155
let appModel = NodeAppModel()
21292156
let url = try #require(URL(string: "openclaw://agent?message=hello"))

0 commit comments

Comments
 (0)