From 9ff4d103eca20b397295a07ae6d776e0cb26aaa6 Mon Sep 17 00:00:00 2001 From: Carlos Villela Date: Wed, 1 Apr 2026 17:09:03 -0700 Subject: [PATCH] fix(cli): classifyGatewayStatus no longer misclassifies "Not connected" Move the unavailable-pattern check before the connected check, and use a strict line-anchored regex (/^\s*(?:Status:\s*)?Connected\s*$/im) so "Not connected", "Disconnected", and other substrings no longer match. Add regression tests for "Status: Not connected" and bare "Connected". Fixes #1279. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/lib/runtime-recovery.test.ts | 2 ++ src/lib/runtime-recovery.ts | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/lib/runtime-recovery.test.ts b/src/lib/runtime-recovery.test.ts index cf364bd8b..868934f3f 100644 --- a/src/lib/runtime-recovery.test.ts +++ b/src/lib/runtime-recovery.test.ts @@ -74,6 +74,8 @@ describe("runtime recovery helpers", () => { expect(classifyGatewayStatus("Gateway: nemoclaw\nStatus: Disconnected").state).toBe( "inactive", ); + expect(classifyGatewayStatus("Status: Not connected").state).toBe("inactive"); + expect(classifyGatewayStatus("Connected").state).toBe("connected"); }); it("only attempts gateway recovery when sandbox access is unavailable and gateway is down", () => { diff --git a/src/lib/runtime-recovery.ts b/src/lib/runtime-recovery.ts index 134d433f2..d33162f59 100644 --- a/src/lib/runtime-recovery.ts +++ b/src/lib/runtime-recovery.ts @@ -61,9 +61,6 @@ export function classifyGatewayStatus(output = ""): StateClassification { if (!clean) { return { state: "inactive", reason: "empty" }; } - if (/\bConnected\b/i.test(clean) && !/\bDisconnected\b/i.test(clean)) { - return { state: "connected", reason: "ok" }; - } if ( /No active gateway|transport error|client error|Connection reset by peer|Connection refused|Gateway: .*Error/i.test( clean, @@ -71,6 +68,9 @@ export function classifyGatewayStatus(output = ""): StateClassification { ) { return { state: "unavailable", reason: "gateway_unavailable" }; } + if (/^\s*(?:Status:\s*)?Connected\s*$/im.test(clean)) { + return { state: "connected", reason: "ok" }; + } return { state: "inactive", reason: "not_connected" }; }