Skip to content

The agent that grows with you

fix: preserve event delivery across scheduler lifecycle boundaries

Xipong3fbc408ff6dd
diff --git a/apps/desktop/src/store/mcp-health.test.ts b/apps/desktop/src/store/mcp-health.test.ts
index f0249fa8a5a..241cde396f5 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<string, unknown>) => 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 bf64f5a9979..c609be13ff7 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