diff --git a/src/lib/onboard/dashboard-port.test.ts b/src/lib/onboard/dashboard-port.test.ts index 4103f9a25bf..1db2fecf7a6 100644 --- a/src/lib/onboard/dashboard-port.test.ts +++ b/src/lib/onboard/dashboard-port.test.ts @@ -283,13 +283,46 @@ describe("typed OpenShell dashboard-port observation", () => { ).toBe(18790); }); - it("blocks allocation when ownership is indeterminate", () => { - expect(() => + it("keeps an unprovable port occupied and allocates the next free port (#11979)", () => { + expect( findAvailableDashboardPortFromObservations("cursor", 18789, [ forwardObservation("cursor", 18789, "indeterminate"), forwardObservation("cursor", 18790, "absent"), ]), - ).toThrow(/could not prove OpenShell forward ownership/i); + ).toBe(18790); + }); + + it("names every unprovable port when no dashboard port can be verified (#11979)", () => { + const observations = Array.from({ length: 11 }, (_, index) => + forwardObservation("cursor", 18789 + index, "indeterminate"), + ); + expect(() => findAvailableDashboardPortFromObservations("cursor", 18789, observations)).toThrow( + "All dashboard ports in range 18789-18799 are occupied:\n" + + Array.from( + { length: 11 }, + (_, index) => ` ${18789 + index} → unverified OpenShell forward ownership`, + ).join("\n"), + ); + }); + + it("still blocks allocation when a forward observation fails for another reason", () => { + expect(() => + findAvailableDashboardPortFromObservations("cursor", 18789, [ + { + state: "indeterminate", + forward: { + gatewayEndpoint: "https://127.0.0.1:9090", + gatewayName: "nemoclaw-9090", + workspace: "default", + sandboxName: "cursor", + localHost: "127.0.0.1", + port: 18789, + }, + error: { kind: "timeout", message: "The OpenShell forward operation timed out." }, + }, + forwardObservation("cursor", 18790, "absent"), + ]), + ).toThrow(/Cannot allocate dashboard port: The OpenShell forward operation timed out/); }); it("treats missing observations as unverified instead of absent", () => { diff --git a/src/lib/onboard/dashboard-port.ts b/src/lib/onboard/dashboard-port.ts index 05ec98f0389..d3f49e86cd5 100644 --- a/src/lib/onboard/dashboard-port.ts +++ b/src/lib/onboard/dashboard-port.ts @@ -426,7 +426,13 @@ export function findAvailablePortInRangeFromObservations( range: HostPortRange, registryOccupiedPorts: ReadonlyMap = new Map(), ): number { - const indeterminate = observations.find((observation) => observation.state === "indeterminate"); + // An unprovable owner on one port only keeps that port occupied below. Any other + // indeterminate result means the observation itself failed, so stop (#11979). + const indeterminate = observations.find( + (observation) => + observation.state === "indeterminate" && + !("error" in observation && observation.error.kind === "ownership"), + ); if (indeterminate) { const message = "error" in indeterminate ? indeterminate.error.message : "Invalid forward request."; diff --git a/src/lib/onboard/hermes-api-port.test.ts b/src/lib/onboard/hermes-api-port.test.ts index 634f8883fd7..e7076506adf 100644 --- a/src/lib/onboard/hermes-api-port.test.ts +++ b/src/lib/onboard/hermes-api-port.test.ts @@ -137,8 +137,8 @@ describe("findAvailableHermesApiPortFromObservations", () => { ).toBe(8643); }); - it("blocks allocation when ownership is indeterminate", () => { - expect(() => + it("keeps an unprovable port occupied and allocates the next free port (#11979)", () => { + expect( findAvailableHermesApiPortFromObservations( "beta", 8642, @@ -148,7 +148,7 @@ describe("findAvailableHermesApiPortFromObservations", () => { ], new Map(), ), - ).toThrow(/could not prove OpenShell forward ownership/i); + ).toBe(8643); }); });