Skip to content

The agent that grows with you

fix(desktop): honor MCP health snooze after restart

KoNit-Kc9277d25b926
diff --git a/apps/desktop/src/store/mcp-health.test.ts b/apps/desktop/src/store/mcp-health.test.ts
index 3e41277e275..c4e8dd9b8c0 100644
--- a/apps/desktop/src/store/mcp-health.test.ts
+++ b/apps/desktop/src/store/mcp-health.test.ts
@@ -82,12 +82,12 @@ describe('shouldNotify', () => {
const DAY = 24 * 60 * 60 * 1000
const now = 1_000_000
- // Transition table with the snooze still active: notify only on a TRANSITION
- // into a bad state; ok never nudges.
+ // With an active snooze, a fresh session and unchanged bad state stay quiet;
+ // later status transitions still notify. Ok never nudges.
it.each<[previous: Status | null, next: Status, notify: boolean]>([
[null, 'ok', false],
- [null, 'needs-auth', true],
- [null, 'error', true],
+ [null, 'needs-auth', false],
+ [null, 'error', false],
['ok', 'ok', false],
['ok', 'needs-auth', true],
['ok', 'error', true],
@@ -101,6 +101,11 @@ describe('shouldNotify', () => {
expect(shouldNotify(previous, next, now + DAY, now)).toBe(expected)
})
+ it('notifies a newly discovered bad server when no snooze has been persisted', () => {
+ expect(shouldNotify(null, 'needs-auth', 0, now)).toBe(true)
+ expect(shouldNotify(null, 'error', 0, now)).toBe(true)
+ })
+
it('re-nudges a server that stays broken once the daily snooze lapses, never for ok', () => {
expect(shouldNotify('needs-auth', 'needs-auth', now - 1, now)).toBe(true)
expect(shouldNotify('error', 'error', now, now)).toBe(true)
@@ -153,6 +158,40 @@ it('shows the toast with Sign in + Disable, then stays quiet for a day and re-nu
}
})
+it('honors a persisted snooze in a fresh module session, then re-notifies after it expires', async () => {
+ const servers = { mcp_servers: { linear: { url: 'https://mcp.linear.app/mcp', auth: 'oauth' } } }
+ const key = 'hermes:mcp-health-snooze-until:default::linear'
+ let clock = 1_700_000_000_000
+ const until = clock + 24 * 60 * 60 * 1000
+ const nowSpy = vi.spyOn(Date, 'now').mockImplementation(() => clock)
+ let freshSession: typeof import('./mcp-health') | undefined
+
+ try {
+ window.localStorage.setItem(key, String(until))
+ mocks.getHermesConfigRecord.mockResolvedValue(servers)
+ mocks.testMcpServer.mockResolvedValue({ ok: false, error: 'OAuth: authorization required', tools: [] })
+
+ // A fresh import drops in-memory transition state, as a renderer restart does.
+ vi.resetModules()
+ freshSession = await import('./mcp-health')
+ freshSession.startMcpHealthChecker()
+ mocks.gatewayState.set('open')
+ await flush()
+ await flush()
+ expect(mocks.notify).not.toHaveBeenCalled()
+
+ clock = until + 1
+ mocks.gatewayState.set('closed')
+ mocks.gatewayState.set('open')
+ await flush()
+ await flush()
+ expect(mocks.notify).toHaveBeenCalledTimes(1)
+ } finally {
+ freshSession?.stopMcpHealthChecker()
+ nowSpy.mockRestore()
+ }
+})
+
it('coalesces reconnects during a sweep into one fresh follow-up sweep', async () => {
let releaseFirst!: (config: Record<string, unknown>) => void
diff --git a/apps/desktop/src/store/mcp-health.ts b/apps/desktop/src/store/mcp-health.ts
index abb0346f353..d2d37ffec2e 100644
--- a/apps/desktop/src/store/mcp-health.ts
+++ b/apps/desktop/src/store/mcp-health.ts
@@ -33,8 +33,9 @@ export type McpHealthStatus = 'error' | 'needs-auth' | 'ok'
/**
* The notify decision, as a pure state machine: nudge on a TRANSITION into a
* bad state — never for ok. An unknown previous state (first sweep of the
- * session) counts as a transition: an expired token discovered at launch is
- * exactly the case this exists for.
+ * session) notifies only when its persisted cooldown is absent or elapsed,
+ * so an expired token discovered at launch is still surfaced without
+ * re-notifying after a renderer restart.
*
* A server that STAYS broken is nudged again once the daily snooze lapses:
* a dead OAuth token is a standing problem the user has to act on (sign in
@@ -53,6 +54,13 @@ export function shouldNotify(
return false
}
+ // A renderer restart clears transition memory but not the per-server
+ // cooldown. Treat that first sweep as a recheck: an active persisted snooze
+ // must still suppress the toast, while an unset or elapsed snooze may nudge.
+ if (previous === null) {
+ return now >= snoozedUntil
+ }
+
return previous !== next || now >= snoozedUntil
}