Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
49 changes: 42 additions & 7 deletions bin/lib/onboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -3233,6 +3233,11 @@ async function setupInference(
step(4, 8, "Setting up inference provider");
runOpenshell(["gateway", "select", GATEWAY_NAME], { ignoreError: true });

// Populated by local-inference branches on WSL2 + Docker Desktop;
// persisted to the registry so later commands / diagnostics can see
// which host IP was injected into `host.openshell.internal`.
let resolvedHostIp = null;

if (
provider === "nvidia-prod" ||
provider === "nvidia-nim" ||
Expand Down Expand Up @@ -3311,12 +3316,25 @@ async function setupInference(
process.exit(applyResult.status || 1);
}
} else if (provider === "vllm-local") {
const validation = validateLocalProvider(provider, runCapture);
const platformOpts = {
isWsl: isWsl(),
isDockerDesktop: getContainerRuntime() === "docker-desktop",
};
const validation = validateLocalProvider(provider, runCapture, platformOpts);
if (!validation.ok) {
console.error(` ${validation.message}`);
process.exit(1);
const answer = (await prompt(" Continue anyway? Inference may fail at runtime. [y/N]: "))
.trim()
.toLowerCase();
if (answer !== "y") {
process.exit(1);
}
Comment on lines 3324 to +3331

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Keep local-provider probe failures non-interactive in --non-interactive mode.

These branches now call prompt() unconditionally on validation failure. If nemoclaw onboard --non-interactive selects ollama or vllm, a bad probe turns into a hang instead of the hard failure the rest of the wizard uses.

Suggested fix
 if (!validation.ok) {
   console.error(`  ${validation.message}`);
+  if (isNonInteractive()) {
+    process.exit(1);
+  }
   const answer = (await prompt("  Continue anyway? Inference may fail at runtime. [y/N]: "))
     .trim()
     .toLowerCase();
   if (answer !== "y") {
     process.exit(1);
   }
 }

Apply the same guard in both local-provider branches.

Also applies to: 3362-3369

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@bin/lib/onboard.js` around lines 3324 - 3331, On validation failure in the
local-provider probe branches (the blocks that check validation.ok, call
prompt(), and call process.exit(1)), respect the global non-interactive flag
instead of always invoking prompt(): if the non-interactive mode flag (the same
boolean used elsewhere in the wizard, e.g., nonInteractive or
flags.nonInteractive) is set then log the validation.message and immediately
call process.exit(1) (no prompt), otherwise keep the existing interactive prompt
flow; apply this same guard to both places that call prompt() (the shown block
and the other branch around lines 3362-3369).

}
resolvedHostIp = validation.resolvedHostIp || null;
if (resolvedHostIp) {
console.log(` Resolved WSL2 host IP for container access: ${resolvedHostIp}`);
}
const baseUrl = getLocalProviderBaseUrl(provider);
const baseUrl = getLocalProviderBaseUrl(provider, resolvedHostIp ?? undefined);
const providerResult = upsertProvider("vllm-local", "openai", "OPENAI_API_KEY", baseUrl, {
OPENAI_API_KEY: "dummy",
});
Expand All @@ -3336,13 +3354,26 @@ async function setupInference(
String(LOCAL_INFERENCE_TIMEOUT_SECS),
]);
} else if (provider === "ollama-local") {
const validation = validateLocalProvider(provider, runCapture);
const platformOpts = {
isWsl: isWsl(),
isDockerDesktop: getContainerRuntime() === "docker-desktop",
};
const validation = validateLocalProvider(provider, runCapture, platformOpts);
if (!validation.ok) {
console.error(` ${validation.message}`);
console.error(" On macOS, local inference also depends on OpenShell host routing support.");
process.exit(1);
const answer = (await prompt(" Continue anyway? Inference may fail at runtime. [y/N]: "))
.trim()
.toLowerCase();
if (answer !== "y") {
process.exit(1);
}
}
resolvedHostIp = validation.resolvedHostIp || null;
if (resolvedHostIp) {
console.log(` Resolved WSL2 host IP for container access: ${resolvedHostIp}`);
}
const baseUrl = getLocalProviderBaseUrl(provider);
const baseUrl = getLocalProviderBaseUrl(provider, resolvedHostIp ?? undefined);
const providerResult = upsertProvider("ollama-local", "openai", "OPENAI_API_KEY", baseUrl, {
OPENAI_API_KEY: "ollama",
});
Expand Down Expand Up @@ -3371,7 +3402,11 @@ async function setupInference(
}

verifyInferenceRoute(provider, model);
registry.updateSandbox(sandboxName, { model, provider });
registry.updateSandbox(sandboxName, {
model,
provider,
resolvedHostIp: resolvedHostIp || null,
});
Comment on lines +3405 to +3409

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

This registry write never reaches the real sandbox entry.

setupInference() still runs before createSandbox(), and onboard() passes GATEWAY_NAME here (Line 4415), not the eventual sandbox name. That makes registry.updateSandbox(...) return false and silently drop model, provider, and resolvedHostIp for normal onboard runs.

Please move this persistence until after the sandbox has been registered, or store it in session state and apply it once the real sandbox entry exists.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@bin/lib/onboard.js` around lines 3405 - 3409, The call to
registry.updateSandbox(...) is writing using the temporary GATEWAY_NAME before
the real sandbox exists (setupInference runs before createSandbox), so its
return is false and the data is lost; fix by deferring the persistence until
after the sandbox is registered (i.e., after createSandbox completes inside
onboard) or by caching the {model, provider, resolvedHostIp} in session state
and applying them when registry.createSandbox / registry.updateSandbox is called
for the real sandbox name; specifically modify the flow around setupInference(),
createSandbox(), and the registry.updateSandbox call so you either move the
registry.updateSandbox invocation to post-createSandbox or add a session/cache
write-read that registry.updateSandbox consumes once the real sandbox entry
exists.

console.log(` ✓ Inference route set: ${provider} / ${model}`);
return { ok: true };
}
Expand Down
4 changes: 4 additions & 0 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ These generated skills let AI agents walk users through NemoClaw tasks (installa
Always edit pages in `docs/`.
Never edit generated skill files under `.agents/skills/nemoclaw-user-*/`. Your changes will be overwritten on the next run.

:::{note}
**For AI coding assistants:** Do not `git add` any file under `.agents/skills/nemoclaw-user-*/` — not even when `git status` shows it as modified. The pre-commit hook regenerates and stages those files automatically from `docs/`. Staging them manually makes the commit diff harder to review and can mask out-of-date hand edits. If you changed user-facing behavior, update the matching page under `docs/` and stage only `docs/**/*.md`; the hook does the rest.
:::

### Generated skills

The current generated skills and their source pages are:
Expand Down
44 changes: 44 additions & 0 deletions docs/reference/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,50 @@ $ nemoclaw onboard
Podman is not a tested runtime.
If onboarding or sandbox lifecycle fails, switch to a tested runtime (Docker Desktop, Colima, or Docker Engine) and rerun onboarding.

### Local inference on WSL2 + Docker Desktop

On WSL2 with Docker Desktop, the conventional `host.openshell.internal`
gateway hostname (backed by Docker's `host-gateway`) often resolves to
an IPv6 ULA or an un-routable gateway IP. That can hang the onboard
container reachability probe (step 4/8) and break inference routing to
a host-side Ollama or vLLM.

Onboarding now detects this combination and probes a list of candidate
host IPs in order:

1. The WSL distro's outbound IPv4 (`ip -4 -o route get 1.1.1.1`) —
correct when Ollama or vLLM runs **inside WSL**.
2. The WSL2 default gateway (`ip -4 -o route show default`) — correct
when Ollama or vLLM runs on the **Windows host** in NAT networking
mode.
3. Other interface addresses from `hostname -I`.

The first candidate whose container-side probe succeeds is injected
into both `OPENAI_BASE_URL` and the reachability check, and persisted
to the sandbox registry entry as `resolvedHostIp`. No manual override
is needed for either Ollama placement.
Comment on lines +176 to +179

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Avoid absolute wording about resolvedHostIp persistence.

This states persistence as guaranteed, but current behavior is best-effort in onboarding flow and has a known persistence-ordering follow-up. Please soften this to "attempts to persist" to avoid misleading troubleshooting expectations.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/reference/troubleshooting.md` around lines 176 - 179, The documentation
currently states that the first successful container-side probe is definitively
"injected into both `OPENAI_BASE_URL` and the reachability check, and persisted
to the sandbox registry entry as `resolvedHostIp`"; change this absolute
language to reflect best-effort behavior by replacing claims of guaranteed
persistence with phrases like "attempts to persist" or "is attempted to be
persisted" for `resolvedHostIp`, and clarify that `OPENAI_BASE_URL` and the
reachability check receive the candidate when the probe succeeds, noting this
occurs during the onboarding flow and that persistence ordering/guarantees are
not strict.


In WSL **mirrored** networking mode, `host.openshell.internal` already
reaches the shared network stack directly, so no override is applied.

If onboarding still reports that the container reachability check
failed for `http://host.openshell.internal:11434`:

- Confirm Ollama is listening on all interfaces:
`OLLAMA_HOST=0.0.0.0:11434 ollama serve`.
- Check your Windows / WSL firewall is not blocking port 11434.
- If Ollama is on the Windows host (not inside WSL), the reachable
address may be the WSL2 default gateway rather than eth0. Use
`ip route show default` to find it, then set
`OPENAI_BASE_URL=http://<gateway-ip>:11434/v1` manually.
- As a last resort, install Docker Engine directly inside WSL2 instead
of Docker Desktop — `host-gateway` works reliably there.

Sandbox pod → host egress is a separate path from the onboard probe. If
inference calls still fail from inside a running sandbox, verify the
sandbox's `HTTP_PROXY` / `ALL_PROXY` env vars include the resolved host
IP in `NO_PROXY`.

### Invalid sandbox name

Sandbox names must follow RFC 1123 subdomain rules: lowercase alphanumeric characters and hyphens only, and must start and end with an alphanumeric character.
Expand Down
158 changes: 155 additions & 3 deletions src/lib/local-inference.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
CONTAINER_REACHABILITY_IMAGE,
DEFAULT_OLLAMA_MODEL,
LARGE_OLLAMA_MIN_MEMORY_MB,
detectWsl2HostIp,
getDefaultOllamaModel,
getBootstrapOllamaModelOptions,
getLocalProviderBaseUrl,
Expand All @@ -34,6 +35,16 @@ describe("local inference helpers", () => {
);
});

it("uses an explicit host IP in the base URL when provided", () => {
expect(getLocalProviderBaseUrl("ollama-local", "172.20.130.16")).toBe(
"http://172.20.130.16:11434/v1",
);
expect(getLocalProviderBaseUrl("vllm-local", "172.20.130.16")).toBe(
"http://172.20.130.16:8000/v1",
);
expect(getLocalProviderBaseUrl("unknown-provider", "172.20.130.16")).toBeNull();
});

it("returns null for unknown local provider URLs", () => {
expect(getLocalProviderBaseUrl("unknown-provider")).toBeNull();
expect(getLocalProviderValidationBaseUrl("unknown-provider")).toBeNull();
Expand All @@ -57,13 +68,22 @@ describe("local inference helpers", () => {
"curl -sf http://localhost:8000/v1/models 2>/dev/null",
);
expect(getLocalProviderContainerReachabilityCheck("vllm-local")).toBe(
`docker run --rm --add-host host.openshell.internal:host-gateway ${CONTAINER_REACHABILITY_IMAGE} -sf http://host.openshell.internal:8000/v1/models 2>/dev/null`,
`docker run --rm --add-host host.openshell.internal:host-gateway ${CONTAINER_REACHABILITY_IMAGE} -4 -sf http://host.openshell.internal:8000/v1/models 2>/dev/null`,
);
});

it("returns the expected container reachability command for ollama-local", () => {
expect(getLocalProviderContainerReachabilityCheck("ollama-local")).toBe(
`docker run --rm --add-host host.openshell.internal:host-gateway ${CONTAINER_REACHABILITY_IMAGE} -sf http://host.openshell.internal:11434/api/tags 2>/dev/null`,
`docker run --rm --add-host host.openshell.internal:host-gateway ${CONTAINER_REACHABILITY_IMAGE} -4 -sf http://host.openshell.internal:11434/api/tags 2>/dev/null`,
);
});

it("uses an explicit host IP when provided", () => {
expect(getLocalProviderContainerReachabilityCheck("ollama-local", "172.20.130.16")).toBe(
`docker run --rm --add-host host.openshell.internal:172.20.130.16 ${CONTAINER_REACHABILITY_IMAGE} -4 -sf http://host.openshell.internal:11434/api/tags 2>/dev/null`,
);
expect(getLocalProviderContainerReachabilityCheck("vllm-local", "172.20.130.16")).toBe(
`docker run --rm --add-host host.openshell.internal:172.20.130.16 ${CONTAINER_REACHABILITY_IMAGE} -4 -sf http://host.openshell.internal:8000/v1/models 2>/dev/null`,
);
});

Expand Down Expand Up @@ -91,7 +111,7 @@ describe("local inference helpers", () => {
});
expect(result.ok).toBe(false);
expect(result.message).toMatch(/host\.openshell\.internal:11434/);
expect(result.message).toMatch(/0\.0\.0\.0:11434/);
expect(result.message).toMatch(/OLLAMA_HOST=0\.0\.0\.0:11434/);
});

it("returns a clear error when vllm-local is unavailable", () => {
Expand All @@ -110,6 +130,138 @@ describe("local inference helpers", () => {
expect(result.message).toMatch(/host\.openshell\.internal:8000/);
});

describe("detectWsl2HostIp", () => {
it("prefers the `ip route get` outbound source address", () => {
const ip = detectWsl2HostIp((cmd) => {
if (cmd.includes("ip -4 -o route get")) {
return "1.1.1.1 via 172.20.128.1 dev eth0 src 172.20.130.16 uid 1000\n";
}
if (cmd.includes("hostname -I")) return "192.168.1.50 172.17.0.1 ";
return "";
});
expect(ip).toBe("172.20.130.16");
});

it("returns eth0 src and default gateway as separate candidates", async () => {
const { detectWsl2HostIpCandidates } = await import(
"../../dist/lib/local-inference"
);
const candidates = detectWsl2HostIpCandidates((cmd) => {
if (cmd.includes("ip -4 -o route get 1.1.1.1")) {
return "1.1.1.1 via 172.20.128.1 dev eth0 src 172.20.130.16 uid 1000";
}
if (cmd.includes("ip -4 -o route show default")) {
return "default via 172.20.128.1 dev eth0 proto kernel\n";
}
return "";
});
expect(candidates).toEqual(["172.20.130.16", "172.20.128.1"]);
});

it("falls back to hostname -I when ip route is unavailable", () => {
const ip = detectWsl2HostIp((cmd) => {
if (cmd.includes("ip -4 -o route get")) return "";
if (cmd.includes("hostname -I")) return "172.20.130.16 172.17.0.1";
return "";
});
expect(ip).toBe("172.20.130.16");
});

it("skips docker bridge, loopback, and link-local addresses", () => {
const ip = detectWsl2HostIp((cmd) => {
if (cmd.includes("ip -4 -o route get")) return "";
if (cmd.includes("hostname -I"))
return "127.0.0.1 172.17.0.1 169.254.1.2 10.42.0.5 192.168.1.50";
return "";
});
expect(ip).toBe("192.168.1.50");
});

it("returns null when no usable address is found", () => {
expect(
detectWsl2HostIp((cmd) => {
if (cmd.includes("ip -4 -o route get")) return "";
if (cmd.includes("hostname -I")) return "127.0.0.1 172.17.0.1";
return "";
}),
).toBeNull();
});

it("returns null when both probes fail", () => {
expect(detectWsl2HostIp(() => "")).toBeNull();
});

it("ignores non-IPv4 tokens from hostname -I (IPv6 etc.)", () => {
const ip = detectWsl2HostIp((cmd) => {
if (cmd.includes("ip -4 -o route get")) return "";
if (cmd.includes("hostname -I")) return "fe80::1234 192.168.1.50";
return "";
});
expect(ip).toBe("192.168.1.50");
});
});

it("detects WSL2 host IP and uses it for the container check", () => {
const result = validateLocalProvider(
"ollama-local",
(cmd) => {
if (cmd.includes("/api/tags") && !cmd.includes("docker run")) {
return '{"models":[]}'; // localhost health check
}
if (cmd.includes("ip -4 -o route get")) {
return "1.1.1.1 via 172.20.128.1 dev eth0 src 172.20.130.16 uid 1000";
}
if (cmd.includes("ip -4 -o route show default")) {
return "default via 172.20.128.1 dev eth0 proto kernel";
}
if (cmd.includes("docker run") && cmd.includes("172.20.130.16")) {
return '{"models":[]}'; // first candidate wins
}
return "";
},
{ isWsl: true, isDockerDesktop: true },
);
expect(result).toEqual({ ok: true, resolvedHostIp: "172.20.130.16" });
});

it("falls back to default gateway when eth0 candidate is not reachable", () => {
const result = validateLocalProvider(
"ollama-local",
(cmd) => {
if (cmd.includes("/api/tags") && !cmd.includes("docker run")) {
return '{"models":[]}';
}
if (cmd.includes("ip -4 -o route get")) {
return "1.1.1.1 via 172.20.128.1 dev eth0 src 172.20.130.16 uid 1000";
}
if (cmd.includes("ip -4 -o route show default")) {
return "default via 172.20.128.1 dev eth0 proto kernel";
}
// only the gateway candidate reaches Windows-hosted Ollama
if (cmd.includes("docker run") && cmd.includes("172.20.128.1")) {
return '{"models":[]}';
}
return "";
},
{ isWsl: true, isDockerDesktop: true },
);
expect(result).toEqual({ ok: true, resolvedHostIp: "172.20.128.1" });
});

it("falls back to host-gateway when not on WSL2 + Docker Desktop", () => {
let callCount = 0;
const result = validateLocalProvider(
"ollama-local",
() => {
callCount += 1;
return '{"models":[]}';
},
{ isWsl: false, isDockerDesktop: false },
);
expect(result).toEqual({ ok: true });
expect(callCount).toBe(2); // no hostname -I call
});

it("treats unknown local providers as already valid", () => {
expect(validateLocalProvider("custom-provider", () => "")).toEqual({ ok: true });
});
Expand Down
Loading