Skip to content

feat(onboard): detect Windows-host Ollama from WSL via host.docker.inernal - #2707

Merged
brandonpelfrey merged 5 commits into
mainfrom
feat/wsl-ollama-detect-host
Apr 30, 2026
Merged

brandonpelfrey merged 5 commits into
mainfrom
feat/wsl-ollama-detect-host

Conversation

@zyang-dev

@zyang-dev zyang-dev commented Apr 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

When Ollama runs on the Windows host (a common WSL setup), the WSL onboard CLI couldn't detect it because Ollama's default 127.0.0.1 binding lives in a different network namespace from WSL. This adds a host.docker.internal fallback probe so WSL users with Windows-host Ollama (OLLAMA_HOST=0.0.0.0) get auto-detection without manual configuration.

Changes

  • New host resolver in src/lib/local-inference.ts: findReachableOllamaHost() probes 127.0.0.1 first and, on WSL only, falls back to host.docker.internal. Result is cached per onboard run; getResolvedOllamaHost() returns it for URL builders, and resetOllamaHostCache() is exposed for tests.
  • All Ollama URL builders and HTTP helpers now go through getResolvedOllamaHost(): getLocalProviderValidationBaseUrl, getLocalProviderHealthEndpoint, getOllamaModelOptions, getOllamaWarmupCommand, getOllamaProbeCommand, plus the validation-failure error message.
  • src/lib/onboard.ts: replaces the direct 127.0.0.1 curl probe with findReachableOllamaHost().
  • Native Linux and macOS behavior is unchanged: findReachableOllamaHost() only probes 127.0.0.1 outside WSL, and getResolvedOllamaHost() falls back to 127.0.0.1 until populated.

Type of Change

  • Code change (feature, bug fix, or refactor)
  • Code change with doc updates
  • Doc only (prose changes, no code sample modifications)
  • Doc only (includes code sample changes)

Verification

  • npx prek run --all-files passes
  • npm test passes
  • Tests added or updated for new or changed behavior
  • No secrets, API keys, or credentials committed
  • Docs updated for user-facing behavior changes
  • make docs builds without warnings (doc changes only)
  • Doc pages follow the style guide (doc changes only)
  • New doc pages include SPDX header and frontmatter (new pages only)

AI Disclosure

  • AI-assisted — tool: Claude Code

Signed-off-by: zyang-dev [email protected]

Summary by CodeRabbit

  • Bug Fixes
    • Improved local Ollama host detection on WSL/Docker so the app reliably finds and uses a reachable local host for health checks.
    • Onboarding now uses cached reachability checks for faster, more consistent local Ollama discovery and status suggestions.
    • Validation messages, model discovery, and warmup/probe operations now reference the resolved host for clearer, more accurate feedback.

@coderabbitai

coderabbitai Bot commented Apr 29, 2026 •

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 998d8739-f6ad-4da5-b379-5fdff57ea731

📥 Commits

Reviewing files that changed from the base of the PR and between 8f40052 and 9ef4f19.

📒 Files selected for processing (1)
  • src/lib/onboard.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/lib/onboard.ts

📝 Walkthrough

Walkthrough

Adds WSL-aware, cached Ollama host resolution: probes candidate hosts (127.0.0.1, host.docker.internal) at /api/tags with short timeouts; exposes findReachableOllamaHost(), getResolvedOllamaHost(), and resetOllamaHostCache(); replaces hardcoded localhost usage and updates onboarding to use the cached probe result.

Changes

Cohort / File(s) Summary
Ollama Host Resolution Infrastructure
src/lib/local-inference.ts
Add OLLAMA_LOCALHOST and OLLAMA_HOST_DOCKER_INTERNAL; implement cached probe findReachableOllamaHost() (short curl/connect timeouts), getResolvedOllamaHost(), and resetOllamaHostCache(); update Ollama URL/health/model discovery/warmup/probe builders and error messages to use resolved host instead of 127.0.0.1.
Onboarding Integration
src/lib/onboard.ts
Change setupNim to base Ollama availability on findReachableOllamaHost() (cached, WSL-aware) instead of a direct uncached 127.0.0.1 /api/tags curl probe.

