Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
dafd889
fix: reconcile non-root OpenClaw model config
rsliter Sep 22, 2026
e362e83
fix: preserve limits during primary reconciliation
rsliter Sep 22, 2026
5793534
merge: update main
rsliter Sep 22, 2026
f380fc6
fix: preserve limits for matching model ids
rsliter Sep 22, 2026
8692e78
test(openclaw): close custom image review gaps
rsliter Sep 22, 2026
441af47
test(openclaw): exercise actual permission boundaries
rsliter Sep 23, 2026
58af59a
test(e2e): map custom image parity coverage
rsliter Sep 23, 2026
62bdb2e
test(e2e): record effective custom image limits
rsliter Sep 23, 2026
7164617
merge: update main
rsliter Sep 23, 2026
e8ef2cb
fix: pass routed model to custom OpenClaw images
rsliter Sep 23, 2026
29a5c02
fix(onboard): pass selected model through custom workload launch
ericksoa Sep 23, 2026
a614893
test(e2e): require Docker custom image proof
rsliter Sep 23, 2026
e114358
fix(openclaw): consume custom image route once
rsliter Sep 23, 2026
dbbbcf7
merge: update main
rsliter Sep 23, 2026
4aebf61
fix(e2e): select custom-image proof for source changes
rsliter Sep 23, 2026
d9c3580
fix(openclaw): reconcile custom image model at build time
rsliter Sep 23, 2026
a48a7c9
fix(openclaw): preserve explicit custom image limits
rsliter Sep 24, 2026
d7f3d00
test(openclaw): prove custom image limits are replaced
rsliter Sep 24, 2026
580a576
docs(openclaw): clarify custom image model limits
rsliter Sep 24, 2026
ebb8466
fix(onboard): preserve custom image runtime behavior
rsliter Sep 25, 2026
dcec0be
merge: sync main into custom image runtime fix
rsliter Sep 25, 2026
03fd2cb
test(e2e): restore Podman switch boundary
rsliter Sep 25, 2026
0c30034
fix(openclaw): repair stale config hash on retry
rsliter Sep 26, 2026
1188ef9
merge: sync main into OpenClaw retry fix
rsliter Sep 26, 2026
2cb8947
fix(openclaw): scope startup route probe
rsliter Sep 26, 2026
fa410c4
fix(openclaw): preserve selected gateway probe
rsliter Sep 26, 2026
790ccb5
docs(openclaw): clarify custom image limits
rsliter Sep 26, 2026
2104192
test(e2e): select inference switch owner
rsliter Sep 26, 2026
524a0b1
merge(main): refresh PR base
rsliter Sep 26, 2026
4b2e9ec
docs(openclaw): clarify mixed custom image limits
rsliter Sep 26, 2026
19897b1
test(openclaw): exercise non-root model override
rsliter Sep 26, 2026
87c3ada
fix(openclaw): preserve custom route on first start
rsliter Sep 26, 2026
e355e70
fix(openclaw): fail closed on receipt cleanup
rsliter Sep 26, 2026
47686a5
fix(onboard): finalize custom route receipt by descriptor
rsliter Sep 27, 2026
8a54f32
fix(onboard): retire custom route receipt after policy verification
rsliter Sep 27, 2026
8e2f4ab
docs(inference): clarify custom image model limits
rsliter Sep 27, 2026
3c381f8
fix(onboard): retire custom route after verification
rsliter Sep 27, 2026
d796a5a
fix(onboard): persist custom route runtime identity
rsliter Sep 28, 2026
140694a
merge(main): integrate current main
rsliter Sep 28, 2026
85a1a09
fix(onboard): reconcile custom route after sandbox creation
rsliter Sep 28, 2026
54ee35c
fix(onboard): support OpenShell custom image builder
rsliter Sep 28, 2026
040fba5
merge(main): integrate current main
rsliter Sep 28, 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
10 changes: 9 additions & 1 deletion docs/inference/configure-model-limits.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ OpenClaw accepts an explicit context window and maximum output-token count.
| `NEMOCLAW_CONTEXT_WINDOW` | Positive integer in tokens | `131072` |
| `NEMOCLAW_MAX_TOKENS` | Positive integer in tokens | `4096` |

