Skip to content

[Bug] Percentage resource profiles exceed Colima Docker capacity (patch and regression tests) #14743

Description

@uncrayon

Investigation Summary

  • On macOS with a 12-CPU/18-GiB host and a Colima Docker VM limited to 4 CPUs and about 11.7 GiB, the developer resource profile requests 9 CPUs/13Gi when Kubernetes allocatable capacity is unavailable.
  • Docker rejects sandbox creation because the CPU request exceeds the engine's 4-CPU limit.
  • The same sizing bug is reproduced by deterministic tests against main at c474038df67fcb22182298ac9a696c81e63f0ee2.
  • A proposed four-file patch and regression tests are included below for maintainer adoption. With the patch, 540 affected tests pass.
  • No live onboarding/E2E validation of the patch or hosted CI run has been performed.

Description

Percentage resource profiles fall back from Kubernetes allocatable resources directly to physical host totals. For a direct Docker gateway running inside a smaller Colima VM, those totals exceed the resources available to Docker.

Expected: calculate percentages against the selected Docker engine's capacity when Kubernetes allocatable capacity is unavailable. Host inventory should still describe the physical host.

In the deterministic fixture (12 host CPUs/18 GiB; Docker 4 CPUs/exactly 12 GiB), the developer profile should pass --cpu 3 --memory 9Gi to OpenShell. Unmodified main passes --cpu 9 --memory 13Gi. The interactive custom-profile preview also uses host totals.

The exact memory value on the original machine differs from the fixture because the engine reports about 11.7 GiB rather than exactly 12 GiB.

Reproduction Steps

  1. Use macOS with more host CPU/memory than the Docker VM; the observed host has 12 CPUs and 18 GiB.
  2. Use a Colima VM configured with colima start --cpu 4 --memory 12 --disk 100 and select that Docker engine.
  3. Run nemoclaw onboard with a direct Docker gateway and select the developer resource profile (75% CPU/memory), without absolute resource overrides.
  4. Observe sandbox creation fail after requesting 9 CPUs from a Docker engine exposing 4.

The regression test avoids a live sandbox: it mocks host inventory and Docker info, leaves Kubernetes unavailable, and exercises appendResourceFlags with the actual developer profile and a temporary OpenShell executable that advertises CPU/memory support. The second regression exercises the custom profile preview.

Environment

  • macOS, Apple M3 Pro, 12 CPUs, 18 GiB RAM.
  • Colima Docker engine: 4 CPUs, approximately 11.7 GiB available memory.
  • Reported installed NemoClaw: v0.0.145; OpenShell: 0.0.116.
  • Patch/test base: c474038df67fcb22182298ac9a696c81e63f0ee2 on main.
  • Exact OS, Docker and Node versions are not included in this report.

Debug Output

The original gateway diagnostics identify Docker's CPU-range rejection (allowed range 0.01–4.00 CPUs). A full debug bundle is not attached; the minimal deterministic evidence is:

Fixture:
  host:   12 CPUs, 18 GiB
  Docker:  4 CPUs, 12 GiB
  Kubernetes allocatable: unavailable

Unmodified main:
  sandbox create --cpu 9 --memory 13Gi
  custom preview: host capacity; CPU=9, RAM=13Gi

With proposed patch:
  sandbox create --cpu 3 --memory 9Gi
  custom preview: 4 CPU cores, 12288 MB RAM; CPU=3, RAM=9Gi

Proposed Fix

  • Read NCPU and MemTotal using the existing Docker adapter and validate the response.
  • Resolve profile capacity in this order: Kubernetes allocatable resources, selected Docker engine capacity, host totals.
  • Preserve physical host inventory and display Docker capacity separately.
  • Share capacity resolution between the custom-profile preview and actual sandbox arguments.
  • Preserve explicit absolute limits and the existing host fallback when Docker capacity is unavailable or invalid.

Searches found related #14232 (Kubernetes memory units) and #13906 (Colima socket selection), but no existing fix for this Docker-capacity fallback.

Test Results

Verification Result
Final regression tests against unchanged production files from the base 2 failed, 45 passed, as expected
Focused source suites plus growth guardrails with the patch 54 passed across 3 files
Affected-test selection with the patch 540 passed across 35 files
CLI typecheck Passed
Formatting and lint for all four changed files Passed
Applicable repository checks 13 passed
git diff --check Passed
Patch application against a pristine temporary index at the stated base Passed

