Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 36 additions & 3 deletions src/lib/onboard/dashboard-port.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
8 changes: 7 additions & 1 deletion src/lib/onboard/dashboard-port.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,13 @@ export function findAvailablePortInRangeFromObservations(
range: HostPortRange,
registryOccupiedPorts: ReadonlyMap<string, string> = 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.";
Expand Down
6 changes: 3 additions & 3 deletions src/lib/onboard/hermes-api-port.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -148,7 +148,7 @@ describe("findAvailableHermesApiPortFromObservations", () => {
],
new Map(),
),
).toThrow(/could not prove OpenShell forward ownership/i);
).toBe(8643);
});
});

Expand Down
Loading