These defaults apply to NemoClaw-managed images.
For a custom image supplied with `--from`, NemoClaw applies valid explicit overrides when it builds the sandbox image.
A runtime route change does not rebuild that image.
Recreate the sandbox to apply explicit limits to the new route.
When the selected model differs from the inherited image model, NemoClaw removes inherited `contextWindow` and `maxTokens` values during that build if no valid explicit overrides exist.
OpenClaw and the selected model then determine the effective limits.

Export one or both values before onboarding.

```bash
Expand All @@ -69,7 +76,8 @@ export NEMOCLAW_MAX_TOKENS=8192
$$nemoclaw onboard
```

NemoClaw ignores invalid values and uses the default instead.
NemoClaw does not apply invalid values.
For a custom image whose selected model differs from the inherited image model, NemoClaw applies each valid explicit limit independently and removes each inherited limit that has no explicit replacement.

</AgentOnly>

Expand Down
14 changes: 14 additions & 0 deletions docs/inference/switch-models.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ If the route metadata is incomplete, NemoClaw stops and tells you to re-run onbo

</AgentOnly>

<AgentOnly variant="openclaw">

At runtime, NemoClaw replaces `contextWindow` only when it resolves a value for the selected model and can retain an existing `maxTokens` value.
For an OpenClaw custom image built with `--from`, onboarding patches an inherited model ID to the selected route during the image build.
When the model ID changes, onboarding keeps each valid explicit limit and removes only an inherited limit without an explicit replacement.
It then refreshes `.config-hash` before restoring the custom image's final user.
On later starts, NemoClaw can also reconcile drift from the live gateway when the sandbox user can write `/sandbox/.openclaw/openclaw.json`.
If that runtime configuration is not writable, NemoClaw reports that reconciliation was skipped and preserves the existing configuration.
Make the configuration writable by the sandbox user if later runtime route changes must update the file, then recreate the sandbox.
To keep an explicit limit for the new model, set its corresponding `NEMOCLAW_CONTEXT_WINDOW` or `NEMOCLAW_MAX_TOKENS` value before you recreate the sandbox.
Refer to [Configure Model Limits](configure-model-limits) for the environment variable requirements.

</AgentOnly>

<AgentOnly variant="hermes">

For Hermes, the command recomputes the target model's context window before it updates the shared native configuration.
Expand Down
7 changes: 5 additions & 2 deletions docs/manage-sandboxes/runtime-controls.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ Some changes apply at runtime, while image and filesystem changes require a rebu

| Item | When the change takes effect | How to change it |
| --- | --- | --- |
| Inference provider | Runtime route and config update; rebuild only if you need to recreate the image | Run `$$nemoclaw inference set` |
| Inference model on the current provider | Runtime route and config update | Run `$$nemoclaw inference set` |
| Inference provider | Runtime route update; configuration update only when the sandbox user can write `/sandbox/.openclaw/openclaw.json` | Run `$$nemoclaw inference set` |
| Inference model on the current provider | Runtime route update; configuration update only when the sandbox user can write `/sandbox/.openclaw/openclaw.json` | Run `$$nemoclaw inference set` |
| Sub-agent | Re-onboard required because the sub-agent and workspace are baked at onboard | `$$nemoclaw onboard --recreate-sandbox` |
| Network policy preset | Runtime on the next request; rebuild only if the preset adds bind-mounted secrets | `$$nemoclaw <name> policy add <preset>` or `policy remove <preset>` |
| Network allowlist | Runtime on the next request | `openshell policy set` or the interactive approval prompt at the gateway |
Expand All @@ -40,6 +40,9 @@ Some changes apply at runtime, while image and filesystem changes require a rebu
| `agents.list` | Runtime after gateway restart; generated OpenClaw configuration disables hot reload | Prefer agent or NemoClaw commands that keep host and sandbox state aligned, then run `$$nemoclaw <name> gateway restart` |
| `openclaw.json` keys | Mixed; supported config and inference updates apply at runtime, while image, policy, web search, and channel changes can require rebuild | Use `$$nemoclaw inference set` or `$$nemoclaw <name> config set` so the config and integrity hash change together |

If NemoClaw skips custom-image configuration synchronization, update the image so the sandbox user owns and can write the OpenClaw configuration, then recreate the sandbox.
Refer to [Switch Models](../../inference/manage-inference/switch-models) for the custom-image route and configuration behavior.

For a new or pristine OpenClaw workspace, `NEMOCLAW_MINIMAL_BOOTSTRAP=1` avoids roughly 3,000 tokens of per-turn project-context overhead by skipping the default template seed. It does not delete existing workspace files.

The runtime source of truth is `/sandbox/.openclaw/openclaw.json`. The host registry caches metadata, but the image and OpenClaw read from the in-sandbox file.
Expand Down
190 changes: 162 additions & 28 deletions scripts/nemoclaw-start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -969,12 +969,6 @@ apply_model_override() {
|| [ -n "${NEMOCLAW_INFERENCE_API_OVERRIDE:-}" ] \
|| return 0

# Host overrides require root startup authority.
if [ "$(id -u)" -ne 0 ]; then
printf '[SECURITY] Model/inference overrides ignored — requires root (non-root mode cannot write to config)\n' >&2
return 0
fi

local config_file="/sandbox/.openclaw/openclaw.json"
local hash_file="/sandbox/.openclaw/.config-hash"

Expand All @@ -985,6 +979,11 @@ apply_model_override() {
return 1
fi

if [ "$(id -u)" -ne 0 ] && [ ! -w "$config_file" ]; then
printf '[SECURITY] Model/inference overrides ignored: OpenClaw config is not writable by the sandbox user\n' >&2
return 0
fi

local model_override="${NEMOCLAW_MODEL_OVERRIDE:-}"
local api_override="${NEMOCLAW_INFERENCE_API_OVERRIDE:-}"

Expand Down Expand Up @@ -1122,9 +1121,8 @@ PYOVERRIDE
# reconciliation the file's stale entry can be pushed back, reverting
# the route.
#
# Probe the live gateway via `openshell inference get --json` and
# treat it as the source of truth: when the gateway model differs
# from the file, align both primary and the inference provider's
# Probe the live gateway via `openshell inference get`. When the route model
# differs from the file, align both primary and the inference provider's
# first model entry so the agent identity and the gateway route stay
# consistent across the next reconcile cycle.
#
Expand All @@ -1141,49 +1139,171 @@ reconcile_agent_model_with_provider() {
# overwrite the user's explicit choice with an inference/-prefixed variant.
[ -z "${NEMOCLAW_MODEL_OVERRIDE:-}" ] || return 0

if [ "$(id -u)" -ne 0 ]; then
return 0
fi

local config_file="/sandbox/.openclaw/openclaw.json"
local hash_file="/sandbox/.openclaw/.config-hash"
local custom_route_marker="/sandbox/.openclaw/.nemoclaw-custom-route-pending"

[ -f "$config_file" ] || return 0

if [ -L "$config_file" ] || [ -L "$hash_file" ]; then
if [ -L "$config_file" ] || [ -L "$hash_file" ] || [ -L "$custom_route_marker" ]; then
printf '[SECURITY] Refusing agent model reconciliation: config, hash, or receipt path is a symlink\n' >&2
return 1
fi
if [ -e "$custom_route_marker" ] && [ ! -f "$custom_route_marker" ]; then
printf '[SECURITY] Refusing agent model reconciliation: custom-image route receipt is not a regular file\n' >&2
return 1
fi

if [ "$(id -u)" -ne 0 ] && [ ! -w "$config_file" ]; then
printf '[config] Agent model reconciliation skipped: OpenClaw config is not writable by the sandbox user\n' >&2
return 0
fi

local gateway_model=""
if command -v openshell >/dev/null 2>&1; then
local model_source="gateway"
if [ -f "$custom_route_marker" ]; then
if ! run_openclaw_config_as_owner /usr/bin/python3 -I - \
"$config_file" "$custom_route_marker" <<'PYCUSTOMROUTE'; then
import hashlib
import os
import re
import stat
import sys

config_path, marker_path = sys.argv[1:]
flags = os.O_RDONLY | os.O_CLOEXEC | getattr(os, "O_NOFOLLOW", 0)


def open_regular(path):
descriptor = os.open(path, flags)
metadata = os.fstat(descriptor)
current = os.stat(path, follow_symlinks=False)
if (
not stat.S_ISREG(metadata.st_mode)
or metadata.st_nlink != 1
or (metadata.st_dev, metadata.st_ino) != (current.st_dev, current.st_ino)
):
os.close(descriptor)
raise OSError("path is not a trusted regular file")
return descriptor


def read_bounded(descriptor, limit):
chunks = []
remaining = limit + 1
while remaining > 0:
chunk = os.read(descriptor, remaining)
if not chunk:
break
chunks.append(chunk)
remaining -= len(chunk)
return b"".join(chunks)


try:
config_fd = open_regular(config_path)
marker_fd = open_regular(marker_path)
try:
config = read_bounded(config_fd, 8 * 1024 * 1024)
marker = read_bounded(marker_fd, 255)
finally:
os.close(marker_fd)
os.close(config_fd)
except OSError:
raise SystemExit(1)

if len(config) > 8 * 1024 * 1024 or len(marker) > 255:
raise SystemExit(1)
match = re.fullmatch(rb"([a-f0-9]{64}) openclaw\.json\n", marker)
if match is None or hashlib.sha256(config).hexdigest().encode("ascii") != match.group(1):
raise SystemExit(1)
PYCUSTOMROUTE
printf '[SECURITY] Refusing invalid custom-image route receipt\n' >&2
return 1
fi
# The staged Dockerfile already reconciled the selected route into this
# exact config. Keep that create-time choice authoritative for the first
# launch; the marker is retired only after the gateway reports readiness.
model_source="custom-image"
elif command -v openshell >/dev/null 2>&1; then
gateway_model="$(
python3 - <<'PYPROBE'
import json, subprocess
/usr/bin/python3 -I - <<'PYPROBE'
import os
import re
import subprocess
import sys

ansi_escape = re.compile(r"\x1b(?:\[[0-?]*[ -/]*[@-~]|[@-_])")
gateway_name = os.environ.get("NEMOCLAW_OPENSHELL_GATEWAY_NAME", "nemoclaw")
if not re.fullmatch(r"nemoclaw(?:-[1-9][0-9]{0,4})?", gateway_name):
print("[config] Gateway model probe unavailable: invalid NemoClaw gateway name", file=sys.stderr)
raise SystemExit(0)

try:
result = subprocess.run(
["openshell", "inference", "get", "--json"],
["openshell", "inference", "get", "-g", gateway_name],
capture_output=True,
encoding="utf-8",
errors="replace",
text=True,
timeout=3,
check=False,
)
except Exception:
except subprocess.TimeoutExpired:
print("[config] Gateway model probe unavailable: openshell inference get timed out", file=sys.stderr)
raise SystemExit(0)
except OSError:
print("[config] Gateway model probe unavailable: openshell inference get could not start", file=sys.stderr)
raise SystemExit(0)
if result.returncode != 0:
print(
f"[config] Gateway model probe unavailable: openshell inference get exited with status {result.returncode}",
file=sys.stderr,
)
raise SystemExit(0)
try:
data = json.loads(result.stdout)
except Exception:

lines = ansi_escape.sub("", result.stdout).splitlines()
section_count = 0
in_inference_section = False
models = []
unconfigured = False
for line in lines:
if re.fullmatch(r"(?:Gateway )?Inference:\s*", line, re.IGNORECASE):
section_count += 1
in_inference_section = True
continue
if in_inference_section and re.fullmatch(r"\S.*:\s*", line):
in_inference_section = False
continue
if not in_inference_section:
continue
if re.fullmatch(r"\s*Not configured\s*", line, re.IGNORECASE):
unconfigured = True
continue
match = re.fullmatch(r"\s*Model:\s*(.+?)\s*", line)
if match:
models.append(match.group(1))

if section_count == 1 and unconfigured and not models:
print("[config] Gateway model probe unavailable: openshell reported no configured inference route", file=sys.stderr)
raise SystemExit(0)
if section_count != 1 or len(models) != 1:
print("[config] Gateway model probe unavailable: openshell returned malformed inference output", file=sys.stderr)
raise SystemExit(0)
model = data.get("model") if isinstance(data, dict) else None
if isinstance(model, str) and model:
print(model)
model = models[0]
if len(model) > 512 or re.fullmatch(r"[A-Za-z0-9._:/-]+", model) is None:
print("[SECURITY] Gateway model probe rejected an unsafe model identifier", file=sys.stderr)
raise SystemExit(0)
print(model)
PYPROBE
)"
else
printf '[config] Gateway model probe unavailable: openshell is not installed\n' >&2
fi

local provider_model_ref
provider_model_ref="$(
run_openclaw_config_as_owner /usr/bin/env GATEWAY_MODEL="${gateway_model:-}" \
run_openclaw_config_as_owner /usr/bin/env GATEWAY_MODEL="${gateway_model:-}" MODEL_SOURCE="$model_source" \
/usr/bin/python3 -I - "$config_file" <<'PYRECONCILE_READ'
import json, os, sys

Expand Down Expand Up @@ -1218,8 +1338,9 @@ if gateway_target is not None:
first_name_ok = isinstance(first_name, str) and first_name == gateway_target
first_id_ok = isinstance(first_id, str) and (first_id == bare or first_id == gateway_target)
if primary_ok and first_name_ok and first_id_ok:
print("already-synced")
sys.exit(0)
print(f"gateway\t{gateway_target}")
print(f"{os.environ.get('MODEL_SOURCE', 'gateway')}\t{gateway_target}")
sys.exit(0)

# Legacy fallback: gateway probe is unavailable. Align primary with
Expand All @@ -1232,11 +1353,20 @@ legacy_target = qualify(first.get("name") or first.get("id"))
if legacy_target is None:
sys.exit(0)
if isinstance(primary, str) and primary == legacy_target:
print("already-synced")
sys.exit(0)
print(f"legacy\t{legacy_target}")
PYRECONCILE_READ
)"

if [ "$provider_model_ref" = "already-synced" ]; then
# A prior attempt may have installed this config before its hash refresh
# failed. Keep the retry fail-closed until both files agree.
local _hash_rc=0
ensure_mutable_openclaw_config_hash || _hash_rc=$?
return "$_hash_rc"
fi

if [ -z "$provider_model_ref" ]; then
return 0
fi
Expand All @@ -1257,7 +1387,7 @@ config_file, provider_model = sys.argv[1], sys.argv[2]
with open(config_file) as f:
cfg = json.load(f)
cfg.setdefault("agents", {}).setdefault("defaults", {}).setdefault("model", {})["primary"] = provider_model
if os.environ.get("RECONCILE_SOURCE") == "gateway":
if os.environ.get("RECONCILE_SOURCE") != "legacy":
bare = (
provider_model[len("inference/"):]
if provider_model.startswith("inference/")
Expand All @@ -1274,8 +1404,12 @@ if os.environ.get("RECONCILE_SOURCE") == "gateway":
if not isinstance(first, dict):
first = {}
models_list[0] = first
provider_model_unchanged = first.get("id") in (bare, provider_model)
first["id"] = bare
first["name"] = provider_model
if not provider_model_unchanged:
first.pop("contextWindow", None)
first.pop("maxTokens", None)
with open(config_file, "w") as f:
json.dump(cfg, f, indent=2)
PYRECONCILE_WRITE
Expand Down
Loading
Loading