The two failing-before regressions are:

  • passes Docker-sized developer limits to OpenShell when Kubernetes is unavailable
  • previews custom percentages against Docker capacity instead of host totals

Additional cases cover Kubernetes precedence, malformed/missing/invalid Docker capacity and explicit limits. Test totals overlap and should not be added together.

Commands:

node_modules/.bin/vitest run --project cli src/lib/resources-cmd.test.ts src/lib/onboard/resource-profile-selection.test.ts --project integration test/automation/pull-requests/growth-guardrails.test.ts
node --import tsx scripts/tests/changed.mts --maxWorkers=1
NODE_OPTIONS=--max-old-space-size=6144 npm run typecheck:cli

The affected tests used an isolated temporary home directory. An earlier run with the real home hit filesystem restrictions; it is not counted as passing. The environment also blocks the tsx CLI's IPC listener, so the affected-test runner used node --import tsx. The repository check runner used its exported runChecks API with the same selected checks and arguments, substituting node --import tsx for the tsx CLI launcher.

Passed repository checks: direct-credential-env, dependency-pins, no-defaulted-dependent-flags, no-coverage-ignore, layer-import-boundaries, source-architecture, no-test-dist-imports, test-create-require-budget, vitest-project-overlap, test-title-style, optimized-build-context-copy-sources, pi-qualification-receipt-refresh, and test-registration-boundary.

This is local validation, not a claim that publication hooks, full E2E, hosted CI, or independent review passed.

Maintainer Adoption Request

Could a maintainer review and adopt the patch onto a branch in NVIDIA/NemoClaw?

The contributor account has read-only upstream access. The reviewed SDK inspector reports required=true for nvidia-openshell-sdk-0.0.116.tgz, and the SDK CI job rejects fork heads. The contributor publication rule directs contributors to request adoption in this situation.

No PR has been opened. Onboarding is a sensitive path; independent maintainer review and normal CI are still needed.

Patch

The complete patch below includes production changes and tests. Save the contents of the diff block as a patch and apply against the stated base using git apply.

