Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(mcp-host): exclude stale/swapped probes from heartbeat round tally (#148)

Alfredo Lopezfc31fa60271d
diff --git a/mcp-host/src/mcp/__tests__/managerStatus.test.ts b/mcp-host/src/mcp/__tests__/managerStatus.test.ts
index 3a010b188..1940a6029 100644
--- a/mcp-host/src/mcp/__tests__/managerStatus.test.ts
+++ b/mcp-host/src/mcp/__tests__/managerStatus.test.ts
@@ -573,6 +573,27 @@ describe('McpManager.refreshAllServerStatus', () => {
})
})
+ it('excludes a stale probe from the summary succeeded/failed tally', async () => {
+ const { McpClient } = await import('../client')
+ vi.spyOn(McpClient.prototype, 'connect').mockImplementation(async function (this: any) {
+ this.connected = true
+ this.tools = [{ name: 'tool-1', inputSchema: {}, serverName: 'svc' }]
+ })
+ vi.spyOn(McpClient.prototype, 'probeTools').mockResolvedValue({
+ ok: false,
+ error: new Error('MCP client svc is superseded'),
+ stale: true,
+ })
+ const m = new McpManager()
+ await m.addServer(serverInfo())
+
+ // A stale probe is skipped from the status commit, so it must not count as a
+ // real failure either — otherwise a benign mid-round swap flips the round to
+ // outcome=failed on the series #148's gate watches.
+ const summary = await m.refreshAllServerStatus()
+ expect(summary).toMatchObject({ serverCount: 1, succeeded: 0, failed: 0, aborted: false })
+ })
+
it('returns an empty summary and is a no-op when no servers are connected', async () => {
const m = new McpManager()
await expect(m.refreshAllServerStatus()).resolves.toEqual({
diff --git a/mcp-host/src/mcp/manager.ts b/mcp-host/src/mcp/manager.ts
index eafa6c1fc..2a44a5de7 100644
--- a/mcp-host/src/mcp/manager.ts
+++ b/mcp-host/src/mcp/manager.ts
@@ -495,16 +495,26 @@ export class McpManager {
}
})
)
- const succeeded = results.filter(({ result }) => result.ok).length
+ // A probe only counts toward the round's tally when its result is
+ // authoritative for the currently-installed client: never a client swapped
+ // out mid-round, never a stale-error probe that raced a reconnect. This is
+ // the same predicate the status commit below uses, so summary.succeeded /
+ // summary.failed match what was written — a benign mid-round swap can't
+ // inflate `failed` and flip the run's outcome on the series #148 watches.
+ const committed = results.filter(
+ ({ name, client, result }) =>
+ this.clients.get(name) === client && !(!result.ok && result.stale)
+ )
+ const succeeded = committed.filter(({ result }) => result.ok).length
const summary: McpStatusRefreshSummary = {
serverCount: entries.length,
succeeded,
- failed: entries.length - succeeded,
- toolCount: results.reduce(
+ failed: committed.length - succeeded,
+ toolCount: committed.reduce(
(total, { result }) => total + (result.ok ? result.toolCount : 0),
0
),
- outputSchemaCount: results.reduce(
+ outputSchemaCount: committed.reduce(
(total, { result }) => total + (result.ok ? result.outputSchemaCount : 0),
0
),
@@ -512,12 +522,7 @@ export class McpManager {
}
if (summary.aborted) return summary
- for (const { name, client, result } of results) {
- // Connection-epoch staleness (dev hardening): never write status for a
- // client that was swapped out mid-round, and skip stale-error probes that
- // raced a reconnect — they carry no authoritative signal for this client.
- if (this.clients.get(name) !== client) continue
- if (!result.ok && result.stale) continue
+ for (const { name, result } of committed) {
if (result.ok) {
this.statusTracker.updateToolCount(name, result.toolCount)
} else {