diff --git a/agents/hermes/Dockerfile b/agents/hermes/Dockerfile index 17384cfe32d..bc30b6ad0a1 100644 --- a/agents/hermes/Dockerfile +++ b/agents/hermes/Dockerfile @@ -373,7 +373,7 @@ COPY --from=hermes-agent-payload / / # 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=8fb5b35e0e175c71f49bbc4846daffc66164257d69eeb0bba3c283afcc6e50b6 +ARG NEMOCLAW_HERMES_IMAGE_BUILD_PROBES_SHA256=ffac0fe42ff405b2334241e97df44bf641e55792516290f23ee8726a52173166 # hadolint ignore=DL3059,DL4006 RUN printf '%s %s\n' \ "$NEMOCLAW_HERMES_IMAGE_BUILD_PROBES_SHA256" /opt/nemoclaw-hermes-config/image-build-probes.py \ @@ -399,7 +399,7 @@ RUN find /opt/nemoclaw-hermes-config -type d -exec chmod 755 {} + \ /ci/reviewed-npm-audit.json \ && chmod -R a+rX /src/lib/messaging -ARG NEMOCLAW_HERMES_IMAGE_BUILD_PROBES_SHA256=8fb5b35e0e175c71f49bbc4846daffc66164257d69eeb0bba3c283afcc6e50b6 +ARG NEMOCLAW_HERMES_IMAGE_BUILD_PROBES_SHA256=ffac0fe42ff405b2334241e97df44bf641e55792516290f23ee8726a52173166 # hadolint ignore=DL3067 COPY --from=hermes-runtime-payload / / @@ -973,7 +973,7 @@ RUN install -o root -g root -m 0444 \ # Fresh named profiles do not receive config.yaml. Patch the pinned Hermes # fallback readers from the generated manifest, then validate a real profile. -ARG NEMOCLAW_HERMES_PROFILE_POLICY_PATCHER_SHA256=954e982162b8c79ca2e08897907f561b307235eefc33fa882b5c22faa22f152a +ARG NEMOCLAW_HERMES_PROFILE_POLICY_PATCHER_SHA256=f275cbd5d766ac970a3f00b267d5ffa981070254c5826e716296be6d6ce6d8a2 # hadolint ignore=DL4006 RUN printf '%s %s\n' \ "$NEMOCLAW_HERMES_PROFILE_POLICY_PATCHER_SHA256" /opt/nemoclaw-hermes-config/patch-profile-policy-defaults.py \ @@ -1016,7 +1016,16 @@ RUN set -eu; \ test ! -e "$profile_probe_home/config.yaml"; \ HOME="$profile_probe_root" HERMES_HOME="$profile_probe_home" \ /opt/hermes/.venv/bin/python -I \ - /opt/nemoclaw-hermes-config/image-build-probes.py profile-policy + /opt/nemoclaw-hermes-config/image-build-probes.py profile-policy; \ + HOME="$profile_probe_root" HERMES_HOME="$profile_probe_home" \ + /opt/hermes/.venv/bin/python -I \ + /opt/nemoclaw-hermes-config/image-build-probes.py web-search-availability; \ + web_probe_home="$profile_probe_root/default-config"; \ + mkdir "$web_probe_home"; \ + cp /sandbox/.hermes/config.yaml "$web_probe_home/config.yaml"; \ + HOME="$profile_probe_root" HERMES_HOME="$web_probe_home" \ + /opt/hermes/.venv/bin/python -I \ + /opt/nemoclaw-hermes-config/image-build-probes.py web-search-availability # hadolint ignore=DL3066 USER sandbox diff --git a/agents/hermes/config/managed-policy.ts b/agents/hermes/config/managed-policy.ts index 15f24675451..f7b95fa54ce 100644 --- a/agents/hermes/config/managed-policy.ts +++ b/agents/hermes/config/managed-policy.ts @@ -123,6 +123,7 @@ const MANAGED_POLICY_PATHS = [ "updates.pre_update_backup", "updates.refresh_cua_driver", ] as const; +const WEB_KEYLESS_FALLBACK_PATH = "web.keyless_fallback"; type HermesManagedConfigBase = Record & { _config_version: number; @@ -160,7 +161,7 @@ export type HermesManagedPolicyV3 = { schema_version: typeof HERMES_MANAGED_POLICY_SCHEMA_VERSION; config: HermesManagedConfig; env_lines: string[]; - managed_paths: [...typeof MANAGED_POLICY_PATHS]; + managed_paths: string[]; shadow_migration: { routing_keys: [...typeof SHADOW_MIGRATION_ROUTING_KEYS]; env_keys: [...typeof SHADOW_MIGRATION_ENV_KEYS]; @@ -302,12 +303,22 @@ export function buildHermesManagedPolicy( // An explicit Tavily selection replaces managed Firecrawl settings. if (settings.webSearchProvider === "tavily") config.web = { backend: "tavily" }; + // Without any web backend, Hermes falls back to anonymous public search + // backends that sandbox egress blocks. Disable that fallback so web_search is + // not offered. A managed gateway backend keeps the Hermes default: its tool + // availability check still depends on the fallback. The managed path carries + // the value to config-less named profiles through the profile-default patch. + const keylessDisabled = settings.webSearchProvider === null && config.web === undefined; + if (keylessDisabled) config.web = { keyless_fallback: false }; return { schema_version: HERMES_MANAGED_POLICY_SCHEMA_VERSION, config, env_lines: buildHermesEnvLines(settings, env), - managed_paths: [...MANAGED_POLICY_PATHS], + managed_paths: [ + ...MANAGED_POLICY_PATHS, + ...(keylessDisabled ? [WEB_KEYLESS_FALLBACK_PATH] : []), + ], shadow_migration: { routing_keys: [...SHADOW_MIGRATION_ROUTING_KEYS], env_keys: [...SHADOW_MIGRATION_ENV_KEYS], diff --git a/agents/hermes/image-build-probes.py b/agents/hermes/image-build-probes.py index 04ad1aa5f13..db9c79e58d2 100644 --- a/agents/hermes/image-build-probes.py +++ b/agents/hermes/image-build-probes.py @@ -770,6 +770,26 @@ def verify_managed_runtime_capability() -> None: raise RuntimeError("Hermes MCP Streamable HTTP runtime is unavailable") +def verify_web_search_availability() -> None: + """Offer Hermes web tools only when the managed policy keeps a web route.""" + from hermes_cli.config import load_config + from hermes_cli.tools_config import _get_platform_tools + from managed_policy import load_managed_policy + from model_tools import get_tool_definitions + + web = load_managed_policy()["config"].get("web") or {} + expected = web.get("keyless_fallback", True) is not False + toolsets = sorted(_get_platform_tools(load_config(), "cli")) + names = { + item["function"]["name"] + for item in get_tool_definitions(enabled_toolsets=toolsets, quiet_mode=True) + } + for tool in ("web_search", "web_extract"): + if (tool in names) != expected: + state = "omits" if expected else "offers" + raise RuntimeError(f"Hermes {state} {tool} against the managed web policy") + + COMMANDS: dict[str, Callable[[], None]] = { "auxiliary-token-limit": verify_auxiliary_token_limit, "compatibility-retirement": verify_compatibility_retirement, @@ -794,6 +814,7 @@ def verify_managed_runtime_capability() -> None: "session-state-create": verify_session_state_create, "session-state-reopen": verify_session_state_reopen, "secure-directory-modes": verify_secure_directory_modes, + "web-search-availability": verify_web_search_availability, } diff --git a/agents/hermes/patch-profile-policy-defaults.py b/agents/hermes/patch-profile-policy-defaults.py index e1b6845785b..e677158c6a7 100755 --- a/agents/hermes/patch-profile-policy-defaults.py +++ b/agents/hermes/patch-profile-policy-defaults.py @@ -7,7 +7,9 @@ v2026.9.14 defaults would therefore enable smart command approval, browser evaluation of sensitive primitives, reasoning/commentary display, update-time state mutation, disk-backed SQLite temporary storage, and indefinite gateway -sessions outside NemoClaw's generated default home. +sessions outside NemoClaw's generated default home. When the image has no web +backend, they would also offer web tools through the keyless public search +backends that the sandbox egress policy blocks. This image-level compatibility patch changes only the pinned upstream default leaves that NemoClaw already writes explicitly for its default and dashboard @@ -151,6 +153,12 @@ def patch_config_source(source: str, values: dict[str, object]) -> str: f' "refresh_cua_driver": {_literal(values["updates.refresh_cua_driver"])}', ), ) + if "web.keyless_fallback" in values: + replacements += (( + '"keyless_fallback": True,', + "# NemoClaw compatibility override: no web backend, so no anonymous search.\n" + f' "keyless_fallback": {_literal(values["web.keyless_fallback"])},', + ),) return _replace_exact(source, replacements, label="Hermes config") diff --git a/test/agents/hermes/hermes-image-build-probes.test.ts b/test/agents/hermes/hermes-image-build-probes.test.ts index bffbb863c22..916816cab80 100644 --- a/test/agents/hermes/hermes-image-build-probes.test.ts +++ b/test/agents/hermes/hermes-image-build-probes.test.ts @@ -88,6 +88,7 @@ const commands = [ "session-state-create", "session-state-reopen", "secure-directory-modes", + "web-search-availability", ] as const; function writeExecutable(target: string, source: string): void { @@ -263,6 +264,36 @@ module.verify_session_delete() } } +function runWebSearchAvailabilityProbe(web: unknown, tools: string[]) { + const source = ` +import importlib.util +import json +import sys +import types + +web, tools = json.loads(sys.argv[2]), json.loads(sys.argv[3]) +modules = { + "hermes_cli": types.ModuleType("hermes_cli"), + "hermes_cli.config": types.SimpleNamespace(load_config=lambda: {}), + "hermes_cli.tools_config": types.SimpleNamespace(_get_platform_tools=lambda _c, _p: {"web"}), + "managed_policy": types.SimpleNamespace(load_managed_policy=lambda: {"config": {"web": web}}), + "model_tools": types.SimpleNamespace( + get_tool_definitions=lambda **_k: [{"function": {"name": name}} for name in tools] + ), +} +sys.modules.update(modules) +spec = importlib.util.spec_from_file_location("image_build_probes", sys.argv[1]) +module = importlib.util.module_from_spec(spec) +spec.loader.exec_module(module) +module.verify_web_search_availability() +`; + return spawnSync( + "python3", + ["-I", "-c", source, probes, JSON.stringify(web), JSON.stringify(tools)], + { encoding: "utf8", timeout: 5000 }, + ); +} + function runGoogleChatOverrideSeamsProbe() { const temporaryRoot = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-googlechat-seams-")); const adapter = path.join(temporaryRoot, "adapter.py"); @@ -405,6 +436,24 @@ describe("Hermes image build probes", () => { ); }); + it.each([ + ["no web backend without web tools", { keyless_fallback: false }, ["terminal"], 0, ""], + [ + "no web backend with web tools", + { keyless_fallback: false }, + ["terminal", "web_search", "web_extract"], + 1, + "offers web_search", + ], + ["a web backend with web tools", { backend: "tavily" }, ["web_search", "web_extract"], 0, ""], + ["a web backend without web tools", { backend: "tavily" }, ["terminal"], 1, "omits web_search"], + ])("checks Hermes web tool exposure for %s (#13584)", (_name, web, tools, status, message) => { + const result = runWebSearchAvailabilityProbe(web, tools); + + expect(result.status, result.stderr).toBe(status); + expect(result.stderr).toContain(message); + }); + it("accepts the Hermes 0.21.3 Google Chat override seams", () => { const result = runGoogleChatOverrideSeamsProbe(); @@ -455,11 +504,18 @@ describe("Hermes image build probes", () => { path.join(import.meta.dirname, "../../../agents/hermes/cron-restore-control.py"), ); const cronRestoreDigest = createHash("sha256").update(cronRestoreControl).digest("hex"); + const profilePolicyPatcher = fs.readFileSync( + path.join(import.meta.dirname, "../../../agents/hermes/patch-profile-policy-defaults.py"), + ); + const patcherDigest = createHash("sha256").update(profilePolicyPatcher).digest("hex"); expect(imageDockerfile).toContain(digestBinding); expect(imageDockerfile).toContain( `ARG NEMOCLAW_HERMES_CRON_RESTORE_CONTROLLER_SHA256=${cronRestoreDigest}`, ); + expect(imageDockerfile).toContain( + `ARG NEMOCLAW_HERMES_PROFILE_POLICY_PATCHER_SHA256=${patcherDigest}`, + ); expect( Array.from( imageDockerfile.matchAll( diff --git a/test/agents/hermes/hermes-managed-policy.test.ts b/test/agents/hermes/hermes-managed-policy.test.ts index 1c1a27c3fb2..1c03891ccbe 100644 --- a/test/agents/hermes/hermes-managed-policy.test.ts +++ b/test/agents/hermes/hermes-managed-policy.test.ts @@ -358,6 +358,24 @@ describe("Hermes managed policy", () => { expect(result.stderr).not.toContain(apiKey); }); + it.each([ + ["Tavily", { webSearchProvider: "tavily" as const }, { backend: "tavily" }], + ["no provider", { webSearchProvider: null }, { keyless_fallback: false }], + [ + "no provider with the managed web gateway", + { + webSearchProvider: null, + managedToolGateways: { brokerEnabled: true, presets: ["nous-web"] }, + }, + { backend: "firecrawl", use_gateway: true }, + ], + ])("writes the Hermes web section for %s (#13584)", (_name, overrides, web) => { + const policy = buildHermesManagedPolicy({ ...SETTINGS, ...overrides }, {}); + expect(policy.config.web).toEqual(web); + const result = loadWithPython(policy, true); + expect(result.status, result.stderr).toBe(0); + }); + it("accepts absent inference while retaining managed restrictions", () => { const policy = buildHermesManagedPolicy({ ...SETTINGS, model: null }, {}); const result = loadWithPython(policy); diff --git a/test/agents/hermes/hermes-profile-policy-defaults.test.ts b/test/agents/hermes/hermes-profile-policy-defaults.test.ts index badbd56e97d..3d95097b332 100644 --- a/test/agents/hermes/hermes-profile-policy-defaults.test.ts +++ b/test/agents/hermes/hermes-profile-policy-defaults.test.ts @@ -50,6 +50,9 @@ DEFAULT_CONFIG = { "pre_update_backup": "quick", "refresh_cua_driver": True, }, + "web": { + "keyless_fallback": True, + }, } `; @@ -153,6 +156,7 @@ function patchSource( | "agent" | "main", source: string, + policy: unknown = MANAGED_POLICY, ) { const harness = `\ import importlib.util @@ -175,7 +179,7 @@ sys.stdout.write(patched) `; const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "hermes-profile-policy-")); const policyPath = path.join(tmp, "managed-policy.json"); - fs.writeFileSync(policyPath, `${JSON.stringify(MANAGED_POLICY)}\n`); + fs.writeFileSync(policyPath, `${JSON.stringify(policy)}\n`); try { return spawnSync("python3", ["-I", "-c", harness, patcher, kind, policyPath], { encoding: "utf8", @@ -223,9 +227,27 @@ describe("Hermes profile policy defaults", () => { }, display: { show_commentary: false, show_reasoning: false }, updates: { pre_update_backup: false, refresh_cua_driver: false }, + web: { keyless_fallback: false }, }); }); + it("keeps the keyless web search default when the image has a web backend (#13584)", () => { + const policy = buildHermesManagedPolicy( + { ...POLICY_SETTINGS, webSearchProvider: "tavily" }, + {}, + ); + const result = patchSource("config", configFixture, policy); + + expect(result.status, result.stderr).toBe(0); + const probe = runPatchedPython( + result.stdout, + 'print(namespace["DEFAULT_CONFIG"]["web"]["keyless_fallback"])', + ); + expect(probe.status, probe.stderr).toBe(0); + expect(probe.stdout.trim()).toBe("True"); + expect(policy.managed_paths).not.toContain("web.keyless_fallback"); + }); + it("keeps the browser runtime npx fallback offline", () => { const result = patchSource("browser", browserFixture); diff --git a/test/generation/generate-hermes-config.test.ts b/test/generation/generate-hermes-config.test.ts index d069889f39f..fc583bff15b 100644 --- a/test/generation/generate-hermes-config.test.ts +++ b/test/generation/generate-hermes-config.test.ts @@ -536,7 +536,7 @@ describe("agents/hermes/generate-config.ts", () => { NEMOCLAW_WEB_SEARCH_PROVIDER: "tavily", }); - expect(config.web).toBeUndefined(); + expect(config.web).toEqual({ keyless_fallback: false }); expect(envFile).not.toContain("TAVILY_API_KEY="); });