Skip to content

Commit 021f8b6

Browse files
authored
fix(macos): preserve status-less health probe errors (#132062)
* test(macos): reproduce status-less health probe diagnostics * fix(macos): preserve status-less health probe diagnoses
1 parent d3abf4a commit 021f8b6

4 files changed

Lines changed: 39 additions & 19 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4172,6 +4172,7 @@ jobs:
41724172
${{ steps.health-render.outputs.artifact-path }}/startup-grace.png
41734173
${{ steps.health-render.outputs.artifact-path }}/stale-socket.png
41744174
${{ steps.health-render.outputs.artifact-path }}/disabled.png
4175+
${{ steps.health-render.outputs.artifact-path }}/probe-permission.png
41754176
if-no-files-found: error
41764177
retention-days: 7
41774178

‎apps/macos/Sources/OpenClaw/HealthStore.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ final class HealthStore {
166166

167167
private static func describeProbeFailure(_ probe: HealthSnapshot.ChannelSummary.Probe) -> String {
168168
let elapsed = probe.elapsedMs.map { "\(Int($0))ms" }
169-
if let error = probe.error, error.lowercased().contains("timeout") || probe.status == nil {
169+
if let error = probe.error, error.lowercased().contains("timeout") {
170170
if let elapsed { return "Health check timed out (\(elapsed))" }
171171
return "Health check timed out"
172172
}

‎apps/macos/Tests/OpenClawIPCTests/HealthStoreStateTests.swift‎

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,23 @@ struct HealthStoreStateTests {
3232
let state = AppState(preview: true)
3333
state.connectionMode = .local
3434
state.isPaused = true
35-
for (name, fields, expected) in [
36-
("ready", ["running": true, "connected": true, "lifecycle": "ready"] as [String: Any],
35+
for (name, channelId, fields, expected) in [
36+
("ready", "telegram", ["running": true, "connected": true, "lifecycle": "ready"] as [String: Any],
3737
"Telegram ready"),
38-
("startup-grace", [
38+
("startup-grace", "telegram", [
3939
"running": true, "connected": false, "lifecycle": "starting", "lastStartAt": 1772798370000,
4040
],
4141
"Telegram running"),
42-
("stale-socket", [
42+
("stale-socket", "telegram", [
4343
"running": true, "connected": true, "lifecycle": "ready", "healthState": "stale-socket",
4444
"lastStartAt": 1772794800000, "lastTransportActivityAt": 1772796540000,
4545
],
4646
"Telegram degraded · stale-socket"),
47-
("disabled", ["enabled": false, "running": false], "Telegram disabled"),
47+
("disabled", "telegram", ["enabled": false, "running": false], "Telegram disabled"),
48+
("probe-permission", "imessage", Self.permissionProbeChannel,
49+
"iMessage degraded · \(Self.permissionProbeError) (status unknown)"),
4850
] {
49-
try Self.withSnapshot(["telegram": fields]) { store in
51+
try Self.withSnapshot([channelId: fields], order: [channelId]) { store in
5052
let hosting = NSHostingView(rootView: GeneralSettings(state: state, page: .connection, isActive: false)
5153
// Capture the view's light canvas, not transparent text over the window's excluded background.
5254
.background(.white)
@@ -132,22 +134,25 @@ struct HealthStoreStateTests {
132134
}
133135

134136
@Test @MainActor func `current channel probe failure degrades state`() throws {
135-
try Self.withSnapshot([
136-
"telegram": [
137+
for (channelId, fields, label, expected) in [
138+
("imessage", Self.permissionProbeChannel, "iMessage", "\(Self.permissionProbeError) (status unknown)"),
139+
// Generic imsg timeouts exercise formatting, not the FDA-only public probe redactor.
140+
("imessage", [
141+
"probe": ["ok": false, "error": "imsg rpc timeout (chats.list)"],
142+
"running": true, "lifecycle": "starting", "lastStartAt": 1772798395000,
143+
], "iMessage", "Health check timed out"),
144+
("telegram", [
137145
"probe": ["ok": false, "status": 503, "error": "gateway connect failed", "elapsedMs": 12],
138146
"lastProbeAt": 1772798400000,
139147
"running": true,
140148
"connected": true,
141149
"lifecycle": "ready",
142-
],
143-
]) { store in
144-
switch store.state {
145-
case let .degraded(message):
146-
#expect(message.contains("gateway connect failed"))
147-
default:
148-
Issue.record("Expected degraded state when a current channel probe fails")
150+
], "Telegram", "gateway connect failed (status 503, 12ms)"),
151+
] {
152+
try Self.withSnapshot([channelId: fields], order: [channelId]) { store in
153+
#expect(store.state == .degraded(expected))
154+
#expect(store.summaryLine == "\(label) degraded · \(expected)")
149155
}
150-
#expect(store.summaryLine.contains("gateway connect failed"))
151156
}
152157
}
153158

@@ -338,6 +343,17 @@ struct HealthStoreStateTests {
338343
}
339344
}
340345

346+
private static let permissionProbeError =
347+
"imsg cannot access ~/Library/Messages/chat.db. Grant Full Disk Access to the Gateway/launcher process and restart Gateway."
348+
349+
private static var permissionProbeChannel: [String: Any] {
350+
// Public health preserves this sanitized FDA error without an HTTP status; startup has no lastError yet.
351+
[
352+
"probe": ["ok": false, "error": self.permissionProbeError],
353+
"running": true, "lifecycle": "starting", "lastStartAt": 1772798395000,
354+
]
355+
}
356+
341357
private static var unlinkedWhatsApp: [String: Any] {
342358
[
343359
"configured": true, "linked": false, "running": false, "connected": false,
@@ -370,7 +386,7 @@ struct HealthStoreStateTests {
370386
account.merge(fields) { _, value in value }
371387
return account
372388
}
373-
// Fixed Gateway response time: fresh starts are 30s old; expired starts are 5m old.
389+
// Fixed Gateway response time keeps grace and expired lifecycle fixtures deterministic.
374390
let fixture: [String: Any] = [
375391
"ok": true,
376392
"ts": 1772798400000,
@@ -379,7 +395,7 @@ struct HealthStoreStateTests {
379395
"channelOrder": order,
380396
"channelLabels": [
381397
"telegram": "Telegram", "matrix": "Matrix", "whatsapp": "WhatsApp", "zalouser": "Zalo Personal",
382-
"disabled": "Disabled",
398+
"disabled": "Disabled", "imessage": "iMessage",
383399
],
384400
"heartbeatSeconds": 60,
385401
"sessions": ["path": "/tmp/sessions.json", "count": 0, "recent": []],

‎docs/platforms/mac/health.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ windows; transient transport flags alone do not mark a channel degraded.
3939
Reported failures such as a stale socket or unavailable inbound processing
4040
still take precedence over a ready-looking connection.
4141

42+
A missing HTTP status does not by itself mean a timeout; the app preserves
43+
the Gateway's reported probe error.
44+
4245
## How health refresh works
4346

4447
The app calls the Gateway's `health` RPC over its existing WebSocket

0 commit comments

Comments
 (0)