mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-02-27 12:54:09 +01:00
⏳ refactor: MCP OAuth Polling with Gradual Backoff and Timeout Handling (#9752)
Some checks failed
Docker Dev Branch Images Build / build (Dockerfile, lc-dev, node) (push) Has been cancelled
Docker Dev Branch Images Build / build (Dockerfile.multi, lc-dev-api, api-build) (push) Has been cancelled
Docker Dev Images Build / build (Dockerfile, librechat-dev, node) (push) Has been cancelled
Docker Dev Images Build / build (Dockerfile.multi, librechat-dev-api, api-build) (push) Has been cancelled
Sync Locize Translations & Create Translation PR / Sync Translation Keys with Locize (push) Has been cancelled
Sync Locize Translations & Create Translation PR / Create Translation PR on Version Published (push) Has been cancelled
Some checks failed
Docker Dev Branch Images Build / build (Dockerfile, lc-dev, node) (push) Has been cancelled
Docker Dev Branch Images Build / build (Dockerfile.multi, lc-dev-api, api-build) (push) Has been cancelled
Docker Dev Images Build / build (Dockerfile, librechat-dev, node) (push) Has been cancelled
Docker Dev Images Build / build (Dockerfile.multi, librechat-dev-api, api-build) (push) Has been cancelled
Sync Locize Translations & Create Translation PR / Sync Translation Keys with Locize (push) Has been cancelled
Sync Locize Translations & Create Translation PR / Create Translation PR on Version Published (push) Has been cancelled
* refactor: Implement gradual backoff polling for oauth connection status with timeout handling * refactor: Enhance OAuth polling with gradual backoff and timeout handling; update reconnection tracking * refactor: reconnection timeout behavior in OAuthReconnectionManager and OAuthReconnectionTracker - Implement tests to verify reconnection timeout handling, including tracking of reconnection states and cleanup of timed-out entries. - Enhance existing methods in OAuthReconnectionManager and OAuthReconnectionTracker to support timeout checks and cleanup logic. - Ensure proper handling of multiple servers with different timeout periods and edge cases for active states. * chore: remove comment * refactor: Enforce strict 3-minute OAuth timeout with updated polling intervals and improved timeout handling * refactor: Remove unused polling logic and prevent duplicate polling for servers in MCP server manager * refactor: Update localization key for no memories message in MemoryViewer * refactor: Improve MCP tool initialization by handling server failures - Introduced a mechanism to track failed MCP servers, preventing retries for unavailable servers. - Added logging for failed tool creation attempts to enhance debugging and monitoring. * refactor: Update reconnection timeout to enforce a strict 3-minute limit * ci: Update reconnection timeout tests to reflect a strict 3-minute limit * ci: Update reconnection timeout tests to enforce a strict 3-minute limit * chore: Remove unused MCP connection timeout message
This commit is contained in:
parent
f0599ad36c
commit
96870e0da0
9 changed files with 560 additions and 41 deletions
|
|
@ -1,17 +1,52 @@
|
|||
export class OAuthReconnectionTracker {
|
||||
// Map of userId -> Set of serverNames that have failed reconnection
|
||||
/** Map of userId -> Set of serverNames that have failed reconnection */
|
||||
private failed: Map<string, Set<string>> = new Map();
|
||||
// Map of userId -> Set of serverNames that are actively reconnecting
|
||||
/** Map of userId -> Set of serverNames that are actively reconnecting */
|
||||
private active: Map<string, Set<string>> = new Map();
|
||||
/** Map of userId:serverName -> timestamp when reconnection started */
|
||||
private activeTimestamps: Map<string, number> = new Map();
|
||||
/** Maximum time (ms) a server can be in reconnecting state before auto-cleanup */
|
||||
private readonly RECONNECTION_TIMEOUT_MS = 3 * 60 * 1000; // 3 minutes
|
||||
|
||||
public isFailed(userId: string, serverName: string): boolean {
|
||||
return this.failed.get(userId)?.has(serverName) ?? false;
|
||||
}
|
||||
|
||||
/** Check if server is in the active set (original simple check) */
|
||||
public isActive(userId: string, serverName: string): boolean {
|
||||
return this.active.get(userId)?.has(serverName) ?? false;
|
||||
}
|
||||
|
||||
/** Check if server is still reconnecting (considers timeout) */
|
||||
public isStillReconnecting(userId: string, serverName: string): boolean {
|
||||
if (!this.isActive(userId, serverName)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const key = `${userId}:${serverName}`;
|
||||
const startTime = this.activeTimestamps.get(key);
|
||||
|
||||
// If there's a timestamp and it has timed out, it's not still reconnecting
|
||||
if (startTime && Date.now() - startTime > this.RECONNECTION_TIMEOUT_MS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Clean up server if it has timed out - returns true if cleanup was performed */
|
||||
public cleanupIfTimedOut(userId: string, serverName: string): boolean {
|
||||
const key = `${userId}:${serverName}`;
|
||||
const startTime = this.activeTimestamps.get(key);
|
||||
|
||||
if (startTime && Date.now() - startTime > this.RECONNECTION_TIMEOUT_MS) {
|
||||
this.removeActive(userId, serverName);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public setFailed(userId: string, serverName: string): void {
|
||||
if (!this.failed.has(userId)) {
|
||||
this.failed.set(userId, new Set());
|
||||
|
|
@ -26,6 +61,10 @@ export class OAuthReconnectionTracker {
|
|||
}
|
||||
|
||||
this.active.get(userId)?.add(serverName);
|
||||
|
||||
/** Track when reconnection started */
|
||||
const key = `${userId}:${serverName}`;
|
||||
this.activeTimestamps.set(key, Date.now());
|
||||
}
|
||||
|
||||
public removeFailed(userId: string, serverName: string): void {
|
||||
|
|
@ -42,5 +81,9 @@ export class OAuthReconnectionTracker {
|
|||
if (userServers?.size === 0) {
|
||||
this.active.delete(userId);
|
||||
}
|
||||
|
||||
/** Clear timestamp tracking */
|
||||
const key = `${userId}:${serverName}`;
|
||||
this.activeTimestamps.delete(key);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue