From 85cfbde5fd95850a28e962be01fc8655a69e8b1c Mon Sep 17 00:00:00 2001 From: kaitranntt Date: Thu, 18 Dec 2025 01:30:35 -0500 Subject: [PATCH] fix(dashboard): detect legacy proxy instances without session lock Proxy status endpoint now falls back to port check when session tracker has no data. Handles proxies started before session persistence feature. --- src/web-server/routes.ts | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/web-server/routes.ts b/src/web-server/routes.ts index 880faaa1..9a4486fd 100644 --- a/src/web-server/routes.ts +++ b/src/web-server/routes.ts @@ -1295,12 +1295,34 @@ apiRoutes.get('/cliproxy/status', async (_req: Request, res: Response): Promise< /** * GET /api/cliproxy/proxy-status - Get detailed proxy process status * Returns: { running, port?, pid?, sessionCount?, startedAt? } - * Uses session tracker for accurate multi-session status + * Combines session tracker data with actual port check for accuracy */ -apiRoutes.get('/cliproxy/proxy-status', (_req: Request, res: Response): void => { +apiRoutes.get('/cliproxy/proxy-status', async (_req: Request, res: Response): Promise => { try { - const status = getProxyProcessStatus(); - res.json(status); + // First check session tracker for detailed info + const sessionStatus = getProxyProcessStatus(); + + // If session tracker says running, trust it + if (sessionStatus.running) { + res.json(sessionStatus); + return; + } + + // Session tracker says not running, but proxy might be running without session tracking + // (e.g., started before session persistence was implemented) + const actuallyRunning = await isCliproxyRunning(); + + if (actuallyRunning) { + // Proxy running but no session lock - legacy/untracked instance + res.json({ + running: true, + port: 8317, // Default port + sessionCount: 0, // Unknown sessions + // No pid/startedAt since we don't have session lock + }); + } else { + res.json(sessionStatus); + } } catch (error) { res.status(500).json({ error: (error as Error).message }); }