[All Platforms][Onboard] Ollama proxy health check passes when Ollama is down
Description
isProxyHealthy() in src/lib/inference/ollama/proxy.ts returns true when Ollama behind the auth proxy is down. The proxy answers /api/tags with 502, so the HTTP probe fails, but the function then falls back to the proxy PID. The proxy process is still alive, so the check passes.
Onboarding and nemoclaw inference set use this check to decide whether a local Ollama route is reachable. With the fallback, they set the route and continue against a dead backend.
Expected: isProxyHealthy() returns false unless the proxy returns Ollama's model list.
Reproduction Steps
- Start the auth proxy with
startOllamaAuthProxy()and nothing listening on the Ollama port. - Request
/api/tagsthrough the proxy. It returns 502. - Call
isProxyHealthy(). It returnstrue.
Environment
- macOS 26.5.2 (arm64), Node.js v22.22.3
- NemoClaw
mainat4c44f7cc8, isolated HOME and test ports - No Docker needed. The repro calls the proxy module directly.
Debug Output
backend :11499 listening: false
proxy started: true | proxy :11498 listening: true
GET /api/tags through proxy -> 502
isProxyHealthy(): true
Proposed fix
Remove the PID fallback and return the probe result. The patch below includes a regression test that fails when the fallback is restored. With it, 685 tests across the 40 affected suites pass and npm run checks:repository passes. I can't open a same-repository PR, and fork PRs fail the required openshell-sdk-package job, so the patch is here for a maintainer to adopt.
Fix: src/lib/inference/ollama/proxy.ts
diff --git a/src/lib/inference/ollama/proxy.ts b/src/lib/inference/ollama/proxy.ts
index d6602dc24..570d6d04c 100644
--- a/src/lib/inference/ollama/proxy.ts
+++ b/src/lib/inference/ollama/proxy.ts
@@ -818,23 +818,17 @@ function getOllamaProxyToken(): string | null {
}
/**
- * Check whether the Ollama auth proxy is actually healthy — not just that
- * the PID exists, but that the proxy endpoint responds to HTTP requests.
+ * Check whether the Ollama auth proxy is actually healthy, meaning the proxy
+ * returned Ollama's model list through its authenticated route.
*
* This is the correct check for the setupInference fallback: if the
* container reachability test fails (Docker bridge issue) but the proxy
* is confirmed healthy on the host, onboarding can safely continue.
+ *
+ * A live proxy PID alone is not enough. The proxy answers 502 when Ollama
+ * behind it is down, so its process can outlive the backend it fronts.
*/
function isProxyHealthy(): boolean {
- // 1. PID check — informational, but don't early-return on failure.
- // The proxy may have been restarted with a new PID that isn't in our
- // PID file, so the HTTP probe is the authoritative signal.
- const pid = loadPersistedProxyPid();
- const hasValidPid = isOllamaProxyProcess(pid);
-
- // 2. HTTP probe — confirm the proxy actually responds. This is the
- // authoritative check: a successful probe wins even if the PID file
- // is missing or stale (e.g., after a manual restart).
const proxyUrl = `http://127.0.0.1:${OLLAMA_PROXY_PORT}/api/tags`;
const token = loadPersistedProxyToken();
const output = runCurlCaptureWithAuthConfig(
@@ -842,12 +836,7 @@ function isProxyHealthy(): boolean {
proxyUrl,
token,
);
- if (output) return true;
-
- // HTTP probe failed — fall back to PID as a weaker signal.
- // This covers edge cases where the probe transiently fails but the
- // process is confirmed alive.
- return hasValidPid;
+ return Boolean(output);
}
function probeOllamaAuthProxyHealth(): { ok: boolean; endpoint: string; detail: string } {
Regression test: src/lib/inference/ollama/proxy.test.ts
diff --git a/src/lib/inference/ollama/proxy.test.ts b/src/lib/inference/ollama/proxy.test.ts
index fe23c4958..49494dc1d 100644
--- a/src/lib/inference/ollama/proxy.test.ts
+++ b/src/lib/inference/ollama/proxy.test.ts
@@ -716,3 +716,55 @@ describe("ollama auth proxy spawn env bind-probe override (#10240)", () => {
expect(stderr).not.toContain("SECURITY PROBE SKIPPED");
});
});
+
+describe("isProxyHealthy with a live proxy PID", () => {
+ const tempHomes: string[] = [];
+
+ afterEach(() => {
+ vi.restoreAllMocks();
+ delete require.cache[LIFECYCLE_DIST];
+ delete require.cache[PROXY_DIST];
+ while (tempHomes.length > 0) {
+ fs.rmSync(tempHomes.pop() as string, { force: true, recursive: true });
+ }
+ });
+
+ // The proxy answers 502 when Ollama behind it is down, so `curl -f` exits 22
+ // while the persisted PID still matches a running proxy.
+ function probeHealth(curl: { status: number; stdout: string }): boolean {
+ const home = fs.mkdtempSync(path.join(fs.realpathSync(os.tmpdir()), "nemoclaw-proxy-health-"));
+ tempHomes.push(home);
+ vi.stubEnv("HOME", home);
+ delete require.cache[LIFECYCLE_DIST];
+ delete require.cache[PROXY_DIST];
+ const lifecycle = require(LIFECYCLE_DIST) as typeof import("../local-adapter-lifecycle");
+ const stateDir = lifecycle.SHARED_LOCAL_ADAPTER_STATE_DIR;
+ fs.mkdirSync(stateDir, { recursive: true, mode: 0o700 });
+ fs.writeFileSync(path.join(stateDir, "ollama-auth-proxy.pid"), "4242", { mode: 0o600 });
+ fs.writeFileSync(path.join(stateDir, "ollama-proxy-token"), "token", { mode: 0o600 });
+ const runner = require(RUNNER_DIST);
+ const childProcess = require(CHILD_PROCESS_DIST) as typeof import("node:child_process");
+ const originalRunCapture = runner.runCapture;
+ runner.runCapture = () => "node /opt/nemoclaw/scripts/ollama-auth-proxy.mts";
+ vi.spyOn(childProcess, "spawnSync").mockReturnValue({
+ ...curl,
+ signal: null,
+ output: [],
+ pid: 1,
+ stderr: "",
+ });
+ try {
+ const proxy = require(PROXY_DIST) as typeof import("./proxy");
+ return proxy.isProxyHealthy();
+ } finally {
+ runner.runCapture = originalRunCapture;
+ }
+ }
+
+ it.each([
+ ["down", { status: 22, stdout: "" }, false],
+ ["serving its model list", { status: 0, stdout: '{"models":[]}' }, true],
+ ] as const)("reports health when Ollama behind the proxy is %s", (_state, curl, healthy) => {
+ expect(probeHealth(curl)).toBe(healthy);
+ });
+});
Checklist
- [x] I confirmed this bug is reproducible
- [x] I searched existing issues and this is not a duplicate
I'd like to work on this. Plan: remove the PID fallback in isProxyHealthy() so it returns true only when the proxy's /api/tags probe succeeds, and add a unit test for the 502 case (backend down, proxy alive).
Could a maintainer confirm the current same-repository continuation for this fix before any new implementation is opened?
At main 7757000943e7378997822be366270957a53e4599, isProxyHealthy still returns the live-PID fallback after the authenticated HTTP probe fails. This is a source check of the failure described in this issue, not a new runtime reproduction.
#12757 was closed with a maintainer note that #13611 preserved Eric Curtin's contribution on an NVIDIA branch. I could not resolve #13611 through the current PR API, so I cannot establish whether that successor is active or has another disposition. Please preserve the original contribution and authorship rather than duplicate it.
The required outcome remains an unhealthy result for an unavailable backend even while the proxy is alive, with successful authenticated model-list responses still accepted. Current-head regression proof should exercise both paths and the actual probe boundary.
My permission is READ, and the required reviewed-SDK job still rejects a fork head (trusted workflow). Could you point to the existing replacement, or provide a same-repository branch route for the bounded repair? No new duplicate PR has been opened.