From 1f37ec842a6b33ec5b250be8e45137c2b9f9f019 Mon Sep 17 00:00:00 2001 From: David Newman Date: Tue, 28 Apr 2026 20:19:35 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=8C=20fix:=20Prevent=20Repeated=20Idle?= =?UTF-8?q?=20Check=20Triggers=20for=20Users=20With=20Failed=20MCP=20Conne?= =?UTF-8?q?ctions=20(#12853)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/api/src/mcp/UserConnectionManager.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/api/src/mcp/UserConnectionManager.ts b/packages/api/src/mcp/UserConnectionManager.ts index 760f84c75e..96d75c625b 100644 --- a/packages/api/src/mcp/UserConnectionManager.ts +++ b/packages/api/src/mcp/UserConnectionManager.ts @@ -268,10 +268,16 @@ export abstract class UserConnectionManager { this.pendingConnections.delete(key); } } - // Ensure user activity timestamp is removed - this.userLastActivity.delete(userId); logger.info(`[MCP][User: ${userId}] All connections processed for disconnection.`); } + /** + * Always clear the activity timestamp, even when userMap was missing. + * `updateUserLastActivity` can be called before a connection is established + * (e.g. in MCPManager.callTool prior to getConnection); if that connection + * attempt fails, the activity entry would otherwise leak and trigger the + * idle check repeatedly for the same userId. + */ + this.userLastActivity.delete(userId); } /** Check for and disconnect idle connections */