From 3fbc408ff6ddc86115a826f9f3f71a805e4d31c8 Mon Sep 17 00:00:00 2001 From: Xipong <217837358+Xipong@users.noreply.github.com> Date: Wed, 9 Sep 2026 02:24:01 +0300 Subject: [PATCH] fix: preserve event delivery across scheduler lifecycle boundaries --- apps/desktop/src/store/mcp-health.test.ts | 17 +++++++++++++++++ apps/desktop/src/store/mcp-health.ts | 2 ++ 2 files changed, 19 insertions(+) diff --git a/apps/desktop/src/store/mcp-health.test.ts b/apps/desktop/src/store/mcp-health.test.ts index f0249fa8a5..241cde396f 100644 --- a/apps/desktop/src/store/mcp-health.test.ts +++ b/apps/desktop/src/store/mcp-health.test.ts @@ -117,3 +117,20 @@ it('coalesces reconnects during a sweep into one fresh follow-up sweep', async ( await flush() expect(mocks.getHermesConfigRecord).toHaveBeenCalledTimes(2) }) + +it.each(['stop', 'disconnect'])('drops the queued sweep on %s', async action => { + let release!: (config: Record) => void + mocks.getHermesConfigRecord.mockReturnValueOnce(new Promise(resolve => { release = resolve })).mockResolvedValue({ mcp_servers: {} }) + startMcpHealthChecker() + mocks.gatewayState.set('open') + mocks.gatewayState.set('closed') + mocks.gatewayState.set('open') + + if (action === 'stop') {stopMcpHealthChecker()} + else {mocks.gatewayState.set('closed')} + + release({ mcp_servers: {} }) + await flush() + await flush() + expect(mocks.getHermesConfigRecord).toHaveBeenCalledTimes(1) +}) diff --git a/apps/desktop/src/store/mcp-health.ts b/apps/desktop/src/store/mcp-health.ts index bf64f5a997..c609be13ff 100644 --- a/apps/desktop/src/store/mcp-health.ts +++ b/apps/desktop/src/store/mcp-health.ts @@ -175,6 +175,8 @@ function arm(): void { } function disarm(): void { + sweepQueued = false + if (timer !== null) { clearInterval(timer) timer = null