Complete four-file patch
diff --git a/src/lib/onboard/resource-profile-selection.test.ts b/src/lib/onboard/resource-profile-selection.test.ts
index f1917a3..727503d 100644
--- a/src/lib/onboard/resource-profile-selection.test.ts
+++ b/src/lib/onboard/resource-profile-selection.test.ts
@@ -6,6 +6,7 @@ import os from "node:os";
 import path from "node:path";
 
 import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+import * as resources from "../resources-cmd";
 import type { ResourceProfileSelectionDeps } from "./resource-profile-selection";
 import {
   appendResourceFlagsForProfile,
@@ -165,6 +166,28 @@ describe("selectResourceProfileForSandbox", () => {
     expect(deps.prompt).toHaveBeenCalledTimes(2);
   });
 
+  it("previews custom percentages against Docker capacity instead of host totals", async () => {
+    vi.spyOn(resources, "getHardwareResources").mockReturnValue({
+      cpu: { cores: 12, model: "test-cpu" },
+      memory: { totalMB: 18 * 1024, swapMB: 0 },
+      docker: { cpuCores: 4, memoryMB: 12 * 1024 },
+      gpu: null,
+      profiles: null,
+    });
+    const log = vi.spyOn(console, "log").mockImplementation(() => {});
+    const deps = makeDeps({
+      promptOrDefault: vi.fn().mockResolvedValue("5"),
+      prompt: vi.fn().mockResolvedValue("75%"),
+    });
+
+    await expect(selectResourceProfileForSandbox(deps)).resolves.toEqual({
+      cpu: "75%",
+      memory: "75%",
+    });
+    expect(log).toHaveBeenCalledWith("  Available: 4 CPU cores, 12288 MB RAM");
+    expect(log).toHaveBeenCalledWith("  Resolved: CPU=3, RAM=9Gi");
+  });
+
   it("exits when custom profile validation fails", async () => {
     const deps = makeDeps({
       promptOrDefault: vi.fn().mockResolvedValue("5"),
diff --git a/src/lib/onboard/resource-profile-selection.ts b/src/lib/onboard/resource-profile-selection.ts
index 02da885..9270a91 100644
--- a/src/lib/onboard/resource-profile-selection.ts
+++ b/src/lib/onboard/resource-profile-selection.ts
@@ -4,8 +4,10 @@
 import {
   appendResourceFlags,
   getHardwareResources,
+  getProfileCapacity,
   loadResourceProfiles,
-  resolveResourceValue,
+  resolveProfile,
+  type HardwareResources,
   type ResourceProfile,
   validateResourceValue,
 } from "../resources-cmd";
@@ -51,14 +53,9 @@ function exitWithResourceProfileError(message: string): never {
   process.exit(1);
 }
 
-function printResolvedResourceProfile(
-  profile: ResourceProfile,
-  cpuTotal: number,
-  memTotal: number,
-): void {
-  const resolvedCpu = resolveResourceValue(profile.cpu, cpuTotal, "cpu");
-  const resolvedMemory = resolveResourceValue(profile.memory, memTotal, "memory");
-  console.log(`  Resolved: CPU=${resolvedCpu}, RAM=${resolvedMemory}`);
+function printResolvedResourceProfile(profile: ResourceProfile, hw: HardwareResources): void {
+  const resolved = resolveProfile(profile, hw);
+  console.log(`  Resolved: CPU=${resolved.cpu}, RAM=${resolved.memory}`);
 }
 
 /** Select and validate a sandbox CPU and memory profile from environment overrides or the interactive menu. */
@@ -109,8 +106,9 @@ export async function selectResourceProfileForSandbox(
       selectedProfile = { ...availableProfiles[profileNames[idx]] };
       console.log(`  Using profile: ${profileNames[idx]}`);
     } else if (idx === profileNames.length) {
+      const capacity = getProfileCapacity(hw);
       console.log("");
-      console.log(`  Available: ${hw.cpu.cores} CPU cores, ${hw.memory.totalMB} MB RAM`);
+      console.log(`  Available: ${capacity.cpuCores} CPU cores, ${capacity.memoryMB} MB RAM`);
       console.log("  Enter values as percentages (e.g. 25%) or absolutes (e.g. 4, 8Gi)");
       console.log("");
       const cpu = (await deps.prompt(`  CPU [25%]: `)).trim() || "25%";
@@ -120,7 +118,7 @@ export async function selectResourceProfileForSandbox(
         memory,
       };
       try {
-        printResolvedResourceProfile(selectedProfile, hw.cpu.cores, hw.memory.totalMB);
+        printResolvedResourceProfile(selectedProfile, hw);
       } catch (e: unknown) {
         exitWithResourceProfileError((e as Error).message);
       }
diff --git a/src/lib/resources-cmd.test.ts b/src/lib/resources-cmd.test.ts
index fc911ad..e9e8c66 100644
--- a/src/lib/resources-cmd.test.ts
+++ b/src/lib/resources-cmd.test.ts
@@ -4,8 +4,9 @@
 import fs from "node:fs";
 import os from "node:os";
 import path from "node:path";
+import childProcess from "node:child_process";
 
-import { afterEach, describe, expect, it, vi } from "vitest";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
 
 import * as docker from "./adapters/docker/exec";
 import {
@@ -61,6 +62,7 @@ describe("resources-cmd", () => {
       {
         cpu: { cores: 16, model: "test-cpu", allocatable: "7500m" },
         memory: { totalMB: 32768, swapMB: 0, allocatableMB: 16384 },
+        docker: null,
         gpu: null,
         profiles: null,
       },
@@ -100,6 +102,78 @@ describe("resources-cmd", () => {
     expect(profiles["game-developer"].cpu).toBe("60%");
   });
 
+  describe("Docker VM resource profiles", () => {
+    beforeEach(() => {
+      vi.spyOn(os, "cpus").mockReturnValue(
+        Array.from({ length: 12 }, () => ({
+          model: "test-cpu",
+          speed: 0,
+          times: { user: 0, nice: 0, sys: 0, idle: 0, irq: 0 },
+        })),
+      );
+      vi.spyOn(os, "totalmem").mockReturnValue(18 * 1024 ** 3);
+      vi.spyOn(childProcess, "execSync").mockImplementation(() => {
+        throw new Error("Host probes unavailable");
+      });
+    });
+
+    function mockDocker(info: string, allocatable?: { cpu: string; memory: string }) {
+      vi.spyOn(docker, "dockerSpawnSync").mockImplementation((args) => ({
+        status: args[0] === "info" || allocatable ? 0 : 1,
+        stdout:
+          args[0] === "info" ? info : JSON.stringify({ items: [{ status: { allocatable } }] }),
+        stderr: "",
+        pid: 1,
+        output: [],
+        signal: null,
+      }));
+    }
+
+    it("passes Docker-sized developer limits to OpenShell when Kubernetes is unavailable", () => {
+      mockDocker(JSON.stringify({ NCPU: 4, MemTotal: 12 * 1024 ** 3 }));
+      const openshell = makeExecutable("#!/usr/bin/env sh\necho '--cpu --memory'\n");
+      const args = ["sandbox", "create"];
+
+      expect(appendResourceFlags(args, loadResourceProfiles().developer, openshell)).toBe(true);
+      expect(args).toEqual(["sandbox", "create", "--cpu", "3", "--memory", "9Gi"]);
+      const hw = getHardwareResources();
+      expect(hw.cpu.cores).toBe(12);
+      expect(hw.memory.totalMB).toBe(18 * 1024);
+    });
+
+    it("keeps Kubernetes allocatable capacity ahead of Docker VM totals", () => {
+      mockDocker(JSON.stringify({ NCPU: 4, MemTotal: 12 * 1024 ** 3 }), {
+        cpu: "2000m",
+        memory: "4Gi",
+      });
+      expect(resolveProfile(loadResourceProfiles().developer, getHardwareResources())).toEqual({
+        cpu: "1500m",
+        memory: "3072Mi",
+      });
+    });
+
+    it.each([
+      ["malformed", "not JSON"],
+      ["missing CPU", JSON.stringify({ MemTotal: 12 * 1024 ** 3 })],
+      ["zero CPU", JSON.stringify({ NCPU: 0, MemTotal: 12 * 1024 ** 3 })],
+      ["negative memory", JSON.stringify({ NCPU: 4, MemTotal: -1 })],
+    ])("retains the host fallback when Docker capacity is %s", (_case, info) => {
+      mockDocker(info);
+      expect(resolveProfile(loadResourceProfiles().developer, getHardwareResources())).toEqual({
+        cpu: "9",
+        memory: "13Gi",
+      });
+    });
+
+    it("preserves explicit limits when Docker has different capacity", () => {
+      mockDocker(JSON.stringify({ NCPU: 4, MemTotal: 12 * 1024 ** 3 }));
+      const openshell = makeExecutable("#!/usr/bin/env sh\necho '--cpu --memory'\n");
+      const args: string[] = [];
+      expect(appendResourceFlags(args, { cpu: "2", memory: "8Gi" }, openshell)).toBe(true);
+      expect(args).toEqual(["--cpu", "2", "--memory", "8Gi"]);
+    });
+  });
+
   it("returns hardware resources and includes parsed blueprint profiles", () => {
     const hw = getHardwareResources();
 
diff --git a/src/lib/resources-cmd.ts b/src/lib/resources-cmd.ts
index 91f3c5c..decfa22 100644
--- a/src/lib/resources-cmd.ts
+++ b/src/lib/resources-cmd.ts
@@ -14,6 +14,7 @@ import * as fs from "fs";
 import * as path from "path";
 import { spawnSync, execSync } from "child_process";
 import * as YAML from "yaml";
+import { z } from "zod";
 
 import { dockerSpawnSync } from "./adapters/docker";
 
@@ -58,6 +59,7 @@ export interface ResourceProfile {
 export interface HardwareResources {
   cpu: { cores: number; model: string; allocatable?: string };
   memory: { totalMB: number; swapMB: number; allocatableMB?: number };
+  docker: { cpuCores: number; memoryMB: number } | null;
   gpu: { type: string; name: string; count: number; vramMB: number } | null;
   profiles: Record<string, ResourceProfile> | null;
 }
@@ -139,6 +141,27 @@ export function resolveCpuModel(
 // ── Implementation ───────────────────────────────────────────────
 
 const BINARY_MEMORY_UNITS = ["", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei"];
+const dockerCapacitySchema = z.object({
+  NCPU: z.number().int().positive(),
+  MemTotal: z.number().positive(),
+});
+
+function getDockerCapacity(): HardwareResources["docker"] {
+  try {
+    const result = dockerSpawnSync(["info", "--format", "{{json .}}"], {
+      encoding: "utf-8",
+      timeout: 5000,
+      maxBuffer: 1024 * 1024,
+      stdio: ["ignore", "pipe", "ignore"],
+    });
+    if (result.status !== 0) return null;
+    const parsed = dockerCapacitySchema.safeParse(JSON.parse(String(result.stdout)));
+    if (!parsed.success) return null;
+    return { cpuCores: parsed.data.NCPU, memoryMB: parsed.data.MemTotal / 1024 ** 2 };
+  } catch {
+    return null;
+  }
+}
 
 /** Convert the kubelet's allocatable memory from bytes or binary units to MiB. */
 function parseAllocatableMemoryMB(quantity: string): number | undefined {
@@ -231,6 +254,7 @@ export function getHardwareResources(): HardwareResources {
   return {
     cpu: { cores: cpus.length, model: cpuModel, allocatable: allocatableCpu },
     memory: { totalMB, swapMB, allocatableMB: allocatableMemMB },
+    docker: getDockerCapacity(),
     gpu,
     profiles,
   };
@@ -257,6 +281,9 @@ export function printHardwareResources(json: boolean): HardwareResources {
   if (hw.memory.allocatableMB) {
     console.log(`             k8s allocatable: ${hw.memory.allocatableMB} MB`);
   }
+  if (hw.docker) {
+    console.log(`  Docker:    ${hw.docker.cpuCores} cores, ${hw.docker.memoryMB} MB RAM`);
+  }
   if (hw.gpu) {
     console.log(`  GPU:       ${hw.gpu.name}`);
     console.log(
@@ -333,18 +360,22 @@ function parseCpuQuantity(value: string): number | null {
 }
 
 /**
- * Resolve profile percentages to absolutes. Prefers k8s allocatable capacity
- * when available (accounts for kubelet/system reservations); falls back to
- * host totals when gateway is not running.
+ * Prefer Kubernetes allocatable capacity, then the selected Docker engine.
+ * Host totals remain the fallback for inventory without a reachable runtime.
  */
+export function getProfileCapacity(hw: HardwareResources): { cpuCores: number; memoryMB: number } {
+  const cpuCores = hw.docker?.cpuCores ?? hw.cpu.cores;
+  return {
+    cpuCores: hw.cpu.allocatable ? (parseCpuQuantity(hw.cpu.allocatable) ?? cpuCores) : cpuCores,
+    memoryMB: hw.memory.allocatableMB ?? hw.docker?.memoryMB ?? hw.memory.totalMB,
+  };
+}
+
 export function resolveProfile(profile: ResourceProfile, hw: HardwareResources): ResourceProfile {
-  const cpuTotal = hw.cpu.allocatable
-    ? (parseCpuQuantity(hw.cpu.allocatable) ?? hw.cpu.cores)
-    : hw.cpu.cores;
-  const memTotalMB = hw.memory.allocatableMB ?? hw.memory.totalMB;
+  const capacity = getProfileCapacity(hw);
   return {
-    cpu: resolveResourceValue(profile.cpu, cpuTotal, "cpu"),
-    memory: resolveResourceValue(profile.memory, memTotalMB, "memory"),
+    cpu: resolveResourceValue(profile.cpu, capacity.cpuCores, "cpu"),
+    memory: resolveResourceValue(profile.memory, capacity.memoryMB, "memory"),
   };
 }
 

Checklist

  • The sizing bug is reproduced with deterministic tests; the original installation also showed Docker's CPU-range failure.
  • Existing issues and PRs were searched; no matching fix was found.

Activity

  1. uncrayon commented on Nov 21, 2026

    @uncrayon
    Author

    The proposed fix and regression tests are now available as a signed commit for maintainer adoption:

    This is the same four-file patch described above. In addition to the previously reported 540 passing affected tests, the normal commit hooks and actual pre-push hooks passed, including publication validation and all three selected TypeScript checks (plugin, JS config and CLI). No hooks were bypassed. The first push was interrupted before publication; the completed retry was verified against the remote branch.

    For adoption into a maintainer branch:

    git fetch git@github.com:uncrayon/NemoClaw.git refs/heads/fix/docker-resource-profile-capacity
    git cherry-pick -S e24fed97c6f7f86f3c8a6b3b722bf98c6c7248b9

    Cherry-picking creates a new commit; -S signs that new commit with the adopting maintainer's configured key. Normal independent review and CI are still needed. No fork PR has been opened; the SDK CI restriction described in the issue remains relevant.

  2. added
    area: onboarding
    area: sandbox
    platform: container
    on Nov 30, 2026
  3. added theissue type on Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: onboardingarea: sandboxplatform: container

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions