Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
da69672
fix(platform): probe Docker with the environment its commands run in
Dongni-Yang Aug 26, 2026
9e70b46
fix(platform): keep the Docker probe on the runner's proxy exclusions
Dongni-Yang Aug 26, 2026
491417c
test(platform): cover the probe's no-verdict classifier
Dongni-Yang Aug 26, 2026
33b8736
merge(main): refresh PR 10379 after advisor repair
apurvvkumaria Aug 30, 2026
786723d
test(platform): apply current formatting
apurvvkumaria Aug 30, 2026
c17a403
merge(main): adopt current policy authority
apurvvkumaria Aug 30, 2026
c1327a7
merge(main): refresh Docker authority probe
apurvvkumaria Aug 31, 2026
a24ae49
docs(cli): correct Docker probe comments
apurvvkumaria Aug 31, 2026
edf8408
merge(main): incorporate release documentation
apurvvkumaria Aug 31, 2026
d1fea67
docs(cli): correct Docker timeout comment
apurvvkumaria Aug 31, 2026
f813e8d
test(platform): cover rootless Docker selection
apurvvkumaria Aug 31, 2026
738d133
merge(main): incorporate current release updates
apurvvkumaria Aug 31, 2026
e678266
fix(onboard): bound Docker preflight probes
apurvvkumaria Aug 31, 2026
dc62ae4
merge: resolve conflicts with main
github-actions[bot] Sep 3, 2026
70ed2fe
fix(platform): preserve inconclusive Docker probes
prekshivyas Sep 3, 2026
fb9acca
test(plugin): cover Docker subprocess authority
prekshivyas Sep 3, 2026
6d4488d
test(plugin): use explicit subprocess env import
prekshivyas Sep 3, 2026
bcf31b5
fix(readiness): preserve inconclusive Docker probes
prekshivyas Sep 3, 2026
82efb29
merge: resolve conflicts with main
github-actions[bot] Sep 4, 2026
7e569aa
merge: resolve conflicts with main
github-actions[bot] Sep 4, 2026
4b81fd4
Merge branch 'main' into fix/10367-docker-host-detection
prekshivyas Sep 4, 2026
b20e7fc
chore(ci): ratchet the subprocess-env fan-in budget to its measured v…
Dongni-Yang Sep 7, 2026
7d1476a
Merge upstream/main into wt/10367-docker-host-detection
Dongni-Yang Sep 9, 2026
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
2 changes: 1 addition & 1 deletion ci/source-architecture-budget.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"src/lib/state/onboard-session.ts": 35,
"src/lib/state/registry.ts": 97,
"src/lib/state/state-root.ts": 21,
"src/lib/subprocess-env.ts": 24,
"src/lib/subprocess-env.ts": 25,
"src/lib/validation.ts": 24
}
},
Expand Down
55 changes: 46 additions & 9 deletions src/lib/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import os from "node:os";
import path from "node:path";

import { dockerSpawnSync } from "./adapters/docker/exec";
import { isSubprocessEnvNameAllowed, withLocalNoProxy } from "./subprocess-env";

export type ContainerRuntime = "podman" | "colima" | "docker-desktop" | "docker" | "unknown";

Expand Down Expand Up @@ -40,13 +41,20 @@ export type DockerVersionIdentity = "docker" | "podman" | "unknown";
export interface DockerHostProbeResult {
reachable: boolean;
identity: DockerVersionIdentity;
/**
* The probe never reached a verdict: the Docker CLI could not be spawned,
* it was killed by the probe timeout, or it produced no complete answer.
* Unreachability was not observed, so this must not license a redirect.
* The timeout therefore biases toward holding the host default — raising
* it buys patience for a slow daemon, not more fallback coverage.
*/
inconclusive?: boolean;
}

export type DockerHostProbe = (dockerHost: string | undefined) => DockerHostProbeResult;

const DOCKER_PROBE_TIMEOUT_MS = 3_000;
const DOCKER_PROBE_MAX_BUFFER_BYTES = 1024 * 1024;
const DOCKER_PROBE_ENV_NAMES = ["HOME", "USER", "LOGNAME", "PATH"] as const;

function isWsl(opts: WslDetectionOptions = {}): boolean {
// Explicit override — lets tests pin behavior regardless of the host kernel.
Expand Down Expand Up @@ -124,14 +132,27 @@ function classifyDockerVersionIdentity(versionOutput = ""): DockerVersionIdentit
return "unknown";
}

/**
* Probe the Docker CLI in the same environment the CLI's real Docker
* commands run in (`buildSubprocessEnv`), minus the authority under test.
*
* The probe predicts whether those commands will reach a daemon, so any
* name they get and it does not can flip its verdict: `SSH_AUTH_SOCK`
* authenticates an `ssh://` Docker context, and the proxy names decide how
* a `tcp://` one is routed. A verdict from a narrower environment can call
* a daemon unreachable that every later command talks to, which sends
* detection to a fallback socket the host never meant to use (#10367).
*/
function buildDockerProbeEnv(
source: NodeJS.ProcessEnv,
dockerHost: string | undefined,
): NodeJS.ProcessEnv {
const env: NodeJS.ProcessEnv = {};
for (const name of DOCKER_PROBE_ENV_NAMES) {
const value = source[name];
if (value !== undefined) env[name] = value;
): Record<string, string> {
const env: Record<string, string> = {};
for (const [name, value] of Object.entries(source)) {
// The probe pins its own authority; an ambient one would mask it.
if (name === "DOCKER_HOST") continue;
if (value === undefined) continue;
if (isSubprocessEnvNameAllowed(name)) env[name] = value;
}
if (dockerHost === undefined) {
if (source.DOCKER_CONFIG !== undefined) env.DOCKER_CONFIG = source.DOCKER_CONFIG;
Expand All @@ -140,6 +161,9 @@ function buildDockerProbeEnv(
if (dockerHost) {
env.DOCKER_HOST = dockerHost;
}
// Keep a local authority off a forwarded host proxy, exactly as
// `buildSubprocessEnv` does for the Docker commands that follow.
withLocalNoProxy(env);
return env;
}

Expand All @@ -153,7 +177,10 @@ function probeDockerHost(
timeout: DOCKER_PROBE_TIMEOUT_MS,
maxBuffer: DOCKER_PROBE_MAX_BUFFER_BYTES,
});
if (!result || result.status !== 0) return { reachable: false, identity: "unknown" };
if (!result || result.error || result.status === null) {
return { reachable: false, identity: "unknown", inconclusive: true };
}
if (result.status !== 0) return { reachable: false, identity: "unknown" };
return {
reachable: true,
identity: classifyDockerVersionIdentity(String(result.stdout ?? "")),
Expand Down Expand Up @@ -240,10 +267,16 @@ function getDockerSocketCandidates(opts: PlatformLookupOptions = {}): string[] {
}

if (platform === "linux") {
const uid = opts.uid ?? process.getuid?.() ?? 1000;
// The rootless Docker daemon puts its socket in the same runtime
// directory as Podman's, and was never a candidate here (#10367).
// Order decides only between candidates that identify as the same
// engine; two engines that both answer still abort the selection below.
return [
...getPodmanSocketCandidates({ home, platform, uid: opts.uid }),
"/run/docker.sock",
"/var/run/docker.sock",
`/run/user/${String(uid)}/docker.sock`,
...getPodmanSocketCandidates({ home, platform, uid: opts.uid }),
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
];
}

Expand All @@ -261,7 +294,11 @@ function detectDockerHost(opts: DockerHostDetectionOptions = {}): DockerHostDete
}

const probe = opts.probeDockerHost ?? ((dockerHost) => probeDockerHost(dockerHost, env));
if (probe(undefined).reachable) return null;
const ambient = probe(undefined);
// Redirect the CLI away from the host's own default authority only after
// observing that the default refuses to answer. A probe that timed out or
// never ran is no evidence at all (#10367).
if (ambient.reachable || ambient.inconclusive) return null;

const fileExists = opts.existsSync ?? defaultExistsSync;
let selection: DockerHostDetection | null = null;
Expand Down
71 changes: 65 additions & 6 deletions test/e2e-runtime/platform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,15 @@ describe("platform helpers", () => {
]);
});

it("returns Linux candidates (Podman > native Docker)", () => {
it("returns Linux candidates (native Docker > rootless Docker > Podman)", () => {
expect(
getDockerSocketCandidates({ platform: "linux", home: "/tmp/test-home", uid: 1000 }),
).toEqual([
"/run/user/1000/podman/podman.sock",
"/run/podman/podman.sock",
"/run/docker.sock",
"/var/run/docker.sock",
"/run/user/1000/docker.sock",
"/run/user/1000/podman/podman.sock",
"/run/podman/podman.sock",
]);
});
});
Expand Down Expand Up @@ -322,7 +323,7 @@ describe("platform helpers", () => {
});
});

it("preserves a reachable Docker context and config before local socket fallbacks (#8816)", () => {
it("probes the default Docker authority with the environment real commands get (#8816, #10367)", () => {
const fixtureDir = mkdtempSync(path.join(os.tmpdir(), "nemoclaw-docker-authority-"));
try {
const docker = path.join(fixtureDir, "docker");
Expand All @@ -332,21 +333,29 @@ describe("platform helpers", () => {
path.join(dockerConfig, "config.json"),
JSON.stringify({ currentContext: "healthy-context" }),
);
// Each guard below stands for a real host whose default authority
// answers only through that name: a named Docker context, a rootless
// daemon under the runtime directory, and a local endpoint kept off a
// forwarded host proxy. Answering Podman under an explicit DOCKER_HOST
// makes any missing name redirect the whole CLI to a fallback socket.
writeFileSync(
docker,
[
"#!/bin/sh",
'test "$1" = "version" || exit 2',
'test -z "${NVIDIA_INFERENCE_API_KEY:-}" || exit 5',
'if test -z "${DOCKER_HOST:-}"; then',
' test "${DOCKER_CONTEXT:-}" = "healthy-context" || exit 4',
` test "\${DOCKER_CONFIG:-}" = "${dockerConfig}" || exit 7`,
' test -f "$DOCKER_CONFIG/config.json" || exit 8',
' test -n "${XDG_RUNTIME_DIR:-}" || exit 3',
' case ",${NO_PROXY:-}," in *,127.0.0.1,*) ;; *) exit 10 ;; esac',
' printf \'%s\\n\' \'{"Server":{"Platform":{"Name":"Docker Engine - Community"}}}\'',
"else",
' test -z "${DOCKER_CONTEXT:-}" || exit 6',
' test -z "${DOCKER_CONFIG:-}" || exit 9',
' printf \'%s\\n\' \'{"Server":{"Components":[{"Name":"Podman Engine"}]}}\'',
"fi",
'test -z "${NVIDIA_INFERENCE_API_KEY:-}" || exit 5',
'printf \'%s\\n\' \'{"Server":{"Platform":{"Name":"Docker Engine - Community"}}}\'',
].join("\n"),
);
chmodSync(docker, 0o755);
Expand All @@ -358,6 +367,8 @@ describe("platform helpers", () => {
PATH: fixtureDir,
DOCKER_CONFIG: dockerConfig,
DOCKER_CONTEXT: "healthy-context",
XDG_RUNTIME_DIR: "/run/user/1000",
HTTP_PROXY: "http://proxy.invalid:3128",
NVIDIA_INFERENCE_API_KEY: "test-secret-must-not-cross-probe-boundary",
},
platform: "linux",
Expand All @@ -371,6 +382,54 @@ describe("platform helpers", () => {
rmSync(fixtureDir, { recursive: true, force: true });
}
});

it("classifies a Docker CLI that dies without answering as no verdict (#10367)", () => {
// Exercises the real probe rather than an injected one. A signal death
// reports the same "no exit status" that the probe timeout produces,
// and must not read as "the default authority refused" and send the
// CLI to the Podman socket that answers right after it.
const fixtureDir = mkdtempSync(path.join(os.tmpdir(), "nemoclaw-docker-no-verdict-"));
try {
const docker = path.join(fixtureDir, "docker");
writeFileSync(
docker,
[
"#!/bin/sh",
'test -n "${DOCKER_HOST:-}" || kill -TERM $$',
'printf \'%s\\n\' \'{"Server":{"Components":[{"Name":"Podman Engine"}]}}\'',
].join("\n"),
);
chmodSync(docker, 0o755);

expect(
detectDockerHost({
env: { HOME: fixtureDir, PATH: fixtureDir },
platform: "linux",
uid: 1000,
existsSync: (candidate) => candidate === "/run/user/1000/podman/podman.sock",
}),
).toBe(null);
} finally {
rmSync(fixtureDir, { recursive: true, force: true });
}
});

it("keeps the host default authority when the default probe never answers (#10367)", () => {
const socketPath = "/run/user/1000/podman/podman.sock";

expect(
detectDockerHost({
env: {},
platform: "linux",
uid: 1000,
existsSync: (candidate) => candidate === socketPath,
probeDockerHost: (dockerHost) =>
dockerHost
? { reachable: true, identity: "podman" }
: { reachable: false, identity: "unknown", inconclusive: true },
}),
).toBe(null);
});
});

describe("classifyDockerVersionIdentity", () => {
Expand Down
Loading