Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 16 additions & 4 deletions agents/hermes/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
COPY agents/hermes/patch-gateway-process-identity.py /opt/nemoclaw-hermes-config/patch-gateway-process-identity.py
COPY agents/hermes/patch-cron-execution-runtime.py /opt/nemoclaw-hermes-config/patch-cron-execution-runtime.py
COPY agents/hermes/patch-cron-restore-drain.py /opt/nemoclaw-hermes-config/patch-cron-restore-drain.py
COPY agents/hermes/patch-auxiliary-token-limit.py /opt/nemoclaw-hermes-config/patch-auxiliary-token-limit.py
COPY agents/hermes/patch-neutral-platform-env-activation.py /opt/nemoclaw-hermes-config/patch-neutral-platform-env-activation.py
COPY agents/hermes/patch-session-list-preview.py /opt/nemoclaw-hermes-config/patch-session-list-preview.py
COPY agents/hermes/patch-profile-policy-defaults.py /opt/nemoclaw-hermes-config/patch-profile-policy-defaults.py
Expand Down Expand Up @@ -455,7 +456,7 @@
# published base can carry the expected Hermes version while omitting either
# optional dependency group. This is a build-time package/import guard; live
# protocol behavior remains a separate E2E concern.
ARG NEMOCLAW_HERMES_IMAGE_BUILD_PROBES_SHA256=ba0ac83296f802780b48ecc6807620a2050c7407e654f20bf7f30bfad4746038
ARG NEMOCLAW_HERMES_IMAGE_BUILD_PROBES_SHA256=5a3c5e9b51228649dc916aa36b3c51f2df8fa6807b139a35926844fd81b7a100
# hadolint ignore=DL3059,DL4006
RUN printf '%s %s\n' \
"$NEMOCLAW_HERMES_IMAGE_BUILD_PROBES_SHA256" /opt/nemoclaw-hermes-config/image-build-probes.py \
Expand Down Expand Up @@ -483,7 +484,7 @@
# same-version wheel selected by its lazy installer. Bind that production
# boundary to NVIDIA/NemoClaw's reviewed wheel hashes.
ARG NEMOCLAW_HERMES_HINDSIGHT_LAZY_INTEGRITY_PATCH_SHA256=5c619477c10e0b76cffd7adc214cbccf3beb77e7a1121f394c443502d9e0b736
ARG NEMOCLAW_HERMES_IMAGE_BUILD_PROBES_SHA256=ba0ac83296f802780b48ecc6807620a2050c7407e654f20bf7f30bfad4746038
ARG NEMOCLAW_HERMES_IMAGE_BUILD_PROBES_SHA256=5a3c5e9b51228649dc916aa36b3c51f2df8fa6807b139a35926844fd81b7a100
# hadolint ignore=DL4006
RUN printf '%s %s\n' \
"$NEMOCLAW_HERMES_HINDSIGHT_LAZY_INTEGRITY_PATCH_SHA256" /opt/nemoclaw-hermes-config/hindsight-lazy-integrity.patch \
Expand Down Expand Up @@ -682,13 +683,18 @@
ARG NEMOCLAW_HERMES_CRON_RUNTIME_PATCHER_SHA256=b8aae8925cacad654d7b09900bd1cc02d776feaec4662c06dde8f4b2f356e22e
ARG NEMOCLAW_HERMES_CRON_EXECUTIONS_SOURCE_SHA256=b4a685a901abdffe2d1232099b3c27391775775a7011d52c90276cb15d3fd75d
ARG NEMOCLAW_HERMES_BACKUP_SOURCE_SHA256=b0838c1f2e120d8f97076c6321297077edc1f150dc6d4b84ba3d13327fcbb156
# Hermes v0.20.6 drops explicit auxiliary output limits on custom endpoints.
# Preserve those limits on NemoClaw's managed inference route so session-title
# generation cannot occupy Ollama's only inference slot until the context fills.
ARG NEMOCLAW_HERMES_AUXILIARY_TOKEN_LIMIT_PATCHER_SHA256=d04ffc133e115caddd6a1243979e317a512a4ffd8b259ec2b053a5057c26ba93

Check warning on line 689 in agents/hermes/Dockerfile

View workflow job for this annotation

GitHub Actions / PR build and direct managed startup (Hermes)

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ARG "NEMOCLAW_HERMES_AUXILIARY_TOKEN_LIMIT_PATCHER_SHA256") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/

Check warning on line 689 in agents/hermes/Dockerfile

View workflow job for this annotation

GitHub Actions / PR build and direct managed startup (Hermes)

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ARG "NEMOCLAW_HERMES_AUXILIARY_TOKEN_LIMIT_PATCHER_SHA256") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/
# hadolint ignore=DL4006
RUN printf '%s %s\n' \
"$NEMOCLAW_HERMES_CRON_RUNTIME_PATCHER_SHA256" /opt/nemoclaw-hermes-config/patch-cron-execution-runtime.py \
"$NEMOCLAW_HERMES_CRON_EXECUTIONS_SOURCE_SHA256" /opt/hermes/cron/executions.py \
"$NEMOCLAW_HERMES_BACKUP_SOURCE_SHA256" /opt/hermes/hermes_cli/backup.py \
"$NEMOCLAW_HERMES_AUXILIARY_TOKEN_LIMIT_PATCHER_SHA256" /opt/nemoclaw-hermes-config/patch-auxiliary-token-limit.py \
| sha256sum -c - \
|| { echo "ERROR: Hermes cron execution runtime source identity mismatch" >&2; exit 1; }
|| { echo "ERROR: Hermes cron or auxiliary token-limit source identity mismatch" >&2; exit 1; }
RUN /usr/bin/python3 -I \
/opt/nemoclaw-hermes-config/patch-cron-execution-runtime.py \
--executions /opt/hermes/cron/executions.py \
Expand All @@ -698,10 +704,15 @@
trap 'rm -rf "$probe_home"' EXIT; \
HERMES_HOME="$probe_home" /opt/hermes/.venv/bin/python -I \
/opt/nemoclaw-hermes-config/image-build-probes.py cron-runtime-source \
&& /usr/bin/python3 -I /opt/nemoclaw-hermes-config/patch-auxiliary-token-limit.py \
&& /opt/hermes/.venv/bin/python -m py_compile /opt/hermes/agent/auxiliary_client.py \
&& /opt/hermes/.venv/bin/python -I \
/opt/nemoclaw-hermes-config/image-build-probes.py auxiliary-token-limit \
&& rm /opt/nemoclaw-hermes-config/patch-gateway-runtime-metadata.py \
/opt/nemoclaw-hermes-config/patch-gateway-process-identity.py \
/opt/nemoclaw-hermes-config/patch-cron-execution-runtime.py \
/opt/nemoclaw-hermes-config/patch-cron-restore-drain.py
/opt/nemoclaw-hermes-config/patch-cron-restore-drain.py \
/opt/nemoclaw-hermes-config/patch-auxiliary-token-limit.py

# Hermes v0.20.6 computes `sessions list` preview from the first user message.
# Its workspace-aware titled table then hides the preview behind an automatic
Expand Down Expand Up @@ -1646,6 +1657,7 @@
&& check_absent /opt/nemoclaw-hermes-config/patch-gateway-process-identity.py \
&& check_absent /opt/nemoclaw-hermes-config/patch-cron-execution-runtime.py \
&& check_absent /opt/nemoclaw-hermes-config/patch-cron-restore-drain.py \
&& check_absent /opt/nemoclaw-hermes-config/patch-auxiliary-token-limit.py \
&& check_absent /opt/nemoclaw-hermes-config/patch-session-list-preview.py \
&& check_absent /opt/nemoclaw-hermes-config/patch-profile-policy-defaults.py \
&& check_absent /opt/nemoclaw-hermes-config/patch-neutral-platform-env-activation.py \
Expand Down
31 changes: 31 additions & 0 deletions agents/hermes/image-build-probes.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,36 @@ def verify_gateway_process_identity() -> None:
)


def verify_auxiliary_token_limit() -> None:
"""Keep explicit auxiliary limits on the managed inference route."""
from agent.auxiliary_client import _build_call_kwargs

common = {
"provider": "custom",
"model": "qwen3-vl:4b",
"messages": [{"role": "user", "content": "probe"}],
"max_tokens": 64,
"task": "title_generation",
}
managed = _build_call_kwargs(
**common,
base_url="https://inference.local/v1",
)
external = _build_call_kwargs(
**common,
base_url="https://example.test/v1",
)
external_moa = _build_call_kwargs(
**{**common, "task": "moa_reference"},
base_url="https://example.test/v1",
)

assert managed.get("max_tokens") == 64, managed
assert "max_tokens" not in external, external
assert "max_completion_tokens" not in external, external
assert external_moa.get("max_tokens") == 64, external_moa


def verify_neutral_platform_inertness() -> None:
import socket

Expand Down Expand Up @@ -704,6 +734,7 @@ def verify_managed_runtime_capability() -> None:


COMMANDS: dict[str, Callable[[], None]] = {
"auxiliary-token-limit": verify_auxiliary_token_limit,
"compatibility-retirement": verify_compatibility_retirement,
"cron-backup": verify_cron_backup,
"cron-create": verify_cron_create,
Expand Down
70 changes: 70 additions & 0 deletions agents/hermes/patch-auxiliary-token-limit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env python3
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
"""Preserve explicit Hermes auxiliary output limits on managed inference.

Hermes v0.20.6 drops ``max_tokens`` from auxiliary OpenAI-compatible
requests unless the provider belongs to a small allowlist. This removes the
64-token limit from session-title generation on NemoClaw's managed Ollama
route. A thinking model can then occupy Ollama's only inference slot until it
fills the context window, which blocks the user's first prompt.

The source fix belongs in Hermes. This pinned image patch keeps the caller's
explicit limit only for ``inference.local``. Other custom endpoints retain
Hermes's compatibility behavior.
"""

from __future__ import annotations

import argparse
from pathlib import Path

UNPATCHED = """ if (
_is_anthropic_compat_endpoint(provider, _effective_base)
or _nous_on_messages
or _is_nvidia_nim
or _is_moa
or _is_gemini_native
):"""

PATCHED = """ if (
_is_anthropic_compat_endpoint(provider, _effective_base)
or _nous_on_messages
or _is_nvidia_nim
or _is_moa
or _is_gemini_native
or base_url_host_matches(_effective_base, "inference.local")
):"""


def patch_file(path: Path) -> None:
source = path.read_text(encoding="utf-8")
unpatched_count = source.count(UNPATCHED)
patched_count = source.count(PATCHED)

if unpatched_count == 0 and patched_count == 1:
return
if unpatched_count != 1 or patched_count != 0:
raise SystemExit(
"ERROR: Hermes auxiliary max_tokens condition changed; "
f"found {unpatched_count} unpatched and {patched_count} patched blocks"
)

path.write_text(source.replace(UNPATCHED, PATCHED), encoding="utf-8")


def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument(
"path",
nargs="?",
default="/opt/hermes/agent/auxiliary_client.py",
help="Hermes auxiliary client module to patch",
)
args = parser.parse_args()
patch_file(Path(args.path))
return 0


if __name__ == "__main__":
raise SystemExit(main())
23 changes: 23 additions & 0 deletions src/lib/actions/sandbox/connect-flow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,24 @@ describe("connectSandbox flow", () => {
portableReceiptDisposition: { kind: "hermes", phase: "active" },
portableRecoveryResult: { kind: "already-running" },
});
const captureResolved = harness.captureResolvedOpenshellSpy.getMockImplementation()!;
const forwardRecovery = requireDist("../../src/lib/actions/sandbox/forward-recovery.js");
let forwardsRestored = false;
harness.captureResolvedOpenshellSpy.mockImplementation(((args: unknown, options: unknown) => {
const argv = Array.isArray(args) ? args.map(String) : [];
return argv[0] === "forward" && argv[1] === "list"
? {
status: 0,
output: forwardsRestored
? "SANDBOX BIND PORT PID STATUS\nalpha 127.0.0.1 18789 12345 running"
: "SANDBOX BIND PORT PID STATUS\n",
}
: captureResolved(args, options);
}) as never);
harness.forwardReachabilitySpy.mockImplementation(() => forwardsRestored);
harness.launchForwardServiceSpy.mockImplementation(() => {
forwardsRestored = true;
});

await expect(harness.connectSandbox("alpha")).rejects.toThrow("process.exit(0)");

Expand All @@ -1107,6 +1125,11 @@ describe("connectSandbox flow", () => {
expect(harness.readSandboxConfigSpy).not.toHaveBeenCalled();
expect(harness.writeSandboxConfigSpy).not.toHaveBeenCalled();
expect(harness.recoverHermesPortableOllamaInferenceSpy).not.toHaveBeenCalled();
expect(harness.launchForwardServiceSpy).toHaveBeenCalledOnce();
expect(forwardRecovery.areSandboxLaunchForwardsHealthy("alpha", "nemoclaw")).toBe(true);
expect(harness.launchForwardServiceSpy.mock.invocationCallOrder[0]!).toBeLessThan(
harness.startSandboxSessionSpy.mock.invocationCallOrder[0]!,
);
expect(sandboxVersion.checkAgentVersion).not.toHaveBeenCalled();
expect(brokerSpy).not.toHaveBeenCalled();
expect(harness.startSandboxSessionSpy).toHaveBeenCalledWith({
Expand Down
8 changes: 8 additions & 0 deletions src/lib/actions/sandbox/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2303,6 +2303,14 @@ export async function prepareInteractiveSession(sandboxName: string): Promise<{
? await verifyHermesPortableInferenceRouteOrExit(sandboxName, agent)
: await ensureSandboxInferenceRouteOrExit(sandboxName, agent);
requalify();
if (hermesPortable) {
const authority = requireHermesPortableActiveLifecycleAuthority(
sandboxName,
undefined,
portableAgentLifecycleAuthorityDeps(),
);
recoverHermesPortableForwardsForConnectProbeOrExit(sandboxName, authority);
}
if (!hermesPortable && !(await settlePortablePairingOrExit(sandboxName))) {
completeInteractiveSessionSetup(sandboxName, sb);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const HERMES_PORTABLE_BUILD_CONTEXT_FILES = [
{ path: "agents/hermes/image-build-probes.py", mode: "100644" },
{ path: "agents/hermes/managed_policy.py", mode: "100644" },
{ path: "agents/hermes/mcp-config-transaction.py", mode: "100755" },
{ path: "agents/hermes/patch-auxiliary-token-limit.py", mode: "100755" },
{ path: "agents/hermes/patch-cron-execution-runtime.py", mode: "100755" },
{ path: "agents/hermes/patch-cron-restore-drain.py", mode: "100755" },
{ path: "agents/hermes/patch-discord-recovery-permissions.py", mode: "100755" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const LOCAL_COPY_SOURCES = [
"agents/hermes/managed_policy.py",
"agents/hermes/managed_policy.py",
"agents/hermes/mcp-config-transaction.py",
"agents/hermes/patch-auxiliary-token-limit.py",
"agents/hermes/patch-cron-execution-runtime.py",
"agents/hermes/patch-cron-restore-drain.py",
"agents/hermes/patch-discord-recovery-permissions.py",
Expand Down
1 change: 1 addition & 0 deletions src/lib/onboard/managed-startup/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,7 @@ export const MANAGED_STARTUP_PROFILE_EXCLUDED_DOCKER_INPUTS = {
{ input: "NEMOCLAW_HERMES_CRON_RESTORE_CONTROLLER_SHA256", reason: "integrity-pin" },
{ input: "NEMOCLAW_HERMES_CRON_RUNTIME_PATCHER_SHA256", reason: "integrity-pin" },
{ input: "NEMOCLAW_HERMES_IMAGE_BUILD_PROBES_SHA256", reason: "integrity-pin" },
{ input: "NEMOCLAW_HERMES_AUXILIARY_TOKEN_LIMIT_PATCHER_SHA256", reason: "integrity-pin" },
{ input: "NEMOCLAW_HERMES_CRON_EXECUTIONS_SOURCE_SHA256", reason: "integrity-pin" },
{ input: "NEMOCLAW_HERMES_BACKUP_SOURCE_SHA256", reason: "integrity-pin" },
{ input: "NEMOCLAW_HERMES_SQLITE_TEMP_STORE_PATCHER_SHA256", reason: "integrity-pin" },
Expand Down
Loading
Loading