Sequence Diagram(s)

sequenceDiagram
  participant Client as Client/UI
  participant Resolver as findReachableOllamaHost()
  participant HostA as 127.0.0.1:/api/tags
  participant HostB as host.docker.internal:/api/tags
  participant Cache as HostCache

  Client->>Resolver: request resolved host
  Resolver->>Cache: check cached host
  alt cache miss
    Resolver->>HostA: GET /api/tags (short timeouts)
    alt HostA responds
      HostA-->>Resolver: 200 OK
      Resolver->>Cache: store HostA
      Resolver-->>Client: return HostA
    else HostA fails
      Resolver->>HostB: GET /api/tags (short timeouts)
      alt HostB responds
        HostB-->>Resolver: 200 OK
        Resolver->>Cache: store HostB
        Resolver-->>Client: return HostB
      else HostB fails
        Resolver-->>Client: return null
      end
    end
  else cache hit
    Cache-->>Resolver: cached host
    Resolver-->>Client: return cached host
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 I hopped from localhost to dock and back,

I tapped /api/tags on every track,
I cached the host so probes run fast,
Now Ollama calls connect at last,
A rabbit's cheer — the network's glad.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 18.18% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding WSL-aware detection of Windows-host Ollama via host.docker.internal fallback. It directly maps to the core problem and solution of the changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/wsl-ollama-detect-host

Review rate limit: 9/10 reviews remaining, refill in 6 minutes.

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/lib/local-inference.ts (1)

294-297: ⚠️ Potential issue | 🟡 Minor

Inconsistent error message: hardcoded 127.0.0.1 should use resolved host.

If Ollama was detected on host.docker.internal (WSL scenario), this message incorrectly states it's "responding on 127.0.0.1". The message at line 271 correctly uses getResolvedOllamaHost() — this should match.

🔧 Proposed fix
     case "ollama-local":
       return {
         ok: false,
-        message: `Local Ollama is responding on 127.0.0.1, but containers cannot reach the auth proxy at http://host.openshell.internal:${OLLAMA_CONTAINER_PORT}. Ensure the Ollama auth proxy is running.`,
+        message: `Local Ollama is responding on ${getResolvedOllamaHost()}, but containers cannot reach the auth proxy at http://host.openshell.internal:${OLLAMA_CONTAINER_PORT}. Ensure the Ollama auth proxy is running.`,
       };
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/lib/local-inference.ts` around lines 294 - 297, The error message in the
switch branch for "ollama-local" incorrectly hardcodes "127.0.0.1"; update the
returned message to use getResolvedOllamaHost() (same as the earlier branch) and
include OLLAMA_CONTAINER_PORT so the message reads consistently (e.g., "Local
Ollama is responding on <getResolvedOllamaHost()>, but containers cannot reach
the auth proxy at http://host.openshell.internal:<OLLAMA_CONTAINER_PORT>. Ensure
the Ollama auth proxy is running."). Target the case "ollama-local" return
object to swap the hardcoded host for the getResolvedOllamaHost() call.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/lib/onboard.ts`:
- Around line 4251-4255: The current code converts the result of
findReachableOllamaHost() to a boolean (ollamaRunning), losing whether the
resolved host was "127.0.0.1" or "host.docker.internal"; change this to capture
and retain the resolved host string (e.g., const ollamaHost =
findReachableOllamaHost()) and derive the running flag from it (const
ollamaRunning = ollamaHost !== null), then update downstream labels/logging to
use ollamaHost (with a safe fallback like "localhost" where UI text expects a
host) instead of always showing "localhost"; after making this change, run the
recommended onboarding E2E jobs (cloud-e2e, sandbox-operations-e2e,
rebuild-openclaw-e2e) before merging.

---

Outside diff comments:
In `@src/lib/local-inference.ts`:
- Around line 294-297: The error message in the switch branch for "ollama-local"
incorrectly hardcodes "127.0.0.1"; update the returned message to use
getResolvedOllamaHost() (same as the earlier branch) and include
OLLAMA_CONTAINER_PORT so the message reads consistently (e.g., "Local Ollama is
responding on <getResolvedOllamaHost()>, but containers cannot reach the auth
proxy at http://host.openshell.internal:<OLLAMA_CONTAINER_PORT>. Ensure the
Ollama auth proxy is running."). Target the case "ollama-local" return object to
swap the hardcoded host for the getResolvedOllamaHost() call.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 2b144ba5-5a77-45f1-952d-5c1d0221609f

📥 Commits

Reviewing files that changed from the base of the PR and between 23699c9 and 1b3ce9e.

📒 Files selected for processing (2)
  • src/lib/local-inference.ts
  • src/lib/onboard.ts

Comment thread src/lib/onboard.ts
Comment on lines +4251 to +4255
// findReachableOllamaHost probes 127.0.0.1 first and, on WSL, falls back
// to host.docker.internal so a Windows-host Ollama bound to a non-loopback
// interface is detected. The result is cached for the rest of the onboard
// run and consumed by the Ollama lifecycle helpers in local-inference.ts.
const ollamaRunning = findReachableOllamaHost() !== null;

@coderabbitai coderabbitai Bot Apr 29, 2026 •

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 | 🟡 Minor

Keep the resolved Ollama host string for accurate UX on WSL.

At Line 4255, host resolution is reduced to a boolean. That works for branching, but it drops whether the selected host is 127.0.0.1 or host.docker.internal. Downstream labels/logs still say localhost, which is misleading in the Windows-host Ollama case.

💡 Suggested patch
-  const ollamaRunning = findReachableOllamaHost() !== null;
+  const reachableOllamaHost = findReachableOllamaHost();
+  const ollamaRunning = reachableOllamaHost !== null;
...
-      label:
-        `Local Ollama (localhost:${OLLAMA_PORT})${ollamaRunning ? " — running" : ""}` +
+      label:
+        `Local Ollama (${reachableOllamaHost ?? "localhost"}:${OLLAMA_PORT})${ollamaRunning ? " — running" : ""}` +
         (ollamaRunning ? " (suggested)" : ""),
...
-          console.log(`  ✓ Using Ollama on localhost:${OLLAMA_PORT}`);
+          console.log(
+            `  ✓ Using Ollama on ${reachableOllamaHost ?? "127.0.0.1"}:${OLLAMA_PORT}`,
+          );

Also, since this touches core onboarding flow, run the recommended onboarding E2E jobs before merge (cloud-e2e, sandbox-operations-e2e, rebuild-openclaw-e2e). As per coding guidelines: src/lib/onboard.ts is core onboarding logic and these E2E jobs are explicitly recommended.

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

In `@src/lib/onboard.ts` around lines 4251 - 4255, The current code converts the
result of findReachableOllamaHost() to a boolean (ollamaRunning), losing whether
the resolved host was "127.0.0.1" or "host.docker.internal"; change this to
capture and retain the resolved host string (e.g., const ollamaHost =
findReachableOllamaHost()) and derive the running flag from it (const
ollamaRunning = ollamaHost !== null), then update downstream labels/logging to
use ollamaHost (with a safe fallback like "localhost" where UI text expects a
host) instead of always showing "localhost"; after making this change, run the
recommended onboarding E2E jobs (cloud-e2e, sandbox-operations-e2e,
rebuild-openclaw-e2e) before merging.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reduced to a boolean to avoid an unused-variable lint warning, since this PR doesn't consume the resolved host. The following PR will switch it back to the host string and use it for labels and logs.

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.

@zyang-dev Thanks for the context. If you’d like to keep this PR behaviorally scoped but still avoid the unused-var lint and improve the UX now, here’s a tiny patch that retains and uses the resolved host string just for the label and WSL log. It keeps the rest of the flow unchanged and won’t trip the linter because the variable is consumed.

diff --git a/src/lib/onboard.ts b/src/lib/onboard.ts
@@
   // Detect local inference options
   const hasOllama = hostCommandExists("ollama");
-  // findReachableOllamaHost probes 127.0.0.1 first and, on WSL, falls back
-  // to host.docker.internal so a Windows-host Ollama bound to a non-loopback
-  // interface is detected. The result is cached for the rest of the onboard
-  // run and consumed by the Ollama lifecycle helpers in local-inference.ts.
-  const ollamaRunning = findReachableOllamaHost() !== null;
+  // findReachableOllamaHost probes 127.0.0.1 first and, on WSL, falls back
+  // to host.docker.internal. The result is cached for this onboard run.
+  const reachableOllamaHost = findReachableOllamaHost();
+  const ollamaRunning = reachableOllamaHost !== null;
@@
-  if (hasOllama || ollamaRunning) {
+  if (hasOllama || ollamaRunning) {
     options.push({
       key: "ollama",
-      label:
-        `Local Ollama (localhost:${OLLAMA_PORT})${ollamaRunning ? " — running" : ""}` +
+      label:
+        `Local Ollama (${reachableOllamaHost ?? "localhost"}:${OLLAMA_PORT})${ollamaRunning ? " — running" : ""}` +
         (ollamaRunning ? " (suggested)" : ""),
     });
   }
@@
       } else if (selected.key === "ollama") {
         if (!checkOllamaPortsOrWarn()) continue selectionLoop;
         if (!ollamaRunning) {
           console.log("  Starting Ollama...");
           const ollamaEnv = isWsl() ? "" : `OLLAMA_HOST=0.0.0.0:${OLLAMA_PORT} `;
           runShell(`${ollamaEnv}ollama serve > /dev/null 2>&1 &`, { ignoreError: true });
           sleep(2);
           if (!isWsl()) printOllamaExposureWarning();
         }
-        if (isWsl()) {
-          // WSL2 doesn't need the proxy — Docker can reach the host directly.
-          console.log(`  ✓ Using Ollama on localhost:${OLLAMA_PORT}`);
-        } else {
+        if (isWsl()) {
+          // WSL2 doesn't need the proxy — Docker can reach the host directly.
+          console.log(
+            `  ✓ Using Ollama on ${reachableOllamaHost ?? "127.0.0.1"}:${OLLAMA_PORT}`,
+          );
+        } else {
           if (!startOllamaAuthProxy()) {
             process.exit(1);
           }
           console.log(
             `  ✓ Using Ollama on localhost:${OLLAMA_PORT} (proxy on :${OLLAMA_PROXY_PORT})`,
           );
         }

If you’d rather keep this PR exactly as-is and handle labels/logs in the follow-up, no problem—let me know and I can open a tracking issue to capture the UX fix.

Also, since this touches src/lib/onboard.ts (core onboarding), please run the recommended E2E jobs before merge:

  • cloud-e2e
  • sandbox-operations-e2e
  • rebuild-openclaw-e2e

Command you can copy-paste:

  • gh workflow run nightly-e2e.yaml --ref feat/wsl-ollama-detect-host -f jobs=cloud-e2e,sandbox-operations-e2e,rebuild-openclaw-e2e

Want me to open the follow-up issue for the label/log polish if you decide to defer?


🧠 Learnings used
Learnt from: jyaunches
Repo: NVIDIA/NemoClaw PR: 2495
File: src/lib/onboard-inference-probes.ts:135-323
Timestamp: 2026-04-27T13:06:57.456Z
Learning: In NVIDIA/NemoClaw PRs that extract code from `src/lib/onboard.ts` into new behavior-preserving modules (e.g., `src/lib/onboard-providers.ts`, `src/lib/onboard-ollama-proxy.ts`, `src/lib/onboard-inference-probes.ts`), reviewers should avoid requesting refactors/complexity/style improvements in the extracted modules as part of the same PR. Only check for correctness and behavior preservation; defer non-behavior-preserving cleanup to separate follow-up PRs.

Learnt from: ericksoa
Repo: NVIDIA/NemoClaw PR: 2554
File: src/lib/onboard.ts:698-700
Timestamp: 2026-04-28T17:22:19.715Z
Learning: For NVIDIA/NemoClaw credential environment hydration/migration, implement fill-only-if-missing semantics across the onboarding and credentials modules: (1) In src/lib/credentials.ts, stageLegacyCredentialsToEnv() should only consider an allowlisted set of credential keys and should set process.env[key] only when getCredential(key) returns null (never override an explicitly provided env export). Treat blank/whitespace values as unset. (2) In src/lib/onboard.ts, hydrateCredentialEnv(envName) must first read getCredential(envName) and only call stageLegacyCredentialsToEnv() when that specific key is missing; after staging, re-read and then set process.env[envName]. This ensures stale credentials.json values cannot override explicitly provided environment credentials.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'd rather keep this PR exactly as-is and handle labels/logs in the follow-up.

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.

@zyang-dev Got it — we’ll keep this PR behavior-scoped and handle the labels/logs in a follow-up.

Would you like me to open a tracking issue for the follow-up? Proposed:

  • Title: UX: show resolved Ollama host in onboard provider label and WSL log
  • Scope:
    • Capture reachable host via findReachableOllamaHost() in setupNim.
    • Use it in the “Local Ollama (…)” option label and the WSL “Using Ollama on …” log line.
    • Keep the rest of the flow unchanged; ensure no unused-var lint.

Also, since this touches src/lib/onboard.ts, please run the recommended E2E jobs before merging:

  • gh workflow run nightly-e2e.yaml --ref feat/wsl-ollama-detect-host -f jobs=cloud-e2e,sandbox-operations-e2e,rebuild-openclaw-e2e

If you want, I can file the issue and/or kick off those workflows for you — just say the word.


🧠 Learnings used
Learnt from: jyaunches
Repo: NVIDIA/NemoClaw PR: 2495
File: src/lib/onboard-inference-probes.ts:135-323
Timestamp: 2026-04-27T13:06:57.456Z
Learning: In NVIDIA/NemoClaw PRs that extract code from `src/lib/onboard.ts` into new behavior-preserving modules (e.g., `src/lib/onboard-providers.ts`, `src/lib/onboard-ollama-proxy.ts`, `src/lib/onboard-inference-probes.ts`), reviewers should avoid requesting refactors/complexity/style improvements in the extracted modules as part of the same PR. Only check for correctness and behavior preservation; defer non-behavior-preserving cleanup to separate follow-up PRs.

Learnt from: ericksoa
Repo: NVIDIA/NemoClaw PR: 2554
File: src/lib/onboard.ts:698-700
Timestamp: 2026-04-28T17:22:19.715Z
Learning: For NVIDIA/NemoClaw credential environment hydration/migration, implement fill-only-if-missing semantics across the onboarding and credentials modules: (1) In src/lib/credentials.ts, stageLegacyCredentialsToEnv() should only consider an allowlisted set of credential keys and should set process.env[key] only when getCredential(key) returns null (never override an explicitly provided env export). Treat blank/whitespace values as unset. (2) In src/lib/onboard.ts, hydrateCredentialEnv(envName) must first read getCredential(envName) and only call stageLegacyCredentialsToEnv() when that specific key is missing; after staging, re-read and then set process.env[envName]. This ensures stale credentials.json values cannot override explicitly provided environment credentials.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/lib/local-inference.ts`:
- Around line 48-54: The host probe in findReachableOllamaHost uses plain curl
which can block; modify the curl invocation built inside findReachableOllamaHost
(and used via runCapture/runCaptureImpl over ollamaCandidateHosts with
OLLAMA_PORT) to include explicit short timeouts (e.g., --connect-timeout and
--max-time) so each probe fails fast on blackholed hosts; update the capture
command array to add these timeout flags (choose small values like 2s/4s) and
keep ignoreError:true so discovery continues to the next host.
- Around line 295-297: The error message returned by the block that currently
constructs the container-reachability string (referencing
getResolvedOllamaHost() and OLLAMA_CONTAINER_PORT) should be made WSL-aware:
detect WSL (use the existing isWsl()/isWSL() helper or add a simple check) and,
when running under WSL, return a different remediation that explains Ollama is
contacted directly from WSL and no auth-proxy is required; otherwise keep the
existing guidance about ensuring the Ollama auth proxy is running at
http://host.openshell.internal:${OLLAMA_CONTAINER_PORT}. Adjust the conditional
around the current return so the message changes based on the WSL check.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 4c99a57b-fdfd-4a51-8098-250481a2bf1a

📥 Commits

Reviewing files that changed from the base of the PR and between 1b3ce9e and cc8ab05.

📒 Files selected for processing (1)
  • src/lib/local-inference.ts

Comment thread src/lib/local-inference.ts Resolved
Comment thread src/lib/local-inference.ts Resolved
…t-host

Signed-off-by: zyang-dev <[email protected]>

# Conflicts:
#	src/lib/local-inference.ts

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/lib/local-inference.ts (1)

42-85: ⚡ Quick win

Add regression coverage for the WSL fallback and cache semantics.

This logic is platform- and state-dependent now. A focused unit suite around candidate order, cache reuse, cache-miss retry behavior, and resetOllamaHostCache() would make this path much safer to change.

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

In `@src/lib/local-inference.ts` around lines 42 - 85, Add unit tests exercising
ollamaCandidateHosts(), findReachableOllamaHost(), getResolvedOllamaHost(), and
resetOllamaHostCache(): cover WSL vs non-WSL candidate order, successful probe
returning first reachable host, caching behavior across repeated
findReachableOllamaHost() calls (no re-probe when cache populated), retry
behavior when initial probes fail then succeed after reset, and that
resetOllamaHostCache() clears the cached host; use dependency injection of
runCaptureImpl to simulate curl success/failure and toggle isWsl() in tests to
validate fallback to OLLAMA_HOST_DOCKER_INTERNAL on WSL.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/lib/local-inference.ts`:
- Around line 77-80: The getter getResolvedOllamaHost currently hides whether a
probe has ever succeeded by always returning OLLAMA_LOCALHOST when
_resolvedOllamaHost is empty; change it to surface the empty cache so callers
can retry resolution: have getResolvedOllamaHost return undefined (or a nullable
type) when _resolvedOllamaHost is unset instead of defaulting to
OLLAMA_LOCALHOST, and update call sites that use getResolvedOllamaHost to call
findReachableOllamaHost() when the result is undefined (referencing
getResolvedOllamaHost, _resolvedOllamaHost, OLLAMA_LOCALHOST, and
findReachableOllamaHost).

---

Nitpick comments:
In `@src/lib/local-inference.ts`:
- Around line 42-85: Add unit tests exercising ollamaCandidateHosts(),
findReachableOllamaHost(), getResolvedOllamaHost(), and resetOllamaHostCache():
cover WSL vs non-WSL candidate order, successful probe returning first reachable
host, caching behavior across repeated findReachableOllamaHost() calls (no
re-probe when cache populated), retry behavior when initial probes fail then
succeed after reset, and that resetOllamaHostCache() clears the cached host; use
dependency injection of runCaptureImpl to simulate curl success/failure and
toggle isWsl() in tests to validate fallback to OLLAMA_HOST_DOCKER_INTERNAL on
WSL.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: ca1700f8-26e3-4455-bba8-4a840fd9bea7

📥 Commits

Reviewing files that changed from the base of the PR and between 41667d0 and 8f40052.

📒 Files selected for processing (2)
  • src/lib/local-inference.ts
  • src/lib/onboard.ts

Comment on lines +77 to +80
// Returns the resolved host if a probe has succeeded, otherwise OLLAMA_LOCALHOST.
// Used by URL-builder helpers that need a string and don't want to re-probe.
export function getResolvedOllamaHost(): string {
return _resolvedOllamaHost ?? OLLAMA_LOCALHOST;

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 | ⚡ Quick win

Retry WSL host resolution when the cache is still empty.

These helpers only read the cached success and otherwise fall back to 127.0.0.1. If the first findReachableOllamaHost() happens before Ollama is started, the later validation/model/probe paths never retry host.docker.internal, so a Windows-host Ollama that comes up mid-onboarding stays invisible for the rest of the run.

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

In `@src/lib/local-inference.ts` around lines 77 - 80, The getter
getResolvedOllamaHost currently hides whether a probe has ever succeeded by
always returning OLLAMA_LOCALHOST when _resolvedOllamaHost is empty; change it
to surface the empty cache so callers can retry resolution: have
getResolvedOllamaHost return undefined (or a nullable type) when
_resolvedOllamaHost is unset instead of defaulting to OLLAMA_LOCALHOST, and
update call sites that use getResolvedOllamaHost to call
findReachableOllamaHost() when the result is undefined (referencing
getResolvedOllamaHost, _resolvedOllamaHost, OLLAMA_LOCALHOST, and
findReachableOllamaHost).

@brandonpelfrey

Copy link
Copy Markdown
Contributor

Automated PR review summary

Reviewed PR #2707: feat(onboard): detect Windows-host Ollama from WSL via host.docker.inernal

Recommendation

  • Recommendation: PASS
  • Highest observed severity: low
  • Block merge: no
  • Why: The highest-risk PR claim is that WSL onboarding can detect Windows-host Ollama via host.docker.internal without regressing native Linux behavior. Source inspection shows the fallback ordering, cache, and downstream helper usage are implemented consistently, and sandbox evidence did not show a native-Linux dependency on host.docker.internal. The remaining issue is only misleading localhost wording in onboarding UX, which the PR discussion already deferred.
  • Reviewer summary: Reviewed the PR with targeted adversarial probes. I confirmed from source that WSL host fallback is cached and propagated through the Ollama helpers, and I validated in the real OpenShell sandbox that native Linux is not accidentally relying on host.docker.internal. I did not find a merge-blocking regression specific to this PR.

Installation and setup findings

  • What went well: the real installer path worked from the local repository, Docker access was healthy, onboarding created the expected sandbox, SSH into that NemoClaw-managed sandbox succeeded, and an in-sandbox OpenClaw prompt returned '4'. What I tried: I first inspected install.sh/scripts/install.sh to confirm the local-source env knob, then ran the repo root installer with NEMOCLAW_REPO_ROOT set, NEMOCLAW_PROVIDER=build, and NVIDIA_API_KEY passed through from NEMOCLAW_NVIDIA_BUILD_KEY, followed by NemoClaw CLI status/list checks, openshell sandbox ssh-config, a non-interactive SSH exec, and an in-sandbox openclaw agent probe.

What was validated

  • The PR revision was checked out in an isolated review environment.
  • The local checkout was installed using the repository installer flow as closely as the environment allowed.
  • Adversarial, PR-specific probes were then run against the installed environment and relevant repository context.
  • Diff summary:
 src/lib/local-inference.ts | 85 +++++++++++++++++++++++++++++++++++++++++-----
 src/lib/onboard.ts         |  9 +++--
 2 files changed, 82 insertions(+), 12 deletions(-)

Failing tests and unresolved impact

  • No failing adversarial tests were captured.

Passing tests and why they mattered

Passing test 1: WSL fallback host ordering and downstream host reuse

  • What was tested: On WSL, Ollama host resolution probes 127.0.0.1 first, falls back to host.docker.internal, caches the winning host, and downstream URL/command builders reuse that resolved host.
  • Why it mattered: If false, the PR’s main Windows-host Ollama detection claim is broken or only partially wired, so onboarding or later Ollama operations would still target the wrong host.
  • Observed result: findReachableOllamaHost() probes 127.0.0.1 first, then host.docker.internal only on WSL; success stores _resolvedOllamaHost. getLocalProviderValidationBaseUrl, getLocalProviderHealthEndpoint, getOllamaModelOptions, getOllamaWarmupCommand, and getOllamaProbeCommand all call getResolvedOllamaHost(); onboard.ts now uses findReachableOllamaHost() instead of a hardcoded localhost curl.
  • Command: python3 targeted inspection of src/lib/local-inference.ts and src/lib/onboard.ts
  • Recommended follow-up coverage: Add an integration/regression test that stubs probe responses and asserts WSL fallback order, cache behavior, and that every exported Ollama URL/command helper uses the resolved host.

Passing test 2: Native Linux sandbox does not incorrectly depend on host.docker.internal

  • What was tested: Outside WSL, behavior remains localhost-only; the real OpenShell sandbox should not expose a working Ollama path via host.docker.internal that would hide a regression in candidate-host selection.
  • Why it mattered: If false, the PR could silently shift native Linux behavior toward a Docker alias and make host resolution semantics inconsistent with the PR description.
  • Observed result: Inside the real sandbox, host.docker.internal resolved to 172.17.0.1 but the Ollama /api/tags probe was unreachable within 5 seconds. This supports the claim that native Linux should not rely on that alias and would still need localhost behavior.
  • Command: ssh -F /tmp/sshcfg openshell-nemoclaw-local-install 'getent hosts host.docker.internal; curl -sf http://host.docker.internal:11434/api/tags'
  • Recommended follow-up coverage: Add a regression test for non-WSL candidate-host selection so future changes do not probe or prefer host.docker.internal on native Linux/macOS.

Bottom line

  • Based on the install evidence and adversarial probes, this PR looks reasonable to approve.

@brandonpelfrey
brandonpelfrey merged commit b1d9f62 into main Apr 30, 2026
17 checks passed
@zyang-dev
zyang-dev deleted the feat/wsl-ollama-detect-host branch April 30, 2026 15:25
ericksoa pushed a commit that referenced this pull request Apr 30, 2026
…#2768)

<!-- markdownlint-disable MD041 -->
## Summary
When Ollama runs on the Windows host (now detected from WSL via
`host.docker.internal` after #2707), `nemoclaw onboard` could detect it
but couldn't pull new models because `pullOllamaModel` shells out to the
`ollama` CLI. This PR adds an HTTP `/api/pull` path that runs only when
the resolved host is `host.docker.internal`. Native Linux/macOS keeps
the existing CLI shell-out unchanged.

## Changes
 - `src/lib/onboard-ollama-proxy.ts`:
- Renamed existing `pullOllamaModel` to `pullOllamaModelViaCli` (no
logic change).
- Added `pullOllamaModelViaHttp(model)`: streams `POST /api/pull` via
curl with `--connect-timeout 10 --max-time 600`, parses NDJSON, renders
an in-place progress bar with throttled status updates. Falls back to
throttled per-line output when stdout is not a TTY.
- Added async dispatcher `pullOllamaModel`: routes to HTTP only when
`getResolvedOllamaHost() ===OLLAMA_HOST_DOCKER_INTERNAL`; otherwise CLI.
    - Made `prepareOllamaModel` async so the dispatcher can await.
- Distinct timeout message on curl exit 28; resume hint on any non-zero
exit (`Already-downloaded layers are kept; re-running the pull resumes
them.`).
- `src/lib/onboard.ts`: two `prepareOllamaModel` callers updated to
`await`.

## Type of Change

- [x] Code change (feature, bug fix, or refactor)
- [ ] Code change with doc updates
- [ ] Doc only (prose changes, no code sample modifications)
- [ ] Doc only (includes code sample changes)

## Verification
<!-- Check each item you ran and confirmed. Leave unchecked items you
skipped. -->
- [x] `npx prek run --all-files` passes
- [x] `npm test` passes
- [ ] Tests added or updated for new or changed behavior
- [x] No secrets, API keys, or credentials committed
- [ ] Docs updated for user-facing behavior changes
- [ ] `make docs` builds without warnings (doc changes only)
- [ ] Doc pages follow the [style
guide](https://github.com/NVIDIA/NemoClaw/blob/main/docs/CONTRIBUTING.md)
(doc changes only)
- [ ] New doc pages include SPDX header and frontmatter (new pages only)

## AI Disclosure
- [x] AI-assisted — tool: Claude Code

---
<!-- DCO sign-off required by CI. Run: git config user.name && git
config user.email -->
Signed-off-by: zyang-dev <[email protected]>


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Asynchronous model pulling with real-time streamed progress and
condensed non-interactive status updates.
* Automatic selection of an HTTP-based pull strategy for Windows/Docker
hosts to improve compatibility.

* **Bug Fixes**
* Pull results are now awaited before proceeding, ensuring accurate
success/failure handling.
* Improved error reporting that clearly distinguishes timeouts from
other connection failures.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: zyang-dev <[email protected]>
@wscurran wscurran added the feature PR adds or expands user-visible functionality label Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature PR adds or expands user-visible functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants