From 9e0029e999ba7e61cbeb675a4f22ed64ce17e6b7 Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Tue, 8 Sep 2026 06:05:44 -0700 Subject: [PATCH 01/23] fix(install): refuse implicit CLI downgrades Signed-off-by: Rebecca Sliter <571084+rsliter@users.noreply.github.com> --- install.sh | 56 ++++++++ .../install-downgrade-guard.test.ts | 120 ++++++++++++++++++ 2 files changed, 176 insertions(+) create mode 100644 test/installer-integration/install-downgrade-guard.test.ts diff --git a/install.sh b/install.sh index 0c4ab8412f3..d5529f30e64 100755 --- a/install.sh +++ b/install.sh @@ -79,6 +79,60 @@ clone_nemoclaw_ref() { ) } +installed_nemoclaw_release_version() { + local cli_path output + cli_path="$(command -v nemoclaw 2>/dev/null || true)" + [[ -n "$cli_path" ]] || return 0 + output="$("$cli_path" --version 2>/dev/null || true)" + if [[ "$output" =~ ^nemoclaw[[:space:]]+v([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then + printf '%s' "${BASH_REMATCH[1]}" + fi +} + +checkout_release_version() { + local source_root="$1" target_commit ref version + target_commit="$(git -C "$source_root" rev-parse HEAD 2>/dev/null || true)" + [[ -n "$target_commit" ]] || return 0 + while read -r commit ref; do + [[ "$commit" == "$target_commit" ]] || continue + ref="${ref%\^\{\}}" + version="${ref#refs/tags/v}" + if [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + printf '%s' "$version" + return 0 + fi + done < <(git -C "$source_root" ls-remote --tags origin 'refs/tags/v*' 2>/dev/null || true) +} + +release_version_is_newer() { + local left="$1" right="$2" left_major left_minor left_patch right_major right_minor right_patch + IFS=. read -r left_major left_minor left_patch <<<"$left" + IFS=. read -r right_major right_minor right_patch <<<"$right" + ((10#$left_major > 10#$right_major)) && return 0 + ((10#$left_major < 10#$right_major)) && return 1 + ((10#$left_minor > 10#$right_minor)) && return 0 + ((10#$left_minor < 10#$right_minor)) && return 1 + ((10#$left_patch > 10#$right_patch)) +} + +guard_implicit_maintained_downgrade() { + local source_root="$1" installed_version target_version + [[ -z "${NEMOCLAW_INSTALL_REF:-}" && -z "${NEMOCLAW_INSTALL_TAG:-}" ]] || return 0 + installed_version="$(installed_nemoclaw_release_version)" + [[ -n "$installed_version" ]] || return 0 + target_version="$(checkout_release_version "$source_root")" + if [[ -z "$target_version" ]]; then + printf "[ERROR] Cannot verify the maintained lkg version before replacing installed NemoClaw v%s.\n" "$installed_version" >&2 + printf " The installed CLI was not changed. Set NEMOCLAW_INSTALL_TAG=v%s to reinstall this release.\n" "$installed_version" >&2 + exit 1 + fi + if release_version_is_newer "$installed_version" "$target_version"; then + printf "[ERROR] Refusing to replace installed NemoClaw v%s with maintained lkg v%s.\n" "$installed_version" "$target_version" >&2 + printf " The installed CLI was not changed. Set NEMOCLAW_INSTALL_TAG=v%s to reinstall this release.\n" "$installed_version" >&2 + exit 1 + fi +} + exec_installer_from_ref() { local ref="$1" shift @@ -91,6 +145,8 @@ exec_installer_from_ref() { clone_nemoclaw_ref "$ref" "$source_root" + guard_implicit_maintained_downgrade "$source_root" + payload_script="${source_root}/scripts/install.sh" legacy_script="${source_root}/install.sh" diff --git a/test/installer-integration/install-downgrade-guard.test.ts b/test/installer-integration/install-downgrade-guard.test.ts new file mode 100644 index 00000000000..570e7628ac1 --- /dev/null +++ b/test/installer-integration/install-downgrade-guard.test.ts @@ -0,0 +1,120 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import { spawnSync } from "node:child_process"; +import fs from "node:fs"; +import os from "node:os"; +import path from "node:path"; + +import { afterEach, describe, expect, it } from "vitest"; + +const INSTALLER = path.join(import.meta.dirname, "../..", "install.sh"); +const temporaryDirectories: string[] = []; + +function writeExecutable(filePath: string, contents: string): void { + fs.writeFileSync(filePath, contents, { mode: 0o755 }); +} + +function runInstall( + installedVersion: string, + targetVersion: string, + extraEnvironment: Record = {}, +) { + const root = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-install-downgrade-")); + temporaryDirectories.push(root); + const bin = path.join(root, "bin"); + const payloadMarker = path.join(root, "payload-ran"); + fs.mkdirSync(bin); + writeExecutable( + path.join(bin, "nemoclaw"), + `#!/usr/bin/env bash +printf 'nemoclaw v%s\n' "${installedVersion}" +`, + ); + writeExecutable( + path.join(bin, "git"), + `#!/usr/bin/env bash +repo='' +if [[ "\${1:-}" == '-C' ]]; then + repo="$2" + shift 2 +fi +case "\${1:-}" in + init) + target="\${@: -1}" + mkdir -p "$target/scripts" + cat >"$target/scripts/install.sh" <<'PAYLOAD' +#!/usr/bin/env bash +# NEMOCLAW_VERSIONED_INSTALLER_PAYLOAD=1 +touch "\${EXECUTION_MARKER:?}" +PAYLOAD + chmod +x "$target/scripts/install.sh" + ;; + rev-parse) + printf 'target-commit\n' + ;; + ls-remote) + printf 'target-commit\trefs/tags/v%s\n' "${targetVersion}" + ;; +esac +`, + ); + + const result = spawnSync("bash", [], { + cwd: root, + input: fs.readFileSync(INSTALLER), + encoding: "utf8", + env: { + HOME: root, + PATH: `${bin}:/usr/bin:/bin`, + EXECUTION_MARKER: payloadMarker, + ...extraEnvironment, + }, + }); + return { result, payloadMarker }; +} + +afterEach(() => { + for (const directory of temporaryDirectories.splice(0)) { + fs.rmSync(directory, { recursive: true, force: true }); + } +}); + +describe("public installer downgrade guard", () => { + it("keeps the installed CLI when the implicit lkg release is older (#10948)", () => { + const { result, payloadMarker } = runInstall("0.0.118", "0.0.109"); + + expect(result.status).toBe(1); + expect(`${result.stdout}${result.stderr}`).toContain( + "Refusing to replace installed NemoClaw v0.0.118 with maintained lkg v0.0.109.", + ); + expect(`${result.stdout}${result.stderr}`).toContain("The installed CLI was not changed."); + expect(fs.existsSync(payloadMarker)).toBe(false); + }); + + it("runs the selected payload when the implicit lkg release is newer", () => { + const { result, payloadMarker } = runInstall("0.0.108", "0.0.109"); + + expect(result.status).toBe(0); + expect(fs.existsSync(payloadMarker)).toBe(true); + }); + + it("runs an older release when the user selects its tag", () => { + const { result, payloadMarker } = runInstall("0.0.118", "0.0.109", { + NEMOCLAW_INSTALL_TAG: "v0.0.109", + }); + + expect(result.status).toBe(0); + expect(fs.existsSync(payloadMarker)).toBe(true); + }); + + it("keeps the installed CLI when the implicit lkg version cannot be verified", () => { + const { result, payloadMarker } = runInstall("0.0.118", "unknown"); + + expect(result.status).toBe(1); + expect(`${result.stdout}${result.stderr}`).toContain( + "Cannot verify the maintained lkg version before replacing installed NemoClaw v0.0.118.", + ); + expect(fs.existsSync(payloadMarker)).toBe(false); + }); +}); From f733be1be8139a7996f28e97ca4bf20a82e5c1ed Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Tue, 8 Sep 2026 09:24:10 -0700 Subject: [PATCH 02/23] fix: harden maintained installer downgrade guard Signed-off-by: Rebecca Sliter <571084+rsliter@users.noreply.github.com> --- docs/manage-sandboxes/update-sandboxes.mdx | 4 +- docs/reference/troubleshooting.mdx | 5 +- install.sh | 61 ++++++++++++++++--- .../install-downgrade-guard.test.ts | 60 +++++++++++++++++- 4 files changed, 118 insertions(+), 12 deletions(-) diff --git a/docs/manage-sandboxes/update-sandboxes.mdx b/docs/manage-sandboxes/update-sandboxes.mdx index 6892737be79..96e95fe69ba 100644 --- a/docs/manage-sandboxes/update-sandboxes.mdx +++ b/docs/manage-sandboxes/update-sandboxes.mdx @@ -68,7 +68,9 @@ curl -fsSL https://www.nvidia.com/nemoclaw.sh | bash $$nemoclaw upgrade-sandboxes --check ``` -If a support workflow asks you to pass the maintained tag explicitly, clear any inherited `NEMOCLAW_INSTALL_REF` and set `NEMOCLAW_INSTALL_TAG` on the `bash` side of the install pipeline. +The default installer preserves a newer installed NemoClaw release. It also stops without changing the CLI when it cannot verify the maintained `lkg` release. To intentionally install an older release, select its immutable version tag with `NEMOCLAW_INSTALL_TAG`. + +If a support workflow asks you to pass the maintained tag explicitly, clear any inherited `NEMOCLAW_INSTALL_REF` and set `NEMOCLAW_INSTALL_TAG` on the `bash` side of the install pipeline. The same downgrade protection applies to an explicit `lkg` selection. ```bash curl -fsSL https://www.nvidia.com/nemoclaw.sh | NEMOCLAW_INSTALL_REF= NEMOCLAW_INSTALL_TAG=lkg bash diff --git a/docs/reference/troubleshooting.mdx b/docs/reference/troubleshooting.mdx index 8dcc5c1a2fd..ebeb1ea4af1 100644 --- a/docs/reference/troubleshooting.mdx +++ b/docs/reference/troubleshooting.mdx @@ -575,12 +575,13 @@ migration N was previously applied has been modified ``` -The first error means the installed OpenShell migration set does not contain migration N. The second error means that migration set defines migration N with different contents. NemoClaw identifies `/openshell.db` as incompatible with the installed OpenShell migration set for both errors. This failure can happen after an OpenShell downgrade. Installing a NemoClaw release that is older than the installed one performs that downgrade, because each release pins one OpenShell version and the installer reinstalls OpenShell at the pin. You reach that state in one of three ways: +The first error means the installed OpenShell migration set does not contain migration N. The second error means that migration set defines migration N with different contents. NemoClaw identifies `/openshell.db` as incompatible with the installed OpenShell migration set for both errors. This failure can happen after an OpenShell downgrade. Installing a NemoClaw release that is older than the installed one performs that downgrade, because each release pins one OpenShell version and the installer reinstalls OpenShell at the pin. You reach that state in one of two ways: - You select an older release with `NEMOCLAW_INSTALL_TAG` or `NEMOCLAW_INSTALL_REF`. -- The default `lkg` release is older than the NemoClaw release already on the host. - You install an older OpenShell yourself. +The default installer and an explicit `NEMOCLAW_INSTALL_TAG=lkg` selection stop before replacing a newer installed NemoClaw release. An intentional downgrade requires an immutable older tag or ref. + The diagnosis always prints the database path. When an unused archive path is available, it also prints that archive path beside the selected state directory and the profile-specific onboarding command. When no unused archive path is available, it asks you to keep the gateway stopped and inspect the state directory instead. diff --git a/install.sh b/install.sh index d5529f30e64..f5af0f57746 100755 --- a/install.sh +++ b/install.sh @@ -19,6 +19,7 @@ BOOTSTRAP_TMPDIR="" PAYLOAD_MARKER="NEMOCLAW_VERSIONED_INSTALLER_PAYLOAD=1" DEFAULT_INSTALL_REF="lkg" INSTALL_TAG_EXAMPLE="vX.Y.Z" +BOOTSTRAP_LOOKUP_TIMEOUT_SECONDS=30 resolve_release_tag() { if [[ -n "${NEMOCLAW_INSTALL_REF:-}" ]]; then @@ -80,19 +81,28 @@ clone_nemoclaw_ref() { } installed_nemoclaw_release_version() { - local cli_path output + local cli_path output status cli_path="$(command -v nemoclaw 2>/dev/null || true)" [[ -n "$cli_path" ]] || return 0 - output="$("$cli_path" --version 2>/dev/null || true)" - if [[ "$output" =~ ^nemoclaw[[:space:]]+v([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then + output="$(run_bounded_bootstrap_lookup "installed NemoClaw version lookup" "$cli_path" --version)" || { + status=$? + ((status == 124)) && exit 1 + return 0 + } + if [[ "$output" =~ ^nemoclaw[[:space:]]+v([0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?)$ ]]; then printf '%s' "${BASH_REMATCH[1]}" fi } checkout_release_version() { - local source_root="$1" target_commit ref version + local source_root="$1" target_commit refs status ref version target_commit="$(git -C "$source_root" rev-parse HEAD 2>/dev/null || true)" [[ -n "$target_commit" ]] || return 0 + refs="$(run_bounded_bootstrap_lookup "maintained release tag lookup" git -C "$source_root" ls-remote --tags origin 'refs/tags/v*')" || { + status=$? + ((status == 124)) && exit 1 + return 0 + } while read -r commit ref; do [[ "$commit" == "$target_commit" ]] || continue ref="${ref%\^\{\}}" @@ -101,11 +111,13 @@ checkout_release_version() { printf '%s' "$version" return 0 fi - done < <(git -C "$source_root" ls-remote --tags origin 'refs/tags/v*' 2>/dev/null || true) + done <<<"$refs" } release_version_is_newer() { local left="$1" right="$2" left_major left_minor left_patch right_major right_minor right_patch + left="${left%%+*}" + left="${left%%-*}" IFS=. read -r left_major left_minor left_patch <<<"$left" IFS=. read -r right_major right_minor right_patch <<<"$right" ((10#$left_major > 10#$right_major)) && return 0 @@ -115,9 +127,42 @@ release_version_is_newer() { ((10#$left_patch > 10#$right_patch)) } +run_bounded_bootstrap_lookup() { + local label="$1" output_file command_pid status ticks=0 + shift + output_file="$(mktemp "${TMPDIR:-/tmp}/nemoclaw-bootstrap-lookup.XXXXXX")" + "$@" >"$output_file" 2>/dev/null & + command_pid=$! + while kill -0 "$command_pid" 2>/dev/null; do + if ((ticks >= BOOTSTRAP_LOOKUP_TIMEOUT_SECONDS * 10)); then + kill -TERM "$command_pid" 2>/dev/null || true + wait "$command_pid" 2>/dev/null || true + rm -f "$output_file" + printf '[ERROR] Timed out during %s after %s seconds.\n' "$label" "$BOOTSTRAP_LOOKUP_TIMEOUT_SECONDS" >&2 + printf ' The installed CLI was not changed. Retry or select an explicit immutable release tag.\n' >&2 + return 124 + fi + sleep 0.1 + ticks=$((ticks + 1)) + done + if wait "$command_pid"; then + status=0 + else + status=$? + fi + if ((status == 0)); then + cat "$output_file" + fi + rm -f "$output_file" + return "$status" +} + guard_implicit_maintained_downgrade() { - local source_root="$1" installed_version target_version - [[ -z "${NEMOCLAW_INSTALL_REF:-}" && -z "${NEMOCLAW_INSTALL_TAG:-}" ]] || return 0 + local source_root="$1" selected_ref="$2" installed_version target_version + case "$selected_ref" in + lkg | refs/tags/lkg) ;; + *) return 0 ;; + esac installed_version="$(installed_nemoclaw_release_version)" [[ -n "$installed_version" ]] || return 0 target_version="$(checkout_release_version "$source_root")" @@ -145,7 +190,7 @@ exec_installer_from_ref() { clone_nemoclaw_ref "$ref" "$source_root" - guard_implicit_maintained_downgrade "$source_root" + guard_implicit_maintained_downgrade "$source_root" "$ref" payload_script="${source_root}/scripts/install.sh" legacy_script="${source_root}/install.sh" diff --git a/test/installer-integration/install-downgrade-guard.test.ts b/test/installer-integration/install-downgrade-guard.test.ts index 570e7628ac1..922b021e744 100644 --- a/test/installer-integration/install-downgrade-guard.test.ts +++ b/test/installer-integration/install-downgrade-guard.test.ts @@ -28,6 +28,9 @@ function runInstall( writeExecutable( path.join(bin, "nemoclaw"), `#!/usr/bin/env bash +if [[ "${installedVersion}" == 'hang' ]]; then + /bin/sleep 60 +fi printf 'nemoclaw v%s\n' "${installedVersion}" `, ); @@ -54,11 +57,24 @@ PAYLOAD printf 'target-commit\n' ;; ls-remote) - printf 'target-commit\trefs/tags/v%s\n' "${targetVersion}" + if [[ "${targetVersion}" == 'hang' ]]; then + /bin/sleep 60 + elif [[ "${targetVersion}" == annotated-* ]]; then + version="${targetVersion.replace(/^annotated-/, "")}" + printf 'tag-object\trefs/tags/v%s\n' "$version" + printf 'target-commit\trefs/tags/v%s^{}\n' "$version" + else + printf 'target-commit\trefs/tags/v%s\n' "${targetVersion}" + fi ;; esac `, ); + const sleepBody = + installedVersion === "hang" || targetVersion === "hang" + ? "#!/usr/bin/env bash\nexit 0\n" + : '#!/usr/bin/env bash\nexec /bin/sleep "$@"\n'; + writeExecutable(path.join(bin, "sleep"), sleepBody); const result = spawnSync("bash", [], { cwd: root, @@ -99,6 +115,27 @@ describe("public installer downgrade guard", () => { expect(fs.existsSync(payloadMarker)).toBe(true); }); + it("runs the selected payload when the implicit lkg release is unchanged", () => { + const { result, payloadMarker } = runInstall("0.0.109", "0.0.109"); + + expect(result.status).toBe(0); + expect(fs.existsSync(payloadMarker)).toBe(true); + }); + + it("keeps a newer installed prerelease when the implicit lkg release is older", () => { + const { result, payloadMarker } = runInstall("0.0.119-rc.1", "0.0.118"); + + expect(result.status).toBe(1); + expect(fs.existsSync(payloadMarker)).toBe(false); + }); + + it("accepts the peeled commit from an annotated maintained release tag", () => { + const { result, payloadMarker } = runInstall("0.0.108", "annotated-0.0.109"); + + expect(result.status).toBe(0); + expect(fs.existsSync(payloadMarker)).toBe(true); + }); + it("runs an older release when the user selects its tag", () => { const { result, payloadMarker } = runInstall("0.0.118", "0.0.109", { NEMOCLAW_INSTALL_TAG: "v0.0.109", @@ -108,6 +145,15 @@ describe("public installer downgrade guard", () => { expect(fs.existsSync(payloadMarker)).toBe(true); }); + it("keeps the installed CLI when lkg is selected explicitly", () => { + const { result, payloadMarker } = runInstall("0.0.118", "0.0.109", { + NEMOCLAW_INSTALL_TAG: "lkg", + }); + + expect(result.status).toBe(1); + expect(fs.existsSync(payloadMarker)).toBe(false); + }); + it("keeps the installed CLI when the implicit lkg version cannot be verified", () => { const { result, payloadMarker } = runInstall("0.0.118", "unknown"); @@ -117,4 +163,16 @@ describe("public installer downgrade guard", () => { ); expect(fs.existsSync(payloadMarker)).toBe(false); }); + + it.each([ + ["installed NemoClaw version lookup", "hang", "0.0.109"], + ["maintained release tag lookup", "0.0.108", "hang"], + ])("bounds the %s", (label, installedVersion, targetVersion) => { + const { result, payloadMarker } = runInstall(installedVersion, targetVersion); + + expect(result.status).toBe(1); + expect(`${result.stdout}${result.stderr}`).toContain(`Timed out during ${label}`); + expect(`${result.stdout}${result.stderr}`).toContain("The installed CLI was not changed."); + expect(fs.existsSync(payloadMarker)).toBe(false); + }); }); From 5f6c718b24eb7cf55af00423a4a23849617103d6 Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Tue, 8 Sep 2026 10:17:57 -0700 Subject: [PATCH 03/23] fix: fail closed on unverifiable installed CLI Signed-off-by: Rebecca Sliter <571084+rsliter@users.noreply.github.com> --- install.sh | 33 +++++++++--- .../install-downgrade-guard.test.ts | 52 ++++++++++++++----- 2 files changed, 64 insertions(+), 21 deletions(-) diff --git a/install.sh b/install.sh index f5af0f57746..c4e70599737 100755 --- a/install.sh +++ b/install.sh @@ -83,15 +83,17 @@ clone_nemoclaw_ref() { installed_nemoclaw_release_version() { local cli_path output status cli_path="$(command -v nemoclaw 2>/dev/null || true)" - [[ -n "$cli_path" ]] || return 0 + [[ -n "$cli_path" ]] || return 3 output="$(run_bounded_bootstrap_lookup "installed NemoClaw version lookup" "$cli_path" --version)" || { status=$? - ((status == 124)) && exit 1 - return 0 + ((status == 124)) && return 124 + return 2 } if [[ "$output" =~ ^nemoclaw[[:space:]]+v([0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?)$ ]]; then printf '%s' "${BASH_REMATCH[1]}" + return 0 fi + return 2 } checkout_release_version() { @@ -128,14 +130,23 @@ release_version_is_newer() { } run_bounded_bootstrap_lookup() { - local label="$1" output_file command_pid status ticks=0 + local label="$1" output_file command_pid status ticks=0 grace_ticks shift output_file="$(mktemp "${TMPDIR:-/tmp}/nemoclaw-bootstrap-lookup.XXXXXX")" + set -m "$@" >"$output_file" 2>/dev/null & command_pid=$! + set +m while kill -0 "$command_pid" 2>/dev/null; do if ((ticks >= BOOTSTRAP_LOOKUP_TIMEOUT_SECONDS * 10)); then - kill -TERM "$command_pid" 2>/dev/null || true + kill -TERM -- "-$command_pid" 2>/dev/null || kill -TERM "$command_pid" 2>/dev/null || true + for ((grace_ticks = 0; grace_ticks < 10; grace_ticks++)); do + kill -0 "$command_pid" 2>/dev/null || break + sleep 0.1 + done + if kill -0 "$command_pid" 2>/dev/null; then + kill -KILL -- "-$command_pid" 2>/dev/null || kill -KILL "$command_pid" 2>/dev/null || true + fi wait "$command_pid" 2>/dev/null || true rm -f "$output_file" printf '[ERROR] Timed out during %s after %s seconds.\n' "$label" "$BOOTSTRAP_LOOKUP_TIMEOUT_SECONDS" >&2 @@ -158,13 +169,19 @@ run_bounded_bootstrap_lookup() { } guard_implicit_maintained_downgrade() { - local source_root="$1" selected_ref="$2" installed_version target_version + local source_root="$1" selected_ref="$2" installed_version target_version status case "$selected_ref" in lkg | refs/tags/lkg) ;; *) return 0 ;; esac - installed_version="$(installed_nemoclaw_release_version)" - [[ -n "$installed_version" ]] || return 0 + installed_version="$(installed_nemoclaw_release_version)" || { + status=$? + ((status == 3)) && return 0 + ((status == 124)) && exit 1 + printf '[ERROR] Cannot verify the installed NemoClaw version before selecting maintained lkg.\n' >&2 + printf ' The installed CLI was not changed. Repair it or select an explicit immutable release tag.\n' >&2 + exit 1 + } target_version="$(checkout_release_version "$source_root")" if [[ -z "$target_version" ]]; then printf "[ERROR] Cannot verify the maintained lkg version before replacing installed NemoClaw v%s.\n" "$installed_version" >&2 diff --git a/test/installer-integration/install-downgrade-guard.test.ts b/test/installer-integration/install-downgrade-guard.test.ts index 922b021e744..33c34a27fd0 100644 --- a/test/installer-integration/install-downgrade-guard.test.ts +++ b/test/installer-integration/install-downgrade-guard.test.ts @@ -28,10 +28,12 @@ function runInstall( writeExecutable( path.join(bin, "nemoclaw"), `#!/usr/bin/env bash -if [[ "${installedVersion}" == 'hang' ]]; then - /bin/sleep 60 -fi -printf 'nemoclaw v%s\n' "${installedVersion}" +case "${installedVersion}" in + hang) /bin/sleep 60 ;; + ignore-term) trap '' TERM; while :; do :; done ;; + invalid) printf 'not a NemoClaw version\n' ;; + *) printf 'nemoclaw v%s\n' "${installedVersion}" ;; +esac `, ); writeExecutable( @@ -71,7 +73,7 @@ esac `, ); const sleepBody = - installedVersion === "hang" || targetVersion === "hang" + ["hang", "ignore-term"].includes(installedVersion) || targetVersion === "hang" ? "#!/usr/bin/env bash\nexit 0\n" : '#!/usr/bin/env bash\nexec /bin/sleep "$@"\n'; writeExecutable(path.join(bin, "sleep"), sleepBody); @@ -154,6 +156,25 @@ describe("public installer downgrade guard", () => { expect(fs.existsSync(payloadMarker)).toBe(false); }); + it("keeps the installed CLI when the fully qualified lkg tag is selected", () => { + const { result, payloadMarker } = runInstall("0.0.118", "0.0.109", { + NEMOCLAW_INSTALL_TAG: "refs/tags/lkg", + }); + + expect(result.status).toBe(1); + expect(fs.existsSync(payloadMarker)).toBe(false); + }); + + it("fails closed when the installed CLI reports an invalid version", () => { + const { result, payloadMarker } = runInstall("invalid", "0.0.109"); + + expect(result.status).toBe(1); + expect(`${result.stdout}${result.stderr}`).toContain( + "Cannot verify the installed NemoClaw version", + ); + expect(fs.existsSync(payloadMarker)).toBe(false); + }); + it("keeps the installed CLI when the implicit lkg version cannot be verified", () => { const { result, payloadMarker } = runInstall("0.0.118", "unknown"); @@ -166,13 +187,18 @@ describe("public installer downgrade guard", () => { it.each([ ["installed NemoClaw version lookup", "hang", "0.0.109"], + ["installed NemoClaw version lookup", "ignore-term", "0.0.109"], ["maintained release tag lookup", "0.0.108", "hang"], - ])("bounds the %s", (label, installedVersion, targetVersion) => { - const { result, payloadMarker } = runInstall(installedVersion, targetVersion); - - expect(result.status).toBe(1); - expect(`${result.stdout}${result.stderr}`).toContain(`Timed out during ${label}`); - expect(`${result.stdout}${result.stderr}`).toContain("The installed CLI was not changed."); - expect(fs.existsSync(payloadMarker)).toBe(false); - }); + ])( + "bounds the %s", + (label, installedVersion, targetVersion) => { + const { result, payloadMarker } = runInstall(installedVersion, targetVersion); + + expect(result.status).toBe(1); + expect(`${result.stdout}${result.stderr}`).toContain(`Timed out during ${label}`); + expect(`${result.stdout}${result.stderr}`).toContain("The installed CLI was not changed."); + expect(fs.existsSync(payloadMarker)).toBe(false); + }, + 15_000, + ); }); From 093577d8488f24fbcb4747439b6c5717ca1b93d2 Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Tue, 8 Sep 2026 11:08:11 -0700 Subject: [PATCH 04/23] fix: clean interrupted installer lookups Signed-off-by: Rebecca Sliter <571084+rsliter@users.noreply.github.com> --- docs/manage-sandboxes/update-sandboxes.mdx | 2 +- docs/reference/troubleshooting.mdx | 2 +- install.sh | 37 +++++++--- .../install-downgrade-guard.test.ts | 69 +++++++++++++++++-- 4 files changed, 92 insertions(+), 18 deletions(-) diff --git a/docs/manage-sandboxes/update-sandboxes.mdx b/docs/manage-sandboxes/update-sandboxes.mdx index 96e95fe69ba..7dfd3427c55 100644 --- a/docs/manage-sandboxes/update-sandboxes.mdx +++ b/docs/manage-sandboxes/update-sandboxes.mdx @@ -68,7 +68,7 @@ curl -fsSL https://www.nvidia.com/nemoclaw.sh | bash $$nemoclaw upgrade-sandboxes --check ``` -The default installer preserves a newer installed NemoClaw release. It also stops without changing the CLI when it cannot verify the maintained `lkg` release. To intentionally install an older release, select its immutable version tag with `NEMOCLAW_INSTALL_TAG`. +The default installer preserves a newer installed NemoClaw release. It also stops without changing the CLI when it cannot verify the maintained `lkg` release. To intentionally install an older release from a fixed source, select its version tag or full commit SHA with `NEMOCLAW_INSTALL_TAG`. If a support workflow asks you to pass the maintained tag explicitly, clear any inherited `NEMOCLAW_INSTALL_REF` and set `NEMOCLAW_INSTALL_TAG` on the `bash` side of the install pipeline. The same downgrade protection applies to an explicit `lkg` selection. diff --git a/docs/reference/troubleshooting.mdx b/docs/reference/troubleshooting.mdx index ebeb1ea4af1..5e1f2f23d33 100644 --- a/docs/reference/troubleshooting.mdx +++ b/docs/reference/troubleshooting.mdx @@ -580,7 +580,7 @@ The first error means the installed OpenShell migration set does not contain mig - You select an older release with `NEMOCLAW_INSTALL_TAG` or `NEMOCLAW_INSTALL_REF`. - You install an older OpenShell yourself. -The default installer and an explicit `NEMOCLAW_INSTALL_TAG=lkg` selection stop before replacing a newer installed NemoClaw release. An intentional downgrade requires an immutable older tag or ref. +The default installer and an explicit `NEMOCLAW_INSTALL_TAG=lkg` selection stop before replacing a newer installed NemoClaw release. Other explicit `NEMOCLAW_INSTALL_TAG` or `NEMOCLAW_INSTALL_REF` values can replace the installed release; use a version tag or full commit SHA when you need a fixed source. The diagnosis always prints the database path. When an unused archive path is available, it also prints that archive path beside the selected state directory and the profile-specific onboarding command. When no unused archive path is available, it asks you to keep the gateway stopped and inspect the state directory instead. diff --git a/install.sh b/install.sh index c4e70599737..cf1cf76ddfa 100755 --- a/install.sh +++ b/install.sh @@ -87,6 +87,7 @@ installed_nemoclaw_release_version() { output="$(run_bounded_bootstrap_lookup "installed NemoClaw version lookup" "$cli_path" --version)" || { status=$? ((status == 124)) && return 124 + ((status >= 128)) && return "$status" return 2 } if [[ "$output" =~ ^nemoclaw[[:space:]]+v([0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?)$ ]]; then @@ -103,6 +104,7 @@ checkout_release_version() { refs="$(run_bounded_bootstrap_lookup "maintained release tag lookup" git -C "$source_root" ls-remote --tags origin 'refs/tags/v*')" || { status=$? ((status == 124)) && exit 1 + ((status >= 128)) && exit "$status" return 0 } while read -r commit ref; do @@ -130,24 +132,20 @@ release_version_is_newer() { } run_bounded_bootstrap_lookup() { - local label="$1" output_file command_pid status ticks=0 grace_ticks + local label="$1" output_file command_pid status ticks=0 shift output_file="$(mktemp "${TMPDIR:-/tmp}/nemoclaw-bootstrap-lookup.XXXXXX")" set -m "$@" >"$output_file" 2>/dev/null & command_pid=$! set +m + trap 'trap - INT TERM EXIT; terminate_bootstrap_lookup_group "$command_pid"; rm -f "$output_file"; exit 130' INT + trap 'trap - INT TERM EXIT; terminate_bootstrap_lookup_group "$command_pid"; rm -f "$output_file"; exit 143' TERM + trap 'status=$?; trap - INT TERM EXIT; terminate_bootstrap_lookup_group "$command_pid"; rm -f "$output_file"; exit "$status"' EXIT while kill -0 "$command_pid" 2>/dev/null; do if ((ticks >= BOOTSTRAP_LOOKUP_TIMEOUT_SECONDS * 10)); then - kill -TERM -- "-$command_pid" 2>/dev/null || kill -TERM "$command_pid" 2>/dev/null || true - for ((grace_ticks = 0; grace_ticks < 10; grace_ticks++)); do - kill -0 "$command_pid" 2>/dev/null || break - sleep 0.1 - done - if kill -0 "$command_pid" 2>/dev/null; then - kill -KILL -- "-$command_pid" 2>/dev/null || kill -KILL "$command_pid" 2>/dev/null || true - fi - wait "$command_pid" 2>/dev/null || true + trap - INT TERM EXIT + terminate_bootstrap_lookup_group "$command_pid" rm -f "$output_file" printf '[ERROR] Timed out during %s after %s seconds.\n' "$label" "$BOOTSTRAP_LOOKUP_TIMEOUT_SECONDS" >&2 printf ' The installed CLI was not changed. Retry or select an explicit immutable release tag.\n' >&2 @@ -164,10 +162,28 @@ run_bounded_bootstrap_lookup() { if ((status == 0)); then cat "$output_file" fi + trap - INT TERM EXIT rm -f "$output_file" return "$status" } +terminate_bootstrap_lookup_group() { + local command_pid="$1" grace_ticks + kill -0 "$command_pid" 2>/dev/null || { + wait "$command_pid" 2>/dev/null || true + return + } + kill -TERM -- "-$command_pid" 2>/dev/null || kill -TERM "$command_pid" 2>/dev/null || true + for ((grace_ticks = 0; grace_ticks < 10; grace_ticks++)); do + kill -0 "$command_pid" 2>/dev/null || break + sleep 0.1 + done + if kill -0 "$command_pid" 2>/dev/null; then + kill -KILL -- "-$command_pid" 2>/dev/null || kill -KILL "$command_pid" 2>/dev/null || true + fi + wait "$command_pid" 2>/dev/null || true +} + guard_implicit_maintained_downgrade() { local source_root="$1" selected_ref="$2" installed_version target_version status case "$selected_ref" in @@ -178,6 +194,7 @@ guard_implicit_maintained_downgrade() { status=$? ((status == 3)) && return 0 ((status == 124)) && exit 1 + ((status >= 128)) && exit "$status" printf '[ERROR] Cannot verify the installed NemoClaw version before selecting maintained lkg.\n' >&2 printf ' The installed CLI was not changed. Repair it or select an explicit immutable release tag.\n' >&2 exit 1 diff --git a/test/installer-integration/install-downgrade-guard.test.ts b/test/installer-integration/install-downgrade-guard.test.ts index 33c34a27fd0..ff4ca3a09c8 100644 --- a/test/installer-integration/install-downgrade-guard.test.ts +++ b/test/installer-integration/install-downgrade-guard.test.ts @@ -19,11 +19,14 @@ function runInstall( installedVersion: string, targetVersion: string, extraEnvironment: Record = {}, + options: { lookupTimeoutSeconds?: number; useRealSleep?: boolean } = {}, ) { const root = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-install-downgrade-")); temporaryDirectories.push(root); const bin = path.join(root, "bin"); const payloadMarker = path.join(root, "payload-ran"); + const lookupPid = path.join(root, "lookup.pid"); + const interruptSent = path.join(root, "interrupt-sent"); fs.mkdirSync(bin); writeExecutable( path.join(bin, "nemoclaw"), @@ -31,6 +34,7 @@ function runInstall( case "${installedVersion}" in hang) /bin/sleep 60 ;; ignore-term) trap '' TERM; while :; do :; done ;; + interrupt) printf '%s' "$$" >"\${LOOKUP_PID:?}"; /bin/sleep 60 ;; invalid) printf 'not a NemoClaw version\n' ;; *) printf 'nemoclaw v%s\n' "${installedVersion}" ;; esac @@ -72,24 +76,37 @@ PAYLOAD esac `, ); - const sleepBody = - ["hang", "ignore-term"].includes(installedVersion) || targetVersion === "hang" - ? "#!/usr/bin/env bash\nexit 0\n" - : '#!/usr/bin/env bash\nexec /bin/sleep "$@"\n'; + const sleepBody = options.useRealSleep + ? '#!/usr/bin/env bash\nexec /bin/sleep "$@"\n' + : installedVersion === "interrupt" + ? '#!/usr/bin/env bash\nif [[ -e "${LOOKUP_PID:?}" && ! -e "${INTERRUPT_SENT:?}" ]]; then touch "$INTERRUPT_SENT"; kill -INT "$PPID"; fi\n' + : ["hang", "ignore-term"].includes(installedVersion) || targetVersion === "hang" + ? "#!/usr/bin/env bash\nexit 0\n" + : '#!/usr/bin/env bash\nexec /bin/sleep "$@"\n'; writeExecutable(path.join(bin, "sleep"), sleepBody); + const installerSource = fs + .readFileSync(INSTALLER, "utf8") + .replace( + "BOOTSTRAP_LOOKUP_TIMEOUT_SECONDS=30", + `BOOTSTRAP_LOOKUP_TIMEOUT_SECONDS=${options.lookupTimeoutSeconds ?? 30}`, + ); + const result = spawnSync("bash", [], { cwd: root, - input: fs.readFileSync(INSTALLER), + input: installerSource, encoding: "utf8", env: { HOME: root, PATH: `${bin}:/usr/bin:/bin`, EXECUTION_MARKER: payloadMarker, + INTERRUPT_SENT: interruptSent, + LOOKUP_PID: lookupPid, + TMPDIR: root, ...extraEnvironment, }, }); - return { result, payloadMarker }; + return { lookupPid, payloadMarker, result, root }; } afterEach(() => { @@ -147,6 +164,15 @@ describe("public installer downgrade guard", () => { expect(fs.existsSync(payloadMarker)).toBe(true); }); + it("runs an older release when the user selects another explicit ref", () => { + const { result, payloadMarker } = runInstall("0.0.118", "0.0.109", { + NEMOCLAW_INSTALL_TAG: "latest", + }); + + expect(result.status).toBe(0); + expect(fs.existsSync(payloadMarker)).toBe(true); + }); + it("keeps the installed CLI when lkg is selected explicitly", () => { const { result, payloadMarker } = runInstall("0.0.118", "0.0.109", { NEMOCLAW_INSTALL_TAG: "lkg", @@ -201,4 +227,35 @@ describe("public installer downgrade guard", () => { }, 15_000, ); + + it("waits for the configured lookup deadline when real sleep is used", () => { + const startedAt = performance.now(); + const { result, payloadMarker } = runInstall( + "hang", + "0.0.109", + {}, + { + lookupTimeoutSeconds: 1, + useRealSleep: true, + }, + ); + const elapsedMs = performance.now() - startedAt; + + expect(result.status).toBe(1); + expect(elapsedMs).toBeGreaterThanOrEqual(900); + expect(elapsedMs).toBeLessThan(5_000); + expect(fs.existsSync(payloadMarker)).toBe(false); + }); + + it("cleans up an active lookup when the installer is interrupted", () => { + const { lookupPid, payloadMarker, result, root } = runInstall("interrupt", "0.0.109"); + + expect(result.status).toBe(130); + expect(fs.existsSync(payloadMarker)).toBe(false); + expect( + fs.readdirSync(root).filter((name) => name.startsWith("nemoclaw-bootstrap-lookup.")), + ).toEqual([]); + const pid = Number(fs.readFileSync(lookupPid, "utf8")); + expect(() => process.kill(pid, 0)).toThrow(); + }); }); From a08c366c2a46e1b4895506af4c1cb70b7298c508 Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Tue, 8 Sep 2026 11:32:03 -0700 Subject: [PATCH 05/23] fix: pin guarded installer revision Signed-off-by: Rebecca Sliter <571084+rsliter@users.noreply.github.com> --- docs/reference/troubleshooting.mdx | 2 +- install.sh | 9 +++++---- .../install-downgrade-guard.test.ts | 17 +++++++++++++++-- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/docs/reference/troubleshooting.mdx b/docs/reference/troubleshooting.mdx index 5e1f2f23d33..c1d56ae9853 100644 --- a/docs/reference/troubleshooting.mdx +++ b/docs/reference/troubleshooting.mdx @@ -580,7 +580,7 @@ The first error means the installed OpenShell migration set does not contain mig - You select an older release with `NEMOCLAW_INSTALL_TAG` or `NEMOCLAW_INSTALL_REF`. - You install an older OpenShell yourself. -The default installer and an explicit `NEMOCLAW_INSTALL_TAG=lkg` selection stop before replacing a newer installed NemoClaw release. Other explicit `NEMOCLAW_INSTALL_TAG` or `NEMOCLAW_INSTALL_REF` values can replace the installed release; use a version tag or full commit SHA when you need a fixed source. +The default installer stops before replacing a newer installed NemoClaw release whenever the selected ref is `lkg` or `refs/tags/lkg`, whether it came from `NEMOCLAW_INSTALL_TAG` or the higher-priority `NEMOCLAW_INSTALL_REF`. Other explicit refs can replace the installed release; use a version tag or full commit SHA when you need a fixed source. The diagnosis always prints the database path. When an unused archive path is available, it also prints that archive path beside the selected state directory and the profile-specific onboarding command. When no unused archive path is available, it asks you to keep the gateway stopped and inspect the state directory instead. diff --git a/install.sh b/install.sh index cf1cf76ddfa..d896d29cd35 100755 --- a/install.sh +++ b/install.sh @@ -131,7 +131,7 @@ release_version_is_newer() { ((10#$left_patch > 10#$right_patch)) } -run_bounded_bootstrap_lookup() { +run_bounded_bootstrap_lookup() ( local label="$1" output_file command_pid status ticks=0 shift output_file="$(mktemp "${TMPDIR:-/tmp}/nemoclaw-bootstrap-lookup.XXXXXX")" @@ -165,7 +165,7 @@ run_bounded_bootstrap_lookup() { trap - INT TERM EXIT rm -f "$output_file" return "$status" -} +) terminate_bootstrap_lookup_group() { local command_pid="$1" grace_ticks @@ -216,13 +216,14 @@ exec_installer_from_ref() { local ref="$1" shift - local tmpdir source_root payload_script legacy_script + local tmpdir source_root payload_script legacy_script selected_commit tmpdir="$(mktemp -d)" BOOTSTRAP_TMPDIR="$tmpdir" trap 'rm -rf "${BOOTSTRAP_TMPDIR:-}"' EXIT source_root="${tmpdir}/source" clone_nemoclaw_ref "$ref" "$source_root" + selected_commit="$(git -C "$source_root" rev-parse HEAD)" guard_implicit_maintained_downgrade "$source_root" "$ref" @@ -235,7 +236,7 @@ exec_installer_from_ref() { # helpers beside scripts/install.sh (including DGX Station preparation) # are therefore staged from the same ref before payload execution. verify_downloaded_script "$payload_script" "versioned installer" - NEMOCLAW_INSTALL_REF="$ref" NEMOCLAW_INSTALL_TAG="$ref" NEMOCLAW_BOOTSTRAP_PAYLOAD=1 \ + NEMOCLAW_INSTALL_REF="$selected_commit" NEMOCLAW_INSTALL_TAG="$ref" NEMOCLAW_BOOTSTRAP_PAYLOAD=1 \ bash "$payload_script" "$@" return fi diff --git a/test/installer-integration/install-downgrade-guard.test.ts b/test/installer-integration/install-downgrade-guard.test.ts index ff4ca3a09c8..37de1cb076a 100644 --- a/test/installer-integration/install-downgrade-guard.test.ts +++ b/test/installer-integration/install-downgrade-guard.test.ts @@ -55,7 +55,7 @@ case "\${1:-}" in cat >"$target/scripts/install.sh" <<'PAYLOAD' #!/usr/bin/env bash # NEMOCLAW_VERSIONED_INSTALLER_PAYLOAD=1 -touch "\${EXECUTION_MARKER:?}" +printf '%s' "\${NEMOCLAW_INSTALL_REF:-}" >"\${EXECUTION_MARKER:?}" PAYLOAD chmod +x "$target/scripts/install.sh" ;; @@ -128,10 +128,17 @@ describe("public installer downgrade guard", () => { }); it("runs the selected payload when the implicit lkg release is newer", () => { - const { result, payloadMarker } = runInstall("0.0.108", "0.0.109"); + const { result, payloadMarker, root } = runInstall("0.0.108", "0.0.109"); expect(result.status).toBe(0); expect(fs.existsSync(payloadMarker)).toBe(true); + expect(fs.readFileSync(payloadMarker, "utf8")).toBe("target-commit"); + expect( + fs + .readdirSync(root, { withFileTypes: true }) + .filter((entry) => entry.isDirectory()) + .map((entry) => entry.name), + ).toEqual(["bin"]); }); it("runs the selected payload when the implicit lkg release is unchanged", () => { @@ -255,6 +262,12 @@ describe("public installer downgrade guard", () => { expect( fs.readdirSync(root).filter((name) => name.startsWith("nemoclaw-bootstrap-lookup.")), ).toEqual([]); + expect( + fs + .readdirSync(root, { withFileTypes: true }) + .filter((entry) => entry.isDirectory()) + .map((entry) => entry.name), + ).toEqual(["bin"]); const pid = Number(fs.readFileSync(lookupPid, "utf8")); expect(() => process.kill(pid, 0)).toThrow(); }); From e2c56c408035df36ab21e70f70304943c19361ff Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Tue, 8 Sep 2026 12:11:50 -0700 Subject: [PATCH 06/23] fix: harden bounded installer lookup Signed-off-by: Rebecca Sliter <571084+rsliter@users.noreply.github.com> --- install.sh | 4 +++- .../install-downgrade-guard.test.ts | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/install.sh b/install.sh index d896d29cd35..4e6c278c53b 100755 --- a/install.sh +++ b/install.sh @@ -136,7 +136,7 @@ run_bounded_bootstrap_lookup() ( shift output_file="$(mktemp "${TMPDIR:-/tmp}/nemoclaw-bootstrap-lookup.XXXXXX")" set -m - "$@" >"$output_file" 2>/dev/null & + "$@" >"$output_file" 2>/dev/null = 128)); then + status=2 fi trap - INT TERM EXIT rm -f "$output_file" diff --git a/test/installer-integration/install-downgrade-guard.test.ts b/test/installer-integration/install-downgrade-guard.test.ts index 37de1cb076a..6e25687887b 100644 --- a/test/installer-integration/install-downgrade-guard.test.ts +++ b/test/installer-integration/install-downgrade-guard.test.ts @@ -35,6 +35,7 @@ case "${installedVersion}" in hang) /bin/sleep 60 ;; ignore-term) trap '' TERM; while :; do :; done ;; interrupt) printf '%s' "$$" >"\${LOOKUP_PID:?}"; /bin/sleep 60 ;; + signaled) kill -KILL "$$" ;; invalid) printf 'not a NemoClaw version\n' ;; *) printf 'nemoclaw v%s\n' "${installedVersion}" ;; esac @@ -208,6 +209,16 @@ describe("public installer downgrade guard", () => { expect(fs.existsSync(payloadMarker)).toBe(false); }); + it("fails closed when the installed version lookup is killed", () => { + const { result, payloadMarker } = runInstall("signaled", "0.0.109"); + + expect(result.status).toBe(1); + expect(`${result.stdout}${result.stderr}`).toContain( + "Cannot verify the installed NemoClaw version", + ); + expect(fs.existsSync(payloadMarker)).toBe(false); + }); + it("keeps the installed CLI when the implicit lkg version cannot be verified", () => { const { result, payloadMarker } = runInstall("0.0.118", "unknown"); @@ -250,9 +261,9 @@ describe("public installer downgrade guard", () => { expect(result.status).toBe(1); expect(elapsedMs).toBeGreaterThanOrEqual(900); - expect(elapsedMs).toBeLessThan(5_000); + expect(elapsedMs).toBeLessThan(10_000); expect(fs.existsSync(payloadMarker)).toBe(false); - }); + }, 15_000); it("cleans up an active lookup when the installer is interrupted", () => { const { lookupPid, payloadMarker, result, root } = runInstall("interrupt", "0.0.109"); From 1ba51e8b31fd029bcc236f8ffb623f7437917b2d Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Tue, 8 Sep 2026 12:37:33 -0700 Subject: [PATCH 07/23] fix: bind installer lookup process group Signed-off-by: Rebecca Sliter <571084+rsliter@users.noreply.github.com> --- docs/manage-sandboxes/update-sandboxes.mdx | 4 ++++ install.sh | 19 +++++++++++---- scripts/install.sh | 6 ++++- .../install-downgrade-guard.test.ts | 23 ++++++++++++++++--- 4 files changed, 43 insertions(+), 9 deletions(-) diff --git a/docs/manage-sandboxes/update-sandboxes.mdx b/docs/manage-sandboxes/update-sandboxes.mdx index 7dfd3427c55..33729ab1ceb 100644 --- a/docs/manage-sandboxes/update-sandboxes.mdx +++ b/docs/manage-sandboxes/update-sandboxes.mdx @@ -70,6 +70,10 @@ $$nemoclaw upgrade-sandboxes --check The default installer preserves a newer installed NemoClaw release. It also stops without changing the CLI when it cannot verify the maintained `lkg` release. To intentionally install an older release from a fixed source, select its version tag or full commit SHA with `NEMOCLAW_INSTALL_TAG`. +```bash +curl -fsSL https://www.nvidia.com/nemoclaw.sh | NEMOCLAW_INSTALL_REF= NEMOCLAW_INSTALL_TAG=vX.Y.Z bash +``` + If a support workflow asks you to pass the maintained tag explicitly, clear any inherited `NEMOCLAW_INSTALL_REF` and set `NEMOCLAW_INSTALL_TAG` on the `bash` side of the install pipeline. The same downgrade protection applies to an explicit `lkg` selection. ```bash diff --git a/install.sh b/install.sh index 4e6c278c53b..f32bbba422c 100755 --- a/install.sh +++ b/install.sh @@ -20,6 +20,7 @@ PAYLOAD_MARKER="NEMOCLAW_VERSIONED_INSTALLER_PAYLOAD=1" DEFAULT_INSTALL_REF="lkg" INSTALL_TAG_EXAMPLE="vX.Y.Z" BOOTSTRAP_LOOKUP_TIMEOUT_SECONDS=30 +SELECTED_PAYLOAD_IDENTITY_REF="" resolve_release_tag() { if [[ -n "${NEMOCLAW_INSTALL_REF:-}" ]]; then @@ -142,7 +143,7 @@ run_bounded_bootstrap_lookup() ( trap 'trap - INT TERM EXIT; terminate_bootstrap_lookup_group "$command_pid"; rm -f "$output_file"; exit 130' INT trap 'trap - INT TERM EXIT; terminate_bootstrap_lookup_group "$command_pid"; rm -f "$output_file"; exit 143' TERM trap 'status=$?; trap - INT TERM EXIT; terminate_bootstrap_lookup_group "$command_pid"; rm -f "$output_file"; exit "$status"' EXIT - while kill -0 "$command_pid" 2>/dev/null; do + while bootstrap_lookup_group_is_alive "$command_pid"; do if ((ticks >= BOOTSTRAP_LOOKUP_TIMEOUT_SECONDS * 10)); then trap - INT TERM EXIT terminate_bootstrap_lookup_group "$command_pid" @@ -169,18 +170,23 @@ run_bounded_bootstrap_lookup() ( return "$status" ) +bootstrap_lookup_group_is_alive() { + local command_pid="$1" + kill -0 -- "-$command_pid" 2>/dev/null || kill -0 "$command_pid" 2>/dev/null +} + terminate_bootstrap_lookup_group() { local command_pid="$1" grace_ticks - kill -0 "$command_pid" 2>/dev/null || { + bootstrap_lookup_group_is_alive "$command_pid" || { wait "$command_pid" 2>/dev/null || true return } kill -TERM -- "-$command_pid" 2>/dev/null || kill -TERM "$command_pid" 2>/dev/null || true for ((grace_ticks = 0; grace_ticks < 10; grace_ticks++)); do - kill -0 "$command_pid" 2>/dev/null || break + bootstrap_lookup_group_is_alive "$command_pid" || break sleep 0.1 done - if kill -0 "$command_pid" 2>/dev/null; then + if bootstrap_lookup_group_is_alive "$command_pid"; then kill -KILL -- "-$command_pid" 2>/dev/null || kill -KILL "$command_pid" 2>/dev/null || true fi wait "$command_pid" 2>/dev/null || true @@ -207,6 +213,7 @@ guard_implicit_maintained_downgrade() { printf " The installed CLI was not changed. Set NEMOCLAW_INSTALL_TAG=v%s to reinstall this release.\n" "$installed_version" >&2 exit 1 fi + SELECTED_PAYLOAD_IDENTITY_REF="v${target_version}" if release_version_is_newer "$installed_version" "$target_version"; then printf "[ERROR] Refusing to replace installed NemoClaw v%s with maintained lkg v%s.\n" "$installed_version" "$target_version" >&2 printf " The installed CLI was not changed. Set NEMOCLAW_INSTALL_TAG=v%s to reinstall this release.\n" "$installed_version" >&2 @@ -238,7 +245,9 @@ exec_installer_from_ref() { # helpers beside scripts/install.sh (including DGX Station preparation) # are therefore staged from the same ref before payload execution. verify_downloaded_script "$payload_script" "versioned installer" - NEMOCLAW_INSTALL_REF="$selected_commit" NEMOCLAW_INSTALL_TAG="$ref" NEMOCLAW_BOOTSTRAP_PAYLOAD=1 \ + NEMOCLAW_BOOTSTRAP_FETCH_REF="$selected_commit" \ + NEMOCLAW_INSTALL_REF="${SELECTED_PAYLOAD_IDENTITY_REF:-$ref}" \ + NEMOCLAW_INSTALL_TAG="$ref" NEMOCLAW_BOOTSTRAP_PAYLOAD=1 \ bash "$payload_script" "$@" return fi diff --git a/scripts/install.sh b/scripts/install.sh index 1e3ef2172aa..a7f95e0c4f7 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -145,8 +145,12 @@ canonical_agent_name() { } # Resolve which Git ref to install from. -# Priority: NEMOCLAW_INSTALL_TAG env var > lkg tag. +# Priority: bootstrap fetch pin > NEMOCLAW_INSTALL_REF > NEMOCLAW_INSTALL_TAG > lkg tag. resolve_release_tag() { + if [[ -n "${NEMOCLAW_BOOTSTRAP_FETCH_REF:-}" ]]; then + printf "%s" "${NEMOCLAW_BOOTSTRAP_FETCH_REF}" + return + fi if [[ -n "${NEMOCLAW_INSTALL_REF:-}" ]]; then printf "%s" "${NEMOCLAW_INSTALL_REF}" return diff --git a/test/installer-integration/install-downgrade-guard.test.ts b/test/installer-integration/install-downgrade-guard.test.ts index 6e25687887b..23942843a99 100644 --- a/test/installer-integration/install-downgrade-guard.test.ts +++ b/test/installer-integration/install-downgrade-guard.test.ts @@ -35,6 +35,7 @@ case "${installedVersion}" in hang) /bin/sleep 60 ;; ignore-term) trap '' TERM; while :; do :; done ;; interrupt) printf '%s' "$$" >"\${LOOKUP_PID:?}"; /bin/sleep 60 ;; + descendant-ignore-term) (trap '' TERM; printf '%s' "\${BASHPID}" >"\${LOOKUP_PID:?}"; while :; do :; done) & exit 0 ;; signaled) kill -KILL "$$" ;; invalid) printf 'not a NemoClaw version\n' ;; *) printf 'nemoclaw v%s\n' "${installedVersion}" ;; @@ -56,7 +57,7 @@ case "\${1:-}" in cat >"$target/scripts/install.sh" <<'PAYLOAD' #!/usr/bin/env bash # NEMOCLAW_VERSIONED_INSTALLER_PAYLOAD=1 -printf '%s' "\${NEMOCLAW_INSTALL_REF:-}" >"\${EXECUTION_MARKER:?}" +printf '%s|%s|%s' "\${NEMOCLAW_BOOTSTRAP_FETCH_REF:-}" "\${NEMOCLAW_INSTALL_REF:-}" "\${NEMOCLAW_INSTALL_TAG:-}" >"\${EXECUTION_MARKER:?}" PAYLOAD chmod +x "$target/scripts/install.sh" ;; @@ -81,7 +82,8 @@ esac ? '#!/usr/bin/env bash\nexec /bin/sleep "$@"\n' : installedVersion === "interrupt" ? '#!/usr/bin/env bash\nif [[ -e "${LOOKUP_PID:?}" && ! -e "${INTERRUPT_SENT:?}" ]]; then touch "$INTERRUPT_SENT"; kill -INT "$PPID"; fi\n' - : ["hang", "ignore-term"].includes(installedVersion) || targetVersion === "hang" + : ["hang", "ignore-term", "descendant-ignore-term"].includes(installedVersion) || + targetVersion === "hang" ? "#!/usr/bin/env bash\nexit 0\n" : '#!/usr/bin/env bash\nexec /bin/sleep "$@"\n'; writeExecutable(path.join(bin, "sleep"), sleepBody); @@ -133,7 +135,7 @@ describe("public installer downgrade guard", () => { expect(result.status).toBe(0); expect(fs.existsSync(payloadMarker)).toBe(true); - expect(fs.readFileSync(payloadMarker, "utf8")).toBe("target-commit"); + expect(fs.readFileSync(payloadMarker, "utf8")).toBe("target-commit|v0.0.109|lkg"); expect( fs .readdirSync(root, { withFileTypes: true }) @@ -282,4 +284,19 @@ describe("public installer downgrade guard", () => { const pid = Number(fs.readFileSync(lookupPid, "utf8")); expect(() => process.kill(pid, 0)).toThrow(); }); + + it("kills a lookup descendant after its process-group leader exits", () => { + const { lookupPid, payloadMarker, result } = runInstall("descendant-ignore-term", "0.0.109"); + + expect(result.status).toBe(1); + expect(`${result.stdout}${result.stderr}`).toContain( + "Timed out during installed NemoClaw version lookup", + ); + expect(fs.existsSync(payloadMarker)).toBe(false); + const pid = Number(fs.readFileSync(lookupPid, "utf8")); + const processState = spawnSync("ps", ["-o", "stat=", "-p", String(pid)], { + encoding: "utf8", + }); + expect(processState.status === 1 || processState.stdout.trim().startsWith("Z")).toBe(true); + }); }); From 2285e1946843c56d88f19a25809f17a29be73690 Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Tue, 8 Sep 2026 13:15:55 -0700 Subject: [PATCH 08/23] fix(installer): harden downgrade guard review gaps Signed-off-by: Rebecca Sliter <571084+rsliter@users.noreply.github.com> --- docs/manage-sandboxes/update-sandboxes.mdx | 2 +- install.sh | 19 ++-- .../install-downgrade-guard.test.ts | 93 ++++++++++++++++++- 3 files changed, 102 insertions(+), 12 deletions(-) diff --git a/docs/manage-sandboxes/update-sandboxes.mdx b/docs/manage-sandboxes/update-sandboxes.mdx index 33729ab1ceb..70d3b8778ca 100644 --- a/docs/manage-sandboxes/update-sandboxes.mdx +++ b/docs/manage-sandboxes/update-sandboxes.mdx @@ -68,7 +68,7 @@ curl -fsSL https://www.nvidia.com/nemoclaw.sh | bash $$nemoclaw upgrade-sandboxes --check ``` -The default installer preserves a newer installed NemoClaw release. It also stops without changing the CLI when it cannot verify the maintained `lkg` release. To intentionally install an older release from a fixed source, select its version tag or full commit SHA with `NEMOCLAW_INSTALL_TAG`. +The default installer preserves a newer installed NemoClaw release. When a NemoClaw CLI is installed, it also stops without changing the CLI when it cannot verify the maintained `lkg` release. To intentionally install an older release from a fixed source, select its version tag or full commit SHA with `NEMOCLAW_INSTALL_TAG`. ```bash curl -fsSL https://www.nvidia.com/nemoclaw.sh | NEMOCLAW_INSTALL_REF= NEMOCLAW_INSTALL_TAG=vX.Y.Z bash diff --git a/install.sh b/install.sh index f32bbba422c..4de4af61a72 100755 --- a/install.sh +++ b/install.sh @@ -82,8 +82,13 @@ clone_nemoclaw_ref() { } installed_nemoclaw_release_version() { - local cli_path output status - cli_path="$(command -v nemoclaw 2>/dev/null || true)" + local cli_name cli_path output status + case "${NEMOCLAW_AGENT:-openclaw}" in + hermes) cli_name="nemohermes" ;; + langchain-deepagents-code) cli_name="nemo-deepagents" ;; + *) cli_name="nemoclaw" ;; + esac + cli_path="$(command -v "$cli_name" 2>/dev/null || true)" [[ -n "$cli_path" ]] || return 3 output="$(run_bounded_bootstrap_lookup "installed NemoClaw version lookup" "$cli_path" --version)" || { status=$? @@ -91,7 +96,7 @@ installed_nemoclaw_release_version() { ((status >= 128)) && return "$status" return 2 } - if [[ "$output" =~ ^nemoclaw[[:space:]]+v([0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?)$ ]]; then + if [[ "$output" =~ ^${cli_name}[[:space:]]+v([0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?)$ ]]; then printf '%s' "${BASH_REMATCH[1]}" return 0 fi @@ -133,16 +138,16 @@ release_version_is_newer() { } run_bounded_bootstrap_lookup() ( - local label="$1" output_file command_pid status ticks=0 + local label="$1" output_file command_pid="" status ticks=0 shift output_file="$(mktemp "${TMPDIR:-/tmp}/nemoclaw-bootstrap-lookup.XXXXXX")" + trap 'trap - INT TERM EXIT; [[ -z "$command_pid" ]] || terminate_bootstrap_lookup_group "$command_pid"; rm -f "$output_file"; exit 130' INT + trap 'trap - INT TERM EXIT; [[ -z "$command_pid" ]] || terminate_bootstrap_lookup_group "$command_pid"; rm -f "$output_file"; exit 143' TERM + trap 'status=$?; trap - INT TERM EXIT; [[ -z "$command_pid" ]] || terminate_bootstrap_lookup_group "$command_pid"; rm -f "$output_file"; exit "$status"' EXIT set -m "$@" >"$output_file" 2>/dev/null = BOOTSTRAP_LOOKUP_TIMEOUT_SECONDS * 10)); then trap - INT TERM EXIT diff --git a/test/installer-integration/install-downgrade-guard.test.ts b/test/installer-integration/install-downgrade-guard.test.ts index 23942843a99..d98e0aeb161 100644 --- a/test/installer-integration/install-downgrade-guard.test.ts +++ b/test/installer-integration/install-downgrade-guard.test.ts @@ -8,6 +8,8 @@ import path from "node:path"; import { afterEach, describe, expect, it } from "vitest"; +import { INSTALLER_PAYLOAD } from "../helpers/installer-sourced-env"; + const INSTALLER = path.join(import.meta.dirname, "../..", "install.sh"); const temporaryDirectories: string[] = []; @@ -19,7 +21,11 @@ function runInstall( installedVersion: string, targetVersion: string, extraEnvironment: Record = {}, - options: { lookupTimeoutSeconds?: number; useRealSleep?: boolean } = {}, + options: { + interruptBeforeLookupTrap?: boolean; + lookupTimeoutSeconds?: number; + useRealSleep?: boolean; + } = {}, ) { const root = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-install-downgrade-")); temporaryDirectories.push(root); @@ -27,18 +33,25 @@ function runInstall( const payloadMarker = path.join(root, "payload-ran"); const lookupPid = path.join(root, "lookup.pid"); const interruptSent = path.join(root, "interrupt-sent"); + const cliName = + extraEnvironment.NEMOCLAW_AGENT === "hermes" + ? "nemohermes" + : extraEnvironment.NEMOCLAW_AGENT === "langchain-deepagents-code" + ? "nemo-deepagents" + : "nemoclaw"; fs.mkdirSync(bin); writeExecutable( - path.join(bin, "nemoclaw"), + path.join(bin, cliName), `#!/usr/bin/env bash case "${installedVersion}" in hang) /bin/sleep 60 ;; ignore-term) trap '' TERM; while :; do :; done ;; interrupt) printf '%s' "$$" >"\${LOOKUP_PID:?}"; /bin/sleep 60 ;; + trap-race) printf '%s' "$$" >"\${LOOKUP_PID:?}"; /bin/sleep 60 ;; descendant-ignore-term) (trap '' TERM; printf '%s' "\${BASHPID}" >"\${LOOKUP_PID:?}"; while :; do :; done) & exit 0 ;; signaled) kill -KILL "$$" ;; invalid) printf 'not a NemoClaw version\n' ;; - *) printf 'nemoclaw v%s\n' "${installedVersion}" ;; + *) printf '${cliName} v%s\n' "${installedVersion}" ;; esac `, ); @@ -88,12 +101,18 @@ esac : '#!/usr/bin/env bash\nexec /bin/sleep "$@"\n'; writeExecutable(path.join(bin, "sleep"), sleepBody); - const installerSource = fs + let installerSource = fs .readFileSync(INSTALLER, "utf8") .replace( "BOOTSTRAP_LOOKUP_TIMEOUT_SECONDS=30", `BOOTSTRAP_LOOKUP_TIMEOUT_SECONDS=${options.lookupTimeoutSeconds ?? 30}`, ); + installerSource = options.interruptBeforeLookupTrap + ? installerSource.replace( + " command_pid=$!\n set +m", + ' command_pid=$!\n while [[ ! -s "${LOOKUP_PID:?}" ]]; do :; done\n /bin/bash -c \'kill -INT "$PPID"\'\n set +m', + ) + : installerSource; const result = spawnSync("bash", [], { cwd: root, @@ -130,6 +149,21 @@ describe("public installer downgrade guard", () => { expect(fs.existsSync(payloadMarker)).toBe(false); }); + it.each([ + ["Hermes", "hermes"], + ["Deep Agents", "langchain-deepagents-code"], + ])("keeps the installed %s CLI when the implicit lkg release is older", (_label, agent) => { + const { result, payloadMarker } = runInstall("0.0.118", "0.0.109", { + NEMOCLAW_AGENT: agent, + }); + + expect(result.status).toBe(1); + expect(`${result.stdout}${result.stderr}`).toContain( + "Refusing to replace installed NemoClaw v0.0.118 with maintained lkg v0.0.109.", + ); + expect(fs.existsSync(payloadMarker)).toBe(false); + }); + it("runs the selected payload when the implicit lkg release is newer", () => { const { result, payloadMarker, root } = runInstall("0.0.108", "0.0.109"); @@ -285,6 +319,23 @@ describe("public installer downgrade guard", () => { expect(() => process.kill(pid, 0)).toThrow(); }); + it("registers cleanup before starting a version lookup", () => { + const { lookupPid, payloadMarker, result, root } = runInstall( + "trap-race", + "0.0.109", + {}, + { interruptBeforeLookupTrap: true }, + ); + + expect(result.status).not.toBe(0); + expect(fs.existsSync(payloadMarker)).toBe(false); + expect( + fs.readdirSync(root).filter((name) => name.startsWith("nemoclaw-bootstrap-lookup.")), + ).toEqual([]); + const pid = Number(fs.readFileSync(lookupPid, "utf8")); + expect(() => process.kill(pid, 0)).toThrow(); + }); + it("kills a lookup descendant after its process-group leader exits", () => { const { lookupPid, payloadMarker, result } = runInstall("descendant-ignore-term", "0.0.109"); @@ -300,3 +351,37 @@ describe("public installer downgrade guard", () => { expect(processState.status === 1 || processState.stdout.trim().startsWith("Z")).toBe(true); }); }); + +describe("versioned installer payload ref selection", () => { + it("passes the bootstrap commit to the managed clone boundary", () => { + const root = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-payload-ref-")); + temporaryDirectories.push(root); + const cloneMarker = path.join(root, "clone-ref"); + const result = spawnSync( + "bash", + [ + "-c", + `source "$INSTALLER_PAYLOAD" >/dev/null +resolve_repo_root() { printf '%s' "$NON_SOURCE_ROOT"; } +clone_nemoclaw_ref() { printf '%s' "$1" >"$CLONE_MARKER"; return 73; } +install_nemoclaw`, + ], + { + encoding: "utf8", + env: { + ...process.env, + CLONE_MARKER: cloneMarker, + HOME: root, + INSTALLER_PAYLOAD, + NEMOCLAW_BOOTSTRAP_FETCH_REF: "bootstrap-commit", + NEMOCLAW_INSTALL_REF: "v0.0.109", + NEMOCLAW_INSTALL_TAG: "lkg", + NON_SOURCE_ROOT: path.join(root, "not-a-checkout"), + }, + }, + ); + + expect(result.status).toBe(73); + expect(fs.readFileSync(cloneMarker, "utf8")).toBe("bootstrap-commit"); + }); +}); From 9f361b00198650373b477d3dbb78b503fcf54b6e Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Tue, 8 Sep 2026 13:59:28 -0700 Subject: [PATCH 09/23] test(installer): cover release and signal ordering Signed-off-by: Rebecca Sliter <571084+rsliter@users.noreply.github.com> --- install.sh | 2 ++ .../install-downgrade-guard.test.ts | 28 +++++++++++++++---- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/install.sh b/install.sh index 4de4af61a72..1e5b9e67713 100755 --- a/install.sh +++ b/install.sh @@ -117,6 +117,8 @@ checkout_release_version() { [[ "$commit" == "$target_commit" ]] || continue ref="${ref%\^\{\}}" version="${ref#refs/tags/v}" + # The maintained lkg must resolve to a stable release. Rejecting prerelease + # tags also prevents replacing a stable install with the same core version. if [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then printf '%s' "$version" return 0 diff --git a/test/installer-integration/install-downgrade-guard.test.ts b/test/installer-integration/install-downgrade-guard.test.ts index d98e0aeb161..8f672f969b2 100644 --- a/test/installer-integration/install-downgrade-guard.test.ts +++ b/test/installer-integration/install-downgrade-guard.test.ts @@ -47,6 +47,7 @@ case "${installedVersion}" in hang) /bin/sleep 60 ;; ignore-term) trap '' TERM; while :; do :; done ;; interrupt) printf '%s' "$$" >"\${LOOKUP_PID:?}"; /bin/sleep 60 ;; + terminate) printf '%s' "$$" >"\${LOOKUP_PID:?}"; /bin/sleep 60 ;; trap-race) printf '%s' "$$" >"\${LOOKUP_PID:?}"; /bin/sleep 60 ;; descendant-ignore-term) (trap '' TERM; printf '%s' "\${BASHPID}" >"\${LOOKUP_PID:?}"; while :; do :; done) & exit 0 ;; signaled) kill -KILL "$$" ;; @@ -93,8 +94,10 @@ esac ); const sleepBody = options.useRealSleep ? '#!/usr/bin/env bash\nexec /bin/sleep "$@"\n' - : installedVersion === "interrupt" - ? '#!/usr/bin/env bash\nif [[ -e "${LOOKUP_PID:?}" && ! -e "${INTERRUPT_SENT:?}" ]]; then touch "$INTERRUPT_SENT"; kill -INT "$PPID"; fi\n' + : installedVersion === "interrupt" || installedVersion === "terminate" + ? `#!/usr/bin/env bash +if [[ -e "\${LOOKUP_PID:?}" && ! -e "\${INTERRUPT_SENT:?}" ]]; then touch "$INTERRUPT_SENT"; kill -${installedVersion === "terminate" ? "TERM" : "INT"} "$PPID"; fi +` : ["hang", "ignore-term", "descendant-ignore-term"].includes(installedVersion) || targetVersion === "hang" ? "#!/usr/bin/env bash\nexit 0\n" @@ -192,6 +195,16 @@ describe("public installer downgrade guard", () => { expect(fs.existsSync(payloadMarker)).toBe(false); }); + it("keeps a stable install when lkg resolves only to the same-core prerelease", () => { + const { result, payloadMarker } = runInstall("0.0.109", "0.0.109-rc.1"); + + expect(result.status).toBe(1); + expect(`${result.stdout}${result.stderr}`).toContain( + "Cannot verify the maintained lkg version before replacing installed NemoClaw v0.0.109.", + ); + expect(fs.existsSync(payloadMarker)).toBe(false); + }); + it("accepts the peeled commit from an annotated maintained release tag", () => { const { result, payloadMarker } = runInstall("0.0.108", "annotated-0.0.109"); @@ -301,10 +314,13 @@ describe("public installer downgrade guard", () => { expect(fs.existsSync(payloadMarker)).toBe(false); }, 15_000); - it("cleans up an active lookup when the installer is interrupted", () => { - const { lookupPid, payloadMarker, result, root } = runInstall("interrupt", "0.0.109"); + it.each([ + ["interrupted", "interrupt", 130], + ["terminated", "terminate", 143], + ])("cleans up an active lookup when the installer is %s", (_label, signal, status) => { + const { lookupPid, payloadMarker, result, root } = runInstall(signal, "0.0.109"); - expect(result.status).toBe(130); + expect(result.status).toBe(status); expect(fs.existsSync(payloadMarker)).toBe(false); expect( fs.readdirSync(root).filter((name) => name.startsWith("nemoclaw-bootstrap-lookup.")), @@ -327,7 +343,7 @@ describe("public installer downgrade guard", () => { { interruptBeforeLookupTrap: true }, ); - expect(result.status).not.toBe(0); + expect(result.status).toBe(130); expect(fs.existsSync(payloadMarker)).toBe(false); expect( fs.readdirSync(root).filter((name) => name.startsWith("nemoclaw-bootstrap-lookup.")), From 85c11f97860bd05157934e058b8599385b69541a Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Tue, 8 Sep 2026 14:21:33 -0700 Subject: [PATCH 10/23] test(installer): target bootstrap signal traps Signed-off-by: Rebecca Sliter <571084+rsliter@users.noreply.github.com> --- .../install-downgrade-guard.test.ts | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/test/installer-integration/install-downgrade-guard.test.ts b/test/installer-integration/install-downgrade-guard.test.ts index 8f672f969b2..578d5cae173 100644 --- a/test/installer-integration/install-downgrade-guard.test.ts +++ b/test/installer-integration/install-downgrade-guard.test.ts @@ -32,7 +32,6 @@ function runInstall( const bin = path.join(root, "bin"); const payloadMarker = path.join(root, "payload-ran"); const lookupPid = path.join(root, "lookup.pid"); - const interruptSent = path.join(root, "interrupt-sent"); const cliName = extraEnvironment.NEMOCLAW_AGENT === "hermes" ? "nemohermes" @@ -46,8 +45,8 @@ function runInstall( case "${installedVersion}" in hang) /bin/sleep 60 ;; ignore-term) trap '' TERM; while :; do :; done ;; - interrupt) printf '%s' "$$" >"\${LOOKUP_PID:?}"; /bin/sleep 60 ;; - terminate) printf '%s' "$$" >"\${LOOKUP_PID:?}"; /bin/sleep 60 ;; + interrupt) printf '%s' "$$" >"\${LOOKUP_PID:?}"; kill -INT "$PPID"; exec /bin/sleep 60 ;; + terminate) printf '%s' "$$" >"\${LOOKUP_PID:?}"; kill -TERM "$PPID"; exec /bin/sleep 60 ;; trap-race) printf '%s' "$$" >"\${LOOKUP_PID:?}"; /bin/sleep 60 ;; descendant-ignore-term) (trap '' TERM; printf '%s' "\${BASHPID}" >"\${LOOKUP_PID:?}"; while :; do :; done) & exit 0 ;; signaled) kill -KILL "$$" ;; @@ -94,14 +93,10 @@ esac ); const sleepBody = options.useRealSleep ? '#!/usr/bin/env bash\nexec /bin/sleep "$@"\n' - : installedVersion === "interrupt" || installedVersion === "terminate" - ? `#!/usr/bin/env bash -if [[ -e "\${LOOKUP_PID:?}" && ! -e "\${INTERRUPT_SENT:?}" ]]; then touch "$INTERRUPT_SENT"; kill -${installedVersion === "terminate" ? "TERM" : "INT"} "$PPID"; fi -` - : ["hang", "ignore-term", "descendant-ignore-term"].includes(installedVersion) || - targetVersion === "hang" - ? "#!/usr/bin/env bash\nexit 0\n" - : '#!/usr/bin/env bash\nexec /bin/sleep "$@"\n'; + : ["hang", "ignore-term", "descendant-ignore-term"].includes(installedVersion) || + targetVersion === "hang" + ? "#!/usr/bin/env bash\nexit 0\n" + : '#!/usr/bin/env bash\nexec /bin/sleep "$@"\n'; writeExecutable(path.join(bin, "sleep"), sleepBody); let installerSource = fs @@ -125,7 +120,6 @@ if [[ -e "\${LOOKUP_PID:?}" && ! -e "\${INTERRUPT_SENT:?}" ]]; then touch "$INTE HOME: root, PATH: `${bin}:/usr/bin:/bin`, EXECUTION_MARKER: payloadMarker, - INTERRUPT_SENT: interruptSent, LOOKUP_PID: lookupPid, TMPDIR: root, ...extraEnvironment, From dd7ecd00ffcb6bb8fa6e63b837ef3a6a88904039 Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Tue, 8 Sep 2026 15:06:45 -0700 Subject: [PATCH 11/23] fix(installer): bound bootstrap lookup output Signed-off-by: Rebecca Sliter <571084+rsliter@users.noreply.github.com> --- install.sh | 13 ++- .../install-downgrade-guard.test.ts | 101 +++++++++++++----- 2 files changed, 87 insertions(+), 27 deletions(-) diff --git a/install.sh b/install.sh index 1e5b9e67713..2ebf0d30acb 100755 --- a/install.sh +++ b/install.sh @@ -20,6 +20,7 @@ PAYLOAD_MARKER="NEMOCLAW_VERSIONED_INSTALLER_PAYLOAD=1" DEFAULT_INSTALL_REF="lkg" INSTALL_TAG_EXAMPLE="vX.Y.Z" BOOTSTRAP_LOOKUP_TIMEOUT_SECONDS=30 +BOOTSTRAP_LOOKUP_MAX_OUTPUT_BYTES=65536 SELECTED_PAYLOAD_IDENTITY_REF="" resolve_release_tag() { @@ -140,14 +141,17 @@ release_version_is_newer() { } run_bounded_bootstrap_lookup() ( - local label="$1" output_file command_pid="" status ticks=0 + local label="$1" output_file command_pid="" output_bytes status ticks=0 shift output_file="$(mktemp "${TMPDIR:-/tmp}/nemoclaw-bootstrap-lookup.XXXXXX")" trap 'trap - INT TERM EXIT; [[ -z "$command_pid" ]] || terminate_bootstrap_lookup_group "$command_pid"; rm -f "$output_file"; exit 130' INT trap 'trap - INT TERM EXIT; [[ -z "$command_pid" ]] || terminate_bootstrap_lookup_group "$command_pid"; rm -f "$output_file"; exit 143' TERM trap 'status=$?; trap - INT TERM EXIT; [[ -z "$command_pid" ]] || terminate_bootstrap_lookup_group "$command_pid"; rm -f "$output_file"; exit "$status"' EXIT set -m - "$@" >"$output_file" 2>/dev/null /dev/null "$output_file" 2>/dev/null & command_pid=$! set +m while bootstrap_lookup_group_is_alive "$command_pid"; do @@ -167,7 +171,10 @@ run_bounded_bootstrap_lookup() ( else status=$? fi - if ((status == 0)); then + output_bytes="$(wc -c <"$output_file")" + if ((output_bytes > BOOTSTRAP_LOOKUP_MAX_OUTPUT_BYTES)); then + status=2 + elif ((status == 0)); then cat "$output_file" elif ((status >= 128)); then status=2 diff --git a/test/installer-integration/install-downgrade-guard.test.ts b/test/installer-integration/install-downgrade-guard.test.ts index 578d5cae173..79423c9d980 100644 --- a/test/installer-integration/install-downgrade-guard.test.ts +++ b/test/installer-integration/install-downgrade-guard.test.ts @@ -23,6 +23,8 @@ function runInstall( extraEnvironment: Record = {}, options: { interruptBeforeLookupTrap?: boolean; + lookupMaxOutputBytes?: number; + lookupSignal?: "INT" | "TERM"; lookupTimeoutSeconds?: number; useRealSleep?: boolean; } = {}, @@ -45,11 +47,12 @@ function runInstall( case "${installedVersion}" in hang) /bin/sleep 60 ;; ignore-term) trap '' TERM; while :; do :; done ;; - interrupt) printf '%s' "$$" >"\${LOOKUP_PID:?}"; kill -INT "$PPID"; exec /bin/sleep 60 ;; - terminate) printf '%s' "$$" >"\${LOOKUP_PID:?}"; kill -TERM "$PPID"; exec /bin/sleep 60 ;; + interrupt) printf '%s' "$$" >"\${LOOKUP_PID:?}"; exec /bin/sleep 60 ;; + terminate) printf '%s' "$$" >"\${LOOKUP_PID:?}"; exec /bin/sleep 60 ;; trap-race) printf '%s' "$$" >"\${LOOKUP_PID:?}"; /bin/sleep 60 ;; descendant-ignore-term) (trap '' TERM; printf '%s' "\${BASHPID}" >"\${LOOKUP_PID:?}"; while :; do :; done) & exit 0 ;; signaled) kill -KILL "$$" ;; + oversized) printf 'nemoclaw v0.0.118'; printf '%0100d' 0 ;; invalid) printf 'not a NemoClaw version\n' ;; *) printf '${cliName} v%s\n' "${installedVersion}" ;; esac @@ -104,11 +107,19 @@ esac .replace( "BOOTSTRAP_LOOKUP_TIMEOUT_SECONDS=30", `BOOTSTRAP_LOOKUP_TIMEOUT_SECONDS=${options.lookupTimeoutSeconds ?? 30}`, + ) + .replace( + "BOOTSTRAP_LOOKUP_MAX_OUTPUT_BYTES=65536", + `BOOTSTRAP_LOOKUP_MAX_OUTPUT_BYTES=${options.lookupMaxOutputBytes ?? 65536}`, ); - installerSource = options.interruptBeforeLookupTrap + const lookupSignal = options.lookupSignal ?? (options.interruptBeforeLookupTrap ? "INT" : ""); + installerSource = lookupSignal ? installerSource.replace( " command_pid=$!\n set +m", - ' command_pid=$!\n while [[ ! -s "${LOOKUP_PID:?}" ]]; do :; done\n /bin/bash -c \'kill -INT "$PPID"\'\n set +m', + ` command_pid=$! + while [[ ! -s "\${LOOKUP_PID:?}" ]]; do :; done + /bin/bash -c 'kill -${lookupSignal} "$PPID"' + set +m`, ) : installerSource; @@ -135,7 +146,7 @@ afterEach(() => { }); describe("public installer downgrade guard", () => { - it("keeps the installed CLI when the implicit lkg release is older (#10948)", () => { + it("keeps the installed CLI when the implicit lkg release is older (#11160)", () => { const { result, payloadMarker } = runInstall("0.0.118", "0.0.109"); expect(result.status).toBe(1); @@ -242,6 +253,18 @@ describe("public installer downgrade guard", () => { expect(fs.existsSync(payloadMarker)).toBe(false); }); + it.each(["lkg", "refs/tags/lkg"])( + "keeps the installed CLI when NEMOCLAW_INSTALL_REF selects %s", + (installRef) => { + const { result, payloadMarker } = runInstall("0.0.118", "0.0.109", { + NEMOCLAW_INSTALL_REF: installRef, + }); + + expect(result.status).toBe(1); + expect(fs.existsSync(payloadMarker)).toBe(false); + }, + ); + it("fails closed when the installed CLI reports an invalid version", () => { const { result, payloadMarker } = runInstall("invalid", "0.0.109"); @@ -262,6 +285,26 @@ describe("public installer downgrade guard", () => { expect(fs.existsSync(payloadMarker)).toBe(false); }); + it("fails closed and cleans up when installed CLI output exceeds the bound", () => { + const { result, payloadMarker, root } = runInstall( + "oversized", + "0.0.109", + {}, + { + lookupMaxOutputBytes: 32, + }, + ); + + expect(result.status).toBe(1); + expect(`${result.stdout}${result.stderr}`).toContain( + "Cannot verify the installed NemoClaw version", + ); + expect(fs.existsSync(payloadMarker)).toBe(false); + expect( + fs.readdirSync(root).filter((name) => name.startsWith("nemoclaw-bootstrap-lookup.")), + ).toEqual([]); + }); + it("keeps the installed CLI when the implicit lkg version cannot be verified", () => { const { result, payloadMarker } = runInstall("0.0.118", "unknown"); @@ -309,25 +352,35 @@ describe("public installer downgrade guard", () => { }, 15_000); it.each([ - ["interrupted", "interrupt", 130], - ["terminated", "terminate", 143], - ])("cleans up an active lookup when the installer is %s", (_label, signal, status) => { - const { lookupPid, payloadMarker, result, root } = runInstall(signal, "0.0.109"); + ["interrupted", "interrupt", "INT", 130], + ["terminated", "terminate", "TERM", 143], + ] as const)( + "cleans up an active lookup when the installer is %s", + (_label, mode, signal, status) => { + const { lookupPid, payloadMarker, result, root } = runInstall( + mode, + "0.0.109", + {}, + { + lookupSignal: signal, + }, + ); - expect(result.status).toBe(status); - expect(fs.existsSync(payloadMarker)).toBe(false); - expect( - fs.readdirSync(root).filter((name) => name.startsWith("nemoclaw-bootstrap-lookup.")), - ).toEqual([]); - expect( - fs - .readdirSync(root, { withFileTypes: true }) - .filter((entry) => entry.isDirectory()) - .map((entry) => entry.name), - ).toEqual(["bin"]); - const pid = Number(fs.readFileSync(lookupPid, "utf8")); - expect(() => process.kill(pid, 0)).toThrow(); - }); + expect(result.status).toBe(status); + expect(fs.existsSync(payloadMarker)).toBe(false); + expect( + fs.readdirSync(root).filter((name) => name.startsWith("nemoclaw-bootstrap-lookup.")), + ).toEqual([]); + expect( + fs + .readdirSync(root, { withFileTypes: true }) + .filter((entry) => entry.isDirectory()) + .map((entry) => entry.name), + ).toEqual(["bin"]); + const pid = Number(fs.readFileSync(lookupPid, "utf8")); + expect(() => process.kill(pid, 0)).toThrow(); + }, + ); it("registers cleanup before starting a version lookup", () => { const { lookupPid, payloadMarker, result, root } = runInstall( @@ -359,7 +412,7 @@ describe("public installer downgrade guard", () => { encoding: "utf8", }); expect(processState.status === 1 || processState.stdout.trim().startsWith("Z")).toBe(true); - }); + }, 15_000); }); describe("versioned installer payload ref selection", () => { From a1499a6a6c3fcfbab05fc15f22456f5c00ea5b21 Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Tue, 8 Sep 2026 15:42:47 -0700 Subject: [PATCH 12/23] fix(installer): separate bootstrap lookup limits Signed-off-by: Rebecca Sliter <571084+rsliter@users.noreply.github.com> --- install.sh | 15 +++--- .../install-downgrade-guard.test.ts | 53 ++++++++++--------- 2 files changed, 37 insertions(+), 31 deletions(-) diff --git a/install.sh b/install.sh index 2ebf0d30acb..39dd7bd7914 100755 --- a/install.sh +++ b/install.sh @@ -20,7 +20,8 @@ PAYLOAD_MARKER="NEMOCLAW_VERSIONED_INSTALLER_PAYLOAD=1" DEFAULT_INSTALL_REF="lkg" INSTALL_TAG_EXAMPLE="vX.Y.Z" BOOTSTRAP_LOOKUP_TIMEOUT_SECONDS=30 -BOOTSTRAP_LOOKUP_MAX_OUTPUT_BYTES=65536 +BOOTSTRAP_CLI_LOOKUP_MAX_OUTPUT_BYTES=65536 +BOOTSTRAP_TAG_LOOKUP_MAX_OUTPUT_BYTES=1048576 SELECTED_PAYLOAD_IDENTITY_REF="" resolve_release_tag() { @@ -91,7 +92,7 @@ installed_nemoclaw_release_version() { esac cli_path="$(command -v "$cli_name" 2>/dev/null || true)" [[ -n "$cli_path" ]] || return 3 - output="$(run_bounded_bootstrap_lookup "installed NemoClaw version lookup" "$cli_path" --version)" || { + output="$(run_bounded_bootstrap_lookup "installed NemoClaw version lookup" "$BOOTSTRAP_CLI_LOOKUP_MAX_OUTPUT_BYTES" "$cli_path" --version)" || { status=$? ((status == 124)) && return 124 ((status >= 128)) && return "$status" @@ -108,7 +109,7 @@ checkout_release_version() { local source_root="$1" target_commit refs status ref version target_commit="$(git -C "$source_root" rev-parse HEAD 2>/dev/null || true)" [[ -n "$target_commit" ]] || return 0 - refs="$(run_bounded_bootstrap_lookup "maintained release tag lookup" git -C "$source_root" ls-remote --tags origin 'refs/tags/v*')" || { + refs="$(run_bounded_bootstrap_lookup "maintained release tag lookup" "$BOOTSTRAP_TAG_LOOKUP_MAX_OUTPUT_BYTES" git -C "$source_root" ls-remote --tags origin 'refs/tags/v*')" || { status=$? ((status == 124)) && exit 1 ((status >= 128)) && exit "$status" @@ -141,8 +142,8 @@ release_version_is_newer() { } run_bounded_bootstrap_lookup() ( - local label="$1" output_file command_pid="" output_bytes status ticks=0 - shift + local label="$1" max_output_bytes="$2" output_file command_pid="" output_bytes status ticks=0 + shift 2 output_file="$(mktemp "${TMPDIR:-/tmp}/nemoclaw-bootstrap-lookup.XXXXXX")" trap 'trap - INT TERM EXIT; [[ -z "$command_pid" ]] || terminate_bootstrap_lookup_group "$command_pid"; rm -f "$output_file"; exit 130' INT trap 'trap - INT TERM EXIT; [[ -z "$command_pid" ]] || terminate_bootstrap_lookup_group "$command_pid"; rm -f "$output_file"; exit 143' TERM @@ -150,7 +151,7 @@ run_bounded_bootstrap_lookup() ( set -m ( set -o pipefail - "$@" 2>/dev/null /dev/null "$output_file" 2>/dev/null & command_pid=$! set +m @@ -172,7 +173,7 @@ run_bounded_bootstrap_lookup() ( status=$? fi output_bytes="$(wc -c <"$output_file")" - if ((output_bytes > BOOTSTRAP_LOOKUP_MAX_OUTPUT_BYTES)); then + if ((output_bytes > max_output_bytes)); then status=2 elif ((status == 0)); then cat "$output_file" diff --git a/test/installer-integration/install-downgrade-guard.test.ts b/test/installer-integration/install-downgrade-guard.test.ts index 79423c9d980..5a8e5034a45 100644 --- a/test/installer-integration/install-downgrade-guard.test.ts +++ b/test/installer-integration/install-downgrade-guard.test.ts @@ -22,9 +22,9 @@ function runInstall( targetVersion: string, extraEnvironment: Record = {}, options: { - interruptBeforeLookupTrap?: boolean; lookupMaxOutputBytes?: number; lookupSignal?: "INT" | "TERM"; + tagLookupMaxOutputBytes?: number; lookupTimeoutSeconds?: number; useRealSleep?: boolean; } = {}, @@ -49,7 +49,6 @@ case "${installedVersion}" in ignore-term) trap '' TERM; while :; do :; done ;; interrupt) printf '%s' "$$" >"\${LOOKUP_PID:?}"; exec /bin/sleep 60 ;; terminate) printf '%s' "$$" >"\${LOOKUP_PID:?}"; exec /bin/sleep 60 ;; - trap-race) printf '%s' "$$" >"\${LOOKUP_PID:?}"; /bin/sleep 60 ;; descendant-ignore-term) (trap '' TERM; printf '%s' "\${BASHPID}" >"\${LOOKUP_PID:?}"; while :; do :; done) & exit 0 ;; signaled) kill -KILL "$$" ;; oversized) printf 'nemoclaw v0.0.118'; printf '%0100d' 0 ;; @@ -87,6 +86,11 @@ PAYLOAD version="${targetVersion.replace(/^annotated-/, "")}" printf 'tag-object\trefs/tags/v%s\n' "$version" printf 'target-commit\trefs/tags/v%s^{}\n' "$version" + elif [[ "${targetVersion}" == 'many-tags' ]]; then + for version in {1..20}; do + printf 'other-%s\trefs/tags/v0.0.%s\n' "$version" "$version" + done + printf 'target-commit\trefs/tags/v0.0.109\n' else printf 'target-commit\trefs/tags/v%s\n' "${targetVersion}" fi @@ -109,16 +113,19 @@ esac `BOOTSTRAP_LOOKUP_TIMEOUT_SECONDS=${options.lookupTimeoutSeconds ?? 30}`, ) .replace( - "BOOTSTRAP_LOOKUP_MAX_OUTPUT_BYTES=65536", - `BOOTSTRAP_LOOKUP_MAX_OUTPUT_BYTES=${options.lookupMaxOutputBytes ?? 65536}`, + "BOOTSTRAP_CLI_LOOKUP_MAX_OUTPUT_BYTES=65536", + `BOOTSTRAP_CLI_LOOKUP_MAX_OUTPUT_BYTES=${options.lookupMaxOutputBytes ?? 65536}`, + ) + .replace( + "BOOTSTRAP_TAG_LOOKUP_MAX_OUTPUT_BYTES=1048576", + `BOOTSTRAP_TAG_LOOKUP_MAX_OUTPUT_BYTES=${options.tagLookupMaxOutputBytes ?? 1048576}`, ); - const lookupSignal = options.lookupSignal ?? (options.interruptBeforeLookupTrap ? "INT" : ""); - installerSource = lookupSignal + installerSource = options.lookupSignal ? installerSource.replace( " command_pid=$!\n set +m", ` command_pid=$! while [[ ! -s "\${LOOKUP_PID:?}" ]]; do :; done - /bin/bash -c 'kill -${lookupSignal} "$PPID"' + /bin/bash -c 'kill -${options.lookupSignal} "$PPID"' set +m`, ) : installerSource; @@ -217,6 +224,21 @@ describe("public installer downgrade guard", () => { expect(fs.existsSync(payloadMarker)).toBe(true); }); + it("finds the maintained release tag beyond the CLI output bound", () => { + const { result, payloadMarker } = runInstall( + "0.0.108", + "many-tags", + {}, + { + lookupMaxOutputBytes: 32, + tagLookupMaxOutputBytes: 2048, + }, + ); + + expect(result.status).toBe(0); + expect(fs.existsSync(payloadMarker)).toBe(true); + }); + it("runs an older release when the user selects its tag", () => { const { result, payloadMarker } = runInstall("0.0.118", "0.0.109", { NEMOCLAW_INSTALL_TAG: "v0.0.109", @@ -382,23 +404,6 @@ describe("public installer downgrade guard", () => { }, ); - it("registers cleanup before starting a version lookup", () => { - const { lookupPid, payloadMarker, result, root } = runInstall( - "trap-race", - "0.0.109", - {}, - { interruptBeforeLookupTrap: true }, - ); - - expect(result.status).toBe(130); - expect(fs.existsSync(payloadMarker)).toBe(false); - expect( - fs.readdirSync(root).filter((name) => name.startsWith("nemoclaw-bootstrap-lookup.")), - ).toEqual([]); - const pid = Number(fs.readFileSync(lookupPid, "utf8")); - expect(() => process.kill(pid, 0)).toThrow(); - }); - it("kills a lookup descendant after its process-group leader exits", () => { const { lookupPid, payloadMarker, result } = runInstall("descendant-ignore-term", "0.0.109"); From 00594f78d54b90ee47f1adbe7bed48a3d2950286 Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Tue, 8 Sep 2026 16:06:35 -0700 Subject: [PATCH 13/23] test(installer): harden lookup fixtures Signed-off-by: Rebecca Sliter <571084+rsliter@users.noreply.github.com> --- .../install-downgrade-guard.test.ts | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/test/installer-integration/install-downgrade-guard.test.ts b/test/installer-integration/install-downgrade-guard.test.ts index 5a8e5034a45..bdc538c2bfc 100644 --- a/test/installer-integration/install-downgrade-guard.test.ts +++ b/test/installer-integration/install-downgrade-guard.test.ts @@ -17,6 +17,11 @@ function writeExecutable(filePath: string, contents: string): void { fs.writeFileSync(filePath, contents, { mode: 0o755 }); } +function replaceRequired(source: string, expected: string, replacement: string): string { + expect(source).toContain(expected); + return source.replace(expected, replacement); +} + function runInstall( installedVersion: string, targetVersion: string, @@ -106,20 +111,20 @@ esac : '#!/usr/bin/env bash\nexec /bin/sleep "$@"\n'; writeExecutable(path.join(bin, "sleep"), sleepBody); - let installerSource = fs - .readFileSync(INSTALLER, "utf8") - .replace( + let installerSource = replaceRequired( + replaceRequired( + fs.readFileSync(INSTALLER, "utf8"), "BOOTSTRAP_LOOKUP_TIMEOUT_SECONDS=30", `BOOTSTRAP_LOOKUP_TIMEOUT_SECONDS=${options.lookupTimeoutSeconds ?? 30}`, - ) - .replace( - "BOOTSTRAP_CLI_LOOKUP_MAX_OUTPUT_BYTES=65536", - `BOOTSTRAP_CLI_LOOKUP_MAX_OUTPUT_BYTES=${options.lookupMaxOutputBytes ?? 65536}`, - ) - .replace( - "BOOTSTRAP_TAG_LOOKUP_MAX_OUTPUT_BYTES=1048576", - `BOOTSTRAP_TAG_LOOKUP_MAX_OUTPUT_BYTES=${options.tagLookupMaxOutputBytes ?? 1048576}`, - ); + ), + "BOOTSTRAP_CLI_LOOKUP_MAX_OUTPUT_BYTES=65536", + `BOOTSTRAP_CLI_LOOKUP_MAX_OUTPUT_BYTES=${options.lookupMaxOutputBytes ?? 65536}`, + ); + installerSource = replaceRequired( + installerSource, + "BOOTSTRAP_TAG_LOOKUP_MAX_OUTPUT_BYTES=1048576", + `BOOTSTRAP_TAG_LOOKUP_MAX_OUTPUT_BYTES=${options.tagLookupMaxOutputBytes ?? 1048576}`, + ); installerSource = options.lookupSignal ? installerSource.replace( " command_pid=$!\n set +m", @@ -198,6 +203,7 @@ describe("public installer downgrade guard", () => { expect(result.status).toBe(0); expect(fs.existsSync(payloadMarker)).toBe(true); + expect(fs.readFileSync(payloadMarker, "utf8")).toBe("target-commit|v0.0.109|lkg"); }); it("keeps a newer installed prerelease when the implicit lkg release is older", () => { From 01b4c0c487a6a91363bd8476a8ad06309e7e54a9 Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Tue, 8 Sep 2026 16:40:52 -0700 Subject: [PATCH 14/23] test(installer): verify bootstrap fetch boundary Signed-off-by: Rebecca Sliter <571084+rsliter@users.noreply.github.com> --- .../install-downgrade-guard.test.ts | 67 +++++++++++++++++-- 1 file changed, 62 insertions(+), 5 deletions(-) diff --git a/test/installer-integration/install-downgrade-guard.test.ts b/test/installer-integration/install-downgrade-guard.test.ts index bdc538c2bfc..7f0d9ab3d4a 100644 --- a/test/installer-integration/install-downgrade-guard.test.ts +++ b/test/installer-integration/install-downgrade-guard.test.ts @@ -81,6 +81,15 @@ printf '%s|%s|%s' "\${NEMOCLAW_BOOTSTRAP_FETCH_REF:-}" "\${NEMOCLAW_INSTALL_REF: PAYLOAD chmod +x "$target/scripts/install.sh" ;; + remote) + [[ "$*" == 'remote add origin https://github.com/NVIDIA/NemoClaw.git' ]] || exit 91 + ;; + fetch) + [[ "$2" == '--quiet' && "$3" == '--depth' && "$4" == '1' && "$5" == 'origin' && "$6" == +*:refs/nemoclaw-install/target ]] || exit 92 + ;; + -c) + [[ "$*" == '-c advice.detachedHead=false checkout --quiet --detach refs/nemoclaw-install/target' ]] || exit 93 + ;; rev-parse) printf 'target-commit\n' ;; @@ -100,6 +109,7 @@ PAYLOAD printf 'target-commit\trefs/tags/v%s\n' "${targetVersion}" fi ;; + *) exit 94 ;; esac `, ); @@ -243,6 +253,27 @@ describe("public installer downgrade guard", () => { expect(result.status).toBe(0); expect(fs.existsSync(payloadMarker)).toBe(true); + expect(fs.readFileSync(payloadMarker, "utf8")).toBe("target-commit|v0.0.109|lkg"); + }); + + it("fails closed and cleans up when release tag output exceeds its bound", () => { + const { result, payloadMarker, root } = runInstall( + "0.0.108", + "many-tags", + {}, + { + tagLookupMaxOutputBytes: 32, + }, + ); + + expect(result.status).toBe(1); + expect(`${result.stdout}${result.stderr}`).toContain( + "Cannot verify the maintained lkg version before replacing installed NemoClaw v0.0.108.", + ); + expect(fs.existsSync(payloadMarker)).toBe(false); + expect( + fs.readdirSync(root).filter((name) => name.startsWith("nemoclaw-bootstrap-lookup.")), + ).toEqual([]); }); it("runs an older release when the user selects its tag", () => { @@ -430,32 +461,58 @@ describe("versioned installer payload ref selection", () => { it("passes the bootstrap commit to the managed clone boundary", () => { const root = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-payload-ref-")); temporaryDirectories.push(root); - const cloneMarker = path.join(root, "clone-ref"); + const bin = path.join(root, "bin"); + const fetchMarker = path.join(root, "fetch-ref"); + fs.mkdirSync(bin); + writeExecutable( + path.join(bin, "git"), + `#!/usr/bin/env bash +if [[ "\${1:-}" == '-C' ]]; then shift 2; fi +case "\${1:-}" in + init) + [[ "$2" == '--quiet' && -n "\${3:-}" && -z "\${4:-}" ]] || exit 91 + mkdir -p "$3" + ;; + remote) + [[ "$*" == 'remote add origin https://github.com/NVIDIA/NemoClaw.git' ]] || exit 92 + ;; + fetch) + [[ "$2" == '--quiet' && "$3" == '--depth' && "$4" == '1' && "$5" == 'origin' && "$6" == '+target-commit:refs/nemoclaw-install/target' && -z "\${7:-}" ]] || exit 93 + printf 'target-commit' >"\${FETCH_MARKER:?}" + ;; + -c) + [[ "$*" == '-c advice.detachedHead=false checkout --quiet --detach refs/nemoclaw-install/target' ]] || exit 94 + exit 73 + ;; + *) exit 95 ;; +esac +`, + ); const result = spawnSync( "bash", [ "-c", `source "$INSTALLER_PAYLOAD" >/dev/null resolve_repo_root() { printf '%s' "$NON_SOURCE_ROOT"; } -clone_nemoclaw_ref() { printf '%s' "$1" >"$CLONE_MARKER"; return 73; } install_nemoclaw`, ], { encoding: "utf8", env: { ...process.env, - CLONE_MARKER: cloneMarker, + FETCH_MARKER: fetchMarker, HOME: root, INSTALLER_PAYLOAD, - NEMOCLAW_BOOTSTRAP_FETCH_REF: "bootstrap-commit", + NEMOCLAW_BOOTSTRAP_FETCH_REF: "target-commit", NEMOCLAW_INSTALL_REF: "v0.0.109", NEMOCLAW_INSTALL_TAG: "lkg", NON_SOURCE_ROOT: path.join(root, "not-a-checkout"), + PATH: `${bin}:/usr/bin:/bin`, }, }, ); expect(result.status).toBe(73); - expect(fs.readFileSync(cloneMarker, "utf8")).toBe("bootstrap-commit"); + expect(fs.readFileSync(fetchMarker, "utf8")).toBe("target-commit"); }); }); From e2c554cbe89bad71f96d1163366ae0dbafab0df8 Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Wed, 9 Sep 2026 07:15:05 -0700 Subject: [PATCH 15/23] fix(install): preserve alias and cancellation safeguards Signed-off-by: Rebecca Sliter <571084+rsliter@users.noreply.github.com> --- install.sh | 33 +++--- .../install-downgrade-guard.test.ts | 102 +++++++++++++++--- 2 files changed, 111 insertions(+), 24 deletions(-) diff --git a/install.sh b/install.sh index 39dd7bd7914..550e7637724 100755 --- a/install.sh +++ b/install.sh @@ -84,10 +84,11 @@ clone_nemoclaw_ref() { } installed_nemoclaw_release_version() { - local cli_name cli_path output status - case "${NEMOCLAW_AGENT:-openclaw}" in - hermes) cli_name="nemohermes" ;; - langchain-deepagents-code) cli_name="nemo-deepagents" ;; + local cli_name cli_path normalized_agent output status + normalized_agent="$(printf '%s' "${NEMOCLAW_AGENT:-openclaw}" | tr '[:upper:]_ ' '[:lower:]--' | sed -E 's/-+/-/g; s/^-//; s/-$//')" + case "$normalized_agent" in + nemohermes | nemo-hermes | hermes) cli_name="nemohermes" ;; + nemo-deepagents | nemo-deepagent | nemodeepagents | nemodeepagent | dcode | deepagent | deepagents | deep-agent | deep-agents | deepagentcode | deepagentscode | deepagent-code | deepagents-code | deep-agent-code | deep-agents-code | langchain | langchain-code | langchaindeepagent | langchaindeepagents | langchain-deepagent | langchain-deepagents | langchaindeepagentcode | langchaindeepagentscode | langchain-deepagent-code | langchain-deepagents-code | langchain-deep-agent | langchain-deep-agents | langchain-deep-agent-code | langchain-deep-agents-code) cli_name="nemo-deepagents" ;; *) cli_name="nemoclaw" ;; esac cli_path="$(command -v "$cli_name" 2>/dev/null || true)" @@ -145,9 +146,21 @@ run_bounded_bootstrap_lookup() ( local label="$1" max_output_bytes="$2" output_file command_pid="" output_bytes status ticks=0 shift 2 output_file="$(mktemp "${TMPDIR:-/tmp}/nemoclaw-bootstrap-lookup.XXXXXX")" - trap 'trap - INT TERM EXIT; [[ -z "$command_pid" ]] || terminate_bootstrap_lookup_group "$command_pid"; rm -f "$output_file"; exit 130' INT - trap 'trap - INT TERM EXIT; [[ -z "$command_pid" ]] || terminate_bootstrap_lookup_group "$command_pid"; rm -f "$output_file"; exit 143' TERM - trap 'status=$?; trap - INT TERM EXIT; [[ -z "$command_pid" ]] || terminate_bootstrap_lookup_group "$command_pid"; rm -f "$output_file"; exit "$status"' EXIT + # Invoked indirectly by the signal and exit traps below. + # shellcheck disable=SC2329 + cleanup_bootstrap_lookup() { + local cleanup_status="$1" + # Preserve cancellation status without interrupting or reentering cleanup. + trap 'cleanup_status=130' INT + trap 'cleanup_status=143' TERM + trap - EXIT + [[ -z "$command_pid" ]] || terminate_bootstrap_lookup_group "$command_pid" + rm -f "$output_file" + exit "$cleanup_status" + } + trap 'cleanup_bootstrap_lookup 130' INT + trap 'cleanup_bootstrap_lookup 143' TERM + trap 'cleanup_bootstrap_lookup "$?"' EXIT set -m ( set -o pipefail @@ -157,9 +170,6 @@ run_bounded_bootstrap_lookup() ( set +m while bootstrap_lookup_group_is_alive "$command_pid"; do if ((ticks >= BOOTSTRAP_LOOKUP_TIMEOUT_SECONDS * 10)); then - trap - INT TERM EXIT - terminate_bootstrap_lookup_group "$command_pid" - rm -f "$output_file" printf '[ERROR] Timed out during %s after %s seconds.\n' "$label" "$BOOTSTRAP_LOOKUP_TIMEOUT_SECONDS" >&2 printf ' The installed CLI was not changed. Retry or select an explicit immutable release tag.\n' >&2 return 124 @@ -172,6 +182,7 @@ run_bounded_bootstrap_lookup() ( else status=$? fi + command_pid="" output_bytes="$(wc -c <"$output_file")" if ((output_bytes > max_output_bytes)); then status=2 @@ -180,8 +191,6 @@ run_bounded_bootstrap_lookup() ( elif ((status >= 128)); then status=2 fi - trap - INT TERM EXIT - rm -f "$output_file" return "$status" ) diff --git a/test/installer-integration/install-downgrade-guard.test.ts b/test/installer-integration/install-downgrade-guard.test.ts index 7f0d9ab3d4a..3338e5d3899 100644 --- a/test/installer-integration/install-downgrade-guard.test.ts +++ b/test/installer-integration/install-downgrade-guard.test.ts @@ -22,6 +22,19 @@ function replaceRequired(source: string, expected: string, replacement: string): return source.replace(expected, replacement); } +function payloadCanonicalAgent(agent: string): string { + const result = spawnSync( + "bash", + ["-c", 'source "$INSTALLER_PAYLOAD" >/dev/null; canonical_agent_name "$AGENT"'], + { + encoding: "utf8", + env: { ...process.env, AGENT: agent, INSTALLER_PAYLOAD }, + }, + ); + expect(result.status).toBe(0); + return result.stdout; +} + function runInstall( installedVersion: string, targetVersion: string, @@ -29,6 +42,7 @@ function runInstall( options: { lookupMaxOutputBytes?: number; lookupSignal?: "INT" | "TERM"; + timeoutCleanupSignal?: "INT" | "TERM"; tagLookupMaxOutputBytes?: number; lookupTimeoutSeconds?: number; useRealSleep?: boolean; @@ -39,12 +53,12 @@ function runInstall( const bin = path.join(root, "bin"); const payloadMarker = path.join(root, "payload-ran"); const lookupPid = path.join(root, "lookup.pid"); - const cliName = - extraEnvironment.NEMOCLAW_AGENT === "hermes" - ? "nemohermes" - : extraEnvironment.NEMOCLAW_AGENT === "langchain-deepagents-code" - ? "nemo-deepagents" - : "nemoclaw"; + const requestedAgent = extraEnvironment.NEMOCLAW_AGENT ?? "openclaw"; + const cliName = ["hermes", "Hermes", "nemohermes", "Nemo Hermes"].includes(requestedAgent) + ? "nemohermes" + : ["langchain-deepagents-code", "dcode", "deep_agents"].includes(requestedAgent) + ? "nemo-deepagents" + : "nemoclaw"; fs.mkdirSync(bin); writeExecutable( path.join(bin, cliName), @@ -52,6 +66,7 @@ function runInstall( case "${installedVersion}" in hang) /bin/sleep 60 ;; ignore-term) trap '' TERM; while :; do :; done ;; + cancel-during-cleanup) trap 'touch "\${LOOKUP_PID:?}.term"' TERM; printf '%s' "$$" >"\${LOOKUP_PID:?}"; while :; do :; done ;; interrupt) printf '%s' "$$" >"\${LOOKUP_PID:?}"; exec /bin/sleep 60 ;; terminate) printf '%s' "$$" >"\${LOOKUP_PID:?}"; exec /bin/sleep 60 ;; descendant-ignore-term) (trap '' TERM; printf '%s' "\${BASHPID}" >"\${LOOKUP_PID:?}"; while :; do :; done) & exit 0 ;; @@ -113,12 +128,20 @@ PAYLOAD esac `, ); - const sleepBody = options.useRealSleep - ? '#!/usr/bin/env bash\nexec /bin/sleep "$@"\n' - : ["hang", "ignore-term", "descendant-ignore-term"].includes(installedVersion) || - targetVersion === "hang" - ? "#!/usr/bin/env bash\nexit 0\n" - : '#!/usr/bin/env bash\nexec /bin/sleep "$@"\n'; + const sleepBody = options.timeoutCleanupSignal + ? `#!/usr/bin/env bash +if [[ -e "\${LOOKUP_PID:?}.term" && ! -e "\${LOOKUP_PID:?}.cancel" ]]; then + touch "\${LOOKUP_PID:?}.cancel" + kill -${options.timeoutCleanupSignal} "$PPID" +fi +exec /bin/sleep "$@" +` + : options.useRealSleep + ? '#!/usr/bin/env bash\nexec /bin/sleep "$@"\n' + : ["hang", "ignore-term", "descendant-ignore-term"].includes(installedVersion) || + targetVersion === "hang" + ? "#!/usr/bin/env bash\nexit 0\n" + : '#!/usr/bin/env bash\nexec /bin/sleep "$@"\n'; writeExecutable(path.join(bin, "sleep"), sleepBody); let installerSource = replaceRequired( @@ -194,6 +217,25 @@ describe("public installer downgrade guard", () => { expect(fs.existsSync(payloadMarker)).toBe(false); }); + it.each([ + ["Hermes", "hermes"], + ["nemohermes", "hermes"], + ["Nemo Hermes", "hermes"], + ["dcode", "langchain-deepagents-code"], + ["deep_agents", "langchain-deepagents-code"], + ])("uses the payload's canonical CLI for the %s alias", (agent, canonicalAgent) => { + expect(payloadCanonicalAgent(agent)).toBe(canonicalAgent); + const { result, payloadMarker } = runInstall("0.0.118", "0.0.109", { + NEMOCLAW_AGENT: agent, + }); + + expect(result.status).toBe(1); + expect(`${result.stdout}${result.stderr}`).toContain( + "Refusing to replace installed NemoClaw v0.0.118 with maintained lkg v0.0.109.", + ); + expect(fs.existsSync(payloadMarker)).toBe(false); + }); + it("runs the selected payload when the implicit lkg release is newer", () => { const { result, payloadMarker, root } = runInstall("0.0.108", "0.0.109"); @@ -441,6 +483,42 @@ describe("public installer downgrade guard", () => { }, ); + it.each([ + ["INT", 130], + ["TERM", 143], + ] as const)( + "finishes timeout cleanup when it receives SIG%s during termination", + (signal, status) => { + const { lookupPid, payloadMarker, result, root } = runInstall( + "cancel-during-cleanup", + "0.0.109", + {}, + { lookupTimeoutSeconds: 1, timeoutCleanupSignal: signal }, + ); + const pid = Number(fs.readFileSync(lookupPid, "utf8")); + + try { + expect(fs.existsSync(`${lookupPid}.cancel`)).toBe(true); + expect(result.status).toBe(status); + expect(fs.existsSync(payloadMarker)).toBe(false); + const processState = spawnSync("ps", ["-o", "stat=", "-p", String(pid)], { + encoding: "utf8", + }); + expect(processState.status === 1 || processState.stdout.trim().startsWith("Z")).toBe(true); + expect( + fs.readdirSync(root).filter((name) => name.startsWith("nemoclaw-bootstrap-lookup.")), + ).toEqual([]); + } finally { + try { + process.kill(pid, "SIGKILL"); + } catch (error) { + expect((error as NodeJS.ErrnoException).code).toBe("ESRCH"); + } + } + }, + 15_000, + ); + it("kills a lookup descendant after its process-group leader exits", () => { const { lookupPid, payloadMarker, result } = runInstall("descendant-ignore-term", "0.0.109"); From cd2b04f5216697b93ee8a790f4e7c095590dd639 Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Wed, 9 Sep 2026 08:00:01 -0700 Subject: [PATCH 16/23] fix(install): close lookup launch cancellation window Signed-off-by: Rebecca Sliter <571084+rsliter@users.noreply.github.com> --- install.sh | 10 +- .../install-downgrade-guard.test.ts | 131 ++++++++---------- 2 files changed, 66 insertions(+), 75 deletions(-) diff --git a/install.sh b/install.sh index 18bbf8d9fee..4b469a1a435 100755 --- a/install.sh +++ b/install.sh @@ -143,7 +143,7 @@ release_version_is_newer() { } run_bounded_bootstrap_lookup() ( - local label="$1" max_output_bytes="$2" output_file command_pid="" output_bytes status ticks=0 + local label="$1" max_output_bytes="$2" output_file command_pid="" output_bytes status ticks=0 pending_signal=0 shift 2 output_file="$(mktemp "${TMPDIR:-/tmp}/nemoclaw-bootstrap-lookup.XXXXXX")" # Invoked indirectly by the signal and exit traps below. @@ -158,8 +158,9 @@ run_bounded_bootstrap_lookup() ( rm -f "$output_file" exit "$cleanup_status" } - trap 'cleanup_bootstrap_lookup 130' INT - trap 'cleanup_bootstrap_lookup 143' TERM + # Defer cancellation until the newly launched process group has an owned PID. + trap 'pending_signal=130' INT + trap 'pending_signal=143' TERM trap 'cleanup_bootstrap_lookup "$?"' EXIT set -m ( @@ -168,6 +169,9 @@ run_bounded_bootstrap_lookup() ( ) >"$output_file" 2>/dev/null & command_pid=$! set +m + trap 'cleanup_bootstrap_lookup 130' INT + trap 'cleanup_bootstrap_lookup 143' TERM + ((pending_signal == 0)) || cleanup_bootstrap_lookup "$pending_signal" while bootstrap_lookup_group_is_alive "$command_pid"; do if ((ticks >= BOOTSTRAP_LOOKUP_TIMEOUT_SECONDS * 10)); then printf '[ERROR] Timed out during %s after %s seconds.\n' "$label" "$BOOTSTRAP_LOOKUP_TIMEOUT_SECONDS" >&2 diff --git a/test/installer-integration/install-downgrade-guard.test.ts b/test/installer-integration/install-downgrade-guard.test.ts index 3338e5d3899..1ea17a3594a 100644 --- a/test/installer-integration/install-downgrade-guard.test.ts +++ b/test/installer-integration/install-downgrade-guard.test.ts @@ -42,10 +42,12 @@ function runInstall( options: { lookupMaxOutputBytes?: number; lookupSignal?: "INT" | "TERM"; + lookupSignalBeforePid?: boolean; timeoutCleanupSignal?: "INT" | "TERM"; tagLookupMaxOutputBytes?: number; lookupTimeoutSeconds?: number; useRealSleep?: boolean; + useRealPayload?: boolean; } = {}, ) { const root = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-install-downgrade-")); @@ -92,7 +94,14 @@ case "\${1:-}" in cat >"$target/scripts/install.sh" <<'PAYLOAD' #!/usr/bin/env bash # NEMOCLAW_VERSIONED_INSTALLER_PAYLOAD=1 -printf '%s|%s|%s' "\${NEMOCLAW_BOOTSTRAP_FETCH_REF:-}" "\${NEMOCLAW_INSTALL_REF:-}" "\${NEMOCLAW_INSTALL_TAG:-}" >"\${EXECUTION_MARKER:?}" +${ + options.useRealPayload + ? `source "$INSTALLER_PAYLOAD" >/dev/null +resolve_repo_root() { printf '%s' "$NON_SOURCE_ROOT"; } +export RECORD_MANAGED_FETCH=1 +install_nemoclaw` + : `printf '%s|%s|%s' "\${NEMOCLAW_BOOTSTRAP_FETCH_REF:-}" "\${NEMOCLAW_INSTALL_REF:-}" "\${NEMOCLAW_INSTALL_TAG:-}" >"\${EXECUTION_MARKER:?}"` +} PAYLOAD chmod +x "$target/scripts/install.sh" ;; @@ -100,10 +109,12 @@ PAYLOAD [[ "$*" == 'remote add origin https://github.com/NVIDIA/NemoClaw.git' ]] || exit 91 ;; fetch) - [[ "$2" == '--quiet' && "$3" == '--depth' && "$4" == '1' && "$5" == 'origin' && "$6" == +*:refs/nemoclaw-install/target ]] || exit 92 + [[ "$2" == '--quiet' && "$3" == '--depth' && "$4" == '1' && "$5" == 'origin' && "$6" == +*:refs/nemoclaw-install/target && -z "\${7:-}" ]] || exit 92 + if [[ "\${RECORD_MANAGED_FETCH:-}" == 1 ]]; then printf '%s' "$6" >"\${EXECUTION_MARKER:?}"; fi ;; -c) [[ "$*" == '-c advice.detachedHead=false checkout --quiet --detach refs/nemoclaw-install/target' ]] || exit 93 + if [[ "\${RECORD_MANAGED_FETCH:-}" == 1 ]]; then exit 73; fi ;; rev-parse) printf 'target-commit\n' @@ -158,13 +169,17 @@ exec /bin/sleep "$@" "BOOTSTRAP_TAG_LOOKUP_MAX_OUTPUT_BYTES=1048576", `BOOTSTRAP_TAG_LOOKUP_MAX_OUTPUT_BYTES=${options.tagLookupMaxOutputBytes ?? 1048576}`, ); + const signalAnchor = options.lookupSignalBeforePid + ? " command_pid=$!" + : ' while bootstrap_lookup_group_is_alive "$command_pid"; do'; installerSource = options.lookupSignal - ? installerSource.replace( - " command_pid=$!\n set +m", - ` command_pid=$! + ? replaceRequired( + installerSource, + signalAnchor, + ` while [[ ! -s "\${LOOKUP_PID:?}" ]]; do :; done /bin/bash -c 'kill -${options.lookupSignal} "$PPID"' - set +m`, +${signalAnchor}`, ) : installerSource; @@ -176,6 +191,8 @@ exec /bin/sleep "$@" HOME: root, PATH: `${bin}:/usr/bin:/bin`, EXECUTION_MARKER: payloadMarker, + INSTALLER_PAYLOAD, + NON_SOURCE_ROOT: path.join(root, "not-a-checkout"), LOOKUP_PID: lookupPid, TMPDIR: root, ...extraEnvironment, @@ -453,33 +470,44 @@ describe("public installer downgrade guard", () => { }, 15_000); it.each([ - ["interrupted", "interrupt", "INT", 130], - ["terminated", "terminate", "TERM", 143], + ["interrupted during lookup", "interrupt", "INT", 130, false], + ["terminated during lookup", "terminate", "TERM", 143, false], + ["interrupted before PID recording", "interrupt", "INT", 130, true], + ["terminated before PID recording", "terminate", "TERM", 143, true], ] as const)( "cleans up an active lookup when the installer is %s", - (_label, mode, signal, status) => { + (_label, mode, signal, status, beforePid) => { const { lookupPid, payloadMarker, result, root } = runInstall( mode, "0.0.109", {}, { lookupSignal: signal, + lookupSignalBeforePid: beforePid, }, ); - expect(result.status).toBe(status); - expect(fs.existsSync(payloadMarker)).toBe(false); - expect( - fs.readdirSync(root).filter((name) => name.startsWith("nemoclaw-bootstrap-lookup.")), - ).toEqual([]); - expect( - fs - .readdirSync(root, { withFileTypes: true }) - .filter((entry) => entry.isDirectory()) - .map((entry) => entry.name), - ).toEqual(["bin"]); const pid = Number(fs.readFileSync(lookupPid, "utf8")); - expect(() => process.kill(pid, 0)).toThrow(); + try { + expect(result.status).toBe(status); + expect(fs.existsSync(payloadMarker)).toBe(false); + expect( + fs.readdirSync(root).filter((name) => name.startsWith("nemoclaw-bootstrap-lookup.")), + ).toEqual([]); + expect( + fs + .readdirSync(root, { withFileTypes: true }) + .filter((entry) => entry.isDirectory()) + .map((entry) => entry.name), + ).toEqual(["bin"]); + expect(() => process.kill(pid, 0)).toThrow(); + } finally { + try { + process.kill(pid, "SIGKILL"); + } catch (error) { + expect((error as NodeJS.ErrnoException).code).toBe("ESRCH"); + } + } }, ); @@ -536,61 +564,20 @@ describe("public installer downgrade guard", () => { }); describe("versioned installer payload ref selection", () => { - it("passes the bootstrap commit to the managed clone boundary", () => { - const root = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-payload-ref-")); - temporaryDirectories.push(root); - const bin = path.join(root, "bin"); - const fetchMarker = path.join(root, "fetch-ref"); - fs.mkdirSync(bin); - writeExecutable( - path.join(bin, "git"), - `#!/usr/bin/env bash -if [[ "\${1:-}" == '-C' ]]; then shift 2; fi -case "\${1:-}" in - init) - [[ "$2" == '--quiet' && -n "\${3:-}" && -z "\${4:-}" ]] || exit 91 - mkdir -p "$3" - ;; - remote) - [[ "$*" == 'remote add origin https://github.com/NVIDIA/NemoClaw.git' ]] || exit 92 - ;; - fetch) - [[ "$2" == '--quiet' && "$3" == '--depth' && "$4" == '1' && "$5" == 'origin' && "$6" == '+target-commit:refs/nemoclaw-install/target' && -z "\${7:-}" ]] || exit 93 - printf 'target-commit' >"\${FETCH_MARKER:?}" - ;; - -c) - [[ "$*" == '-c advice.detachedHead=false checkout --quiet --detach refs/nemoclaw-install/target' ]] || exit 94 - exit 73 - ;; - *) exit 95 ;; -esac -`, - ); - const result = spawnSync( - "bash", - [ - "-c", - `source "$INSTALLER_PAYLOAD" >/dev/null -resolve_repo_root() { printf '%s' "$NON_SOURCE_ROOT"; } -install_nemoclaw`, - ], + it("passes the public bootstrap commit through the real payload to the managed clone", () => { + const { result, payloadMarker } = runInstall( + "0.0.108", + "0.0.109", { - encoding: "utf8", - env: { - ...process.env, - FETCH_MARKER: fetchMarker, - HOME: root, - INSTALLER_PAYLOAD, - NEMOCLAW_BOOTSTRAP_FETCH_REF: "target-commit", - NEMOCLAW_INSTALL_REF: "v0.0.109", - NEMOCLAW_INSTALL_TAG: "lkg", - NON_SOURCE_ROOT: path.join(root, "not-a-checkout"), - PATH: `${bin}:/usr/bin:/bin`, - }, + NEMOCLAW_INSTALL_REF: "lkg", + NEMOCLAW_INSTALL_TAG: "v0.0.108", }, + { useRealPayload: true }, ); expect(result.status).toBe(73); - expect(fs.readFileSync(fetchMarker, "utf8")).toBe("target-commit"); + expect(fs.readFileSync(payloadMarker, "utf8")).toBe( + "+target-commit:refs/nemoclaw-install/target", + ); }); }); From 7da64b9ceb3e53d9dd27c8d4bbc7d0963eef77bb Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Wed, 9 Sep 2026 08:53:36 -0700 Subject: [PATCH 17/23] fix(install): protect bootstrap source handoff Signed-off-by: Rebecca Sliter <571084+rsliter@users.noreply.github.com> --- docs/resources/local-credential-form.html | 3 +- scripts/local-credential-helper.mts | 3 +- src/lib/security/process-control-env.test.ts | 1 + src/lib/security/process-control-env.ts | 1 + .../local-credential-helper-suite.ts | 30 ++++++++----- test/generation/starter-prompt-docs.test.ts | 1 + .../install-downgrade-guard.test.ts | 44 ++++++++++++------- 7 files changed, 55 insertions(+), 28 deletions(-) diff --git a/docs/resources/local-credential-form.html b/docs/resources/local-credential-form.html index 98ca7a9f91a..8c1016af3bb 100644 --- a/docs/resources/local-credential-form.html +++ b/docs/resources/local-credential-form.html @@ -9,7 +9,7 @@ NemoClaw Local Credential Form @@ -222,6 +222,7 @@

NemoClaw Local Credential Form

"NO_PROXY", "NETRC", "NEMOCLAW_ACCEPT_DEV_UNVERIFIED_INSTALL", + "NEMOCLAW_BOOTSTRAP_FETCH_REF", "NEMOCLAW_BOOTSTRAP_PAYLOAD", "NEMOCLAW_INSTALL_REF", "NEMOCLAW_INSTALL_TAG", diff --git a/scripts/local-credential-helper.mts b/scripts/local-credential-helper.mts index 3e4e60e2c83..cdd8cb8ee87 100755 --- a/scripts/local-credential-helper.mts +++ b/scripts/local-credential-helper.mts @@ -23,7 +23,7 @@ import path from "node:path"; import { fileURLToPath } from "node:url"; export const EXPECTED_LOCAL_CREDENTIAL_FORM_SHA256 = - "5512a256e0ad7c63a26ab82cf4f5924e98652097172ab8a5dc9d9358dd4f6ae8"; // gitleaks:allow -- checked-in SHA-256 integrity pin + "cdd85dc6a0b31a8b9773e7ddaacb38a4e8162b0a13b70bebef3dc297ae7a6c44"; // gitleaks:allow -- checked-in SHA-256 integrity pin export const LOCAL_CREDENTIAL_HELPER_HOST = "127.0.0.1"; export const LOCAL_CREDENTIAL_FORM_PATH = "/local-credential-form.html"; @@ -110,6 +110,7 @@ const FORBIDDEN_CHILD_ENV_NAMES = new Set([ "NO_PROXY", "NETRC", "NEMOCLAW_ACCEPT_DEV_UNVERIFIED_INSTALL", + "NEMOCLAW_BOOTSTRAP_FETCH_REF", "NEMOCLAW_BOOTSTRAP_PAYLOAD", "NEMOCLAW_INSTALL_REF", "NEMOCLAW_INSTALL_TAG", diff --git a/src/lib/security/process-control-env.test.ts b/src/lib/security/process-control-env.test.ts index 53543b49de4..309b562f0dc 100644 --- a/src/lib/security/process-control-env.test.ts +++ b/src/lib/security/process-control-env.test.ts @@ -48,6 +48,7 @@ describe("credential-handoff process-control environment policy", () => { "LOCPATH", "NETRC", "NEMOCLAW_ACCEPT_DEV_UNVERIFIED_INSTALL", + "NEMOCLAW_BOOTSTRAP_FETCH_REF", "NEMOCLAW_BOOTSTRAP_PAYLOAD", "NEMOCLAW_INSTALL_REF", "NEMOCLAW_INSTALL_TAG", diff --git a/src/lib/security/process-control-env.ts b/src/lib/security/process-control-env.ts index 64a2b63524e..aae65973ec5 100644 --- a/src/lib/security/process-control-env.ts +++ b/src/lib/security/process-control-env.ts @@ -72,6 +72,7 @@ export const PROCESS_CONTROL_ENV_NAMES: ReadonlySet = new Set([ "NO_PROXY", "NETRC", "NEMOCLAW_ACCEPT_DEV_UNVERIFIED_INSTALL", + "NEMOCLAW_BOOTSTRAP_FETCH_REF", "NEMOCLAW_BOOTSTRAP_PAYLOAD", "NEMOCLAW_INSTALL_REF", "NEMOCLAW_INSTALL_TAG", diff --git a/test/credentials/local-credential-helper-suite.ts b/test/credentials/local-credential-helper-suite.ts index 0080c070a9c..b161fc704f4 100644 --- a/test/credentials/local-credential-helper-suite.ts +++ b/test/credentials/local-credential-helper-suite.ts @@ -47,6 +47,7 @@ const CONFIG_ROOT_ENV_NAMES = [ "LOCPATH", "NETRC", "NEMOCLAW_ACCEPT_DEV_UNVERIFIED_INSTALL", + "NEMOCLAW_BOOTSTRAP_FETCH_REF", "NEMOCLAW_BOOTSTRAP_PAYLOAD", "NEMOCLAW_INSTALL_REF", "NEMOCLAW_INSTALL_TAG", @@ -625,19 +626,26 @@ export function registerLocalCredentialHelperTests(group: LocalCredentialHelperT ).toThrow(); }); - it("wires field rejection through the CLI entrypoint before listening (#5048)", async () => { - const captured = captureChild( - helperArgs(["PATH:text"], [process.execPath, "-e", "process.exit(0)"]), - ); + it.each(["PATH", "NEMOCLAW_BOOTSTRAP_FETCH_REF"])( + "rejects %s through the CLI entrypoint before listening (#5048)", + async (name) => { + const captured = captureChild( + helperArgs([`${name}:text`], [process.execPath, "-e", "process.exit(0)"]), + ); - const result = await withTimeout(captured.closed, PROCESS_TIMEOUT_MS, "invalid helper CLI"); + const result = await withTimeout( + captured.closed, + PROCESS_TIMEOUT_MS, + "invalid helper CLI", + ); - expect(result.code).not.toBe(0); - expect(captured.output()).toContain( - "--field PATH is a process-control environment variable and is not allowed", - ); - expect(captured.output()).not.toMatch(READINESS_URL_PATTERN); - }); + expect(result.code).not.toBe(0); + expect(captured.output()).toContain( + `--field ${name} is a process-control environment variable and is not allowed`, + ); + expect(captured.output()).not.toMatch(READINESS_URL_PATTERN); + }, + ); it.each([ { executable: "node" }, diff --git a/test/generation/starter-prompt-docs.test.ts b/test/generation/starter-prompt-docs.test.ts index b0f0f4270f8..7de068c03f5 100644 --- a/test/generation/starter-prompt-docs.test.ts +++ b/test/generation/starter-prompt-docs.test.ts @@ -80,6 +80,7 @@ const localCredentialConfigControlNames = [ "LOCPATH", "NETRC", "NEMOCLAW_ACCEPT_DEV_UNVERIFIED_INSTALL", + "NEMOCLAW_BOOTSTRAP_FETCH_REF", "NEMOCLAW_BOOTSTRAP_PAYLOAD", "NEMOCLAW_INSTALL_REF", "NEMOCLAW_INSTALL_TAG", diff --git a/test/installer-integration/install-downgrade-guard.test.ts b/test/installer-integration/install-downgrade-guard.test.ts index 1ea17a3594a..821c7999b23 100644 --- a/test/installer-integration/install-downgrade-guard.test.ts +++ b/test/installer-integration/install-downgrade-guard.test.ts @@ -8,6 +8,7 @@ import path from "node:path"; import { afterEach, describe, expect, it } from "vitest"; +import { AGENT_ALIASES, resolveAgentNameAlias } from "../../src/lib/agent/aliases"; import { INSTALLER_PAYLOAD } from "../helpers/installer-sourced-env"; const INSTALLER = path.join(import.meta.dirname, "../..", "install.sh"); @@ -56,15 +57,22 @@ function runInstall( const payloadMarker = path.join(root, "payload-ran"); const lookupPid = path.join(root, "lookup.pid"); const requestedAgent = extraEnvironment.NEMOCLAW_AGENT ?? "openclaw"; - const cliName = ["hermes", "Hermes", "nemohermes", "Nemo Hermes"].includes(requestedAgent) - ? "nemohermes" - : ["langchain-deepagents-code", "dcode", "deep_agents"].includes(requestedAgent) - ? "nemo-deepagents" - : "nemoclaw"; + const canonicalAgent = resolveAgentNameAlias(requestedAgent, [ + "openclaw", + "hermes", + "langchain-deepagents-code", + ]); + const cliName = + canonicalAgent === "hermes" + ? "nemohermes" + : canonicalAgent === "langchain-deepagents-code" + ? "nemo-deepagents" + : "nemoclaw"; fs.mkdirSync(bin); - writeExecutable( - path.join(bin, cliName), - `#!/usr/bin/env bash + for (const installedCli of installedVersion === "absent" ? [] : [cliName]) { + writeExecutable( + path.join(bin, installedCli), + `#!/usr/bin/env bash case "${installedVersion}" in hang) /bin/sleep 60 ;; ignore-term) trap '' TERM; while :; do :; done ;; @@ -73,12 +81,13 @@ case "${installedVersion}" in terminate) printf '%s' "$$" >"\${LOOKUP_PID:?}"; exec /bin/sleep 60 ;; descendant-ignore-term) (trap '' TERM; printf '%s' "\${BASHPID}" >"\${LOOKUP_PID:?}"; while :; do :; done) & exit 0 ;; signaled) kill -KILL "$$" ;; - oversized) printf 'nemoclaw v0.0.118'; printf '%0100d' 0 ;; + oversized) printf 'nemoclaw v0.0.108+'; printf '%0100d' 0 ;; invalid) printf 'not a NemoClaw version\n' ;; *) printf '${cliName} v%s\n' "${installedVersion}" ;; esac `, - ); + ); + } writeExecutable( path.join(bin, "git"), `#!/usr/bin/env bash @@ -235,11 +244,13 @@ describe("public installer downgrade guard", () => { }); it.each([ + ...Object.entries(AGENT_ALIASES), ["Hermes", "hermes"], - ["nemohermes", "hermes"], ["Nemo Hermes", "hermes"], - ["dcode", "langchain-deepagents-code"], ["deep_agents", "langchain-deepagents-code"], + ["NEMO_DEEPAGENTS", "langchain-deepagents-code"], + ["Deep Agents", "langchain-deepagents-code"], + ["LANGCHAIN", "langchain-deepagents-code"], ])("uses the payload's canonical CLI for the %s alias", (agent, canonicalAgent) => { expect(payloadCanonicalAgent(agent)).toBe(canonicalAgent); const { result, payloadMarker } = runInstall("0.0.118", "0.0.109", { @@ -253,12 +264,15 @@ describe("public installer downgrade guard", () => { expect(fs.existsSync(payloadMarker)).toBe(false); }); - it("runs the selected payload when the implicit lkg release is newer", () => { - const { result, payloadMarker, root } = runInstall("0.0.108", "0.0.109"); + it.each([ + ["the implicit lkg release is newer", "0.0.108", "v0.0.109"], + ["no CLI is installed", "absent", "lkg"], + ])("runs the selected payload when %s", (_condition, installedVersion, selectedRef) => { + const { result, payloadMarker, root } = runInstall(installedVersion, "0.0.109"); expect(result.status).toBe(0); expect(fs.existsSync(payloadMarker)).toBe(true); - expect(fs.readFileSync(payloadMarker, "utf8")).toBe("target-commit|v0.0.109|lkg"); + expect(fs.readFileSync(payloadMarker, "utf8")).toBe(`target-commit|${selectedRef}|lkg`); expect( fs .readdirSync(root, { withFileTypes: true }) From e74b5da330c7baf3a665b5017352f9424ba18faf Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Wed, 9 Sep 2026 08:54:59 -0700 Subject: [PATCH 18/23] docs(security): pin the repaired credential helper pair Signed-off-by: Rebecca Sliter <571084+rsliter@users.noreply.github.com> --- docs/resources/starter-prompt.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/resources/starter-prompt.md b/docs/resources/starter-prompt.md index 4fa477448b8..ded8e1028eb 100644 --- a/docs/resources/starter-prompt.md +++ b/docs/resources/starter-prompt.md @@ -155,8 +155,8 @@ Before collecting secrets, determine every environment-variable name and the com Do not generate, rewrite, or redesign the helper or form. Use this reviewed pair without modification: -- Helper: `https://raw.githubusercontent.com/NVIDIA/NemoClaw/dd61a307d7ddf7be99de8ff1e2678fb8ef42f8e6/scripts/local-credential-helper.mts` (SHA-256 `1a42bbe8dbc9003cb79d4e641b53760571aacd85293671aee97c09c0746fef33`). -- Form: `https://raw.githubusercontent.com/NVIDIA/NemoClaw/dd61a307d7ddf7be99de8ff1e2678fb8ef42f8e6/docs/resources/local-credential-form.html` (SHA-256 `5512a256e0ad7c63a26ab82cf4f5924e98652097172ab8a5dc9d9358dd4f6ae8`). +- Helper: `https://raw.githubusercontent.com/NVIDIA/NemoClaw/7da64b9ceb3e53d9dd27c8d4bbc7d0963eef77bb/scripts/local-credential-helper.mts` (SHA-256 `1b58a6dbb6611e29e1daf88b8eb8ec502e82d3bf5cdba86b23db9a0804e6cfad`). +- Form: `https://raw.githubusercontent.com/NVIDIA/NemoClaw/7da64b9ceb3e53d9dd27c8d4bbc7d0963eef77bb/docs/resources/local-credential-form.html` (SHA-256 `cdd85dc6a0b31a8b9773e7ddaacb38a4e8162b0a13b70bebef3dc297ae7a6c44`). - Treat the two immutable URL and digest pairs as one reviewed trust boundary; before executing the helper, compute the SHA-256 digest of both downloaded files and compare each result with its pinned digest. - If either digest differs, do not execute the helper; delete both temporary files and stop. From 6b75bf3439cbd12621d9db9b38a96b37d3ba365e Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Wed, 9 Sep 2026 12:16:24 -0700 Subject: [PATCH 19/23] fix(docs): pin merged credential helper pair Signed-off-by: Rebecca Sliter <571084+rsliter@users.noreply.github.com> --- docs/resources/starter-prompt.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/resources/starter-prompt.md b/docs/resources/starter-prompt.md index 92f3dfe2cd0..9f76c159e44 100644 --- a/docs/resources/starter-prompt.md +++ b/docs/resources/starter-prompt.md @@ -155,8 +155,8 @@ Before collecting secrets, determine every environment-variable name and the com Do not generate, rewrite, or redesign the helper or form. Use this reviewed pair without modification: -- Helper: `https://raw.githubusercontent.com/NVIDIA/NemoClaw/7da64b9ceb3e53d9dd27c8d4bbc7d0963eef77bb/scripts/local-credential-helper.mts` (SHA-256 `f7c255120735307c93767c348bfcd54e7c7008275f9f5215f249e4c1a9daa9be`). -- Form: `https://raw.githubusercontent.com/NVIDIA/NemoClaw/7da64b9ceb3e53d9dd27c8d4bbc7d0963eef77bb/docs/resources/local-credential-form.html` (SHA-256 `cdd85dc6a0b31a8b9773e7ddaacb38a4e8162b0a13b70bebef3dc297ae7a6c44`). +- Helper: `https://raw.githubusercontent.com/NVIDIA/NemoClaw/15bd0dd25b185eafae02a067532fe18718b2be23/scripts/local-credential-helper.mts` (SHA-256 `f7c255120735307c93767c348bfcd54e7c7008275f9f5215f249e4c1a9daa9be`). +- Form: `https://raw.githubusercontent.com/NVIDIA/NemoClaw/15bd0dd25b185eafae02a067532fe18718b2be23/docs/resources/local-credential-form.html` (SHA-256 `cdd85dc6a0b31a8b9773e7ddaacb38a4e8162b0a13b70bebef3dc297ae7a6c44`). - Treat the two immutable URL and digest pairs as one reviewed trust boundary; before executing the helper, compute the SHA-256 digest of both downloaded files and compare each result with its pinned digest. - If either digest differs, do not execute the helper; delete both temporary files and stop. From e56c1f7b726dcd8b5fb78161a763fca909b5dcc9 Mon Sep 17 00:00:00 2001 From: Charan Jagwani Date: Wed, 9 Sep 2026 13:48:29 -0700 Subject: [PATCH 20/23] test(install): close downgrade guard review gaps Signed-off-by: Charan Jagwani --- test/installer-integration/install-downgrade-guard.test.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/installer-integration/install-downgrade-guard.test.ts b/test/installer-integration/install-downgrade-guard.test.ts index 821c7999b23..805aa85a1fb 100644 --- a/test/installer-integration/install-downgrade-guard.test.ts +++ b/test/installer-integration/install-downgrade-guard.test.ts @@ -356,6 +356,7 @@ describe("public installer downgrade guard", () => { expect(result.status).toBe(0); expect(fs.existsSync(payloadMarker)).toBe(true); + expect(fs.readFileSync(payloadMarker, "utf8")).toBe("target-commit|v0.0.109|v0.0.109"); }); it("runs an older release when the user selects another explicit ref", () => { @@ -365,6 +366,7 @@ describe("public installer downgrade guard", () => { expect(result.status).toBe(0); expect(fs.existsSync(payloadMarker)).toBe(true); + expect(fs.readFileSync(payloadMarker, "utf8")).toBe("target-commit|latest|latest"); }); it("keeps the installed CLI when lkg is selected explicitly", () => { @@ -514,7 +516,10 @@ describe("public installer downgrade guard", () => { .filter((entry) => entry.isDirectory()) .map((entry) => entry.name), ).toEqual(["bin"]); - expect(() => process.kill(pid, 0)).toThrow(); + const processState = spawnSync("ps", ["-o", "stat=", "-p", String(pid)], { + encoding: "utf8", + }); + expect(processState.status === 1 || processState.stdout.trim().startsWith("Z")).toBe(true); } finally { try { process.kill(pid, "SIGKILL"); From e5423341d0335922d68595715610f2c7bbcb8394 Mon Sep 17 00:00:00 2001 From: Charan Jagwani Date: Wed, 9 Sep 2026 14:38:49 -0700 Subject: [PATCH 21/23] chore(ci): validate after upstream image repair Signed-off-by: Charan Jagwani From ba0d7e96dd0f07b74f27dce437fb10d0c2f3dafe Mon Sep 17 00:00:00 2001 From: Julie Yaunches Date: Wed, 9 Sep 2026 16:35:21 -0400 Subject: [PATCH 22/23] fix(images): refresh Hermes probe digest Signed-off-by: Julie Yaunches (cherry picked from commit a4030cdff8865ca3b3fa7de0fa54cb966debf942) --- agents/hermes/Dockerfile | 4 ++-- ci/source-shape-test-budget.json | 5 ++++ .../hermes/hermes-image-build-probes.test.ts | 23 +++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/agents/hermes/Dockerfile b/agents/hermes/Dockerfile index 5572513a3d2..7c668174a0f 100644 --- a/agents/hermes/Dockerfile +++ b/agents/hermes/Dockerfile @@ -453,7 +453,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=7c74c3f190845fef222e3aac1bd7074d58968447e78221114344545c149595c2 +ARG NEMOCLAW_HERMES_IMAGE_BUILD_PROBES_SHA256=085fa6866b33295e4efed2a10197d56369d98b25cee1fe0dde7f97e892950cc8 # hadolint ignore=DL3059,DL4006 RUN printf '%s %s\n' \ "$NEMOCLAW_HERMES_IMAGE_BUILD_PROBES_SHA256" /opt/nemoclaw-hermes-config/image-build-probes.py \ @@ -481,7 +481,7 @@ RUN find /opt/nemoclaw-hermes-config -type d -exec chmod 755 {} + \ # 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=7c74c3f190845fef222e3aac1bd7074d58968447e78221114344545c149595c2 +ARG NEMOCLAW_HERMES_IMAGE_BUILD_PROBES_SHA256=085fa6866b33295e4efed2a10197d56369d98b25cee1fe0dde7f97e892950cc8 # hadolint ignore=DL4006 RUN printf '%s %s\n' \ "$NEMOCLAW_HERMES_HINDSIGHT_LAZY_INTEGRITY_PATCH_SHA256" /opt/nemoclaw-hermes-config/hindsight-lazy-integrity.patch \ diff --git a/ci/source-shape-test-budget.json b/ci/source-shape-test-budget.json index b2fa12237d6..4eae5803683 100644 --- a/ci/source-shape-test-budget.json +++ b/ci/source-shape-test-budget.json @@ -211,6 +211,11 @@ "test": "rejects malformed reviewed source package specifications", "category": "security" }, + { + "file": "test/agents/hermes/hermes-image-build-probes.test.ts", + "test": "binds every image build probe pin to its source digest", + "category": "security" + }, { "file": "test/agents/hermes/hermes-image-build-probes.test.ts", "test": "binds the runtime environment validator to its source digest", diff --git a/test/agents/hermes/hermes-image-build-probes.test.ts b/test/agents/hermes/hermes-image-build-probes.test.ts index d008619dafd..7be3c4f43d5 100644 --- a/test/agents/hermes/hermes-image-build-probes.test.ts +++ b/test/agents/hermes/hermes-image-build-probes.test.ts @@ -169,6 +169,29 @@ function runNeutralPlatformProbe(configuration: string) { } describe("Hermes image build probes", () => { + // source-shape-contract: security -- Every executed probe must match the reviewed source digest + it("binds every image build probe pin to its source digest", () => { + const imageDockerfile = fs.readFileSync( + path.join(import.meta.dirname, "../../../agents/hermes/Dockerfile"), + "utf8", + ); + const imageBuildProbes = fs.readFileSync( + path.join(import.meta.dirname, "../../../agents/hermes/image-build-probes.py"), + ); + const digest = createHash("sha256").update(imageBuildProbes).digest("hex"); + const digestBinding = `ARG NEMOCLAW_HERMES_IMAGE_BUILD_PROBES_SHA256=${digest}`; + + expect(imageDockerfile).toContain(digestBinding); + expect( + Array.from( + imageDockerfile.matchAll( + /^ARG NEMOCLAW_HERMES_IMAGE_BUILD_PROBES_SHA256=([0-9a-f]{64})$/gmu, + ), + (match) => match[1], + ), + ).toEqual([digest, digest]); + }); + it("verifies the A2A neutralization patch before root applies it", () => { const digest = createHash("sha256").update(a2aNeutralPatch).digest("hex"); const digestBinding = `ARG NEMOCLAW_HERMES_A2A_NEUTRAL_PATCH_SHA256=${digest}`; From a46d1b1bdff7cab91a3058888c408440ffd77085 Mon Sep 17 00:00:00 2001 From: Charan Jagwani Date: Wed, 9 Sep 2026 15:55:45 -0700 Subject: [PATCH 23/23] test(credentials): verify static form CSP hash Signed-off-by: Charan Jagwani --- test/credentials/local-credential-helper-suite.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/credentials/local-credential-helper-suite.ts b/test/credentials/local-credential-helper-suite.ts index 97db6f87993..38e45aabbb4 100644 --- a/test/credentials/local-credential-helper-suite.ts +++ b/test/credentials/local-credential-helper-suite.ts @@ -528,6 +528,20 @@ export function registerLocalCredentialHelperTests(group: LocalCredentialHelperT expect(csp).toContain("style-src 'sha256-"); }); + it("matches the checked-in form CSP to its inline resources (#11160)", () => { + const formBytes = fs.readFileSync(FORM_PATH); + const formSource = formBytes.toString("utf8"); + const metaCsp = formSource.match( + /http-equiv="Content-Security-Policy"\s+content="([^"]+)"/, + )?.[1]; + const expectedMetaCsp = `${buildCredentialFormCsp(formBytes).replace( + "; frame-ancestors 'none'", + "", + )};`; + + expect(metaCsp).toBe(expectedMetaCsp); + }); + it("drops every ambient entry without mutating the source environment (#5048)", () => { const ambient = { ...CONFIG_ROOT_ENV_OVERRIDES,