From 48a3200fe30b3ac599b8af8d65641d2c84dc2d05 Mon Sep 17 00:00:00 2001 From: San Dang Date: Mon, 10 Aug 2026 18:40:34 +0700 Subject: [PATCH 01/34] ci(e2e): add Colossus-backed Jetson dispatch Signed-off-by: San Dang --- .../SKILL.md | 4 +- .../scripts/release-e2e-evidence.mts | 7 + .../nemoclaw-maintainer-day/MERGE-GATE.md | 2 +- .../skills/nemoclaw-maintainer-e2e/SKILL.md | 29 +- .../scripts/validate-full-e2e-evidence.mts | 5 + .../references/release-train.md | 2 +- .github/workflows/e2e.yaml | 84 ++-- .../verify-openshell-e2e-qualification.mts | 7 + test/e2e/README.md | 19 +- test/e2e/docs/README.md | 6 +- test/e2e/docs/jetson-colossus-dispatch.md | 427 ++++++++++++++++++ .../support/jetson-dispatch-contract.test.ts | 415 +++++++++++++++++ .../support/jetson-dispatch-worker.test.ts | 91 ++++ .../support/jetson-workflow-boundary.test.ts | 63 +-- test/maintainer-e2e-skill.test.ts | 11 +- test/openshell-e2e-qualification.test.ts | 1 + test/release-e2e-evidence.test.ts | 18 +- tools/advisors/risk-plan.mts | 4 +- tools/e2e/cli-artifact-workflow-boundary.mts | 2 +- tools/e2e/jetson-dispatch-client.mts | 247 ++++++++++ tools/e2e/jetson-dispatch-contract.mts | 274 +++++++++++ tools/e2e/jetson-dispatch-lifecycle.mts | 332 ++++++++++++++ tools/e2e/jetson-dispatch-service.mts | 244 ++++++++++ tools/e2e/jetson-dispatch-worker.mts | 386 ++++++++++++++++ tools/e2e/operations-workflow-boundary.mts | 8 +- ...upload-e2e-artifacts-workflow-boundary.mts | 8 + tools/e2e/workflow-boundary.mts | 115 +++-- 27 files changed, 2662 insertions(+), 149 deletions(-) create mode 100644 test/e2e/docs/jetson-colossus-dispatch.md create mode 100644 test/e2e/support/jetson-dispatch-contract.test.ts create mode 100644 test/e2e/support/jetson-dispatch-worker.test.ts create mode 100644 tools/e2e/jetson-dispatch-client.mts create mode 100644 tools/e2e/jetson-dispatch-contract.mts create mode 100644 tools/e2e/jetson-dispatch-lifecycle.mts create mode 100644 tools/e2e/jetson-dispatch-service.mts create mode 100644 tools/e2e/jetson-dispatch-worker.mts diff --git a/.agents/skills/nemoclaw-maintainer-cut-release-tag/SKILL.md b/.agents/skills/nemoclaw-maintainer-cut-release-tag/SKILL.md index 6b54aa5e7ec..b5444dd0285 100644 --- a/.agents/skills/nemoclaw-maintainer-cut-release-tag/SKILL.md +++ b/.agents/skills/nemoclaw-maintainer-cut-release-tag/SKILL.md @@ -136,7 +136,7 @@ npm run release:e2e-evidence -- \ The preflight derives every required execution from one empty-selector dispatch. The full run includes every default-selected workflow E2E plus `Exact staging Brev Launchable`. -Accepted release evidence requires `allow_jetson_runner_queue=false` and `allow_dgx_spark_runner_queue=false`. +Accepted release evidence requires `allow_jetson_dispatch=false` and `allow_dgx_spark_runner_queue=false`. The required denominator excludes `jetson-nvmap-gpu`, `llama-cpp-dgx-spark-plan`, and `llama-cpp-dgx-spark-qualification`. Each job that declares `RELEASE_E2E_ACTIVATION_PATH` requires that path at the candidate SHA. A missing activation path is a preflight failure. @@ -148,7 +148,7 @@ Monitor the dispatched correlation ID with one bounded status query. Before accepting full-mode exact Brev evidence, require: - the workflow `head_sha` to equal the plan candidate SHA; -- the trusted dispatch receipt to prove empty selectors, `include_staging_brev_launchable=true`, `allowJetsonRunnerQueue: false`, and `allowDgxSparkRunnerQueue: false`; +- the trusted dispatch receipt to prove empty selectors, `include_staging_brev_launchable=true`, `allowJetsonDispatch: false`, `allowJetsonRunnerQueue: false`, and `allowDgxSparkRunnerQueue: false`; - the workflow conclusion to be `success`; - the `Exact staging Brev Launchable` job conclusion to be `success`; - the job URL and selected successful Launchable job attempt; diff --git a/.agents/skills/nemoclaw-maintainer-cut-release-tag/scripts/release-e2e-evidence.mts b/.agents/skills/nemoclaw-maintainer-cut-release-tag/scripts/release-e2e-evidence.mts index 5c3f9dd07d9..590885f907b 100644 --- a/.agents/skills/nemoclaw-maintainer-cut-release-tag/scripts/release-e2e-evidence.mts +++ b/.agents/skills/nemoclaw-maintainer-cut-release-tag/scripts/release-e2e-evidence.mts @@ -484,6 +484,13 @@ export function buildReleaseE2eLedger( false, `${label}.dispatch.allowJetsonRunnerQueue`, ); + if (dispatch.kind === "nemoclaw-e2e-dispatch-v2") { + requireEqual( + booleanField(dispatch, "allowJetsonDispatch", `${label}.dispatch`), + false, + `${label}.dispatch.allowJetsonDispatch`, + ); + } requireEqual( booleanField(dispatch, "allowDgxSparkRunnerQueue", `${label}.dispatch`), false, diff --git a/.agents/skills/nemoclaw-maintainer-day/MERGE-GATE.md b/.agents/skills/nemoclaw-maintainer-day/MERGE-GATE.md index a7227e17e13..6bac644d45d 100644 --- a/.agents/skills/nemoclaw-maintainer-day/MERGE-GATE.md +++ b/.agents/skills/nemoclaw-maintainer-day/MERGE-GATE.md @@ -85,7 +85,7 @@ After a failure, inspect the artifacts and remove resources that target cleanup Dispatch the trusted `main` workflow with the current PR number, lowercase 40-character head SHA, head repository, lowercase 40-character base SHA, trusted workflow SHA, and a review reason containing 10 to 500 printable characters. Leave job and target selectors empty and keep Launchable disabled. -Keep `allow_jetson_runner_queue=false` and `allow_dgx_spark_runner_queue=false` for the default PR revision selection. +Keep `allow_jetson_dispatch=false` and `allow_dgx_spark_runner_queue=false` for the default PR revision selection. If the DGX Spark flag is `true`, GitHub can pause `llama-cpp-dgx-spark-qualification` for the `approve-dgx-spark-image-qualification` environment. An authorized environment reviewer must approve it before qualification starts. The trusted pre-checkout step requires current `maintain` or `admin` access and validates the exact open PR before candidate code runs. diff --git a/.agents/skills/nemoclaw-maintainer-e2e/SKILL.md b/.agents/skills/nemoclaw-maintainer-e2e/SKILL.md index 2cdc2155007..8bc5fecbfe6 100644 --- a/.agents/skills/nemoclaw-maintainer-e2e/SKILL.md +++ b/.agents/skills/nemoclaw-maintainer-e2e/SKILL.md @@ -67,7 +67,8 @@ Choose exactly one mode: - every default-selected free-standing workflow E2E except `Exact staging Brev Launchable`; - every shared credential-free test; and - these controller-selected registry targets: `ubuntu-policy-custom-missing-presets-negative`, `ubuntu-repo-cloud-langchain-deepagents-code`, `ubuntu-repo-cloud-openclaw`, and `ubuntu-repo-docker-post-reboot-recovery`. - The run skips `jetson-nvmap-gpu`, `llama-cpp-dgx-spark-plan`, and `llama-cpp-dgx-spark-qualification` unless their separate runner-queue flags are `true`. + The run skips `jetson-nvmap-gpu` unless its Colossus dispatch flag is `true`. + It skips `llama-cpp-dgx-spark-plan` and `llama-cpp-dgx-spark-qualification` unless their runner-queue flag is `true`. - For protected managed-image runtime qualification, set `E2E_JOBS=managed-image-protected-runtime`. The exact candidate must contain `ci/protected-managed-image-multiarch-activation-v1.json` and `ci/protected-managed-image-runtime-activation-v1.json`. Leave `targets` empty and keep Launchable disabled: @@ -81,7 +82,7 @@ esac REVIEW_REASON='Reviewed the PR head commit for credentialed E2E.' CORRELATION_ID="$(python3 -c 'import uuid; print(uuid.uuid4())')" INFERENCE_MODE=mock -ALLOW_JETSON_RUNNER_QUEUE=false +ALLOW_JETSON_DISPATCH=false ALLOW_DGX_SPARK_RUNNER_QUEUE=false gh workflow run .github/workflows/e2e.yaml \ --repo NVIDIA/NemoClaw \ @@ -90,7 +91,7 @@ gh workflow run .github/workflows/e2e.yaml \ -f "jobs=${E2E_JOBS}" \ -f "inference_mode=${INFERENCE_MODE}" \ -f include_staging_brev_launchable=false \ - -f "allow_jetson_runner_queue=${ALLOW_JETSON_RUNNER_QUEUE}" \ + -f "allow_jetson_dispatch=${ALLOW_JETSON_DISPATCH}" \ -f "allow_dgx_spark_runner_queue=${ALLOW_DGX_SPARK_RUNNER_QUEUE}" \ -f "pr_number=${PR_NUMBER}" \ -f "checkout_sha=${HEAD_SHA}" \ @@ -162,7 +163,7 @@ Ask for clarification only when the request contains conflicting mode phrases. Ordinary mode selects every default-selected workflow E2E except `Exact staging Brev Launchable`. Launchable mode runs only `Exact staging Brev Launchable`. Full mode adds `Exact staging Brev Launchable` to the default E2E selection in the same workflow run. -The documented invocations for all three modes keep both hardware runner-queue flags set to `false`. +The documented invocations for all three modes keep the Jetson dispatch and DGX Spark runner-queue flags set to `false`. ## Resolve the Candidate @@ -199,7 +200,7 @@ gh workflow run .github/workflows/e2e.yaml \ -f jobs= \ -f inference_mode=mock \ -f include_staging_brev_launchable=false \ - -f allow_jetson_runner_queue=false \ + -f allow_jetson_dispatch=false \ -f allow_dgx_spark_runner_queue=false \ -f "correlation_id=${CORRELATION_ID}" ``` @@ -214,7 +215,7 @@ gh workflow run .github/workflows/e2e.yaml \ -f jobs=staging-brev-launchable \ -f inference_mode=mock \ -f include_staging_brev_launchable=false \ - -f allow_jetson_runner_queue=false \ + -f allow_jetson_dispatch=false \ -f allow_dgx_spark_runner_queue=false \ -f "correlation_id=${CORRELATION_ID}" ``` @@ -229,7 +230,7 @@ gh workflow run .github/workflows/e2e.yaml \ -f jobs= \ -f inference_mode=mock \ -f include_staging_brev_launchable=true \ - -f allow_jetson_runner_queue=false \ + -f allow_jetson_dispatch=false \ -f allow_dgx_spark_runner_queue=false \ -f "correlation_id=${CORRELATION_ID}" ``` @@ -240,11 +241,11 @@ The `include_staging_brev_launchable` input adds the Launchable E2E job to that The trusted `main` workflow verifies that the dispatching and rerunning actors have repository `maintain` or `admin` permission before the Launchable path's source checkout. That role check is the authorization. -A user permitted to dispatch this workflow may set -`allow_jetson_runner_queue=true` to add `jetson-nvmap-gpu` to an empty-selector -manual run or enable its explicit selection. Set it only after a repository -administrator confirms an online Jetson runner in the authoritative runner -inventory. +A user permitted to dispatch this workflow may set `allow_jetson_dispatch=true` +to add `jetson-nvmap-gpu` to an empty-selector manual run or enable its explicit +selection. Set it only after every deployment check in +[Jetson Dispatch Through Colossus](../../../test/e2e/docs/jetson-colossus-dispatch.md) +passes. A permitted dispatcher may set `allow_dgx_spark_runner_queue=true` to add `llama-cpp-dgx-spark-plan` and `llama-cpp-dgx-spark-qualification` to an empty-selector manual run or enable explicit qualification selection. Set it @@ -349,7 +350,7 @@ node --experimental-strip-types --no-warnings \ The validator requires: - the workflow run to succeed for the selected SHA; -- `dispatch.json` to bind the same run, empty selectors, `include_staging_brev_launchable=true`, `allowJetsonRunnerQueue: false`, `allowDgxSparkRunnerQueue: false`, and the selected successful Launchable job attempt; +- `dispatch.json` to bind the same run, empty selectors, `include_staging_brev_launchable=true`, `allowJetsonDispatch: false`, `allowJetsonRunnerQueue: false`, `allowDgxSparkRunnerQueue: false`, and the selected successful Launchable job attempt; - `Exact staging Brev Launchable` to conclude `success` in the selected current or earlier attempt of the same workflow run; - `launchable-e2e.json` to identify the selected SHA in the repository and provision records; - the booted repository to be unmodified; @@ -376,7 +377,7 @@ If the release candidate SHA changes, discard the earlier full run and dispatch No release-note-only delta exception is currently defined. When `nemoclaw-maintainer-cut-release-tag` invokes this skill, return the validated fields for its pre-tag E2E evidence ledger. -The trusted `dispatch.json` receipt proves that full mode used empty selectors, included `Exact staging Brev Launchable`, and disabled both optional hardware paths. +The trusted `dispatch.json` receipt proves that full mode used empty selectors, included `Exact staging Brev Launchable`, and disabled the optional Jetson dispatch and DGX Spark runner paths. The release evidence ledger proves the result of each workflow E2E. Do not ask for the release confirmation phrase in this skill. diff --git a/.agents/skills/nemoclaw-maintainer-e2e/scripts/validate-full-e2e-evidence.mts b/.agents/skills/nemoclaw-maintainer-e2e/scripts/validate-full-e2e-evidence.mts index 1bb2a540b1d..f38b36ae847 100644 --- a/.agents/skills/nemoclaw-maintainer-e2e/scripts/validate-full-e2e-evidence.mts +++ b/.agents/skills/nemoclaw-maintainer-e2e/scripts/validate-full-e2e-evidence.mts @@ -30,6 +30,7 @@ export interface FullE2eEvidenceSummary { }; dispatch: { allowDgxSparkRunnerQueue: false; + allowJetsonDispatch: false; allowJetsonRunnerQueue: false; emptySelectors: true; includeStagingBrevLaunchable: true; @@ -166,6 +167,9 @@ export function validateFullE2eEvidence(input: FullE2eEvidenceInput): FullE2eEvi "dispatch.includeStagingBrevLaunchable", ); requireEqual(dispatch.allowJetsonRunnerQueue, false, "dispatch.allowJetsonRunnerQueue"); + if (dispatch.kind === "nemoclaw-e2e-dispatch-v2" || Object.hasOwn(dispatch, "allowJetsonDispatch")) { + requireEqual(dispatch.allowJetsonDispatch, false, "dispatch.allowJetsonDispatch"); + } requireEqual(dispatch.allowDgxSparkRunnerQueue, false, "dispatch.allowDgxSparkRunnerQueue"); requireEqual(dispatch.emptySelectors, true, "dispatch.emptySelectors"); @@ -233,6 +237,7 @@ export function validateFullE2eEvidence(input: FullE2eEvidenceInput): FullE2eEvi }, dispatch: { allowDgxSparkRunnerQueue: false, + allowJetsonDispatch: false, allowJetsonRunnerQueue: false, emptySelectors: true, includeStagingBrevLaunchable: true, diff --git a/.agents/skills/nemoclaw-maintainer-policies/references/release-train.md b/.agents/skills/nemoclaw-maintainer-policies/references/release-train.md index 36f05b574cf..152d98abe3a 100644 --- a/.agents/skills/nemoclaw-maintainer-policies/references/release-train.md +++ b/.agents/skills/nemoclaw-maintainer-policies/references/release-train.md @@ -57,7 +57,7 @@ Before asking for the release confirmation phrase, build and show an evidence le - Require the workflow-produced trusted dispatch receipt to bind the accepted run candidate SHA, run ID, attempt, and selector inputs. - Run `nemoclaw-maintainer-e2e` in full mode when the ledger lacks complete evidence for the candidate SHA. - Require one completed, successful full workflow run for all default-selected workflow E2E jobs and the full-mode additions, including `Exact staging Brev Launchable`. -- Require the trusted dispatch receipt to record `allowJetsonRunnerQueue: false` and `allowDgxSparkRunnerQueue: false`. +- Require the trusted dispatch receipt to record `allowJetsonDispatch: false`, `allowJetsonRunnerQueue: false`, and `allowDgxSparkRunnerQueue: false`. - Exclude `jetson-nvmap-gpu`, `llama-cpp-dgx-spark-plan`, and `llama-cpp-dgx-spark-qualification` from the required denominator. - Require the trusted dispatch receipt to bind the workflow run and an attempt no later than the run's latest attempt. The receipt must record empty selectors and `include_staging_brev_launchable=true`. - Require the Launchable E2E receipt to identify the candidate SHA in the repository and provision records. diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index 64b9cf05d45..b109d82358c 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -15,7 +15,7 @@ on: default: "" type: string jobs: - description: "Optional comma-separated E2E test IDs. Empty selectors choose the default suite. Set include_staging_brev_launchable for Launchable. Jetson and DGX Spark require their queue flags. PR revisions use the trusted controller matrix." + description: "Optional comma-separated E2E test IDs. Empty selectors choose the default suite. Set include_staging_brev_launchable for Launchable. Jetson dispatch and DGX Spark require their opt-in flags. PR revisions use the trusted controller matrix." required: false default: "" type: string @@ -33,8 +33,8 @@ on: - mock - internal-nvidia - public-nvidia - allow_jetson_runner_queue: - description: "Before setting true for jetson-nvmap-gpu, obtain repository administrator confirmation of an online Jetson runner in the authoritative NVIDIA/NemoClaw Settings -> Actions -> Runners inventory; queued jobs do not honor timeout-minutes before assignment." + allow_jetson_dispatch: + description: "Set true for jetson-nvmap-gpu only after the Colossus dispatcher, Cloudflare Tunnel, reset helper, and JETSON_DISPATCH_URL repository variable have passed the deployment checks in test/e2e/docs/jetson-colossus-dispatch.md." required: false default: false type: boolean @@ -304,7 +304,8 @@ jobs: if: ${{ github.event_name == 'workflow_dispatch' }} env: ALLOW_DGX_SPARK_RUNNER_QUEUE: ${{ inputs.allow_dgx_spark_runner_queue && 'true' || 'false' }} - ALLOW_JETSON_RUNNER_QUEUE: ${{ inputs.allow_jetson_runner_queue && 'true' || 'false' }} + ALLOW_JETSON_DISPATCH: ${{ inputs.allow_jetson_dispatch && 'true' || 'false' }} + ALLOW_JETSON_RUNNER_QUEUE: "false" BASE_SHA: ${{ inputs.checkout_sha != '' && inputs.base_sha || github.sha }} CANDIDATE_REPOSITORY: ${{ inputs.checkout_repository || github.repository }} CANDIDATE_SHA: ${{ inputs.checkout_sha || github.sha }} @@ -334,6 +335,7 @@ jobs: --arg workflowRunId "$RUN_ID" \ --arg workflowSha "$WORKFLOW_SHA" \ --argjson allowDgxSparkRunnerQueue "$ALLOW_DGX_SPARK_RUNNER_QUEUE" \ + --argjson allowJetsonDispatch "$ALLOW_JETSON_DISPATCH" \ --argjson allowJetsonRunnerQueue "$ALLOW_JETSON_RUNNER_QUEUE" \ --argjson includeStagingBrevLaunchable "$INCLUDE_STAGING_BREV_LAUNCHABLE" \ --argjson workflowRunAttempt "$RUN_ATTEMPT" \ @@ -351,6 +353,7 @@ jobs: jobs: $jobs, targets: $targets, allowDgxSparkRunnerQueue: $allowDgxSparkRunnerQueue, + allowJetsonDispatch: $allowJetsonDispatch, allowJetsonRunnerQueue: $allowJetsonRunnerQueue, includeStagingBrevLaunchable: $includeStagingBrevLaunchable, emptySelectors: ($jobs == "" and $targets == "") @@ -4918,70 +4921,39 @@ jobs: jetson-nvmap-gpu: needs: generate-matrix - # The opt-in flag prevents assignment to an unavailable Jetson runner. - if: ${{ inputs.allow_jetson_runner_queue && github.repository == 'NVIDIA/NemoClaw' && github.ref == 'refs/heads/main' && ((github.event_name != 'workflow_dispatch' || (inputs.jobs == '' && inputs.targets == '')) || contains(format(',{0},', inputs.jobs), ',jetson-nvmap-gpu,') || contains(format(',{0},', inputs.targets), ',jetson-nvmap-gpu,')) }} - runs-on: ${{ vars.JETSON_E2E_RUNNER_LABEL || 'linux-arm64-gpu-jetson-orin-latest-1' }} + if: ${{ inputs.allow_jetson_dispatch && github.repository == 'NVIDIA/NemoClaw' && github.ref == 'refs/heads/main' && github.event_name == 'workflow_dispatch' && (inputs.checkout_repository == '' || inputs.checkout_repository == github.repository) && ((inputs.jobs == '' && inputs.targets == '') || contains(format(',{0},', inputs.jobs), ',jetson-nvmap-gpu,') || contains(format(',{0},', inputs.targets), ',jetson-nvmap-gpu,')) }} + runs-on: ubuntu-latest timeout-minutes: 60 + permissions: + contents: read + id-token: write env: - E2E_JOB: "1" - E2E_TARGET_ID: "jetson-nvmap-gpu" - E2E_ARTIFACT_DIR: ${{ github.workspace }}/e2e-artifacts/live/jetson-nvmap-gpu - NEMOCLAW_CLI_BIN: ${{ github.workspace }}/bin/nemoclaw.js - NEMOCLAW_RUN_LIVE_E2E: "1" - NEMOCLAW_NON_INTERACTIVE: "1" - NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE: "1" - NEMOCLAW_SANDBOX_NAME: "e2e-jetson-nvmap" - NEMOCLAW_RECREATE_SANDBOX: "1" - NEMOCLAW_PROVIDER: "ollama" - OPENSHELL_GATEWAY: "nemoclaw" + E2E_ARTIFACT_DIR: ${{ runner.temp }}/e2e-artifacts/live/jetson-nvmap-gpu steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - name: Check out trusted Jetson controller + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: - repository: ${{ inputs.checkout_repository || github.repository }} - ref: ${{ inputs.checkout_sha || github.sha }} + repository: NVIDIA/NemoClaw + ref: ${{ github.workflow_sha }} persist-credentials: false - - *dockerhub-auth - - - name: Prepare E2E workspace - uses: NVIDIA/NemoClaw/.github/actions/prepare-e2e@f6304bc25fc35bfaa441c8c2fbfee38f72805a75 - with: - build-cli: "false" - - - name: Restore exact-commit CLI artifact - uses: NVIDIA/NemoClaw/.github/actions/restore-e2e-cli-artifact@c246409193a31133cab10c8a3589001cc0d59eb3 + - name: Set up Node for Jetson controller + uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 with: - provenance-json: ${{ needs.generate-matrix.outputs.cli_artifact_provenance }} - - - name: Verify Jetson GPU availability - run: | - set -euo pipefail - echo "=== Tegra release ===" - cat /etc/nv_tegra_release 2>/dev/null || echo "(no /etc/nv_tegra_release)" - echo "" - echo "=== /dev/nvmap ===" - ls -l /dev/nvmap 2>/dev/null || echo "(no /dev/nvmap)" - echo "" - echo "=== Docker ===" - docker info --format '{{.ServerVersion}}' - docker info --format '{{json .Runtimes}}' + node-version: 22 - - name: Run Jetson nvmap GPU live Vitest test - # Keeps the - # Jetson/Tegra host, NVIDIA Docker runtime, install.sh, OpenShell - # sandbox exec, /dev/nvmap, CUDA cuInit(0), and status-proof boundary. - run: | - set -euo pipefail - npx tsx tools/e2e/live-vitest-invocation.mts run --test-path test/e2e/live/jetson-nvmap-gpu.test.ts + - name: Dispatch exact commit to Jetson through Colossus + env: + JETSON_DISPATCH_CANDIDATE_SHA: ${{ inputs.checkout_sha || github.sha }} + JETSON_DISPATCH_URL: ${{ vars.JETSON_DISPATCH_URL }} + run: node --experimental-strip-types --no-warnings tools/e2e/jetson-dispatch-client.mts - name: Upload Jetson nvmap GPU artifacts if: always() uses: NVIDIA/NemoClaw/.github/actions/upload-e2e-artifacts@7768e15eb90d3ee2d33432f481dfe8747e4f6d57 - - - name: Clean up Docker auth - if: always() - shell: bash - run: bash .github/scripts/docker-auth-cleanup.sh + with: + name: e2e-jetson-nvmap-gpu + path: ${{ runner.temp }}/e2e-artifacts/live/jetson-nvmap-gpu/ concurrent-gateway-ports: needs: generate-matrix diff --git a/scripts/checks/verify-openshell-e2e-qualification.mts b/scripts/checks/verify-openshell-e2e-qualification.mts index dacf1bf4150..742def53fa1 100644 --- a/scripts/checks/verify-openshell-e2e-qualification.mts +++ b/scripts/checks/verify-openshell-e2e-qualification.mts @@ -179,6 +179,7 @@ export type PullRequestIdentity = { export type E2EDispatchReceipt = { allowDgxSparkRunnerQueue: boolean; + allowJetsonDispatch: boolean; allowJetsonRunnerQueue: boolean; baseSha: string; candidateRepository: string; @@ -199,6 +200,7 @@ export type E2EDispatchReceipt = { type E2EDispatchReceiptEnvelope = Omit< E2EDispatchReceipt, | "allowDgxSparkRunnerQueue" + | "allowJetsonDispatch" | "allowJetsonRunnerQueue" | "emptySelectors" | "includeStagingBrevLaunchable" @@ -206,6 +208,7 @@ type E2EDispatchReceiptEnvelope = Omit< | "targets" > & { allowDgxSparkRunnerQueue: boolean; + allowJetsonDispatch: boolean; allowJetsonRunnerQueue: boolean; emptySelectors: boolean; includeStagingBrevLaunchable: boolean; @@ -728,6 +731,7 @@ export function validateDispatchReceipt( receipt.targets !== "" || receipt.emptySelectors !== true || receipt.allowDgxSparkRunnerQueue !== false || + receipt.allowJetsonDispatch !== false || receipt.allowJetsonRunnerQueue !== false || receipt.includeStagingBrevLaunchable !== false ) { @@ -745,6 +749,7 @@ function validateDispatchReceiptEnvelope( value, [ "allowDgxSparkRunnerQueue", + "allowJetsonDispatch", "allowJetsonRunnerQueue", "baseSha", "candidateRepository", @@ -780,6 +785,7 @@ function validateDispatchReceiptEnvelope( typeof value.emptySelectors !== "boolean" || value.emptySelectors !== (value.jobs === "" && value.targets === "") || typeof value.allowDgxSparkRunnerQueue !== "boolean" || + typeof value.allowJetsonDispatch !== "boolean" || typeof value.allowJetsonRunnerQueue !== "boolean" || typeof value.includeStagingBrevLaunchable !== "boolean" ) { @@ -987,6 +993,7 @@ async function selectQualifiedRun(options: { receipt.targets !== "" || !receipt.emptySelectors || receipt.allowDgxSparkRunnerQueue || + receipt.allowJetsonDispatch || receipt.allowJetsonRunnerQueue || receipt.includeStagingBrevLaunchable ) { diff --git a/test/e2e/README.md b/test/e2e/README.md index c1d8b40b352..564ecc4ddf2 100644 --- a/test/e2e/README.md +++ b/test/e2e/README.md @@ -455,17 +455,16 @@ environment approval. The job uses the non-cancelling runs remain queued instead of replacing one another. The Jetson nvmap and DGX Spark llama.cpp jobs remain excluded from ordinary and -full runs unless their independent runner-queue flags are `true`. -A user permitted to dispatch this workflow may set either flag, but only after -a repository administrator confirms the corresponding runner is online in the -authoritative repository runner inventory. -Set `allow_jetson_runner_queue=true` to select `jetson-nvmap-gpu`. +full runs unless their independent opt-in flags are `true`. +Set `allow_jetson_dispatch=true` to select `jetson-nvmap-gpu` only after every +deployment check in +[Jetson Dispatch Through Colossus](docs/jetson-colossus-dispatch.md) passes. Set `allow_dgx_spark_runner_queue=true` to select both `llama-cpp-dgx-spark-plan` and `llama-cpp-dgx-spark-qualification`. GitHub can pause the qualification job for the `approve-dgx-spark-image-qualification` environment before it reaches the DGX Spark runner. -Pre-tag evidence requires both runner-queue flags to remain `false`. +Pre-tag evidence requires both hardware opt-in flags to remain `false`. Results from opt-in hardware runs do not enter the required pre-tag E2E denominator. @@ -796,9 +795,9 @@ For a PR revision run, a repository maintainer or administrator leaves `jobs` an - every shared credential-free test; and - these controller-selected registry targets: `ubuntu-policy-custom-missing-presets-negative`, `ubuntu-repo-cloud-langchain-deepagents-code`, `ubuntu-repo-cloud-openclaw`, and `ubuntu-repo-docker-post-reboot-recovery`. -The run skips `jetson-nvmap-gpu`, `llama-cpp-dgx-spark-plan`, and -`llama-cpp-dgx-spark-qualification` unless their separate runner-queue flags -are `true`. +The run skips `jetson-nvmap-gpu` unless its Colossus dispatch flag is `true`. +It skips `llama-cpp-dgx-spark-plan` and `llama-cpp-dgx-spark-qualification` +unless their runner-queue flag is `true`. The trusted workflow definition remains on `main` and binds the candidate head to the current PR base SHA. It does not run GitHub's synthetic merge commit. @@ -827,7 +826,7 @@ For `managed-image-protected-runtime`, the workflow supplies the long-lived `NVI For a manual PR run, provide the current PR number, lowercase 40-character head SHA, head repository, lowercase 40-character base SHA, trusted `main` workflow SHA, and a review reason containing 10 to 500 printable characters. Leave `jobs` and `targets` empty and keep `include_staging_brev_launchable=false` to use this PR revision selection. -Keep `allow_jetson_runner_queue=false` and `allow_dgx_spark_runner_queue=false` for the default PR revision selection. +Keep `allow_jetson_dispatch=false` and `allow_dgx_spark_runner_queue=false` for the default PR revision selection. If `allow_dgx_spark_runner_queue=true`, GitHub can pause the qualification job for the `approve-dgx-spark-image-qualification` environment. An authorized environment reviewer must approve it before qualification starts. To select the protected managed-image runtime qualification, set `jobs=managed-image-protected-runtime`. diff --git a/test/e2e/docs/README.md b/test/e2e/docs/README.md index 3c573288b7f..cda0bb2e469 100644 --- a/test/e2e/docs/README.md +++ b/test/e2e/docs/README.md @@ -306,7 +306,7 @@ test/e2e/ `ubuntu-policy-custom-missing-presets-negative`, `ubuntu-repo-cloud-langchain-deepagents-code`, `ubuntu-repo-cloud-openclaw`, and `ubuntu-repo-docker-post-reboot-recovery`. Keep - `allow_jetson_runner_queue=false` and `allow_dgx_spark_runner_queue=false` for + `allow_jetson_dispatch=false` and `allow_dgx_spark_runner_queue=false` for this default selection. If the DGX Spark flag is `true`, GitHub can pause the qualification job for the `approve-dgx-spark-image-qualification` environment. An authorized environment reviewer must approve it before qualification starts. @@ -314,6 +314,10 @@ test/e2e/ `jobs` value is `managed-image-protected-runtime`; `targets` must remain empty. Refer to [NemoClaw E2E CI](../README.md). +- [Jetson Dispatch Through Colossus](jetson-colossus-dispatch.md) defines how + maintainers deploy and verify the temporary authenticated controller, + dispatcher, SSH, reset, and recovery path for `jetson-nvmap-gpu`. + - `.github/workflows/e2e.yaml` runs selected or all supported live E2E targets and uploads an explicit artifact allowlist with JSON summaries plus action, log, and shell command-evidence directories under diff --git a/test/e2e/docs/jetson-colossus-dispatch.md b/test/e2e/docs/jetson-colossus-dispatch.md new file mode 100644 index 00000000000..28305a95933 --- /dev/null +++ b/test/e2e/docs/jetson-colossus-dispatch.md @@ -0,0 +1,427 @@ + + + +# Jetson Dispatch Through Colossus + +This temporary path runs the `jetson-nvmap-gpu` end-to-end (E2E) job on one Jetson behind a Colossus host. +GitHub Actions controls the job through an authenticated HTTPS endpoint. +Colossus retains the Cloudflare Tunnel credential, Jetson SSH key, SSH host key, device lock, and reset capability. +Candidate code runs only on the Jetson. + +Do not set `allow_jetson_dispatch=true` until every deployment check on this page passes. + +## Trust Boundary + +The deployment has these input and credential boundaries: + +| System | Receives | Must not receive | +| --- | --- | --- | +| GitHub-hosted controller | Candidate commit SHA, workflow run identity, public dispatch URL, and short-lived GitHub OpenID Connect (OIDC) token | Jetson SSH key, tunnel credential, and reset privilege | +| Colossus dispatcher | Validated workflow identity, fixed target, and candidate commit SHA | Request-controlled command, SSH host, repository, path, or reset command | +| Jetson | Candidate checkout and the fixed live E2E command | GitHub OIDC token, tunnel credential, and Colossus SSH private key | + +The dispatcher accepts only `NVIDIA/NemoClaw` and the trusted `main` E2E workflow. +It requires a GitHub-hosted controller, one repository ID, one workflow run identity, and the `jetson-nvmap-gpu` target. +It also requires a lowercase 40-character candidate commit SHA. +The temporary path rejects fork repositories. + +The credentials have these lifecycles: + +| Credential | Location and access | Lifetime and removal | +| --- | --- | --- | +| GitHub OIDC token | GitHub-hosted controller process memory and the authenticated request | The client requests a new token for each request. It does not write the token to disk. | +| Cloudflare account certificate | The administrator account that runs `cloudflared tunnel login` | Remove `cert.pem` from Colossus after tunnel creation and DNS routing. Reauthenticate before later management changes. | +| Cloudflare Tunnel credential | `/etc/cloudflared/TUNNEL_UUID.json`, readable only by the tunnel service account | Keep it for this temporary deployment. Revoke the tunnel and remove the file when the deployment ends. | +| Jetson SSH private key | `/var/lib/nemoclaw-jetson-dispatch/id_ed25519`, readable only by the dispatcher service account | Keep it for this temporary deployment. Remove the matching Jetson public key and private key when the deployment ends. | + +The dispatcher rejects an OIDC token whose issued-to-expiry window exceeds 15 minutes. +The GitHub repository variable contains only the public dispatch URL. +Do not put a credential in `JETSON_DISPATCH_URL`. + +## Prepare a Known Jetson Baseline + +Use a dedicated Jetson without production data or credentials. +The E2E job gives candidate code Docker access, which can control the dedicated host. +The reset procedure must restore a known image after every result. + +Run these checks as the `nvidia` account that the dispatcher uses: + +```bash +uname -m +tr -d '\0' /dev/null; then echo 'unexpected passwordless sudo'; exit 1; fi +``` + +The architecture must be `aarch64`, and Node.js must have major version 22. +Docker must expose the NVIDIA runtime required by the existing Jetson live E2E test. +Preinstall Ollama so candidate code does not invoke its host installer. +The `nvidia` account must not have passwordless `sudo` access. + +Define a reset procedure that restores the verified baseline. +A reboot alone does not reset candidate changes. +Candidate code can change the `nvidia` home directory, SSH configuration, packages, processes, and Docker state. + +The reset procedure must verify these conditions before it returns success: + +- The expected Jetson model, Jetson Linux release, kernel, and storage layout are present. +- SSH is reachable with the dispatcher's restricted key and pinned host key. +- `/var/tmp/nemoclaw-jetson-e2e` is absent. +- The `e2e-jetson-nvmap` sandbox, `nemoclaw` gateway, and test containers are absent. +- `/dev/nvmap` and the NVIDIA Docker runtime are available. +- No candidate-created process remains. + +Use a known-image reflash, immutable-root rollback, or equivalent reprovisioning procedure. +Do not treat `boardctl reset` or another power cycle as baseline restoration. +A reviewed Thor flash process can use `boardctl` only as one step in known-image restoration. +The reset attestation must not rely only on commands that run through the candidate-controlled Jetson account. +If a known-image restore and independent attestation cannot be automated, stop the deployment. + +## Create the Colossus Dispatcher Account + +Run these commands on Colossus. +Replace the checkout path if the host uses a managed deployment location. +The dispatcher requires `/usr/bin/node` 22.19.0 or later. + +```bash +/usr/bin/node --version +/usr/bin/node -e ' + const [major, minor] = process.versions.node.split(".").map(Number); + if (major < 22 || (major === 22 && minor < 19)) process.exit(1); +' +sudo useradd --system --create-home \ + --home-dir /var/lib/nemoclaw-jetson-dispatch \ + --shell /usr/sbin/nologin nemoclaw-jetson-dispatch +sudo install -d -o nemoclaw-jetson-dispatch -g nemoclaw-jetson-dispatch -m 0700 \ + /var/lib/nemoclaw-jetson-dispatch /etc/nemoclaw-jetson-dispatch +sudo git clone --branch main --single-branch https://github.com/NVIDIA/NemoClaw.git \ + /opt/nemoclaw-jetson-dispatch +git -C /opt/nemoclaw-jetson-dispatch rev-parse HEAD +``` + +Deploy a reviewed commit and record its commit SHA. +Do not automatically update this checkout. +The service runs controller and dispatcher files from this trusted commit. +It never checks candidate code out on Colossus. + +Create a dedicated SSH key owned by the service account: + +```bash +sudo -u nemoclaw-jetson-dispatch ssh-keygen -t ed25519 -N '' \ + -f /var/lib/nemoclaw-jetson-dispatch/id_ed25519 +``` + +Add the public key to the Jetson `nvidia` account. +Restrict it to the Colossus source IP address and disable SSH session features that the worker does not use. +For the default USB link, the entry has this shape: + +```text +from="192.168.55.100",restrict ssh-ed25519 AAAA... +``` + +Capture the Jetson host key and verify its fingerprint through the serial console or another trusted channel: + +```bash +ssh-keyscan -H 192.168.55.1 >/tmp/jetson_known_hosts +ssh-keygen -lf /tmp/jetson_known_hosts +sudo install -o nemoclaw-jetson-dispatch -g nemoclaw-jetson-dispatch -m 0600 \ + /tmp/jetson_known_hosts /var/lib/nemoclaw-jetson-dispatch/known_hosts +rm /tmp/jetson_known_hosts +``` + +The known image must preserve the verified SSH host identity. +Do not accept a changed host key without reconciling it through the serial console or another trusted channel. + +Install the reset program at an absolute path such as `/usr/local/libexec/nemoclaw-jetson-reset`. +It must accept no arguments and must not be group- or world-writable. +It must perform and attest the baseline restoration defined above. +It must not remove `/var/lib/nemoclaw-jetson-dispatch/state/device.lock`. +The dispatcher removes that lock only after the reset program exits with status zero. + +Run the reset program as `nemoclaw-jetson-dispatch` when host permissions allow it. +Use device rules to grant access to the exact USB devices that the reset program needs. +If restoration requires root, use a reviewed privilege-separated service whose unprivileged, +root-owned client accepts no arguments and returns only after restoration and attestation finish. +The dispatcher service unit below prevents privilege elevation, so a reset client that invokes +`sudo` or relies on a set-user-ID executable is incompatible with this deployment. +Do not remove that protection or grant the dispatcher account passwordless `sudo` access. + +Test the SSH and reset paths as the service account: + +> Warning: The reset test replaces Jetson state with the known baseline. +> Remove any data that the deployment must retain before this test. + +```bash +sudo -u nemoclaw-jetson-dispatch ssh -F /dev/null -o BatchMode=yes \ + -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes \ + -o UserKnownHostsFile=/var/lib/nemoclaw-jetson-dispatch/known_hosts \ + -i /var/lib/nemoclaw-jetson-dispatch/id_ed25519 \ + nvidia@192.168.55.1 'uname -m' +sudo -u nemoclaw-jetson-dispatch /usr/local/libexec/nemoclaw-jetson-reset +``` + +## Configure the Dispatcher Service + +Get the immutable GitHub repository ID: + +```bash +gh api repos/NVIDIA/NemoClaw --jq .id +``` + +Create `/etc/nemoclaw-jetson-dispatch/environment` as a root-owned file with mode `0600`. +Substitute the repository ID returned above: + +```text +JETSON_DISPATCH_STATE_DIRECTORY=/var/lib/nemoclaw-jetson-dispatch/state +JETSON_DISPATCH_GITHUB_REPOSITORY_ID=REPOSITORY_ID +JETSON_DISPATCH_PORT=8787 +JETSON_DISPATCH_EXECUTION_TIMEOUT_SECONDS=3000 +JETSON_DISPATCH_RESET_TIMEOUT_SECONDS=300 +JETSON_DISPATCH_TEST_TIMEOUT_SECONDS=2700 +JETSON_DISPATCH_SSH_DESTINATION=nvidia@192.168.55.1 +JETSON_DISPATCH_SSH_IDENTITY_FILE=/var/lib/nemoclaw-jetson-dispatch/id_ed25519 +JETSON_DISPATCH_SSH_KNOWN_HOSTS_FILE=/var/lib/nemoclaw-jetson-dispatch/known_hosts +JETSON_DISPATCH_RESET_EXECUTABLE=/usr/local/libexec/nemoclaw-jetson-reset +``` + +Install `/etc/systemd/system/nemoclaw-jetson-dispatch.service`: + +```ini +[Unit] +Description=NemoClaw Jetson dispatcher +After=network-online.target +Wants=network-online.target + +[Service] +Type=simple +User=nemoclaw-jetson-dispatch +Group=nemoclaw-jetson-dispatch +UMask=0077 +WorkingDirectory=/opt/nemoclaw-jetson-dispatch +EnvironmentFile=/etc/nemoclaw-jetson-dispatch/environment +ExecStart=/usr/bin/node --experimental-strip-types --no-warnings tools/e2e/jetson-dispatch-service.mts +Restart=on-failure +RestartSec=5 +NoNewPrivileges=true +PrivateTmp=true +ProtectHome=true +ProtectSystem=strict +ReadWritePaths=/var/lib/nemoclaw-jetson-dispatch + +[Install] +WantedBy=multi-user.target +``` + +Start the service and confirm that it listens only on loopback: + +```bash +sudo systemctl daemon-reload +sudo systemctl enable --now nemoclaw-jetson-dispatch.service +sudo systemctl status nemoclaw-jetson-dispatch.service +sudo ss -ltnp | grep '127.0.0.1:8787' +``` + +An anonymous request must fail: + +```bash +curl --fail-with-body -X POST http://127.0.0.1:8787/v1/jobs \ + -H 'Content-Type: application/json' \ + --data '{"schemaVersion":1,"target":"jetson-nvmap-gpu","candidateSha":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","workflowRunId":"1","workflowRunAttempt":1}' +``` + +The expected result is HTTP `401`. +A malformed request returns HTTP `400`, and an unknown route returns HTTP `404`. + +## Publish the Dispatcher With Cloudflare Tunnel + +Install `cloudflared` from the approved package source for Colossus. +The next commands create a public DNS route to the authenticated dispatcher. +Do not create the route until the loopback authentication check returns HTTP `401` for an anonymous request. +Use an administrator account to create one named tunnel and route one DNS hostname: + +```bash +cloudflared tunnel login +cloudflared tunnel create nemoclaw-jetson-dispatch +cloudflared tunnel route dns nemoclaw-jetson-dispatch jetson-e2e.example.com +``` + +Record the tunnel UUID from the create command. +Substitute it for `TUNNEL_UUID` in each later command and file. +Create a dedicated `cloudflared` service account if the approved package did not create one: + +```bash +sudo useradd --system --create-home --home-dir /var/lib/cloudflared \ + --shell /usr/sbin/nologin cloudflared +``` + +Install only the tunnel credential for that account: + +```bash +sudo install -d -o cloudflared -g cloudflared -m 0700 /etc/cloudflared +sudo install -o cloudflared -g cloudflared -m 0600 \ + "$HOME/.cloudflared/TUNNEL_UUID.json" /etc/cloudflared/TUNNEL_UUID.json +sudo -u cloudflared test -r /etc/cloudflared/TUNNEL_UUID.json +rm "$HOME/.cloudflared/cert.pem" "$HOME/.cloudflared/TUNNEL_UUID.json" +``` + +The removed `cert.pem` authorizes Cloudflare account management. +Do not give it to the tunnel service account. + +Create `/etc/cloudflared/jetson-dispatch.yml` with mode `0600` and the tunnel service account as owner: + +```yaml +tunnel: TUNNEL_UUID +credentials-file: /etc/cloudflared/TUNNEL_UUID.json +ingress: + - hostname: jetson-e2e.example.com + service: http://127.0.0.1:8787 + - service: http_status:404 +``` + +Run `cloudflared` as its own restricted service account. +Install `/etc/systemd/system/nemoclaw-jetson-tunnel.service`: + +```ini +[Unit] +Description=NemoClaw Jetson Cloudflare Tunnel +After=network-online.target nemoclaw-jetson-dispatch.service +Wants=network-online.target + +[Service] +Type=simple +User=cloudflared +Group=cloudflared +ExecStart=/usr/bin/cloudflared --no-autoupdate --config /etc/cloudflared/jetson-dispatch.yml tunnel run +Restart=on-failure +RestartSec=5 +NoNewPrivileges=true +PrivateTmp=true +ProtectHome=true +ProtectSystem=strict + +[Install] +WantedBy=multi-user.target +``` + +Start the tunnel service and inspect its status: + +```bash +sudo systemctl daemon-reload +sudo systemctl enable --now nemoclaw-jetson-tunnel.service +sudo systemctl status nemoclaw-jetson-tunnel.service +``` + +The origin service validates the GitHub OIDC signature and claims on every job, status, cancel, and artifact request. +Cloudflare Tunnel does not replace origin authentication. +Apply a Cloudflare rate limit to `/v1/jobs*` if the managed zone supports one. +Without that rate limit, origin authentication still rejects unauthorized work, but public requests can consume dispatcher connections. + +Confirm the public endpoint also rejects an anonymous request with HTTP `401`. +Confirm Colossus has outbound HTTPS access to GitHub's OIDC key endpoint: + +```bash +curl --fail-with-body \ + https://token.actions.githubusercontent.com/.well-known/jwks +``` + +## Configure GitHub and Run a Proof Job + +The next command updates a repository Actions variable. +Set the public HTTPS origin as a repository Actions variable: + +```bash +gh variable set JETSON_DISPATCH_URL --repo NVIDIA/NemoClaw \ + --body 'https://jetson-e2e.example.com' +``` + +First select only the Jetson target from the trusted `main` workflow: + +```bash +gh workflow run .github/workflows/e2e.yaml --repo NVIDIA/NemoClaw --ref main \ + -f targets=jetson-nvmap-gpu \ + -f jobs= \ + -f inference_mode=mock \ + -f include_staging_brev_launchable=false \ + -f allow_jetson_dispatch=true \ + -f allow_dgx_spark_runner_queue=false +``` + +The controller must run on `ubuntu-latest`. +The GitHub controller log must show one `Jetson dispatch accepted as ` line. +The Colossus journal must not contain a bearer token. +The uploaded `e2e-jetson-nvmap-gpu` artifact must contain `jetson-dispatch.json` with these results: + +- The requested candidate commit SHA and workflow run identity. +- The Jetson model, JetPack package version or `unavailable`, Jetson Linux release, and kernel. +- The test conclusion and bounded log. +- `reset: "succeeded"` before `conclusion: "success"`. + +After the workflow completes, independently rerun the baseline checks. +Then run one controlled failing candidate and confirm that its artifact records the same reset evidence. +For a cancellation proof, cancel a controller after it logs the job ID. +The controller can exit before it downloads an artifact, so inspect the private Colossus +`.json` status for `conclusion: "cancelled"` and `reset: "succeeded"` instead. +Independently rerun the baseline checks after that cancellation. + +## Recover or Disable the Deployment + +The dispatcher permits one active job. +A process crash leaves `device.lock` in the state directory. +On restart, the dispatcher invokes the reset program before it removes that stale lock or accepts more work. +If reset fails, startup fails or the completed job reports `reset-failed`. +The lock remains after either reset failure. + +Do not delete `device.lock` to bypass recovery. +Repair the reset path, run and verify the reset program, and restart the dispatcher. +Preserve the job JSON and log files for diagnosis. +These private state files can contain candidate output, and the dispatcher does not prune them. +Apply the host's approved retention policy after GitHub uploads the artifact and no device lock exists. + +To disable the temporary path, leave `allow_jetson_dispatch=false` on later dispatches and run: + +```bash +gh variable delete JETSON_DISPATCH_URL --repo NVIDIA/NemoClaw +sudo systemctl disable --now nemoclaw-jetson-tunnel.service +sudo systemctl disable --now nemoclaw-jetson-dispatch.service +``` + +Reauthenticate with `cloudflared tunnel login` as a Cloudflare administrator. +Delete the `jetson-e2e.example.com` DNS record from the Cloudflare zone, then delete the named +tunnel with `cloudflared tunnel delete TUNNEL_UUID`. +Confirm that `cloudflared tunnel list` no longer returns `TUNNEL_UUID`. +Remove the new local account certificate after the administrative deletion. +Remove the local tunnel credential, configuration, and service unit: + +```bash +rm "$HOME/.cloudflared/cert.pem" +sudo rm /etc/cloudflared/TUNNEL_UUID.json \ + /etc/cloudflared/jetson-dispatch.yml \ + /etc/systemd/system/nemoclaw-jetson-tunnel.service +sudo systemctl daemon-reload +test ! -e /etc/cloudflared/TUNNEL_UUID.json +test ! -e /etc/cloudflared/jetson-dispatch.yml +test ! -e /etc/systemd/system/nemoclaw-jetson-tunnel.service +``` + +Confirm that the public endpoint is unreachable and the repository variable is absent: + +```bash +if curl --silent --show-error --output /dev/null --connect-timeout 10 \ + https://jetson-e2e.example.com/v1/jobs; then + echo 'Jetson dispatch endpoint is still reachable' >&2 + exit 1 +fi +test -z "$(gh variable list --repo NVIDIA/NemoClaw --json name \ + --jq '.[] | select(.name == "JETSON_DISPATCH_URL") | .name')" +``` + +Remove the dedicated Jetson public key and the Colossus SSH private key. +After the required retention period, remove the private job state and logs. +Remove the dispatcher environment, service unit, and trusted checkout when no investigation or +rollback requirement remains. diff --git a/test/e2e/support/jetson-dispatch-contract.test.ts b/test/e2e/support/jetson-dispatch-contract.test.ts new file mode 100644 index 00000000000..94dc0fa6ebc --- /dev/null +++ b/test/e2e/support/jetson-dispatch-contract.test.ts @@ -0,0 +1,415 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import { createSign, generateKeyPairSync, type KeyObject } from "node:crypto"; +import fs from "node:fs"; +import type { AddressInfo } from "node:net"; +import os from "node:os"; +import path from "node:path"; + +import { afterEach, describe, expect, it, vi } from "vitest"; + +import { + createGitHubJwksResolver, + JETSON_DISPATCH_AUDIENCE, + JETSON_DISPATCH_REPOSITORY, + JETSON_DISPATCH_TARGET, + JETSON_DISPATCH_WORKFLOW_REF, + parseJetsonDispatchRequest, + verifyGitHubOidcToken, +} from "../../../tools/e2e/jetson-dispatch-contract.mts"; +import { + JetsonDispatchBusyError, + JetsonDispatchCoordinator, + type JetsonDispatchStatus, + type JetsonDispatchWorker, +} from "../../../tools/e2e/jetson-dispatch-lifecycle.mts"; +import { createJetsonDispatchServer } from "../../../tools/e2e/jetson-dispatch-service.mts"; + +const NOW_SECONDS = 1_800_000_000; +const REPOSITORY_ID = "987654321"; +const CANDIDATE_SHA = "a".repeat(40); +const WORKFLOW_SHA = "b".repeat(40); +const REQUEST = parseJetsonDispatchRequest({ + schemaVersion: 1, + target: JETSON_DISPATCH_TARGET, + candidateSha: CANDIDATE_SHA, + workflowRunId: "123456789", + workflowRunAttempt: 1, +}); + +const temporaryDirectories: string[] = []; + +afterEach(() => { + vi.useRealTimers(); + for (const directory of temporaryDirectories.splice(0)) { + fs.rmSync(directory, { force: true, recursive: true }); + } +}); + +function temporaryDirectory(): string { + const directory = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-jetson-dispatch-")); + temporaryDirectories.push(directory); + return directory; +} + +function claims(overrides: Record = {}): Record { + return { + iss: "https://token.actions.githubusercontent.com", + aud: JETSON_DISPATCH_AUDIENCE, + sub: "repo:NVIDIA/NemoClaw:ref:refs/heads/main", + repository: JETSON_DISPATCH_REPOSITORY, + repository_id: REPOSITORY_ID, + workflow_ref: JETSON_DISPATCH_WORKFLOW_REF, + workflow_sha: WORKFLOW_SHA, + sha: WORKFLOW_SHA, + ref: "refs/heads/main", + event_name: "workflow_dispatch", + runner_environment: "github-hosted", + run_id: REQUEST.workflowRunId, + run_attempt: String(REQUEST.workflowRunAttempt), + jti: "token-id", + iat: NOW_SECONDS - 60, + nbf: NOW_SECONDS - 60, + exp: NOW_SECONDS + 9 * 60, + ...overrides, + }; +} + +function signToken(privateKey: KeyObject, payload: Record): string { + const header = Buffer.from( + JSON.stringify({ alg: "RS256", kid: "test-key", typ: "JWT" }), + ).toString("base64url"); + const body = Buffer.from(JSON.stringify(payload)).toString("base64url"); + const signer = createSign("RSA-SHA256"); + signer.update(`${header}.${body}`, "ascii"); + signer.end(); + return `${header}.${body}.${signer.sign(privateKey).toString("base64url")}`; +} + +function signingKeys(): { privateKey: KeyObject; publicKey: KeyObject } { + return generateKeyPairSync("rsa", { modulusLength: 2048 }); +} + +function identity() { + return { + repository: JETSON_DISPATCH_REPOSITORY, + repositoryId: REPOSITORY_ID, + runId: REQUEST.workflowRunId, + runAttempt: REQUEST.workflowRunAttempt, + workflowSha: WORKFLOW_SHA, + tokenId: "token-id", + } as const; +} + +async function waitForCompletion( + coordinator: JetsonDispatchCoordinator, + jobId: string, +): Promise { + for (let attempt = 0; attempt < 100; attempt += 1) { + const status = coordinator.status(jobId); + if (status.state === "completed") return status; + await new Promise((resolve) => setImmediate(resolve)); + } + throw new Error("Jetson dispatch did not complete in the test deadline"); +} + +function worker( + options: { run?: JetsonDispatchWorker["run"]; reset?: JetsonDispatchWorker["reset"] } = {}, +): JetsonDispatchWorker { + return { + run: + options.run ?? + (async () => ({ + device: { + model: "NVIDIA Jetson AGX Thor Developer Kit", + jetpackVersion: "7.2.2", + jetsonLinuxRelease: "R38", + kernel: "6.8.12-tegra", + }, + log: "passed\n", + })), + reset: options.reset ?? (async () => {}), + }; +} + +function coordinator(stateDirectory: string, dispatchWorker: JetsonDispatchWorker) { + return new JetsonDispatchCoordinator({ + stateDirectory, + worker: dispatchWorker, + executionTimeoutMs: 60_000, + resetTimeoutMs: 10_000, + }); +} + +describe("Jetson dispatch request and OIDC boundary", () => { + it("accepts only the fixed target and exact workflow run identity (#8142)", () => { + expect(REQUEST).toEqual({ + schemaVersion: 1, + target: "jetson-nvmap-gpu", + candidateSha: CANDIDATE_SHA, + workflowRunId: "123456789", + workflowRunAttempt: 1, + }); + }); + + it.each([ + "command", + "host", + "identityFile", + "repository", + "url", + ])("rejects request-controlled %s fields (#8142)", (field) => { + expect(() => parseJetsonDispatchRequest({ ...REQUEST, [field]: "unsafe" })).toThrow( + "dispatch request fields must match the fixed Jetson contract", + ); + }); + + it("verifies the signature and all trusted GitHub controller claims (#8142)", async () => { + const keys = signingKeys(); + const verified = await verifyGitHubOidcToken({ + token: signToken(keys.privateKey, claims()), + request: REQUEST, + policy: { repositoryId: REPOSITORY_ID }, + resolveSigningKey: async () => keys.publicKey, + nowMs: NOW_SECONDS * 1_000, + }); + + expect(verified).toEqual(identity()); + }); + + it.each([ + ["issuer", { iss: "https://example.test" }], + ["audience", { aud: "another-service" }], + ["repository", { repository: "someone/NemoClaw" }], + ["repository ID", { repository_id: "123" }], + ["workflow", { workflow_ref: "NVIDIA/NemoClaw/.github/workflows/other.yaml@refs/heads/main" }], + ["ref", { ref: "refs/heads/feature" }], + ["event", { event_name: "pull_request" }], + ["runner", { runner_environment: "self-hosted" }], + ["run ID", { run_id: "999" }], + ["run attempt", { run_attempt: "2" }], + ["workflow SHA", { sha: "c".repeat(40) }], + ])("rejects a mismatched %s claim (#8142)", async (_name, override) => { + const keys = signingKeys(); + await expect( + verifyGitHubOidcToken({ + token: signToken(keys.privateKey, claims(override)), + request: REQUEST, + policy: { repositoryId: REPOSITORY_ID }, + resolveSigningKey: async () => keys.publicKey, + nowMs: NOW_SECONDS * 1_000, + }), + ).rejects.toThrow("OIDC claims do not match the trusted Jetson controller"); + }); + + it("rejects expired and incorrectly signed controller tokens (#8142)", async () => { + const trusted = signingKeys(); + const untrusted = signingKeys(); + await expect( + verifyGitHubOidcToken({ + token: signToken(trusted.privateKey, claims({ exp: NOW_SECONDS - 60 })), + request: REQUEST, + policy: { repositoryId: REPOSITORY_ID }, + resolveSigningKey: async () => trusted.publicKey, + nowMs: NOW_SECONDS * 1_000, + }), + ).rejects.toThrow("OIDC token is outside its allowed validity window"); + await expect( + verifyGitHubOidcToken({ + token: signToken(untrusted.privateKey, claims()), + request: REQUEST, + policy: { repositoryId: REPOSITORY_ID }, + resolveSigningKey: async () => trusted.publicKey, + nowMs: NOW_SECONDS * 1_000, + }), + ).rejects.toThrow("OIDC signature verification failed"); + }); + + it("coalesces key-set loads and bounds unknown-key refreshes (#8142)", async () => { + const keys = signingKeys(); + const jwk = keys.publicKey.export({ format: "jwk" }); + const fetchImpl = vi.fn(async () => + Response.json({ keys: [{ ...jwk, alg: "RS256", kid: "known", use: "sig" }] }), + ); + const resolve = createGitHubJwksResolver(fetchImpl as typeof fetch); + + await Promise.all([ + expect(resolve("missing-1")).rejects.toThrow("OIDC signing key is unknown"), + expect(resolve("missing-2")).rejects.toThrow("OIDC signing key is unknown"), + ]); + await expect(resolve("missing-3")).rejects.toThrow("OIDC signing key is unknown"); + await expect(resolve("known")).resolves.toMatchObject({ type: "public" }); + + expect(fetchImpl).toHaveBeenCalledOnce(); + }); +}); + +describe("Jetson single-device lifecycle", () => { + it("records success only after reset succeeds (#8142)", async () => { + const reset = vi.fn(async () => {}); + const dispatch = coordinator(temporaryDirectory(), worker({ reset })); + await dispatch.initialize(); + const accepted = dispatch.dispatch(REQUEST, identity()); + const completed = await waitForCompletion(dispatch, accepted.jobId); + + expect(completed).toMatchObject({ + state: "completed", + conclusion: "success", + reset: "succeeded", + device: { model: "NVIDIA Jetson AGX Thor Developer Kit" }, + }); + expect(reset).toHaveBeenCalledOnce(); + expect(dispatch.artifact(accepted.jobId).log).toBe("passed\n"); + }); + + it("rejects a second job while the Jetson lock is held (#8142)", async () => { + let finish: (() => void) | undefined; + const run = vi.fn( + () => + new Promise((_resolve, reject) => { + finish = () => reject(new Error("finished by test")); + }), + ); + const dispatch = coordinator(temporaryDirectory(), worker({ run })); + await dispatch.initialize(); + const accepted = dispatch.dispatch(REQUEST, identity()); + const other = { ...REQUEST, candidateSha: "c".repeat(40) }; + expect(() => dispatch.dispatch(other, identity())).toThrow(JetsonDispatchBusyError); + finish!(); + await waitForCompletion(dispatch, accepted.jobId); + }); + + it("cancels the worker and still resets the device (#8142)", async () => { + const reset = vi.fn(async () => {}); + const run = vi.fn( + (_request, options) => + new Promise((_resolve, reject) => { + options.signal.addEventListener("abort", () => reject(new Error("cancelled")), { + once: true, + }); + }), + ); + const dispatch = coordinator(temporaryDirectory(), worker({ reset, run })); + await dispatch.initialize(); + const accepted = dispatch.dispatch(REQUEST, identity()); + dispatch.cancel(accepted.jobId); + const completed = await waitForCompletion(dispatch, accepted.jobId); + + expect(completed).toMatchObject({ conclusion: "cancelled", reset: "succeeded" }); + expect(reset).toHaveBeenCalledOnce(); + }); + + it("times out the worker and still resets the device (#8142)", async () => { + vi.useFakeTimers(); + const reset = vi.fn(async () => {}); + const run = vi.fn( + (_request, options) => + new Promise((_resolve, reject) => { + options.signal.addEventListener("abort", () => reject(new Error("timed out")), { + once: true, + }); + }), + ); + const dispatch = coordinator(temporaryDirectory(), worker({ reset, run })); + await dispatch.initialize(); + const accepted = dispatch.dispatch(REQUEST, identity()); + await vi.advanceTimersByTimeAsync(60_000); + const completed = dispatch.status(accepted.jobId); + + expect(completed).toMatchObject({ conclusion: "timed-out", reset: "succeeded" }); + expect(reset).toHaveBeenCalledOnce(); + }); + + it("keeps the device locked when reset fails (#8142)", async () => { + const stateDirectory = temporaryDirectory(); + const dispatch = coordinator( + stateDirectory, + worker({ reset: async () => Promise.reject(new Error("reset helper failed")) }), + ); + await dispatch.initialize(); + const accepted = dispatch.dispatch(REQUEST, identity()); + const completed = await waitForCompletion(dispatch, accepted.jobId); + + expect(completed).toMatchObject({ conclusion: "reset-failed", reset: "failed" }); + expect(fs.existsSync(path.join(stateDirectory, "device.lock"))).toBe(true); + expect(() => + dispatch.dispatch({ ...REQUEST, candidateSha: "c".repeat(40) }, identity()), + ).toThrow("Jetson device lock requires recovery"); + await expect(dispatch.shutdown()).rejects.toThrow( + "Jetson device lock still requires reset recovery", + ); + }); + + it("resets a stale lock before accepting work after restart (#8142)", async () => { + const stateDirectory = temporaryDirectory(); + fs.writeFileSync(path.join(stateDirectory, "device.lock"), "stale-job\n", { mode: 0o600 }); + const reset = vi.fn(async () => {}); + const dispatch = coordinator(stateDirectory, worker({ reset })); + await dispatch.initialize(); + + expect(reset).toHaveBeenCalledOnce(); + expect(fs.existsSync(path.join(stateDirectory, "device.lock"))).toBe(false); + }); +}); + +describe("Jetson dispatch HTTP boundary", () => { + it("denies anonymous requests and returns authenticated result evidence (#8142)", async () => { + const keys = signingKeys(); + const now = Math.floor(Date.now() / 1_000); + const token = signToken( + keys.privateKey, + claims({ exp: now + 9 * 60, iat: now - 60, nbf: now - 60 }), + ); + const dispatch = coordinator(temporaryDirectory(), worker()); + await dispatch.initialize(); + const server = createJetsonDispatchServer({ + coordinator: dispatch, + repositoryId: REPOSITORY_ID, + resolveSigningKey: async () => keys.publicKey, + }); + await new Promise((resolve, reject) => { + server.once("error", reject); + server.listen(0, "127.0.0.1", resolve); + }); + const { port } = server.address() as AddressInfo; + const url = `http://127.0.0.1:${port}/v1/jobs`; + try { + const anonymous = await fetch(url, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify(REQUEST), + }); + expect(anonymous.status).toBe(401); + + const injected = await fetch(url, { + method: "POST", + headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json" }, + body: JSON.stringify({ ...REQUEST, command: "uname -a" }), + }); + expect(injected.status).toBe(400); + + const accepted = await fetch(url, { + method: "POST", + headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json" }, + body: JSON.stringify(REQUEST), + }); + expect(accepted.status).toBe(202); + const acceptedBody = (await accepted.json()) as { job: { jobId: string } }; + await waitForCompletion(dispatch, acceptedBody.job.jobId); + + const artifact = await fetch(`${url}/${acceptedBody.job.jobId}/artifact`, { + headers: { Authorization: `Bearer ${token}` }, + }); + expect(artifact.status).toBe(200); + await expect(artifact.json()).resolves.toMatchObject({ + log: "passed\n", + status: { conclusion: "success", reset: "succeeded" }, + }); + } finally { + await new Promise((resolve, reject) => + server.close((error) => (error ? reject(error) : resolve())), + ); + } + }); +}); diff --git a/test/e2e/support/jetson-dispatch-worker.test.ts b/test/e2e/support/jetson-dispatch-worker.test.ts new file mode 100644 index 00000000000..831f8d854f2 --- /dev/null +++ b/test/e2e/support/jetson-dispatch-worker.test.ts @@ -0,0 +1,91 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import fs from "node:fs"; +import os from "node:os"; +import path from "node:path"; + +import { afterEach, describe, expect, it } from "vitest"; + +import { loadSshJetsonWorkerConfig } from "../../../tools/e2e/jetson-dispatch-worker.mts"; + +const temporaryDirectories: string[] = []; + +afterEach(() => { + for (const directory of temporaryDirectories.splice(0)) { + fs.rmSync(directory, { force: true, recursive: true }); + } +}); + +function deploymentFiles() { + const directory = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-jetson-worker-")); + temporaryDirectories.push(directory); + const identityFile = path.join(directory, "id_ed25519"); + const knownHostsFile = path.join(directory, "known_hosts"); + const resetExecutable = path.join(directory, "reset-jetson"); + fs.writeFileSync(identityFile, "test-key", { mode: 0o600 }); + fs.writeFileSync(knownHostsFile, "test-host-key", { mode: 0o600 }); + fs.writeFileSync(resetExecutable, "#!/bin/sh\nexit 0\n", { mode: 0o700 }); + return { identityFile, knownHostsFile, resetExecutable }; +} + +function environment(files = deploymentFiles()): NodeJS.ProcessEnv { + return { + JETSON_DISPATCH_SSH_DESTINATION: "nvidia@192.168.55.1", + JETSON_DISPATCH_SSH_IDENTITY_FILE: files.identityFile, + JETSON_DISPATCH_SSH_KNOWN_HOSTS_FILE: files.knownHostsFile, + JETSON_DISPATCH_RESET_EXECUTABLE: files.resetExecutable, + JETSON_DISPATCH_TEST_TIMEOUT_SECONDS: "2700", + }; +} + +describe("Colossus SSH worker deployment boundary", () => { + it("loads fixed SSH, host-key, timeout, and reset configuration (#8142)", () => { + expect(loadSshJetsonWorkerConfig(environment())).toMatchObject({ + destination: "nvidia@192.168.55.1", + testTimeoutSeconds: 2700, + }); + }); + + it.each([ + "nvidia@192.168.55.1 -o StrictHostKeyChecking=no", + "nvidia@host;uname", + "root@", + "-oProxyCommand=unsafe", + ])("rejects an SSH destination that is not one fixed user and host: %s (#8142)", (destination) => { + expect(() => + loadSshJetsonWorkerConfig({ + ...environment(), + JETSON_DISPATCH_SSH_DESTINATION: destination, + }), + ).toThrow("JETSON_DISPATCH_SSH_DESTINATION must be a fixed user and host"); + }); + + it("rejects a writable SSH identity file (#8142)", () => { + const files = deploymentFiles(); + fs.chmodSync(files.identityFile, 0o666); + expect(() => loadSshJetsonWorkerConfig(environment(files))).toThrow( + "must not be group- or world-writable", + ); + }); + + it("rejects a group-readable SSH identity file (#8142)", () => { + const files = deploymentFiles(); + fs.chmodSync(files.identityFile, 0o640); + expect(() => loadSshJetsonWorkerConfig(environment(files))).toThrow( + "must be readable only by its owner", + ); + }); + + it("rejects a symbolic-link reset executable (#8142)", () => { + const files = deploymentFiles(); + const link = path.join(path.dirname(files.resetExecutable), "reset-link"); + fs.symlinkSync(files.resetExecutable, link); + expect(() => + loadSshJetsonWorkerConfig({ + ...environment(files), + JETSON_DISPATCH_RESET_EXECUTABLE: link, + }), + ).toThrow("must be a regular file"); + }); +}); diff --git a/test/e2e/support/jetson-workflow-boundary.test.ts b/test/e2e/support/jetson-workflow-boundary.test.ts index b68ccc73986..be30033007c 100644 --- a/test/e2e/support/jetson-workflow-boundary.test.ts +++ b/test/e2e/support/jetson-workflow-boundary.test.ts @@ -4,7 +4,7 @@ import { describe, expect, it } from "vitest"; import { validateE2eWorkflowBoundary, - validateJetsonRunnerDispatchBoundary, + validateJetsonDispatchBoundary, } from "../../../tools/e2e/workflow-boundary.mts"; import { readWorkflow } from "../../helpers/e2e-workflow-contract.ts"; @@ -13,65 +13,72 @@ function validateWorkflowMutation( ): string[] { const workflow = readWorkflow(); mutate(workflow); - return validateJetsonRunnerDispatchBoundary(workflow); + return validateJetsonDispatchBoundary(workflow); } describe("Jetson nvmap GPU E2E workflow boundary", () => { - it("rejects a permissive Jetson runner opt-in", () => { + it("rejects a permissive Colossus dispatch opt-in (#8142)", () => { const inputErrors = validateWorkflowMutation((workflow) => { const triggers = (workflow.on ?? workflow[true as unknown as string]) as { workflow_dispatch?: { inputs?: Record; }; }; - const input = triggers.workflow_dispatch!.inputs!.allow_jetson_runner_queue; + const input = triggers.workflow_dispatch!.inputs!.allow_jetson_dispatch; input.type = "string"; input.default = true; - input.description = "Queue the runner"; + input.description = "Dispatch the Jetson"; }); expect(inputErrors).toEqual( expect.arrayContaining([ - "workflow_dispatch allow_jetson_runner_queue input must be boolean", - "workflow_dispatch allow_jetson_runner_queue input must default to false", - "workflow_dispatch allow_jetson_runner_queue input must require repository administrator confirmation from the authoritative NVIDIA/NemoClaw Settings -> Actions -> Runners inventory and document queued timeout behavior", + "workflow_dispatch allow_jetson_dispatch input must be boolean", + "workflow_dispatch allow_jetson_dispatch input must default to false", + "workflow_dispatch allow_jetson_dispatch input must require the Colossus dispatcher, tunnel, reset helper, repository URL variable, and deployment checks", ]), ); + }); - const guardErrors = validateWorkflowMutation((workflow) => { + it("keeps opt-in and trusted selectors before controller assignment (#8142)", () => { + const errors = validateWorkflowMutation((workflow) => { const job = (workflow.jobs as Record)["jetson-nvmap-gpu"] as { - "runs-on"?: string; if?: string; - steps?: Array<{ name?: string }>; }; - job["runs-on"] = "self-hosted"; job.if = "${{ true }}"; - job.steps!.push({ name: "Guard Jetson runner dispatch" }); }); - expect(guardErrors).toEqual( - expect.arrayContaining([ - "jetson-nvmap-gpu job must require allow_jetson_runner_queue before runner assignment and retain trusted-main selectors", - "jetson-nvmap-gpu job must use the configured runner only after job-level opt-in", - "jetson-nvmap-gpu must enforce opt-in before runner assignment, not in a step", - ]), + + expect(errors).toContain( + "jetson-nvmap-gpu job must require the dispatch opt-in, trusted main workflow dispatch, same-repository candidate, and target selectors", ); }); - it("requires the Jetson flag at the job boundary", () => { + it("rejects candidate execution or credential-bearing controller steps (#8142)", () => { const errors = validateWorkflowMutation((workflow) => { const job = (workflow.jobs as Record)["jetson-nvmap-gpu"] as { - if?: string; + permissions?: Record; + steps?: Array<{ name?: string; run?: string; with?: Record }>; }; - job.if = job.if?.replace("inputs.allow_jetson_runner_queue && ", ""); + job.permissions!.contents = "write"; + const checkout = job.steps!.find( + (step) => step.name === "Check out trusted Jetson controller", + )!; + checkout.with!.ref = "${{ inputs.checkout_sha }}"; + const dispatch = job.steps!.find( + (step) => step.name === "Dispatch exact commit to Jetson through Colossus", + )!; + dispatch.run = "bash candidate-script.sh"; }); - expect(errors).toContain( - "jetson-nvmap-gpu job must require allow_jetson_runner_queue before runner assignment and retain trusted-main selectors", + expect(errors).toEqual( + expect.arrayContaining([ + "jetson-nvmap-gpu controller must grant only contents:read and id-token:write", + "jetson-nvmap-gpu checkout must use the trusted workflow SHA without credentials", + "jetson-nvmap-gpu controller must dispatch only the exact candidate and configured URL", + ]), ); }); - it("accepts the real workflow without Jetson queue contract errors", () => { - const errors = validateE2eWorkflowBoundary(); - expect(errors.filter((error) => /jetson|allow_jetson_runner_queue/iu.test(error))).toEqual([]); - expect(errors).toEqual([]); + it("accepts the real workflow without Jetson dispatch errors (#8142)", () => { + expect(validateJetsonDispatchBoundary(readWorkflow())).toEqual([]); + expect(validateE2eWorkflowBoundary()).toEqual([]); }); }); diff --git a/test/maintainer-e2e-skill.test.ts b/test/maintainer-e2e-skill.test.ts index b425c2f5e80..a4ae9584015 100644 --- a/test/maintainer-e2e-skill.test.ts +++ b/test/maintainer-e2e-skill.test.ts @@ -20,6 +20,7 @@ function validEvidence() { }, dispatch: { allowDgxSparkRunnerQueue: false, + allowJetsonDispatch: false, allowJetsonRunnerQueue: false, candidateSha, emptySelectors: true, @@ -119,6 +120,7 @@ describe("nemoclaw-maintainer-e2e evidence validation", () => { }, dispatch: { allowDgxSparkRunnerQueue: false, + allowJetsonDispatch: false, allowJetsonRunnerQueue: false, emptySelectors: true, includeStagingBrevLaunchable: true, @@ -220,7 +222,14 @@ describe("nemoclaw-maintainer-e2e evidence validation", () => { "dispatch.jobs", ], [ - "a full dispatch that opts into the Jetson runner queue", + "a full dispatch that opts into Colossus Jetson execution", + (evidence: ReturnType) => { + evidence.dispatch.allowJetsonDispatch = true; + }, + "dispatch.allowJetsonDispatch", + ], + [ + "a full dispatch that enables the retired Jetson runner receipt field", (evidence: ReturnType) => { evidence.dispatch.allowJetsonRunnerQueue = true; }, diff --git a/test/openshell-e2e-qualification.test.ts b/test/openshell-e2e-qualification.test.ts index 2a19801d4c1..3d6937ee503 100644 --- a/test/openshell-e2e-qualification.test.ts +++ b/test/openshell-e2e-qualification.test.ts @@ -41,6 +41,7 @@ function prFile(filename: string, status = "modified") { function validReceipt(overrides: Record = {}) { return { allowDgxSparkRunnerQueue: false, + allowJetsonDispatch: false, allowJetsonRunnerQueue: false, baseSha: BASE_SHA, candidateRepository: REPOSITORY, diff --git a/test/release-e2e-evidence.test.ts b/test/release-e2e-evidence.test.ts index f5aef666837..32208b4f8db 100644 --- a/test/release-e2e-evidence.test.ts +++ b/test/release-e2e-evidence.test.ts @@ -45,6 +45,7 @@ function runEvidence( return { dispatch: { allowDgxSparkRunnerQueue: false, + allowJetsonDispatch: false, allowJetsonRunnerQueue: false, ...(receiptVersion === 2 ? { @@ -274,11 +275,20 @@ describe("release E2E evidence", () => { }); it.each([ - ["allowJetsonRunnerQueue", "runs[0].dispatch.allowJetsonRunnerQueue must equal false"], - ["allowDgxSparkRunnerQueue", "runs[0].dispatch.allowDgxSparkRunnerQueue must equal false"], - ])("rejects release evidence that opts into %s", (field, message) => { + ["allowJetsonDispatch", "runs[0].dispatch.allowJetsonDispatch must equal false", 2 as const], + [ + "allowJetsonRunnerQueue", + "runs[0].dispatch.allowJetsonRunnerQueue must equal false", + 1 as const, + ], + [ + "allowDgxSparkRunnerQueue", + "runs[0].dispatch.allowDgxSparkRunnerQueue must equal false", + 1 as const, + ], + ])("rejects release evidence that opts into %s", (field, message, receiptVersion) => { const plan = preflight(); - const evidence = runEvidence(plan, "default"); + const evidence = runEvidence(plan, "default", { receiptVersion }); (evidence.dispatch as Record)[field] = true; expect(() => buildReleaseE2eLedger(plan, [evidence])).toThrow(message); diff --git a/tools/advisors/risk-plan.mts b/tools/advisors/risk-plan.mts index d8b047964c1..49256653a7b 100644 --- a/tools/advisors/risk-plan.mts +++ b/tools/advisors/risk-plan.mts @@ -237,8 +237,8 @@ export function isPrE2eTypedTargetId(value: string): boolean { } export function isPrE2ePlanningJob(value: string): boolean { - // Automatic PR planning cannot confirm an online self-hosted Jetson runner. - // Remove this exclusion after the Colossus-backed runner path can make that confirmation. + // Automatic PR planning cannot attest the external Colossus dispatcher and reset path. + // Remove this exclusion after that hardware gate produces trusted planning evidence. return !PR_E2E_PLANNING_OMITTED_JOB_IDS.has(value); } diff --git a/tools/e2e/cli-artifact-workflow-boundary.mts b/tools/e2e/cli-artifact-workflow-boundary.mts index e964cdb9bdf..0d9a8e8ff6f 100644 --- a/tools/e2e/cli-artifact-workflow-boundary.mts +++ b/tools/e2e/cli-artifact-workflow-boundary.mts @@ -39,7 +39,7 @@ const CLI_ARTIFACT_PROVENANCE_STEP = "Record CLI artifact provenance"; const CANDIDATE_CHECKOUT_STEP_CONTENT_SHA256 = "3578a053cede863f7aa4814d8399b4ca21ea0b77cee712e6d549c684818f11dd"; const CLI_ARTIFACT_WORKFLOW_CONTRACT_SHA256 = - "cf436f4885b22d05444f78362b9acb0dddd7027bb369ff47bf15c6a0ec66cf55"; + "e1e76d322e4f3bafcb407dc78a530e0c98ecabe8f99c184390dadb5fa914efb0"; type WorkflowRecord = Record; type WorkflowStep = WorkflowRecord & { diff --git a/tools/e2e/jetson-dispatch-client.mts b/tools/e2e/jetson-dispatch-client.mts new file mode 100644 index 00000000000..a973243f3fe --- /dev/null +++ b/tools/e2e/jetson-dispatch-client.mts @@ -0,0 +1,247 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import fs from "node:fs"; +import path from "node:path"; +import { pathToFileURL } from "node:url"; + +import { + JETSON_DISPATCH_AUDIENCE, + JETSON_DISPATCH_TARGET, + parseJetsonDispatchRequest, +} from "./jetson-dispatch-contract.mts"; +import type { JetsonDispatchArtifact, JetsonDispatchStatus } from "./jetson-dispatch-lifecycle.mts"; +import { writePrivateRegularFile } from "./private-file.mts"; + +const MAX_STATUS_BYTES = 64 * 1024; +const MAX_ARTIFACT_BYTES = 5 * 1024 * 1024; +const POLL_INTERVAL_MS = 10_000; +const MAX_WAIT_MS = 54 * 60_000; +const JOB_ID_PATTERN = /^[a-f0-9]{64}$/u; + +function record(value: unknown, name: string): Record { + if (!value || typeof value !== "object" || Array.isArray(value)) { + throw new Error(`${name} must be an object`); + } + return value as Record; +} + +function dispatcherBaseUrl(value: string | undefined): URL { + if (!value) throw new Error("JETSON_DISPATCH_URL is required"); + const url = new URL(value); + if ( + url.protocol !== "https:" || + url.username || + url.password || + url.search || + url.hash || + (url.pathname !== "" && url.pathname !== "/") + ) { + throw new Error("JETSON_DISPATCH_URL must be an HTTPS origin without credentials or a path"); + } + url.pathname = "/"; + return url; +} + +async function githubOidcToken(env: NodeJS.ProcessEnv = process.env): Promise { + const requestUrlValue = env.ACTIONS_ID_TOKEN_REQUEST_URL; + const requestToken = env.ACTIONS_ID_TOKEN_REQUEST_TOKEN; + if (!requestUrlValue || !requestToken) throw new Error("GitHub OIDC environment is unavailable"); + const requestUrl = new URL(requestUrlValue); + if (requestUrl.protocol !== "https:") throw new Error("GitHub OIDC request URL must use HTTPS"); + requestUrl.searchParams.set("audience", JETSON_DISPATCH_AUDIENCE); + const response = await fetch(requestUrl, { + headers: { Authorization: `Bearer ${requestToken}` }, + signal: AbortSignal.timeout(15_000), + }); + if (!response.ok) throw new Error(`GitHub OIDC token request returned HTTP ${response.status}`); + const payload = record(await response.json(), "GitHub OIDC token response"); + if ( + typeof payload.value !== "string" || + payload.value.length === 0 || + payload.value.length > 16 * 1024 + ) { + throw new Error("GitHub OIDC token response is invalid"); + } + return payload.value; +} + +async function dispatcherRequest(options: { + baseUrl: URL; + method: "DELETE" | "GET" | "POST"; + path: string; + body?: unknown; + maxBytes: number; +}): Promise { + const token = await githubOidcToken(); + const response = await fetch(new URL(options.path, options.baseUrl), { + method: options.method, + headers: { + Accept: "application/json", + Authorization: `Bearer ${token}`, + ...(options.body === undefined ? {} : { "Content-Type": "application/json" }), + }, + body: options.body === undefined ? undefined : JSON.stringify(options.body), + signal: AbortSignal.timeout(15_000), + }); + const contentLength = response.headers.get("content-length"); + if ( + contentLength && + /^[0-9]+$/u.test(contentLength) && + Number(contentLength) > options.maxBytes + ) { + throw new Error("Jetson dispatcher response is too large"); + } + if (!response.body) throw new Error("Jetson dispatcher returned an empty response"); + const reader = response.body.getReader(); + const chunks: Uint8Array[] = []; + let responseBytes = 0; + while (true) { + const { done, value } = await reader.read(); + if (done) break; + responseBytes += value.length; + if (responseBytes > options.maxBytes) { + await reader.cancel(); + throw new Error("Jetson dispatcher response is too large"); + } + chunks.push(value); + } + const bytes = Buffer.concat(chunks, responseBytes); + let payload: unknown; + try { + payload = JSON.parse(bytes.toString("utf8")); + } catch { + throw new Error("Jetson dispatcher returned invalid JSON"); + } + if (!response.ok) { + const error = record(payload, "Jetson dispatcher error").error; + throw new Error( + `Jetson dispatcher returned HTTP ${response.status}: ${typeof error === "string" ? error.slice(0, 500) : "request failed"}`, + ); + } + return payload; +} + +function validateStatus(value: unknown): JetsonDispatchStatus { + const response = record(value, "Jetson dispatcher response"); + const job = record(response.job, "Jetson dispatch job"); + if ( + typeof job.jobId !== "string" || + !JOB_ID_PATTERN.test(job.jobId) || + !["queued", "running", "completed"].includes(String(job.state)) + ) { + throw new Error("Jetson dispatcher returned an invalid job status"); + } + return job as unknown as JetsonDispatchStatus; +} + +function validateArtifact(value: unknown, jobId: string): JetsonDispatchArtifact { + const artifact = record(value, "Jetson dispatch artifact"); + const status = record(artifact.status, "Jetson dispatch artifact status"); + if ( + status.jobId !== jobId || + status.state !== "completed" || + typeof status.conclusion !== "string" || + typeof artifact.log !== "string" + ) { + throw new Error("Jetson dispatcher returned an invalid artifact"); + } + return artifact as unknown as JetsonDispatchArtifact; +} + +function delay(milliseconds: number): Promise { + return new Promise((resolve) => setTimeout(resolve, milliseconds)); +} + +async function main(): Promise { + const request = parseJetsonDispatchRequest({ + schemaVersion: 1, + target: JETSON_DISPATCH_TARGET, + candidateSha: process.env.JETSON_DISPATCH_CANDIDATE_SHA, + workflowRunId: process.env.GITHUB_RUN_ID, + workflowRunAttempt: Number(process.env.GITHUB_RUN_ATTEMPT), + }); + const baseUrl = dispatcherBaseUrl(process.env.JETSON_DISPATCH_URL); + const artifactDirectory = process.env.E2E_ARTIFACT_DIR ?? ""; + if (!path.isAbsolute(artifactDirectory)) throw new Error("E2E_ARTIFACT_DIR must be absolute"); + fs.mkdirSync(artifactDirectory, { recursive: true, mode: 0o700 }); + fs.chmodSync(artifactDirectory, 0o700); + + let jobId: string | undefined; + let stopping = false; + const cancel = (): void => { + if (stopping) return; + stopping = true; + if (!jobId) { + process.exitCode = 1; + return; + } + void dispatcherRequest({ + baseUrl, + method: "DELETE", + path: `v1/jobs/${jobId}`, + maxBytes: MAX_STATUS_BYTES, + }).finally(() => { + process.exitCode = 1; + }); + }; + process.on("SIGINT", cancel); + process.on("SIGTERM", cancel); + + const dispatched = validateStatus( + await dispatcherRequest({ + baseUrl, + method: "POST", + path: "v1/jobs", + body: request, + maxBytes: MAX_STATUS_BYTES, + }), + ); + jobId = dispatched.jobId; + console.log(`Jetson dispatch accepted as ${jobId}`); + const deadline = Date.now() + MAX_WAIT_MS; + let status = dispatched; + while (status.state !== "completed") { + if (stopping) throw new Error("Jetson dispatch cancellation requested"); + if (Date.now() >= deadline) { + await dispatcherRequest({ + baseUrl, + method: "DELETE", + path: `v1/jobs/${jobId}`, + maxBytes: MAX_STATUS_BYTES, + }); + throw new Error("Jetson dispatcher did not complete before the controller deadline"); + } + await delay(POLL_INTERVAL_MS); + status = validateStatus( + await dispatcherRequest({ + baseUrl, + method: "GET", + path: `v1/jobs/${jobId}`, + maxBytes: MAX_STATUS_BYTES, + }), + ); + console.log(`Jetson dispatch state: ${status.state}`); + } + + const artifactValue = await dispatcherRequest({ + baseUrl, + method: "GET", + path: `v1/jobs/${jobId}/artifact`, + maxBytes: MAX_ARTIFACT_BYTES, + }); + const artifact = validateArtifact(artifactValue, jobId); + writePrivateRegularFile( + path.join(artifactDirectory, "jetson-dispatch.json"), + `${JSON.stringify(artifact, null, 2)}\n`, + ); + console.log(`Jetson dispatch conclusion: ${artifact.status.conclusion}`); + if (artifact.status.conclusion !== "success") process.exitCode = 1; +} + +if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) { + main().catch((error) => { + console.error(error instanceof Error ? error.message : "Jetson dispatch client failed"); + process.exitCode = 1; + }); +} diff --git a/tools/e2e/jetson-dispatch-contract.mts b/tools/e2e/jetson-dispatch-contract.mts new file mode 100644 index 00000000000..7a8c668d19a --- /dev/null +++ b/tools/e2e/jetson-dispatch-contract.mts @@ -0,0 +1,274 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import { createPublicKey, createVerify, type JsonWebKeyInput, type KeyObject } from "node:crypto"; + +export const JETSON_DISPATCH_AUDIENCE = "nemoclaw-jetson-dispatch"; +export const JETSON_DISPATCH_TARGET = "jetson-nvmap-gpu"; +export const JETSON_DISPATCH_REPOSITORY = "NVIDIA/NemoClaw"; +export const JETSON_DISPATCH_WORKFLOW_REF = + "NVIDIA/NemoClaw/.github/workflows/e2e.yaml@refs/heads/main"; + +const GITHUB_OIDC_ISSUER = "https://token.actions.githubusercontent.com"; +const GITHUB_OIDC_JWKS_URL = `${GITHUB_OIDC_ISSUER}/.well-known/jwks`; +const SHA_PATTERN = /^[a-f0-9]{40}$/u; +const POSITIVE_INTEGER_PATTERN = /^[1-9][0-9]*$/u; +const MAX_TOKEN_BYTES = 16 * 1024; +const MAX_TOKEN_LIFETIME_SECONDS = 15 * 60; +const CLOCK_SKEW_SECONDS = 30; +const JWKS_CACHE_MS = 5 * 60_000; +const UNKNOWN_KEY_REFRESH_INTERVAL_MS = 60_000; + +export interface JetsonDispatchRequest { + schemaVersion: 1; + target: typeof JETSON_DISPATCH_TARGET; + candidateSha: string; + workflowRunId: string; + workflowRunAttempt: number; +} + +export interface GitHubOidcIdentity { + repository: typeof JETSON_DISPATCH_REPOSITORY; + repositoryId: string; + runId: string; + runAttempt: number; + workflowSha: string; + tokenId: string; +} + +export interface GitHubOidcPolicy { + repositoryId: string; +} + +export type SigningKeyResolver = (keyId: string) => Promise; + +function record(value: unknown, name: string): Record { + if (!value || typeof value !== "object" || Array.isArray(value)) { + throw new Error(`${name} must be an object`); + } + return value as Record; +} + +function positiveInteger(value: unknown, name: string): number { + if (!Number.isSafeInteger(value) || (value as number) < 1) { + throw new Error(`${name} must be a positive safe integer`); + } + return value as number; +} + +function positiveIntegerString(value: unknown, name: string): string { + if (typeof value !== "string" || !POSITIVE_INTEGER_PATTERN.test(value)) { + throw new Error(`${name} must be a positive decimal integer`); + } + return value; +} + +export function parseJetsonDispatchRequest(value: unknown): JetsonDispatchRequest { + const request = record(value, "dispatch request"); + const expectedKeys = [ + "candidateSha", + "schemaVersion", + "target", + "workflowRunAttempt", + "workflowRunId", + ]; + const actualKeys = Object.keys(request).sort(); + if ( + actualKeys.length !== expectedKeys.length || + actualKeys.some((key, index) => key !== expectedKeys[index]) + ) { + throw new Error("dispatch request fields must match the fixed Jetson contract"); + } + if (request.schemaVersion !== 1) { + throw new Error("dispatch request schemaVersion must be 1"); + } + if (request.target !== JETSON_DISPATCH_TARGET) { + throw new Error(`dispatch target must be ${JETSON_DISPATCH_TARGET}`); + } + if (typeof request.candidateSha !== "string" || !SHA_PATTERN.test(request.candidateSha)) { + throw new Error("candidateSha must be a lowercase 40-character commit SHA"); + } + const workflowRunId = positiveIntegerString(request.workflowRunId, "workflowRunId"); + const workflowRunAttempt = positiveInteger(request.workflowRunAttempt, "workflowRunAttempt"); + return { + schemaVersion: 1, + target: JETSON_DISPATCH_TARGET, + candidateSha: request.candidateSha, + workflowRunId, + workflowRunAttempt, + }; +} + +function decodeJwtPart(encoded: string, name: string): Record { + if (!/^[A-Za-z0-9_-]+$/u.test(encoded)) throw new Error(`OIDC ${name} encoding is invalid`); + let value: unknown; + try { + value = JSON.parse(Buffer.from(encoded, "base64url").toString("utf8")); + } catch { + throw new Error(`OIDC ${name} is not valid JSON`); + } + return record(value, `OIDC ${name}`); +} + +function stringClaim(claims: Record, name: string): string { + const value = claims[name]; + if (typeof value !== "string" || value.length === 0) { + throw new Error(`OIDC ${name} claim is invalid`); + } + return value; +} + +function numericDateClaim(claims: Record, name: string): number { + const value = claims[name]; + if (!Number.isSafeInteger(value) || (value as number) < 1) { + throw new Error(`OIDC ${name} claim is invalid`); + } + return value as number; +} + +export async function verifyGitHubOidcToken(options: { + token: string; + request: JetsonDispatchRequest; + policy: GitHubOidcPolicy; + resolveSigningKey: SigningKeyResolver; + nowMs?: number; +}): Promise { + if ( + typeof options.token !== "string" || + options.token.length === 0 || + Buffer.byteLength(options.token) > MAX_TOKEN_BYTES + ) { + throw new Error("OIDC token size is invalid"); + } + if (!POSITIVE_INTEGER_PATTERN.test(options.policy.repositoryId)) { + throw new Error("trusted repository ID must be a positive decimal integer"); + } + const parts = options.token.split("."); + if (parts.length !== 3 || parts.some((part) => part.length === 0)) { + throw new Error("OIDC token must be a compact JWT"); + } + const [encodedHeader, encodedClaims, encodedSignature] = parts as [string, string, string]; + const header = decodeJwtPart(encodedHeader, "header"); + if (header.alg !== "RS256" || header.typ !== "JWT") { + throw new Error("OIDC token must use an RS256 JWT header"); + } + const keyId = stringClaim(header, "kid"); + if (keyId.length > 256 || /[\u0000-\u001f\u007f]/u.test(keyId)) { + throw new Error("OIDC kid header is invalid"); + } + + const claims = decodeJwtPart(encodedClaims, "claims"); + if (!/^[A-Za-z0-9_-]+$/u.test(encodedSignature)) { + throw new Error("OIDC signature encoding is invalid"); + } + const signature = Buffer.from(encodedSignature, "base64url"); + const verifier = createVerify("RSA-SHA256"); + verifier.update(`${encodedHeader}.${encodedClaims}`, "ascii"); + verifier.end(); + const signingKey = await options.resolveSigningKey(keyId); + if (!verifier.verify(signingKey, signature)) { + throw new Error("OIDC signature verification failed"); + } + + const nowSeconds = Math.floor((options.nowMs ?? Date.now()) / 1000); + const issuedAt = numericDateClaim(claims, "iat"); + const notBefore = numericDateClaim(claims, "nbf"); + const expiresAt = numericDateClaim(claims, "exp"); + if ( + issuedAt > nowSeconds + CLOCK_SKEW_SECONDS || + notBefore > nowSeconds + CLOCK_SKEW_SECONDS || + expiresAt <= nowSeconds - CLOCK_SKEW_SECONDS || + expiresAt <= issuedAt || + expiresAt - issuedAt > MAX_TOKEN_LIFETIME_SECONDS + ) { + throw new Error("OIDC token is outside its allowed validity window"); + } + + const workflowSha = stringClaim(claims, "workflow_sha"); + const workflowRunId = positiveIntegerString(claims.run_id, "OIDC run_id claim"); + const workflowRunAttempt = positiveIntegerString(claims.run_attempt, "OIDC run_attempt claim"); + if ( + stringClaim(claims, "iss") !== GITHUB_OIDC_ISSUER || + stringClaim(claims, "aud") !== JETSON_DISPATCH_AUDIENCE || + stringClaim(claims, "repository") !== JETSON_DISPATCH_REPOSITORY || + stringClaim(claims, "repository_id") !== options.policy.repositoryId || + stringClaim(claims, "workflow_ref") !== JETSON_DISPATCH_WORKFLOW_REF || + stringClaim(claims, "ref") !== "refs/heads/main" || + stringClaim(claims, "event_name") !== "workflow_dispatch" || + stringClaim(claims, "runner_environment") !== "github-hosted" || + !SHA_PATTERN.test(workflowSha) || + stringClaim(claims, "sha") !== workflowSha || + workflowRunId !== options.request.workflowRunId || + Number(workflowRunAttempt) !== options.request.workflowRunAttempt + ) { + throw new Error("OIDC claims do not match the trusted Jetson controller"); + } + + return { + repository: JETSON_DISPATCH_REPOSITORY, + repositoryId: options.policy.repositoryId, + runId: workflowRunId, + runAttempt: options.request.workflowRunAttempt, + workflowSha, + tokenId: stringClaim(claims, "jti"), + }; +} + +type FetchLike = typeof fetch; + +export function createGitHubJwksResolver(fetchImpl: FetchLike = fetch): SigningKeyResolver { + let cachedAt = 0; + let cachedKeys = new Map(); + let refreshInFlight: Promise | undefined; + + async function refresh(): Promise { + const response = await fetchImpl(GITHUB_OIDC_JWKS_URL, { + headers: { Accept: "application/json" }, + signal: AbortSignal.timeout(5_000), + }); + if (!response.ok) throw new Error(`GitHub OIDC JWKS returned HTTP ${response.status}`); + const payload = record(await response.json(), "GitHub OIDC JWKS response"); + if (!Array.isArray(payload.keys) || payload.keys.length === 0 || payload.keys.length > 20) { + throw new Error("GitHub OIDC JWKS response has an invalid key set"); + } + const nextKeys = new Map(); + for (const value of payload.keys) { + const key = record(value, "GitHub OIDC JWK"); + if ( + key.kty !== "RSA" || + key.use !== "sig" || + key.alg !== "RS256" || + typeof key.kid !== "string" || + key.kid.length === 0 || + typeof key.n !== "string" || + typeof key.e !== "string" + ) { + continue; + } + nextKeys.set(key.kid, createPublicKey({ key, format: "jwk" } as JsonWebKeyInput)); + } + if (nextKeys.size === 0) throw new Error("GitHub OIDC JWKS contains no RS256 signing key"); + cachedKeys = nextKeys; + cachedAt = Date.now(); + } + + async function refreshOnce(): Promise { + refreshInFlight ??= refresh().finally(() => { + refreshInFlight = undefined; + }); + await refreshInFlight; + } + + return async (keyId) => { + const now = Date.now(); + const refreshedExpiredCache = cachedAt === 0 || now - cachedAt > JWKS_CACHE_MS; + if (refreshedExpiredCache) await refreshOnce(); + let key = cachedKeys.get(keyId); + if (!key && !refreshedExpiredCache && now - cachedAt > UNKNOWN_KEY_REFRESH_INTERVAL_MS) { + await refreshOnce(); + key = cachedKeys.get(keyId); + } + if (!key) throw new Error("OIDC signing key is unknown"); + return key; + }; +} diff --git a/tools/e2e/jetson-dispatch-lifecycle.mts b/tools/e2e/jetson-dispatch-lifecycle.mts new file mode 100644 index 00000000000..588f7ef2115 --- /dev/null +++ b/tools/e2e/jetson-dispatch-lifecycle.mts @@ -0,0 +1,332 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import { createHash } from "node:crypto"; +import fs from "node:fs"; +import path from "node:path"; +import type { GitHubOidcIdentity, JetsonDispatchRequest } from "./jetson-dispatch-contract.mts"; +import { + createPrivateRegularFile, + readPrivateRegularFile, + writePrivateRegularFile, +} from "./private-file.mts"; + +const MAX_LOG_BYTES = 4 * 1024 * 1024; + +export type JetsonDispatchConclusion = + | "cancelled" + | "failure" + | "reset-failed" + | "success" + | "timed-out"; + +export interface JetsonDeviceIdentity { + model: string; + jetpackVersion: string; + jetsonLinuxRelease: string; + kernel: string; +} + +export interface JetsonWorkerResult { + device: JetsonDeviceIdentity; + log: string; +} + +export interface JetsonDispatchWorker { + run( + request: JetsonDispatchRequest, + options: { jobId: string; signal: AbortSignal }, + ): Promise; + reset(options: { signal: AbortSignal }): Promise; +} + +export interface JetsonDispatchStatus { + schemaVersion: 1; + jobId: string; + request: JetsonDispatchRequest; + state: "queued" | "running" | "completed"; + conclusion?: JetsonDispatchConclusion; + createdAt: string; + startedAt?: string; + completedAt?: string; + device?: JetsonDeviceIdentity; + reset: "pending" | "succeeded" | "failed"; + error?: string; +} + +export interface JetsonDispatchArtifact { + status: JetsonDispatchStatus; + log: string; +} + +export class JetsonDispatchBusyError extends Error {} + +export class JetsonDispatchNotFoundError extends Error {} + +function safeError(error: unknown): string { + const message = error instanceof Error ? error.message : "Jetson dispatch failed"; + return message.replace(/[\u0000-\u001f\u007f]/gu, " ").slice(0, 500); +} + +function workerErrorLog(error: unknown): string | undefined { + if (!error || typeof error !== "object" || !("log" in error)) return undefined; + const log = (error as { log?: unknown }).log; + if (typeof log !== "string" || Buffer.byteLength(log) > MAX_LOG_BYTES) return undefined; + return log; +} + +function ensurePrivateDirectory(directory: string): void { + fs.mkdirSync(directory, { recursive: true, mode: 0o700 }); + const stat = fs.lstatSync(directory); + if (!stat.isDirectory() || stat.isSymbolicLink()) { + throw new Error(`${directory} must be a private directory`); + } + const currentUid = process.getuid?.(); + if (currentUid !== undefined && stat.uid !== currentUid) { + throw new Error(`${directory} must be owned by the dispatcher user`); + } + fs.chmodSync(directory, 0o700); +} + +function dispatchJobId(request: JetsonDispatchRequest): string { + return createHash("sha256") + .update( + `${request.schemaVersion}:${request.target}:${request.candidateSha}:${request.workflowRunId}:${request.workflowRunAttempt}`, + "utf8", + ) + .digest("hex"); +} + +function withTimeout( + timeoutMs: number, + operation: (signal: AbortSignal) => Promise, +): Promise { + const controller = new AbortController(); + const timer = setTimeout(() => controller.abort(new Error("operation timed out")), timeoutMs); + timer.unref(); + return operation(controller.signal).finally(() => clearTimeout(timer)); +} + +export class JetsonDispatchCoordinator { + readonly #stateDirectory: string; + readonly #lockPath: string; + readonly #worker: JetsonDispatchWorker; + readonly #executionTimeoutMs: number; + readonly #resetTimeoutMs: number; + readonly #jobs = new Map(); + #activeJobId: string | undefined; + #activeAbort: AbortController | undefined; + #activeRun: Promise | undefined; + #cancelRequested = false; + #initialized = false; + + constructor(options: { + stateDirectory: string; + worker: JetsonDispatchWorker; + executionTimeoutMs: number; + resetTimeoutMs: number; + }) { + if (!path.isAbsolute(options.stateDirectory)) { + throw new Error("Jetson dispatcher state directory must be absolute"); + } + if ( + !Number.isSafeInteger(options.executionTimeoutMs) || + options.executionTimeoutMs < 60_000 || + options.executionTimeoutMs > 55 * 60_000 + ) { + throw new Error("Jetson execution timeout must be between 1 and 55 minutes"); + } + if ( + !Number.isSafeInteger(options.resetTimeoutMs) || + options.resetTimeoutMs < 10_000 || + options.resetTimeoutMs > 10 * 60_000 + ) { + throw new Error("Jetson reset timeout must be between 10 seconds and 10 minutes"); + } + this.#stateDirectory = options.stateDirectory; + this.#lockPath = path.join(options.stateDirectory, "device.lock"); + this.#worker = options.worker; + this.#executionTimeoutMs = options.executionTimeoutMs; + this.#resetTimeoutMs = options.resetTimeoutMs; + } + + async initialize(): Promise { + if (this.#initialized) return; + ensurePrivateDirectory(this.#stateDirectory); + const staleLock = readPrivateRegularFile(this.#lockPath, { + allowMissing: true, + maxBytes: 1024, + }); + if (staleLock !== null) { + await withTimeout(this.#resetTimeoutMs, (signal) => this.#worker.reset({ signal })); + fs.unlinkSync(this.#lockPath); + } + this.#initialized = true; + } + + dispatch(request: JetsonDispatchRequest, identity: GitHubOidcIdentity): JetsonDispatchStatus { + this.#requireInitialized(); + if ( + identity.runId !== request.workflowRunId || + identity.runAttempt !== request.workflowRunAttempt + ) { + throw new Error("dispatch identity does not match the workflow run"); + } + const jobId = dispatchJobId(request); + const existing = this.#jobs.get(jobId); + if (existing) return structuredClone(existing); + if (this.#activeJobId) { + throw new JetsonDispatchBusyError("Jetson device is already running another job"); + } + + try { + createPrivateRegularFile(this.#lockPath, `${jobId}\n`); + } catch (error) { + if ((error as NodeJS.ErrnoException).code === "EEXIST") { + throw new JetsonDispatchBusyError("Jetson device lock requires recovery"); + } + throw error; + } + const status: JetsonDispatchStatus = { + schemaVersion: 1, + jobId, + request: structuredClone(request), + state: "queued", + createdAt: new Date().toISOString(), + reset: "pending", + }; + try { + this.#persist(status); + } catch (error) { + fs.unlinkSync(this.#lockPath); + throw error; + } + this.#jobs.set(jobId, status); + this.#activeJobId = jobId; + this.#activeRun = this.#run(status); + return structuredClone(status); + } + + status(jobId: string): JetsonDispatchStatus { + this.#requireInitialized(); + const status = this.#jobs.get(jobId); + if (!status) throw new JetsonDispatchNotFoundError("Jetson dispatch job was not found"); + return structuredClone(status); + } + + request(jobId: string): JetsonDispatchRequest { + return this.status(jobId).request; + } + + cancel(jobId: string): JetsonDispatchStatus { + const status = this.#jobs.get(jobId); + if (!status) throw new JetsonDispatchNotFoundError("Jetson dispatch job was not found"); + if (status.state !== "completed" && this.#activeJobId === jobId) { + this.#cancelRequested = true; + this.#activeAbort?.abort(new Error("dispatch cancelled")); + } + return structuredClone(status); + } + + async shutdown(): Promise { + if (this.#activeJobId) this.cancel(this.#activeJobId); + await this.#activeRun; + if ( + readPrivateRegularFile(this.#lockPath, { + allowMissing: true, + maxBytes: 1024, + }) !== null + ) { + throw new Error("Jetson device lock still requires reset recovery"); + } + } + + artifact(jobId: string): JetsonDispatchArtifact { + const status = this.status(jobId); + if (status.state !== "completed") + throw new JetsonDispatchBusyError("Jetson job is not complete"); + const log = readPrivateRegularFile(this.#logPath(jobId), { maxBytes: MAX_LOG_BYTES }) ?? ""; + return { status, log }; + } + + async #run(status: JetsonDispatchStatus): Promise { + const controller = new AbortController(); + this.#activeAbort = controller; + this.#cancelRequested = false; + let timedOut = false; + let conclusion: JetsonDispatchConclusion = "failure"; + const timer = setTimeout(() => { + timedOut = true; + controller.abort(new Error("Jetson execution timed out")); + }, this.#executionTimeoutMs); + timer.unref(); + + try { + status.state = "running"; + status.startedAt = new Date().toISOString(); + this.#persist(status); + const result = await this.#worker.run(status.request, { + jobId: status.jobId, + signal: controller.signal, + }); + if (Buffer.byteLength(result.log) > MAX_LOG_BYTES) { + throw new Error(`Jetson log exceeds ${MAX_LOG_BYTES} bytes`); + } + writePrivateRegularFile(this.#logPath(status.jobId), result.log); + status.device = result.device; + conclusion = "success"; + } catch (error) { + status.error = safeError(error); + conclusion = timedOut ? "timed-out" : this.#cancelRequested ? "cancelled" : "failure"; + try { + writePrivateRegularFile(this.#logPath(status.jobId), workerErrorLog(error) ?? ""); + } catch (logError) { + status.error = `${status.error}; log persistence failed: ${safeError(logError)}`.slice( + 0, + 500, + ); + } + } finally { + clearTimeout(timer); + try { + await withTimeout(this.#resetTimeoutMs, (signal) => this.#worker.reset({ signal })); + status.reset = "succeeded"; + fs.unlinkSync(this.#lockPath); + } catch (error) { + status.reset = "failed"; + status.error = `Jetson reset failed: ${safeError(error)}`; + conclusion = "reset-failed"; + } + status.conclusion = conclusion; + status.state = "completed"; + status.completedAt = new Date().toISOString(); + try { + this.#persist(status); + } catch (error) { + status.error = `Final status persistence failed: ${safeError(error)}`; + status.conclusion = "failure"; + } finally { + this.#activeAbort = undefined; + this.#activeRun = undefined; + this.#activeJobId = undefined; + this.#cancelRequested = false; + } + } + } + + #persist(status: JetsonDispatchStatus): void { + writePrivateRegularFile(this.#statusPath(status.jobId), `${JSON.stringify(status, null, 2)}\n`); + } + + #statusPath(jobId: string): string { + return path.join(this.#stateDirectory, `${jobId}.json`); + } + + #logPath(jobId: string): string { + return path.join(this.#stateDirectory, `${jobId}.log`); + } + + #requireInitialized(): void { + if (!this.#initialized) throw new Error("Jetson dispatcher is not initialized"); + } +} diff --git a/tools/e2e/jetson-dispatch-service.mts b/tools/e2e/jetson-dispatch-service.mts new file mode 100644 index 00000000000..39398760e2f --- /dev/null +++ b/tools/e2e/jetson-dispatch-service.mts @@ -0,0 +1,244 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import { createServer, type IncomingMessage, type Server, type ServerResponse } from "node:http"; +import path from "node:path"; +import { pathToFileURL } from "node:url"; + +import { + createGitHubJwksResolver, + type GitHubOidcIdentity, + parseJetsonDispatchRequest, + type SigningKeyResolver, + verifyGitHubOidcToken, +} from "./jetson-dispatch-contract.mts"; +import { + JetsonDispatchBusyError, + JetsonDispatchCoordinator, + JetsonDispatchNotFoundError, +} from "./jetson-dispatch-lifecycle.mts"; +import { loadSshJetsonWorkerConfig, SshJetsonDispatchWorker } from "./jetson-dispatch-worker.mts"; + +const MAX_REQUEST_BYTES = 8 * 1024; +const JOB_PATH_PATTERN = /^\/v1\/jobs\/([a-f0-9]{64})(?:\/(artifact))?$/u; + +function positiveIntegerEnvironment( + value: string | undefined, + name: string, + minimum: number, + maximum: number, +): number { + if (!value || !/^[1-9][0-9]*$/u.test(value)) { + throw new Error(`${name} must be a positive integer`); + } + const parsed = Number(value); + if (!Number.isSafeInteger(parsed) || parsed < minimum || parsed > maximum) { + throw new Error(`${name} must be between ${minimum} and ${maximum}`); + } + return parsed; +} + +function bearerToken(request: IncomingMessage): string { + const authorization = request.headers.authorization; + const match = + typeof authorization === "string" ? /^Bearer ([A-Za-z0-9._-]+)$/u.exec(authorization) : null; + if (!match) throw new Error("request requires a bearer token"); + return match[1]!; +} + +async function readJsonBody(request: IncomingMessage): Promise { + if (request.headers["content-type"]?.split(";", 1)[0]?.trim() !== "application/json") { + throw new Error("request Content-Type must be application/json"); + } + const chunks: Buffer[] = []; + let bytes = 0; + for await (const chunk of request) { + const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk); + bytes += buffer.length; + if (bytes > MAX_REQUEST_BYTES) throw new Error("request body is too large"); + chunks.push(buffer); + } + if (bytes === 0) throw new Error("request body is required"); + try { + return JSON.parse(Buffer.concat(chunks).toString("utf8")); + } catch { + throw new Error("request body must be valid JSON"); + } +} + +function sendJson(response: ServerResponse, status: number, value: unknown): void { + const body = `${JSON.stringify(value)}\n`; + response.writeHead(status, { + "Cache-Control": "no-store", + "Content-Length": Buffer.byteLength(body), + "Content-Type": "application/json; charset=utf-8", + "X-Content-Type-Options": "nosniff", + }); + response.end(body); +} + +export function createJetsonDispatchServer(options: { + coordinator: JetsonDispatchCoordinator; + repositoryId: string; + resolveSigningKey: SigningKeyResolver; +}): Server { + async function authenticate( + incoming: IncomingMessage, + dispatchRequest: ReturnType, + ): Promise { + return verifyGitHubOidcToken({ + token: bearerToken(incoming), + request: dispatchRequest, + policy: { repositoryId: options.repositoryId }, + resolveSigningKey: options.resolveSigningKey, + }); + } + + return createServer((request, response) => { + void (async () => { + if (!request.url) { + sendJson(response, 404, { error: "not found" }); + return; + } + if (request.method === "POST" && request.url === "/v1/jobs") { + let dispatchRequest; + try { + dispatchRequest = parseJetsonDispatchRequest(await readJsonBody(request)); + } catch (error) { + sendJson(response, 400, { + error: error instanceof Error ? error.message : "invalid request", + }); + return; + } + let identity; + try { + identity = await authenticate(request, dispatchRequest); + } catch { + sendJson(response, 401, { error: "request authentication failed" }); + return; + } + sendJson(response, 202, { job: options.coordinator.dispatch(dispatchRequest, identity) }); + return; + } + + const match = JOB_PATH_PATTERN.exec(request.url); + if (!match || !["DELETE", "GET"].includes(request.method ?? "")) { + sendJson(response, 404, { error: "not found" }); + return; + } + const jobId = match[1]!; + const artifact = match[2] === "artifact"; + const dispatchRequest = options.coordinator.request(jobId); + try { + await authenticate(request, dispatchRequest); + } catch { + sendJson(response, 401, { error: "request authentication failed" }); + return; + } + if (request.method === "DELETE") { + if (artifact) { + sendJson(response, 405, { error: "method not allowed" }); + return; + } + sendJson(response, 202, { job: options.coordinator.cancel(jobId) }); + return; + } + sendJson( + response, + 200, + artifact ? options.coordinator.artifact(jobId) : { job: options.coordinator.status(jobId) }, + ); + })().catch((error) => { + if (response.headersSent) { + response.destroy(); + return; + } + if (error instanceof JetsonDispatchBusyError) { + sendJson(response, 409, { error: error.message }); + return; + } + if (error instanceof JetsonDispatchNotFoundError) { + sendJson(response, 404, { error: error.message }); + return; + } + console.error(error instanceof Error ? error.message : "Jetson dispatch service failed"); + sendJson(response, 500, { error: "Jetson dispatch service failed" }); + }); + }); +} + +async function main(): Promise { + const stateDirectory = process.env.JETSON_DISPATCH_STATE_DIRECTORY ?? ""; + if (!path.isAbsolute(stateDirectory)) { + throw new Error("JETSON_DISPATCH_STATE_DIRECTORY must be absolute"); + } + const repositoryId = process.env.JETSON_DISPATCH_GITHUB_REPOSITORY_ID ?? ""; + if (!/^[1-9][0-9]*$/u.test(repositoryId)) { + throw new Error("JETSON_DISPATCH_GITHUB_REPOSITORY_ID must be a positive integer"); + } + const executionTimeoutSeconds = positiveIntegerEnvironment( + process.env.JETSON_DISPATCH_EXECUTION_TIMEOUT_SECONDS, + "JETSON_DISPATCH_EXECUTION_TIMEOUT_SECONDS", + 120, + 55 * 60, + ); + const resetTimeoutSeconds = positiveIntegerEnvironment( + process.env.JETSON_DISPATCH_RESET_TIMEOUT_SECONDS, + "JETSON_DISPATCH_RESET_TIMEOUT_SECONDS", + 10, + 10 * 60, + ); + const workerConfig = loadSshJetsonWorkerConfig(); + if (executionTimeoutSeconds < workerConfig.testTimeoutSeconds + 30) { + throw new Error("Jetson execution timeout must exceed the remote test timeout by 30 seconds"); + } + const coordinator = new JetsonDispatchCoordinator({ + stateDirectory, + worker: new SshJetsonDispatchWorker(workerConfig), + executionTimeoutMs: executionTimeoutSeconds * 1_000, + resetTimeoutMs: resetTimeoutSeconds * 1_000, + }); + await coordinator.initialize(); + const server = createJetsonDispatchServer({ + coordinator, + repositoryId, + resolveSigningKey: createGitHubJwksResolver(), + }); + server.headersTimeout = 10_000; + server.requestTimeout = 15_000; + server.keepAliveTimeout = 5_000; + const port = positiveIntegerEnvironment( + process.env.JETSON_DISPATCH_PORT ?? "8787", + "JETSON_DISPATCH_PORT", + 1, + 65_535, + ); + await new Promise((resolve, reject) => { + server.once("error", reject); + server.listen(port, "127.0.0.1", resolve); + }); + console.log(`Jetson dispatch service listening on 127.0.0.1:${port}`); + + let stopping = false; + const stop = (): void => { + if (stopping) return; + stopping = true; + void new Promise((resolve, reject) => { + server.close((error) => (error ? reject(error) : resolve())); + }) + .then(() => coordinator.shutdown()) + .catch((error) => { + console.error(error instanceof Error ? error.message : "Jetson dispatch shutdown failed"); + process.exitCode = 1; + }); + }; + process.on("SIGINT", stop); + process.on("SIGTERM", stop); +} + +if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) { + main().catch((error) => { + console.error(error instanceof Error ? error.message : "Jetson dispatch service failed"); + process.exitCode = 1; + }); +} diff --git a/tools/e2e/jetson-dispatch-worker.mts b/tools/e2e/jetson-dispatch-worker.mts new file mode 100644 index 00000000000..7a17652e544 --- /dev/null +++ b/tools/e2e/jetson-dispatch-worker.mts @@ -0,0 +1,386 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import { spawn } from "node:child_process"; +import fs from "node:fs"; +import path from "node:path"; + +import type { JetsonDispatchRequest } from "./jetson-dispatch-contract.mts"; +import type { + JetsonDeviceIdentity, + JetsonDispatchWorker, + JetsonWorkerResult, +} from "./jetson-dispatch-lifecycle.mts"; + +const MAX_PROCESS_OUTPUT_BYTES = 4 * 1024 * 1024; +const SSH_DESTINATION_PATTERN = + /^[a-z_][a-z0-9_-]{0,31}@[A-Za-z0-9](?:[A-Za-z0-9.-]{0,251}[A-Za-z0-9])?$/u; +const SAFE_PROCESS_ENV = { + LANG: "C.UTF-8", + PATH: "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", +}; + +const DEVICE_IDENTITY_SCRIPT = String.raw`set -eu +clean_line() { tr -d '\000\r\n\t'; } +printf 'model\t' +if [ -r /proc/device-tree/model ]; then clean_line /dev/null 2>&1; then + jetpack_version="$(dpkg-query -W -f='${"${Version}"}' nvidia-jetpack 2>/dev/null || true)" + if [ -n "$jetpack_version" ]; then printf '%s' "$jetpack_version" | clean_line; else printf 'unavailable'; fi +else + printf 'unavailable' +fi +printf '\njetsonLinuxRelease\t' +if [ -r /etc/nv_tegra_release ]; then sed -n '1p' /etc/nv_tegra_release | clean_line; else printf 'unavailable'; fi +printf '\nkernel\t' +uname -r | clean_line +printf '\n' +`; + +const JETSON_TEST_SCRIPT = String.raw`set -euo pipefail +candidate_sha="$1" +job_id="$2" +timeout_seconds="$3" +[[ "$candidate_sha" =~ ^[a-f0-9]{40}$ ]] +[[ "$job_id" =~ ^[a-f0-9]{64}$ ]] +[[ "$timeout_seconds" =~ ^[1-9][0-9]*$ ]] + +workspace_root=/var/tmp/nemoclaw-jetson-e2e +if [ -L "$workspace_root" ]; then + echo "Jetson E2E workspace root must not be a symbolic link" >&2 + exit 1 +fi +install -d -m 0700 "$workspace_root" +workspace="$workspace_root/$job_id" +if [ -e "$workspace" ]; then + echo "Jetson E2E workspace already exists; reset recovery is required" >&2 + exit 1 +fi +install -d -m 0700 "$workspace" +cleanup() { + rm -rf -- "$workspace" +} +trap cleanup EXIT + +git init --quiet "$workspace/repository" +git -C "$workspace/repository" remote add origin https://github.com/NVIDIA/NemoClaw.git +git -C "$workspace/repository" fetch --quiet --depth=1 --no-tags origin "$candidate_sha" +fetched_sha="$(git -C "$workspace/repository" rev-parse FETCH_HEAD)" +[[ "$fetched_sha" == "$candidate_sha" ]] +git -C "$workspace/repository" checkout --quiet --detach "$candidate_sha" +cd "$workspace/repository" + +node_major="$(node -p 'process.versions.node.split(".")[0]')" +[[ "$node_major" == "22" ]] || { + echo "Jetson E2E requires Node.js 22" >&2 + exit 1 +} +npm ci --ignore-scripts +npm run build:cli + +export E2E_JOB=1 +export E2E_TARGET_ID=jetson-nvmap-gpu +export E2E_ARTIFACT_DIR="$workspace/e2e-artifacts/live/jetson-nvmap-gpu" +export NEMOCLAW_CLI_BIN="$workspace/repository/bin/nemoclaw.js" +export NEMOCLAW_RUN_LIVE_E2E=1 +export NEMOCLAW_NON_INTERACTIVE=1 +export NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE=1 +export NEMOCLAW_SANDBOX_NAME=e2e-jetson-nvmap +export NEMOCLAW_RECREATE_SANDBOX=1 +export NEMOCLAW_PROVIDER=ollama +export OPENSHELL_GATEWAY=nemoclaw + +timeout --foreground --signal=TERM --kill-after=30s "${"${timeout_seconds}"}s" \ + npx tsx tools/e2e/live-vitest-invocation.mts run \ + --test-path test/e2e/live/jetson-nvmap-gpu.test.ts +`; + +export interface SshJetsonWorkerConfig { + destination: string; + identityFile: string; + knownHostsFile: string; + resetExecutable: string; + testTimeoutSeconds: number; +} + +function requireSecureFile( + file: string, + options: { executable?: boolean; private?: boolean }, +): void { + if (!path.isAbsolute(file) || /[\u0000-\u001f\u007f]/u.test(file)) { + throw new Error(`${file} must be an absolute path without control characters`); + } + const stat = fs.lstatSync(file); + if (!stat.isFile() || stat.isSymbolicLink()) throw new Error(`${file} must be a regular file`); + if ((stat.mode & 0o022) !== 0) throw new Error(`${file} must not be group- or world-writable`); + if (options.private && (stat.mode & 0o077) !== 0) { + throw new Error(`${file} must be readable only by its owner`); + } + const currentUid = process.getuid?.(); + if (currentUid !== undefined && stat.uid !== currentUid && stat.uid !== 0) { + throw new Error(`${file} must be owned by root or the dispatcher user`); + } + if (options.executable && (stat.mode & 0o111) === 0) { + throw new Error(`${file} must be executable`); + } +} + +function positiveIntegerEnvironment( + value: string | undefined, + name: string, + minimum: number, + maximum: number, +): number { + if (!value || !/^[1-9][0-9]*$/u.test(value)) { + throw new Error(`${name} must be a positive integer`); + } + const parsed = Number(value); + if (!Number.isSafeInteger(parsed) || parsed < minimum || parsed > maximum) { + throw new Error(`${name} must be between ${minimum} and ${maximum}`); + } + return parsed; +} + +export function loadSshJetsonWorkerConfig( + env: NodeJS.ProcessEnv = process.env, +): SshJetsonWorkerConfig { + const destination = env.JETSON_DISPATCH_SSH_DESTINATION ?? ""; + if (!SSH_DESTINATION_PATTERN.test(destination)) { + throw new Error("JETSON_DISPATCH_SSH_DESTINATION must be a fixed user and host"); + } + const identityFile = env.JETSON_DISPATCH_SSH_IDENTITY_FILE ?? ""; + const knownHostsFile = env.JETSON_DISPATCH_SSH_KNOWN_HOSTS_FILE ?? ""; + const resetExecutable = env.JETSON_DISPATCH_RESET_EXECUTABLE ?? ""; + requireSecureFile(identityFile, { private: true }); + requireSecureFile(knownHostsFile, {}); + requireSecureFile(resetExecutable, { executable: true }); + return { + destination, + identityFile, + knownHostsFile, + resetExecutable, + testTimeoutSeconds: positiveIntegerEnvironment( + env.JETSON_DISPATCH_TEST_TIMEOUT_SECONDS, + "JETSON_DISPATCH_TEST_TIMEOUT_SECONDS", + 60, + 50 * 60, + ), + }; +} + +interface ProcessResult { + stdout: string; + stderr: string; +} + +class ProcessFailure extends Error { + readonly result: ProcessResult; + + constructor(message: string, result: ProcessResult) { + super(message); + this.result = result; + } +} + +function runProcess(options: { + executable: string; + args: string[]; + input?: string; + signal: AbortSignal; +}): Promise { + return new Promise((resolve, reject) => { + const child = spawn(options.executable, options.args, { + env: SAFE_PROCESS_ENV, + stdio: ["pipe", "pipe", "pipe"], + }); + const stdout: Buffer[] = []; + const stderr: Buffer[] = []; + let outputBytes = 0; + let settled = false; + let killTimer: NodeJS.Timeout | undefined; + + const finish = (error?: Error, result?: ProcessResult): void => { + if (settled) return; + settled = true; + options.signal.removeEventListener("abort", abort); + if (error) reject(error); + else resolve(result!); + }; + const stop = (): void => { + child.kill("SIGTERM"); + killTimer = setTimeout(() => child.kill("SIGKILL"), 5_000); + killTimer.unref(); + }; + const abort = (): void => stop(); + const collect = (chunks: Buffer[], chunk: Buffer): void => { + if (settled) return; + outputBytes += chunk.length; + if (outputBytes > MAX_PROCESS_OUTPUT_BYTES) { + stop(); + finish(new Error(`Jetson command output exceeds ${MAX_PROCESS_OUTPUT_BYTES} bytes`)); + return; + } + chunks.push(chunk); + }; + + options.signal.addEventListener("abort", abort, { once: true }); + if (options.signal.aborted) abort(); + child.stdout.on("data", (chunk: Buffer) => collect(stdout, chunk)); + child.stderr.on("data", (chunk: Buffer) => collect(stderr, chunk)); + child.stdin.on("error", (error: NodeJS.ErrnoException) => { + if (error.code !== "EPIPE") { + stop(); + finish(error); + } + }); + child.once("error", (error) => finish(error)); + child.once("close", (code, signal) => { + if (killTimer) clearTimeout(killTimer); + if (settled) return; + const result = { + stdout: Buffer.concat(stdout).toString("utf8"), + stderr: Buffer.concat(stderr).toString("utf8"), + }; + if (options.signal.aborted) { + finish(new ProcessFailure("Jetson command was interrupted", result)); + return; + } + if (code !== 0) { + finish( + new ProcessFailure( + `Jetson command exited with ${code ?? `signal ${signal ?? "unknown"}`}: ${result.stderr.slice(-500)}`, + result, + ), + ); + return; + } + finish(undefined, result); + }); + if (options.input !== undefined) child.stdin.end(options.input, "utf8"); + else child.stdin.end(); + }); +} + +function parseDeviceIdentity(output: string): JetsonDeviceIdentity { + if (Buffer.byteLength(output) > 8 * 1024) throw new Error("Jetson identity output is too large"); + const entries = new Map(); + for (const line of output.trimEnd().split("\n")) { + const separator = line.indexOf("\t"); + if (separator < 1) throw new Error("Jetson identity output is malformed"); + const key = line.slice(0, separator); + const value = line.slice(separator + 1); + if (entries.has(key) || value.length === 0 || /[\u0000-\u001f\u007f]/u.test(value)) { + throw new Error("Jetson identity output is malformed"); + } + entries.set(key, value.slice(0, 500)); + } + const expected = ["jetpackVersion", "jetsonLinuxRelease", "kernel", "model"]; + if (entries.size !== expected.length || expected.some((key) => !entries.has(key))) { + throw new Error("Jetson identity output is incomplete"); + } + return { + model: entries.get("model")!, + jetpackVersion: entries.get("jetpackVersion")!, + jetsonLinuxRelease: entries.get("jetsonLinuxRelease")!, + kernel: entries.get("kernel")!, + }; +} + +export class SshJetsonDispatchWorker implements JetsonDispatchWorker { + readonly #config: SshJetsonWorkerConfig; + + constructor(config: SshJetsonWorkerConfig) { + this.#config = config; + } + + async run( + request: JetsonDispatchRequest, + options: { jobId: string; signal: AbortSignal }, + ): Promise { + const identityResult = await runProcess({ + executable: "ssh", + args: [...this.#sshArgs(), this.#config.destination, "bash", "-s"], + input: DEVICE_IDENTITY_SCRIPT, + signal: options.signal, + }); + const device = parseDeviceIdentity(identityResult.stdout); + let testResult: ProcessResult; + try { + testResult = await runProcess({ + executable: "ssh", + args: [ + ...this.#sshArgs(), + this.#config.destination, + "bash", + "-s", + "--", + request.candidateSha, + options.jobId, + String(this.#config.testTimeoutSeconds), + ], + input: JETSON_TEST_SCRIPT, + signal: options.signal, + }); + } catch (error) { + if (error instanceof ProcessFailure) { + const failure = new Error(error.message) as Error & { log: string }; + failure.log = [ + "=== Jetson identity ===", + identityResult.stdout.trimEnd(), + "=== Jetson E2E stdout ===", + error.result.stdout.trimEnd(), + "=== Jetson E2E stderr ===", + error.result.stderr.trimEnd(), + "", + ].join("\n"); + throw failure; + } + throw error; + } + return { + device, + log: [ + "=== Jetson identity ===", + identityResult.stdout.trimEnd(), + "=== Jetson E2E stdout ===", + testResult.stdout.trimEnd(), + "=== Jetson E2E stderr ===", + testResult.stderr.trimEnd(), + "", + ].join("\n"), + }; + } + + async reset(options: { signal: AbortSignal }): Promise { + await runProcess({ + executable: this.#config.resetExecutable, + args: [], + signal: options.signal, + }); + } + + #sshArgs(): string[] { + return [ + "-F", + "/dev/null", + "-T", + "-o", + "BatchMode=yes", + "-o", + "ConnectTimeout=15", + "-o", + "IdentitiesOnly=yes", + "-o", + "ServerAliveCountMax=2", + "-o", + "ServerAliveInterval=15", + "-o", + "StrictHostKeyChecking=yes", + "-o", + `UserKnownHostsFile=${this.#config.knownHostsFile}`, + "-i", + this.#config.identityFile, + ]; + } +} diff --git a/tools/e2e/operations-workflow-boundary.mts b/tools/e2e/operations-workflow-boundary.mts index 65a02a806aa..58655edd16d 100644 --- a/tools/e2e/operations-workflow-boundary.mts +++ b/tools/e2e/operations-workflow-boundary.mts @@ -368,6 +368,11 @@ function validateManualPrDispatch(errors: string[], workflow: OperationsWorkflow step.name === "Checkout trusted llama.cpp qualification" && step.with?.repository === "${{ github.repository }}" && step.with?.ref === "${{ inputs.workflow_sha || github.workflow_sha }}"; + const trustedJetsonControllerCheckout = + jobName === "jetson-nvmap-gpu" && + step.name === "Check out trusted Jetson controller" && + step.with?.repository === "NVIDIA/NemoClaw" && + step.with?.ref === "${{ github.workflow_sha }}"; const trustedCheckout = trustedHermesFixtureCheckout || trustedReportHelperCheckout || @@ -375,7 +380,8 @@ function validateManualPrDispatch(errors: string[], workflow: OperationsWorkflow trustedPublicationCheckout || trustedManagedImageRuntimeCheckout || trustedLlamaCppPlanCheckout || - trustedLlamaCppQualificationCheckout; + trustedLlamaCppQualificationCheckout || + trustedJetsonControllerCheckout; if ( step.uses?.startsWith("actions/checkout@") && step.with?.ref !== "${{ inputs.checkout_sha || github.sha }}" && diff --git a/tools/e2e/upload-e2e-artifacts-workflow-boundary.mts b/tools/e2e/upload-e2e-artifacts-workflow-boundary.mts index c43e8420008..e1fcdf1bb15 100644 --- a/tools/e2e/upload-e2e-artifacts-workflow-boundary.mts +++ b/tools/e2e/upload-e2e-artifacts-workflow-boundary.mts @@ -95,6 +95,13 @@ const EXPLICIT_UPLOAD_CONTRACTS = new Map([ path: "${{ runner.temp }}/nemoclaw-e2e-dispatch/dispatch.json", }, ], + [ + "jetson-nvmap-gpu", + { + name: "e2e-jetson-nvmap-gpu", + path: "${{ runner.temp }}/e2e-artifacts/live/jetson-nvmap-gpu/", + }, + ], [ "retired-selector-compatibility", { @@ -415,6 +422,7 @@ export function validateUploadE2eArtifactsInvocations(workflow: WorkflowRecord): return ( jobName === "staging-brev-launchable" || jobName === "generate-matrix" || + jobName === "jetson-nvmap-gpu" || jobName === "live" || jobName === RETIRED_SELECTOR_COMPATIBILITY_JOB || env.E2E_JOB === "1" || diff --git a/tools/e2e/workflow-boundary.mts b/tools/e2e/workflow-boundary.mts index 9b187c79b15..f74963a2386 100644 --- a/tools/e2e/workflow-boundary.mts +++ b/tools/e2e/workflow-boundary.mts @@ -3958,63 +3958,122 @@ function validateBedrockRuntimeCompatibleAnthropicJob( requireRunDoesNotContain(errors, runVitest, "${{ inputs."); } -function validateAllowJetsonRunnerQueueInput( - errors: string[], - dispatchInputs: WorkflowRecord, -): void { - const input = requireInput(errors, dispatchInputs, "allow_jetson_runner_queue"); +function validateAllowJetsonDispatchInput(errors: string[], dispatchInputs: WorkflowRecord): void { + const input = requireInput(errors, dispatchInputs, "allow_jetson_dispatch"); if (input.type !== "boolean") { - errors.push("workflow_dispatch allow_jetson_runner_queue input must be boolean"); + errors.push("workflow_dispatch allow_jetson_dispatch input must be boolean"); } if (input.default !== false) { - errors.push("workflow_dispatch allow_jetson_runner_queue input must default to false"); + errors.push("workflow_dispatch allow_jetson_dispatch input must default to false"); } const description = stringValue(input.description); if ( - !description.includes("repository administrator confirmation") || - !description.includes("Jetson runner") || - !description.includes("authoritative") || - !description.includes("NVIDIA/NemoClaw Settings -> Actions -> Runners") || - !description.includes("timeout-minutes") + !description.includes("Colossus dispatcher") || + !description.includes("Cloudflare Tunnel") || + !description.includes("reset helper") || + !description.includes("JETSON_DISPATCH_URL") || + !description.includes("test/e2e/docs/jetson-colossus-dispatch.md") ) { errors.push( - "workflow_dispatch allow_jetson_runner_queue input must require repository administrator confirmation from the authoritative NVIDIA/NemoClaw Settings -> Actions -> Runners inventory and document queued timeout behavior", + "workflow_dispatch allow_jetson_dispatch input must require the Colossus dispatcher, tunnel, reset helper, repository URL variable, and deployment checks", ); } } -function validateJetsonJobOptInBoundary(errors: string[], jobs: WorkflowRecord): void { +function validateJetsonControllerBoundary(errors: string[], jobs: WorkflowRecord): void { const job = asRecord(jobs["jetson-nvmap-gpu"]); if (job.needs !== "generate-matrix") { errors.push("jetson-nvmap-gpu job must depend on generate-matrix"); } const trustedSelector = - "${{ inputs.allow_jetson_runner_queue && github.repository == 'NVIDIA/NemoClaw' && github.ref == 'refs/heads/main' && ((github.event_name != 'workflow_dispatch' || (inputs.jobs == '' && inputs.targets == '')) || contains(format(',{0},', inputs.jobs), ',jetson-nvmap-gpu,') || contains(format(',{0},', inputs.targets), ',jetson-nvmap-gpu,')) }}"; + "${{ inputs.allow_jetson_dispatch && github.repository == 'NVIDIA/NemoClaw' && github.ref == 'refs/heads/main' && github.event_name == 'workflow_dispatch' && (inputs.checkout_repository == '' || inputs.checkout_repository == github.repository) && ((inputs.jobs == '' && inputs.targets == '') || contains(format(',{0},', inputs.jobs), ',jetson-nvmap-gpu,') || contains(format(',{0},', inputs.targets), ',jetson-nvmap-gpu,')) }}"; if (job.if !== trustedSelector) { errors.push( - "jetson-nvmap-gpu job must require allow_jetson_runner_queue before runner assignment and retain trusted-main selectors", + "jetson-nvmap-gpu job must require the dispatch opt-in, trusted main workflow dispatch, same-repository candidate, and target selectors", ); } - const configuredRunsOn = - "${{ vars.JETSON_E2E_RUNNER_LABEL || 'linux-arm64-gpu-jetson-orin-latest-1' }}"; - if (job["runs-on"] !== configuredRunsOn) { - errors.push("jetson-nvmap-gpu job must use the configured runner only after job-level opt-in"); + if (job["runs-on"] !== "ubuntu-latest") { + errors.push("jetson-nvmap-gpu controller must use a GitHub-hosted runner"); + } + if (job["timeout-minutes"] !== 60) + errors.push("jetson-nvmap-gpu controller timeout must be 60 minutes"); + if (!isDeepStrictEqual(asRecord(job.permissions), { contents: "read", "id-token": "write" })) { + errors.push("jetson-nvmap-gpu controller must grant only contents:read and id-token:write"); + } + if ( + !isDeepStrictEqual(asRecord(job.env), { + E2E_ARTIFACT_DIR: "${{ runner.temp }}/e2e-artifacts/live/jetson-nvmap-gpu", + }) + ) { + errors.push("jetson-nvmap-gpu controller environment must contain only its artifact directory"); } const steps = asSteps(job.steps); - if (steps.some((step) => step.name === "Guard Jetson runner dispatch")) { - errors.push("jetson-nvmap-gpu must enforce opt-in before runner assignment, not in a step"); + const checkout = namedStep(steps, "Check out trusted Jetson controller"); + if (!checkout || !stringValue(checkout.uses).startsWith("actions/checkout@")) { + errors.push("jetson-nvmap-gpu controller must check out the trusted workflow source"); + } else { + requireFullShaAction(errors, checkout, "jetson-nvmap-gpu trusted checkout"); + if ( + !isDeepStrictEqual(asRecord(checkout.with), { + repository: "NVIDIA/NemoClaw", + ref: "${{ github.workflow_sha }}", + "persist-credentials": false, + }) + ) { + errors.push( + "jetson-nvmap-gpu checkout must use the trusted workflow SHA without credentials", + ); + } + } + const setupNode = namedStep(steps, "Set up Node for Jetson controller"); + if (!setupNode || !stringValue(setupNode.uses).startsWith("actions/setup-node@")) { + errors.push("jetson-nvmap-gpu controller must set up Node.js"); + } else { + requireFullShaAction(errors, setupNode, "jetson-nvmap-gpu Node setup"); + if (asRecord(setupNode.with)["node-version"] !== 22) { + errors.push("jetson-nvmap-gpu controller must use Node.js 22"); + } + } + const dispatch = namedStep(steps, "Dispatch exact commit to Jetson through Colossus"); + if ( + dispatch?.run !== + "node --experimental-strip-types --no-warnings tools/e2e/jetson-dispatch-client.mts" || + !isDeepStrictEqual(asRecord(dispatch?.env), { + JETSON_DISPATCH_CANDIDATE_SHA: "${{ inputs.checkout_sha || github.sha }}", + JETSON_DISPATCH_URL: "${{ vars.JETSON_DISPATCH_URL }}", + }) + ) { + errors.push( + "jetson-nvmap-gpu controller must dispatch only the exact candidate and configured URL", + ); + } + const upload = namedStep(steps, "Upload Jetson nvmap GPU artifacts"); + if ( + upload?.if !== "always()" || + upload.uses !== UPLOAD_E2E_ARTIFACTS_ACTION || + !isDeepStrictEqual(asRecord(upload.with), { + name: "e2e-jetson-nvmap-gpu", + path: "${{ runner.temp }}/e2e-artifacts/live/jetson-nvmap-gpu/", + }) + ) { + errors.push("jetson-nvmap-gpu controller must upload its bounded dispatch artifact"); + } + if (steps.length !== 4) { + errors.push( + "jetson-nvmap-gpu controller must contain only checkout, Node setup, dispatch, and upload", + ); } } -export function validateJetsonRunnerDispatchBoundary(workflow: unknown): string[] { +export function validateJetsonDispatchBoundary(workflow: unknown): string[] { const workflowRecord = asRecord(workflow); const triggers = asRecord(workflowRecord.on ?? workflowRecord[true as unknown as string]); const workflowDispatch = asRecord(triggers.workflow_dispatch); const errors: string[] = []; - validateAllowJetsonRunnerQueueInput(errors, asRecord(workflowDispatch.inputs)); - validateJetsonJobOptInBoundary(errors, asRecord(workflowRecord.jobs)); + validateAllowJetsonDispatchInput(errors, asRecord(workflowDispatch.inputs)); + validateJetsonControllerBoundary(errors, asRecord(workflowRecord.jobs)); return errors; } @@ -4291,7 +4350,8 @@ function validateTrustedE2eDispatchReceipt( const dispatchReceiptEnv = asRecord(dispatchReceipt?.env); const expectedDispatchReceiptEnv = { ALLOW_DGX_SPARK_RUNNER_QUEUE: "${{ inputs.allow_dgx_spark_runner_queue && 'true' || 'false' }}", - ALLOW_JETSON_RUNNER_QUEUE: "${{ inputs.allow_jetson_runner_queue && 'true' || 'false' }}", + ALLOW_JETSON_DISPATCH: "${{ inputs.allow_jetson_dispatch && 'true' || 'false' }}", + ALLOW_JETSON_RUNNER_QUEUE: "false", BASE_SHA: "${{ inputs.checkout_sha != '' && inputs.base_sha || github.sha }}", CANDIDATE_REPOSITORY: "${{ inputs.checkout_repository || github.repository }}", CANDIDATE_SHA: "${{ inputs.checkout_sha || github.sha }}", @@ -4329,6 +4389,7 @@ function validateTrustedE2eDispatchReceipt( "jobs: $jobs", "targets: $targets", "allowDgxSparkRunnerQueue: $allowDgxSparkRunnerQueue", + "allowJetsonDispatch: $allowJetsonDispatch", "allowJetsonRunnerQueue: $allowJetsonRunnerQueue", "includeStagingBrevLaunchable: $includeStagingBrevLaunchable", 'emptySelectors: ($jobs == "" and $targets == "")', @@ -4446,7 +4507,7 @@ export function validateE2eWorkflow(workflowValue: unknown): string[] { if (workflow["run-name"] !== expectedRunName) { errors.push("workflow run-name must expose the unique manual-dispatch correlation ID"); } - errors.push(...validateJetsonRunnerDispatchBoundary(workflow)); + errors.push(...validateJetsonDispatchBoundary(workflow)); const { errors: inventoryErrors, inventory: freeStandingInventory } = deriveFreeStandingJobsInventoryFromJobs(jobs); errors.push(...inventoryErrors); From eaf3d6fccadcd6de0dbfc49a8dfceffbbe70bf60 Mon Sep 17 00:00:00 2001 From: San Dang Date: Mon, 10 Aug 2026 18:51:05 +0700 Subject: [PATCH 02/34] test(e2e): keep Jetson completion polling linear Signed-off-by: San Dang --- test/e2e/support/jetson-dispatch-contract.test.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/test/e2e/support/jetson-dispatch-contract.test.ts b/test/e2e/support/jetson-dispatch-contract.test.ts index 94dc0fa6ebc..ae99ea0b3e5 100644 --- a/test/e2e/support/jetson-dispatch-contract.test.ts +++ b/test/e2e/support/jetson-dispatch-contract.test.ts @@ -106,12 +106,11 @@ async function waitForCompletion( coordinator: JetsonDispatchCoordinator, jobId: string, ): Promise { - for (let attempt = 0; attempt < 100; attempt += 1) { - const status = coordinator.status(jobId); - if (status.state === "completed") return status; - await new Promise((resolve) => setImmediate(resolve)); - } - throw new Error("Jetson dispatch did not complete in the test deadline"); + await vi.waitFor(() => expect(coordinator.status(jobId).state).toBe("completed"), { + interval: 1, + timeout: 1_000, + }); + return coordinator.status(jobId); } function worker( From 6bb1464a3908c2785f95e48ac3ccb922dfb271c6 Mon Sep 17 00:00:00 2001 From: San Dang Date: Mon, 10 Aug 2026 18:56:49 +0700 Subject: [PATCH 03/34] fix(e2e): pin Jetson dispatcher deployment commit Signed-off-by: San Dang --- test/e2e/docs/jetson-colossus-dispatch.md | 19 ++++++++++++++----- .../support/jetson-dispatch-worker.test.ts | 17 +++++++++++++++++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/test/e2e/docs/jetson-colossus-dispatch.md b/test/e2e/docs/jetson-colossus-dispatch.md index 28305a95933..6381f48f65c 100644 --- a/test/e2e/docs/jetson-colossus-dispatch.md +++ b/test/e2e/docs/jetson-colossus-dispatch.md @@ -88,6 +88,7 @@ If a known-image restore and independent attestation cannot be automated, stop t Run these commands on Colossus. Replace the checkout path if the host uses a managed deployment location. The dispatcher requires `/usr/bin/node` 22.19.0 or later. +Replace `REVIEWED_COMMIT_SHA` with the full 40-character SHA of the reviewed commit to deploy. ```bash /usr/bin/node --version @@ -100,13 +101,21 @@ sudo useradd --system --create-home \ --shell /usr/sbin/nologin nemoclaw-jetson-dispatch sudo install -d -o nemoclaw-jetson-dispatch -g nemoclaw-jetson-dispatch -m 0700 \ /var/lib/nemoclaw-jetson-dispatch /etc/nemoclaw-jetson-dispatch -sudo git clone --branch main --single-branch https://github.com/NVIDIA/NemoClaw.git \ - /opt/nemoclaw-jetson-dispatch -git -C /opt/nemoclaw-jetson-dispatch rev-parse HEAD +REVIEWED_COMMIT_SHA=0000000000000000000000000000000000000000 +sudo install -d -o root -g root -m 0755 /opt/nemoclaw-jetson-dispatch +sudo git -C /opt/nemoclaw-jetson-dispatch init +sudo git -C /opt/nemoclaw-jetson-dispatch remote add origin \ + https://github.com/NVIDIA/NemoClaw.git +sudo git -C /opt/nemoclaw-jetson-dispatch fetch --depth=1 --no-tags origin \ + "$REVIEWED_COMMIT_SHA" +sudo git -C /opt/nemoclaw-jetson-dispatch checkout --detach FETCH_HEAD +test "$(sudo git -C /opt/nemoclaw-jetson-dispatch rev-parse HEAD)" = \ + "$REVIEWED_COMMIT_SHA" +test -z "$(sudo git -C /opt/nemoclaw-jetson-dispatch status --short)" ``` -Deploy a reviewed commit and record its commit SHA. -Do not automatically update this checkout. +The two final checks must pass before the dispatcher service starts. +Do not deploy a branch reference or automatically update this checkout. The service runs controller and dispatcher files from this trusted commit. It never checks candidate code out on Colossus. diff --git a/test/e2e/support/jetson-dispatch-worker.test.ts b/test/e2e/support/jetson-dispatch-worker.test.ts index 831f8d854f2..291db550c11 100644 --- a/test/e2e/support/jetson-dispatch-worker.test.ts +++ b/test/e2e/support/jetson-dispatch-worker.test.ts @@ -9,6 +9,10 @@ import { afterEach, describe, expect, it } from "vitest"; import { loadSshJetsonWorkerConfig } from "../../../tools/e2e/jetson-dispatch-worker.mts"; +const dispatcherRunbook = fs.readFileSync( + path.join(process.cwd(), "test/e2e/docs/jetson-colossus-dispatch.md"), + "utf8", +); const temporaryDirectories: string[] = []; afterEach(() => { @@ -40,6 +44,19 @@ function environment(files = deploymentFiles()): NodeJS.ProcessEnv { } describe("Colossus SSH worker deployment boundary", () => { + it("pins dispatcher deployment to one reviewed commit before service startup (#8142)", () => { + const verification = 'test "$(sudo git -C /opt/nemoclaw-jetson-dispatch rev-parse HEAD)" ='; + expect(dispatcherRunbook).toContain( + 'fetch --depth=1 --no-tags origin \\\n "$REVIEWED_COMMIT_SHA"', + ); + expect(dispatcherRunbook).toContain("checkout --detach FETCH_HEAD"); + expect(dispatcherRunbook).toContain(verification); + expect(dispatcherRunbook.indexOf(verification)).toBeLessThan( + dispatcherRunbook.indexOf("## Configure the Dispatcher Service"), + ); + expect(dispatcherRunbook).not.toContain("git clone --branch main"); + }); + it("loads fixed SSH, host-key, timeout, and reset configuration (#8142)", () => { expect(loadSshJetsonWorkerConfig(environment())).toMatchObject({ destination: "nvidia@192.168.55.1", From 4b65478ffebb9c1b88f8c748b3037dd7908cc9de Mon Sep 17 00:00:00 2001 From: San Dang Date: Mon, 10 Aug 2026 18:59:40 +0700 Subject: [PATCH 04/34] docs(e2e): clarify Jetson dispatch code authority Signed-off-by: San Dang --- test/e2e/docs/jetson-colossus-dispatch.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/e2e/docs/jetson-colossus-dispatch.md b/test/e2e/docs/jetson-colossus-dispatch.md index 6381f48f65c..eec505da12c 100644 --- a/test/e2e/docs/jetson-colossus-dispatch.md +++ b/test/e2e/docs/jetson-colossus-dispatch.md @@ -88,7 +88,7 @@ If a known-image restore and independent attestation cannot be automated, stop t Run these commands on Colossus. Replace the checkout path if the host uses a managed deployment location. The dispatcher requires `/usr/bin/node` 22.19.0 or later. -Replace `REVIEWED_COMMIT_SHA` with the full 40-character SHA of the reviewed commit to deploy. +Replace `REVIEWED_COMMIT_SHA` with the full lowercase 40-character SHA of the reviewed commit to deploy. ```bash /usr/bin/node --version @@ -116,7 +116,8 @@ test -z "$(sudo git -C /opt/nemoclaw-jetson-dispatch status --short)" The two final checks must pass before the dispatcher service starts. Do not deploy a branch reference or automatically update this checkout. -The service runs controller and dispatcher files from this trusted commit. +The Colossus service runs the dispatcher files from this trusted commit. +The GitHub-hosted controller runs the client from the trusted workflow commit. It never checks candidate code out on Colossus. Create a dedicated SSH key owned by the service account: From 6969ab337dbc58776124419e8848540144e49305 Mon Sep 17 00:00:00 2001 From: San Dang Date: Mon, 10 Aug 2026 19:18:12 +0700 Subject: [PATCH 05/34] fix(e2e): harden Jetson dispatch boundaries Signed-off-by: San Dang --- .../SKILL.md | 4 +- .../scripts/release-e2e-evidence.mts | 5 +- .github/workflows/e2e.yaml | 3 +- test/e2e-private-file.test.ts | 4 + test/e2e/docs/jetson-colossus-dispatch.md | 5 +- .../support/jetson-dispatch-contract.test.ts | 134 ++++++++++++- .../support/jetson-dispatch-worker.test.ts | 50 ++++- .../support/jetson-workflow-boundary.test.ts | 23 +++ test/release-e2e-evidence.test.ts | 17 +- tools/e2e/jetson-dispatch-client.mts | 181 +++++++++++++----- tools/e2e/jetson-dispatch-lifecycle.mts | 78 +++++++- tools/e2e/jetson-dispatch-service.mts | 57 ++++-- tools/e2e/jetson-dispatch-worker.mts | 103 +++++++--- tools/e2e/private-file.mts | 7 +- tools/e2e/workflow-boundary.mts | 9 +- 15 files changed, 565 insertions(+), 115 deletions(-) diff --git a/.agents/skills/nemoclaw-maintainer-cut-release-tag/SKILL.md b/.agents/skills/nemoclaw-maintainer-cut-release-tag/SKILL.md index b5444dd0285..56962b1681c 100644 --- a/.agents/skills/nemoclaw-maintainer-cut-release-tag/SKILL.md +++ b/.agents/skills/nemoclaw-maintainer-cut-release-tag/SKILL.md @@ -136,7 +136,7 @@ npm run release:e2e-evidence -- \ The preflight derives every required execution from one empty-selector dispatch. The full run includes every default-selected workflow E2E plus `Exact staging Brev Launchable`. -Accepted release evidence requires `allow_jetson_dispatch=false` and `allow_dgx_spark_runner_queue=false`. +Accepted release evidence requires `allowJetsonDispatch: false`, `allowJetsonRunnerQueue: false`, and `allowDgxSparkRunnerQueue: false`. The required denominator excludes `jetson-nvmap-gpu`, `llama-cpp-dgx-spark-plan`, and `llama-cpp-dgx-spark-qualification`. Each job that declares `RELEASE_E2E_ACTIVATION_PATH` requires that path at the candidate SHA. A missing activation path is a preflight failure. @@ -148,7 +148,7 @@ Monitor the dispatched correlation ID with one bounded status query. Before accepting full-mode exact Brev evidence, require: - the workflow `head_sha` to equal the plan candidate SHA; -- the trusted dispatch receipt to prove empty selectors, `include_staging_brev_launchable=true`, `allowJetsonDispatch: false`, `allowJetsonRunnerQueue: false`, and `allowDgxSparkRunnerQueue: false`; +- the trusted dispatch receipt to prove empty selectors, `include_staging_brev_launchable=true`, `allowJetsonRunnerQueue: false`, and `allowDgxSparkRunnerQueue: false`; a v1 receipt may omit `allowJetsonDispatch` but must set it to `false` when present, while a v2 receipt must include `allowJetsonDispatch: false`; - the workflow conclusion to be `success`; - the `Exact staging Brev Launchable` job conclusion to be `success`; - the job URL and selected successful Launchable job attempt; diff --git a/.agents/skills/nemoclaw-maintainer-cut-release-tag/scripts/release-e2e-evidence.mts b/.agents/skills/nemoclaw-maintainer-cut-release-tag/scripts/release-e2e-evidence.mts index 590885f907b..0eba947839a 100644 --- a/.agents/skills/nemoclaw-maintainer-cut-release-tag/scripts/release-e2e-evidence.mts +++ b/.agents/skills/nemoclaw-maintainer-cut-release-tag/scripts/release-e2e-evidence.mts @@ -484,7 +484,10 @@ export function buildReleaseE2eLedger( false, `${label}.dispatch.allowJetsonRunnerQueue`, ); - if (dispatch.kind === "nemoclaw-e2e-dispatch-v2") { + if ( + dispatch.kind === "nemoclaw-e2e-dispatch-v2" || + Object.hasOwn(dispatch, "allowJetsonDispatch") + ) { requireEqual( booleanField(dispatch, "allowJetsonDispatch", `${label}.dispatch`), false, diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index b109d82358c..07d7d894a76 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -4927,8 +4927,6 @@ jobs: permissions: contents: read id-token: write - env: - E2E_ARTIFACT_DIR: ${{ runner.temp }}/e2e-artifacts/live/jetson-nvmap-gpu steps: - name: Check out trusted Jetson controller uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 @@ -4944,6 +4942,7 @@ jobs: - name: Dispatch exact commit to Jetson through Colossus env: + E2E_ARTIFACT_DIR: ${{ runner.temp }}/e2e-artifacts/live/jetson-nvmap-gpu JETSON_DISPATCH_CANDIDATE_SHA: ${{ inputs.checkout_sha || github.sha }} JETSON_DISPATCH_URL: ${{ vars.JETSON_DISPATCH_URL }} run: node --experimental-strip-types --no-warnings tools/e2e/jetson-dispatch-client.mts diff --git a/test/e2e-private-file.test.ts b/test/e2e-private-file.test.ts index bf313088e62..a61a5a23ce8 100644 --- a/test/e2e-private-file.test.ts +++ b/test/e2e-private-file.test.ts @@ -18,6 +18,7 @@ describe("private E2E controller files", () => { it("writes private regular files without following links or truncating hardlink targets", () => { const directory = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-private-file-")); const regular = path.join(directory, "regular.json"); + const binary = path.join(directory, "artifact.tar.gz"); const target = path.join(directory, "target.json"); const symlink = path.join(directory, "symlink.json"); const hardlink = path.join(directory, "hardlink.json"); @@ -28,6 +29,9 @@ describe("private E2E controller files", () => { writePrivateRegularFile(regular, "updated\n"); appendPrivateRegularFile(regular, "appended\n", { maxBytes: 64 }); expect(readPrivateRegularFile(regular, { maxBytes: 64 })).toBe("updated\nappended\n"); + writePrivateRegularFile(binary, Uint8Array.from([0, 255, 31, 139])); + expect(fs.readFileSync(binary)).toEqual(Buffer.from([0, 255, 31, 139])); + expect(fs.statSync(binary).mode & 0o777).toBe(0o600); fs.writeFileSync(target, "protected\n"); fs.symlinkSync(target, symlink); diff --git a/test/e2e/docs/jetson-colossus-dispatch.md b/test/e2e/docs/jetson-colossus-dispatch.md index eec505da12c..41fca171018 100644 --- a/test/e2e/docs/jetson-colossus-dispatch.md +++ b/test/e2e/docs/jetson-colossus-dispatch.md @@ -118,7 +118,7 @@ The two final checks must pass before the dispatcher service starts. Do not deploy a branch reference or automatically update this checkout. The Colossus service runs the dispatcher files from this trusted commit. The GitHub-hosted controller runs the client from the trusted workflow commit. -It never checks candidate code out on Colossus. +The Colossus service never checks out candidate code. Create a dedicated SSH key owned by the service account: @@ -372,6 +372,9 @@ The uploaded `e2e-jetson-nvmap-gpu` artifact must contain `jetson-dispatch.json` - The test conclusion and bounded log. - `reset: "succeeded"` before `conclusion: "success"`. +It must also contain `jetson-e2e-artifacts.tar.gz`. +The dispatcher creates that archive from the remote E2E artifact directory before it removes the candidate workspace and rejects archives larger than 1 MiB. + After the workflow completes, independently rerun the baseline checks. Then run one controlled failing candidate and confirm that its artifact records the same reset evidence. For a cancellation proof, cancel a controller after it logs the job ID. diff --git a/test/e2e/support/jetson-dispatch-contract.test.ts b/test/e2e/support/jetson-dispatch-contract.test.ts index ae99ea0b3e5..ce5c21ab2b7 100644 --- a/test/e2e/support/jetson-dispatch-contract.test.ts +++ b/test/e2e/support/jetson-dispatch-contract.test.ts @@ -8,7 +8,10 @@ import os from "node:os"; import path from "node:path"; import { afterEach, describe, expect, it, vi } from "vitest"; - +import { + createGitHubOidcTokenProvider, + pollJetsonDispatch, +} from "../../../tools/e2e/jetson-dispatch-client.mts"; import { createGitHubJwksResolver, JETSON_DISPATCH_AUDIENCE, @@ -21,6 +24,7 @@ import { import { JetsonDispatchBusyError, JetsonDispatchCoordinator, + JetsonDispatchNotFoundError, type JetsonDispatchStatus, type JetsonDispatchWorker, } from "../../../tools/e2e/jetson-dispatch-lifecycle.mts"; @@ -30,6 +34,7 @@ const NOW_SECONDS = 1_800_000_000; const REPOSITORY_ID = "987654321"; const CANDIDATE_SHA = "a".repeat(40); const WORKFLOW_SHA = "b".repeat(40); +const ARTIFACT_ARCHIVE_BASE64 = Buffer.from("bounded archive").toString("base64"); const REQUEST = parseJetsonDispatchRequest({ schemaVersion: 1, target: JETSON_DISPATCH_TARGET, @@ -42,6 +47,7 @@ const temporaryDirectories: string[] = []; afterEach(() => { vi.useRealTimers(); + vi.restoreAllMocks(); for (const directory of temporaryDirectories.splice(0)) { fs.rmSync(directory, { force: true, recursive: true }); } @@ -120,6 +126,7 @@ function worker( run: options.run ?? (async () => ({ + artifactArchiveBase64: ARTIFACT_ARCHIVE_BASE64, device: { model: "NVIDIA Jetson AGX Thor Developer Kit", jetpackVersion: "7.2.2", @@ -177,6 +184,24 @@ describe("Jetson dispatch request and OIDC boundary", () => { expect(verified).toEqual(identity()); }); + it("reuses each GitHub OIDC token for a bounded polling interval (#8142)", async () => { + let nowMs = 1_000; + const fetchImpl = vi.fn(async () => Response.json({ value: `token-${nowMs}` })); + const token = createGitHubOidcTokenProvider({ fetchImpl, now: () => nowMs }); + const env = { + ACTIONS_ID_TOKEN_REQUEST_TOKEN: "request-token", + ACTIONS_ID_TOKEN_REQUEST_URL: "https://token.actions.test/id-token", + }; + + await expect(token(env)).resolves.toBe("token-1000"); + nowMs += 60_000; + await expect(token(env)).resolves.toBe("token-1000"); + nowMs += 4 * 60_000; + await expect(token(env)).resolves.toBe("token-301000"); + + expect(fetchImpl).toHaveBeenCalledTimes(2); + }); + it.each([ ["issuer", { iss: "https://example.test" }], ["audience", { aud: "another-service" }], @@ -259,7 +284,10 @@ describe("Jetson single-device lifecycle", () => { device: { model: "NVIDIA Jetson AGX Thor Developer Kit" }, }); expect(reset).toHaveBeenCalledOnce(); - expect(dispatch.artifact(accepted.jobId).log).toBe("passed\n"); + expect(dispatch.artifact(accepted.jobId)).toMatchObject({ + artifactArchiveBase64: ARTIFACT_ARCHIVE_BASE64, + log: "passed\n", + }); }); it("rejects a second job while the Jetson lock is held (#8142)", async () => { @@ -314,12 +342,47 @@ describe("Jetson single-device lifecycle", () => { await dispatch.initialize(); const accepted = dispatch.dispatch(REQUEST, identity()); await vi.advanceTimersByTimeAsync(60_000); - const completed = dispatch.status(accepted.jobId); + const completed = await waitForCompletion(dispatch, accepted.jobId); expect(completed).toMatchObject({ conclusion: "timed-out", reset: "succeeded" }); expect(reset).toHaveBeenCalledOnce(); }); + it("keeps reset evidence accurate when lock removal fails (#8142)", async () => { + const reset = vi.fn(async () => {}); + vi.spyOn(fs, "unlinkSync").mockImplementationOnce(() => { + throw new Error("lock filesystem unavailable"); + }); + const dispatch = coordinator(temporaryDirectory(), worker({ reset })); + await dispatch.initialize(); + const accepted = dispatch.dispatch(REQUEST, identity()); + const completed = await waitForCompletion(dispatch, accepted.jobId); + + expect(completed).toMatchObject({ + conclusion: "reset-failed", + error: "Jetson lock removal failed: lock filesystem unavailable", + reset: "succeeded", + }); + }); + + it("bounds retained in-memory job status while preserving private evidence (#8142)", async () => { + const stateDirectory = temporaryDirectory(); + const dispatch = coordinator(stateDirectory, worker()); + await dispatch.initialize(); + let firstJobId = ""; + for (let index = 0; index < 129; index += 1) { + const accepted = dispatch.dispatch( + { ...REQUEST, candidateSha: index.toString(16).padStart(40, "0") }, + identity(), + ); + firstJobId ||= accepted.jobId; + await waitForCompletion(dispatch, accepted.jobId); + } + + expect(() => dispatch.status(firstJobId)).toThrow(JetsonDispatchNotFoundError); + expect(fs.existsSync(path.join(stateDirectory, `${firstJobId}.json`))).toBe(true); + }); + it("keeps the device locked when reset fails (#8142)", async () => { const stateDirectory = temporaryDirectory(); const dispatch = coordinator( @@ -353,6 +416,60 @@ describe("Jetson single-device lifecycle", () => { }); describe("Jetson dispatch HTTP boundary", () => { + it("retries transient status failures and cancels after the bounded limit (#8142)", async () => { + vi.spyOn(console, "warn").mockImplementation(() => {}); + const jobId = "d".repeat(64); + const initialStatus: JetsonDispatchStatus = { + schemaVersion: 1, + jobId, + request: REQUEST, + state: "queued", + createdAt: new Date(0).toISOString(), + reset: "pending", + }; + const completed = { + job: { + ...initialStatus, + state: "completed", + conclusion: "success", + reset: "succeeded", + }, + }; + const recoveredRequest = vi + .fn() + .mockRejectedValueOnce(new Error("tunnel reset")) + .mockRejectedValueOnce(new Error("tunnel reset")) + .mockResolvedValueOnce(completed); + + await expect( + pollJetsonDispatch({ + baseUrl: new URL("https://dispatch.test/"), + deadlineMs: 10_000, + initialStatus, + jobId, + now: () => 0, + request: recoveredRequest, + wait: async () => {}, + }), + ).resolves.toMatchObject({ state: "completed" }); + + const failedRequest = vi.fn().mockRejectedValue(new Error("tunnel unavailable")); + await expect( + pollJetsonDispatch({ + baseUrl: new URL("https://dispatch.test/"), + deadlineMs: 10_000, + initialStatus, + jobId, + now: () => 0, + request: failedRequest, + wait: async () => {}, + }), + ).rejects.toThrow("tunnel unavailable"); + expect(failedRequest).toHaveBeenLastCalledWith( + expect.objectContaining({ method: "DELETE", path: `v1/jobs/${jobId}` }), + ); + }); + it("denies anonymous requests and returns authenticated result evidence (#8142)", async () => { const keys = signingKeys(); const now = Math.floor(Date.now() / 1_000); @@ -397,6 +514,17 @@ describe("Jetson dispatch HTTP boundary", () => { const acceptedBody = (await accepted.json()) as { job: { jobId: string } }; await waitForCompletion(dispatch, acceptedBody.job.jobId); + const anonymousExisting = await fetch(`${url}/${acceptedBody.job.jobId}`); + const anonymousUnknown = await fetch(`${url}/${"f".repeat(64)}`); + const authenticatedUnknown = await fetch(`${url}/${"f".repeat(64)}`, { + headers: { Authorization: `Bearer ${token}` }, + }); + expect([ + anonymousExisting.status, + anonymousUnknown.status, + authenticatedUnknown.status, + ]).toEqual([401, 401, 401]); + const artifact = await fetch(`${url}/${acceptedBody.job.jobId}/artifact`, { headers: { Authorization: `Bearer ${token}` }, }); diff --git a/test/e2e/support/jetson-dispatch-worker.test.ts b/test/e2e/support/jetson-dispatch-worker.test.ts index 291db550c11..3ee75abbdab 100644 --- a/test/e2e/support/jetson-dispatch-worker.test.ts +++ b/test/e2e/support/jetson-dispatch-worker.test.ts @@ -5,9 +5,12 @@ import fs from "node:fs"; import os from "node:os"; import path from "node:path"; -import { afterEach, describe, expect, it } from "vitest"; +import { afterEach, describe, expect, it, vi } from "vitest"; -import { loadSshJetsonWorkerConfig } from "../../../tools/e2e/jetson-dispatch-worker.mts"; +import { + loadSshJetsonWorkerConfig, + SshJetsonDispatchWorker, +} from "../../../tools/e2e/jetson-dispatch-worker.mts"; const dispatcherRunbook = fs.readFileSync( path.join(process.cwd(), "test/e2e/docs/jetson-colossus-dispatch.md"), @@ -58,12 +61,53 @@ describe("Colossus SSH worker deployment boundary", () => { }); it("loads fixed SSH, host-key, timeout, and reset configuration (#8142)", () => { - expect(loadSshJetsonWorkerConfig(environment())).toMatchObject({ + const files = deploymentFiles(); + expect(loadSshJetsonWorkerConfig(environment(files))).toEqual({ destination: "nvidia@192.168.55.1", + identityFile: files.identityFile, + knownHostsFile: files.knownHostsFile, + resetExecutable: files.resetExecutable, testTimeoutSeconds: 2700, }); }); + it("collects a bounded artifact archive before the remote workspace is removed (#8142)", async () => { + const files = deploymentFiles(); + const artifactArchiveBase64 = Buffer.from("remote archive").toString("base64"); + const processRunner = vi + .fn() + .mockResolvedValueOnce({ + stdout: + "model\tNVIDIA Jetson AGX Thor Developer Kit\njetpackVersion\t7.2.2\njetsonLinuxRelease\tR38\nkernel\t6.8.12-tegra\n", + stderr: "", + }) + .mockResolvedValueOnce({ stdout: "test passed\n", stderr: "" }) + .mockResolvedValueOnce({ stdout: artifactArchiveBase64, stderr: "" }); + const worker = new SshJetsonDispatchWorker( + loadSshJetsonWorkerConfig(environment(files)), + processRunner, + ); + + await expect( + worker.run( + { + schemaVersion: 1, + target: "jetson-nvmap-gpu", + candidateSha: "a".repeat(40), + workflowRunId: "123", + workflowRunAttempt: 1, + }, + { jobId: "b".repeat(64), signal: new AbortController().signal }, + ), + ).resolves.toMatchObject({ + artifactArchiveBase64, + log: expect.stringContaining("test passed"), + }); + expect(processRunner.mock.calls[1]![0].input).not.toContain("trap cleanup EXIT"); + expect(processRunner.mock.calls[2]![0].input).toContain("trap cleanup EXIT"); + expect(processRunner.mock.calls[2]![0].input).toContain("base64 --wrap=0"); + }); + it.each([ "nvidia@192.168.55.1 -o StrictHostKeyChecking=no", "nvidia@host;uname", diff --git a/test/e2e/support/jetson-workflow-boundary.test.ts b/test/e2e/support/jetson-workflow-boundary.test.ts index be30033007c..d53146dd3d3 100644 --- a/test/e2e/support/jetson-workflow-boundary.test.ts +++ b/test/e2e/support/jetson-workflow-boundary.test.ts @@ -77,6 +77,29 @@ describe("Jetson nvmap GPU E2E workflow boundary", () => { ); }); + it("keeps the runner temporary artifact path on the dispatch step (#8142)", () => { + const errors = validateWorkflowMutation((workflow) => { + const job = (workflow.jobs as Record)["jetson-nvmap-gpu"] as { + env?: Record; + steps?: Array<{ env?: Record; name?: string }>; + }; + job.env = { + E2E_ARTIFACT_DIR: "${{ runner.temp }}/e2e-artifacts/live/jetson-nvmap-gpu", + }; + const dispatch = job.steps!.find( + (step) => step.name === "Dispatch exact commit to Jetson through Colossus", + )!; + dispatch.env!.E2E_ARTIFACT_DIR = "${{ github.workspace }}/e2e-artifacts"; + }); + + expect(errors).toEqual( + expect.arrayContaining([ + "jetson-nvmap-gpu controller must not define a job-level environment", + "jetson-nvmap-gpu controller must dispatch only the exact candidate and configured URL", + ]), + ); + }); + it("accepts the real workflow without Jetson dispatch errors (#8142)", () => { expect(validateJetsonDispatchBoundary(readWorkflow())).toEqual([]); expect(validateE2eWorkflowBoundary()).toEqual([]); diff --git a/test/release-e2e-evidence.test.ts b/test/release-e2e-evidence.test.ts index 32208b4f8db..203fe95bd93 100644 --- a/test/release-e2e-evidence.test.ts +++ b/test/release-e2e-evidence.test.ts @@ -275,18 +275,19 @@ describe("release E2E evidence", () => { }); it.each([ - ["allowJetsonDispatch", "runs[0].dispatch.allowJetsonDispatch must equal false", 2 as const], + [2 as const, "allowJetsonDispatch", "runs[0].dispatch.allowJetsonDispatch must equal false"], + [1 as const, "allowJetsonDispatch", "runs[0].dispatch.allowJetsonDispatch must equal false"], [ + 1 as const, "allowJetsonRunnerQueue", "runs[0].dispatch.allowJetsonRunnerQueue must equal false", - 1 as const, ], [ + 1 as const, "allowDgxSparkRunnerQueue", "runs[0].dispatch.allowDgxSparkRunnerQueue must equal false", - 1 as const, ], - ])("rejects release evidence that opts into %s", (field, message, receiptVersion) => { + ])("rejects v%s release evidence that opts into %s", (receiptVersion, field, message) => { const plan = preflight(); const evidence = runEvidence(plan, "default", { receiptVersion }); (evidence.dispatch as Record)[field] = true; @@ -294,6 +295,14 @@ describe("release E2E evidence", () => { expect(() => buildReleaseE2eLedger(plan, [evidence])).toThrow(message); }); + it("keeps allowJetsonDispatch optional for v1 release evidence", () => { + const plan = preflight(); + const evidence = runEvidence(plan, "default", { receiptVersion: 1 }); + delete (evidence.dispatch as Record).allowJetsonDispatch; + + expect(buildReleaseE2eLedger(plan, [evidence]).missingCount).toBe(0); + }); + it("reports a failed matrix row without collapsing its successful siblings", () => { const plan = preflight(); const failedId = 'hermes-gpu-startup[scenario="fallback",sandbox_name="e2e-hgpu-fallback"]'; diff --git a/tools/e2e/jetson-dispatch-client.mts b/tools/e2e/jetson-dispatch-client.mts index a973243f3fe..360550b5d1f 100644 --- a/tools/e2e/jetson-dispatch-client.mts +++ b/tools/e2e/jetson-dispatch-client.mts @@ -10,13 +10,19 @@ import { JETSON_DISPATCH_TARGET, parseJetsonDispatchRequest, } from "./jetson-dispatch-contract.mts"; -import type { JetsonDispatchArtifact, JetsonDispatchStatus } from "./jetson-dispatch-lifecycle.mts"; +import { + decodeJetsonArtifactArchive, + type JetsonDispatchArtifact, + type JetsonDispatchStatus, +} from "./jetson-dispatch-lifecycle.mts"; import { writePrivateRegularFile } from "./private-file.mts"; const MAX_STATUS_BYTES = 64 * 1024; const MAX_ARTIFACT_BYTES = 5 * 1024 * 1024; const POLL_INTERVAL_MS = 10_000; const MAX_WAIT_MS = 54 * 60_000; +const MAX_CONSECUTIVE_POLL_FAILURES = 3; +const OIDC_TOKEN_CACHE_MS = 4 * 60_000; const JOB_ID_PATTERN = /^[a-f0-9]{64}$/u; function record(value: unknown, name: string): Record { @@ -43,29 +49,60 @@ function dispatcherBaseUrl(value: string | undefined): URL { return url; } -async function githubOidcToken(env: NodeJS.ProcessEnv = process.env): Promise { - const requestUrlValue = env.ACTIONS_ID_TOKEN_REQUEST_URL; - const requestToken = env.ACTIONS_ID_TOKEN_REQUEST_TOKEN; - if (!requestUrlValue || !requestToken) throw new Error("GitHub OIDC environment is unavailable"); - const requestUrl = new URL(requestUrlValue); - if (requestUrl.protocol !== "https:") throw new Error("GitHub OIDC request URL must use HTTPS"); - requestUrl.searchParams.set("audience", JETSON_DISPATCH_AUDIENCE); - const response = await fetch(requestUrl, { - headers: { Authorization: `Bearer ${requestToken}` }, - signal: AbortSignal.timeout(15_000), - }); - if (!response.ok) throw new Error(`GitHub OIDC token request returned HTTP ${response.status}`); - const payload = record(await response.json(), "GitHub OIDC token response"); - if ( - typeof payload.value !== "string" || - payload.value.length === 0 || - payload.value.length > 16 * 1024 - ) { - throw new Error("GitHub OIDC token response is invalid"); - } - return payload.value; +export function createGitHubOidcTokenProvider( + options: { fetchImpl?: typeof fetch; now?: () => number } = {}, +): (env?: NodeJS.ProcessEnv) => Promise { + const fetchImpl = options.fetchImpl ?? fetch; + const now = options.now ?? Date.now; + let cached: + | { expiresAtMs: number; requestToken: string; requestUrlValue: string; value: string } + | undefined; + return async (env: NodeJS.ProcessEnv = process.env): Promise => { + const requestUrlValue = env.ACTIONS_ID_TOKEN_REQUEST_URL; + const requestToken = env.ACTIONS_ID_TOKEN_REQUEST_TOKEN; + if (!requestUrlValue || !requestToken) { + throw new Error("GitHub OIDC environment is unavailable"); + } + if ( + cached && + cached.requestUrlValue === requestUrlValue && + cached.requestToken === requestToken && + now() < cached.expiresAtMs + ) { + return cached.value; + } + const requestUrl = new URL(requestUrlValue); + if (requestUrl.protocol !== "https:") { + throw new Error("GitHub OIDC request URL must use HTTPS"); + } + requestUrl.searchParams.set("audience", JETSON_DISPATCH_AUDIENCE); + const response = await fetchImpl(requestUrl, { + headers: { Authorization: `Bearer ${requestToken}` }, + signal: AbortSignal.timeout(15_000), + }); + if (!response.ok) { + throw new Error(`GitHub OIDC token request returned HTTP ${response.status}`); + } + const payload = record(await response.json(), "GitHub OIDC token response"); + if ( + typeof payload.value !== "string" || + payload.value.length === 0 || + payload.value.length > 16 * 1024 + ) { + throw new Error("GitHub OIDC token response is invalid"); + } + cached = { + expiresAtMs: now() + OIDC_TOKEN_CACHE_MS, + requestToken, + requestUrlValue, + value: payload.value, + }; + return payload.value; + }; } +const githubOidcToken = createGitHubOidcTokenProvider(); + async function dispatcherRequest(options: { baseUrl: URL; method: "DELETE" | "GET" | "POST"; @@ -146,6 +183,12 @@ function validateArtifact(value: unknown, jobId: string): JetsonDispatchArtifact ) { throw new Error("Jetson dispatcher returned an invalid artifact"); } + if (artifact.artifactArchiveBase64 !== undefined) { + decodeJetsonArtifactArchive(artifact.artifactArchiveBase64); + } + if (status.conclusion === "success" && artifact.artifactArchiveBase64 === undefined) { + throw new Error("Successful Jetson dispatch did not return its E2E artifact archive"); + } return artifact as unknown as JetsonDispatchArtifact; } @@ -153,6 +196,61 @@ function delay(milliseconds: number): Promise { return new Promise((resolve) => setTimeout(resolve, milliseconds)); } +export async function pollJetsonDispatch(options: { + baseUrl: URL; + deadlineMs: number; + initialStatus: JetsonDispatchStatus; + jobId: string; + now?: () => number; + request?: typeof dispatcherRequest; + stopping?: () => boolean; + wait?: typeof delay; +}): Promise { + const now = options.now ?? Date.now; + const request = options.request ?? dispatcherRequest; + const wait = options.wait ?? delay; + let consecutiveFailures = 0; + let status = options.initialStatus; + while (status.state !== "completed") { + if (options.stopping?.()) throw new Error("Jetson dispatch cancellation requested"); + if (now() >= options.deadlineMs) { + await request({ + baseUrl: options.baseUrl, + method: "DELETE", + path: `v1/jobs/${options.jobId}`, + maxBytes: MAX_STATUS_BYTES, + }); + throw new Error("Jetson dispatcher did not complete before the controller deadline"); + } + await wait(POLL_INTERVAL_MS); + try { + status = validateStatus( + await request({ + baseUrl: options.baseUrl, + method: "GET", + path: `v1/jobs/${options.jobId}`, + maxBytes: MAX_STATUS_BYTES, + }), + ); + consecutiveFailures = 0; + console.log(`Jetson dispatch state: ${status.state}`); + } catch (error) { + consecutiveFailures += 1; + if (consecutiveFailures >= MAX_CONSECUTIVE_POLL_FAILURES) { + await request({ + baseUrl: options.baseUrl, + method: "DELETE", + path: `v1/jobs/${options.jobId}`, + maxBytes: MAX_STATUS_BYTES, + }).catch(() => undefined); + throw error; + } + console.warn("Jetson dispatch status request failed; retrying"); + } + } + return status; +} + async function main(): Promise { const request = parseJetsonDispatchRequest({ schemaVersion: 1, @@ -200,29 +298,13 @@ async function main(): Promise { jobId = dispatched.jobId; console.log(`Jetson dispatch accepted as ${jobId}`); const deadline = Date.now() + MAX_WAIT_MS; - let status = dispatched; - while (status.state !== "completed") { - if (stopping) throw new Error("Jetson dispatch cancellation requested"); - if (Date.now() >= deadline) { - await dispatcherRequest({ - baseUrl, - method: "DELETE", - path: `v1/jobs/${jobId}`, - maxBytes: MAX_STATUS_BYTES, - }); - throw new Error("Jetson dispatcher did not complete before the controller deadline"); - } - await delay(POLL_INTERVAL_MS); - status = validateStatus( - await dispatcherRequest({ - baseUrl, - method: "GET", - path: `v1/jobs/${jobId}`, - maxBytes: MAX_STATUS_BYTES, - }), - ); - console.log(`Jetson dispatch state: ${status.state}`); - } + const status = await pollJetsonDispatch({ + baseUrl, + deadlineMs: deadline, + initialStatus: dispatched, + jobId, + stopping: () => stopping, + }); const artifactValue = await dispatcherRequest({ baseUrl, @@ -231,10 +313,17 @@ async function main(): Promise { maxBytes: MAX_ARTIFACT_BYTES, }); const artifact = validateArtifact(artifactValue, jobId); + const { artifactArchiveBase64, ...artifactReceipt } = artifact; writePrivateRegularFile( path.join(artifactDirectory, "jetson-dispatch.json"), - `${JSON.stringify(artifact, null, 2)}\n`, + `${JSON.stringify(artifactReceipt, null, 2)}\n`, ); + if (artifactArchiveBase64 !== undefined) { + writePrivateRegularFile( + path.join(artifactDirectory, "jetson-e2e-artifacts.tar.gz"), + decodeJetsonArtifactArchive(artifactArchiveBase64), + ); + } console.log(`Jetson dispatch conclusion: ${artifact.status.conclusion}`); if (artifact.status.conclusion !== "success") process.exitCode = 1; } diff --git a/tools/e2e/jetson-dispatch-lifecycle.mts b/tools/e2e/jetson-dispatch-lifecycle.mts index 588f7ef2115..1dec8c7d571 100644 --- a/tools/e2e/jetson-dispatch-lifecycle.mts +++ b/tools/e2e/jetson-dispatch-lifecycle.mts @@ -12,6 +12,10 @@ import { } from "./private-file.mts"; const MAX_LOG_BYTES = 4 * 1024 * 1024; +const MAX_RETAINED_JOB_STATUSES = 128; +export const MAX_JETSON_ARTIFACT_ARCHIVE_BYTES = 1024 * 1024; +const MAX_JETSON_ARTIFACT_ARCHIVE_BASE64_CHARACTERS = + Math.ceil(MAX_JETSON_ARTIFACT_ARCHIVE_BYTES / 3) * 4; export type JetsonDispatchConclusion = | "cancelled" @@ -30,6 +34,7 @@ export interface JetsonDeviceIdentity { export interface JetsonWorkerResult { device: JetsonDeviceIdentity; log: string; + artifactArchiveBase64?: string; } export interface JetsonDispatchWorker { @@ -57,6 +62,7 @@ export interface JetsonDispatchStatus { export interface JetsonDispatchArtifact { status: JetsonDispatchStatus; log: string; + artifactArchiveBase64?: string; } export class JetsonDispatchBusyError extends Error {} @@ -75,6 +81,35 @@ function workerErrorLog(error: unknown): string | undefined { return log; } +export function decodeJetsonArtifactArchive(value: unknown): Buffer { + if ( + typeof value !== "string" || + value.length === 0 || + value.length > MAX_JETSON_ARTIFACT_ARCHIVE_BASE64_CHARACTERS || + !/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/u.test(value) + ) { + throw new Error("Jetson artifact archive must be bounded canonical base64"); + } + const decoded = Buffer.from(value, "base64"); + if (decoded.length > MAX_JETSON_ARTIFACT_ARCHIVE_BYTES || decoded.toString("base64") !== value) { + throw new Error("Jetson artifact archive must be bounded canonical base64"); + } + return decoded; +} + +function workerErrorArtifactArchive(error: unknown): string | undefined { + if (!error || typeof error !== "object" || !("artifactArchiveBase64" in error)) { + return undefined; + } + const value = (error as { artifactArchiveBase64?: unknown }).artifactArchiveBase64; + try { + decodeJetsonArtifactArchive(value); + return value as string; + } catch { + return undefined; + } +} + function ensurePrivateDirectory(directory: string): void { fs.mkdirSync(directory, { recursive: true, mode: 0o700 }); const stat = fs.lstatSync(directory); @@ -178,6 +213,7 @@ export class JetsonDispatchCoordinator { if (this.#activeJobId) { throw new JetsonDispatchBusyError("Jetson device is already running another job"); } + this.#evictOldestCompletedJob(); try { createPrivateRegularFile(this.#lockPath, `${jobId}\n`); @@ -246,7 +282,16 @@ export class JetsonDispatchCoordinator { if (status.state !== "completed") throw new JetsonDispatchBusyError("Jetson job is not complete"); const log = readPrivateRegularFile(this.#logPath(jobId), { maxBytes: MAX_LOG_BYTES }) ?? ""; - return { status, log }; + const artifactArchiveBase64 = readPrivateRegularFile(this.#artifactPath(jobId), { + allowMissing: true, + maxBytes: MAX_JETSON_ARTIFACT_ARCHIVE_BASE64_CHARACTERS, + }); + if (artifactArchiveBase64 !== null) decodeJetsonArtifactArchive(artifactArchiveBase64); + return { + status, + log, + ...(artifactArchiveBase64 === null ? {} : { artifactArchiveBase64 }), + }; } async #run(status: JetsonDispatchStatus): Promise { @@ -273,6 +318,10 @@ export class JetsonDispatchCoordinator { throw new Error(`Jetson log exceeds ${MAX_LOG_BYTES} bytes`); } writePrivateRegularFile(this.#logPath(status.jobId), result.log); + if (result.artifactArchiveBase64 !== undefined) { + decodeJetsonArtifactArchive(result.artifactArchiveBase64); + writePrivateRegularFile(this.#artifactPath(status.jobId), result.artifactArchiveBase64); + } status.device = result.device; conclusion = "success"; } catch (error) { @@ -280,6 +329,10 @@ export class JetsonDispatchCoordinator { conclusion = timedOut ? "timed-out" : this.#cancelRequested ? "cancelled" : "failure"; try { writePrivateRegularFile(this.#logPath(status.jobId), workerErrorLog(error) ?? ""); + const artifactArchiveBase64 = workerErrorArtifactArchive(error); + if (artifactArchiveBase64 !== undefined) { + writePrivateRegularFile(this.#artifactPath(status.jobId), artifactArchiveBase64); + } } catch (logError) { status.error = `${status.error}; log persistence failed: ${safeError(logError)}`.slice( 0, @@ -291,12 +344,19 @@ export class JetsonDispatchCoordinator { try { await withTimeout(this.#resetTimeoutMs, (signal) => this.#worker.reset({ signal })); status.reset = "succeeded"; - fs.unlinkSync(this.#lockPath); } catch (error) { status.reset = "failed"; status.error = `Jetson reset failed: ${safeError(error)}`; conclusion = "reset-failed"; } + if (status.reset === "succeeded") { + try { + fs.unlinkSync(this.#lockPath); + } catch (error) { + status.error = `Jetson lock removal failed: ${safeError(error)}`; + conclusion = "reset-failed"; + } + } status.conclusion = conclusion; status.state = "completed"; status.completedAt = new Date().toISOString(); @@ -326,6 +386,20 @@ export class JetsonDispatchCoordinator { return path.join(this.#stateDirectory, `${jobId}.log`); } + #artifactPath(jobId: string): string { + return path.join(this.#stateDirectory, `${jobId}.artifacts.tar.gz.b64`); + } + + #evictOldestCompletedJob(): void { + if (this.#jobs.size < MAX_RETAINED_JOB_STATUSES) return; + for (const [jobId, status] of this.#jobs) { + if (status.state === "completed") { + this.#jobs.delete(jobId); + return; + } + } + } + #requireInitialized(): void { if (!this.#initialized) throw new Error("Jetson dispatcher is not initialized"); } diff --git a/tools/e2e/jetson-dispatch-service.mts b/tools/e2e/jetson-dispatch-service.mts index 39398760e2f..3dc460f52fc 100644 --- a/tools/e2e/jetson-dispatch-service.mts +++ b/tools/e2e/jetson-dispatch-service.mts @@ -83,11 +83,11 @@ export function createJetsonDispatchServer(options: { resolveSigningKey: SigningKeyResolver; }): Server { async function authenticate( - incoming: IncomingMessage, + token: string, dispatchRequest: ReturnType, ): Promise { return verifyGitHubOidcToken({ - token: bearerToken(incoming), + token, request: dispatchRequest, policy: { repositoryId: options.repositoryId }, resolveSigningKey: options.resolveSigningKey, @@ -100,8 +100,24 @@ export function createJetsonDispatchServer(options: { sendJson(response, 404, { error: "not found" }); return; } - if (request.method === "POST" && request.url === "/v1/jobs") { - let dispatchRequest; + let token: string; + try { + token = bearerToken(request); + } catch { + sendJson(response, 401, { error: "request authentication failed" }); + return; + } + const createJob = request.method === "POST" && request.url === "/v1/jobs"; + const match = JOB_PATH_PATTERN.exec(request.url); + if (!createJob && (!match || !["DELETE", "GET"].includes(request.method ?? ""))) { + sendJson(response, 404, { error: "not found" }); + return; + } + + let dispatchRequest; + let jobId: string | undefined; + let artifact = false; + if (createJob) { try { dispatchRequest = parseJetsonDispatchRequest(await readJsonBody(request)); } catch (error) { @@ -110,43 +126,44 @@ export function createJetsonDispatchServer(options: { }); return; } - let identity; + } else { + jobId = match![1]!; + artifact = match![2] === "artifact"; try { - identity = await authenticate(request, dispatchRequest); + dispatchRequest = options.coordinator.request(jobId); } catch { sendJson(response, 401, { error: "request authentication failed" }); return; } - sendJson(response, 202, { job: options.coordinator.dispatch(dispatchRequest, identity) }); - return; } - const match = JOB_PATH_PATTERN.exec(request.url); - if (!match || !["DELETE", "GET"].includes(request.method ?? "")) { - sendJson(response, 404, { error: "not found" }); - return; - } - const jobId = match[1]!; - const artifact = match[2] === "artifact"; - const dispatchRequest = options.coordinator.request(jobId); + let identity; try { - await authenticate(request, dispatchRequest); + identity = await authenticate(token, dispatchRequest); } catch { sendJson(response, 401, { error: "request authentication failed" }); return; } + if (createJob) { + sendJson(response, 202, { job: options.coordinator.dispatch(dispatchRequest, identity) }); + return; + } + + const existingJobId = jobId!; if (request.method === "DELETE") { if (artifact) { sendJson(response, 405, { error: "method not allowed" }); return; } - sendJson(response, 202, { job: options.coordinator.cancel(jobId) }); + sendJson(response, 202, { job: options.coordinator.cancel(existingJobId) }); return; } sendJson( response, 200, - artifact ? options.coordinator.artifact(jobId) : { job: options.coordinator.status(jobId) }, + artifact + ? options.coordinator.artifact(existingJobId) + : { job: options.coordinator.status(existingJobId) }, ); })().catch((error) => { if (response.headersSent) { @@ -161,7 +178,7 @@ export function createJetsonDispatchServer(options: { sendJson(response, 404, { error: error.message }); return; } - console.error(error instanceof Error ? error.message : "Jetson dispatch service failed"); + console.error("Jetson dispatch service failed"); sendJson(response, 500, { error: "Jetson dispatch service failed" }); }); }); diff --git a/tools/e2e/jetson-dispatch-worker.mts b/tools/e2e/jetson-dispatch-worker.mts index 7a17652e544..501104b6476 100644 --- a/tools/e2e/jetson-dispatch-worker.mts +++ b/tools/e2e/jetson-dispatch-worker.mts @@ -6,10 +6,12 @@ import fs from "node:fs"; import path from "node:path"; import type { JetsonDispatchRequest } from "./jetson-dispatch-contract.mts"; -import type { +import { + decodeJetsonArtifactArchive, JetsonDeviceIdentity, JetsonDispatchWorker, JetsonWorkerResult, + MAX_JETSON_ARTIFACT_ARCHIVE_BYTES, } from "./jetson-dispatch-lifecycle.mts"; const MAX_PROCESS_OUTPUT_BYTES = 4 * 1024 * 1024; @@ -58,10 +60,6 @@ if [ -e "$workspace" ]; then exit 1 fi install -d -m 0700 "$workspace" -cleanup() { - rm -rf -- "$workspace" -} -trap cleanup EXIT git init --quiet "$workspace/repository" git -C "$workspace/repository" remote add origin https://github.com/NVIDIA/NemoClaw.git @@ -96,6 +94,35 @@ timeout --foreground --signal=TERM --kill-after=30s "${"${timeout_seconds}"}s" \ --test-path test/e2e/live/jetson-nvmap-gpu.test.ts `; +const COLLECT_ARTIFACT_SCRIPT = String.raw`set -euo pipefail +job_id="$1" +[[ "$job_id" =~ ^[a-f0-9]{64}$ ]] +workspace="/var/tmp/nemoclaw-jetson-e2e/$job_id" +cleanup() { + rm -rf -- "$workspace" +} +trap cleanup EXIT + +artifact_directory="$workspace/e2e-artifacts/live/jetson-nvmap-gpu" +if [ ! -d "$artifact_directory" ] || [ -L "$artifact_directory" ]; then + exit 0 +fi +artifact_bytes="$(du --apparent-size --block-size=1 --summarize "$artifact_directory" | cut -f1)" +[[ "$artifact_bytes" =~ ^[0-9]+$ ]] +if (( artifact_bytes > ${MAX_JETSON_ARTIFACT_ARCHIVE_BYTES} )); then + echo "Jetson E2E artifacts exceed ${MAX_JETSON_ARTIFACT_ARCHIVE_BYTES} bytes" >&2 + exit 1 +fi +archive="$workspace/jetson-e2e-artifacts.tar.gz" +tar --one-file-system --create --gzip --file "$archive" --directory "$artifact_directory" -- . +archive_bytes="$(stat --format='%s' "$archive")" +if (( archive_bytes > ${MAX_JETSON_ARTIFACT_ARCHIVE_BYTES} )); then + echo "Jetson E2E artifact archive exceeds ${MAX_JETSON_ARTIFACT_ARCHIVE_BYTES} bytes" >&2 + exit 1 +fi +base64 --wrap=0 "$archive" +`; + export interface SshJetsonWorkerConfig { destination: string; identityFile: string; @@ -289,25 +316,28 @@ function parseDeviceIdentity(output: string): JetsonDeviceIdentity { export class SshJetsonDispatchWorker implements JetsonDispatchWorker { readonly #config: SshJetsonWorkerConfig; + readonly #runProcess: typeof runProcess; - constructor(config: SshJetsonWorkerConfig) { + constructor(config: SshJetsonWorkerConfig, processRunner: typeof runProcess = runProcess) { this.#config = config; + this.#runProcess = processRunner; } async run( request: JetsonDispatchRequest, options: { jobId: string; signal: AbortSignal }, ): Promise { - const identityResult = await runProcess({ + const identityResult = await this.#runProcess({ executable: "ssh", args: [...this.#sshArgs(), this.#config.destination, "bash", "-s"], input: DEVICE_IDENTITY_SCRIPT, signal: options.signal, }); const device = parseDeviceIdentity(identityResult.stdout); - let testResult: ProcessResult; + let testResult: ProcessResult | undefined; + let testError: unknown; try { - testResult = await runProcess({ + testResult = await this.#runProcess({ executable: "ssh", args: [ ...this.#sshArgs(), @@ -323,22 +353,37 @@ export class SshJetsonDispatchWorker implements JetsonDispatchWorker { signal: options.signal, }); } catch (error) { - if (error instanceof ProcessFailure) { - const failure = new Error(error.message) as Error & { log: string }; - failure.log = [ - "=== Jetson identity ===", - identityResult.stdout.trimEnd(), - "=== Jetson E2E stdout ===", - error.result.stdout.trimEnd(), - "=== Jetson E2E stderr ===", - error.result.stderr.trimEnd(), - "", - ].join("\n"); - throw failure; + testError = error; + } + const artifactArchiveBase64 = options.signal.aborted + ? undefined + : await this.#collectArtifact(options.jobId, options.signal); + if (testError instanceof ProcessFailure) { + const failure = new Error(testError.message) as Error & { + artifactArchiveBase64?: string; + log: string; + }; + failure.log = [ + "=== Jetson identity ===", + identityResult.stdout.trimEnd(), + "=== Jetson E2E stdout ===", + testError.result.stdout.trimEnd(), + "=== Jetson E2E stderr ===", + testError.result.stderr.trimEnd(), + "", + ].join("\n"); + if (artifactArchiveBase64 !== undefined) { + failure.artifactArchiveBase64 = artifactArchiveBase64; } - throw error; + throw failure; + } + if (testError) throw testError; + if (!testResult) throw new Error("Jetson E2E did not return a process result"); + if (artifactArchiveBase64 === undefined) { + throw new Error("Successful Jetson E2E did not produce a bounded artifact archive"); } return { + artifactArchiveBase64, device, log: [ "=== Jetson identity ===", @@ -352,8 +397,20 @@ export class SshJetsonDispatchWorker implements JetsonDispatchWorker { }; } + async #collectArtifact(jobId: string, signal: AbortSignal): Promise { + const result = await this.#runProcess({ + executable: "ssh", + args: [...this.#sshArgs(), this.#config.destination, "bash", "-s", "--", jobId], + input: COLLECT_ARTIFACT_SCRIPT, + signal, + }); + if (result.stdout.length === 0) return undefined; + decodeJetsonArtifactArchive(result.stdout); + return result.stdout; + } + async reset(options: { signal: AbortSignal }): Promise { - await runProcess({ + await this.#runProcess({ executable: this.#config.resetExecutable, args: [], signal: options.signal, diff --git a/tools/e2e/private-file.mts b/tools/e2e/private-file.mts index 18e62303187..115533cc5d8 100644 --- a/tools/e2e/private-file.mts +++ b/tools/e2e/private-file.mts @@ -76,7 +76,7 @@ export function readPrivateRegularFile( } } -export function writePrivateRegularFile(file: string, contents: string): void { +export function writePrivateRegularFile(file: string, contents: string | Uint8Array): void { const descriptor = openPrivateFileForWrite(file); try { const stat = fs.fstatSync(descriptor); @@ -85,7 +85,10 @@ export function writePrivateRegularFile(file: string, contents: string): void { } fs.fchmodSync(descriptor, 0o600); fs.ftruncateSync(descriptor, 0); - fs.writeFileSync(descriptor, contents, "utf8"); + fs.writeFileSync( + descriptor, + typeof contents === "string" ? Buffer.from(contents, "utf8") : contents, + ); fs.fsyncSync(descriptor); } finally { fs.closeSync(descriptor); diff --git a/tools/e2e/workflow-boundary.mts b/tools/e2e/workflow-boundary.mts index f74963a2386..885566669d1 100644 --- a/tools/e2e/workflow-boundary.mts +++ b/tools/e2e/workflow-boundary.mts @@ -4000,12 +4000,8 @@ function validateJetsonControllerBoundary(errors: string[], jobs: WorkflowRecord if (!isDeepStrictEqual(asRecord(job.permissions), { contents: "read", "id-token": "write" })) { errors.push("jetson-nvmap-gpu controller must grant only contents:read and id-token:write"); } - if ( - !isDeepStrictEqual(asRecord(job.env), { - E2E_ARTIFACT_DIR: "${{ runner.temp }}/e2e-artifacts/live/jetson-nvmap-gpu", - }) - ) { - errors.push("jetson-nvmap-gpu controller environment must contain only its artifact directory"); + if (Object.keys(asRecord(job.env)).length !== 0) { + errors.push("jetson-nvmap-gpu controller must not define a job-level environment"); } const steps = asSteps(job.steps); @@ -4040,6 +4036,7 @@ function validateJetsonControllerBoundary(errors: string[], jobs: WorkflowRecord dispatch?.run !== "node --experimental-strip-types --no-warnings tools/e2e/jetson-dispatch-client.mts" || !isDeepStrictEqual(asRecord(dispatch?.env), { + E2E_ARTIFACT_DIR: "${{ runner.temp }}/e2e-artifacts/live/jetson-nvmap-gpu", JETSON_DISPATCH_CANDIDATE_SHA: "${{ inputs.checkout_sha || github.sha }}", JETSON_DISPATCH_URL: "${{ vars.JETSON_DISPATCH_URL }}", }) From b4220a4ffae11314348ec06c9110f880c3b98597 Mon Sep 17 00:00:00 2001 From: San Dang Date: Mon, 10 Aug 2026 19:21:45 +0700 Subject: [PATCH 06/34] docs(e2e): clarify v1 Jetson receipt policy Signed-off-by: San Dang --- .../nemoclaw-maintainer-policies/references/release-train.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.agents/skills/nemoclaw-maintainer-policies/references/release-train.md b/.agents/skills/nemoclaw-maintainer-policies/references/release-train.md index 152d98abe3a..0e98df5b46e 100644 --- a/.agents/skills/nemoclaw-maintainer-policies/references/release-train.md +++ b/.agents/skills/nemoclaw-maintainer-policies/references/release-train.md @@ -57,7 +57,7 @@ Before asking for the release confirmation phrase, build and show an evidence le - Require the workflow-produced trusted dispatch receipt to bind the accepted run candidate SHA, run ID, attempt, and selector inputs. - Run `nemoclaw-maintainer-e2e` in full mode when the ledger lacks complete evidence for the candidate SHA. - Require one completed, successful full workflow run for all default-selected workflow E2E jobs and the full-mode additions, including `Exact staging Brev Launchable`. -- Require the trusted dispatch receipt to record `allowJetsonDispatch: false`, `allowJetsonRunnerQueue: false`, and `allowDgxSparkRunnerQueue: false`. +- Require the trusted dispatch receipt to record `allowJetsonRunnerQueue: false` and `allowDgxSparkRunnerQueue: false`. A v1 receipt may omit `allowJetsonDispatch` but must record `false` when the field is present. A v2 receipt must record `allowJetsonDispatch: false`. - Exclude `jetson-nvmap-gpu`, `llama-cpp-dgx-spark-plan`, and `llama-cpp-dgx-spark-qualification` from the required denominator. - Require the trusted dispatch receipt to bind the workflow run and an attempt no later than the run's latest attempt. The receipt must record empty selectors and `include_staging_brev_launchable=true`. - Require the Launchable E2E receipt to identify the candidate SHA in the repository and provision records. From b6f69f8a6cdbc780d1375e4e8ca52a6664f3c5de Mon Sep 17 00:00:00 2001 From: San Dang Date: Mon, 10 Aug 2026 19:30:39 +0700 Subject: [PATCH 07/34] fix(e2e): align Jetson dispatch evidence bounds Signed-off-by: San Dang --- test/e2e/docs/jetson-colossus-dispatch.md | 14 ++++++---- .../support/jetson-dispatch-contract.test.ts | 24 ++++++++++++++++ tools/e2e/jetson-dispatch-client.mts | 4 +-- tools/e2e/jetson-dispatch-lifecycle.mts | 28 ++++++++++++------- 4 files changed, 53 insertions(+), 17 deletions(-) diff --git a/test/e2e/docs/jetson-colossus-dispatch.md b/test/e2e/docs/jetson-colossus-dispatch.md index 41fca171018..2b2d045c44c 100644 --- a/test/e2e/docs/jetson-colossus-dispatch.md +++ b/test/e2e/docs/jetson-colossus-dispatch.md @@ -29,7 +29,7 @@ The credentials have these lifecycles: | Credential | Location and access | Lifetime and removal | | --- | --- | --- | -| GitHub OIDC token | GitHub-hosted controller process memory and the authenticated request | The client requests a new token for each request. It does not write the token to disk. | +| GitHub OIDC token | GitHub-hosted controller process memory and the authenticated request | The client reuses a token in process memory for at most four minutes and then requests another. It does not write the token to disk. | | Cloudflare account certificate | The administrator account that runs `cloudflared tunnel login` | Remove `cert.pem` from Colossus after tunnel creation and DNS routing. Reauthenticate before later management changes. | | Cloudflare Tunnel credential | `/etc/cloudflared/TUNNEL_UUID.json`, readable only by the tunnel service account | Keep it for this temporary deployment. Revoke the tunnel and remove the file when the deployment ends. | | Jetson SSH private key | `/var/lib/nemoclaw-jetson-dispatch/id_ed25519`, readable only by the dispatcher service account | Keep it for this temporary deployment. Remove the matching Jetson public key and private key when the deployment ends. | @@ -373,7 +373,8 @@ The uploaded `e2e-jetson-nvmap-gpu` artifact must contain `jetson-dispatch.json` - `reset: "succeeded"` before `conclusion: "success"`. It must also contain `jetson-e2e-artifacts.tar.gz`. -The dispatcher creates that archive from the remote E2E artifact directory before it removes the candidate workspace and rejects archives larger than 1 MiB. +The dispatcher creates that archive from the remote E2E artifact directory before it removes the candidate workspace. +It rejects an artifact directory or compressed archive larger than 1 MiB. After the workflow completes, independently rerun the baseline checks. Then run one controlled failing candidate and confirm that its artifact records the same reset evidence. @@ -387,11 +388,14 @@ Independently rerun the baseline checks after that cancellation. The dispatcher permits one active job. A process crash leaves `device.lock` in the state directory. On restart, the dispatcher invokes the reset program before it removes that stale lock or accepts more work. -If reset fails, startup fails or the completed job reports `reset-failed`. -The lock remains after either reset failure. +If reset fails, startup fails or the completed job reports `conclusion: "reset-failed"` with `reset: "failed"`. +If reset succeeds but lock removal fails, the completed job reports `conclusion: "reset-failed"` with `reset: "succeeded"`. +The lock remains in either case. Do not delete `device.lock` to bypass recovery. -Repair the reset path, run and verify the reset program, and restart the dispatcher. +For `reset: "failed"`, repair the reset path. +For `reset: "succeeded"` with a lock-removal error, repair the state-directory filesystem or permissions. +Then restart the dispatcher; startup runs and verifies another reset before removing the stale lock. Preserve the job JSON and log files for diagnosis. These private state files can contain candidate output, and the dispatcher does not prune them. Apply the host's approved retention policy after GitHub uploads the artifact and no device lock exists. diff --git a/test/e2e/support/jetson-dispatch-contract.test.ts b/test/e2e/support/jetson-dispatch-contract.test.ts index ce5c21ab2b7..85a4b40b4b2 100644 --- a/test/e2e/support/jetson-dispatch-contract.test.ts +++ b/test/e2e/support/jetson-dispatch-contract.test.ts @@ -27,6 +27,9 @@ import { JetsonDispatchNotFoundError, type JetsonDispatchStatus, type JetsonDispatchWorker, + MAX_JETSON_ARTIFACT_ARCHIVE_BYTES, + MAX_JETSON_DISPATCH_ARTIFACT_RESPONSE_BYTES, + MAX_JETSON_DISPATCH_LOG_BYTES, } from "../../../tools/e2e/jetson-dispatch-lifecycle.mts"; import { createJetsonDispatchServer } from "../../../tools/e2e/jetson-dispatch-service.mts"; @@ -270,6 +273,27 @@ describe("Jetson dispatch request and OIDC boundary", () => { }); describe("Jetson single-device lifecycle", () => { + it("keeps the maximum log and archive response within the controller bound (#8142)", () => { + const artifact = { + artifactArchiveBase64: Buffer.alloc(MAX_JETSON_ARTIFACT_ARCHIVE_BYTES).toString("base64"), + log: "\0".repeat(MAX_JETSON_DISPATCH_LOG_BYTES), + status: { + schemaVersion: 1, + jobId: "d".repeat(64), + request: REQUEST, + state: "completed", + conclusion: "success", + createdAt: new Date(0).toISOString(), + completedAt: new Date(0).toISOString(), + reset: "succeeded", + }, + }; + + expect(Buffer.byteLength(`${JSON.stringify(artifact)}\n`)).toBeLessThanOrEqual( + MAX_JETSON_DISPATCH_ARTIFACT_RESPONSE_BYTES, + ); + }); + it("records success only after reset succeeds (#8142)", async () => { const reset = vi.fn(async () => {}); const dispatch = coordinator(temporaryDirectory(), worker({ reset })); diff --git a/tools/e2e/jetson-dispatch-client.mts b/tools/e2e/jetson-dispatch-client.mts index 360550b5d1f..a8319e02104 100644 --- a/tools/e2e/jetson-dispatch-client.mts +++ b/tools/e2e/jetson-dispatch-client.mts @@ -14,11 +14,11 @@ import { decodeJetsonArtifactArchive, type JetsonDispatchArtifact, type JetsonDispatchStatus, + MAX_JETSON_DISPATCH_ARTIFACT_RESPONSE_BYTES, } from "./jetson-dispatch-lifecycle.mts"; import { writePrivateRegularFile } from "./private-file.mts"; const MAX_STATUS_BYTES = 64 * 1024; -const MAX_ARTIFACT_BYTES = 5 * 1024 * 1024; const POLL_INTERVAL_MS = 10_000; const MAX_WAIT_MS = 54 * 60_000; const MAX_CONSECUTIVE_POLL_FAILURES = 3; @@ -310,7 +310,7 @@ async function main(): Promise { baseUrl, method: "GET", path: `v1/jobs/${jobId}/artifact`, - maxBytes: MAX_ARTIFACT_BYTES, + maxBytes: MAX_JETSON_DISPATCH_ARTIFACT_RESPONSE_BYTES, }); const artifact = validateArtifact(artifactValue, jobId); const { artifactArchiveBase64, ...artifactReceipt } = artifact; diff --git a/tools/e2e/jetson-dispatch-lifecycle.mts b/tools/e2e/jetson-dispatch-lifecycle.mts index 1dec8c7d571..d43e73d84b7 100644 --- a/tools/e2e/jetson-dispatch-lifecycle.mts +++ b/tools/e2e/jetson-dispatch-lifecycle.mts @@ -11,11 +11,16 @@ import { writePrivateRegularFile, } from "./private-file.mts"; -const MAX_LOG_BYTES = 4 * 1024 * 1024; +export const MAX_JETSON_DISPATCH_LOG_BYTES = 4 * 1024 * 1024; const MAX_RETAINED_JOB_STATUSES = 128; export const MAX_JETSON_ARTIFACT_ARCHIVE_BYTES = 1024 * 1024; const MAX_JETSON_ARTIFACT_ARCHIVE_BASE64_CHARACTERS = Math.ceil(MAX_JETSON_ARTIFACT_ARCHIVE_BYTES / 3) * 4; +const MAX_JETSON_DISPATCH_ARTIFACT_JSON_OVERHEAD_BYTES = 256 * 1024; +export const MAX_JETSON_DISPATCH_ARTIFACT_RESPONSE_BYTES = + MAX_JETSON_DISPATCH_LOG_BYTES * 6 + + MAX_JETSON_ARTIFACT_ARCHIVE_BASE64_CHARACTERS + + MAX_JETSON_DISPATCH_ARTIFACT_JSON_OVERHEAD_BYTES; export type JetsonDispatchConclusion = | "cancelled" @@ -77,7 +82,9 @@ function safeError(error: unknown): string { function workerErrorLog(error: unknown): string | undefined { if (!error || typeof error !== "object" || !("log" in error)) return undefined; const log = (error as { log?: unknown }).log; - if (typeof log !== "string" || Buffer.byteLength(log) > MAX_LOG_BYTES) return undefined; + if (typeof log !== "string" || Buffer.byteLength(log) > MAX_JETSON_DISPATCH_LOG_BYTES) { + return undefined; + } return log; } @@ -281,7 +288,10 @@ export class JetsonDispatchCoordinator { const status = this.status(jobId); if (status.state !== "completed") throw new JetsonDispatchBusyError("Jetson job is not complete"); - const log = readPrivateRegularFile(this.#logPath(jobId), { maxBytes: MAX_LOG_BYTES }) ?? ""; + const log = + readPrivateRegularFile(this.#logPath(jobId), { + maxBytes: MAX_JETSON_DISPATCH_LOG_BYTES, + }) ?? ""; const artifactArchiveBase64 = readPrivateRegularFile(this.#artifactPath(jobId), { allowMissing: true, maxBytes: MAX_JETSON_ARTIFACT_ARCHIVE_BASE64_CHARACTERS, @@ -314,8 +324,8 @@ export class JetsonDispatchCoordinator { jobId: status.jobId, signal: controller.signal, }); - if (Buffer.byteLength(result.log) > MAX_LOG_BYTES) { - throw new Error(`Jetson log exceeds ${MAX_LOG_BYTES} bytes`); + if (Buffer.byteLength(result.log) > MAX_JETSON_DISPATCH_LOG_BYTES) { + throw new Error(`Jetson log exceeds ${MAX_JETSON_DISPATCH_LOG_BYTES} bytes`); } writePrivateRegularFile(this.#logPath(status.jobId), result.log); if (result.artifactArchiveBase64 !== undefined) { @@ -333,11 +343,9 @@ export class JetsonDispatchCoordinator { if (artifactArchiveBase64 !== undefined) { writePrivateRegularFile(this.#artifactPath(status.jobId), artifactArchiveBase64); } - } catch (logError) { - status.error = `${status.error}; log persistence failed: ${safeError(logError)}`.slice( - 0, - 500, - ); + } catch (resultError) { + status.error = + `${status.error}; result persistence failed: ${safeError(resultError)}`.slice(0, 500); } } finally { clearTimeout(timer); From 56c04d98eeedac663b6d5d95a73712c88511578e Mon Sep 17 00:00:00 2001 From: San Dang Date: Mon, 10 Aug 2026 19:43:57 +0700 Subject: [PATCH 08/34] fix(e2e): preserve Jetson dispatch failure evidence Signed-off-by: San Dang --- .../support/jetson-dispatch-contract.test.ts | 42 +++++++++++++++++++ .../support/jetson-dispatch-worker.test.ts | 39 +++++++++++++++++ tools/e2e/jetson-dispatch-client.mts | 4 +- tools/e2e/jetson-dispatch-lifecycle.mts | 1 + tools/e2e/jetson-dispatch-worker.mts | 21 +++++++--- 5 files changed, 100 insertions(+), 7 deletions(-) diff --git a/test/e2e/support/jetson-dispatch-contract.test.ts b/test/e2e/support/jetson-dispatch-contract.test.ts index 85a4b40b4b2..f4ba40e7b51 100644 --- a/test/e2e/support/jetson-dispatch-contract.test.ts +++ b/test/e2e/support/jetson-dispatch-contract.test.ts @@ -314,6 +314,21 @@ describe("Jetson single-device lifecycle", () => { }); }); + it("returns completed evidence when its result log is missing (#8142)", async () => { + const stateDirectory = temporaryDirectory(); + const dispatch = coordinator(stateDirectory, worker()); + await dispatch.initialize(); + const accepted = dispatch.dispatch(REQUEST, identity()); + await waitForCompletion(dispatch, accepted.jobId); + fs.rmSync(path.join(stateDirectory, `${accepted.jobId}.log`)); + + expect(dispatch.artifact(accepted.jobId)).toMatchObject({ + artifactArchiveBase64: ARTIFACT_ARCHIVE_BASE64, + log: "", + status: { conclusion: "success", state: "completed" }, + }); + }); + it("rejects a second job while the Jetson lock is held (#8142)", async () => { let finish: (() => void) | undefined; const run = vi.fn( @@ -440,6 +455,33 @@ describe("Jetson single-device lifecycle", () => { }); describe("Jetson dispatch HTTP boundary", () => { + it("reports the controller deadline when cancellation also fails (#8142)", async () => { + const jobId = "d".repeat(64); + const request = vi.fn().mockRejectedValue(new Error("tunnel unavailable")); + + await expect( + pollJetsonDispatch({ + baseUrl: new URL("https://dispatch.test/"), + deadlineMs: 10_000, + initialStatus: { + schemaVersion: 1, + jobId, + request: REQUEST, + state: "queued", + createdAt: new Date(0).toISOString(), + reset: "pending", + }, + jobId, + now: () => 10_000, + request, + wait: async () => {}, + }), + ).rejects.toThrow("Jetson dispatcher did not complete before the controller deadline"); + expect(request).toHaveBeenCalledWith( + expect.objectContaining({ method: "DELETE", path: `v1/jobs/${jobId}` }), + ); + }); + it("retries transient status failures and cancels after the bounded limit (#8142)", async () => { vi.spyOn(console, "warn").mockImplementation(() => {}); const jobId = "d".repeat(64); diff --git a/test/e2e/support/jetson-dispatch-worker.test.ts b/test/e2e/support/jetson-dispatch-worker.test.ts index 3ee75abbdab..685249d657f 100644 --- a/test/e2e/support/jetson-dispatch-worker.test.ts +++ b/test/e2e/support/jetson-dispatch-worker.test.ts @@ -9,6 +9,7 @@ import { afterEach, describe, expect, it, vi } from "vitest"; import { loadSshJetsonWorkerConfig, + ProcessFailure, SshJetsonDispatchWorker, } from "../../../tools/e2e/jetson-dispatch-worker.mts"; @@ -108,6 +109,44 @@ describe("Colossus SSH worker deployment boundary", () => { expect(processRunner.mock.calls[2]![0].input).toContain("base64 --wrap=0"); }); + it("preserves test-failure logs when artifact collection fails (#8142)", async () => { + const files = deploymentFiles(); + const processRunner = vi + .fn() + .mockResolvedValueOnce({ + stdout: + "model\tNVIDIA Jetson AGX Thor Developer Kit\njetpackVersion\t7.2.2\njetsonLinuxRelease\tR38\nkernel\t6.8.12-tegra\n", + stderr: "", + }) + .mockRejectedValueOnce( + new ProcessFailure("Jetson test failed", { + stdout: "failed test output\n", + stderr: "failed test error\n", + }), + ) + .mockRejectedValueOnce(new Error("artifact collection unavailable")); + const worker = new SshJetsonDispatchWorker( + loadSshJetsonWorkerConfig(environment(files)), + processRunner, + ); + + await expect( + worker.run( + { + schemaVersion: 1, + target: "jetson-nvmap-gpu", + candidateSha: "a".repeat(40), + workflowRunId: "123", + workflowRunAttempt: 1, + }, + { jobId: "b".repeat(64), signal: new AbortController().signal }, + ), + ).rejects.toMatchObject({ + message: "Jetson test failed; artifact collection failed: artifact collection unavailable", + log: expect.stringContaining("failed test output"), + }); + }); + it.each([ "nvidia@192.168.55.1 -o StrictHostKeyChecking=no", "nvidia@host;uname", diff --git a/tools/e2e/jetson-dispatch-client.mts b/tools/e2e/jetson-dispatch-client.mts index a8319e02104..a74632c86b4 100644 --- a/tools/e2e/jetson-dispatch-client.mts +++ b/tools/e2e/jetson-dispatch-client.mts @@ -219,7 +219,7 @@ export async function pollJetsonDispatch(options: { method: "DELETE", path: `v1/jobs/${options.jobId}`, maxBytes: MAX_STATUS_BYTES, - }); + }).catch(() => undefined); throw new Error("Jetson dispatcher did not complete before the controller deadline"); } await wait(POLL_INTERVAL_MS); @@ -298,7 +298,7 @@ async function main(): Promise { jobId = dispatched.jobId; console.log(`Jetson dispatch accepted as ${jobId}`); const deadline = Date.now() + MAX_WAIT_MS; - const status = await pollJetsonDispatch({ + await pollJetsonDispatch({ baseUrl, deadlineMs: deadline, initialStatus: dispatched, diff --git a/tools/e2e/jetson-dispatch-lifecycle.mts b/tools/e2e/jetson-dispatch-lifecycle.mts index d43e73d84b7..08c58a45c04 100644 --- a/tools/e2e/jetson-dispatch-lifecycle.mts +++ b/tools/e2e/jetson-dispatch-lifecycle.mts @@ -290,6 +290,7 @@ export class JetsonDispatchCoordinator { throw new JetsonDispatchBusyError("Jetson job is not complete"); const log = readPrivateRegularFile(this.#logPath(jobId), { + allowMissing: true, maxBytes: MAX_JETSON_DISPATCH_LOG_BYTES, }) ?? ""; const artifactArchiveBase64 = readPrivateRegularFile(this.#artifactPath(jobId), { diff --git a/tools/e2e/jetson-dispatch-worker.mts b/tools/e2e/jetson-dispatch-worker.mts index 501104b6476..00f638906cb 100644 --- a/tools/e2e/jetson-dispatch-worker.mts +++ b/tools/e2e/jetson-dispatch-worker.mts @@ -201,7 +201,7 @@ interface ProcessResult { stderr: string; } -class ProcessFailure extends Error { +export class ProcessFailure extends Error { readonly result: ProcessResult; constructor(message: string, result: ProcessResult) { @@ -355,11 +355,21 @@ export class SshJetsonDispatchWorker implements JetsonDispatchWorker { } catch (error) { testError = error; } - const artifactArchiveBase64 = options.signal.aborted - ? undefined - : await this.#collectArtifact(options.jobId, options.signal); + let artifactArchiveBase64: string | undefined; + let artifactCollectionError: unknown; + if (!options.signal.aborted) { + try { + artifactArchiveBase64 = await this.#collectArtifact(options.jobId, options.signal); + } catch (error) { + artifactCollectionError = error; + } + } if (testError instanceof ProcessFailure) { - const failure = new Error(testError.message) as Error & { + const collectionFailure = + artifactCollectionError instanceof Error + ? `; artifact collection failed: ${artifactCollectionError.message}` + : ""; + const failure = new Error(`${testError.message}${collectionFailure}`) as Error & { artifactArchiveBase64?: string; log: string; }; @@ -378,6 +388,7 @@ export class SshJetsonDispatchWorker implements JetsonDispatchWorker { throw failure; } if (testError) throw testError; + if (artifactCollectionError) throw artifactCollectionError; if (!testResult) throw new Error("Jetson E2E did not return a process result"); if (artifactArchiveBase64 === undefined) { throw new Error("Successful Jetson E2E did not produce a bounded artifact archive"); From f3d739c93db4f87eda4468c2abd360e5d6833ffb Mon Sep 17 00:00:00 2001 From: San Dang Date: Mon, 10 Aug 2026 19:51:53 +0700 Subject: [PATCH 09/34] fix(e2e): retain successful Jetson test output Signed-off-by: San Dang --- .../support/jetson-dispatch-worker.test.ts | 33 +++++++++++++++++++ tools/e2e/jetson-dispatch-worker.mts | 20 ++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/test/e2e/support/jetson-dispatch-worker.test.ts b/test/e2e/support/jetson-dispatch-worker.test.ts index 685249d657f..a60c1b7322f 100644 --- a/test/e2e/support/jetson-dispatch-worker.test.ts +++ b/test/e2e/support/jetson-dispatch-worker.test.ts @@ -147,6 +147,39 @@ describe("Colossus SSH worker deployment boundary", () => { }); }); + it("preserves successful test logs when artifact collection fails (#8142)", async () => { + const files = deploymentFiles(); + const processRunner = vi + .fn() + .mockResolvedValueOnce({ + stdout: + "model\tNVIDIA Jetson AGX Thor Developer Kit\njetpackVersion\t7.2.2\njetsonLinuxRelease\tR38\nkernel\t6.8.12-tegra\n", + stderr: "", + }) + .mockResolvedValueOnce({ stdout: "successful test output\n", stderr: "" }) + .mockRejectedValueOnce(new Error("artifact collection unavailable")); + const worker = new SshJetsonDispatchWorker( + loadSshJetsonWorkerConfig(environment(files)), + processRunner, + ); + + await expect( + worker.run( + { + schemaVersion: 1, + target: "jetson-nvmap-gpu", + candidateSha: "a".repeat(40), + workflowRunId: "123", + workflowRunAttempt: 1, + }, + { jobId: "b".repeat(64), signal: new AbortController().signal }, + ), + ).rejects.toMatchObject({ + message: "artifact collection unavailable", + log: expect.stringContaining("successful test output"), + }); + }); + it.each([ "nvidia@192.168.55.1 -o StrictHostKeyChecking=no", "nvidia@host;uname", diff --git a/tools/e2e/jetson-dispatch-worker.mts b/tools/e2e/jetson-dispatch-worker.mts index 00f638906cb..0dfc0e01b4c 100644 --- a/tools/e2e/jetson-dispatch-worker.mts +++ b/tools/e2e/jetson-dispatch-worker.mts @@ -388,8 +388,26 @@ export class SshJetsonDispatchWorker implements JetsonDispatchWorker { throw failure; } if (testError) throw testError; - if (artifactCollectionError) throw artifactCollectionError; if (!testResult) throw new Error("Jetson E2E did not return a process result"); + if (artifactCollectionError) { + const collectionMessage = + artifactCollectionError instanceof Error + ? artifactCollectionError.message + : "artifact collection failed"; + const failure = new Error(collectionMessage) as Error & { log: string }; + failure.log = [ + "=== Jetson identity ===", + identityResult.stdout.trimEnd(), + "=== Jetson E2E stdout ===", + testResult.stdout.trimEnd(), + "=== Jetson E2E stderr ===", + testResult.stderr.trimEnd(), + "=== Jetson artifact collection error ===", + collectionMessage, + "", + ].join("\n"); + throw failure; + } if (artifactArchiveBase64 === undefined) { throw new Error("Successful Jetson E2E did not produce a bounded artifact archive"); } From 6b07355d6749d0bc8a10eb149e5a413851f9dfa4 Mon Sep 17 00:00:00 2001 From: San Dang Date: Mon, 10 Aug 2026 20:56:31 +0700 Subject: [PATCH 10/34] fix(e2e): bound Jetson dispatch cleanup Signed-off-by: San Dang --- .../skills/nemoclaw-maintainer-e2e/SKILL.md | 3 + .github/workflows/e2e.yaml | 2 +- test/e2e/README.md | 3 + test/e2e/docs/README.md | 3 +- test/e2e/docs/jetson-colossus-dispatch.md | 190 ++++++++---- test/e2e/live/jetson-nvmap-gpu.test.ts | 42 +-- .../support/jetson-dispatch-contract.test.ts | 136 ++++++--- .../support/jetson-dispatch-worker.test.ts | 185 +++++++++--- .../support/jetson-workflow-boundary.test.ts | 2 +- test/helpers/vitest-watch-triggers.ts | 4 + test/vitest-watch-triggers.test.ts | 4 + tools/advisors/risk-plan.mts | 2 +- tools/e2e/cli-artifact-workflow-boundary.mts | 2 +- tools/e2e/jetson-dispatch-cleanup.sh | 278 ++++++++++++++++++ tools/e2e/jetson-dispatch-lifecycle.mts | 54 ++-- tools/e2e/jetson-dispatch-service.mts | 10 +- tools/e2e/jetson-dispatch-worker.mts | 203 ++++++++++++- tools/e2e/workflow-boundary.mts | 4 +- 18 files changed, 910 insertions(+), 217 deletions(-) create mode 100755 tools/e2e/jetson-dispatch-cleanup.sh diff --git a/.agents/skills/nemoclaw-maintainer-e2e/SKILL.md b/.agents/skills/nemoclaw-maintainer-e2e/SKILL.md index 8bc5fecbfe6..0a3427ecd48 100644 --- a/.agents/skills/nemoclaw-maintainer-e2e/SKILL.md +++ b/.agents/skills/nemoclaw-maintainer-e2e/SKILL.md @@ -246,6 +246,9 @@ to add `jetson-nvmap-gpu` to an empty-selector manual run or enable its explicit selection. Set it only after every deployment check in [Jetson Dispatch Through Colossus](../../../test/e2e/docs/jetson-colossus-dispatch.md) passes. +The Jetson lifecycle removes and verifies only its fixed job-owned cleanup +allowlist. Do not treat `cleanup: "succeeded"` as evidence that every possible +candidate host change was reversed. A permitted dispatcher may set `allow_dgx_spark_runner_queue=true` to add `llama-cpp-dgx-spark-plan` and `llama-cpp-dgx-spark-qualification` to an empty-selector manual run or enable explicit qualification selection. Set it diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index 07d7d894a76..ab5ecec9ceb 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -34,7 +34,7 @@ on: - internal-nvidia - public-nvidia allow_jetson_dispatch: - description: "Set true for jetson-nvmap-gpu only after the Colossus dispatcher, Cloudflare Tunnel, reset helper, and JETSON_DISPATCH_URL repository variable have passed the deployment checks in test/e2e/docs/jetson-colossus-dispatch.md." + description: "Set true for jetson-nvmap-gpu only after the Colossus dispatcher, Cloudflare Tunnel, cleanup helper, and JETSON_DISPATCH_URL repository variable have passed the deployment checks in test/e2e/docs/jetson-colossus-dispatch.md." required: false default: false type: boolean diff --git a/test/e2e/README.md b/test/e2e/README.md index 564ecc4ddf2..be38df38079 100644 --- a/test/e2e/README.md +++ b/test/e2e/README.md @@ -459,6 +459,9 @@ full runs unless their independent opt-in flags are `true`. Set `allow_jetson_dispatch=true` to select `jetson-nvmap-gpu` only after every deployment check in [Jetson Dispatch Through Colossus](docs/jetson-colossus-dispatch.md) passes. +The Colossus lifecycle removes and verifies only the fixed job-owned cleanup +allowlist. Its cleanup evidence does not attest that every possible candidate +host change was reversed. Set `allow_dgx_spark_runner_queue=true` to select both `llama-cpp-dgx-spark-plan` and `llama-cpp-dgx-spark-qualification`. GitHub can pause the qualification job for the diff --git a/test/e2e/docs/README.md b/test/e2e/docs/README.md index cda0bb2e469..8f17b23e4ca 100644 --- a/test/e2e/docs/README.md +++ b/test/e2e/docs/README.md @@ -316,7 +316,8 @@ test/e2e/ - [Jetson Dispatch Through Colossus](jetson-colossus-dispatch.md) defines how maintainers deploy and verify the temporary authenticated controller, - dispatcher, SSH, reset, and recovery path for `jetson-nvmap-gpu`. + dispatcher, SSH, bounded cleanup, and stale-lock recovery path for + `jetson-nvmap-gpu`. - `.github/workflows/e2e.yaml` runs selected or all supported live E2E targets and uploads an explicit artifact allowlist with diff --git a/test/e2e/docs/jetson-colossus-dispatch.md b/test/e2e/docs/jetson-colossus-dispatch.md index 2b2d045c44c..2850aaadbd1 100644 --- a/test/e2e/docs/jetson-colossus-dispatch.md +++ b/test/e2e/docs/jetson-colossus-dispatch.md @@ -5,7 +5,7 @@ This temporary path runs the `jetson-nvmap-gpu` end-to-end (E2E) job on one Jetson behind a Colossus host. GitHub Actions controls the job through an authenticated HTTPS endpoint. -Colossus retains the Cloudflare Tunnel credential, Jetson SSH key, SSH host key, device lock, and reset capability. +Colossus retains the Cloudflare Tunnel credential, Jetson SSH key, SSH host key, device lock, and cleanup capability. Candidate code runs only on the Jetson. Do not set `allow_jetson_dispatch=true` until every deployment check on this page passes. @@ -16,8 +16,8 @@ The deployment has these input and credential boundaries: | System | Receives | Must not receive | | --- | --- | --- | -| GitHub-hosted controller | Candidate commit SHA, workflow run identity, public dispatch URL, and short-lived GitHub OpenID Connect (OIDC) token | Jetson SSH key, tunnel credential, and reset privilege | -| Colossus dispatcher | Validated workflow identity, fixed target, and candidate commit SHA | Request-controlled command, SSH host, repository, path, or reset command | +| GitHub-hosted controller | Candidate commit SHA, workflow run identity, public dispatch URL, and short-lived GitHub OpenID Connect (OIDC) token | Jetson SSH key, tunnel credential, and cleanup privilege | +| Colossus dispatcher | Validated workflow identity, fixed target, and candidate commit SHA | Request-controlled command, SSH host, repository, path, or cleanup command | | Jetson | Candidate checkout and the fixed live E2E command | GitHub OIDC token, tunnel credential, and Colossus SSH private key | The dispatcher accepts only `NVIDIA/NemoClaw` and the trusted `main` E2E workflow. @@ -38,11 +38,12 @@ The dispatcher rejects an OIDC token whose issued-to-expiry window exceeds 15 mi The GitHub repository variable contains only the public dispatch URL. Do not put a credential in `JETSON_DISPATCH_URL`. -## Prepare a Known Jetson Baseline +## Prepare the Dedicated Jetson Use a dedicated Jetson without production data or credentials. The E2E job gives candidate code Docker access, which can control the dedicated host. -The reset procedure must restore a known image after every result. +Cleanup removes only the fixed job-owned resources defined below. +It does not attest that cleanup reversed every possible host change made by candidate code. Run these checks as the `nvidia` account that the dispatcher uses: @@ -63,25 +64,51 @@ The architecture must be `aarch64`, and Node.js must have major version 22. Docker must expose the NVIDIA runtime required by the existing Jetson live E2E test. Preinstall Ollama so candidate code does not invoke its host installer. The `nvidia` account must not have passwordless `sudo` access. - -Define a reset procedure that restores the verified baseline. -A reboot alone does not reset candidate changes. -Candidate code can change the `nvidia` home directory, SSH configuration, packages, processes, and Docker state. - -The reset procedure must verify these conditions before it returns success: - -- The expected Jetson model, Jetson Linux release, kernel, and storage layout are present. -- SSH is reachable with the dispatcher's restricted key and pinned host key. -- `/var/tmp/nemoclaw-jetson-e2e` is absent. -- The `e2e-jetson-nvmap` sandbox, `nemoclaw` gateway, and test containers are absent. -- `/dev/nvmap` and the NVIDIA Docker runtime are available. -- No candidate-created process remains. - -Use a known-image reflash, immutable-root rollback, or equivalent reprovisioning procedure. -Do not treat `boardctl reset` or another power cycle as baseline restoration. -A reviewed Thor flash process can use `boardctl` only as one step in known-image restoration. -The reset attestation must not rely only on commands that run through the candidate-controlled Jetson account. -If a known-image restore and independent attestation cannot be automated, stop the deployment. +The worker gives each job its own `HOME`, `TMPDIR`, XDG directories, and npm prefix under the job workspace. +The test installs the NemoClaw CLI and its state only in those job-owned paths, so workspace removal removes them without a host-wide uninstall. +If a later reviewed cleanup path requires the NemoClaw uninstaller, it must use `--keep-openshell` and must retain the same resource allowlist. + +Reserve these names and paths for this E2E target: + +- The current dispatcher-created `/var/tmp/nemoclaw-jetson-e2e/` workspace. +- The `/tmp/nemoclaw-services-e2e-jetson-nvmap` helper-service directory. +- The `e2e-jetson-nvmap` NemoClaw and OpenShell sandbox name. +- The `nemoclaw` OpenShell gateway name and forwards for the named sandbox. +- The recorded `ollama-auth-proxy`, OpenShell Docker gateway, and helper `cloudflared` processes. +- OpenShell-managed Docker containers labeled for `e2e-jetson-nvmap`. +- The volumes recorded from those labeled containers. +- The `openshell-cluster-nemoclaw` gateway container, volume, and recorded attached volumes. + +Do not run unrelated work under these reserved names. +The cleanup program must act only on this allowlist. + +Before candidate execution, the worker records this protected tool and model baseline: + +- The resolved Node.js path and version. +- The resolved npm path and version. +- The resolved Ollama path and a SHA-256 digest of the sorted Ollama model names and IDs. +- The resolved OpenShell path. + +The dispatcher stores the recorded values in a private `.baseline.json` state file. +After cleanup, the worker repeats the probes and compares them with that record. +Before and after candidate execution, the worker also requires `/dev/nvmap` and the Docker NVIDIA runtime to be available. +The worker removes the record only after every comparison and cleanup absence check succeeds. + +These other host resources also remain outside the cleanup allowlist: + +- Node.js, npm, the OpenShell executable, and the Docker engine. +- The Ollama binary, service, models, configuration, and unrelated `ollama serve` processes. +- The NVIDIA container runtime and Docker images that the test does not own exclusively. +- The `/dev/nvmap` character device and its permissions. +- JetPack, Jetson Linux, CUDA, NVIDIA packages, other `apt` packages, SDK Manager, and downloaded flashing files. +- User accounts, SSH keys, and user files outside the current job workspace and named NemoClaw resources. +- Docker resources without the exact label or name association defined above. +- Processes other than the recorded job-home helper processes defined above. +- Colossus credentials, service configuration, and job evidence. + +The cleanup program must not change or remove any resource outside its allowlist. +Review its command construction and target resolution before deployment. +Do not use broad process termination, Docker pruning, wildcard paths, or host-wide package removal. ## Create the Colossus Dispatcher Account @@ -145,37 +172,71 @@ sudo install -o nemoclaw-jetson-dispatch -g nemoclaw-jetson-dispatch -m 0600 \ rm /tmp/jetson_known_hosts ``` -The known image must preserve the verified SSH host identity. +Treat the verified SSH host identity as part of the protected baseline. Do not accept a changed host key without reconciling it through the serial console or another trusted channel. -Install the reset program at an absolute path such as `/usr/local/libexec/nemoclaw-jetson-reset`. +## Define the Cleanup Program + +Install the bundled cleanup program from the trusted checkout: + +```bash +sudo install -d -o root -g root -m 0755 /usr/local/libexec +sudo install -o root -g root -m 0755 \ + /opt/nemoclaw-jetson-dispatch/tools/e2e/jetson-dispatch-cleanup.sh \ + /usr/local/libexec/nemoclaw-jetson-cleanup +``` + It must accept no arguments and must not be group- or world-writable. -It must perform and attest the baseline restoration defined above. +It must derive the lowercase 64-character job ID from the private dispatcher `device.lock`. +It must reject a missing or malformed lock instead of selecting a broader target. +The bundled program fixes the state directory, SSH files, SSH destination, and cleanup names listed on this page. +Changing one of those values requires a corresponding reviewed source change. +The dispatcher invokes it after success, failure, cancellation, and timeout. +The dispatcher also invokes it during startup when `device.lock` remains from an interrupted service process. + +The cleanup program must perform these bounded actions: + +1. Stop and remove only the named sandbox, its forwards, and the named gateway. +2. Stop only the recorded helper PIDs after verifying the process owner, command marker, and job `HOME`. +3. Remove only the labeled sandbox containers, the exact gateway container, and their recorded volumes. +4. Remove only the helper-service directory and `/var/tmp/nemoclaw-jetson-e2e/` workspace for the locked job. +5. Verify that every allowlisted resource is absent. + +The cleanup program must be idempotent. +It must treat an already absent allowlisted resource as success. +It must exit nonzero when target ownership is ambiguous, cleanup fails, or absence verification is inconclusive. It must not remove `/var/lib/nemoclaw-jetson-dispatch/state/device.lock`. -The dispatcher removes that lock only after the reset program exits with status zero. - -Run the reset program as `nemoclaw-jetson-dispatch` when host permissions allow it. -Use device rules to grant access to the exact USB devices that the reset program needs. -If restoration requires root, use a reviewed privilege-separated service whose unprivileged, -root-owned client accepts no arguments and returns only after restoration and attestation finish. -The dispatcher service unit below prevents privilege elevation, so a reset client that invokes -`sudo` or relies on a set-user-ID executable is incompatible with this deployment. -Do not remove that protection or grant the dispatcher account passwordless `sudo` access. +The dispatcher removes that lock only after cleanup and absence verification succeed. + +After the helper exits, the worker independently verifies these conditions over pinned-host-key SSH: + +- The validated job workspace is absent and is not a symbolic link. +- No OpenShell-managed container has the `e2e-jetson-nvmap` sandbox label. +- The `openshell-cluster-nemoclaw` gateway container and volume are absent. +- Every recorded Node.js, npm, Ollama, Ollama model, and OpenShell baseline value matches. +- `/dev/nvmap` exists, and Docker still reports the NVIDIA runtime. -Test the SSH and reset paths as the service account: +The worker reports cleanup failure when any helper or independent verification step fails. + +The dispatcher runs the cleanup program as `nemoclaw-jetson-dispatch`. +The service unit below prevents privilege elevation. +Do not remove that protection or grant the dispatcher account passwordless `sudo` access. -> Warning: The reset test replaces Jetson state with the known baseline. -> Remove any data that the deployment must retain before this test. +Test cleanup-program access and the SSH path as the service account: ```bash +sudo -u nemoclaw-jetson-dispatch test -x \ + /usr/local/libexec/nemoclaw-jetson-cleanup sudo -u nemoclaw-jetson-dispatch ssh -F /dev/null -o BatchMode=yes \ -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes \ -o UserKnownHostsFile=/var/lib/nemoclaw-jetson-dispatch/known_hosts \ -i /var/lib/nemoclaw-jetson-dispatch/id_ed25519 \ nvidia@192.168.55.1 'uname -m' -sudo -u nemoclaw-jetson-dispatch /usr/local/libexec/nemoclaw-jetson-reset ``` +Do not invoke the cleanup program manually without the dispatcher-created device lock and baseline record. +The proof-job procedure below exercises cleanup and verifies its result. + ## Configure the Dispatcher Service Get the immutable GitHub repository ID: @@ -192,12 +253,12 @@ JETSON_DISPATCH_STATE_DIRECTORY=/var/lib/nemoclaw-jetson-dispatch/state JETSON_DISPATCH_GITHUB_REPOSITORY_ID=REPOSITORY_ID JETSON_DISPATCH_PORT=8787 JETSON_DISPATCH_EXECUTION_TIMEOUT_SECONDS=3000 -JETSON_DISPATCH_RESET_TIMEOUT_SECONDS=300 +JETSON_DISPATCH_CLEANUP_TIMEOUT_SECONDS=300 JETSON_DISPATCH_TEST_TIMEOUT_SECONDS=2700 JETSON_DISPATCH_SSH_DESTINATION=nvidia@192.168.55.1 JETSON_DISPATCH_SSH_IDENTITY_FILE=/var/lib/nemoclaw-jetson-dispatch/id_ed25519 JETSON_DISPATCH_SSH_KNOWN_HOSTS_FILE=/var/lib/nemoclaw-jetson-dispatch/known_hosts -JETSON_DISPATCH_RESET_EXECUTABLE=/usr/local/libexec/nemoclaw-jetson-reset +JETSON_DISPATCH_CLEANUP_EXECUTABLE=/usr/local/libexec/nemoclaw-jetson-cleanup ``` Install `/etc/systemd/system/nemoclaw-jetson-dispatch.service`: @@ -228,7 +289,7 @@ ReadWritePaths=/var/lib/nemoclaw-jetson-dispatch WantedBy=multi-user.target ``` -Start the service and confirm that it listens only on loopback: +Start the service and confirm that it listens only on the loopback address: ```bash sudo systemctl daemon-reload @@ -370,32 +431,42 @@ The uploaded `e2e-jetson-nvmap-gpu` artifact must contain `jetson-dispatch.json` - The requested candidate commit SHA and workflow run identity. - The Jetson model, JetPack package version or `unavailable`, Jetson Linux release, and kernel. - The test conclusion and bounded log. -- `reset: "succeeded"` before `conclusion: "success"`. +- `cleanup: "succeeded"` before `conclusion: "success"`. It must also contain `jetson-e2e-artifacts.tar.gz`. The dispatcher creates that archive from the remote E2E artifact directory before it removes the candidate workspace. It rejects an artifact directory or compressed archive larger than 1 MiB. -After the workflow completes, independently rerun the baseline checks. -Then run one controlled failing candidate and confirm that its artifact records the same reset evidence. +After the workflow completes, independently verify every allowlisted resource is absent. +Then run one controlled failing candidate and confirm that its artifact records the same cleanup evidence. For a cancellation proof, cancel a controller after it logs the job ID. -The controller can exit before it downloads an artifact, so inspect the private Colossus -`.json` status for `conclusion: "cancelled"` and `reset: "succeeded"` instead. -Independently rerun the baseline checks after that cancellation. +The controller can exit before it downloads an artifact. +Inspect the private Colossus `.json` status for `conclusion: "cancelled"` and `cleanup: "succeeded"`. +Independently verify the cleanup allowlist after that cancellation. + +These checks establish bounded cleanup of the allowlisted resources. +They do not attest that cleanup reversed every possible host change made by candidate code. ## Recover or Disable the Deployment The dispatcher permits one active job. -A process crash leaves `device.lock` in the state directory. -On restart, the dispatcher invokes the reset program before it removes that stale lock or accepts more work. -If reset fails, startup fails or the completed job reports `conclusion: "reset-failed"` with `reset: "failed"`. -If reset succeeds but lock removal fails, the completed job reports `conclusion: "reset-failed"` with `reset: "succeeded"`. +A process interruption leaves `device.lock` in the state directory. +On startup, the dispatcher invokes the cleanup program before it removes that stale lock or accepts more work. +If cleanup fails, startup fails or the completed job reports `conclusion: "cleanup-failed"` with `cleanup: "failed"`. +If cleanup succeeds but lock removal fails, the completed job reports `conclusion: "cleanup-failed"` with `cleanup: "succeeded"`. The lock remains in either case. Do not delete `device.lock` to bypass recovery. -For `reset: "failed"`, repair the reset path. -For `reset: "succeeded"` with a lock-removal error, repair the state-directory filesystem or permissions. -Then restart the dispatcher; startup runs and verifies another reset before removing the stale lock. +For `cleanup: "failed"`, repair the cleanup program or the allowlisted resource state. +For `cleanup: "succeeded"` with a lock-removal error, repair the state-directory filesystem or permissions. +Restart the dispatcher after the repair. +Startup runs cleanup and absence verification again before it removes the stale lock. + +Do not dispatch another job when cleanup verification is inconclusive. +Manual recovery must stay within the same cleanup allowlist. +Escalate any suspected protected baseline change for separate host investigation. +Cleanup evidence alone is not evidence that every candidate host change was reversed. + Preserve the job JSON and log files for diagnosis. These private state files can contain candidate output, and the dispatcher does not prune them. Apply the host's approved retention policy after GitHub uploads the artifact and no device lock exists. @@ -409,8 +480,8 @@ sudo systemctl disable --now nemoclaw-jetson-dispatch.service ``` Reauthenticate with `cloudflared tunnel login` as a Cloudflare administrator. -Delete the `jetson-e2e.example.com` DNS record from the Cloudflare zone, then delete the named -tunnel with `cloudflared tunnel delete TUNNEL_UUID`. +Delete the `jetson-e2e.example.com` DNS record from the Cloudflare zone. +Delete the named tunnel with `cloudflared tunnel delete TUNNEL_UUID`. Confirm that `cloudflared tunnel list` no longer returns `TUNNEL_UUID`. Remove the new local account certificate after the administrative deletion. Remove the local tunnel credential, configuration, and service unit: @@ -440,5 +511,4 @@ test -z "$(gh variable list --repo NVIDIA/NemoClaw --json name \ Remove the dedicated Jetson public key and the Colossus SSH private key. After the required retention period, remove the private job state and logs. -Remove the dispatcher environment, service unit, and trusted checkout when no investigation or -rollback requirement remains. +Remove the dispatcher environment, service unit, and trusted checkout when no investigation or rollback requirement remains. diff --git a/test/e2e/live/jetson-nvmap-gpu.test.ts b/test/e2e/live/jetson-nvmap-gpu.test.ts index b69de1713a9..6e0c72e06f6 100644 --- a/test/e2e/live/jetson-nvmap-gpu.test.ts +++ b/test/e2e/live/jetson-nvmap-gpu.test.ts @@ -21,12 +21,17 @@ const TIMEOUT_MS = 50 * 60_000; function env(extra: NodeJS.ProcessEnv = {}): NodeJS.ProcessEnv { return { ...buildAvailabilityProbeEnv(), + NEMOCLAW_DEFER_OPENSHELL_INSTALL: process.env.NEMOCLAW_DEFER_OPENSHELL_INSTALL, NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE: "1", NEMOCLAW_NON_INTERACTIVE: "1", NEMOCLAW_PROVIDER: process.env.NEMOCLAW_PROVIDER ?? "ollama", NEMOCLAW_RECREATE_SANDBOX: "1", NEMOCLAW_SANDBOX_NAME: SANDBOX_NAME, OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY ?? "nemoclaw", + XDG_CACHE_HOME: process.env.XDG_CACHE_HOME, + XDG_DATA_HOME: process.env.XDG_DATA_HOME, + XDG_STATE_HOME: process.env.XDG_STATE_HOME, + npm_config_prefix: process.env.npm_config_prefix, ...extra, }; } @@ -55,9 +60,7 @@ fi if command -v openshell >/dev/null 2>&1; then openshell sandbox delete "$NEMOCLAW_SANDBOX_NAME" 2>/dev/null || true openshell gateway destroy -g nemoclaw 2>/dev/null || true -fi -pkill -f "ollama serve" 2>/dev/null || true -pkill -f "ollama-auth-proxy" 2>/dev/null || true`, +fi`, "cleanup-jetson-nvmap", 120_000, ).catch(() => undefined); @@ -112,25 +115,6 @@ fi`, "Not a Jetson/Tegra host (/dev/nvmap absent) — reporter workflow requires Jetson hardware; hermetic #4231 coverage remains in src/lib/onboard/docker-gpu-patch.test.ts.", ); - cleanup.trackDisposable("stop Jetson Ollama processes", async () => { - const stop = await hostShell( - host, - String.raw`set +e -status=0 -for pattern in '[o]llama serve' '[o]llama-auth-proxy'; do - pkill -f "$pattern" - rc=$? - case "$rc" in - 0|1) ;; - *) status="$rc" ;; - esac -done -exit "$status"`, - "cleanup-jetson-ollama-processes", - 120_000, - ); - expect(stop.exitCode, resultText(stop)).toBe(0); - }); const gatewayCleanupOptions = { artifactName: "cleanup-jetson-openshell-gateway", env: env(), @@ -224,17 +208,13 @@ exit "$status"`, // A3: preserve the reporter workflow by installing/running the real onboarding shell path. progress.phase("install NemoClaw on the Jetson host"); - const installOllama = await hostShell( + const ollamaBaseline = await hostShell( host, - 'if [ "${NEMOCLAW_PROVIDER:-ollama}" = "ollama" ] && ! command -v ollama >/dev/null 2>&1; then\n' + - " curl -fsSL https://ollama.com/install.sh | sh 2>&1 || true\n" + - " systemctl stop ollama 2>/dev/null || true\n" + - ' pkill -f "ollama serve" 2>/dev/null || true\n' + - "fi", - "phase-1-install-ollama-if-needed", - 10 * 60_000, + "command -v ollama && ollama list", + "phase-1-ollama-baseline", + 120_000, ); - expect(installOllama.exitCode, resultText(installOllama)).toBe(0); + expect(ollamaBaseline.exitCode, resultText(ollamaBaseline)).toBe(0); const install = await host.command("bash", ["install.sh", "--non-interactive"], { artifactName: "phase-2-install-jetson-nvmap", diff --git a/test/e2e/support/jetson-dispatch-contract.test.ts b/test/e2e/support/jetson-dispatch-contract.test.ts index f4ba40e7b51..8239319cfd1 100644 --- a/test/e2e/support/jetson-dispatch-contract.test.ts +++ b/test/e2e/support/jetson-dispatch-contract.test.ts @@ -123,7 +123,7 @@ async function waitForCompletion( } function worker( - options: { run?: JetsonDispatchWorker["run"]; reset?: JetsonDispatchWorker["reset"] } = {}, + options: { cleanup?: JetsonDispatchWorker["cleanup"]; run?: JetsonDispatchWorker["run"] } = {}, ): JetsonDispatchWorker { return { run: @@ -138,7 +138,7 @@ function worker( }, log: "passed\n", })), - reset: options.reset ?? (async () => {}), + cleanup: options.cleanup ?? (async () => {}), }; } @@ -147,7 +147,7 @@ function coordinator(stateDirectory: string, dispatchWorker: JetsonDispatchWorke stateDirectory, worker: dispatchWorker, executionTimeoutMs: 60_000, - resetTimeoutMs: 10_000, + cleanupTimeoutMs: 10_000, }); } @@ -285,7 +285,7 @@ describe("Jetson single-device lifecycle", () => { conclusion: "success", createdAt: new Date(0).toISOString(), completedAt: new Date(0).toISOString(), - reset: "succeeded", + cleanup: "succeeded", }, }; @@ -294,9 +294,9 @@ describe("Jetson single-device lifecycle", () => { ); }); - it("records success only after reset succeeds (#8142)", async () => { - const reset = vi.fn(async () => {}); - const dispatch = coordinator(temporaryDirectory(), worker({ reset })); + it("records success only after cleanup succeeds (#8142)", async () => { + const cleanup = vi.fn(async () => {}); + const dispatch = coordinator(temporaryDirectory(), worker({ cleanup })); await dispatch.initialize(); const accepted = dispatch.dispatch(REQUEST, identity()); const completed = await waitForCompletion(dispatch, accepted.jobId); @@ -304,16 +304,34 @@ describe("Jetson single-device lifecycle", () => { expect(completed).toMatchObject({ state: "completed", conclusion: "success", - reset: "succeeded", + cleanup: "succeeded", device: { model: "NVIDIA Jetson AGX Thor Developer Kit" }, }); - expect(reset).toHaveBeenCalledOnce(); + expect(cleanup).toHaveBeenCalledOnce(); expect(dispatch.artifact(accepted.jobId)).toMatchObject({ artifactArchiveBase64: ARTIFACT_ARCHIVE_BASE64, log: "passed\n", }); }); + it("records test failure after cleanup succeeds (#8142)", async () => { + const cleanup = vi.fn(async () => {}); + const dispatch = coordinator( + temporaryDirectory(), + worker({ cleanup, run: async () => Promise.reject(new Error("test failed")) }), + ); + await dispatch.initialize(); + const accepted = dispatch.dispatch(REQUEST, identity()); + const completed = await waitForCompletion(dispatch, accepted.jobId); + + expect(completed).toMatchObject({ + cleanup: "succeeded", + conclusion: "failure", + error: "test failed", + }); + expect(cleanup).toHaveBeenCalledOnce(); + }); + it("returns completed evidence when its result log is missing (#8142)", async () => { const stateDirectory = temporaryDirectory(); const dispatch = coordinator(stateDirectory, worker()); @@ -346,29 +364,36 @@ describe("Jetson single-device lifecycle", () => { await waitForCompletion(dispatch, accepted.jobId); }); - it("cancels the worker and still resets the device (#8142)", async () => { - const reset = vi.fn(async () => {}); + it("cancels the worker and still cleans the device with a fresh signal (#8142)", async () => { + let runSignal: AbortSignal | undefined; + let cleanupSignal: AbortSignal | undefined; + const cleanup = vi.fn(async (options: { jobId: string; signal: AbortSignal }) => { + cleanupSignal = options.signal; + }); const run = vi.fn( (_request, options) => new Promise((_resolve, reject) => { + runSignal = options.signal; options.signal.addEventListener("abort", () => reject(new Error("cancelled")), { once: true, }); }), ); - const dispatch = coordinator(temporaryDirectory(), worker({ reset, run })); + const dispatch = coordinator(temporaryDirectory(), worker({ cleanup, run })); await dispatch.initialize(); const accepted = dispatch.dispatch(REQUEST, identity()); dispatch.cancel(accepted.jobId); const completed = await waitForCompletion(dispatch, accepted.jobId); - expect(completed).toMatchObject({ conclusion: "cancelled", reset: "succeeded" }); - expect(reset).toHaveBeenCalledOnce(); + expect(completed).toMatchObject({ cleanup: "succeeded", conclusion: "cancelled" }); + expect(cleanup).toHaveBeenCalledOnce(); + expect(cleanupSignal).not.toBe(runSignal); + expect(cleanupSignal?.aborted).toBe(false); }); - it("times out the worker and still resets the device (#8142)", async () => { + it("times out the worker and still cleans the device (#8142)", async () => { vi.useFakeTimers(); - const reset = vi.fn(async () => {}); + const cleanup = vi.fn(async () => {}); const run = vi.fn( (_request, options) => new Promise((_resolve, reject) => { @@ -377,30 +402,30 @@ describe("Jetson single-device lifecycle", () => { }); }), ); - const dispatch = coordinator(temporaryDirectory(), worker({ reset, run })); + const dispatch = coordinator(temporaryDirectory(), worker({ cleanup, run })); await dispatch.initialize(); const accepted = dispatch.dispatch(REQUEST, identity()); await vi.advanceTimersByTimeAsync(60_000); const completed = await waitForCompletion(dispatch, accepted.jobId); - expect(completed).toMatchObject({ conclusion: "timed-out", reset: "succeeded" }); - expect(reset).toHaveBeenCalledOnce(); + expect(completed).toMatchObject({ cleanup: "succeeded", conclusion: "timed-out" }); + expect(cleanup).toHaveBeenCalledOnce(); }); - it("keeps reset evidence accurate when lock removal fails (#8142)", async () => { - const reset = vi.fn(async () => {}); + it("keeps cleanup evidence accurate when lock removal fails (#8142)", async () => { + const cleanup = vi.fn(async () => {}); vi.spyOn(fs, "unlinkSync").mockImplementationOnce(() => { throw new Error("lock filesystem unavailable"); }); - const dispatch = coordinator(temporaryDirectory(), worker({ reset })); + const dispatch = coordinator(temporaryDirectory(), worker({ cleanup })); await dispatch.initialize(); const accepted = dispatch.dispatch(REQUEST, identity()); const completed = await waitForCompletion(dispatch, accepted.jobId); expect(completed).toMatchObject({ - conclusion: "reset-failed", + conclusion: "cleanup-failed", error: "Jetson lock removal failed: lock filesystem unavailable", - reset: "succeeded", + cleanup: "succeeded", }); }); @@ -422,36 +447,73 @@ describe("Jetson single-device lifecycle", () => { expect(fs.existsSync(path.join(stateDirectory, `${firstJobId}.json`))).toBe(true); }); - it("keeps the device locked when reset fails (#8142)", async () => { + it("keeps the device locked when cleanup fails (#8142)", async () => { const stateDirectory = temporaryDirectory(); const dispatch = coordinator( stateDirectory, - worker({ reset: async () => Promise.reject(new Error("reset helper failed")) }), + worker({ cleanup: async () => Promise.reject(new Error("cleanup helper failed")) }), ); await dispatch.initialize(); const accepted = dispatch.dispatch(REQUEST, identity()); const completed = await waitForCompletion(dispatch, accepted.jobId); - expect(completed).toMatchObject({ conclusion: "reset-failed", reset: "failed" }); + expect(completed).toMatchObject({ cleanup: "failed", conclusion: "cleanup-failed" }); expect(fs.existsSync(path.join(stateDirectory, "device.lock"))).toBe(true); expect(() => dispatch.dispatch({ ...REQUEST, candidateSha: "c".repeat(40) }, identity()), ).toThrow("Jetson device lock requires recovery"); await expect(dispatch.shutdown()).rejects.toThrow( - "Jetson device lock still requires reset recovery", + "Jetson device lock still requires cleanup recovery", + ); + }); + + it("reports both candidate and cleanup failures while retaining the lock (#8142)", async () => { + const stateDirectory = temporaryDirectory(); + const dispatch = coordinator( + stateDirectory, + worker({ + cleanup: async () => Promise.reject(new Error("cleanup verification failed")), + run: async () => Promise.reject(new Error("artifact collection failed")), + }), ); + await dispatch.initialize(); + const accepted = dispatch.dispatch(REQUEST, identity()); + const completed = await waitForCompletion(dispatch, accepted.jobId); + + expect(completed).toMatchObject({ + cleanup: "failed", + conclusion: "cleanup-failed", + error: "artifact collection failed; Jetson cleanup failed: cleanup verification failed", + }); + expect(fs.existsSync(path.join(stateDirectory, "device.lock"))).toBe(true); }); - it("resets a stale lock before accepting work after restart (#8142)", async () => { + it("cleans a stale lock before accepting work after restart (#8142)", async () => { const stateDirectory = temporaryDirectory(); - fs.writeFileSync(path.join(stateDirectory, "device.lock"), "stale-job\n", { mode: 0o600 }); - const reset = vi.fn(async () => {}); - const dispatch = coordinator(stateDirectory, worker({ reset })); + const staleJobId = "d".repeat(64); + fs.writeFileSync(path.join(stateDirectory, "device.lock"), `${staleJobId}\n`, { mode: 0o600 }); + const cleanup = vi.fn(async () => {}); + const dispatch = coordinator(stateDirectory, worker({ cleanup })); await dispatch.initialize(); - expect(reset).toHaveBeenCalledOnce(); + expect(cleanup).toHaveBeenCalledWith({ jobId: staleJobId, signal: expect.any(AbortSignal) }); expect(fs.existsSync(path.join(stateDirectory, "device.lock"))).toBe(false); }); + + it("rejects a stale lock that cannot identify one dispatcher job (#8142)", async () => { + const stateDirectory = temporaryDirectory(); + fs.writeFileSync(path.join(stateDirectory, "device.lock"), "../../arbitrary-path\n", { + mode: 0o600, + }); + const cleanup = vi.fn(async () => {}); + const dispatch = coordinator(stateDirectory, worker({ cleanup })); + + await expect(dispatch.initialize()).rejects.toThrow( + "Jetson device lock contains an invalid job ID", + ); + expect(cleanup).not.toHaveBeenCalled(); + expect(fs.existsSync(path.join(stateDirectory, "device.lock"))).toBe(true); + }); }); describe("Jetson dispatch HTTP boundary", () => { @@ -469,7 +531,7 @@ describe("Jetson dispatch HTTP boundary", () => { request: REQUEST, state: "queued", createdAt: new Date(0).toISOString(), - reset: "pending", + cleanup: "pending", }, jobId, now: () => 10_000, @@ -491,14 +553,14 @@ describe("Jetson dispatch HTTP boundary", () => { request: REQUEST, state: "queued", createdAt: new Date(0).toISOString(), - reset: "pending", + cleanup: "pending", }; const completed = { job: { ...initialStatus, state: "completed", conclusion: "success", - reset: "succeeded", + cleanup: "succeeded", }, }; const recoveredRequest = vi @@ -597,7 +659,7 @@ describe("Jetson dispatch HTTP boundary", () => { expect(artifact.status).toBe(200); await expect(artifact.json()).resolves.toMatchObject({ log: "passed\n", - status: { conclusion: "success", reset: "succeeded" }, + status: { cleanup: "succeeded", conclusion: "success" }, }); } finally { await new Promise((resolve, reject) => diff --git a/test/e2e/support/jetson-dispatch-worker.test.ts b/test/e2e/support/jetson-dispatch-worker.test.ts index a60c1b7322f..8e0d58f1904 100644 --- a/test/e2e/support/jetson-dispatch-worker.test.ts +++ b/test/e2e/support/jetson-dispatch-worker.test.ts @@ -17,7 +17,29 @@ const dispatcherRunbook = fs.readFileSync( path.join(process.cwd(), "test/e2e/docs/jetson-colossus-dispatch.md"), "utf8", ); +const cleanupProgram = fs.readFileSync( + path.join(process.cwd(), "tools/e2e/jetson-dispatch-cleanup.sh"), + "utf8", +); const temporaryDirectories: string[] = []; +const BASELINE = { + nodePath: "/usr/bin/node", + nodeVersion: "v22.19.0", + npmPath: "/usr/bin/npm", + npmVersion: "10.9.3", + ollamaPath: "/usr/local/bin/ollama", + ollamaModelsSha256: "a".repeat(64), + openshellPath: "/usr/local/bin/openshell", +}; + +function baselineOutput(overrides: Partial = {}): string { + const baseline = { ...BASELINE, ...overrides }; + return `${Object.entries(baseline) + .map(([key, value]) => `${key}\t${value}`) + .join("\n")}\n`; +} + +const BASELINE_OUTPUT = baselineOutput(); afterEach(() => { for (const directory of temporaryDirectories.splice(0)) { @@ -30,11 +52,11 @@ function deploymentFiles() { temporaryDirectories.push(directory); const identityFile = path.join(directory, "id_ed25519"); const knownHostsFile = path.join(directory, "known_hosts"); - const resetExecutable = path.join(directory, "reset-jetson"); + const cleanupExecutable = path.join(directory, "cleanup-jetson"); fs.writeFileSync(identityFile, "test-key", { mode: 0o600 }); fs.writeFileSync(knownHostsFile, "test-host-key", { mode: 0o600 }); - fs.writeFileSync(resetExecutable, "#!/bin/sh\nexit 0\n", { mode: 0o700 }); - return { identityFile, knownHostsFile, resetExecutable }; + fs.writeFileSync(cleanupExecutable, "#!/bin/sh\nexit 0\n", { mode: 0o700 }); + return { cleanupExecutable, identityFile, knownHostsFile, stateDirectory: directory }; } function environment(files = deploymentFiles()): NodeJS.ProcessEnv { @@ -42,11 +64,15 @@ function environment(files = deploymentFiles()): NodeJS.ProcessEnv { JETSON_DISPATCH_SSH_DESTINATION: "nvidia@192.168.55.1", JETSON_DISPATCH_SSH_IDENTITY_FILE: files.identityFile, JETSON_DISPATCH_SSH_KNOWN_HOSTS_FILE: files.knownHostsFile, - JETSON_DISPATCH_RESET_EXECUTABLE: files.resetExecutable, + JETSON_DISPATCH_CLEANUP_EXECUTABLE: files.cleanupExecutable, JETSON_DISPATCH_TEST_TIMEOUT_SECONDS: "2700", }; } +function loadConfig(files = deploymentFiles()) { + return loadSshJetsonWorkerConfig({ stateDirectory: files.stateDirectory }, environment(files)); +} + describe("Colossus SSH worker deployment boundary", () => { it("pins dispatcher deployment to one reviewed commit before service startup (#8142)", () => { const verification = 'test "$(sudo git -C /opt/nemoclaw-jetson-dispatch rev-parse HEAD)" ='; @@ -61,13 +87,14 @@ describe("Colossus SSH worker deployment boundary", () => { expect(dispatcherRunbook).not.toContain("git clone --branch main"); }); - it("loads fixed SSH, host-key, timeout, and reset configuration (#8142)", () => { + it("loads fixed SSH, host-key, timeout, and cleanup configuration (#8142)", () => { const files = deploymentFiles(); - expect(loadSshJetsonWorkerConfig(environment(files))).toEqual({ + expect(loadConfig(files)).toEqual({ + cleanupExecutable: files.cleanupExecutable, destination: "nvidia@192.168.55.1", identityFile: files.identityFile, knownHostsFile: files.knownHostsFile, - resetExecutable: files.resetExecutable, + stateDirectory: files.stateDirectory, testTimeoutSeconds: 2700, }); }); @@ -77,6 +104,7 @@ describe("Colossus SSH worker deployment boundary", () => { const artifactArchiveBase64 = Buffer.from("remote archive").toString("base64"); const processRunner = vi .fn() + .mockResolvedValueOnce({ stdout: BASELINE_OUTPUT, stderr: "" }) .mockResolvedValueOnce({ stdout: "model\tNVIDIA Jetson AGX Thor Developer Kit\njetpackVersion\t7.2.2\njetsonLinuxRelease\tR38\nkernel\t6.8.12-tegra\n", @@ -84,10 +112,7 @@ describe("Colossus SSH worker deployment boundary", () => { }) .mockResolvedValueOnce({ stdout: "test passed\n", stderr: "" }) .mockResolvedValueOnce({ stdout: artifactArchiveBase64, stderr: "" }); - const worker = new SshJetsonDispatchWorker( - loadSshJetsonWorkerConfig(environment(files)), - processRunner, - ); + const worker = new SshJetsonDispatchWorker(loadConfig(files), processRunner); await expect( worker.run( @@ -104,15 +129,16 @@ describe("Colossus SSH worker deployment boundary", () => { artifactArchiveBase64, log: expect.stringContaining("test passed"), }); - expect(processRunner.mock.calls[1]![0].input).not.toContain("trap cleanup EXIT"); - expect(processRunner.mock.calls[2]![0].input).toContain("trap cleanup EXIT"); - expect(processRunner.mock.calls[2]![0].input).toContain("base64 --wrap=0"); + expect(processRunner.mock.calls[2]![0].input).not.toContain("trap cleanup EXIT"); + expect(processRunner.mock.calls[3]![0].input).not.toContain("trap cleanup EXIT"); + expect(processRunner.mock.calls[3]![0].input).toContain("base64 --wrap=0"); }); it("preserves test-failure logs when artifact collection fails (#8142)", async () => { const files = deploymentFiles(); const processRunner = vi .fn() + .mockResolvedValueOnce({ stdout: BASELINE_OUTPUT, stderr: "" }) .mockResolvedValueOnce({ stdout: "model\tNVIDIA Jetson AGX Thor Developer Kit\njetpackVersion\t7.2.2\njetsonLinuxRelease\tR38\nkernel\t6.8.12-tegra\n", @@ -125,10 +151,7 @@ describe("Colossus SSH worker deployment boundary", () => { }), ) .mockRejectedValueOnce(new Error("artifact collection unavailable")); - const worker = new SshJetsonDispatchWorker( - loadSshJetsonWorkerConfig(environment(files)), - processRunner, - ); + const worker = new SshJetsonDispatchWorker(loadConfig(files), processRunner); await expect( worker.run( @@ -151,6 +174,7 @@ describe("Colossus SSH worker deployment boundary", () => { const files = deploymentFiles(); const processRunner = vi .fn() + .mockResolvedValueOnce({ stdout: BASELINE_OUTPUT, stderr: "" }) .mockResolvedValueOnce({ stdout: "model\tNVIDIA Jetson AGX Thor Developer Kit\njetpackVersion\t7.2.2\njetsonLinuxRelease\tR38\nkernel\t6.8.12-tegra\n", @@ -158,10 +182,7 @@ describe("Colossus SSH worker deployment boundary", () => { }) .mockResolvedValueOnce({ stdout: "successful test output\n", stderr: "" }) .mockRejectedValueOnce(new Error("artifact collection unavailable")); - const worker = new SshJetsonDispatchWorker( - loadSshJetsonWorkerConfig(environment(files)), - processRunner, - ); + const worker = new SshJetsonDispatchWorker(loadConfig(files), processRunner); await expect( worker.run( @@ -181,44 +202,126 @@ describe("Colossus SSH worker deployment boundary", () => { }); it.each([ + "nvidia@192.168.55.2", "nvidia@192.168.55.1 -o StrictHostKeyChecking=no", "nvidia@host;uname", "root@", "-oProxyCommand=unsafe", - ])("rejects an SSH destination that is not one fixed user and host: %s (#8142)", (destination) => { + ])("rejects an SSH destination that is not the fixed Jetson user and host: %s (#8142)", (destination) => { + const files = deploymentFiles(); expect(() => - loadSshJetsonWorkerConfig({ - ...environment(), - JETSON_DISPATCH_SSH_DESTINATION: destination, - }), - ).toThrow("JETSON_DISPATCH_SSH_DESTINATION must be a fixed user and host"); + loadSshJetsonWorkerConfig( + { stateDirectory: files.stateDirectory }, + { + ...environment(files), + JETSON_DISPATCH_SSH_DESTINATION: destination, + }, + ), + ).toThrow("JETSON_DISPATCH_SSH_DESTINATION must be nvidia@192.168.55.1"); }); it("rejects a writable SSH identity file (#8142)", () => { const files = deploymentFiles(); fs.chmodSync(files.identityFile, 0o666); - expect(() => loadSshJetsonWorkerConfig(environment(files))).toThrow( - "must not be group- or world-writable", - ); + expect(() => loadConfig(files)).toThrow("must not be group- or world-writable"); }); it("rejects a group-readable SSH identity file (#8142)", () => { const files = deploymentFiles(); fs.chmodSync(files.identityFile, 0o640); - expect(() => loadSshJetsonWorkerConfig(environment(files))).toThrow( - "must be readable only by its owner", - ); + expect(() => loadConfig(files)).toThrow("must be readable only by its owner"); }); - it("rejects a symbolic-link reset executable (#8142)", () => { + it("rejects a symbolic-link cleanup executable (#8142)", () => { const files = deploymentFiles(); - const link = path.join(path.dirname(files.resetExecutable), "reset-link"); - fs.symlinkSync(files.resetExecutable, link); + const link = path.join(path.dirname(files.cleanupExecutable), "cleanup-link"); + fs.symlinkSync(files.cleanupExecutable, link); expect(() => - loadSshJetsonWorkerConfig({ - ...environment(files), - JETSON_DISPATCH_RESET_EXECUTABLE: link, - }), + loadSshJetsonWorkerConfig( + { stateDirectory: files.stateDirectory }, + { + ...environment(files), + JETSON_DISPATCH_CLEANUP_EXECUTABLE: link, + }, + ), ).toThrow("must be a regular file"); }); + + it("invokes the fixed cleanup executable without request-controlled arguments (#8142)", async () => { + const files = deploymentFiles(); + const jobId = "b".repeat(64); + fs.writeFileSync( + path.join(files.stateDirectory, `${jobId}.baseline.json`), + `${JSON.stringify(BASELINE)}\n`, + { mode: 0o600 }, + ); + const processRunner = vi + .fn() + .mockResolvedValueOnce({ stdout: "", stderr: "" }) + .mockResolvedValueOnce({ stdout: BASELINE_OUTPUT, stderr: "" }); + const worker = new SshJetsonDispatchWorker(loadConfig(files), processRunner); + + await expect( + worker.cleanup({ jobId, signal: new AbortController().signal }), + ).resolves.toBeUndefined(); + + expect(processRunner.mock.calls[0]![0]).toMatchObject({ + args: [], + executable: files.cleanupExecutable, + }); + expect(processRunner.mock.calls[0]![0].input).toBeUndefined(); + expect(processRunner.mock.calls[1]![0]).toMatchObject({ + executable: "ssh", + input: expect.stringContaining('workspace="/var/tmp/nemoclaw-jetson-e2e/$job_id"'), + }); + expect(processRunner.mock.calls[1]![0].input).toContain("docker info --format"); + expect(processRunner.mock.calls[1]![0].input).toContain("test -c /dev/nvmap"); + expect(processRunner.mock.calls[1]![0].input).toContain("ollama list"); + expect(processRunner.mock.calls[1]![0].args).toEqual( + expect.arrayContaining(["nvidia@192.168.55.1", "--", jobId]), + ); + }); + + it.each([ + ["Node.js", { nodeVersion: "v22.20.0" }], + ["npm", { npmVersion: "11.0.0" }], + ["Ollama executable", { ollamaPath: "/tmp/ollama" }], + ["Ollama models", { ollamaModelsSha256: "c".repeat(64) }], + ["OpenShell executable", { openshellPath: "/tmp/openshell" }], + ])("rejects cleanup when the protected %s baseline changes (#8142)", async (_name, change) => { + const files = deploymentFiles(); + const jobId = "b".repeat(64); + const baselinePath = path.join(files.stateDirectory, `${jobId}.baseline.json`); + fs.writeFileSync(baselinePath, `${JSON.stringify(BASELINE)}\n`, { mode: 0o600 }); + const processRunner = vi + .fn() + .mockResolvedValueOnce({ stdout: "", stderr: "" }) + .mockResolvedValueOnce({ stdout: baselineOutput(change), stderr: "" }); + const worker = new SshJetsonDispatchWorker(loadConfig(files), processRunner); + + await expect(worker.cleanup({ jobId, signal: new AbortController().signal })).rejects.toThrow( + "Jetson cleanup changed the protected tool or Ollama model baseline", + ); + expect(fs.existsSync(baselinePath)).toBe(true); + }); + + it("keeps cleanup targets fixed and preserves the Jetson baseline (#8142)", () => { + expect(cleanupProgram).toContain("sandbox_name=e2e-jetson-nvmap"); + expect(cleanupProgram).toContain("gateway_name=nemoclaw"); + expect(cleanupProgram).toContain("destination=nvidia@192.168.55.1"); + expect(cleanupProgram).toContain('if [ "$#" -ne 0 ]'); + expect(cleanupProgram).toContain('IFS= read -r job_id <"$lock_file"'); + expect(cleanupProgram).toContain('require_plain_directory_if_present "$service_directory"'); + expect(cleanupProgram).toContain('rm -rf -- "$workspace"'); + expect(cleanupProgram).toContain("ollama-auth-proxy.pid"); + expect(cleanupProgram).toContain('process_uid="$(awk'); + expect(cleanupProgram).toContain('grep -Fqx "HOME=$job_home"'); + expect(cleanupProgram).toContain('kill "$pid"'); + expect(cleanupProgram).toContain("label=openshell.ai/sandbox-name=$sandbox_name"); + expect(cleanupProgram).not.toMatch(/pkill|pgrep|docker (?:system|container|volume) prune/u); + expect(cleanupProgram).not.toContain('rm -rf -- "$workspace_root"'); + expect(cleanupProgram).not.toContain("ollama serve"); + expect(cleanupProgram).not.toMatch(/apt(?:-get)?|boardctl|reboot|shutdown|nvidia-l4t/u); + expect(cleanupProgram).not.toMatch(/npm uninstall|uninstall\.sh|rm .*openshell|rm .*ollama/u); + }); }); diff --git a/test/e2e/support/jetson-workflow-boundary.test.ts b/test/e2e/support/jetson-workflow-boundary.test.ts index d53146dd3d3..b6f7d568f6d 100644 --- a/test/e2e/support/jetson-workflow-boundary.test.ts +++ b/test/e2e/support/jetson-workflow-boundary.test.ts @@ -33,7 +33,7 @@ describe("Jetson nvmap GPU E2E workflow boundary", () => { expect.arrayContaining([ "workflow_dispatch allow_jetson_dispatch input must be boolean", "workflow_dispatch allow_jetson_dispatch input must default to false", - "workflow_dispatch allow_jetson_dispatch input must require the Colossus dispatcher, tunnel, reset helper, repository URL variable, and deployment checks", + "workflow_dispatch allow_jetson_dispatch input must require the Colossus dispatcher, tunnel, cleanup helper, repository URL variable, and deployment checks", ]), ); }); diff --git a/test/helpers/vitest-watch-triggers.ts b/test/helpers/vitest-watch-triggers.ts index c79f04330da..02f1ff0403b 100644 --- a/test/helpers/vitest-watch-triggers.ts +++ b/test/helpers/vitest-watch-triggers.ts @@ -92,6 +92,10 @@ export const vitestWatchTriggerPatterns: VitestWatchTriggerPattern[] = [ pattern: /(?:^|\/)scripts\/setup-jetson\.sh$/, testsToRun: runTests("test/setup-jetson.test.ts"), }, + { + pattern: /(?:^|\/)tools\/e2e\/jetson-dispatch-cleanup\.sh$/, + testsToRun: runTests("test/e2e/support/jetson-dispatch-worker.test.ts"), + }, { pattern: /(?:^|\/)(?:\.github\/workflows\/base-image\.yaml|scripts\/export-managed-base-image-contract\.sh)$/, diff --git a/test/vitest-watch-triggers.test.ts b/test/vitest-watch-triggers.test.ts index f451c048c42..a325a740e29 100644 --- a/test/vitest-watch-triggers.test.ts +++ b/test/vitest-watch-triggers.test.ts @@ -61,6 +61,7 @@ const OPAQUE_INPUTS = [ "agents/hermes/mcp-config-transaction.py", "test/e2e/lib/ci-compatible-inference.sh", "scripts/setup-jetson.sh", + "tools/e2e/jetson-dispatch-cleanup.sh", ".github/workflows/base-image.yaml", "scripts/export-managed-base-image-contract.sh", "scripts/checks/validate-managed-base-index.sh", @@ -125,6 +126,9 @@ describe("Vitest opaque-input watch triggers", () => { "test/e2e/support/hosted-inference.test.ts", ]); expect(triggeredBy("scripts/setup-jetson.sh")).toEqual(["test/setup-jetson.test.ts"]); + expect(triggeredBy("tools/e2e/jetson-dispatch-cleanup.sh")).toEqual([ + "test/e2e/support/jetson-dispatch-worker.test.ts", + ]); expect(triggeredBy(".github/workflows/base-image.yaml")).toEqual([ "test/managed-base-image-contract.test.ts", "test/managed-image-publication-workflow.test.ts", diff --git a/tools/advisors/risk-plan.mts b/tools/advisors/risk-plan.mts index 49256653a7b..89436ca7171 100644 --- a/tools/advisors/risk-plan.mts +++ b/tools/advisors/risk-plan.mts @@ -237,7 +237,7 @@ export function isPrE2eTypedTargetId(value: string): boolean { } export function isPrE2ePlanningJob(value: string): boolean { - // Automatic PR planning cannot attest the external Colossus dispatcher and reset path. + // Automatic PR planning cannot attest the external Colossus dispatcher and cleanup path. // Remove this exclusion after that hardware gate produces trusted planning evidence. return !PR_E2E_PLANNING_OMITTED_JOB_IDS.has(value); } diff --git a/tools/e2e/cli-artifact-workflow-boundary.mts b/tools/e2e/cli-artifact-workflow-boundary.mts index 0d9a8e8ff6f..6989df1ba6c 100644 --- a/tools/e2e/cli-artifact-workflow-boundary.mts +++ b/tools/e2e/cli-artifact-workflow-boundary.mts @@ -39,7 +39,7 @@ const CLI_ARTIFACT_PROVENANCE_STEP = "Record CLI artifact provenance"; const CANDIDATE_CHECKOUT_STEP_CONTENT_SHA256 = "3578a053cede863f7aa4814d8399b4ca21ea0b77cee712e6d549c684818f11dd"; const CLI_ARTIFACT_WORKFLOW_CONTRACT_SHA256 = - "e1e76d322e4f3bafcb407dc78a530e0c98ecabe8f99c184390dadb5fa914efb0"; + "1138f6070c01d615c45ddf42f45dd1bd50ab81c70bb71a3df0d4abf2e0c702d6"; type WorkflowRecord = Record; type WorkflowStep = WorkflowRecord & { diff --git a/tools/e2e/jetson-dispatch-cleanup.sh b/tools/e2e/jetson-dispatch-cleanup.sh new file mode 100755 index 00000000000..8c476090d56 --- /dev/null +++ b/tools/e2e/jetson-dispatch-cleanup.sh @@ -0,0 +1,278 @@ +#!/usr/bin/env bash +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set -euo pipefail + +if [ "$#" -ne 0 ]; then + echo "Jetson cleanup accepts no arguments" >&2 + exit 2 +fi + +state_directory=/var/lib/nemoclaw-jetson-dispatch/state +lock_file="$state_directory/device.lock" +identity_file=/var/lib/nemoclaw-jetson-dispatch/id_ed25519 +known_hosts_file=/var/lib/nemoclaw-jetson-dispatch/known_hosts +destination=nvidia@192.168.55.1 + +IFS= read -r job_id <"$lock_file" +if ! [[ "$job_id" =~ ^[a-f0-9]{64}$ ]]; then + echo "Jetson cleanup lock contains an invalid job ID" >&2 + exit 1 +fi + +exec ssh -F /dev/null -T \ + -o BatchMode=yes \ + -o ConnectTimeout=15 \ + -o IdentitiesOnly=yes \ + -o ServerAliveCountMax=2 \ + -o ServerAliveInterval=15 \ + -o StrictHostKeyChecking=yes \ + -o "UserKnownHostsFile=$known_hosts_file" \ + -i "$identity_file" \ + "$destination" bash -s -- "$job_id" <<'JETSON_CLEANUP' +set -euo pipefail + +job_id="$1" +[[ "$job_id" =~ ^[a-f0-9]{64}$ ]] + +workspace_root=/var/tmp/nemoclaw-jetson-e2e +workspace="$workspace_root/$job_id" +job_home="$workspace/home" +sandbox_name=e2e-jetson-nvmap +gateway_name=nemoclaw +gateway_container=openshell-cluster-nemoclaw +gateway_volume=openshell-cluster-nemoclaw +service_directory="/tmp/nemoclaw-services-$sandbox_name" + +if [ -L "$workspace_root" ] || { [ -e "$workspace_root" ] && [ ! -d "$workspace_root" ]; }; then + echo "Jetson E2E workspace root is not a trusted directory" >&2 + exit 1 +fi +if [ -L "$workspace" ] || { [ -e "$workspace" ] && [ ! -d "$workspace" ]; }; then + echo "Jetson E2E job workspace is not a trusted directory" >&2 + exit 1 +fi +if [ -L "$job_home" ] || { [ -e "$job_home" ] && [ ! -d "$job_home" ]; }; then + echo "Jetson E2E job home is not a trusted directory" >&2 + exit 1 +fi + +require_plain_directory_if_present() { + local directory="$1" + if [ -L "$directory" ] || { [ -e "$directory" ] && [ ! -d "$directory" ]; }; then + echo "Refusing an untrusted cleanup directory: $directory" >&2 + exit 1 + fi +} + +require_plain_directory_if_present "$job_home/.nemoclaw" +require_plain_directory_if_present "$job_home/.local" +require_plain_directory_if_present "$job_home/.local/state" +require_plain_directory_if_present "$job_home/.local/state/nemoclaw" +require_plain_directory_if_present "$job_home/.local/state/nemoclaw/openshell-docker-gateway" +require_plain_directory_if_present "$service_directory" + +recorded_volumes=() +record_volume() { + local volume="$1" + [[ "$volume" =~ ^[A-Za-z0-9][A-Za-z0-9_.-]{0,254}$ ]] || { + echo "Refusing an invalid recorded Docker volume name" >&2 + exit 1 + } + local recorded + for recorded in "${recorded_volumes[@]}"; do + [ "$recorded" = "$volume" ] && return 0 + done + recorded_volumes+=("$volume") +} + +record_container_volumes() { + local container="$1" volume + while IFS= read -r volume; do + [ -n "$volume" ] || continue + record_volume "$volume" + done < <( + docker container inspect --format \ + '{{range .Mounts}}{{if eq .Type "volume"}}{{println .Name}}{{end}}{{end}}' \ + "$container" + ) +} + +mapfile -t sandbox_containers < <( + docker ps -aq \ + --filter label=openshell.ai/managed-by=openshell \ + --filter "label=openshell.ai/sandbox-name=$sandbox_name" +) +for container in "${sandbox_containers[@]}"; do + [[ "$container" =~ ^[a-f0-9]{12,64}$ ]] || { + echo "Refusing an invalid recorded Docker container ID" >&2 + exit 1 + } + record_container_volumes "$container" +done +if docker container inspect "$gateway_container" >/dev/null 2>&1; then + record_container_volumes "$gateway_container" +fi +record_volume "$gateway_volume" + +read_recorded_pid() { + local pid_file="$1" + if [ ! -e "$pid_file" ]; then + return 0 + fi + if [ -L "$pid_file" ] || [ ! -f "$pid_file" ]; then + echo "Refusing an untrusted cleanup PID file: $pid_file" >&2 + exit 1 + fi + local pid + IFS= read -r pid <"$pid_file" + [[ "$pid" =~ ^[1-9][0-9]*$ ]] || { + echo "Refusing an invalid cleanup PID file: $pid_file" >&2 + exit 1 + } + printf '%s\n' "$pid" +} + +auth_proxy_pid="$(read_recorded_pid "$job_home/.nemoclaw/ollama-auth-proxy.pid")" +gateway_pid="$(read_recorded_pid "$job_home/.local/state/nemoclaw/openshell-docker-gateway/openshell-gateway.pid")" +cloudflared_pid="$(read_recorded_pid "$service_directory/cloudflared.pid")" + +stop_recorded_pid() { + local pid="$1" marker="$2" + [ -n "$pid" ] || return 0 + kill -0 "$pid" 2>/dev/null || return 0 + local process_uid cmdline + process_uid="$(awk '/^Uid:/ { print $2; exit }' "/proc/$pid/status")" + [ "$process_uid" = "$(id -u)" ] || { + echo "Refusing to stop a process owned by another user" >&2 + exit 1 + } + cmdline="$(tr '\000' ' ' <"/proc/$pid/cmdline")" + case "$cmdline" in + *"$marker"*) ;; + *) echo "Refusing to stop a recorded PID with an unexpected command" >&2; exit 1 ;; + esac + if ! tr '\000' '\n' <"/proc/$pid/environ" | grep -Fqx "HOME=$job_home"; then + echo "Refusing to stop a process outside the job home" >&2 + exit 1 + fi + kill "$pid" + for _attempt in 1 2 3 4 5 6 7 8 9 10; do + kill -0 "$pid" 2>/dev/null || return 0 + sleep 0.2 + done + kill -KILL "$pid" + for _attempt in 1 2 3 4 5; do + kill -0 "$pid" 2>/dev/null || return 0 + sleep 0.2 + done + echo "Recorded cleanup process $pid did not stop" >&2 + exit 1 +} + +gateway_present=0 +if [ -d "$job_home" ]; then + gateway_json="$(HOME="$job_home" openshell gateway list -o json)" + gateway_state="$(printf '%s' "$gateway_json" | node -e ' + const fs = require("node:fs"); + const rows = JSON.parse(fs.readFileSync(0, "utf8")); + if (!Array.isArray(rows)) throw new Error("invalid gateway list"); + process.stdout.write(rows.some((row) => row && row.name === "nemoclaw") ? "present" : "absent"); + ')" + if [ "$gateway_state" = present ]; then + gateway_present=1 + fi +fi + +if [ "$gateway_present" -eq 1 ]; then + forward_list="$(HOME="$job_home" openshell forward list --gateway "$gateway_name")" + while IFS= read -r port; do + [ -n "$port" ] || continue + [[ "$port" =~ ^[1-9][0-9]{0,4}$ ]] || { + echo "Refusing an invalid recorded OpenShell forward port" >&2 + exit 1 + } + HOME="$job_home" openshell forward stop "$port" "$sandbox_name" + done < <( + printf '%s\n' "$forward_list" | awk -v sandbox="$sandbox_name" \ + '$1 == sandbox && $3 ~ /^[0-9]+$/ { print $3 }' + ) + + sandbox_names="$(HOME="$job_home" openshell sandbox list --names -g "$gateway_name")" + if printf '%s\n' "$sandbox_names" | grep -Fqx "$sandbox_name"; then + HOME="$job_home" openshell sandbox delete "$sandbox_name" + fi + sandbox_names="$(HOME="$job_home" openshell sandbox list --names -g "$gateway_name")" + if printf '%s\n' "$sandbox_names" | grep -Fqx "$sandbox_name"; then + echo "The test-owned OpenShell sandbox remains" >&2 + exit 1 + fi + forward_list="$(HOME="$job_home" openshell forward list --gateway "$gateway_name")" + if printf '%s\n' "$forward_list" | awk -v sandbox="$sandbox_name" \ + '$1 == sandbox && $3 ~ /^[0-9]+$/ { found = 1 } END { exit found ? 0 : 1 }'; then + echo "A test-owned OpenShell forward remains" >&2 + exit 1 + fi + HOME="$job_home" openshell gateway remove "$gateway_name" \ + || HOME="$job_home" openshell gateway destroy -g "$gateway_name" + gateway_json="$(HOME="$job_home" openshell gateway list -o json)" + gateway_state="$(printf '%s' "$gateway_json" | node -e ' + const fs = require("node:fs"); + const rows = JSON.parse(fs.readFileSync(0, "utf8")); + if (!Array.isArray(rows)) throw new Error("invalid gateway list"); + process.stdout.write(rows.some((row) => row && row.name === "nemoclaw") ? "present" : "absent"); + ')" + if [ "$gateway_state" = present ]; then + echo "The test-owned OpenShell gateway remains" >&2 + exit 1 + fi +fi + +stop_recorded_pid "$auth_proxy_pid" ollama-auth-proxy. +stop_recorded_pid "$gateway_pid" openshell-gateway +stop_recorded_pid "$cloudflared_pid" cloudflared + +for container in "${sandbox_containers[@]}"; do + if docker container inspect "$container" >/dev/null 2>&1; then + docker container rm --force "$container" + fi +done +if docker container inspect "$gateway_container" >/dev/null 2>&1; then + docker container rm --force "$gateway_container" +fi +for volume in "${recorded_volumes[@]}"; do + if docker volume inspect "$volume" >/dev/null 2>&1; then + docker volume rm "$volume" + fi +done + +if [ -e "$service_directory" ]; then + rm -rf -- "$service_directory" +fi +if [ -e "$workspace" ]; then + rm -rf -- "$workspace" +fi + +test ! -e "$workspace" +test ! -e "$service_directory" +test -z "$(docker ps -aq \ + --filter label=openshell.ai/managed-by=openshell \ + --filter "label=openshell.ai/sandbox-name=$sandbox_name")" +if docker container inspect "$gateway_container" >/dev/null 2>&1; then + echo "The test-owned gateway container remains" >&2 + exit 1 +fi +for volume in "${recorded_volumes[@]}"; do + if docker volume inspect "$volume" >/dev/null 2>&1; then + echo "A recorded test-owned Docker volume remains" >&2 + exit 1 + fi +done +for pid in "$auth_proxy_pid" "$gateway_pid" "$cloudflared_pid"; do + if [ -n "$pid" ] && kill -0 "$pid" 2>/dev/null; then + echo "A recorded test-owned helper process remains" >&2 + exit 1 + fi +done +JETSON_CLEANUP diff --git a/tools/e2e/jetson-dispatch-lifecycle.mts b/tools/e2e/jetson-dispatch-lifecycle.mts index 08c58a45c04..1c115c6d504 100644 --- a/tools/e2e/jetson-dispatch-lifecycle.mts +++ b/tools/e2e/jetson-dispatch-lifecycle.mts @@ -24,8 +24,8 @@ export const MAX_JETSON_DISPATCH_ARTIFACT_RESPONSE_BYTES = export type JetsonDispatchConclusion = | "cancelled" + | "cleanup-failed" | "failure" - | "reset-failed" | "success" | "timed-out"; @@ -47,7 +47,7 @@ export interface JetsonDispatchWorker { request: JetsonDispatchRequest, options: { jobId: string; signal: AbortSignal }, ): Promise; - reset(options: { signal: AbortSignal }): Promise; + cleanup(options: { jobId: string; signal: AbortSignal }): Promise; } export interface JetsonDispatchStatus { @@ -60,7 +60,7 @@ export interface JetsonDispatchStatus { startedAt?: string; completedAt?: string; device?: JetsonDeviceIdentity; - reset: "pending" | "succeeded" | "failed"; + cleanup: "pending" | "succeeded" | "failed"; error?: string; } @@ -154,7 +154,7 @@ export class JetsonDispatchCoordinator { readonly #lockPath: string; readonly #worker: JetsonDispatchWorker; readonly #executionTimeoutMs: number; - readonly #resetTimeoutMs: number; + readonly #cleanupTimeoutMs: number; readonly #jobs = new Map(); #activeJobId: string | undefined; #activeAbort: AbortController | undefined; @@ -166,7 +166,7 @@ export class JetsonDispatchCoordinator { stateDirectory: string; worker: JetsonDispatchWorker; executionTimeoutMs: number; - resetTimeoutMs: number; + cleanupTimeoutMs: number; }) { if (!path.isAbsolute(options.stateDirectory)) { throw new Error("Jetson dispatcher state directory must be absolute"); @@ -179,17 +179,17 @@ export class JetsonDispatchCoordinator { throw new Error("Jetson execution timeout must be between 1 and 55 minutes"); } if ( - !Number.isSafeInteger(options.resetTimeoutMs) || - options.resetTimeoutMs < 10_000 || - options.resetTimeoutMs > 10 * 60_000 + !Number.isSafeInteger(options.cleanupTimeoutMs) || + options.cleanupTimeoutMs < 10_000 || + options.cleanupTimeoutMs > 10 * 60_000 ) { - throw new Error("Jetson reset timeout must be between 10 seconds and 10 minutes"); + throw new Error("Jetson cleanup timeout must be between 10 seconds and 10 minutes"); } this.#stateDirectory = options.stateDirectory; this.#lockPath = path.join(options.stateDirectory, "device.lock"); this.#worker = options.worker; this.#executionTimeoutMs = options.executionTimeoutMs; - this.#resetTimeoutMs = options.resetTimeoutMs; + this.#cleanupTimeoutMs = options.cleanupTimeoutMs; } async initialize(): Promise { @@ -200,7 +200,13 @@ export class JetsonDispatchCoordinator { maxBytes: 1024, }); if (staleLock !== null) { - await withTimeout(this.#resetTimeoutMs, (signal) => this.#worker.reset({ signal })); + const jobId = staleLock.trim(); + if (!/^[a-f0-9]{64}$/u.test(jobId)) { + throw new Error("Jetson device lock contains an invalid job ID"); + } + await withTimeout(this.#cleanupTimeoutMs, (signal) => + this.#worker.cleanup({ jobId, signal }), + ); fs.unlinkSync(this.#lockPath); } this.#initialized = true; @@ -236,7 +242,7 @@ export class JetsonDispatchCoordinator { request: structuredClone(request), state: "queued", createdAt: new Date().toISOString(), - reset: "pending", + cleanup: "pending", }; try { this.#persist(status); @@ -280,7 +286,7 @@ export class JetsonDispatchCoordinator { maxBytes: 1024, }) !== null ) { - throw new Error("Jetson device lock still requires reset recovery"); + throw new Error("Jetson device lock still requires cleanup recovery"); } } @@ -351,19 +357,25 @@ export class JetsonDispatchCoordinator { } finally { clearTimeout(timer); try { - await withTimeout(this.#resetTimeoutMs, (signal) => this.#worker.reset({ signal })); - status.reset = "succeeded"; + await withTimeout(this.#cleanupTimeoutMs, (signal) => + this.#worker.cleanup({ jobId: status.jobId, signal }), + ); + status.cleanup = "succeeded"; } catch (error) { - status.reset = "failed"; - status.error = `Jetson reset failed: ${safeError(error)}`; - conclusion = "reset-failed"; + status.cleanup = "failed"; + const cleanupError = `Jetson cleanup failed: ${safeError(error)}`; + status.error = status.error + ? `${status.error}; ${cleanupError}`.slice(0, 500) + : cleanupError; + conclusion = "cleanup-failed"; } - if (status.reset === "succeeded") { + if (status.cleanup === "succeeded") { try { fs.unlinkSync(this.#lockPath); } catch (error) { - status.error = `Jetson lock removal failed: ${safeError(error)}`; - conclusion = "reset-failed"; + const lockError = `Jetson lock removal failed: ${safeError(error)}`; + status.error = status.error ? `${status.error}; ${lockError}`.slice(0, 500) : lockError; + conclusion = "cleanup-failed"; } } status.conclusion = conclusion; diff --git a/tools/e2e/jetson-dispatch-service.mts b/tools/e2e/jetson-dispatch-service.mts index 3dc460f52fc..738a71fc126 100644 --- a/tools/e2e/jetson-dispatch-service.mts +++ b/tools/e2e/jetson-dispatch-service.mts @@ -199,13 +199,13 @@ async function main(): Promise { 120, 55 * 60, ); - const resetTimeoutSeconds = positiveIntegerEnvironment( - process.env.JETSON_DISPATCH_RESET_TIMEOUT_SECONDS, - "JETSON_DISPATCH_RESET_TIMEOUT_SECONDS", + const cleanupTimeoutSeconds = positiveIntegerEnvironment( + process.env.JETSON_DISPATCH_CLEANUP_TIMEOUT_SECONDS, + "JETSON_DISPATCH_CLEANUP_TIMEOUT_SECONDS", 10, 10 * 60, ); - const workerConfig = loadSshJetsonWorkerConfig(); + const workerConfig = loadSshJetsonWorkerConfig({ stateDirectory }); if (executionTimeoutSeconds < workerConfig.testTimeoutSeconds + 30) { throw new Error("Jetson execution timeout must exceed the remote test timeout by 30 seconds"); } @@ -213,7 +213,7 @@ async function main(): Promise { stateDirectory, worker: new SshJetsonDispatchWorker(workerConfig), executionTimeoutMs: executionTimeoutSeconds * 1_000, - resetTimeoutMs: resetTimeoutSeconds * 1_000, + cleanupTimeoutMs: cleanupTimeoutSeconds * 1_000, }); await coordinator.initialize(); const server = createJetsonDispatchServer({ diff --git a/tools/e2e/jetson-dispatch-worker.mts b/tools/e2e/jetson-dispatch-worker.mts index 0dfc0e01b4c..635664de7c7 100644 --- a/tools/e2e/jetson-dispatch-worker.mts +++ b/tools/e2e/jetson-dispatch-worker.mts @@ -13,14 +13,15 @@ import { JetsonWorkerResult, MAX_JETSON_ARTIFACT_ARCHIVE_BYTES, } from "./jetson-dispatch-lifecycle.mts"; +import { readPrivateRegularFile, writePrivateRegularFile } from "./private-file.mts"; const MAX_PROCESS_OUTPUT_BYTES = 4 * 1024 * 1024; -const SSH_DESTINATION_PATTERN = - /^[a-z_][a-z0-9_-]{0,31}@[A-Za-z0-9](?:[A-Za-z0-9.-]{0,251}[A-Za-z0-9])?$/u; +const JETSON_SSH_DESTINATION = "nvidia@192.168.55.1"; const SAFE_PROCESS_ENV = { LANG: "C.UTF-8", PATH: "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", }; +const MAX_BASELINE_BYTES = 4 * 1024; const DEVICE_IDENTITY_SCRIPT = String.raw`set -eu clean_line() { tr -d '\000\r\n\t'; } @@ -40,6 +41,52 @@ uname -r | clean_line printf '\n' `; +const PRESERVED_BASELINE_SCRIPT = String.raw`set -euo pipefail +export LC_ALL=C +clean_line() { tr -d '\000\r\n\t'; } +node_path="$(command -v node)" +npm_path="$(command -v npm)" +ollama_path="$(command -v ollama)" +openshell_path="$(command -v openshell)" +test -c /dev/nvmap +docker_runtimes="$(docker info --format '{{json .Runtimes}}')" +case "$docker_runtimes" in + *nvidia*) ;; + *) echo "Docker does not report the NVIDIA runtime" >&2; exit 1 ;; +esac +ollama_models_sha256="$(ollama list | awk 'NR > 1 && NF >= 2 { print $1 "\t" $2 }' | sort | sha256sum | cut -d ' ' -f 1)" +printf 'nodePath\t'; printf '%s' "$node_path" | clean_line +printf '\nnodeVersion\t'; node --version | clean_line +printf '\nnpmPath\t'; printf '%s' "$npm_path" | clean_line +printf '\nnpmVersion\t'; npm --version | clean_line +printf '\nollamaPath\t'; printf '%s' "$ollama_path" | clean_line +printf '\nollamaModelsSha256\t'; printf '%s' "$ollama_models_sha256" | clean_line +printf '\nopenshellPath\t'; printf '%s' "$openshell_path" | clean_line +printf '\n' +`; + +const CLEANUP_VERIFICATION_SCRIPT = + String.raw`set -euo pipefail +job_id="$1" +[[ "$job_id" =~ ^[a-f0-9]{64}$ ]] +workspace="/var/tmp/nemoclaw-jetson-e2e/$job_id" +sandbox_name=e2e-jetson-nvmap +gateway_name=nemoclaw +test ! -e "$workspace" +test ! -L "$workspace" +test -z "$(docker ps -aq \ + --filter label=openshell.ai/managed-by=openshell \ + --filter "label=openshell.ai/sandbox-name=$sandbox_name")" +if docker container inspect "openshell-cluster-$gateway_name" >/dev/null 2>&1; then + echo "The test-owned OpenShell gateway container remains" >&2 + exit 1 +fi +if docker volume inspect "openshell-cluster-$gateway_name" >/dev/null 2>&1; then + echo "The test-owned OpenShell gateway volume remains" >&2 + exit 1 +fi +` + PRESERVED_BASELINE_SCRIPT; + const JETSON_TEST_SCRIPT = String.raw`set -euo pipefail candidate_sha="$1" job_id="$2" @@ -56,10 +103,21 @@ fi install -d -m 0700 "$workspace_root" workspace="$workspace_root/$job_id" if [ -e "$workspace" ]; then - echo "Jetson E2E workspace already exists; reset recovery is required" >&2 + echo "Jetson E2E workspace already exists; cleanup recovery is required" >&2 exit 1 fi install -d -m 0700 "$workspace" +install -d -m 0700 "$workspace/home" "$workspace/npm-prefix" "$workspace/tmp" + +export HOME="$workspace/home" +export TMPDIR="$workspace/tmp" +export XDG_CACHE_HOME="$workspace/home/.cache" +export XDG_CONFIG_HOME="$workspace/home/.config" +export XDG_DATA_HOME="$workspace/home/.local/share" +export XDG_STATE_HOME="$workspace/home/.local/state" +export npm_config_prefix="$workspace/npm-prefix" +export PATH="$workspace/npm-prefix/bin:$PATH" +export NEMOCLAW_DEFER_OPENSHELL_INSTALL=1 git init --quiet "$workspace/repository" git -C "$workspace/repository" remote add origin https://github.com/NVIDIA/NemoClaw.git @@ -98,10 +156,6 @@ const COLLECT_ARTIFACT_SCRIPT = String.raw`set -euo pipefail job_id="$1" [[ "$job_id" =~ ^[a-f0-9]{64}$ ]] workspace="/var/tmp/nemoclaw-jetson-e2e/$job_id" -cleanup() { - rm -rf -- "$workspace" -} -trap cleanup EXIT artifact_directory="$workspace/e2e-artifacts/live/jetson-nvmap-gpu" if [ ! -d "$artifact_directory" ] || [ -L "$artifact_directory" ]; then @@ -124,10 +178,11 @@ base64 --wrap=0 "$archive" `; export interface SshJetsonWorkerConfig { + cleanupExecutable: string; destination: string; identityFile: string; knownHostsFile: string; - resetExecutable: string; + stateDirectory: string; testTimeoutSeconds: number; } @@ -170,23 +225,28 @@ function positiveIntegerEnvironment( } export function loadSshJetsonWorkerConfig( + options: { stateDirectory: string }, env: NodeJS.ProcessEnv = process.env, ): SshJetsonWorkerConfig { + if (!path.isAbsolute(options.stateDirectory)) { + throw new Error("Jetson dispatcher state directory must be absolute"); + } const destination = env.JETSON_DISPATCH_SSH_DESTINATION ?? ""; - if (!SSH_DESTINATION_PATTERN.test(destination)) { - throw new Error("JETSON_DISPATCH_SSH_DESTINATION must be a fixed user and host"); + if (destination !== JETSON_SSH_DESTINATION) { + throw new Error(`JETSON_DISPATCH_SSH_DESTINATION must be ${JETSON_SSH_DESTINATION}`); } const identityFile = env.JETSON_DISPATCH_SSH_IDENTITY_FILE ?? ""; const knownHostsFile = env.JETSON_DISPATCH_SSH_KNOWN_HOSTS_FILE ?? ""; - const resetExecutable = env.JETSON_DISPATCH_RESET_EXECUTABLE ?? ""; + const cleanupExecutable = env.JETSON_DISPATCH_CLEANUP_EXECUTABLE ?? ""; requireSecureFile(identityFile, { private: true }); requireSecureFile(knownHostsFile, {}); - requireSecureFile(resetExecutable, { executable: true }); + requireSecureFile(cleanupExecutable, { executable: true }); return { + cleanupExecutable, destination, identityFile, knownHostsFile, - resetExecutable, + stateDirectory: options.stateDirectory, testTimeoutSeconds: positiveIntegerEnvironment( env.JETSON_DISPATCH_TEST_TIMEOUT_SECONDS, "JETSON_DISPATCH_TEST_TIMEOUT_SECONDS", @@ -314,6 +374,90 @@ function parseDeviceIdentity(output: string): JetsonDeviceIdentity { }; } +interface JetsonPreservedBaseline { + nodePath: string; + nodeVersion: string; + npmPath: string; + npmVersion: string; + ollamaPath: string; + ollamaModelsSha256: string; + openshellPath: string; +} + +function parsePreservedBaseline(output: string): JetsonPreservedBaseline { + if (Buffer.byteLength(output) > MAX_BASELINE_BYTES) { + throw new Error("Jetson protected-baseline output is too large"); + } + const entries = new Map(); + for (const line of output.trimEnd().split("\n")) { + const separator = line.indexOf("\t"); + if (separator < 1) throw new Error("Jetson protected-baseline output is malformed"); + const key = line.slice(0, separator); + const value = line.slice(separator + 1); + if (entries.has(key) || value.length === 0 || /[\u0000-\u001f\u007f]/u.test(value)) { + throw new Error("Jetson protected-baseline output is malformed"); + } + entries.set(key, value); + } + const expected = [ + "nodePath", + "nodeVersion", + "npmPath", + "npmVersion", + "ollamaPath", + "ollamaModelsSha256", + "openshellPath", + ] as const; + if (entries.size !== expected.length || expected.some((key) => !entries.has(key))) { + throw new Error("Jetson protected-baseline output is incomplete"); + } + const baseline: JetsonPreservedBaseline = { + nodePath: entries.get("nodePath")!, + nodeVersion: entries.get("nodeVersion")!, + npmPath: entries.get("npmPath")!, + npmVersion: entries.get("npmVersion")!, + ollamaPath: entries.get("ollamaPath")!, + ollamaModelsSha256: entries.get("ollamaModelsSha256")!, + openshellPath: entries.get("openshellPath")!, + }; + if (!/^[a-f0-9]{64}$/u.test(baseline.ollamaModelsSha256)) { + throw new Error("Jetson protected-baseline Ollama model digest is malformed"); + } + return baseline; +} + +function parsePreservedBaselineJson(output: string): JetsonPreservedBaseline { + if (Buffer.byteLength(output) > MAX_BASELINE_BYTES) { + throw new Error("Jetson protected-baseline record is too large"); + } + let parsed: unknown; + try { + parsed = JSON.parse(output); + } catch { + throw new Error("Jetson protected-baseline record is malformed"); + } + if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) { + throw new Error("Jetson protected-baseline record is malformed"); + } + const record = parsed as Record; + const expected = [ + "nodePath", + "nodeVersion", + "npmPath", + "npmVersion", + "ollamaPath", + "ollamaModelsSha256", + "openshellPath", + ]; + if ( + Object.keys(record).length !== expected.length || + expected.some((key) => typeof record[key] !== "string") + ) { + throw new Error("Jetson protected-baseline record is incomplete"); + } + return parsePreservedBaseline(expected.map((key) => `${key}\t${record[key]}`).join("\n")); +} + export class SshJetsonDispatchWorker implements JetsonDispatchWorker { readonly #config: SshJetsonWorkerConfig; readonly #runProcess: typeof runProcess; @@ -327,6 +471,14 @@ export class SshJetsonDispatchWorker implements JetsonDispatchWorker { request: JetsonDispatchRequest, options: { jobId: string; signal: AbortSignal }, ): Promise { + const baselineResult = await this.#runProcess({ + executable: "ssh", + args: [...this.#sshArgs(), this.#config.destination, "bash", "-s"], + input: PRESERVED_BASELINE_SCRIPT, + signal: options.signal, + }); + const baseline = parsePreservedBaseline(baselineResult.stdout); + writePrivateRegularFile(this.#baselinePath(options.jobId), `${JSON.stringify(baseline)}\n`); const identityResult = await this.#runProcess({ executable: "ssh", args: [...this.#sshArgs(), this.#config.destination, "bash", "-s"], @@ -438,12 +590,33 @@ export class SshJetsonDispatchWorker implements JetsonDispatchWorker { return result.stdout; } - async reset(options: { signal: AbortSignal }): Promise { + async cleanup(options: { jobId: string; signal: AbortSignal }): Promise { await this.#runProcess({ - executable: this.#config.resetExecutable, + executable: this.#config.cleanupExecutable, args: [], signal: options.signal, }); + const expectedRaw = readPrivateRegularFile(this.#baselinePath(options.jobId), { + maxBytes: MAX_BASELINE_BYTES, + }); + if (expectedRaw === null) throw new Error("Jetson protected-baseline record is missing"); + const expected = parsePreservedBaselineJson(expectedRaw); + const verification = await this.#runProcess({ + executable: "ssh", + args: [...this.#sshArgs(), this.#config.destination, "bash", "-s", "--", options.jobId], + input: CLEANUP_VERIFICATION_SCRIPT, + signal: options.signal, + }); + const actual = parsePreservedBaseline(verification.stdout); + if (JSON.stringify(actual) !== JSON.stringify(expected)) { + throw new Error("Jetson cleanup changed the protected tool or Ollama model baseline"); + } + fs.unlinkSync(this.#baselinePath(options.jobId)); + } + + #baselinePath(jobId: string): string { + if (!/^[a-f0-9]{64}$/u.test(jobId)) throw new Error("Jetson job ID is invalid"); + return path.join(this.#config.stateDirectory, `${jobId}.baseline.json`); } #sshArgs(): string[] { diff --git a/tools/e2e/workflow-boundary.mts b/tools/e2e/workflow-boundary.mts index 885566669d1..0e7f44b70f3 100644 --- a/tools/e2e/workflow-boundary.mts +++ b/tools/e2e/workflow-boundary.mts @@ -3970,12 +3970,12 @@ function validateAllowJetsonDispatchInput(errors: string[], dispatchInputs: Work if ( !description.includes("Colossus dispatcher") || !description.includes("Cloudflare Tunnel") || - !description.includes("reset helper") || + !description.includes("cleanup helper") || !description.includes("JETSON_DISPATCH_URL") || !description.includes("test/e2e/docs/jetson-colossus-dispatch.md") ) { errors.push( - "workflow_dispatch allow_jetson_dispatch input must require the Colossus dispatcher, tunnel, reset helper, repository URL variable, and deployment checks", + "workflow_dispatch allow_jetson_dispatch input must require the Colossus dispatcher, tunnel, cleanup helper, repository URL variable, and deployment checks", ); } } From 03b9200cd613dce1ff7bb364f0068c4c06cd470f Mon Sep 17 00:00:00 2001 From: San Dang Date: Mon, 10 Aug 2026 21:19:50 +0700 Subject: [PATCH 11/34] fix(e2e): preserve Jetson cleanup recovery Signed-off-by: San Dang --- test/e2e/docs/jetson-colossus-dispatch.md | 110 ++++++++++++++++-- .../support/jetson-dispatch-contract.test.ts | 43 ++++++- .../support/jetson-dispatch-worker.test.ts | 79 +++++++++++-- tools/e2e/jetson-dispatch-lifecycle.mts | 6 + tools/e2e/jetson-dispatch-worker.mts | 31 +++-- 5 files changed, 241 insertions(+), 28 deletions(-) diff --git a/test/e2e/docs/jetson-colossus-dispatch.md b/test/e2e/docs/jetson-colossus-dispatch.md index 2850aaadbd1..d940f7d7a16 100644 --- a/test/e2e/docs/jetson-colossus-dispatch.md +++ b/test/e2e/docs/jetson-colossus-dispatch.md @@ -52,15 +52,25 @@ uname -m tr -d '\0' /dev/null; then echo 'unexpected passwordless sudo'; exit 1; fi ``` -The architecture must be `aarch64`, and Node.js must have major version 22. +The architecture must be `aarch64`. +Node.js must be version 22.19.0 or later, and npm must have major version 10 or later. +The OpenShell version command and `ollama list` must both succeed. Docker must expose the NVIDIA runtime required by the existing Jetson live E2E test. Preinstall Ollama so candidate code does not invoke its host installer. The `nvidia` account must not have passwordless `sudo` access. @@ -92,7 +102,10 @@ Before candidate execution, the worker records this protected tool and model bas The dispatcher stores the recorded values in a private `.baseline.json` state file. After cleanup, the worker repeats the probes and compares them with that record. Before and after candidate execution, the worker also requires `/dev/nvmap` and the Docker NVIDIA runtime to be available. -The worker removes the record only after every comparison and cleanup absence check succeeds. +The worker keeps the record through cleanup and device-lock release so startup recovery can repeat the same comparison. +The host retention policy may remove it only after no device lock exists. +Before a replay of the same job ID, the worker removes the earlier record and writes a new record before it invokes candidate code. +If the initial baseline probe fails, the worker never invokes candidate code; cleanup verifies current prerequisites and allowlisted-resource absence without a before-and-after comparison. These other host resources also remain outside the cleanup allowlist: @@ -279,6 +292,7 @@ EnvironmentFile=/etc/nemoclaw-jetson-dispatch/environment ExecStart=/usr/bin/node --experimental-strip-types --no-warnings tools/e2e/jetson-dispatch-service.mts Restart=on-failure RestartSec=5 +TimeoutStopSec=360 NoNewPrivileges=true PrivateTmp=true ProtectHome=true @@ -436,6 +450,7 @@ The uploaded `e2e-jetson-nvmap-gpu` artifact must contain `jetson-dispatch.json` It must also contain `jetson-e2e-artifacts.tar.gz`. The dispatcher creates that archive from the remote E2E artifact directory before it removes the candidate workspace. It rejects an artifact directory or compressed archive larger than 1 MiB. +Before a restarted dispatcher replays the same deterministic job ID, it removes the earlier log and archive so evidence cannot cross executions. After the workflow completes, independently verify every allowlisted resource is absent. Then run one controlled failing candidate and confirm that its artifact records the same cleanup evidence. @@ -456,10 +471,24 @@ If cleanup fails, startup fails or the completed job reports `conclusion: "clean If cleanup succeeds but lock removal fails, the completed job reports `conclusion: "cleanup-failed"` with `cleanup: "succeeded"`. The lock remains in either case. +The unit uses `Restart=on-failure`, so a startup cleanup failure otherwise retries every five seconds. +Stop that retry loop before investigation or repair: + +```bash +sudo systemctl stop nemoclaw-jetson-dispatch.service +``` + Do not delete `device.lock` to bypass recovery. -For `cleanup: "failed"`, repair the cleanup program or the allowlisted resource state. +For `cleanup: "failed"`, inspect the recorded error before choosing a recovery action. +Repair the cleanup program or allowlisted resource state only when that named operation failed. +If the protected tool or Ollama model baseline differs after cleanup, investigate candidate activity and external host drift without assigning the change to cleanup. For `cleanup: "succeeded"` with a lock-removal error, repair the state-directory filesystem or permissions. -Restart the dispatcher after the repair. +Start the dispatcher after the named condition is fixed: + +```bash +sudo systemctl start nemoclaw-jetson-dispatch.service +``` + Startup runs cleanup and absence verification again before it removes the stale lock. Do not dispatch another job when cleanup verification is inconclusive. @@ -467,15 +496,78 @@ Manual recovery must stay within the same cleanup allowlist. Escalate any suspected protected baseline change for separate host investigation. Cleanup evidence alone is not evidence that every candidate host change was reversed. -Preserve the job JSON and log files for diagnosis. -These private state files can contain candidate output, and the dispatcher does not prune them. +Preserve the job JSON, log, artifact, and protected-baseline files for diagnosis and stale-lock recovery. +These private state files can contain candidate output, and the dispatcher does not otherwise prune them. Apply the host's approved retention policy after GitHub uploads the artifact and no device lock exists. -To disable the temporary path, leave `allow_jetson_dispatch=false` on later dispatches and run: +To disable the temporary path, first prevent another controller from reaching the dispatcher. +Delete the repository variable and stop the public tunnel, but keep the dispatcher and its SSH credentials available while any accepted job finishes its bounded execution and cleanup: ```bash gh variable delete JETSON_DISPATCH_URL --repo NVIDIA/NemoClaw sudo systemctl disable --now nemoclaw-jetson-tunnel.service +``` + +Use the last accepted job ID from the controller log. +Wait for the device lock to disappear, require that job's private status to report successful cleanup, and independently check the remaining allowlisted resources: + +```bash +LAST_JOB_ID=0000000000000000000000000000000000000000000000000000000000000000 +[[ "$LAST_JOB_ID" =~ ^[a-f0-9]{64}$ ]] +state=/var/lib/nemoclaw-jetson-dispatch/state +timeout 3600 bash -c 'while [ -e "$1" ]; do sleep 5; done' wait-lock \ + "$state/device.lock" +test ! -e "$state/device.lock" +/usr/bin/node -e ' + const fs = require("node:fs"); + const status = JSON.parse(fs.readFileSync(process.argv[1], "utf8")); + if (status.state !== "completed" || status.cleanup !== "succeeded") process.exit(1); +' "$state/$LAST_JOB_ID.json" +sudo -u nemoclaw-jetson-dispatch ssh -F /dev/null -T \ + -o BatchMode=yes -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes \ + -o UserKnownHostsFile=/var/lib/nemoclaw-jetson-dispatch/known_hosts \ + -i /var/lib/nemoclaw-jetson-dispatch/id_ed25519 \ + nvidia@192.168.55.1 bash -s -- "$LAST_JOB_ID" <<'VERIFY_JETSON_IDLE' +set -euo pipefail +job_id="$1" +[[ "$job_id" =~ ^[a-f0-9]{64}$ ]] +job_home="/var/tmp/nemoclaw-jetson-e2e/$job_id/home" +test ! -e "/var/tmp/nemoclaw-jetson-e2e/$job_id" +test ! -e /tmp/nemoclaw-services-e2e-jetson-nvmap +if [ -e /var/tmp/nemoclaw-jetson-e2e ]; then + test -d /var/tmp/nemoclaw-jetson-e2e + test ! -L /var/tmp/nemoclaw-jetson-e2e + test -z "$(find /var/tmp/nemoclaw-jetson-e2e -mindepth 1 -maxdepth 1 -print -quit)" +fi +test -z "$(docker ps -aq --filter label=openshell.ai/managed-by=openshell \ + --filter label=openshell.ai/sandbox-name=e2e-jetson-nvmap)" +! docker container inspect openshell-cluster-nemoclaw >/dev/null 2>&1 +! docker volume inspect openshell-cluster-nemoclaw >/dev/null 2>&1 +for proc_dir in /proc/[0-9]*; do + [ -r "$proc_dir/environ" ] || continue + tr '\000' '\n' <"$proc_dir/environ" | grep -Fqx "HOME=$job_home" || continue + cmdline="$(tr '\000' ' ' <"$proc_dir/cmdline")" + case "$cmdline" in + *ollama-auth-proxy.*|*openshell-gateway*|*cloudflared*) + echo "A job-owned helper process remains: ${proc_dir##*/}" >&2 + exit 1 + ;; + esac +done +command -v node npm ollama openshell +ollama list >/dev/null +test -c /dev/nvmap +case "$(docker info --format '{{json .Runtimes}}')" in + *nvidia*) ;; + *) exit 1 ;; +esac +VERIFY_JETSON_IDLE +``` + +If any check fails, keep the dispatcher and SSH credentials, then use the recovery procedure above. +Only after every check passes should you stop the dispatcher: + +```bash sudo systemctl disable --now nemoclaw-jetson-dispatch.service ``` @@ -511,4 +603,4 @@ test -z "$(gh variable list --repo NVIDIA/NemoClaw --json name \ Remove the dedicated Jetson public key and the Colossus SSH private key. After the required retention period, remove the private job state and logs. -Remove the dispatcher environment, service unit, and trusted checkout when no investigation or rollback requirement remains. +Remove the dispatcher environment, service unit, and trusted checkout when no investigation, recovery, or retention requirement remains. diff --git a/test/e2e/support/jetson-dispatch-contract.test.ts b/test/e2e/support/jetson-dispatch-contract.test.ts index 8239319cfd1..0e6fc998bf4 100644 --- a/test/e2e/support/jetson-dispatch-contract.test.ts +++ b/test/e2e/support/jetson-dispatch-contract.test.ts @@ -413,11 +413,18 @@ describe("Jetson single-device lifecycle", () => { }); it("keeps cleanup evidence accurate when lock removal fails (#8142)", async () => { + const stateDirectory = temporaryDirectory(); const cleanup = vi.fn(async () => {}); - vi.spyOn(fs, "unlinkSync").mockImplementationOnce(() => { - throw new Error("lock filesystem unavailable"); + const unlinkSync = fs.unlinkSync.bind(fs); + let rejectLockRemoval = true; + vi.spyOn(fs, "unlinkSync").mockImplementation((file) => { + if (rejectLockRemoval) { + rejectLockRemoval = false; + throw new Error("lock filesystem unavailable"); + } + return unlinkSync(file); }); - const dispatch = coordinator(temporaryDirectory(), worker({ cleanup })); + const dispatch = coordinator(stateDirectory, worker({ cleanup })); await dispatch.initialize(); const accepted = dispatch.dispatch(REQUEST, identity()); const completed = await waitForCompletion(dispatch, accepted.jobId); @@ -427,6 +434,36 @@ describe("Jetson single-device lifecycle", () => { error: "Jetson lock removal failed: lock filesystem unavailable", cleanup: "succeeded", }); + expect(fs.existsSync(path.join(stateDirectory, "device.lock"))).toBe(true); + + const restarted = coordinator(stateDirectory, worker({ cleanup })); + await restarted.initialize(); + + expect(cleanup).toHaveBeenCalledTimes(2); + expect(fs.existsSync(path.join(stateDirectory, "device.lock"))).toBe(false); + }); + + it("does not return an archive from an earlier replay after restart (#8142)", async () => { + const stateDirectory = temporaryDirectory(); + const first = coordinator(stateDirectory, worker()); + await first.initialize(); + const firstAccepted = first.dispatch(REQUEST, identity()); + await waitForCompletion(first, firstAccepted.jobId); + expect(first.artifact(firstAccepted.jobId).artifactArchiveBase64).toBe(ARTIFACT_ARCHIVE_BASE64); + + const replay = coordinator( + stateDirectory, + worker({ run: async () => Promise.reject(new Error("replayed candidate failed")) }), + ); + await replay.initialize(); + const replayAccepted = replay.dispatch(REQUEST, identity()); + const replayCompleted = await waitForCompletion(replay, replayAccepted.jobId); + const replayArtifact = replay.artifact(replayAccepted.jobId); + + expect(replayAccepted.jobId).toBe(firstAccepted.jobId); + expect(replayCompleted).toMatchObject({ conclusion: "failure", cleanup: "succeeded" }); + expect(replayArtifact.log).toBe(""); + expect(replayArtifact).not.toHaveProperty("artifactArchiveBase64"); }); it("bounds retained in-memory job status while preserving private evidence (#8142)", async () => { diff --git a/test/e2e/support/jetson-dispatch-worker.test.ts b/test/e2e/support/jetson-dispatch-worker.test.ts index 8e0d58f1904..ec69d02a4fb 100644 --- a/test/e2e/support/jetson-dispatch-worker.test.ts +++ b/test/e2e/support/jetson-dispatch-worker.test.ts @@ -101,6 +101,11 @@ describe("Colossus SSH worker deployment boundary", () => { it("collects a bounded artifact archive before the remote workspace is removed (#8142)", async () => { const files = deploymentFiles(); + const jobId = "b".repeat(64); + const baselinePath = path.join(files.stateDirectory, `${jobId}.baseline.json`); + fs.writeFileSync(baselinePath, `${JSON.stringify({ ...BASELINE, nodeVersion: "v22.0.0" })}\n`, { + mode: 0o600, + }); const artifactArchiveBase64 = Buffer.from("remote archive").toString("base64"); const processRunner = vi .fn() @@ -123,12 +128,21 @@ describe("Colossus SSH worker deployment boundary", () => { workflowRunId: "123", workflowRunAttempt: 1, }, - { jobId: "b".repeat(64), signal: new AbortController().signal }, + { jobId, signal: new AbortController().signal }, ), ).resolves.toMatchObject({ artifactArchiveBase64, log: expect.stringContaining("test passed"), }); + expect(processRunner.mock.calls[0]![0].input).toContain( + "major < 22 || (major === 22 && minor < 19)", + ); + expect(processRunner.mock.calls[0]![0].input).toContain("npm_major >= 10"); + expect(processRunner.mock.calls[2]![0].input).toContain( + "major < 22 || (major === 22 && minor < 19)", + ); + expect(processRunner.mock.calls[2]![0].input).toContain("npm_major >= 10"); + expect(JSON.parse(fs.readFileSync(baselinePath, "utf8"))).toEqual(BASELINE); expect(processRunner.mock.calls[2]![0].input).not.toContain("trap cleanup EXIT"); expect(processRunner.mock.calls[3]![0].input).not.toContain("trap cleanup EXIT"); expect(processRunner.mock.calls[3]![0].input).toContain("base64 --wrap=0"); @@ -250,11 +264,8 @@ describe("Colossus SSH worker deployment boundary", () => { it("invokes the fixed cleanup executable without request-controlled arguments (#8142)", async () => { const files = deploymentFiles(); const jobId = "b".repeat(64); - fs.writeFileSync( - path.join(files.stateDirectory, `${jobId}.baseline.json`), - `${JSON.stringify(BASELINE)}\n`, - { mode: 0o600 }, - ); + const baselinePath = path.join(files.stateDirectory, `${jobId}.baseline.json`); + fs.writeFileSync(baselinePath, `${JSON.stringify(BASELINE)}\n`, { mode: 0o600 }); const processRunner = vi .fn() .mockResolvedValueOnce({ stdout: "", stderr: "" }) @@ -280,6 +291,24 @@ describe("Colossus SSH worker deployment boundary", () => { expect(processRunner.mock.calls[1]![0].args).toEqual( expect.arrayContaining(["nvidia@192.168.55.1", "--", jobId]), ); + expect(fs.existsSync(baselinePath)).toBe(true); + }); + + it("verifies cleanup after a pre-candidate failure without a baseline record (#8142)", async () => { + const files = deploymentFiles(); + const jobId = "b".repeat(64); + const processRunner = vi + .fn() + .mockResolvedValueOnce({ stdout: "", stderr: "" }) + .mockResolvedValueOnce({ stdout: BASELINE_OUTPUT, stderr: "" }); + const worker = new SshJetsonDispatchWorker(loadConfig(files), processRunner); + + await expect( + worker.cleanup({ jobId, signal: new AbortController().signal }), + ).resolves.toBeUndefined(); + + expect(processRunner).toHaveBeenCalledTimes(2); + expect(fs.existsSync(path.join(files.stateDirectory, `${jobId}.baseline.json`))).toBe(false); }); it.each([ @@ -300,7 +329,7 @@ describe("Colossus SSH worker deployment boundary", () => { const worker = new SshJetsonDispatchWorker(loadConfig(files), processRunner); await expect(worker.cleanup({ jobId, signal: new AbortController().signal })).rejects.toThrow( - "Jetson cleanup changed the protected tool or Ollama model baseline", + "Jetson protected tool or Ollama model baseline differs after cleanup", ); expect(fs.existsSync(baselinePath)).toBe(true); }); @@ -324,4 +353,40 @@ describe("Colossus SSH worker deployment boundary", () => { expect(cleanupProgram).not.toMatch(/apt(?:-get)?|boardctl|reboot|shutdown|nvidia-l4t/u); expect(cleanupProgram).not.toMatch(/npm uninstall|uninstall\.sh|rm .*openshell|rm .*ollama/u); }); + + it("requires every protected Jetson prerequisite before dispatch (#8142)", () => { + expect(dispatcherRunbook).toContain( + "command -v bash curl docker git node npm ollama openshell timeout", + ); + expect(dispatcherRunbook).toContain( + "if (major < 22 || (major === 22 && minor < 19)) process.exit(1)", + ); + expect(dispatcherRunbook).toContain('test "${npm_version%%.*}" -ge 10'); + expect(dispatcherRunbook).toContain("ollama list"); + }); + + it("keeps recovery credentials until idle teardown verification succeeds (#8142)", () => { + const stopTunnel = dispatcherRunbook.indexOf( + "sudo systemctl disable --now nemoclaw-jetson-tunnel.service", + ); + const waitForLock = dispatcherRunbook.indexOf( + "timeout 3600 bash -c 'while [ -e \"$1\" ]; do sleep 5; done'", + ); + const verifyCleanup = dispatcherRunbook.indexOf( + 'if (status.state !== "completed" || status.cleanup !== "succeeded") process.exit(1)', + ); + const stopDispatcher = dispatcherRunbook.indexOf( + "sudo systemctl disable --now nemoclaw-jetson-dispatch.service", + ); + const removeSshKey = dispatcherRunbook.indexOf( + "Remove the dedicated Jetson public key and the Colossus SSH private key.", + ); + + expect(dispatcherRunbook).toContain("TimeoutStopSec=360"); + expect(stopTunnel).toBeGreaterThan(-1); + expect(waitForLock).toBeGreaterThan(stopTunnel); + expect(verifyCleanup).toBeGreaterThan(waitForLock); + expect(stopDispatcher).toBeGreaterThan(verifyCleanup); + expect(removeSshKey).toBeGreaterThan(stopDispatcher); + }); }); diff --git a/tools/e2e/jetson-dispatch-lifecycle.mts b/tools/e2e/jetson-dispatch-lifecycle.mts index 1c115c6d504..4d33f2460aa 100644 --- a/tools/e2e/jetson-dispatch-lifecycle.mts +++ b/tools/e2e/jetson-dispatch-lifecycle.mts @@ -245,6 +245,7 @@ export class JetsonDispatchCoordinator { cleanup: "pending", }; try { + this.#clearPriorResultFiles(jobId); this.#persist(status); } catch (error) { fs.unlinkSync(this.#lockPath); @@ -411,6 +412,11 @@ export class JetsonDispatchCoordinator { return path.join(this.#stateDirectory, `${jobId}.artifacts.tar.gz.b64`); } + #clearPriorResultFiles(jobId: string): void { + fs.rmSync(this.#logPath(jobId), { force: true }); + fs.rmSync(this.#artifactPath(jobId), { force: true }); + } + #evictOldestCompletedJob(): void { if (this.#jobs.size < MAX_RETAINED_JOB_STATUSES) return; for (const [jobId, status] of this.#jobs) { diff --git a/tools/e2e/jetson-dispatch-worker.mts b/tools/e2e/jetson-dispatch-worker.mts index 635664de7c7..31610b351c6 100644 --- a/tools/e2e/jetson-dispatch-worker.mts +++ b/tools/e2e/jetson-dispatch-worker.mts @@ -48,6 +48,14 @@ node_path="$(command -v node)" npm_path="$(command -v npm)" ollama_path="$(command -v ollama)" openshell_path="$(command -v openshell)" +node_version="$(node --version)" +node -e ' + const [major, minor] = process.versions.node.split(".").map(Number); + if (major < 22 || (major === 22 && minor < 19)) process.exit(1); +' +npm_version="$(npm --version)" +npm_major="${"${npm_version%%.*}"}" +[[ "$npm_major" =~ ^[0-9]+$ ]] && (( npm_major >= 10 )) test -c /dev/nvmap docker_runtimes="$(docker info --format '{{json .Runtimes}}')" case "$docker_runtimes" in @@ -56,9 +64,9 @@ case "$docker_runtimes" in esac ollama_models_sha256="$(ollama list | awk 'NR > 1 && NF >= 2 { print $1 "\t" $2 }' | sort | sha256sum | cut -d ' ' -f 1)" printf 'nodePath\t'; printf '%s' "$node_path" | clean_line -printf '\nnodeVersion\t'; node --version | clean_line +printf '\nnodeVersion\t'; printf '%s' "$node_version" | clean_line printf '\nnpmPath\t'; printf '%s' "$npm_path" | clean_line -printf '\nnpmVersion\t'; npm --version | clean_line +printf '\nnpmVersion\t'; printf '%s' "$npm_version" | clean_line printf '\nollamaPath\t'; printf '%s' "$ollama_path" | clean_line printf '\nollamaModelsSha256\t'; printf '%s' "$ollama_models_sha256" | clean_line printf '\nopenshellPath\t'; printf '%s' "$openshell_path" | clean_line @@ -127,9 +135,13 @@ fetched_sha="$(git -C "$workspace/repository" rev-parse FETCH_HEAD)" git -C "$workspace/repository" checkout --quiet --detach "$candidate_sha" cd "$workspace/repository" -node_major="$(node -p 'process.versions.node.split(".")[0]')" -[[ "$node_major" == "22" ]] || { - echo "Jetson E2E requires Node.js 22" >&2 +node -e ' + const [major, minor] = process.versions.node.split(".").map(Number); + if (major < 22 || (major === 22 && minor < 19)) process.exit(1); +' || { echo "Jetson E2E requires Node.js 22.19.0 or later" >&2; exit 1; } +npm_major="$(npm --version | cut -d . -f 1)" +[[ "$npm_major" =~ ^[0-9]+$ ]] && (( npm_major >= 10 )) || { + echo "Jetson E2E requires npm 10 or later" >&2 exit 1 } npm ci --ignore-scripts @@ -471,6 +483,7 @@ export class SshJetsonDispatchWorker implements JetsonDispatchWorker { request: JetsonDispatchRequest, options: { jobId: string; signal: AbortSignal }, ): Promise { + fs.rmSync(this.#baselinePath(options.jobId), { force: true }); const baselineResult = await this.#runProcess({ executable: "ssh", args: [...this.#sshArgs(), this.#config.destination, "bash", "-s"], @@ -597,10 +610,9 @@ export class SshJetsonDispatchWorker implements JetsonDispatchWorker { signal: options.signal, }); const expectedRaw = readPrivateRegularFile(this.#baselinePath(options.jobId), { + allowMissing: true, maxBytes: MAX_BASELINE_BYTES, }); - if (expectedRaw === null) throw new Error("Jetson protected-baseline record is missing"); - const expected = parsePreservedBaselineJson(expectedRaw); const verification = await this.#runProcess({ executable: "ssh", args: [...this.#sshArgs(), this.#config.destination, "bash", "-s", "--", options.jobId], @@ -608,10 +620,11 @@ export class SshJetsonDispatchWorker implements JetsonDispatchWorker { signal: options.signal, }); const actual = parsePreservedBaseline(verification.stdout); + if (expectedRaw === null) return; + const expected = parsePreservedBaselineJson(expectedRaw); if (JSON.stringify(actual) !== JSON.stringify(expected)) { - throw new Error("Jetson cleanup changed the protected tool or Ollama model baseline"); + throw new Error("Jetson protected tool or Ollama model baseline differs after cleanup"); } - fs.unlinkSync(this.#baselinePath(options.jobId)); } #baselinePath(jobId: string): string { From 7ea3c9accf799b7b0c1f93f7b3c27e056b62cf5f Mon Sep 17 00:00:00 2001 From: San Dang Date: Mon, 10 Aug 2026 21:42:22 +0700 Subject: [PATCH 12/34] fix(e2e): retain Jetson cleanup identities Signed-off-by: San Dang --- .../skills/nemoclaw-maintainer-e2e/SKILL.md | 9 +- test/e2e/docs/jetson-colossus-dispatch.md | 122 ++++++++++++- .../support/jetson-dispatch-worker.test.ts | 110 +++++++++++- tools/e2e/jetson-dispatch-cleanup.sh | 11 ++ tools/e2e/jetson-dispatch-worker.mts | 161 +++++++++++++++++- 5 files changed, 398 insertions(+), 15 deletions(-) diff --git a/.agents/skills/nemoclaw-maintainer-e2e/SKILL.md b/.agents/skills/nemoclaw-maintainer-e2e/SKILL.md index 0a3427ecd48..8f5adc3dbe7 100644 --- a/.agents/skills/nemoclaw-maintainer-e2e/SKILL.md +++ b/.agents/skills/nemoclaw-maintainer-e2e/SKILL.md @@ -353,7 +353,9 @@ node --experimental-strip-types --no-warnings \ The validator requires: - the workflow run to succeed for the selected SHA; -- `dispatch.json` to bind the same run, empty selectors, `include_staging_brev_launchable=true`, `allowJetsonDispatch: false`, `allowJetsonRunnerQueue: false`, `allowDgxSparkRunnerQueue: false`, and the selected successful Launchable job attempt; +- `dispatch.json` to bind the same run, empty selectors, `include_staging_brev_launchable=true`, `allowJetsonRunnerQueue: false`, `allowDgxSparkRunnerQueue: false`, and the selected successful Launchable job attempt; +- `allowJetsonDispatch: false` in every v2 `dispatch.json` receipt; +- `allowJetsonDispatch` to be absent or `false` in every v1 `dispatch.json` receipt; - `Exact staging Brev Launchable` to conclude `success` in the selected current or earlier attempt of the same workflow run; - `launchable-e2e.json` to identify the selected SHA in the repository and provision records; - the booted repository to be unmodified; @@ -380,7 +382,10 @@ If the release candidate SHA changes, discard the earlier full run and dispatch No release-note-only delta exception is currently defined. When `nemoclaw-maintainer-cut-release-tag` invokes this skill, return the validated fields for its pre-tag E2E evidence ledger. -The trusted `dispatch.json` receipt proves that full mode used empty selectors, included `Exact staging Brev Launchable`, and disabled the optional Jetson dispatch and DGX Spark runner paths. +The trusted `dispatch.json` receipt proves that full mode used empty selectors and included `Exact staging Brev Launchable`. +For Jetson dispatch, a v2 receipt requires `allowJetsonDispatch: false`. +A v1 receipt may omit `allowJetsonDispatch`, but it must be `false` when present. +Both receipt versions require the optional DGX Spark runner path to be disabled. The release evidence ledger proves the result of each workflow E2E. Do not ask for the release confirmation phrase in this skill. diff --git a/test/e2e/docs/jetson-colossus-dispatch.md b/test/e2e/docs/jetson-colossus-dispatch.md index d940f7d7a16..9a16ec85f76 100644 --- a/test/e2e/docs/jetson-colossus-dispatch.md +++ b/test/e2e/docs/jetson-colossus-dispatch.md @@ -221,11 +221,34 @@ It must exit nonzero when target ownership is ambiguous, cleanup fails, or absen It must not remove `/var/lib/nemoclaw-jetson-dispatch/state/device.lock`. The dispatcher removes that lock only after cleanup and absence verification succeed. +After the fixed cleanup helper exits with status zero, the worker parses its bounded evidence block. +The worker writes the validated identities to this private state file with mode `0600`: + +```text +/var/lib/nemoclaw-jetson-dispatch/state/.cleanup.json +``` + +The file has this exact schema: + +```json +{ + "schemaVersion": 1, + "volumes": ["example-volume"], + "processIds": [1234] +} +``` + +Either identity array can be empty. +The worker merges new identities with the existing record instead of replacing earlier identities. +This merge preserves identities when cleanup verification fails and the dispatcher retries cleanup for the same job. +The dispatcher retains the cleanup record after it removes the device lock. + After the helper exits, the worker independently verifies these conditions over pinned-host-key SSH: - The validated job workspace is absent and is not a symbolic link. - No OpenShell-managed container has the `e2e-jetson-nvmap` sandbox label. - The `openshell-cluster-nemoclaw` gateway container and volume are absent. +- Every Docker volume and process ID in the merged cleanup record is absent. - Every recorded Node.js, npm, Ollama, Ollama model, and OpenShell baseline value matches. - `/dev/nvmap` exists, and Docker still reports the NVIDIA runtime. @@ -453,6 +476,7 @@ It rejects an artifact directory or compressed archive larger than 1 MiB. Before a restarted dispatcher replays the same deterministic job ID, it removes the earlier log and archive so evidence cannot cross executions. After the workflow completes, independently verify every allowlisted resource is absent. +Require the private `.cleanup.json` file and verify every recorded volume and process ID is absent. Then run one controlled failing candidate and confirm that its artifact records the same cleanup evidence. For a cancellation proof, cancel a controller after it logs the job ID. The controller can exit before it downloads an artifact. @@ -496,9 +520,10 @@ Manual recovery must stay within the same cleanup allowlist. Escalate any suspected protected baseline change for separate host investigation. Cleanup evidence alone is not evidence that every candidate host change was reversed. -Preserve the job JSON, log, artifact, and protected-baseline files for diagnosis and stale-lock recovery. +Retain every `.cleanup.json` file until the temporary path teardown completes. +Preserve the other private job state required for diagnosis and stale-lock recovery. These private state files can contain candidate output, and the dispatcher does not otherwise prune them. -Apply the host's approved retention policy after GitHub uploads the artifact and no device lock exists. +Apply the host's approved retention policy to other private state after GitHub uploads the artifact and no device lock exists. To disable the temporary path, first prevent another controller from reaching the dispatcher. Delete the repository variable and stop the public tunnel, but keep the dispatcher and its SSH credentials available while any accepted job finishes its bounded execution and cleanup: @@ -509,20 +534,101 @@ sudo systemctl disable --now nemoclaw-jetson-tunnel.service ``` Use the last accepted job ID from the controller log. -Wait for the device lock to disappear, require that job's private status to report successful cleanup, and independently check the remaining allowlisted resources: +Wait for the device lock to disappear and require that job's private status to report successful cleanup. +Require the last job's cleanup record. +Use Node.js `readdirSync` with the exact `^[a-f0-9]{64}\.cleanup\.json$` basename pattern. +Validate and aggregate every retained cleanup record that matches this pattern. +Independently verify every aggregated resource identity and the remaining fixed allowlist: ```bash +set -euo pipefail LAST_JOB_ID=0000000000000000000000000000000000000000000000000000000000000000 [[ "$LAST_JOB_ID" =~ ^[a-f0-9]{64}$ ]] state=/var/lib/nemoclaw-jetson-dispatch/state -timeout 3600 bash -c 'while [ -e "$1" ]; do sleep 5; done' wait-lock \ +sudo -u nemoclaw-jetson-dispatch \ + timeout 3600 bash -c 'while [ -e "$1" ]; do sleep 5; done' wait-lock \ "$state/device.lock" -test ! -e "$state/device.lock" -/usr/bin/node -e ' +sudo -u nemoclaw-jetson-dispatch test ! -e "$state/device.lock" +sudo -u nemoclaw-jetson-dispatch /usr/bin/node -e ' const fs = require("node:fs"); const status = JSON.parse(fs.readFileSync(process.argv[1], "utf8")); if (status.state !== "completed" || status.cleanup !== "succeeded") process.exit(1); ' "$state/$LAST_JOB_ID.json" +cleanup_identities="$(sudo -u nemoclaw-jetson-dispatch /usr/bin/node -e ' + const fs = require("node:fs"); + const path = require("node:path"); + const stateDirectory = process.argv[1]; + const lastJobId = process.argv[2]; + const cleanupName = /^[a-f0-9]{64}\.cleanup\.json$/; + const names = fs.readdirSync(stateDirectory).filter((name) => cleanupName.test(name)).sort(); + if (!names.includes(`${lastJobId}.cleanup.json`)) process.exit(1); + const expectedKeys = ["processIds", "schemaVersion", "volumes"]; + const validVolume = (value) => + typeof value === "string" && /^[A-Za-z0-9][A-Za-z0-9_.-]{0,254}$/.test(value); + const validProcessId = (value) => Number.isSafeInteger(value) && value > 0; + const volumes = new Set(); + const processIds = new Set(); + for (const name of names) { + const file = path.join(stateDirectory, name); + const metadata = fs.lstatSync(file); + if (!metadata.isFile() || (metadata.mode & 0o777) !== 0o600) process.exit(1); + const raw = fs.readFileSync(file, "utf8"); + if (Buffer.byteLength(raw) > 64 * 1024) process.exit(1); + const record = JSON.parse(raw); + const keys = Object.keys(record).sort(); + if ( + JSON.stringify(keys) !== JSON.stringify(expectedKeys) || + record.schemaVersion !== 1 || + !Array.isArray(record.volumes) || + !record.volumes.every(validVolume) || + !Array.isArray(record.processIds) || + !record.processIds.every(validProcessId) + ) process.exit(1); + for (const volume of record.volumes) volumes.add(volume); + for (const processId of record.processIds) processIds.add(processId); + } + for (const volume of [...volumes].sort()) console.log(`volume\t${volume}`); + for (const processId of [...processIds].sort((a, b) => a - b)) { + console.log(`processId\t${processId}`); + } +' "$state" "$LAST_JOB_ID")" +cleanup_volumes=() +cleanup_process_ids=() +while IFS=$'\t' read -r identity_kind identity; do + [ -n "$identity_kind" ] || continue + case "$identity_kind" in + volume) cleanup_volumes+=("$identity") ;; + processId) cleanup_process_ids+=("$identity") ;; + *) exit 1 ;; + esac +done <<<"$cleanup_identities" +for volume in "${cleanup_volumes[@]}"; do + sudo -u nemoclaw-jetson-dispatch ssh -F /dev/null -T \ + -o BatchMode=yes -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes \ + -o UserKnownHostsFile=/var/lib/nemoclaw-jetson-dispatch/known_hosts \ + -i /var/lib/nemoclaw-jetson-dispatch/id_ed25519 \ + nvidia@192.168.55.1 bash -s -- "$volume" <<'VERIFY_RECORDED_VOLUME' +set -euo pipefail +docker info >/dev/null +if docker volume inspect "$1" >/dev/null 2>&1; then + echo "A recorded job-owned Docker volume remains: $1" >&2 + exit 1 +fi +VERIFY_RECORDED_VOLUME +done +for process_id in "${cleanup_process_ids[@]}"; do + sudo -u nemoclaw-jetson-dispatch ssh -F /dev/null -T \ + -o BatchMode=yes -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes \ + -o UserKnownHostsFile=/var/lib/nemoclaw-jetson-dispatch/known_hosts \ + -i /var/lib/nemoclaw-jetson-dispatch/id_ed25519 \ + nvidia@192.168.55.1 bash -s -- "$process_id" <<'VERIFY_RECORDED_PROCESS' +set -euo pipefail +if [ -e "/proc/$1" ]; then + echo "A recorded job-owned process ID remains: $1" >&2 + exit 1 +fi +VERIFY_RECORDED_PROCESS +done sudo -u nemoclaw-jetson-dispatch ssh -F /dev/null -T \ -o BatchMode=yes -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes \ -o UserKnownHostsFile=/var/lib/nemoclaw-jetson-dispatch/known_hosts \ @@ -564,7 +670,9 @@ esac VERIFY_JETSON_IDLE ``` -If any check fails, keep the dispatcher and SSH credentials, then use the recovery procedure above. +If the last cleanup record is missing, keep the dispatcher and SSH credentials. +Keep them when any retained cleanup record is malformed or an absence check fails. +Use the recovery procedure above before teardown. Only after every check passes should you stop the dispatcher: ```bash diff --git a/test/e2e/support/jetson-dispatch-worker.test.ts b/test/e2e/support/jetson-dispatch-worker.test.ts index ec69d02a4fb..db2e488e94c 100644 --- a/test/e2e/support/jetson-dispatch-worker.test.ts +++ b/test/e2e/support/jetson-dispatch-worker.test.ts @@ -41,6 +41,22 @@ function baselineOutput(overrides: Partial = {}): string { const BASELINE_OUTPUT = baselineOutput(); +function cleanupOutput({ + volumes = [], + processIds = [], +}: { + volumes?: string[]; + processIds?: number[]; +} = {}): string { + return [ + "nemoclaw-cleanup-evidence-v1-begin", + ...volumes.map((volume) => `volume\t${volume}`), + ...processIds.map((pid) => `processId\t${pid}`), + "nemoclaw-cleanup-evidence-v1-end", + "", + ].join("\n"); +} + afterEach(() => { for (const directory of temporaryDirectories.splice(0)) { fs.rmSync(directory, { force: true, recursive: true }); @@ -268,7 +284,10 @@ describe("Colossus SSH worker deployment boundary", () => { fs.writeFileSync(baselinePath, `${JSON.stringify(BASELINE)}\n`, { mode: 0o600 }); const processRunner = vi .fn() - .mockResolvedValueOnce({ stdout: "", stderr: "" }) + .mockResolvedValueOnce({ + stdout: cleanupOutput({ volumes: ["sandbox-volume"], processIds: [1234] }), + stderr: "", + }) .mockResolvedValueOnce({ stdout: BASELINE_OUTPUT, stderr: "" }); const worker = new SshJetsonDispatchWorker(loadConfig(files), processRunner); @@ -288,10 +307,28 @@ describe("Colossus SSH worker deployment boundary", () => { expect(processRunner.mock.calls[1]![0].input).toContain("docker info --format"); expect(processRunner.mock.calls[1]![0].input).toContain("test -c /dev/nvmap"); expect(processRunner.mock.calls[1]![0].input).toContain("ollama list"); + expect(processRunner.mock.calls[1]![0].input).toContain( + 'for volume in "${recorded_volumes[@]}"', + ); + expect(processRunner.mock.calls[1]![0].input).toContain( + 'for pid in "${recorded_process_ids[@]}"', + ); expect(processRunner.mock.calls[1]![0].args).toEqual( expect.arrayContaining(["nvidia@192.168.55.1", "--", jobId]), ); + const encodedEvidence = processRunner.mock.calls[1]![0].args.at(-1); + expect(JSON.parse(Buffer.from(encodedEvidence!, "base64").toString("utf8"))).toEqual({ + schemaVersion: 1, + volumes: ["sandbox-volume"], + processIds: [1234], + }); expect(fs.existsSync(baselinePath)).toBe(true); + expect( + JSON.parse(fs.readFileSync(path.join(files.stateDirectory, `${jobId}.cleanup.json`), "utf8")), + ).toEqual({ schemaVersion: 1, volumes: ["sandbox-volume"], processIds: [1234] }); + expect(fs.statSync(path.join(files.stateDirectory, `${jobId}.cleanup.json`)).mode & 0o777).toBe( + 0o600, + ); }); it("verifies cleanup after a pre-candidate failure without a baseline record (#8142)", async () => { @@ -299,7 +336,7 @@ describe("Colossus SSH worker deployment boundary", () => { const jobId = "b".repeat(64); const processRunner = vi .fn() - .mockResolvedValueOnce({ stdout: "", stderr: "" }) + .mockResolvedValueOnce({ stdout: cleanupOutput(), stderr: "" }) .mockResolvedValueOnce({ stdout: BASELINE_OUTPUT, stderr: "" }); const worker = new SshJetsonDispatchWorker(loadConfig(files), processRunner); @@ -324,7 +361,7 @@ describe("Colossus SSH worker deployment boundary", () => { fs.writeFileSync(baselinePath, `${JSON.stringify(BASELINE)}\n`, { mode: 0o600 }); const processRunner = vi .fn() - .mockResolvedValueOnce({ stdout: "", stderr: "" }) + .mockResolvedValueOnce({ stdout: cleanupOutput(), stderr: "" }) .mockResolvedValueOnce({ stdout: baselineOutput(change), stderr: "" }); const worker = new SshJetsonDispatchWorker(loadConfig(files), processRunner); @@ -334,6 +371,57 @@ describe("Colossus SSH worker deployment boundary", () => { expect(fs.existsSync(baselinePath)).toBe(true); }); + it("retains every validated cleanup identity across stale-lock recovery (#8142)", async () => { + const files = deploymentFiles(); + const jobId = "b".repeat(64); + fs.writeFileSync( + path.join(files.stateDirectory, `${jobId}.baseline.json`), + `${JSON.stringify(BASELINE)}\n`, + { mode: 0o600 }, + ); + const processRunner = vi + .fn() + .mockResolvedValueOnce({ + stdout: cleanupOutput({ volumes: ["sandbox-volume"], processIds: [1234] }), + stderr: "", + }) + .mockResolvedValueOnce({ stdout: BASELINE_OUTPUT, stderr: "" }) + .mockResolvedValueOnce({ + stdout: cleanupOutput({ volumes: ["gateway-volume"], processIds: [5678] }), + stderr: "", + }) + .mockResolvedValueOnce({ stdout: BASELINE_OUTPUT, stderr: "" }); + const worker = new SshJetsonDispatchWorker(loadConfig(files), processRunner); + + await worker.cleanup({ jobId, signal: new AbortController().signal }); + await worker.cleanup({ jobId, signal: new AbortController().signal }); + + expect( + JSON.parse(fs.readFileSync(path.join(files.stateDirectory, `${jobId}.cleanup.json`), "utf8")), + ).toEqual({ + schemaVersion: 1, + volumes: ["gateway-volume", "sandbox-volume"], + processIds: [1234, 5678], + }); + }); + + it.each([ + "", + "nemoclaw-cleanup-evidence-v1-begin\nvolume\t../unsafe\nnemoclaw-cleanup-evidence-v1-end\n", + "nemoclaw-cleanup-evidence-v1-begin\nprocessId\t0\nnemoclaw-cleanup-evidence-v1-end\n", + ])("rejects missing or unsafe cleanup identity evidence (#8142)", async (stdout) => { + const files = deploymentFiles(); + const jobId = "b".repeat(64); + const processRunner = vi.fn().mockResolvedValueOnce({ stdout, stderr: "" }); + const worker = new SshJetsonDispatchWorker(loadConfig(files), processRunner); + + await expect(worker.cleanup({ jobId, signal: new AbortController().signal })).rejects.toThrow( + /Jetson cleanup/u, + ); + expect(processRunner).toHaveBeenCalledTimes(1); + expect(fs.existsSync(path.join(files.stateDirectory, `${jobId}.cleanup.json`))).toBe(false); + }); + it("keeps cleanup targets fixed and preserves the Jetson baseline (#8142)", () => { expect(cleanupProgram).toContain("sandbox_name=e2e-jetson-nvmap"); expect(cleanupProgram).toContain("gateway_name=nemoclaw"); @@ -347,6 +435,8 @@ describe("Colossus SSH worker deployment boundary", () => { expect(cleanupProgram).toContain('grep -Fqx "HOME=$job_home"'); expect(cleanupProgram).toContain('kill "$pid"'); expect(cleanupProgram).toContain("label=openshell.ai/sandbox-name=$sandbox_name"); + expect(cleanupProgram).toContain("nemoclaw-cleanup-evidence-v1-begin"); + expect(cleanupProgram).toContain("nemoclaw-cleanup-evidence-v1-end"); expect(cleanupProgram).not.toMatch(/pkill|pgrep|docker (?:system|container|volume) prune/u); expect(cleanupProgram).not.toContain('rm -rf -- "$workspace_root"'); expect(cleanupProgram).not.toContain("ollama serve"); @@ -375,6 +465,11 @@ describe("Colossus SSH worker deployment boundary", () => { const verifyCleanup = dispatcherRunbook.indexOf( 'if (status.state !== "completed" || status.cleanup !== "succeeded") process.exit(1)', ); + const aggregateCleanupRecords = dispatcherRunbook.indexOf( + "const cleanupName = /^[a-f0-9]{64}\\.cleanup\\.json$/", + ); + const verifyRecordedVolume = dispatcherRunbook.indexOf('docker volume inspect "$1"'); + const verifyRecordedProcess = dispatcherRunbook.indexOf('if [ -e "/proc/$1" ]'); const stopDispatcher = dispatcherRunbook.indexOf( "sudo systemctl disable --now nemoclaw-jetson-dispatch.service", ); @@ -386,7 +481,14 @@ describe("Colossus SSH worker deployment boundary", () => { expect(stopTunnel).toBeGreaterThan(-1); expect(waitForLock).toBeGreaterThan(stopTunnel); expect(verifyCleanup).toBeGreaterThan(waitForLock); - expect(stopDispatcher).toBeGreaterThan(verifyCleanup); + expect(dispatcherRunbook).toContain( + 'const expectedKeys = ["processIds", "schemaVersion", "volumes"]', + ); + expect(dispatcherRunbook).toContain("record.schemaVersion !== 1"); + expect(aggregateCleanupRecords).toBeGreaterThan(verifyCleanup); + expect(verifyRecordedVolume).toBeGreaterThan(aggregateCleanupRecords); + expect(verifyRecordedProcess).toBeGreaterThan(verifyRecordedVolume); + expect(stopDispatcher).toBeGreaterThan(verifyRecordedProcess); expect(removeSshKey).toBeGreaterThan(stopDispatcher); }); }); diff --git a/tools/e2e/jetson-dispatch-cleanup.sh b/tools/e2e/jetson-dispatch-cleanup.sh index 8c476090d56..0deb6c7f959 100755 --- a/tools/e2e/jetson-dispatch-cleanup.sh +++ b/tools/e2e/jetson-dispatch-cleanup.sh @@ -275,4 +275,15 @@ for pid in "$auth_proxy_pid" "$gateway_pid" "$cloudflared_pid"; do exit 1 fi done + +printf '%s\n' nemoclaw-cleanup-evidence-v1-begin +for volume in "${recorded_volumes[@]}"; do + printf 'volume\t%s\n' "$volume" +done +for pid in "$auth_proxy_pid" "$gateway_pid" "$cloudflared_pid"; do + if [ -n "$pid" ]; then + printf 'processId\t%s\n' "$pid" + fi +done +printf '%s\n' nemoclaw-cleanup-evidence-v1-end JETSON_CLEANUP diff --git a/tools/e2e/jetson-dispatch-worker.mts b/tools/e2e/jetson-dispatch-worker.mts index 31610b351c6..01196c7b3ea 100644 --- a/tools/e2e/jetson-dispatch-worker.mts +++ b/tools/e2e/jetson-dispatch-worker.mts @@ -22,6 +22,15 @@ const SAFE_PROCESS_ENV = { PATH: "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", }; const MAX_BASELINE_BYTES = 4 * 1024; +const MAX_CLEANUP_EVIDENCE_BYTES = 64 * 1024; +const CLEANUP_EVIDENCE_BEGIN = "nemoclaw-cleanup-evidence-v1-begin"; +const CLEANUP_EVIDENCE_END = "nemoclaw-cleanup-evidence-v1-end"; + +interface JetsonCleanupEvidence { + schemaVersion: 1; + volumes: string[]; + processIds: number[]; +} const DEVICE_IDENTITY_SCRIPT = String.raw`set -eu clean_line() { tr -d '\000\r\n\t'; } @@ -76,10 +85,37 @@ printf '\n' const CLEANUP_VERIFICATION_SCRIPT = String.raw`set -euo pipefail job_id="$1" +cleanup_evidence_base64="$2" [[ "$job_id" =~ ^[a-f0-9]{64}$ ]] workspace="/var/tmp/nemoclaw-jetson-e2e/$job_id" sandbox_name=e2e-jetson-nvmap gateway_name=nemoclaw +recorded_volumes=() +recorded_process_ids=() +cleanup_rows="$( + printf '%s' "$cleanup_evidence_base64" | base64 --decode | node -e ' + const fs = require("node:fs"); + const value = JSON.parse(fs.readFileSync(0, "utf8")); + if (value.schemaVersion !== 1 || !Array.isArray(value.volumes) || !Array.isArray(value.processIds)) process.exit(1); + for (const volume of value.volumes) { + if (typeof volume !== "string" || !/^[A-Za-z0-9][A-Za-z0-9_.-]{0,254}$/.test(volume)) process.exit(1); + process.stdout.write("volume\t" + volume + "\n"); + } + for (const pid of value.processIds) { + if (!Number.isSafeInteger(pid) || pid < 1) process.exit(1); + process.stdout.write("processId\t" + pid + "\n"); + } + ' +)" +if [ -n "$cleanup_rows" ]; then + while IFS=$'\t' read -r kind identity; do + case "$kind" in + volume) recorded_volumes+=("$identity") ;; + processId) recorded_process_ids+=("$identity") ;; + *) echo "Cleanup evidence contains an invalid identity" >&2; exit 1 ;; + esac + done <<<"$cleanup_rows" +fi test ! -e "$workspace" test ! -L "$workspace" test -z "$(docker ps -aq \ @@ -93,6 +129,18 @@ if docker volume inspect "openshell-cluster-$gateway_name" >/dev/null 2>&1; then echo "The test-owned OpenShell gateway volume remains" >&2 exit 1 fi +for volume in "${"${recorded_volumes[@]}"}"; do + if docker volume inspect "$volume" >/dev/null 2>&1; then + echo "A recorded test-owned Docker volume remains" >&2 + exit 1 + fi +done +for pid in "${"${recorded_process_ids[@]}"}"; do + if kill -0 "$pid" 2>/dev/null; then + echo "A recorded test-owned helper process remains" >&2 + exit 1 + fi +done ` + PRESERVED_BASELINE_SCRIPT; const JETSON_TEST_SCRIPT = String.raw`set -euo pipefail @@ -470,6 +518,87 @@ function parsePreservedBaselineJson(output: string): JetsonPreservedBaseline { return parsePreservedBaseline(expected.map((key) => `${key}\t${record[key]}`).join("\n")); } +function validateCleanupEvidence(value: unknown): JetsonCleanupEvidence { + if (!value || typeof value !== "object" || Array.isArray(value)) { + throw new Error("Jetson cleanup evidence is malformed"); + } + const record = value as Record; + if ( + Object.keys(record).length !== 3 || + record.schemaVersion !== 1 || + !Array.isArray(record.volumes) || + !Array.isArray(record.processIds) + ) { + throw new Error("Jetson cleanup evidence is malformed"); + } + const volumes = record.volumes; + const processIds = record.processIds; + if ( + volumes.some( + (volume) => typeof volume !== "string" || !/^[A-Za-z0-9][A-Za-z0-9_.-]{0,254}$/u.test(volume), + ) || + processIds.some((pid) => typeof pid !== "number" || !Number.isSafeInteger(pid) || pid < 1) + ) { + throw new Error("Jetson cleanup evidence contains an invalid resource identity"); + } + return { + schemaVersion: 1, + volumes: [...new Set(volumes as string[])].sort(), + processIds: [...new Set(processIds as number[])].sort((left, right) => left - right), + }; +} + +function parseCleanupEvidenceJson(output: string): JetsonCleanupEvidence { + if (Buffer.byteLength(output) > MAX_CLEANUP_EVIDENCE_BYTES) { + throw new Error("Jetson cleanup evidence is too large"); + } + try { + return validateCleanupEvidence(JSON.parse(output)); + } catch (error) { + if (error instanceof Error && error.message.startsWith("Jetson cleanup evidence")) throw error; + throw new Error("Jetson cleanup evidence is malformed"); + } +} + +function parseCleanupCommandEvidence(output: string): JetsonCleanupEvidence { + if (Buffer.byteLength(output) > MAX_PROCESS_OUTPUT_BYTES) { + throw new Error("Jetson cleanup output is too large"); + } + const lines = output.replace(/\r/gu, "").split("\n"); + while (lines.at(-1) === "") lines.pop(); + const endIndex = lines.lastIndexOf(CLEANUP_EVIDENCE_END); + const beginIndex = lines.lastIndexOf(CLEANUP_EVIDENCE_BEGIN, endIndex - 1); + if (beginIndex < 0 || endIndex !== lines.length - 1 || beginIndex >= endIndex) { + throw new Error("Jetson cleanup did not return bounded resource evidence"); + } + const volumes: string[] = []; + const processIds: number[] = []; + for (const line of lines.slice(beginIndex + 1, endIndex)) { + const fields = line.split("\t"); + if (fields.length !== 2) throw new Error("Jetson cleanup evidence is malformed"); + const [kind, identity] = fields; + if (kind === "volume") { + volumes.push(identity!); + } else if (kind === "processId" && /^[1-9][0-9]*$/u.test(identity!)) { + processIds.push(Number(identity)); + } else { + throw new Error("Jetson cleanup evidence is malformed"); + } + } + return validateCleanupEvidence({ schemaVersion: 1, volumes, processIds }); +} + +function mergeCleanupEvidence( + previous: JetsonCleanupEvidence | undefined, + current: JetsonCleanupEvidence, +): JetsonCleanupEvidence { + return validateCleanupEvidence({ + schemaVersion: 1, + volumes: [...(previous?.volumes ?? []), ...current.volumes], + processIds: [...(previous?.processIds ?? []), ...current.processIds], + }); +} + export class SshJetsonDispatchWorker implements JetsonDispatchWorker { readonly #config: SshJetsonWorkerConfig; readonly #runProcess: typeof runProcess; @@ -604,18 +733,41 @@ export class SshJetsonDispatchWorker implements JetsonDispatchWorker { } async cleanup(options: { jobId: string; signal: AbortSignal }): Promise { - await this.#runProcess({ + const cleanupResult = await this.#runProcess({ executable: this.#config.cleanupExecutable, args: [], signal: options.signal, }); + const currentEvidence = parseCleanupCommandEvidence(cleanupResult.stdout); + const evidencePath = this.#cleanupEvidencePath(options.jobId); + const previousRaw = readPrivateRegularFile(evidencePath, { + allowMissing: true, + maxBytes: MAX_CLEANUP_EVIDENCE_BYTES, + }); + const evidence = mergeCleanupEvidence( + previousRaw === null ? undefined : parseCleanupEvidenceJson(previousRaw), + currentEvidence, + ); + const serializedEvidence = `${JSON.stringify(evidence)}\n`; + if (Buffer.byteLength(serializedEvidence) > MAX_CLEANUP_EVIDENCE_BYTES) { + throw new Error("Jetson cleanup evidence is too large"); + } + writePrivateRegularFile(evidencePath, serializedEvidence); const expectedRaw = readPrivateRegularFile(this.#baselinePath(options.jobId), { allowMissing: true, maxBytes: MAX_BASELINE_BYTES, }); const verification = await this.#runProcess({ executable: "ssh", - args: [...this.#sshArgs(), this.#config.destination, "bash", "-s", "--", options.jobId], + args: [ + ...this.#sshArgs(), + this.#config.destination, + "bash", + "-s", + "--", + options.jobId, + Buffer.from(serializedEvidence).toString("base64"), + ], input: CLEANUP_VERIFICATION_SCRIPT, signal: options.signal, }); @@ -632,6 +784,11 @@ export class SshJetsonDispatchWorker implements JetsonDispatchWorker { return path.join(this.#config.stateDirectory, `${jobId}.baseline.json`); } + #cleanupEvidencePath(jobId: string): string { + if (!/^[a-f0-9]{64}$/u.test(jobId)) throw new Error("Jetson job ID is invalid"); + return path.join(this.#config.stateDirectory, `${jobId}.cleanup.json`); + } + #sshArgs(): string[] { return [ "-F", From 8563f665c44c8b9896984b044f58b74cc6f2d048 Mon Sep 17 00:00:00 2001 From: San Dang Date: Mon, 10 Aug 2026 21:51:22 +0700 Subject: [PATCH 13/34] fix(e2e): persist failed Jetson cleanup evidence Signed-off-by: San Dang --- test/e2e/docs/jetson-colossus-dispatch.md | 24 +++++-- .../support/jetson-dispatch-worker.test.ts | 45 +++++++++++++ tools/e2e/jetson-dispatch-cleanup.sh | 35 +++++++---- tools/e2e/jetson-dispatch-worker.mts | 63 ++++++++++++------- 4 files changed, 127 insertions(+), 40 deletions(-) diff --git a/test/e2e/docs/jetson-colossus-dispatch.md b/test/e2e/docs/jetson-colossus-dispatch.md index 9a16ec85f76..055291b8e0a 100644 --- a/test/e2e/docs/jetson-colossus-dispatch.md +++ b/test/e2e/docs/jetson-colossus-dispatch.md @@ -221,8 +221,9 @@ It must exit nonzero when target ownership is ambiguous, cleanup fails, or absen It must not remove `/var/lib/nemoclaw-jetson-dispatch/state/device.lock`. The dispatcher removes that lock only after cleanup and absence verification succeed. -After the fixed cleanup helper exits with status zero, the worker parses its bounded evidence block. -The worker writes the validated identities to this private state file with mode `0600`: +Before any destructive cleanup action, the helper validates every discovered Docker volume name and process ID. +The helper then emits one bounded evidence block between its versioned sentinel lines. +The worker writes these identities to this private state file with mode `0600`: ```text /var/lib/nemoclaw-jetson-dispatch/state/.cleanup.json @@ -240,10 +241,13 @@ The file has this exact schema: Either identity array can be empty. The worker merges new identities with the existing record instead of replacing earlier identities. -This merge preserves identities when cleanup verification fails and the dispatcher retries cleanup for the same job. +After the helper succeeds, the worker parses and merges the evidence block before independent verification. +If a later helper action fails, the worker receives `ProcessFailure`. +The worker parses and merges the emitted block before it rethrows that failure. +The failure keeps the device lock for startup recovery. The dispatcher retains the cleanup record after it removes the device lock. -After the helper exits, the worker independently verifies these conditions over pinned-host-key SSH: +After the helper succeeds, the worker independently verifies these conditions over pinned-host-key SSH: - The validated job workspace is absent and is not a symbolic link. - No OpenShell-managed container has the `e2e-jetson-nvmap` sandbox label. @@ -468,7 +472,8 @@ The uploaded `e2e-jetson-nvmap-gpu` artifact must contain `jetson-dispatch.json` - The requested candidate commit SHA and workflow run identity. - The Jetson model, JetPack package version or `unavailable`, Jetson Linux release, and kernel. - The test conclusion and bounded log. -- `cleanup: "succeeded"` before `conclusion: "success"`. +- `cleanup: "succeeded"`. +- `conclusion: "success"` for the successful proof job. It must also contain `jetson-e2e-artifacts.tar.gz`. The dispatcher creates that archive from the remote E2E artifact directory before it removes the candidate workspace. @@ -477,7 +482,10 @@ Before a restarted dispatcher replays the same deterministic job ID, it removes After the workflow completes, independently verify every allowlisted resource is absent. Require the private `.cleanup.json` file and verify every recorded volume and process ID is absent. -Then run one controlled failing candidate and confirm that its artifact records the same cleanup evidence. +The private cleanup record is Colossus state and is not part of the uploaded artifact. +Then run one controlled failing candidate. +Confirm that its `jetson-dispatch.json` artifact shows `cleanup: "succeeded"` and `conclusion: "failure"`. +Require its private cleanup record and verify every recorded identity is absent. For a cancellation proof, cancel a controller after it logs the job ID. The controller can exit before it downloads an artifact. Inspect the private Colossus `.json` status for `conclusion: "cancelled"` and `cleanup: "succeeded"`. @@ -495,6 +503,10 @@ If cleanup fails, startup fails or the completed job reports `conclusion: "clean If cleanup succeeds but lock removal fails, the completed job reports `conclusion: "cleanup-failed"` with `cleanup: "succeeded"`. The lock remains in either case. +A helper failure after evidence emission leaves validated identities in the private cleanup record. +On the next startup attempt, the worker merges new identities with every identity already in that record. +After the helper succeeds, independent verification checks every retained and new identity before the dispatcher removes the lock. + The unit uses `Restart=on-failure`, so a startup cleanup failure otherwise retries every five seconds. Stop that retry loop before investigation or repair: diff --git a/test/e2e/support/jetson-dispatch-worker.test.ts b/test/e2e/support/jetson-dispatch-worker.test.ts index db2e488e94c..2ef04a20912 100644 --- a/test/e2e/support/jetson-dispatch-worker.test.ts +++ b/test/e2e/support/jetson-dispatch-worker.test.ts @@ -405,6 +405,45 @@ describe("Colossus SSH worker deployment boundary", () => { }); }); + it("retains a failed volume identity for startup cleanup recovery (#8142)", async () => { + const files = deploymentFiles(); + const jobId = "b".repeat(64); + fs.writeFileSync( + path.join(files.stateDirectory, `${jobId}.baseline.json`), + `${JSON.stringify(BASELINE)}\n`, + { mode: 0o600 }, + ); + const processRunner = vi + .fn() + .mockRejectedValueOnce( + new ProcessFailure("volume removal failed", { + stdout: `${cleanupOutput({ volumes: ["sandbox-volume"] })}container removed\n`, + stderr: "volume is still in use\n", + }), + ) + .mockResolvedValueOnce({ stdout: cleanupOutput(), stderr: "" }) + .mockResolvedValueOnce({ stdout: BASELINE_OUTPUT, stderr: "" }); + const worker = new SshJetsonDispatchWorker(loadConfig(files), processRunner); + + await expect(worker.cleanup({ jobId, signal: new AbortController().signal })).rejects.toThrow( + "volume removal failed", + ); + expect( + JSON.parse(fs.readFileSync(path.join(files.stateDirectory, `${jobId}.cleanup.json`), "utf8")), + ).toEqual({ schemaVersion: 1, volumes: ["sandbox-volume"], processIds: [] }); + + const restartedWorker = new SshJetsonDispatchWorker(loadConfig(files), processRunner); + await expect( + restartedWorker.cleanup({ jobId, signal: new AbortController().signal }), + ).resolves.toBeUndefined(); + const encodedEvidence = processRunner.mock.calls[2]![0].args.at(-1); + expect(JSON.parse(Buffer.from(encodedEvidence!, "base64").toString("utf8"))).toEqual({ + schemaVersion: 1, + volumes: ["sandbox-volume"], + processIds: [], + }); + }); + it.each([ "", "nemoclaw-cleanup-evidence-v1-begin\nvolume\t../unsafe\nnemoclaw-cleanup-evidence-v1-end\n", @@ -437,6 +476,12 @@ describe("Colossus SSH worker deployment boundary", () => { expect(cleanupProgram).toContain("label=openshell.ai/sandbox-name=$sandbox_name"); expect(cleanupProgram).toContain("nemoclaw-cleanup-evidence-v1-begin"); expect(cleanupProgram).toContain("nemoclaw-cleanup-evidence-v1-end"); + expect(cleanupProgram.indexOf("nemoclaw-cleanup-evidence-v1-begin")).toBeLessThan( + cleanupProgram.indexOf('docker container rm --force "$container"'), + ); + expect(cleanupProgram.indexOf("nemoclaw-cleanup-evidence-v1-end")).toBeLessThan( + cleanupProgram.indexOf('docker volume rm "$volume"'), + ); expect(cleanupProgram).not.toMatch(/pkill|pgrep|docker (?:system|container|volume) prune/u); expect(cleanupProgram).not.toContain('rm -rf -- "$workspace_root"'); expect(cleanupProgram).not.toContain("ollama serve"); diff --git a/tools/e2e/jetson-dispatch-cleanup.sh b/tools/e2e/jetson-dispatch-cleanup.sh index 0deb6c7f959..2320d7a3e23 100755 --- a/tools/e2e/jetson-dispatch-cleanup.sh +++ b/tools/e2e/jetson-dispatch-cleanup.sh @@ -138,7 +138,7 @@ auth_proxy_pid="$(read_recorded_pid "$job_home/.nemoclaw/ollama-auth-proxy.pid") gateway_pid="$(read_recorded_pid "$job_home/.local/state/nemoclaw/openshell-docker-gateway/openshell-gateway.pid")" cloudflared_pid="$(read_recorded_pid "$service_directory/cloudflared.pid")" -stop_recorded_pid() { +validate_recorded_pid() { local pid="$1" marker="$2" [ -n "$pid" ] || return 0 kill -0 "$pid" 2>/dev/null || return 0 @@ -157,6 +157,13 @@ stop_recorded_pid() { echo "Refusing to stop a process outside the job home" >&2 exit 1 fi +} + +stop_recorded_pid() { + local pid="$1" marker="$2" + [ -n "$pid" ] || return 0 + kill -0 "$pid" 2>/dev/null || return 0 + validate_recorded_pid "$pid" "$marker" kill "$pid" for _attempt in 1 2 3 4 5 6 7 8 9 10; do kill -0 "$pid" 2>/dev/null || return 0 @@ -171,6 +178,21 @@ stop_recorded_pid() { exit 1 } +validate_recorded_pid "$auth_proxy_pid" ollama-auth-proxy. +validate_recorded_pid "$gateway_pid" openshell-gateway +validate_recorded_pid "$cloudflared_pid" cloudflared + +printf '%s\n' nemoclaw-cleanup-evidence-v1-begin +for volume in "${recorded_volumes[@]}"; do + printf 'volume\t%s\n' "$volume" +done +for pid in "$auth_proxy_pid" "$gateway_pid" "$cloudflared_pid"; do + if [ -n "$pid" ]; then + printf 'processId\t%s\n' "$pid" + fi +done +printf '%s\n' nemoclaw-cleanup-evidence-v1-end + gateway_present=0 if [ -d "$job_home" ]; then gateway_json="$(HOME="$job_home" openshell gateway list -o json)" @@ -275,15 +297,4 @@ for pid in "$auth_proxy_pid" "$gateway_pid" "$cloudflared_pid"; do exit 1 fi done - -printf '%s\n' nemoclaw-cleanup-evidence-v1-begin -for volume in "${recorded_volumes[@]}"; do - printf 'volume\t%s\n' "$volume" -done -for pid in "$auth_proxy_pid" "$gateway_pid" "$cloudflared_pid"; do - if [ -n "$pid" ]; then - printf 'processId\t%s\n' "$pid" - fi -done -printf '%s\n' nemoclaw-cleanup-evidence-v1-end JETSON_CLEANUP diff --git a/tools/e2e/jetson-dispatch-worker.mts b/tools/e2e/jetson-dispatch-worker.mts index 01196c7b3ea..8d32e3c25b1 100644 --- a/tools/e2e/jetson-dispatch-worker.mts +++ b/tools/e2e/jetson-dispatch-worker.mts @@ -566,9 +566,15 @@ function parseCleanupCommandEvidence(output: string): JetsonCleanupEvidence { } const lines = output.replace(/\r/gu, "").split("\n"); while (lines.at(-1) === "") lines.pop(); - const endIndex = lines.lastIndexOf(CLEANUP_EVIDENCE_END); - const beginIndex = lines.lastIndexOf(CLEANUP_EVIDENCE_BEGIN, endIndex - 1); - if (beginIndex < 0 || endIndex !== lines.length - 1 || beginIndex >= endIndex) { + const beginIndex = lines.indexOf(CLEANUP_EVIDENCE_BEGIN); + const endIndex = lines.indexOf(CLEANUP_EVIDENCE_END); + if ( + beginIndex < 0 || + endIndex < 0 || + beginIndex !== lines.lastIndexOf(CLEANUP_EVIDENCE_BEGIN) || + endIndex !== lines.lastIndexOf(CLEANUP_EVIDENCE_END) || + beginIndex >= endIndex + ) { throw new Error("Jetson cleanup did not return bounded resource evidence"); } const volumes: string[] = []; @@ -733,26 +739,20 @@ export class SshJetsonDispatchWorker implements JetsonDispatchWorker { } async cleanup(options: { jobId: string; signal: AbortSignal }): Promise { - const cleanupResult = await this.#runProcess({ - executable: this.#config.cleanupExecutable, - args: [], - signal: options.signal, - }); - const currentEvidence = parseCleanupCommandEvidence(cleanupResult.stdout); - const evidencePath = this.#cleanupEvidencePath(options.jobId); - const previousRaw = readPrivateRegularFile(evidencePath, { - allowMissing: true, - maxBytes: MAX_CLEANUP_EVIDENCE_BYTES, - }); - const evidence = mergeCleanupEvidence( - previousRaw === null ? undefined : parseCleanupEvidenceJson(previousRaw), - currentEvidence, - ); - const serializedEvidence = `${JSON.stringify(evidence)}\n`; - if (Buffer.byteLength(serializedEvidence) > MAX_CLEANUP_EVIDENCE_BYTES) { - throw new Error("Jetson cleanup evidence is too large"); + let serializedEvidence: string; + try { + const cleanupResult = await this.#runProcess({ + executable: this.#config.cleanupExecutable, + args: [], + signal: options.signal, + }); + serializedEvidence = this.#recordCleanupEvidence(options.jobId, cleanupResult.stdout); + } catch (error) { + if (error instanceof ProcessFailure && error.result.stdout.includes(CLEANUP_EVIDENCE_BEGIN)) { + this.#recordCleanupEvidence(options.jobId, error.result.stdout); + } + throw error; } - writePrivateRegularFile(evidencePath, serializedEvidence); const expectedRaw = readPrivateRegularFile(this.#baselinePath(options.jobId), { allowMissing: true, maxBytes: MAX_BASELINE_BYTES, @@ -779,6 +779,25 @@ export class SshJetsonDispatchWorker implements JetsonDispatchWorker { } } + #recordCleanupEvidence(jobId: string, output: string): string { + const currentEvidence = parseCleanupCommandEvidence(output); + const evidencePath = this.#cleanupEvidencePath(jobId); + const previousRaw = readPrivateRegularFile(evidencePath, { + allowMissing: true, + maxBytes: MAX_CLEANUP_EVIDENCE_BYTES, + }); + const evidence = mergeCleanupEvidence( + previousRaw === null ? undefined : parseCleanupEvidenceJson(previousRaw), + currentEvidence, + ); + const serializedEvidence = `${JSON.stringify(evidence)}\n`; + if (Buffer.byteLength(serializedEvidence) > MAX_CLEANUP_EVIDENCE_BYTES) { + throw new Error("Jetson cleanup evidence is too large"); + } + writePrivateRegularFile(evidencePath, serializedEvidence); + return serializedEvidence; + } + #baselinePath(jobId: string): string { if (!/^[a-f0-9]{64}$/u.test(jobId)) throw new Error("Jetson job ID is invalid"); return path.join(this.#config.stateDirectory, `${jobId}.baseline.json`); From 0cd689a960f92db7fed80c22947ae3fe7dde99bc Mon Sep 17 00:00:00 2001 From: San Dang Date: Mon, 10 Aug 2026 22:05:31 +0700 Subject: [PATCH 14/34] fix(e2e): fsync Jetson cleanup evidence Signed-off-by: San Dang --- test/e2e/docs/jetson-colossus-dispatch.md | 36 ++- .../support/jetson-dispatch-worker.test.ts | 104 +++++-- tools/e2e/jetson-dispatch-cleanup.sh | 272 +++++++++++++----- tools/e2e/jetson-dispatch-worker.mts | 58 +--- 4 files changed, 331 insertions(+), 139 deletions(-) diff --git a/test/e2e/docs/jetson-colossus-dispatch.md b/test/e2e/docs/jetson-colossus-dispatch.md index 055291b8e0a..6975dc4a146 100644 --- a/test/e2e/docs/jetson-colossus-dispatch.md +++ b/test/e2e/docs/jetson-colossus-dispatch.md @@ -207,7 +207,17 @@ Changing one of those values requires a corresponding reviewed source change. The dispatcher invokes it after success, failure, cancellation, and timeout. The dispatcher also invokes it during startup when `device.lock` remains from an interrupted service process. -The cleanup program must perform these bounded actions: +The cleanup program uses these phases in order: + +1. Run read-only discovery over pinned-host-key SSH and validate every discovered volume and process identity. +2. Strictly parse and merge those identities with the existing private cleanup record on Colossus. +3. Persist the merged record before starting destructive cleanup over pinned-host-key SSH. + +For durable persistence, the helper writes a mode-`0600` temporary file in the state directory. +It fsyncs the file, atomically renames it to `.cleanup.json`, and fsyncs the state directory. +If discovery, validation, or durable persistence fails, the helper does not start destructive cleanup. + +The destructive phase must perform these bounded actions: 1. Stop and remove only the named sandbox, its forwards, and the named gateway. 2. Stop only the recorded helper PIDs after verifying the process owner, command marker, and job `HOME`. @@ -221,9 +231,7 @@ It must exit nonzero when target ownership is ambiguous, cleanup fails, or absen It must not remove `/var/lib/nemoclaw-jetson-dispatch/state/device.lock`. The dispatcher removes that lock only after cleanup and absence verification succeed. -Before any destructive cleanup action, the helper validates every discovered Docker volume name and process ID. -The helper then emits one bounded evidence block between its versioned sentinel lines. -The worker writes these identities to this private state file with mode `0600`: +The durable cleanup record uses this path: ```text /var/lib/nemoclaw-jetson-dispatch/state/.cleanup.json @@ -240,11 +248,12 @@ The file has this exact schema: ``` Either identity array can be empty. -The worker merges new identities with the existing record instead of replacing earlier identities. -After the helper succeeds, the worker parses and merges the evidence block before independent verification. -If a later helper action fails, the worker receives `ProcessFailure`. -The worker parses and merges the emitted block before it rethrows that failure. -The failure keeps the device lock for startup recovery. +The helper merges new identities with the existing record instead of replacing earlier identities. +The destructive phase receives this merged record and acts on every recorded identity. +After destructive cleanup succeeds, the helper emits one bounded evidence block for the merged record. +The worker reads and revalidates that successful output against the durable record before independent verification. +Failure durability belongs to the helper's pre-cleanup record, not to worker parsing of failed process output. +Any helper failure or interruption keeps the device lock for startup recovery. The dispatcher retains the cleanup record after it removes the device lock. After the helper succeeds, the worker independently verifies these conditions over pinned-host-key SSH: @@ -503,9 +512,12 @@ If cleanup fails, startup fails or the completed job reports `conclusion: "clean If cleanup succeeds but lock removal fails, the completed job reports `conclusion: "cleanup-failed"` with `cleanup: "succeeded"`. The lock remains in either case. -A helper failure after evidence emission leaves validated identities in the private cleanup record. -On the next startup attempt, the worker merges new identities with every identity already in that record. -After the helper succeeds, independent verification checks every retained and new identity before the dispatcher removes the lock. +If the service stops before durable persistence completes, destructive cleanup has not started. +If it stops after durable persistence, the cleanup record and device lock remain for startup recovery. +On startup, the helper discovers current identities and merges them with every retained identity before cleanup resumes. +For example, termination after container removal cannot erase the volume identities recorded before that removal. +The startup cleanup passes those retained volumes into deletion and independent verification. +After the helper succeeds, the worker revalidates its output and every retained identity before the dispatcher removes the lock. The unit uses `Restart=on-failure`, so a startup cleanup failure otherwise retries every five seconds. Stop that retry loop before investigation or repair: diff --git a/test/e2e/support/jetson-dispatch-worker.test.ts b/test/e2e/support/jetson-dispatch-worker.test.ts index 2ef04a20912..5bd46b57fe4 100644 --- a/test/e2e/support/jetson-dispatch-worker.test.ts +++ b/test/e2e/support/jetson-dispatch-worker.test.ts @@ -57,6 +57,16 @@ function cleanupOutput({ ].join("\n"); } +function persistCleanupEvidence( + files: ReturnType, + jobId: string, + evidence: { schemaVersion: 1; volumes: string[]; processIds: number[] }, +): string { + const file = path.join(files.stateDirectory, `${jobId}.cleanup.json`); + fs.writeFileSync(file, `${JSON.stringify(evidence)}\n`, { mode: 0o600 }); + return file; +} + afterEach(() => { for (const directory of temporaryDirectories.splice(0)) { fs.rmSync(directory, { force: true, recursive: true }); @@ -282,6 +292,11 @@ describe("Colossus SSH worker deployment boundary", () => { const jobId = "b".repeat(64); const baselinePath = path.join(files.stateDirectory, `${jobId}.baseline.json`); fs.writeFileSync(baselinePath, `${JSON.stringify(BASELINE)}\n`, { mode: 0o600 }); + persistCleanupEvidence(files, jobId, { + schemaVersion: 1, + volumes: ["sandbox-volume"], + processIds: [1234], + }); const processRunner = vi .fn() .mockResolvedValueOnce({ @@ -334,6 +349,7 @@ describe("Colossus SSH worker deployment boundary", () => { it("verifies cleanup after a pre-candidate failure without a baseline record (#8142)", async () => { const files = deploymentFiles(); const jobId = "b".repeat(64); + persistCleanupEvidence(files, jobId, { schemaVersion: 1, volumes: [], processIds: [] }); const processRunner = vi .fn() .mockResolvedValueOnce({ stdout: cleanupOutput(), stderr: "" }) @@ -359,6 +375,7 @@ describe("Colossus SSH worker deployment boundary", () => { const jobId = "b".repeat(64); const baselinePath = path.join(files.stateDirectory, `${jobId}.baseline.json`); fs.writeFileSync(baselinePath, `${JSON.stringify(BASELINE)}\n`, { mode: 0o600 }); + persistCleanupEvidence(files, jobId, { schemaVersion: 1, volumes: [], processIds: [] }); const processRunner = vi .fn() .mockResolvedValueOnce({ stdout: cleanupOutput(), stderr: "" }) @@ -381,14 +398,31 @@ describe("Colossus SSH worker deployment boundary", () => { ); const processRunner = vi .fn() - .mockResolvedValueOnce({ - stdout: cleanupOutput({ volumes: ["sandbox-volume"], processIds: [1234] }), - stderr: "", + .mockImplementationOnce(async () => { + persistCleanupEvidence(files, jobId, { + schemaVersion: 1, + volumes: ["sandbox-volume"], + processIds: [1234], + }); + return { + stdout: cleanupOutput({ volumes: ["sandbox-volume"], processIds: [1234] }), + stderr: "", + }; }) .mockResolvedValueOnce({ stdout: BASELINE_OUTPUT, stderr: "" }) - .mockResolvedValueOnce({ - stdout: cleanupOutput({ volumes: ["gateway-volume"], processIds: [5678] }), - stderr: "", + .mockImplementationOnce(async () => { + persistCleanupEvidence(files, jobId, { + schemaVersion: 1, + volumes: ["gateway-volume", "sandbox-volume"], + processIds: [1234, 5678], + }); + return { + stdout: cleanupOutput({ + volumes: ["gateway-volume", "sandbox-volume"], + processIds: [1234, 5678], + }), + stderr: "", + }; }) .mockResolvedValueOnce({ stdout: BASELINE_OUTPUT, stderr: "" }); const worker = new SshJetsonDispatchWorker(loadConfig(files), processRunner); @@ -408,6 +442,7 @@ describe("Colossus SSH worker deployment boundary", () => { it("retains a failed volume identity for startup cleanup recovery (#8142)", async () => { const files = deploymentFiles(); const jobId = "b".repeat(64); + const cleanupEvidencePath = path.join(files.stateDirectory, `${jobId}.cleanup.json`); fs.writeFileSync( path.join(files.stateDirectory, `${jobId}.baseline.json`), `${JSON.stringify(BASELINE)}\n`, @@ -415,22 +450,32 @@ describe("Colossus SSH worker deployment boundary", () => { ); const processRunner = vi .fn() - .mockRejectedValueOnce( - new ProcessFailure("volume removal failed", { - stdout: `${cleanupOutput({ volumes: ["sandbox-volume"] })}container removed\n`, - stderr: "volume is still in use\n", - }), - ) - .mockResolvedValueOnce({ stdout: cleanupOutput(), stderr: "" }) + .mockImplementationOnce(async () => { + persistCleanupEvidence(files, jobId, { + schemaVersion: 1, + volumes: ["sandbox-volume"], + processIds: [], + }); + throw new ProcessFailure("cleanup interrupted after container removal", { + stdout: "container removed\n", + stderr: "service interrupted\n", + }); + }) + .mockResolvedValueOnce({ + stdout: cleanupOutput({ volumes: ["sandbox-volume"] }), + stderr: "", + }) .mockResolvedValueOnce({ stdout: BASELINE_OUTPUT, stderr: "" }); const worker = new SshJetsonDispatchWorker(loadConfig(files), processRunner); await expect(worker.cleanup({ jobId, signal: new AbortController().signal })).rejects.toThrow( - "volume removal failed", + "cleanup interrupted after container removal", ); - expect( - JSON.parse(fs.readFileSync(path.join(files.stateDirectory, `${jobId}.cleanup.json`), "utf8")), - ).toEqual({ schemaVersion: 1, volumes: ["sandbox-volume"], processIds: [] }); + expect(JSON.parse(fs.readFileSync(cleanupEvidencePath, "utf8"))).toEqual({ + schemaVersion: 1, + volumes: ["sandbox-volume"], + processIds: [], + }); const restartedWorker = new SshJetsonDispatchWorker(loadConfig(files), processRunner); await expect( @@ -461,7 +506,27 @@ describe("Colossus SSH worker deployment boundary", () => { expect(fs.existsSync(path.join(files.stateDirectory, `${jobId}.cleanup.json`))).toBe(false); }); + it("rejects cleanup output that differs from the durable identity record (#8142)", async () => { + const files = deploymentFiles(); + const jobId = "b".repeat(64); + persistCleanupEvidence(files, jobId, { schemaVersion: 1, volumes: [], processIds: [] }); + const processRunner = vi.fn().mockResolvedValueOnce({ + stdout: cleanupOutput({ volumes: ["unpersisted-volume"] }), + stderr: "", + }); + const worker = new SshJetsonDispatchWorker(loadConfig(files), processRunner); + + await expect(worker.cleanup({ jobId, signal: new AbortController().signal })).rejects.toThrow( + "Jetson cleanup output differs from its durable resource evidence", + ); + expect(processRunner).toHaveBeenCalledTimes(1); + }); + it("keeps cleanup targets fixed and preserves the Jetson baseline (#8142)", () => { + const fileFsync = cleanupProgram.indexOf("fs.fsyncSync(descriptor)"); + const atomicRename = cleanupProgram.indexOf("fs.renameSync(temporaryFile, cleanupFile)"); + const directoryFsync = cleanupProgram.indexOf("fs.fsyncSync(directoryDescriptor)"); + const destructivePhase = cleanupProgram.indexOf("<<'JETSON_CLEANUP'"); expect(cleanupProgram).toContain("sandbox_name=e2e-jetson-nvmap"); expect(cleanupProgram).toContain("gateway_name=nemoclaw"); expect(cleanupProgram).toContain("destination=nvidia@192.168.55.1"); @@ -482,6 +547,11 @@ describe("Colossus SSH worker deployment boundary", () => { expect(cleanupProgram.indexOf("nemoclaw-cleanup-evidence-v1-end")).toBeLessThan( cleanupProgram.indexOf('docker volume rm "$volume"'), ); + expect(cleanupProgram).toContain("fs.constants.O_EXCL"); + expect(fileFsync).toBeGreaterThan(cleanupProgram.indexOf("<<'JETSON_DISCOVERY'")); + expect(atomicRename).toBeGreaterThan(fileFsync); + expect(directoryFsync).toBeGreaterThan(atomicRename); + expect(destructivePhase).toBeGreaterThan(directoryFsync); expect(cleanupProgram).not.toMatch(/pkill|pgrep|docker (?:system|container|volume) prune/u); expect(cleanupProgram).not.toContain('rm -rf -- "$workspace_root"'); expect(cleanupProgram).not.toContain("ollama serve"); diff --git a/tools/e2e/jetson-dispatch-cleanup.sh b/tools/e2e/jetson-dispatch-cleanup.sh index 2320d7a3e23..00c60bd4227 100755 --- a/tools/e2e/jetson-dispatch-cleanup.sh +++ b/tools/e2e/jetson-dispatch-cleanup.sh @@ -21,16 +21,21 @@ if ! [[ "$job_id" =~ ^[a-f0-9]{64}$ ]]; then exit 1 fi -exec ssh -F /dev/null -T \ - -o BatchMode=yes \ - -o ConnectTimeout=15 \ - -o IdentitiesOnly=yes \ - -o ServerAliveCountMax=2 \ - -o ServerAliveInterval=15 \ - -o StrictHostKeyChecking=yes \ - -o "UserKnownHostsFile=$known_hosts_file" \ - -i "$identity_file" \ - "$destination" bash -s -- "$job_id" <<'JETSON_CLEANUP' +ssh_args=( + -F /dev/null + -T + -o BatchMode=yes + -o ConnectTimeout=15 + -o IdentitiesOnly=yes + -o ServerAliveCountMax=2 + -o ServerAliveInterval=15 + -o StrictHostKeyChecking=yes + -o "UserKnownHostsFile=$known_hosts_file" + -i "$identity_file" +) + +discovery_output="$( + ssh "${ssh_args[@]}" "$destination" bash -s -- "$job_id" <<'JETSON_DISCOVERY' set -euo pipefail job_id="$1" @@ -40,24 +45,10 @@ workspace_root=/var/tmp/nemoclaw-jetson-e2e workspace="$workspace_root/$job_id" job_home="$workspace/home" sandbox_name=e2e-jetson-nvmap -gateway_name=nemoclaw gateway_container=openshell-cluster-nemoclaw gateway_volume=openshell-cluster-nemoclaw service_directory="/tmp/nemoclaw-services-$sandbox_name" -if [ -L "$workspace_root" ] || { [ -e "$workspace_root" ] && [ ! -d "$workspace_root" ]; }; then - echo "Jetson E2E workspace root is not a trusted directory" >&2 - exit 1 -fi -if [ -L "$workspace" ] || { [ -e "$workspace" ] && [ ! -d "$workspace" ]; }; then - echo "Jetson E2E job workspace is not a trusted directory" >&2 - exit 1 -fi -if [ -L "$job_home" ] || { [ -e "$job_home" ] && [ ! -d "$job_home" ]; }; then - echo "Jetson E2E job home is not a trusted directory" >&2 - exit 1 -fi - require_plain_directory_if_present() { local directory="$1" if [ -L "$directory" ] || { [ -e "$directory" ] && [ ! -d "$directory" ]; }; then @@ -66,6 +57,9 @@ require_plain_directory_if_present() { fi } +require_plain_directory_if_present "$workspace_root" +require_plain_directory_if_present "$workspace" +require_plain_directory_if_present "$job_home" require_plain_directory_if_present "$job_home/.nemoclaw" require_plain_directory_if_present "$job_home/.local" require_plain_directory_if_present "$job_home/.local/state" @@ -75,12 +69,11 @@ require_plain_directory_if_present "$service_directory" recorded_volumes=() record_volume() { - local volume="$1" + local volume="$1" recorded [[ "$volume" =~ ^[A-Za-z0-9][A-Za-z0-9_.-]{0,254}$ ]] || { echo "Refusing an invalid recorded Docker volume name" >&2 exit 1 } - local recorded for recorded in "${recorded_volumes[@]}"; do [ "$recorded" = "$volume" ] && return 0 done @@ -134,10 +127,6 @@ read_recorded_pid() { printf '%s\n' "$pid" } -auth_proxy_pid="$(read_recorded_pid "$job_home/.nemoclaw/ollama-auth-proxy.pid")" -gateway_pid="$(read_recorded_pid "$job_home/.local/state/nemoclaw/openshell-docker-gateway/openshell-gateway.pid")" -cloudflared_pid="$(read_recorded_pid "$service_directory/cloudflared.pid")" - validate_recorded_pid() { local pid="$1" marker="$2" [ -n "$pid" ] || return 0 @@ -145,25 +134,181 @@ validate_recorded_pid() { local process_uid cmdline process_uid="$(awk '/^Uid:/ { print $2; exit }' "/proc/$pid/status")" [ "$process_uid" = "$(id -u)" ] || { - echo "Refusing to stop a process owned by another user" >&2 + echo "Refusing to record a process owned by another user" >&2 exit 1 } cmdline="$(tr '\000' ' ' <"/proc/$pid/cmdline")" case "$cmdline" in *"$marker"*) ;; - *) echo "Refusing to stop a recorded PID with an unexpected command" >&2; exit 1 ;; + *) echo "Refusing to record a PID with an unexpected command" >&2; exit 1 ;; esac if ! tr '\000' '\n' <"/proc/$pid/environ" | grep -Fqx "HOME=$job_home"; then - echo "Refusing to stop a process outside the job home" >&2 + echo "Refusing to record a process outside the job home" >&2 + exit 1 + fi +} + +auth_proxy_pid="$(read_recorded_pid "$job_home/.nemoclaw/ollama-auth-proxy.pid")" +gateway_pid="$(read_recorded_pid "$job_home/.local/state/nemoclaw/openshell-docker-gateway/openshell-gateway.pid")" +cloudflared_pid="$(read_recorded_pid "$service_directory/cloudflared.pid")" +validate_recorded_pid "$auth_proxy_pid" ollama-auth-proxy. +validate_recorded_pid "$gateway_pid" openshell-gateway +validate_recorded_pid "$cloudflared_pid" cloudflared + +printf '%s\n' nemoclaw-cleanup-evidence-v1-begin +for volume in "${recorded_volumes[@]}"; do + printf 'volume\t%s\n' "$volume" +done +for pid in "$auth_proxy_pid" "$gateway_pid" "$cloudflared_pid"; do + if [ -n "$pid" ]; then + printf 'processId\t%s\n' "$pid" + fi +done +printf '%s\n' nemoclaw-cleanup-evidence-v1-end +JETSON_DISCOVERY +)" + +canonical_evidence="$( + # shellcheck disable=SC2016 + printf '%s\n' "$discovery_output" | /usr/bin/node -e ' + const fs = require("node:fs"); + const path = require("node:path"); + const stateDirectory = process.argv[1]; + const jobId = process.argv[2]; + if (!/^[a-f0-9]{64}$/.test(jobId)) process.exit(1); + const begin = "nemoclaw-cleanup-evidence-v1-begin"; + const end = "nemoclaw-cleanup-evidence-v1-end"; + const lines = fs.readFileSync(0, "utf8").replace(/\r/g, "").trimEnd().split("\n"); + const beginIndex = lines.indexOf(begin); + const endIndex = lines.indexOf(end); + if (beginIndex < 0 || endIndex < 0 || beginIndex !== lines.lastIndexOf(begin) || endIndex !== lines.lastIndexOf(end) || beginIndex >= endIndex) process.exit(1); + const discovered = { schemaVersion: 1, volumes: [], processIds: [] }; + for (const line of lines.slice(beginIndex + 1, endIndex)) { + const fields = line.split("\t"); + if (fields.length !== 2) process.exit(1); + if (fields[0] === "volume" && /^[A-Za-z0-9][A-Za-z0-9_.-]{0,254}$/.test(fields[1])) discovered.volumes.push(fields[1]); + else if (fields[0] === "processId" && /^[1-9][0-9]*$/.test(fields[1]) && Number.isSafeInteger(Number(fields[1]))) discovered.processIds.push(Number(fields[1])); + else process.exit(1); + } + const cleanupFile = path.join(stateDirectory, `${jobId}.cleanup.json`); + let previous = { schemaVersion: 1, volumes: [], processIds: [] }; + if (fs.existsSync(cleanupFile)) { + const metadata = fs.lstatSync(cleanupFile); + if (!metadata.isFile() || metadata.nlink !== 1 || (metadata.mode & 0o077) !== 0 || metadata.size > 64 * 1024) process.exit(1); + previous = JSON.parse(fs.readFileSync(cleanupFile, "utf8")); + } + const validate = (record) => { + const keys = Object.keys(record).sort(); + if (JSON.stringify(keys) !== JSON.stringify(["processIds", "schemaVersion", "volumes"]) || record.schemaVersion !== 1 || !Array.isArray(record.volumes) || !Array.isArray(record.processIds)) process.exit(1); + if (!record.volumes.every((value) => typeof value === "string" && /^[A-Za-z0-9][A-Za-z0-9_.-]{0,254}$/.test(value))) process.exit(1); + if (!record.processIds.every((value) => Number.isSafeInteger(value) && value > 0)) process.exit(1); + }; + validate(previous); + validate(discovered); + const merged = { + schemaVersion: 1, + volumes: [...new Set([...previous.volumes, ...discovered.volumes])].sort(), + processIds: [...new Set([...previous.processIds, ...discovered.processIds])].sort((a, b) => a - b), + }; + const serialized = `${JSON.stringify(merged)}\n`; + if (Buffer.byteLength(serialized) > 64 * 1024) process.exit(1); + const temporaryFile = path.join(stateDirectory, `.${jobId}.${process.pid}.cleanup.tmp`); + let descriptor; + try { + descriptor = fs.openSync(temporaryFile, fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_EXCL | (fs.constants.O_NOFOLLOW ?? 0), 0o600); + fs.fchmodSync(descriptor, 0o600); + fs.writeFileSync(descriptor, serialized, "utf8"); + fs.fsyncSync(descriptor); + } finally { + if (descriptor !== undefined) fs.closeSync(descriptor); + } + fs.renameSync(temporaryFile, cleanupFile); + const directoryDescriptor = fs.openSync(stateDirectory, fs.constants.O_RDONLY); + try { fs.fsyncSync(directoryDescriptor); } finally { fs.closeSync(directoryDescriptor); } + process.stdout.write(serialized); + ' "$state_directory" "$job_id" +)" + +cleanup_evidence_base64="$(printf '%s\n' "$canonical_evidence" | base64 --wrap=0)" +ssh "${ssh_args[@]}" "$destination" bash -s -- "$job_id" "$cleanup_evidence_base64" <<'JETSON_CLEANUP' +set -euo pipefail + +job_id="$1" +cleanup_evidence_base64="$2" +[[ "$job_id" =~ ^[a-f0-9]{64}$ ]] + +workspace_root=/var/tmp/nemoclaw-jetson-e2e +workspace="$workspace_root/$job_id" +job_home="$workspace/home" +sandbox_name=e2e-jetson-nvmap +gateway_name=nemoclaw +gateway_container=openshell-cluster-nemoclaw +service_directory="/tmp/nemoclaw-services-$sandbox_name" + +require_plain_directory_if_present() { + local directory="$1" + if [ -L "$directory" ] || { [ -e "$directory" ] && [ ! -d "$directory" ]; }; then + echo "Refusing an untrusted cleanup directory: $directory" >&2 exit 1 fi } +require_plain_directory_if_present "$workspace_root" +require_plain_directory_if_present "$workspace" +require_plain_directory_if_present "$job_home" +require_plain_directory_if_present "$job_home/.nemoclaw" +require_plain_directory_if_present "$job_home/.local" +require_plain_directory_if_present "$job_home/.local/state" +require_plain_directory_if_present "$job_home/.local/state/nemoclaw" +require_plain_directory_if_present "$job_home/.local/state/nemoclaw/openshell-docker-gateway" +require_plain_directory_if_present "$service_directory" + +cleanup_rows="$( + printf '%s' "$cleanup_evidence_base64" | base64 --decode | node -e ' + const fs = require("node:fs"); + const value = JSON.parse(fs.readFileSync(0, "utf8")); + const keys = Object.keys(value).sort(); + if (JSON.stringify(keys) !== JSON.stringify(["processIds", "schemaVersion", "volumes"]) || value.schemaVersion !== 1 || !Array.isArray(value.volumes) || !Array.isArray(value.processIds)) process.exit(1); + for (const volume of value.volumes) { + if (typeof volume !== "string" || !/^[A-Za-z0-9][A-Za-z0-9_.-]{0,254}$/.test(volume)) process.exit(1); + process.stdout.write("volume\t" + volume + "\n"); + } + for (const pid of value.processIds) { + if (!Number.isSafeInteger(pid) || pid < 1) process.exit(1); + process.stdout.write("processId\t" + pid + "\n"); + } + ' +)" +recorded_volumes=() +recorded_process_ids=() +if [ -n "$cleanup_rows" ]; then + while IFS=$'\t' read -r kind identity; do + case "$kind" in + volume) recorded_volumes+=("$identity") ;; + processId) recorded_process_ids+=("$identity") ;; + *) exit 1 ;; + esac + done <<<"$cleanup_rows" +fi + stop_recorded_pid() { - local pid="$1" marker="$2" - [ -n "$pid" ] || return 0 + local pid="$1" kill -0 "$pid" 2>/dev/null || return 0 - validate_recorded_pid "$pid" "$marker" + local process_uid cmdline + process_uid="$(awk '/^Uid:/ { print $2; exit }' "/proc/$pid/status")" + [ "$process_uid" = "$(id -u)" ] || { + echo "Refusing to stop a process owned by another user" >&2 + exit 1 + } + cmdline="$(tr '\000' ' ' <"/proc/$pid/cmdline")" + case "$cmdline" in + *ollama-auth-proxy.* | *openshell-gateway* | *cloudflared*) ;; + *) echo "Refusing to stop a recorded PID with an unexpected command" >&2; exit 1 ;; + esac + if ! tr '\000' '\n' <"/proc/$pid/environ" | grep -Fqx "HOME=$job_home"; then + echo "Refusing to stop a process outside the job home" >&2 + exit 1 + fi kill "$pid" for _attempt in 1 2 3 4 5 6 7 8 9 10; do kill -0 "$pid" 2>/dev/null || return 0 @@ -178,21 +323,6 @@ stop_recorded_pid() { exit 1 } -validate_recorded_pid "$auth_proxy_pid" ollama-auth-proxy. -validate_recorded_pid "$gateway_pid" openshell-gateway -validate_recorded_pid "$cloudflared_pid" cloudflared - -printf '%s\n' nemoclaw-cleanup-evidence-v1-begin -for volume in "${recorded_volumes[@]}"; do - printf 'volume\t%s\n' "$volume" -done -for pid in "$auth_proxy_pid" "$gateway_pid" "$cloudflared_pid"; do - if [ -n "$pid" ]; then - printf 'processId\t%s\n' "$pid" - fi -done -printf '%s\n' nemoclaw-cleanup-evidence-v1-end - gateway_present=0 if [ -d "$job_home" ]; then gateway_json="$(HOME="$job_home" openshell gateway list -o json)" @@ -202,25 +332,19 @@ if [ -d "$job_home" ]; then if (!Array.isArray(rows)) throw new Error("invalid gateway list"); process.stdout.write(rows.some((row) => row && row.name === "nemoclaw") ? "present" : "absent"); ')" - if [ "$gateway_state" = present ]; then - gateway_present=1 - fi + [ "$gateway_state" = present ] && gateway_present=1 fi if [ "$gateway_present" -eq 1 ]; then forward_list="$(HOME="$job_home" openshell forward list --gateway "$gateway_name")" while IFS= read -r port; do [ -n "$port" ] || continue - [[ "$port" =~ ^[1-9][0-9]{0,4}$ ]] || { - echo "Refusing an invalid recorded OpenShell forward port" >&2 - exit 1 - } + [[ "$port" =~ ^[1-9][0-9]{0,4}$ ]] || exit 1 HOME="$job_home" openshell forward stop "$port" "$sandbox_name" done < <( printf '%s\n' "$forward_list" | awk -v sandbox="$sandbox_name" \ '$1 == sandbox && $3 ~ /^[0-9]+$/ { print $3 }' ) - sandbox_names="$(HOME="$job_home" openshell sandbox list --names -g "$gateway_name")" if printf '%s\n' "$sandbox_names" | grep -Fqx "$sandbox_name"; then HOME="$job_home" openshell sandbox delete "$sandbox_name" @@ -251,14 +375,18 @@ if [ "$gateway_present" -eq 1 ]; then fi fi -stop_recorded_pid "$auth_proxy_pid" ollama-auth-proxy. -stop_recorded_pid "$gateway_pid" openshell-gateway -stop_recorded_pid "$cloudflared_pid" cloudflared +for pid in "${recorded_process_ids[@]}"; do + stop_recorded_pid "$pid" +done +mapfile -t sandbox_containers < <( + docker ps -aq \ + --filter label=openshell.ai/managed-by=openshell \ + --filter "label=openshell.ai/sandbox-name=$sandbox_name" +) for container in "${sandbox_containers[@]}"; do - if docker container inspect "$container" >/dev/null 2>&1; then - docker container rm --force "$container" - fi + [[ "$container" =~ ^[a-f0-9]{12,64}$ ]] || exit 1 + docker container rm --force "$container" done if docker container inspect "$gateway_container" >/dev/null 2>&1; then docker container rm --force "$gateway_container" @@ -291,10 +419,20 @@ for volume in "${recorded_volumes[@]}"; do exit 1 fi done -for pid in "$auth_proxy_pid" "$gateway_pid" "$cloudflared_pid"; do - if [ -n "$pid" ] && kill -0 "$pid" 2>/dev/null; then +for pid in "${recorded_process_ids[@]}"; do + if kill -0 "$pid" 2>/dev/null; then echo "A recorded test-owned helper process remains" >&2 exit 1 fi done JETSON_CLEANUP + +printf '%s\n' nemoclaw-cleanup-evidence-v1-begin +# shellcheck disable=SC2016 +printf '%s\n' "$canonical_evidence" | /usr/bin/node -e ' + const fs = require("node:fs"); + const value = JSON.parse(fs.readFileSync(0, "utf8")); + for (const volume of value.volumes) console.log(`volume\t${volume}`); + for (const pid of value.processIds) console.log(`processId\t${pid}`); +' +printf '%s\n' nemoclaw-cleanup-evidence-v1-end diff --git a/tools/e2e/jetson-dispatch-worker.mts b/tools/e2e/jetson-dispatch-worker.mts index 8d32e3c25b1..0bee4057889 100644 --- a/tools/e2e/jetson-dispatch-worker.mts +++ b/tools/e2e/jetson-dispatch-worker.mts @@ -594,17 +594,6 @@ function parseCleanupCommandEvidence(output: string): JetsonCleanupEvidence { return validateCleanupEvidence({ schemaVersion: 1, volumes, processIds }); } -function mergeCleanupEvidence( - previous: JetsonCleanupEvidence | undefined, - current: JetsonCleanupEvidence, -): JetsonCleanupEvidence { - return validateCleanupEvidence({ - schemaVersion: 1, - volumes: [...(previous?.volumes ?? []), ...current.volumes], - processIds: [...(previous?.processIds ?? []), ...current.processIds], - }); -} - export class SshJetsonDispatchWorker implements JetsonDispatchWorker { readonly #config: SshJetsonWorkerConfig; readonly #runProcess: typeof runProcess; @@ -739,20 +728,22 @@ export class SshJetsonDispatchWorker implements JetsonDispatchWorker { } async cleanup(options: { jobId: string; signal: AbortSignal }): Promise { - let serializedEvidence: string; - try { - const cleanupResult = await this.#runProcess({ - executable: this.#config.cleanupExecutable, - args: [], - signal: options.signal, - }); - serializedEvidence = this.#recordCleanupEvidence(options.jobId, cleanupResult.stdout); - } catch (error) { - if (error instanceof ProcessFailure && error.result.stdout.includes(CLEANUP_EVIDENCE_BEGIN)) { - this.#recordCleanupEvidence(options.jobId, error.result.stdout); - } - throw error; + const cleanupResult = await this.#runProcess({ + executable: this.#config.cleanupExecutable, + args: [], + signal: options.signal, + }); + const reportedEvidence = parseCleanupCommandEvidence(cleanupResult.stdout); + const evidencePath = this.#cleanupEvidencePath(options.jobId); + const persistedRaw = readPrivateRegularFile(evidencePath, { + maxBytes: MAX_CLEANUP_EVIDENCE_BYTES, + }); + if (persistedRaw === null) throw new Error("Jetson cleanup evidence is missing"); + const persistedEvidence = parseCleanupEvidenceJson(persistedRaw); + if (JSON.stringify(reportedEvidence) !== JSON.stringify(persistedEvidence)) { + throw new Error("Jetson cleanup output differs from its durable resource evidence"); } + const serializedEvidence = `${JSON.stringify(persistedEvidence)}\n`; const expectedRaw = readPrivateRegularFile(this.#baselinePath(options.jobId), { allowMissing: true, maxBytes: MAX_BASELINE_BYTES, @@ -779,25 +770,6 @@ export class SshJetsonDispatchWorker implements JetsonDispatchWorker { } } - #recordCleanupEvidence(jobId: string, output: string): string { - const currentEvidence = parseCleanupCommandEvidence(output); - const evidencePath = this.#cleanupEvidencePath(jobId); - const previousRaw = readPrivateRegularFile(evidencePath, { - allowMissing: true, - maxBytes: MAX_CLEANUP_EVIDENCE_BYTES, - }); - const evidence = mergeCleanupEvidence( - previousRaw === null ? undefined : parseCleanupEvidenceJson(previousRaw), - currentEvidence, - ); - const serializedEvidence = `${JSON.stringify(evidence)}\n`; - if (Buffer.byteLength(serializedEvidence) > MAX_CLEANUP_EVIDENCE_BYTES) { - throw new Error("Jetson cleanup evidence is too large"); - } - writePrivateRegularFile(evidencePath, serializedEvidence); - return serializedEvidence; - } - #baselinePath(jobId: string): string { if (!/^[a-f0-9]{64}$/u.test(jobId)) throw new Error("Jetson job ID is invalid"); return path.join(this.#config.stateDirectory, `${jobId}.baseline.json`); From 2b3eff1dc5cd9c503ceae6ff75755762e6856bf9 Mon Sep 17 00:00:00 2001 From: San Dang Date: Mon, 10 Aug 2026 23:51:10 +0700 Subject: [PATCH 15/34] fix(e2e): isolate Jetson OpenShell lifecycle Signed-off-by: San Dang --- .github/workflows/e2e.yaml | 11 +- test/e2e/docs/jetson-colossus-dispatch.md | 228 +++++++++++++++--- test/e2e/live/jetson-nvmap-gpu.test.ts | 24 +- .../e2e-operations-workflow-boundary.test.ts | 21 +- .../support/jetson-dispatch-contract.test.ts | 16 ++ .../support/jetson-dispatch-worker.test.ts | 80 +++++- .../support/jetson-workflow-boundary.test.ts | 16 ++ tools/e2e/jetson-dispatch-cleanup.sh | 103 +++++++- tools/e2e/jetson-dispatch-lifecycle.mts | 4 +- tools/e2e/jetson-dispatch-worker.mts | 59 ++++- tools/e2e/operations-workflow-boundary.mts | 3 +- 11 files changed, 484 insertions(+), 81 deletions(-) diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index ab5ecec9ceb..68670923821 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -224,6 +224,7 @@ jobs: if: ${{ inputs.checkout_sha != '' }} env: ACTOR: ${{ github.actor }} + ALLOW_JETSON_DISPATCH: ${{ inputs.allow_jetson_dispatch && 'true' || 'false' }} BASE_SHA: ${{ inputs.base_sha }} CHECKOUT_REPOSITORY: ${{ inputs.checkout_repository }} CHECKOUT_SHA: ${{ inputs.checkout_sha }} @@ -268,10 +269,10 @@ jobs: exit 1 } [[ "$RUN_ATTEMPT" == "1" ]] || { echo "::error::Manual PR E2E cannot be rerun" >&2; exit 1; } - case "${JOBS}:${TARGETS}:${INCLUDE_LAUNCHABLE}" in - ::false | managed-image-protected-runtime::false) ;; + case "${JOBS}:${TARGETS}:${INCLUDE_LAUNCHABLE}:${ALLOW_JETSON_DISPATCH}" in + ::false:false | managed-image-protected-runtime::false:false | :jetson-nvmap-gpu:false:true) ;; *) - echo "::error::Manual PR E2E accepts only empty selectors or managed-image-protected-runtime without target or Launchable selectors" >&2 + echo "::error::Manual PR E2E accepts only empty selectors, managed-image-protected-runtime, or jetson-nvmap-gpu with its dispatch flag" >&2 exit 1 ;; esac @@ -286,7 +287,7 @@ jobs: require_maintainer "$ACTOR" - if [[ "${TRIGGERING_ACTOR,,}" != "${ACTOR,,}" ]]; then + if [[ "$(printf '%s' "$TRIGGERING_ACTOR" | tr '[:upper:]' '[:lower:]')" != "$(printf '%s' "$ACTOR" | tr '[:upper:]' '[:lower:]')" ]]; then require_maintainer "$TRIGGERING_ACTOR" fi @@ -403,7 +404,7 @@ jobs: } require_maintainer "$ACTOR" - if [[ "${TRIGGERING_ACTOR,,}" != "${ACTOR,,}" ]]; then + if [[ "$(printf '%s' "$TRIGGERING_ACTOR" | tr '[:upper:]' '[:lower:]')" != "$(printf '%s' "$ACTOR" | tr '[:upper:]' '[:lower:]')" ]]; then require_maintainer "$TRIGGERING_ACTOR" fi diff --git a/test/e2e/docs/jetson-colossus-dispatch.md b/test/e2e/docs/jetson-colossus-dispatch.md index 6975dc4a146..308fa3fefb3 100644 --- a/test/e2e/docs/jetson-colossus-dispatch.md +++ b/test/e2e/docs/jetson-colossus-dispatch.md @@ -60,8 +60,19 @@ git --version npm --version npm_version="$(npm --version)" test "${npm_version%%.*}" -ge 10 -command -v bash curl docker git node npm ollama openshell timeout -openshell --version +command -v bash curl docker git node npm ollama timeout +for openshell_component in openshell openshell-gateway openshell-sandbox; do + if command -v "$openshell_component" >/dev/null 2>&1; then + echo 'OpenShell must be absent from the prepared Jetson' >&2 + exit 1 + fi + for host_bin in \ + "/usr/local/bin/$openshell_component" \ + "/usr/bin/$openshell_component" \ + "$HOME/.local/bin/$openshell_component"; do + test ! -e "$host_bin" && test ! -L "$host_bin" + done +done ollama list docker info --format '{{json .Runtimes}}' test -c /dev/nvmap @@ -70,13 +81,31 @@ if sudo -n true 2>/dev/null; then echo 'unexpected passwordless sudo'; exit 1; f The architecture must be `aarch64`. Node.js must be version 22.19.0 or later, and npm must have major version 10 or later. -The OpenShell version command and `ollama list` must both succeed. +OpenShell must be absent from the host `PATH` and the three checked host binary directories. +Do not preinstall OpenShell on the Jetson. +The `ollama list` command must succeed. Docker must expose the NVIDIA runtime required by the existing Jetson live E2E test. Preinstall Ollama so candidate code does not invoke its host installer. The `nvidia` account must not have passwordless `sudo` access. -The worker gives each job its own `HOME`, `TMPDIR`, XDG directories, and npm prefix under the job workspace. -The test installs the NemoClaw CLI and its state only in those job-owned paths, so workspace removal removes them without a host-wide uninstall. -If a later reviewed cleanup path requires the NemoClaw uninstaller, it must use `--keep-openshell` and must retain the same resource allowlist. + +The worker creates `/var/tmp/nemoclaw-jetson-e2e/` and sets these job-local paths: + +- `HOME=/home` +- `TMPDIR=/tmp` +- `XDG_CACHE_HOME=/home/.cache` +- `XDG_CONFIG_HOME=/home/.config` +- `XDG_DATA_HOME=/home/.local/share` +- `XDG_STATE_HOME=/home/.local/state` +- `XDG_BIN_HOME=/home/.local/bin` +- `npm_config_prefix=/npm-prefix` +- `PATH=$XDG_BIN_HOME:/npm-prefix/bin:$PATH` + +The worker must not set `NEMOCLAW_DEFER_OPENSHELL_INSTALL`. +It must not invoke `scripts/install-openshell.sh`. +The existing live E2E runs `bash install.sh --non-interactive`. +NemoClaw onboarding owns the compatible pinned OpenShell installation in the job workspace. +After onboarding, `nemoclaw`, `openshell`, `openshell-gateway`, and `openshell-sandbox` must resolve canonically inside the job workspace. +The worker rejects a symbolic link or resolved path that leaves that workspace. Reserve these names and paths for this E2E target: @@ -88,6 +117,7 @@ Reserve these names and paths for this E2E target: - OpenShell-managed Docker containers labeled for `e2e-jetson-nvmap`. - The volumes recorded from those labeled containers. - The `openshell-cluster-nemoclaw` gateway container, volume, and recorded attached volumes. +- `nemoclaw-sandbox-local` images whose tag begins with `e2e-jetson-nvmap-`. Do not run unrelated work under these reserved names. The cleanup program must act only on this allowlist. @@ -97,7 +127,7 @@ Before candidate execution, the worker records this protected tool and model bas - The resolved Node.js path and version. - The resolved npm path and version. - The resolved Ollama path and a SHA-256 digest of the sorted Ollama model names and IDs. -- The resolved OpenShell path. +- The required absence of host-level `openshell`, `openshell-gateway`, and `openshell-sandbox` binaries. The dispatcher stores the recorded values in a private `.baseline.json` state file. After cleanup, the worker repeats the probes and compares them with that record. @@ -109,13 +139,13 @@ If the initial baseline probe fails, the worker never invokes candidate code; cl These other host resources also remain outside the cleanup allowlist: -- Node.js, npm, the OpenShell executable, and the Docker engine. +- Node.js, npm, and the Docker engine. - The Ollama binary, service, models, configuration, and unrelated `ollama serve` processes. - The NVIDIA container runtime and Docker images that the test does not own exclusively. - The `/dev/nvmap` character device and its permissions. - JetPack, Jetson Linux, CUDA, NVIDIA packages, other `apt` packages, SDK Manager, and downloaded flashing files. - User accounts, SSH keys, and user files outside the current job workspace and named NemoClaw resources. -- Docker resources without the exact label or name association defined above. +- Docker resources without the exact label, repository tag, or name association defined above. - Processes other than the recorded job-home helper processes defined above. - Colossus credentials, service configuration, and job evidence. @@ -207,23 +237,17 @@ Changing one of those values requires a corresponding reviewed source change. The dispatcher invokes it after success, failure, cancellation, and timeout. The dispatcher also invokes it during startup when `device.lock` remains from an interrupted service process. -The cleanup program uses these phases in order: - -1. Run read-only discovery over pinned-host-key SSH and validate every discovered volume and process identity. -2. Strictly parse and merge those identities with the existing private cleanup record on Colossus. -3. Persist the merged record before starting destructive cleanup over pinned-host-key SSH. - -For durable persistence, the helper writes a mode-`0600` temporary file in the state directory. -It fsyncs the file, atomically renames it to `.cleanup.json`, and fsyncs the state directory. -If discovery, validation, or durable persistence fails, the helper does not start destructive cleanup. +Before destructive cleanup, the program discovers and validates the job-owned Docker volume and process identities. +It merges them into a mode-`0600` private `.cleanup.json` record on Colossus. +The record survives retries so stale-lock recovery can clean and verify the same identities. The destructive phase must perform these bounded actions: -1. Stop and remove only the named sandbox, its forwards, and the named gateway. +1. Use only the canonical job-local OpenShell installation to stop the named forwards, sandbox, and gateway. 2. Stop only the recorded helper PIDs after verifying the process owner, command marker, and job `HOME`. -3. Remove only the labeled sandbox containers, the exact gateway container, and their recorded volumes. +3. Remove only the labeled sandbox containers, exact gateway container, recorded volumes, and reserved test image tags. 4. Remove only the helper-service directory and `/var/tmp/nemoclaw-jetson-e2e/` workspace for the locked job. -5. Verify that every allowlisted resource is absent. +5. After workspace removal, verify that the allowlisted resources are absent, host OpenShell remains absent, and the host baseline matches. The cleanup program must be idempotent. It must treat an already absent allowlisted resource as success. @@ -231,7 +255,7 @@ It must exit nonzero when target ownership is ambiguous, cleanup fails, or absen It must not remove `/var/lib/nemoclaw-jetson-dispatch/state/device.lock`. The dispatcher removes that lock only after cleanup and absence verification succeed. -The durable cleanup record uses this path: +The private cleanup record uses this path: ```text /var/lib/nemoclaw-jetson-dispatch/state/.cleanup.json @@ -248,11 +272,7 @@ The file has this exact schema: ``` Either identity array can be empty. -The helper merges new identities with the existing record instead of replacing earlier identities. -The destructive phase receives this merged record and acts on every recorded identity. -After destructive cleanup succeeds, the helper emits one bounded evidence block for the merged record. -The worker reads and revalidates that successful output against the durable record before independent verification. -Failure durability belongs to the helper's pre-cleanup record, not to worker parsing of failed process output. +The helper merges new identities with the existing record and cleans every recorded identity. Any helper failure or interruption keeps the device lock for startup recovery. The dispatcher retains the cleanup record after it removes the device lock. @@ -261,8 +281,10 @@ After the helper succeeds, the worker independently verifies these conditions ov - The validated job workspace is absent and is not a symbolic link. - No OpenShell-managed container has the `e2e-jetson-nvmap` sandbox label. - The `openshell-cluster-nemoclaw` gateway container and volume are absent. +- No `nemoclaw-sandbox-local` image has a tag that begins with `e2e-jetson-nvmap-`. - Every Docker volume and process ID in the merged cleanup record is absent. -- Every recorded Node.js, npm, Ollama, Ollama model, and OpenShell baseline value matches. +- Every recorded Node.js, npm, Ollama, and Ollama model baseline value matches. +- No host-level `openshell`, `openshell-gateway`, or `openshell-sandbox` binary resolves or exists in a checked host binary path. - `/dev/nvmap` exists, and Docker still reports the NVIDIA runtime. The worker reports cleanup failure when any helper or independent verification step fails. @@ -461,7 +483,25 @@ gh variable set JETSON_DISPATCH_URL --repo NVIDIA/NemoClaw \ --body 'https://jetson-e2e.example.com' ``` -First select only the Jetson target from the trusted `main` workflow: +Resolve the non-fork pull request (PR) and trusted workflow identities. +Replace `1234` with the PR number: + +```bash +set -euo pipefail +PR_NUMBER=1234 +PR_JSON="$(gh api "repos/NVIDIA/NemoClaw/pulls/$PR_NUMBER")" +CANDIDATE_REPOSITORY="$(jq -r .head.repo.full_name <<<"$PR_JSON")" +CANDIDATE_SHA="$(jq -r .head.sha <<<"$PR_JSON")" +BASE_SHA="$(jq -r .base.sha <<<"$PR_JSON")" +git fetch --prune origin main +WORKFLOW_SHA="$(git rev-parse origin/main)" +test "$CANDIDATE_REPOSITORY" = NVIDIA/NemoClaw +[[ "$CANDIDATE_SHA" =~ ^[a-f0-9]{40}$ ]] +[[ "$BASE_SHA" =~ ^[a-f0-9]{40}$ ]] +[[ "$WORKFLOW_SHA" =~ ^[a-f0-9]{40}$ ]] +``` + +Select only the Jetson target from the trusted `main` workflow: ```bash gh workflow run .github/workflows/e2e.yaml --repo NVIDIA/NemoClaw --ref main \ @@ -470,7 +510,13 @@ gh workflow run .github/workflows/e2e.yaml --repo NVIDIA/NemoClaw --ref main \ -f inference_mode=mock \ -f include_staging_brev_launchable=false \ -f allow_jetson_dispatch=true \ - -f allow_dgx_spark_runner_queue=false + -f allow_dgx_spark_runner_queue=false \ + -f "pr_number=$PR_NUMBER" \ + -f "checkout_sha=$CANDIDATE_SHA" \ + -f "checkout_repository=$CANDIDATE_REPOSITORY" \ + -f "base_sha=$BASE_SHA" \ + -f "workflow_sha=$WORKFLOW_SHA" \ + -f review_reason='Reviewed this PR commit for the isolated Jetson E2E.' ``` The controller must run on `ubuntu-latest`. @@ -478,11 +524,67 @@ The GitHub controller log must show one `Jetson dispatch accepted as ` li The Colossus journal must not contain a bearer token. The uploaded `e2e-jetson-nvmap-gpu` artifact must contain `jetson-dispatch.json` with these results: -- The requested candidate commit SHA and workflow run identity. +- The requested candidate commit SHA and workflow run ID and attempt. - The Jetson model, JetPack package version or `unavailable`, Jetson Linux release, and kernel. - The test conclusion and bounded log. -- `cleanup: "succeeded"`. -- `conclusion: "success"` for the successful proof job. +- `status.cleanup: "succeeded"`. +- `status.conclusion: "success"` for the successful proof job. + +Download the trusted `e2e-dispatch--` receipt artifact and the `e2e-jetson-nvmap-gpu` artifact. +Set `RUN_ID` and `RUN_ATTEMPT` from the selected workflow run: + +```bash +EVIDENCE_DIR="$(mktemp -d)" +chmod 700 "$EVIDENCE_DIR" +RUN_ID=123456789 +RUN_ATTEMPT=1 +gh run download "$RUN_ID" --repo NVIDIA/NemoClaw \ + --name "e2e-dispatch-$RUN_ID-$RUN_ATTEMPT" \ + --dir "$EVIDENCE_DIR/trusted-dispatch" +gh run download "$RUN_ID" --repo NVIDIA/NemoClaw \ + --name e2e-jetson-nvmap-gpu \ + --dir "$EVIDENCE_DIR/jetson" +DISPATCH_JSON="$EVIDENCE_DIR/trusted-dispatch/dispatch.json" +JETSON_JSON="$EVIDENCE_DIR/jetson/jetson-dispatch.json" +``` + +Require `dispatch.json` to establish the repository, PR number, base SHA, candidate SHA, and trusted workflow SHA independently: + +```bash +jq -e \ + --arg repository NVIDIA/NemoClaw \ + --arg candidateRepository "$CANDIDATE_REPOSITORY" \ + --arg candidateSha "$CANDIDATE_SHA" \ + --arg baseSha "$BASE_SHA" \ + --arg workflowSha "$WORKFLOW_SHA" \ + --arg workflowRunId "$RUN_ID" \ + --argjson prNumber "$PR_NUMBER" \ + --argjson workflowRunAttempt "$RUN_ATTEMPT" ' + .kind == "nemoclaw-e2e-dispatch-v2" and + .repository == $repository and + .candidateRepository == $candidateRepository and + .candidateRepository == .repository and + .candidateSha == $candidateSha and + .prNumber == $prNumber and + .baseSha == $baseSha and + .workflowSha == $workflowSha and + .workflowRunId == $workflowRunId and + .workflowRunAttempt == $workflowRunAttempt and + .allowJetsonDispatch == true + ' "$DISPATCH_JSON" +``` + +Then bind `jetson-dispatch.json` to that trusted receipt by comparing its candidate SHA and workflow run ID and attempt: + +```bash +jq -e --slurpfile dispatch "$DISPATCH_JSON" ' + .status.request.candidateSha == $dispatch[0].candidateSha and + .status.request.workflowRunId == $dispatch[0].workflowRunId and + .status.request.workflowRunAttempt == $dispatch[0].workflowRunAttempt and + .status.cleanup == "succeeded" and + .status.conclusion == "success" +' "$JETSON_JSON" +``` It must also contain `jetson-e2e-artifacts.tar.gz`. The dispatcher creates that archive from the remote E2E artifact directory before it removes the candidate workspace. @@ -493,7 +595,7 @@ After the workflow completes, independently verify every allowlisted resource is Require the private `.cleanup.json` file and verify every recorded volume and process ID is absent. The private cleanup record is Colossus state and is not part of the uploaded artifact. Then run one controlled failing candidate. -Confirm that its `jetson-dispatch.json` artifact shows `cleanup: "succeeded"` and `conclusion: "failure"`. +Confirm that its `jetson-dispatch.json` artifact shows `status.cleanup: "succeeded"` and `status.conclusion: "failure"`. Require its private cleanup record and verify every recorded identity is absent. For a cancellation proof, cancel a controller after it logs the job ID. The controller can exit before it downloads an artifact. @@ -684,8 +786,23 @@ for proc_dir in /proc/[0-9]*; do ;; esac done -command -v node npm ollama openshell +test -z "$(docker image ls --format '{{.Repository}}\t{{.Tag}}' | + awk '$1 == "nemoclaw-sandbox-local" && index($2, "e2e-jetson-nvmap-") == 1 { print $1 ":" $2 }')" +command -v node npm ollama ollama list >/dev/null +for openshell_component in openshell openshell-gateway openshell-sandbox; do + if command -v "$openshell_component" >/dev/null 2>&1; then + echo "A host-level OpenShell binary remains after cleanup: $openshell_component" >&2 + exit 1 + fi + for host_bin in \ + "/usr/local/bin/$openshell_component" \ + "/usr/bin/$openshell_component" \ + "$HOME/.local/bin/$openshell_component"; do + test ! -e "$host_bin" + test ! -L "$host_bin" + done +done test -c /dev/nvmap case "$(docker info --format '{{json .Runtimes}}')" in *nvidia*) ;; @@ -734,5 +851,46 @@ test -z "$(gh variable list --repo NVIDIA/NemoClaw --json name \ ``` Remove the dedicated Jetson public key and the Colossus SSH private key. +Encode the exact authorized-key line so the space-containing value remains one remote-command argument, then verify that exact line is absent before deleting the Colossus key: + +```bash +JETSON_PUBLIC_KEY="$(sudo cat /var/lib/nemoclaw-jetson-dispatch/id_ed25519.pub)" +case "$JETSON_PUBLIC_KEY" in + ssh-ed25519\ *) ;; + *) echo 'Unexpected Jetson public key format' >&2; exit 1 ;; +esac +JETSON_AUTHORIZED_KEY_LINE="from=\"192.168.55.100\",restrict $JETSON_PUBLIC_KEY" +JETSON_AUTHORIZED_KEY_B64="$(printf '%s' "$JETSON_AUTHORIZED_KEY_LINE" | base64 --wrap=0)" +sudo -u nemoclaw-jetson-dispatch ssh -F /dev/null -T \ + -o BatchMode=yes -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes \ + -o UserKnownHostsFile=/var/lib/nemoclaw-jetson-dispatch/known_hosts \ + -i /var/lib/nemoclaw-jetson-dispatch/id_ed25519 \ + nvidia@192.168.55.1 bash -s -- "$JETSON_AUTHORIZED_KEY_B64" <<'REMOVE_DISPATCH_KEY' +set -euo pipefail +authorized_key_line="$(printf '%s' "$1" | base64 --decode)" +authorized_keys="$HOME/.ssh/authorized_keys" +test -f "$authorized_keys" +temporary="$(mktemp "$HOME/.ssh/.authorized_keys.XXXXXX")" +trap 'rm -f "$temporary"' EXIT +chmod 600 "$temporary" +while IFS= read -r line || [ -n "$line" ]; do + if [ "$line" != "$authorized_key_line" ]; then + printf '%s\n' "$line" + fi +done <"$authorized_keys" >"$temporary" +mv "$temporary" "$authorized_keys" +trap - EXIT +if grep -Fqx -- "$authorized_key_line" "$authorized_keys"; then + echo 'Dedicated Jetson public key remains authorized' >&2 + exit 1 +fi +REMOVE_DISPATCH_KEY +sudo rm -- \ + /var/lib/nemoclaw-jetson-dispatch/id_ed25519 \ + /var/lib/nemoclaw-jetson-dispatch/id_ed25519.pub +sudo test ! -e /var/lib/nemoclaw-jetson-dispatch/id_ed25519 +sudo test ! -e /var/lib/nemoclaw-jetson-dispatch/id_ed25519.pub +``` + After the required retention period, remove the private job state and logs. Remove the dispatcher environment, service unit, and trusted checkout when no investigation, recovery, or retention requirement remains. diff --git a/test/e2e/live/jetson-nvmap-gpu.test.ts b/test/e2e/live/jetson-nvmap-gpu.test.ts index 6e0c72e06f6..b632b0818c2 100644 --- a/test/e2e/live/jetson-nvmap-gpu.test.ts +++ b/test/e2e/live/jetson-nvmap-gpu.test.ts @@ -21,14 +21,19 @@ const TIMEOUT_MS = 50 * 60_000; function env(extra: NodeJS.ProcessEnv = {}): NodeJS.ProcessEnv { return { ...buildAvailabilityProbeEnv(), - NEMOCLAW_DEFER_OPENSHELL_INSTALL: process.env.NEMOCLAW_DEFER_OPENSHELL_INSTALL, + HOME: process.env.HOME, NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE: "1", + NEMOCLAW_JETSON_WORKSPACE: process.env.NEMOCLAW_JETSON_WORKSPACE, NEMOCLAW_NON_INTERACTIVE: "1", NEMOCLAW_PROVIDER: process.env.NEMOCLAW_PROVIDER ?? "ollama", NEMOCLAW_RECREATE_SANDBOX: "1", NEMOCLAW_SANDBOX_NAME: SANDBOX_NAME, OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY ?? "nemoclaw", + PATH: process.env.PATH, + TMPDIR: process.env.TMPDIR, + XDG_BIN_HOME: process.env.XDG_BIN_HOME, XDG_CACHE_HOME: process.env.XDG_CACHE_HOME, + XDG_CONFIG_HOME: process.env.XDG_CONFIG_HOME, XDG_DATA_HOME: process.env.XDG_DATA_HOME, XDG_STATE_HOME: process.env.XDG_STATE_HOME, npm_config_prefix: process.env.npm_config_prefix, @@ -229,6 +234,23 @@ fi`, expect(installedCli.exitCode, resultText(installedCli)).toBe(0); expect(installedCli.stdout.trim()).not.toBe(""); + const installedBinaries = await hostShell( + host, + String.raw`set -euo pipefail +[ -n "$NEMOCLAW_JETSON_WORKSPACE" ] +for installed_command in nemoclaw openshell openshell-gateway openshell-sandbox; do + installed_path="$(command -v "$installed_command")" + canonical_path="$(realpath -e "$installed_path")" + case "$canonical_path" in + "$NEMOCLAW_JETSON_WORKSPACE"/*) printf '%s\t%s\n' "$installed_command" "$canonical_path" ;; + *) echo "$installed_command resolved outside the Jetson job workspace" >&2; exit 1 ;; + esac +done`, + "phase-2-job-local-installation", + ); + expect(installedBinaries.exitCode, resultText(installedBinaries)).toBe(0); + expect(installedBinaries.stdout.trim().split("\n")).toHaveLength(4); + // A4: the Jetson recreate must grant Tegra device-node groups via --group-add. expect(resultText(install)).toContain( "Granting sandbox user the detected Jetson GPU device groups via --group-add", diff --git a/test/e2e/support/e2e-operations-workflow-boundary.test.ts b/test/e2e/support/e2e-operations-workflow-boundary.test.ts index e8963656586..385d09fc3b5 100644 --- a/test/e2e/support/e2e-operations-workflow-boundary.test.ts +++ b/test/e2e/support/e2e-operations-workflow-boundary.test.ts @@ -228,27 +228,29 @@ const interpolatedNeeds = \${{ toJSON ( needs ) }}; ); }); - it("limits manual PR runs to empty selectors or protected managed-runtime qualification", () => { + it("limits manual PR runs to empty selectors, protected managed-runtime qualification, or Jetson dispatch", () => { const workflow = readE2eOperationsWorkflow(); const authentication = workflow.jobs["generate-matrix"].steps!.find( (step) => step.name === "Authenticate manual PR dispatch", )!; authentication.run = authentication.run!.replace( - "Manual PR E2E accepts only empty selectors or managed-image-protected-runtime", + "Manual PR E2E accepts only empty selectors, managed-image-protected-runtime, or jetson-nvmap-gpu with its dispatch flag", "Manual PR E2E accepts arbitrary selectors", ); expect(validateE2eOperationsWorkflow(workflow)).toContain( - "Manual PR authentication must retain Manual PR E2E accepts only empty selectors or managed-image-protected-runtime", + "Manual PR authentication must retain Manual PR E2E accepts only empty selectors, managed-image-protected-runtime, or jetson-nvmap-gpu with its dispatch flag", ); }); it.each([ - ["maintain", "", 0, ""], - ["maintain", "managed-image-protected-runtime", 0, ""], - ["maintain", "gpu-e2e", 1, "accepts only empty selectors or managed-image-protected-runtime"], - ["write", "", 1, "requires a repository maintainer or administrator"], - ])("requires a maintainer role and bounded selector before manual PR E2E for %s with %s", (role, jobs, expectedStatus, expectedStderr) => { + ["maintain", "", "", "false", 0, ""], + ["maintain", "managed-image-protected-runtime", "", "false", 0, ""], + ["maintain", "", "jetson-nvmap-gpu", "true", 0, ""], + ["maintain", "", "jetson-nvmap-gpu", "false", 1, "accepts only empty selectors"], + ["maintain", "gpu-e2e", "", "false", 1, "accepts only empty selectors"], + ["write", "", "", "false", 1, "requires a repository maintainer or administrator"], + ])("requires a maintainer role and bounded selector before manual PR E2E for %s with jobs %s and targets %s", (role, jobs, targets, allowJetsonDispatch, expectedStatus, expectedStderr) => { const workflow = readE2eOperationsWorkflow(); const authentication = workflow.jobs["generate-matrix"].steps!.find( (step) => step.name === "Authenticate manual PR dispatch", @@ -273,6 +275,7 @@ const interpolatedNeeds = \${{ toJSON ( needs ) }}; env: { ...process.env, ACTOR: "maintainer", + ALLOW_JETSON_DISPATCH: allowJetsonDispatch, BASE_SHA: baseSha, CHECKOUT_REPOSITORY: "contributor/NemoClaw", CHECKOUT_SHA: headSha, @@ -284,7 +287,7 @@ const interpolatedNeeds = \${{ toJSON ( needs ) }}; PR_NUMBER: "42", REVIEW_REASON: "Reviewed PR head revision", RUN_ATTEMPT: "1", - TARGETS: "", + TARGETS: targets, TRIGGERING_ACTOR: "maintainer", WORKFLOW_EVENT: "workflow_dispatch", WORKFLOW_REF: "refs/heads/main", diff --git a/test/e2e/support/jetson-dispatch-contract.test.ts b/test/e2e/support/jetson-dispatch-contract.test.ts index 0e6fc998bf4..4cb2da35866 100644 --- a/test/e2e/support/jetson-dispatch-contract.test.ts +++ b/test/e2e/support/jetson-dispatch-contract.test.ts @@ -551,6 +551,22 @@ describe("Jetson single-device lifecycle", () => { expect(cleanup).not.toHaveBeenCalled(); expect(fs.existsSync(path.join(stateDirectory, "device.lock"))).toBe(true); }); + + it.each([ + `${"d".repeat(64)}\nextra\n`, + `${"d".repeat(64)}\n\n`, + ])("rejects trailing data in a stale device lock (#8142)", async (lockContents) => { + const stateDirectory = temporaryDirectory(); + fs.writeFileSync(path.join(stateDirectory, "device.lock"), lockContents, { mode: 0o600 }); + const cleanup = vi.fn(async () => {}); + const dispatch = coordinator(stateDirectory, worker({ cleanup })); + + await expect(dispatch.initialize()).rejects.toThrow( + "Jetson device lock contains an invalid job ID", + ); + expect(cleanup).not.toHaveBeenCalled(); + expect(fs.existsSync(path.join(stateDirectory, "device.lock"))).toBe(true); + }); }); describe("Jetson dispatch HTTP boundary", () => { diff --git a/test/e2e/support/jetson-dispatch-worker.test.ts b/test/e2e/support/jetson-dispatch-worker.test.ts index 5bd46b57fe4..69897514026 100644 --- a/test/e2e/support/jetson-dispatch-worker.test.ts +++ b/test/e2e/support/jetson-dispatch-worker.test.ts @@ -21,6 +21,14 @@ const cleanupProgram = fs.readFileSync( path.join(process.cwd(), "tools/e2e/jetson-dispatch-cleanup.sh"), "utf8", ); +const workerProgram = fs.readFileSync( + path.join(process.cwd(), "tools/e2e/jetson-dispatch-worker.mts"), + "utf8", +); +const jetsonLiveTest = fs.readFileSync( + path.join(process.cwd(), "test/e2e/live/jetson-nvmap-gpu.test.ts"), + "utf8", +); const temporaryDirectories: string[] = []; const BASELINE = { nodePath: "/usr/bin/node", @@ -29,7 +37,7 @@ const BASELINE = { npmVersion: "10.9.3", ollamaPath: "/usr/local/bin/ollama", ollamaModelsSha256: "a".repeat(64), - openshellPath: "/usr/local/bin/openshell", + openshellState: "absent", }; function baselineOutput(overrides: Partial = {}): string { @@ -369,7 +377,6 @@ describe("Colossus SSH worker deployment boundary", () => { ["npm", { npmVersion: "11.0.0" }], ["Ollama executable", { ollamaPath: "/tmp/ollama" }], ["Ollama models", { ollamaModelsSha256: "c".repeat(64) }], - ["OpenShell executable", { openshellPath: "/tmp/openshell" }], ])("rejects cleanup when the protected %s baseline changes (#8142)", async (_name, change) => { const files = deploymentFiles(); const jobId = "b".repeat(64); @@ -388,6 +395,26 @@ describe("Colossus SSH worker deployment boundary", () => { expect(fs.existsSync(baselinePath)).toBe(true); }); + it("rejects cleanup unless OpenShell returns to the absent baseline (#8142)", async () => { + const files = deploymentFiles(); + const jobId = "b".repeat(64); + fs.writeFileSync( + path.join(files.stateDirectory, `${jobId}.baseline.json`), + `${JSON.stringify(BASELINE)}\n`, + { mode: 0o600 }, + ); + persistCleanupEvidence(files, jobId, { schemaVersion: 1, volumes: [], processIds: [] }); + const processRunner = vi + .fn() + .mockResolvedValueOnce({ stdout: cleanupOutput(), stderr: "" }) + .mockResolvedValueOnce({ stdout: baselineOutput({ openshellState: "present" }), stderr: "" }); + const worker = new SshJetsonDispatchWorker(loadConfig(files), processRunner); + + await expect(worker.cleanup({ jobId, signal: new AbortController().signal })).rejects.toThrow( + "Jetson protected-baseline OpenShell state is malformed", + ); + }); + it("retains every validated cleanup identity across stale-lock recovery (#8142)", async () => { const files = deploymentFiles(); const jobId = "b".repeat(64); @@ -522,6 +549,18 @@ describe("Colossus SSH worker deployment boundary", () => { expect(processRunner).toHaveBeenCalledTimes(1); }); + it("reports a missing durable cleanup record after valid helper output (#8142)", async () => { + const files = deploymentFiles(); + const worker = new SshJetsonDispatchWorker( + loadConfig(files), + vi.fn().mockResolvedValueOnce({ stdout: cleanupOutput(), stderr: "" }), + ); + + await expect( + worker.cleanup({ jobId: "b".repeat(64), signal: new AbortController().signal }), + ).rejects.toThrow("Jetson cleanup evidence is missing"); + }); + it("keeps cleanup targets fixed and preserves the Jetson baseline (#8142)", () => { const fileFsync = cleanupProgram.indexOf("fs.fsyncSync(descriptor)"); const atomicRename = cleanupProgram.indexOf("fs.renameSync(temporaryFile, cleanupFile)"); @@ -531,7 +570,8 @@ describe("Colossus SSH worker deployment boundary", () => { expect(cleanupProgram).toContain("gateway_name=nemoclaw"); expect(cleanupProgram).toContain("destination=nvidia@192.168.55.1"); expect(cleanupProgram).toContain('if [ "$#" -ne 0 ]'); - expect(cleanupProgram).toContain('IFS= read -r job_id <"$lock_file"'); + expect(cleanupProgram).toContain('mapfile -t lock_lines <"$lock_file"'); + expect(cleanupProgram).toContain('[ "${#lock_lines[@]}" -ne 1 ]'); expect(cleanupProgram).toContain('require_plain_directory_if_present "$service_directory"'); expect(cleanupProgram).toContain('rm -rf -- "$workspace"'); expect(cleanupProgram).toContain("ollama-auth-proxy.pid"); @@ -539,6 +579,14 @@ describe("Colossus SSH worker deployment boundary", () => { expect(cleanupProgram).toContain('grep -Fqx "HOME=$job_home"'); expect(cleanupProgram).toContain('kill "$pid"'); expect(cleanupProgram).toContain("label=openshell.ai/sandbox-name=$sandbox_name"); + expect(cleanupProgram).toContain("image_repository=nemoclaw-sandbox-local"); + expect(cleanupProgram).toContain('docker image rm "$image"'); + expect(cleanupProgram.indexOf('docker image rm "$image"')).toBeLessThan( + cleanupProgram.indexOf('rm -rf -- "$workspace"'), + ); + expect(cleanupProgram).toContain('"$job_home/.local/bin/openshell"'); + expect(cleanupProgram).toContain("Refusing an OpenShell binary outside the job workspace"); + expect(cleanupProgram).toContain("A host-level OpenShell binary remains after cleanup"); expect(cleanupProgram).toContain("nemoclaw-cleanup-evidence-v1-begin"); expect(cleanupProgram).toContain("nemoclaw-cleanup-evidence-v1-end"); expect(cleanupProgram.indexOf("nemoclaw-cleanup-evidence-v1-begin")).toBeLessThan( @@ -556,13 +604,31 @@ describe("Colossus SSH worker deployment boundary", () => { expect(cleanupProgram).not.toContain('rm -rf -- "$workspace_root"'); expect(cleanupProgram).not.toContain("ollama serve"); expect(cleanupProgram).not.toMatch(/apt(?:-get)?|boardctl|reboot|shutdown|nvidia-l4t/u); - expect(cleanupProgram).not.toMatch(/npm uninstall|uninstall\.sh|rm .*openshell|rm .*ollama/u); + expect(cleanupProgram).not.toMatch(/npm uninstall|uninstall\.sh|rm .*ollama/u); }); - it("requires every protected Jetson prerequisite before dispatch (#8142)", () => { - expect(dispatcherRunbook).toContain( - "command -v bash curl docker git node npm ollama openshell timeout", + it("keeps OpenShell installation owned by NemoClaw onboarding inside the job workspace (#8142)", () => { + expect(workerProgram).not.toContain("NEMOCLAW_DEFER_OPENSHELL_INSTALL"); + expect(jetsonLiveTest).not.toContain("NEMOCLAW_DEFER_OPENSHELL_INSTALL"); + expect(workerProgram).not.toContain("scripts/install-openshell.sh"); + expect(cleanupProgram).not.toContain("scripts/install-openshell.sh"); + expect(jetsonLiveTest).not.toContain("scripts/install-openshell.sh"); + expect(jetsonLiveTest).toContain('host.command("bash", ["install.sh", "--non-interactive"]'); + expect(workerProgram).toContain('export XDG_BIN_HOME="$workspace/home/.local/bin"'); + expect(workerProgram).toContain('export PATH="$XDG_BIN_HOME:$workspace/npm-prefix/bin:$PATH"'); + expect(workerProgram).toContain( + "for installed_command in nemoclaw openshell openshell-gateway openshell-sandbox", + ); + expect(jetsonLiveTest).toContain( + "for installed_command in nemoclaw openshell openshell-gateway openshell-sandbox", ); + expect(cleanupProgram.indexOf("job_openshell sandbox delete")).toBeLessThan( + cleanupProgram.indexOf('rm -rf -- "$workspace"'), + ); + }); + + it("requires every protected Jetson prerequisite before dispatch (#8142)", () => { + expect(dispatcherRunbook).toContain("OpenShell must be absent"); expect(dispatcherRunbook).toContain( "if (major < 22 || (major === 22 && minor < 19)) process.exit(1)", ); diff --git a/test/e2e/support/jetson-workflow-boundary.test.ts b/test/e2e/support/jetson-workflow-boundary.test.ts index b6f7d568f6d..e933288bdf7 100644 --- a/test/e2e/support/jetson-workflow-boundary.test.ts +++ b/test/e2e/support/jetson-workflow-boundary.test.ts @@ -77,6 +77,22 @@ describe("Jetson nvmap GPU E2E workflow boundary", () => { ); }); + it("rejects a direct OpenShell installer step in the Jetson controller (#8142)", () => { + const errors = validateWorkflowMutation((workflow) => { + const job = (workflow.jobs as Record)["jetson-nvmap-gpu"] as { + steps?: Array<{ name?: string; run?: string }>; + }; + job.steps!.push({ + name: "Install OpenShell directly", + run: "bash scripts/install-openshell.sh", + }); + }); + + expect(errors).toContain( + "jetson-nvmap-gpu controller must contain only checkout, Node setup, dispatch, and upload", + ); + }); + it("keeps the runner temporary artifact path on the dispatch step (#8142)", () => { const errors = validateWorkflowMutation((workflow) => { const job = (workflow.jobs as Record)["jetson-nvmap-gpu"] as { diff --git a/tools/e2e/jetson-dispatch-cleanup.sh b/tools/e2e/jetson-dispatch-cleanup.sh index 00c60bd4227..d5c09d275c6 100755 --- a/tools/e2e/jetson-dispatch-cleanup.sh +++ b/tools/e2e/jetson-dispatch-cleanup.sh @@ -15,7 +15,12 @@ identity_file=/var/lib/nemoclaw-jetson-dispatch/id_ed25519 known_hosts_file=/var/lib/nemoclaw-jetson-dispatch/known_hosts destination=nvidia@192.168.55.1 -IFS= read -r job_id <"$lock_file" +mapfile -t lock_lines <"$lock_file" +if [ "${#lock_lines[@]}" -ne 1 ]; then + echo "Jetson cleanup lock contains trailing data" >&2 + exit 1 +fi +job_id="${lock_lines[0]}" if ! [[ "$job_id" =~ ^[a-f0-9]{64}$ ]]; then echo "Jetson cleanup lock contains an invalid job ID" >&2 exit 1 @@ -47,6 +52,7 @@ job_home="$workspace/home" sandbox_name=e2e-jetson-nvmap gateway_container=openshell-cluster-nemoclaw gateway_volume=openshell-cluster-nemoclaw +image_repository=nemoclaw-sandbox-local service_directory="/tmp/nemoclaw-services-$sandbox_name" require_plain_directory_if_present() { @@ -102,6 +108,11 @@ for container in "${sandbox_containers[@]}"; do echo "Refusing an invalid recorded Docker container ID" >&2 exit 1 } + container_image="$(docker container inspect --format '{{.Config.Image}}' "$container")" + case "$container_image" in + "$image_repository:$sandbox_name-"*) ;; + *) echo "Refusing a sandbox container whose image is not test-owned" >&2; exit 1 ;; + esac record_container_volumes "$container" done if docker container inspect "$gateway_container" >/dev/null 2>&1; then @@ -243,6 +254,7 @@ job_home="$workspace/home" sandbox_name=e2e-jetson-nvmap gateway_name=nemoclaw gateway_container=openshell-cluster-nemoclaw +image_repository=nemoclaw-sandbox-local service_directory="/tmp/nemoclaw-services-$sandbox_name" require_plain_directory_if_present() { @@ -323,9 +335,39 @@ stop_recorded_pid() { exit 1 } +openshell_bin="" +openshell_install_complete=1 +for component in openshell openshell-gateway openshell-sandbox; do + component_path="$job_home/.local/bin/$component" + if [ -x "$component_path" ]; then + canonical_component="$(realpath -e "$component_path")" + case "$canonical_component" in + "$workspace"/*) ;; + *) echo "Refusing an OpenShell binary outside the job workspace" >&2; exit 1 ;; + esac + else + openshell_install_complete=0 + fi +done +if [ "$openshell_install_complete" -eq 1 ]; then + openshell_bin="$job_home/.local/bin/openshell" +fi + +job_openshell() { + HOME="$job_home" \ + TMPDIR="$workspace/tmp" \ + XDG_BIN_HOME="$job_home/.local/bin" \ + XDG_CACHE_HOME="$job_home/.cache" \ + XDG_CONFIG_HOME="$job_home/.config" \ + XDG_DATA_HOME="$job_home/.local/share" \ + XDG_STATE_HOME="$job_home/.local/state" \ + PATH="$job_home/.local/bin:$workspace/npm-prefix/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" \ + "$openshell_bin" "$@" +} + gateway_present=0 -if [ -d "$job_home" ]; then - gateway_json="$(HOME="$job_home" openshell gateway list -o json)" +if [ -n "$openshell_bin" ]; then + gateway_json="$(job_openshell gateway list -o json)" gateway_state="$(printf '%s' "$gateway_json" | node -e ' const fs = require("node:fs"); const rows = JSON.parse(fs.readFileSync(0, "utf8")); @@ -336,33 +378,33 @@ if [ -d "$job_home" ]; then fi if [ "$gateway_present" -eq 1 ]; then - forward_list="$(HOME="$job_home" openshell forward list --gateway "$gateway_name")" + forward_list="$(job_openshell forward list --gateway "$gateway_name")" while IFS= read -r port; do [ -n "$port" ] || continue [[ "$port" =~ ^[1-9][0-9]{0,4}$ ]] || exit 1 - HOME="$job_home" openshell forward stop "$port" "$sandbox_name" + job_openshell forward stop "$port" "$sandbox_name" done < <( printf '%s\n' "$forward_list" | awk -v sandbox="$sandbox_name" \ '$1 == sandbox && $3 ~ /^[0-9]+$/ { print $3 }' ) - sandbox_names="$(HOME="$job_home" openshell sandbox list --names -g "$gateway_name")" + sandbox_names="$(job_openshell sandbox list --names -g "$gateway_name")" if printf '%s\n' "$sandbox_names" | grep -Fqx "$sandbox_name"; then - HOME="$job_home" openshell sandbox delete "$sandbox_name" + job_openshell sandbox delete "$sandbox_name" fi - sandbox_names="$(HOME="$job_home" openshell sandbox list --names -g "$gateway_name")" + sandbox_names="$(job_openshell sandbox list --names -g "$gateway_name")" if printf '%s\n' "$sandbox_names" | grep -Fqx "$sandbox_name"; then echo "The test-owned OpenShell sandbox remains" >&2 exit 1 fi - forward_list="$(HOME="$job_home" openshell forward list --gateway "$gateway_name")" + forward_list="$(job_openshell forward list --gateway "$gateway_name")" if printf '%s\n' "$forward_list" | awk -v sandbox="$sandbox_name" \ '$1 == sandbox && $3 ~ /^[0-9]+$/ { found = 1 } END { exit found ? 0 : 1 }'; then echo "A test-owned OpenShell forward remains" >&2 exit 1 fi - HOME="$job_home" openshell gateway remove "$gateway_name" \ - || HOME="$job_home" openshell gateway destroy -g "$gateway_name" - gateway_json="$(HOME="$job_home" openshell gateway list -o json)" + job_openshell gateway remove "$gateway_name" \ + || job_openshell gateway destroy -g "$gateway_name" + gateway_json="$(job_openshell gateway list -o json)" gateway_state="$(printf '%s' "$gateway_json" | node -e ' const fs = require("node:fs"); const rows = JSON.parse(fs.readFileSync(0, "utf8")); @@ -397,6 +439,26 @@ for volume in "${recorded_volumes[@]}"; do fi done +list_test_owned_images() { + local image_rows repository tag + image_rows="$(docker image ls "$image_repository" --format '{{.Repository}}\t{{.Tag}}')" + while IFS=$'\t' read -r repository tag; do + [ -n "$repository" ] || continue + if [ "$repository" = "$image_repository" ] && [[ "$tag" =~ ^e2e-jetson-nvmap-[a-z0-9_.-]+$ ]]; then + printf '%s:%s\n' "$repository" "$tag" + fi + done <<<"$image_rows" +} + +job_images_output="$(list_test_owned_images)" +job_images=() +if [ -n "$job_images_output" ]; then + mapfile -t job_images <<<"$job_images_output" +fi +for image in "${job_images[@]}"; do + docker image rm "$image" +done + if [ -e "$service_directory" ]; then rm -rf -- "$service_directory" fi @@ -425,6 +487,23 @@ for pid in "${recorded_process_ids[@]}"; do exit 1 fi done +if [ -n "$(list_test_owned_images)" ]; then + echo "A test-owned Jetson image remains" >&2 + exit 1 +fi +for openshell_component in openshell openshell-gateway openshell-sandbox; do + if PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \ + command -v "$openshell_component" >/dev/null 2>&1; then + echo "A host-level OpenShell binary remains after cleanup" >&2 + exit 1 + fi + for host_bin in "/usr/local/bin/$openshell_component" "/usr/bin/$openshell_component" "$HOME/.local/bin/$openshell_component"; do + if [ -e "$host_bin" ] || [ -L "$host_bin" ]; then + echo "A host-level OpenShell binary remains after cleanup" >&2 + exit 1 + fi + done +done JETSON_CLEANUP printf '%s\n' nemoclaw-cleanup-evidence-v1-begin diff --git a/tools/e2e/jetson-dispatch-lifecycle.mts b/tools/e2e/jetson-dispatch-lifecycle.mts index 4d33f2460aa..8d09c96a827 100644 --- a/tools/e2e/jetson-dispatch-lifecycle.mts +++ b/tools/e2e/jetson-dispatch-lifecycle.mts @@ -200,10 +200,10 @@ export class JetsonDispatchCoordinator { maxBytes: 1024, }); if (staleLock !== null) { - const jobId = staleLock.trim(); - if (!/^[a-f0-9]{64}$/u.test(jobId)) { + if (!/^[a-f0-9]{64}\n?$/u.test(staleLock)) { throw new Error("Jetson device lock contains an invalid job ID"); } + const jobId = staleLock.endsWith("\n") ? staleLock.slice(0, -1) : staleLock; await withTimeout(this.#cleanupTimeoutMs, (signal) => this.#worker.cleanup({ jobId, signal }), ); diff --git a/tools/e2e/jetson-dispatch-worker.mts b/tools/e2e/jetson-dispatch-worker.mts index 0bee4057889..cc50a5e8907 100644 --- a/tools/e2e/jetson-dispatch-worker.mts +++ b/tools/e2e/jetson-dispatch-worker.mts @@ -56,7 +56,18 @@ clean_line() { tr -d '\000\r\n\t'; } node_path="$(command -v node)" npm_path="$(command -v npm)" ollama_path="$(command -v ollama)" -openshell_path="$(command -v openshell)" +for openshell_component in openshell openshell-gateway openshell-sandbox; do + if command -v "$openshell_component" >/dev/null 2>&1; then + echo "Jetson dispatch requires OpenShell to be absent before the job" >&2 + exit 1 + fi + for host_bin in "/usr/local/bin/$openshell_component" "/usr/bin/$openshell_component" "$HOME/.local/bin/$openshell_component"; do + if [ -e "$host_bin" ] || [ -L "$host_bin" ]; then + echo "Jetson dispatch requires host-level OpenShell binaries to be absent" >&2 + exit 1 + fi + done +done node_version="$(node --version)" node -e ' const [major, minor] = process.versions.node.split(".").map(Number); @@ -72,13 +83,15 @@ case "$docker_runtimes" in *) echo "Docker does not report the NVIDIA runtime" >&2; exit 1 ;; esac ollama_models_sha256="$(ollama list | awk 'NR > 1 && NF >= 2 { print $1 "\t" $2 }' | sort | sha256sum | cut -d ' ' -f 1)" +test_owned_images="$(docker image ls nemoclaw-sandbox-local --format '{{.Repository}}\t{{.Tag}}' | awk '$1 == "nemoclaw-sandbox-local" && index($2, "e2e-jetson-nvmap-") == 1 { print $1 ":" $2 }')" +[ -z "$test_owned_images" ] || { echo "A test-owned Jetson image remains before dispatch" >&2; exit 1; } printf 'nodePath\t'; printf '%s' "$node_path" | clean_line printf '\nnodeVersion\t'; printf '%s' "$node_version" | clean_line printf '\nnpmPath\t'; printf '%s' "$npm_path" | clean_line printf '\nnpmVersion\t'; printf '%s' "$npm_version" | clean_line printf '\nollamaPath\t'; printf '%s' "$ollama_path" | clean_line printf '\nollamaModelsSha256\t'; printf '%s' "$ollama_models_sha256" | clean_line -printf '\nopenshellPath\t'; printf '%s' "$openshell_path" | clean_line +printf '\nopenshellState\tabsent' printf '\n' `; @@ -163,7 +176,15 @@ if [ -e "$workspace" ]; then exit 1 fi install -d -m 0700 "$workspace" -install -d -m 0700 "$workspace/home" "$workspace/npm-prefix" "$workspace/tmp" +install -d -m 0700 \ + "$workspace/home" \ + "$workspace/home/.cache" \ + "$workspace/home/.config" \ + "$workspace/home/.local/bin" \ + "$workspace/home/.local/share" \ + "$workspace/home/.local/state" \ + "$workspace/npm-prefix" \ + "$workspace/tmp" export HOME="$workspace/home" export TMPDIR="$workspace/tmp" @@ -171,9 +192,16 @@ export XDG_CACHE_HOME="$workspace/home/.cache" export XDG_CONFIG_HOME="$workspace/home/.config" export XDG_DATA_HOME="$workspace/home/.local/share" export XDG_STATE_HOME="$workspace/home/.local/state" +export XDG_BIN_HOME="$workspace/home/.local/bin" export npm_config_prefix="$workspace/npm-prefix" -export PATH="$workspace/npm-prefix/bin:$PATH" -export NEMOCLAW_DEFER_OPENSHELL_INSTALL=1 +export PATH="$XDG_BIN_HOME:$workspace/npm-prefix/bin:$PATH" +export NEMOCLAW_JETSON_WORKSPACE="$workspace" +unset NEMOCLAW_OPENSHELL_BIN NEMOCLAW_OPENSHELL_GATEWAY_BIN + +if [ -w /usr/local/bin ] || [ -w /usr/bin ]; then + echo "Jetson job user must not be able to install OpenShell into a host binary directory" >&2 + exit 1 +fi git init --quiet "$workspace/repository" git -C "$workspace/repository" remote add origin https://github.com/NVIDIA/NemoClaw.git @@ -210,6 +238,15 @@ export OPENSHELL_GATEWAY=nemoclaw timeout --foreground --signal=TERM --kill-after=30s "${"${timeout_seconds}"}s" \ npx tsx tools/e2e/live-vitest-invocation.mts run \ --test-path test/e2e/live/jetson-nvmap-gpu.test.ts + +for installed_command in nemoclaw openshell openshell-gateway openshell-sandbox; do + installed_path="$(command -v "$installed_command")" + canonical_path="$(realpath -e "$installed_path")" + case "$canonical_path" in + "$workspace"/*) ;; + *) echo "$installed_command resolved outside the Jetson job workspace" >&2; exit 1 ;; + esac +done `; const COLLECT_ARTIFACT_SCRIPT = String.raw`set -euo pipefail @@ -441,7 +478,7 @@ interface JetsonPreservedBaseline { npmVersion: string; ollamaPath: string; ollamaModelsSha256: string; - openshellPath: string; + openshellState: "absent"; } function parsePreservedBaseline(output: string): JetsonPreservedBaseline { @@ -466,7 +503,7 @@ function parsePreservedBaseline(output: string): JetsonPreservedBaseline { "npmVersion", "ollamaPath", "ollamaModelsSha256", - "openshellPath", + "openshellState", ] as const; if (entries.size !== expected.length || expected.some((key) => !entries.has(key))) { throw new Error("Jetson protected-baseline output is incomplete"); @@ -478,8 +515,11 @@ function parsePreservedBaseline(output: string): JetsonPreservedBaseline { npmVersion: entries.get("npmVersion")!, ollamaPath: entries.get("ollamaPath")!, ollamaModelsSha256: entries.get("ollamaModelsSha256")!, - openshellPath: entries.get("openshellPath")!, + openshellState: entries.get("openshellState") as "absent", }; + if (baseline.openshellState !== "absent") { + throw new Error("Jetson protected-baseline OpenShell state is malformed"); + } if (!/^[a-f0-9]{64}$/u.test(baseline.ollamaModelsSha256)) { throw new Error("Jetson protected-baseline Ollama model digest is malformed"); } @@ -507,7 +547,7 @@ function parsePreservedBaselineJson(output: string): JetsonPreservedBaseline { "npmVersion", "ollamaPath", "ollamaModelsSha256", - "openshellPath", + "openshellState", ]; if ( Object.keys(record).length !== expected.length || @@ -736,6 +776,7 @@ export class SshJetsonDispatchWorker implements JetsonDispatchWorker { const reportedEvidence = parseCleanupCommandEvidence(cleanupResult.stdout); const evidencePath = this.#cleanupEvidencePath(options.jobId); const persistedRaw = readPrivateRegularFile(evidencePath, { + allowMissing: true, maxBytes: MAX_CLEANUP_EVIDENCE_BYTES, }); if (persistedRaw === null) throw new Error("Jetson cleanup evidence is missing"); diff --git a/tools/e2e/operations-workflow-boundary.mts b/tools/e2e/operations-workflow-boundary.mts index 58655edd16d..5f8068eec8c 100644 --- a/tools/e2e/operations-workflow-boundary.mts +++ b/tools/e2e/operations-workflow-boundary.mts @@ -271,6 +271,7 @@ function validateManualPrDispatch(errors: string[], workflow: OperationsWorkflow } const authEnvironment = { ACTOR: "${{ github.actor }}", + ALLOW_JETSON_DISPATCH: "${{ inputs.allow_jetson_dispatch && 'true' || 'false' }}", BASE_SHA: "${{ inputs.base_sha }}", CHECKOUT_REPOSITORY: "${{ inputs.checkout_repository }}", CHECKOUT_SHA: "${{ inputs.checkout_sha }}", @@ -305,7 +306,7 @@ function validateManualPrDispatch(errors: string[], workflow: OperationsWorkflow "${#REVIEW_REASON} <= 500", '"$EXPECTED_WORKFLOW_SHA" == "$WORKFLOW_SHA"', "Manual PR E2E requires a repository maintainer or administrator", - "Manual PR E2E accepts only empty selectors or managed-image-protected-runtime", + "Manual PR E2E accepts only empty selectors, managed-image-protected-runtime, or jetson-nvmap-gpu with its dispatch flag", "https://api.github.com/repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}", `[[ "$(jq -r '.head.repo.full_name // ""' <<< "$pull_json")" == "$CHECKOUT_REPOSITORY" ]]`, `[[ "$(jq -r '.head.sha' <<< "$pull_json")" == "$CHECKOUT_SHA" ]]`, From c6bf59e72824180d4b31e62ab6f8a4d782f7e0a3 Mon Sep 17 00:00:00 2001 From: San Dang Date: Tue, 11 Aug 2026 00:06:20 +0700 Subject: [PATCH 16/34] fix(e2e): make Jetson cleanup fail closed Signed-off-by: San Dang --- test/e2e/docs/jetson-colossus-dispatch.md | 73 ++++-- .../support/jetson-dispatch-worker.test.ts | 25 +- tools/e2e/jetson-dispatch-cleanup.sh | 218 +++++++++--------- tools/e2e/jetson-dispatch-worker.mts | 26 ++- 4 files changed, 215 insertions(+), 127 deletions(-) diff --git a/test/e2e/docs/jetson-colossus-dispatch.md b/test/e2e/docs/jetson-colossus-dispatch.md index 308fa3fefb3..98145f596f6 100644 --- a/test/e2e/docs/jetson-colossus-dispatch.md +++ b/test/e2e/docs/jetson-colossus-dispatch.md @@ -48,6 +48,7 @@ It does not attest that cleanup reversed every possible host change made by cand Run these checks as the `nvidia` account that the dispatcher uses: ```bash +set -euo pipefail uname -m tr -d '\0' .cleanup.json` record on Colossus. The record survives retries so stale-lock recovery can clean and verify the same identities. +The cleanup program must not execute OpenShell or any other executable installed in the job workspace. The destructive phase must perform these bounded actions: -1. Use only the canonical job-local OpenShell installation to stop the named forwards, sandbox, and gateway. -2. Stop only the recorded helper PIDs after verifying the process owner, command marker, and job `HOME`. -3. Remove only the labeled sandbox containers, exact gateway container, recorded volumes, and reserved test image tags. -4. Remove only the helper-service directory and `/var/tmp/nemoclaw-jetson-e2e/` workspace for the locked job. -5. After workspace removal, verify that the allowlisted resources are absent, host OpenShell remains absent, and the host baseline matches. +1. Stop recorded helper and forward PIDs after verifying the process owner, exact job `HOME`, and command marker. +2. Remove the exact labeled sandbox containers and exact gateway container. +3. Remove the recorded volumes and reserved test image tags. +4. Remove the helper-service directory and `/var/tmp/nemoclaw-jetson-e2e/` workspace for the locked job. +5. Independently verify that the allowlisted resources are absent, host OpenShell remains absent, and the host baseline matches. The cleanup program must be idempotent. It must treat an already absent allowlisted resource as success. @@ -735,8 +745,11 @@ for volume in "${cleanup_volumes[@]}"; do -i /var/lib/nemoclaw-jetson-dispatch/id_ed25519 \ nvidia@192.168.55.1 bash -s -- "$volume" <<'VERIFY_RECORDED_VOLUME' set -euo pipefail -docker info >/dev/null -if docker volume inspect "$1" >/dev/null 2>&1; then +volume_names="$(docker volume ls --format '{{.Name}}')" || { + echo 'Unable to list Docker volumes' >&2 + exit 1 +} +if printf '%s\n' "$volume_names" | grep -Fqx -- "$1"; then echo "A recorded job-owned Docker volume remains: $1" >&2 exit 1 fi @@ -771,22 +784,46 @@ if [ -e /var/tmp/nemoclaw-jetson-e2e ]; then test ! -L /var/tmp/nemoclaw-jetson-e2e test -z "$(find /var/tmp/nemoclaw-jetson-e2e -mindepth 1 -maxdepth 1 -print -quit)" fi -test -z "$(docker ps -aq --filter label=openshell.ai/managed-by=openshell \ - --filter label=openshell.ai/sandbox-name=e2e-jetson-nvmap)" -! docker container inspect openshell-cluster-nemoclaw >/dev/null 2>&1 -! docker volume inspect openshell-cluster-nemoclaw >/dev/null 2>&1 +sandbox_container_output="$(docker ps -aq \ + --filter label=openshell.ai/managed-by=openshell \ + --filter label=openshell.ai/sandbox-name=e2e-jetson-nvmap)" || { + echo 'Unable to list labeled sandbox containers' >&2 + exit 1 +} +test -z "$sandbox_container_output" +container_rows="$(docker container ls --all --no-trunc --format '{{.ID}}\t{{.Names}}')" || { + echo 'Unable to list Docker containers' >&2 + exit 1 +} +if printf '%s\n' "$container_rows" | + awk -F '\t' '$2 == "openshell-cluster-nemoclaw" { found = 1 } END { exit found ? 0 : 1 }'; then + echo 'The job-owned gateway container remains' >&2 + exit 1 +fi +volume_names="$(docker volume ls --format '{{.Name}}')" || { + echo 'Unable to list Docker volumes' >&2 + exit 1 +} +if printf '%s\n' "$volume_names" | grep -Fqx openshell-cluster-nemoclaw; then + echo 'The job-owned gateway volume remains' >&2 + exit 1 +fi for proc_dir in /proc/[0-9]*; do [ -r "$proc_dir/environ" ] || continue tr '\000' '\n' <"$proc_dir/environ" | grep -Fqx "HOME=$job_home" || continue cmdline="$(tr '\000' ' ' <"$proc_dir/cmdline")" case "$cmdline" in - *ollama-auth-proxy.*|*openshell-gateway*|*cloudflared*) + *ollama-auth-proxy.*|*openshell-gateway*|*openshell-forward*|*openshell\ forward*|*cloudflared*) echo "A job-owned helper process remains: ${proc_dir##*/}" >&2 exit 1 ;; esac done -test -z "$(docker image ls --format '{{.Repository}}\t{{.Tag}}' | +image_rows="$(docker image ls nemoclaw-sandbox-local --format '{{.Repository}}\t{{.Tag}}')" || { + echo 'Unable to list job-owned Docker images' >&2 + exit 1 +} +test -z "$(printf '%s\n' "$image_rows" | awk '$1 == "nemoclaw-sandbox-local" && index($2, "e2e-jetson-nvmap-") == 1 { print $1 ":" $2 }')" command -v node npm ollama ollama list >/dev/null @@ -892,5 +929,15 @@ sudo test ! -e /var/lib/nemoclaw-jetson-dispatch/id_ed25519 sudo test ! -e /var/lib/nemoclaw-jetson-dispatch/id_ed25519.pub ``` +Remove the cleanup executable and pinned SSH host-key file, then verify their absence: + +```bash +sudo rm -- \ + /usr/local/libexec/nemoclaw-jetson-cleanup \ + /var/lib/nemoclaw-jetson-dispatch/known_hosts +sudo test ! -e /usr/local/libexec/nemoclaw-jetson-cleanup +sudo test ! -e /var/lib/nemoclaw-jetson-dispatch/known_hosts +``` + After the required retention period, remove the private job state and logs. Remove the dispatcher environment, service unit, and trusted checkout when no investigation, recovery, or retention requirement remains. diff --git a/test/e2e/support/jetson-dispatch-worker.test.ts b/test/e2e/support/jetson-dispatch-worker.test.ts index 69897514026..eb366227406 100644 --- a/test/e2e/support/jetson-dispatch-worker.test.ts +++ b/test/e2e/support/jetson-dispatch-worker.test.ts @@ -336,6 +336,12 @@ describe("Colossus SSH worker deployment boundary", () => { expect(processRunner.mock.calls[1]![0].input).toContain( 'for pid in "${recorded_process_ids[@]}"', ); + expect(processRunner.mock.calls[1]![0].input).toContain("docker container ls --all --no-trunc"); + expect(processRunner.mock.calls[1]![0].input).toContain( + "docker volume ls --format '{{.Name}}'", + ); + expect(processRunner.mock.calls[1]![0].input).not.toContain("docker container inspect"); + expect(processRunner.mock.calls[1]![0].input).not.toContain("docker volume inspect"); expect(processRunner.mock.calls[1]![0].args).toEqual( expect.arrayContaining(["nvidia@192.168.55.1", "--", jobId]), ); @@ -567,7 +573,7 @@ describe("Colossus SSH worker deployment boundary", () => { const directoryFsync = cleanupProgram.indexOf("fs.fsyncSync(directoryDescriptor)"); const destructivePhase = cleanupProgram.indexOf("<<'JETSON_CLEANUP'"); expect(cleanupProgram).toContain("sandbox_name=e2e-jetson-nvmap"); - expect(cleanupProgram).toContain("gateway_name=nemoclaw"); + expect(cleanupProgram).toContain("gateway_container=openshell-cluster-nemoclaw"); expect(cleanupProgram).toContain("destination=nvidia@192.168.55.1"); expect(cleanupProgram).toContain('if [ "$#" -ne 0 ]'); expect(cleanupProgram).toContain('mapfile -t lock_lines <"$lock_file"'); @@ -577,6 +583,8 @@ describe("Colossus SSH worker deployment boundary", () => { expect(cleanupProgram).toContain("ollama-auth-proxy.pid"); expect(cleanupProgram).toContain('process_uid="$(awk'); expect(cleanupProgram).toContain('grep -Fqx "HOME=$job_home"'); + expect(cleanupProgram).toContain("*openshell-forward*"); + expect(cleanupProgram).toContain("*openshell\\ forward*"); expect(cleanupProgram).toContain('kill "$pid"'); expect(cleanupProgram).toContain("label=openshell.ai/sandbox-name=$sandbox_name"); expect(cleanupProgram).toContain("image_repository=nemoclaw-sandbox-local"); @@ -584,8 +592,12 @@ describe("Colossus SSH worker deployment boundary", () => { expect(cleanupProgram.indexOf('docker image rm "$image"')).toBeLessThan( cleanupProgram.indexOf('rm -rf -- "$workspace"'), ); - expect(cleanupProgram).toContain('"$job_home/.local/bin/openshell"'); - expect(cleanupProgram).toContain("Refusing an OpenShell binary outside the job workspace"); + expect(cleanupProgram).not.toContain("job_openshell"); + expect(cleanupProgram).not.toContain('"$job_home/.local/bin/openshell"'); + expect(cleanupProgram).toContain("docker container ls --all --no-trunc"); + expect(cleanupProgram).toContain("docker volume ls --format '{{.Name}}'"); + expect(cleanupProgram).not.toMatch(/if docker (?:container|volume) inspect/u); + expect(cleanupProgram).not.toContain("mapfile -t sandbox_containers < <("); expect(cleanupProgram).toContain("A host-level OpenShell binary remains after cleanup"); expect(cleanupProgram).toContain("nemoclaw-cleanup-evidence-v1-begin"); expect(cleanupProgram).toContain("nemoclaw-cleanup-evidence-v1-end"); @@ -622,7 +634,10 @@ describe("Colossus SSH worker deployment boundary", () => { expect(jetsonLiveTest).toContain( "for installed_command in nemoclaw openshell openshell-gateway openshell-sandbox", ); - expect(cleanupProgram.indexOf("job_openshell sandbox delete")).toBeLessThan( + expect(cleanupProgram.indexOf('stop_recorded_pid "$pid"')).toBeLessThan( + cleanupProgram.indexOf('docker container rm --force "$container"'), + ); + expect(cleanupProgram.indexOf('docker container rm --force "$container"')).toBeLessThan( cleanupProgram.indexOf('rm -rf -- "$workspace"'), ); }); @@ -649,7 +664,7 @@ describe("Colossus SSH worker deployment boundary", () => { const aggregateCleanupRecords = dispatcherRunbook.indexOf( "const cleanupName = /^[a-f0-9]{64}\\.cleanup\\.json$/", ); - const verifyRecordedVolume = dispatcherRunbook.indexOf('docker volume inspect "$1"'); + const verifyRecordedVolume = dispatcherRunbook.indexOf("docker volume ls --format '{{.Name}}'"); const verifyRecordedProcess = dispatcherRunbook.indexOf('if [ -e "/proc/$1" ]'); const stopDispatcher = dispatcherRunbook.indexOf( "sudo systemctl disable --now nemoclaw-jetson-dispatch.service", diff --git a/tools/e2e/jetson-dispatch-cleanup.sh b/tools/e2e/jetson-dispatch-cleanup.sh index d5c09d275c6..fecc42750af 100755 --- a/tools/e2e/jetson-dispatch-cleanup.sh +++ b/tools/e2e/jetson-dispatch-cleanup.sh @@ -87,22 +87,33 @@ record_volume() { } record_container_volumes() { - local container="$1" volume - while IFS= read -r volume; do - [ -n "$volume" ] || continue - record_volume "$volume" - done < <( + local container="$1" volume volume_output + volume_output="$( docker container inspect --format \ '{{range .Mounts}}{{if eq .Type "volume"}}{{println .Name}}{{end}}{{end}}' \ "$container" - ) + )" || { + echo "Unable to inspect a test-owned Docker container" >&2 + exit 1 + } + while IFS= read -r volume; do + [ -n "$volume" ] || continue + record_volume "$volume" + done <<<"$volume_output" } -mapfile -t sandbox_containers < <( +sandbox_container_output="$( docker ps -aq \ --filter label=openshell.ai/managed-by=openshell \ --filter "label=openshell.ai/sandbox-name=$sandbox_name" -) +)" || { + echo "Unable to list test-owned Docker containers" >&2 + exit 1 +} +sandbox_containers=() +if [ -n "$sandbox_container_output" ]; then + mapfile -t sandbox_containers <<<"$sandbox_container_output" +fi for container in "${sandbox_containers[@]}"; do [[ "$container" =~ ^[a-f0-9]{12,64}$ ]] || { echo "Refusing an invalid recorded Docker container ID" >&2 @@ -115,8 +126,19 @@ for container in "${sandbox_containers[@]}"; do esac record_container_volumes "$container" done -if docker container inspect "$gateway_container" >/dev/null 2>&1; then - record_container_volumes "$gateway_container" +container_rows="$(docker container ls --all --no-trunc --format '{{.ID}}\t{{.Names}}')" || { + echo "Unable to list Docker containers" >&2 + exit 1 +} +gateway_container_ids="$( + printf '%s\n' "$container_rows" | awk -F '\t' -v name="$gateway_container" '$2 == name { print $1 }' +)" +if [ -n "$gateway_container_ids" ]; then + if [[ "$gateway_container_ids" == *$'\n'* ]] || ! [[ "$gateway_container_ids" =~ ^[a-f0-9]{12,64}$ ]]; then + echo "Refusing an ambiguous test-owned gateway container" >&2 + exit 1 + fi + record_container_volumes "$gateway_container_ids" fi record_volume "$gateway_volume" @@ -175,6 +197,18 @@ for pid in "$auth_proxy_pid" "$gateway_pid" "$cloudflared_pid"; do printf 'processId\t%s\n' "$pid" fi done +for proc_dir in /proc/[0-9]*; do + [ -r "$proc_dir/status" ] && [ -r "$proc_dir/environ" ] && [ -r "$proc_dir/cmdline" ] || continue + process_uid="$(awk '/^Uid:/ { print $2; exit }' "$proc_dir/status")" + [ "$process_uid" = "$(id -u)" ] || continue + tr '\000' '\n' <"$proc_dir/environ" | grep -Fqx "HOME=$job_home" || continue + cmdline="$(tr '\000' ' ' <"$proc_dir/cmdline")" + case "$cmdline" in + *ollama-auth-proxy.* | *openshell-gateway* | *openshell-forward* | *openshell\ forward* | *cloudflared*) + printf 'processId\t%s\n' "${proc_dir##*/}" + ;; + esac +done printf '%s\n' nemoclaw-cleanup-evidence-v1-end JETSON_DISCOVERY )" @@ -252,7 +286,6 @@ workspace_root=/var/tmp/nemoclaw-jetson-e2e workspace="$workspace_root/$job_id" job_home="$workspace/home" sandbox_name=e2e-jetson-nvmap -gateway_name=nemoclaw gateway_container=openshell-cluster-nemoclaw image_repository=nemoclaw-sandbox-local service_directory="/tmp/nemoclaw-services-$sandbox_name" @@ -314,7 +347,7 @@ stop_recorded_pid() { } cmdline="$(tr '\000' ' ' <"/proc/$pid/cmdline")" case "$cmdline" in - *ollama-auth-proxy.* | *openshell-gateway* | *cloudflared*) ;; + *ollama-auth-proxy.* | *openshell-gateway* | *openshell-forward* | *openshell\ forward* | *cloudflared*) ;; *) echo "Refusing to stop a recorded PID with an unexpected command" >&2; exit 1 ;; esac if ! tr '\000' '\n' <"/proc/$pid/environ" | grep -Fqx "HOME=$job_home"; then @@ -335,113 +368,61 @@ stop_recorded_pid() { exit 1 } -openshell_bin="" -openshell_install_complete=1 -for component in openshell openshell-gateway openshell-sandbox; do - component_path="$job_home/.local/bin/$component" - if [ -x "$component_path" ]; then - canonical_component="$(realpath -e "$component_path")" - case "$canonical_component" in - "$workspace"/*) ;; - *) echo "Refusing an OpenShell binary outside the job workspace" >&2; exit 1 ;; - esac - else - openshell_install_complete=0 - fi -done -if [ "$openshell_install_complete" -eq 1 ]; then - openshell_bin="$job_home/.local/bin/openshell" -fi - -job_openshell() { - HOME="$job_home" \ - TMPDIR="$workspace/tmp" \ - XDG_BIN_HOME="$job_home/.local/bin" \ - XDG_CACHE_HOME="$job_home/.cache" \ - XDG_CONFIG_HOME="$job_home/.config" \ - XDG_DATA_HOME="$job_home/.local/share" \ - XDG_STATE_HOME="$job_home/.local/state" \ - PATH="$job_home/.local/bin:$workspace/npm-prefix/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" \ - "$openshell_bin" "$@" -} - -gateway_present=0 -if [ -n "$openshell_bin" ]; then - gateway_json="$(job_openshell gateway list -o json)" - gateway_state="$(printf '%s' "$gateway_json" | node -e ' - const fs = require("node:fs"); - const rows = JSON.parse(fs.readFileSync(0, "utf8")); - if (!Array.isArray(rows)) throw new Error("invalid gateway list"); - process.stdout.write(rows.some((row) => row && row.name === "nemoclaw") ? "present" : "absent"); - ')" - [ "$gateway_state" = present ] && gateway_present=1 -fi - -if [ "$gateway_present" -eq 1 ]; then - forward_list="$(job_openshell forward list --gateway "$gateway_name")" - while IFS= read -r port; do - [ -n "$port" ] || continue - [[ "$port" =~ ^[1-9][0-9]{0,4}$ ]] || exit 1 - job_openshell forward stop "$port" "$sandbox_name" - done < <( - printf '%s\n' "$forward_list" | awk -v sandbox="$sandbox_name" \ - '$1 == sandbox && $3 ~ /^[0-9]+$/ { print $3 }' - ) - sandbox_names="$(job_openshell sandbox list --names -g "$gateway_name")" - if printf '%s\n' "$sandbox_names" | grep -Fqx "$sandbox_name"; then - job_openshell sandbox delete "$sandbox_name" - fi - sandbox_names="$(job_openshell sandbox list --names -g "$gateway_name")" - if printf '%s\n' "$sandbox_names" | grep -Fqx "$sandbox_name"; then - echo "The test-owned OpenShell sandbox remains" >&2 - exit 1 - fi - forward_list="$(job_openshell forward list --gateway "$gateway_name")" - if printf '%s\n' "$forward_list" | awk -v sandbox="$sandbox_name" \ - '$1 == sandbox && $3 ~ /^[0-9]+$/ { found = 1 } END { exit found ? 0 : 1 }'; then - echo "A test-owned OpenShell forward remains" >&2 - exit 1 - fi - job_openshell gateway remove "$gateway_name" \ - || job_openshell gateway destroy -g "$gateway_name" - gateway_json="$(job_openshell gateway list -o json)" - gateway_state="$(printf '%s' "$gateway_json" | node -e ' - const fs = require("node:fs"); - const rows = JSON.parse(fs.readFileSync(0, "utf8")); - if (!Array.isArray(rows)) throw new Error("invalid gateway list"); - process.stdout.write(rows.some((row) => row && row.name === "nemoclaw") ? "present" : "absent"); - ')" - if [ "$gateway_state" = present ]; then - echo "The test-owned OpenShell gateway remains" >&2 - exit 1 - fi -fi - for pid in "${recorded_process_ids[@]}"; do stop_recorded_pid "$pid" done -mapfile -t sandbox_containers < <( +sandbox_container_output="$( docker ps -aq \ --filter label=openshell.ai/managed-by=openshell \ --filter "label=openshell.ai/sandbox-name=$sandbox_name" -) +)" || { + echo "Unable to list test-owned Docker containers" >&2 + exit 1 +} +sandbox_containers=() +if [ -n "$sandbox_container_output" ]; then + mapfile -t sandbox_containers <<<"$sandbox_container_output" +fi for container in "${sandbox_containers[@]}"; do [[ "$container" =~ ^[a-f0-9]{12,64}$ ]] || exit 1 + container_image="$(docker container inspect --format '{{.Config.Image}}' "$container")" + case "$container_image" in + "$image_repository:$sandbox_name-"*) ;; + *) echo "Refusing a sandbox container whose image is not test-owned" >&2; exit 1 ;; + esac docker container rm --force "$container" done -if docker container inspect "$gateway_container" >/dev/null 2>&1; then - docker container rm --force "$gateway_container" +container_rows="$(docker container ls --all --no-trunc --format '{{.ID}}\t{{.Names}}')" || { + echo "Unable to list Docker containers" >&2 + exit 1 +} +gateway_container_ids="$( + printf '%s\n' "$container_rows" | awk -F '\t' -v name="$gateway_container" '$2 == name { print $1 }' +)" +if [ -n "$gateway_container_ids" ]; then + if [[ "$gateway_container_ids" == *$'\n'* ]] || ! [[ "$gateway_container_ids" =~ ^[a-f0-9]{12,64}$ ]]; then + echo "Refusing an ambiguous test-owned gateway container" >&2 + exit 1 + fi + docker container rm --force "$gateway_container_ids" fi +volume_names="$(docker volume ls --format '{{.Name}}')" || { + echo "Unable to list Docker volumes" >&2 + exit 1 +} for volume in "${recorded_volumes[@]}"; do - if docker volume inspect "$volume" >/dev/null 2>&1; then + if printf '%s\n' "$volume_names" | grep -Fqx "$volume"; then docker volume rm "$volume" fi done list_test_owned_images() { local image_rows repository tag - image_rows="$(docker image ls "$image_repository" --format '{{.Repository}}\t{{.Tag}}')" + image_rows="$(docker image ls "$image_repository" --format '{{.Repository}}\t{{.Tag}}')" || { + echo "Unable to list test-owned Docker images" >&2 + return 1 + } while IFS=$'\t' read -r repository tag; do [ -n "$repository" ] || continue if [ "$repository" = "$image_repository" ] && [[ "$tag" =~ ^e2e-jetson-nvmap-[a-z0-9_.-]+$ ]]; then @@ -468,15 +449,30 @@ fi test ! -e "$workspace" test ! -e "$service_directory" -test -z "$(docker ps -aq \ +sandbox_container_output="$(docker ps -aq \ --filter label=openshell.ai/managed-by=openshell \ - --filter "label=openshell.ai/sandbox-name=$sandbox_name")" -if docker container inspect "$gateway_container" >/dev/null 2>&1; then + --filter "label=openshell.ai/sandbox-name=$sandbox_name")" || { + echo "Unable to verify test-owned Docker container absence" >&2 + exit 1 +} +if [ -n "$sandbox_container_output" ]; then + echo "A test-owned sandbox container remains" >&2 + exit 1 +fi +container_rows="$(docker container ls --all --no-trunc --format '{{.ID}}\t{{.Names}}')" || { + echo "Unable to verify Docker container absence" >&2 + exit 1 +} +if printf '%s\n' "$container_rows" | awk -F '\t' -v name="$gateway_container" '$2 == name { found = 1 } END { exit found ? 0 : 1 }'; then echo "The test-owned gateway container remains" >&2 exit 1 fi +volume_names="$(docker volume ls --format '{{.Name}}')" || { + echo "Unable to verify Docker volume absence" >&2 + exit 1 +} for volume in "${recorded_volumes[@]}"; do - if docker volume inspect "$volume" >/dev/null 2>&1; then + if printf '%s\n' "$volume_names" | grep -Fqx "$volume"; then echo "A recorded test-owned Docker volume remains" >&2 exit 1 fi @@ -487,7 +483,19 @@ for pid in "${recorded_process_ids[@]}"; do exit 1 fi done -if [ -n "$(list_test_owned_images)" ]; then +for proc_dir in /proc/[0-9]*; do + [ -r "$proc_dir/environ" ] && [ -r "$proc_dir/cmdline" ] || continue + tr '\000' '\n' <"$proc_dir/environ" | grep -Fqx "HOME=$job_home" || continue + cmdline="$(tr '\000' ' ' <"$proc_dir/cmdline")" + case "$cmdline" in + *ollama-auth-proxy.* | *openshell-gateway* | *openshell-forward* | *openshell\ forward* | *cloudflared*) + echo "A job-owned helper process remains" >&2 + exit 1 + ;; + esac +done +remaining_job_images="$(list_test_owned_images)" || exit 1 +if [ -n "$remaining_job_images" ]; then echo "A test-owned Jetson image remains" >&2 exit 1 fi diff --git a/tools/e2e/jetson-dispatch-worker.mts b/tools/e2e/jetson-dispatch-worker.mts index cc50a5e8907..5a3d8a8537b 100644 --- a/tools/e2e/jetson-dispatch-worker.mts +++ b/tools/e2e/jetson-dispatch-worker.mts @@ -101,6 +101,7 @@ job_id="$1" cleanup_evidence_base64="$2" [[ "$job_id" =~ ^[a-f0-9]{64}$ ]] workspace="/var/tmp/nemoclaw-jetson-e2e/$job_id" +job_home="$workspace/home" sandbox_name=e2e-jetson-nvmap gateway_name=nemoclaw recorded_volumes=() @@ -131,19 +132,25 @@ if [ -n "$cleanup_rows" ]; then fi test ! -e "$workspace" test ! -L "$workspace" -test -z "$(docker ps -aq \ +sandbox_container_output="$(docker ps -aq \ --filter label=openshell.ai/managed-by=openshell \ --filter "label=openshell.ai/sandbox-name=$sandbox_name")" -if docker container inspect "openshell-cluster-$gateway_name" >/dev/null 2>&1; then +if [ -n "$sandbox_container_output" ]; then + echo "A test-owned OpenShell sandbox container remains" >&2 + exit 1 +fi +container_rows="$(docker container ls --all --no-trunc --format '{{.ID}}\t{{.Names}}')" +if printf '%s\n' "$container_rows" | awk -F '\t' -v name="openshell-cluster-$gateway_name" '$2 == name { found = 1 } END { exit found ? 0 : 1 }'; then echo "The test-owned OpenShell gateway container remains" >&2 exit 1 fi -if docker volume inspect "openshell-cluster-$gateway_name" >/dev/null 2>&1; then +volume_names="$(docker volume ls --format '{{.Name}}')" +if printf '%s\n' "$volume_names" | grep -Fqx "openshell-cluster-$gateway_name"; then echo "The test-owned OpenShell gateway volume remains" >&2 exit 1 fi for volume in "${"${recorded_volumes[@]}"}"; do - if docker volume inspect "$volume" >/dev/null 2>&1; then + if printf '%s\n' "$volume_names" | grep -Fqx "$volume"; then echo "A recorded test-owned Docker volume remains" >&2 exit 1 fi @@ -154,6 +161,17 @@ for pid in "${"${recorded_process_ids[@]}"}"; do exit 1 fi done +for proc_dir in /proc/[0-9]*; do + [ -r "$proc_dir/environ" ] && [ -r "$proc_dir/cmdline" ] || continue + tr '\000' '\n' <"$proc_dir/environ" | grep -Fqx "HOME=$job_home" || continue + cmdline="$(tr '\000' ' ' <"$proc_dir/cmdline")" + case "$cmdline" in + *ollama-auth-proxy.* | *openshell-gateway* | *openshell-forward* | *openshell\ forward* | *cloudflared*) + echo "A job-owned helper process remains" >&2 + exit 1 + ;; + esac +done ` + PRESERVED_BASELINE_SCRIPT; const JETSON_TEST_SCRIPT = String.raw`set -euo pipefail From 80db10df9d20a14180a7c09db8e9bfe1e46a1d30 Mon Sep 17 00:00:00 2001 From: San Dang Date: Tue, 11 Aug 2026 00:21:25 +0700 Subject: [PATCH 17/34] test(e2e): keep Jetson lock failure setup linear Signed-off-by: San Dang --- test/e2e/support/jetson-dispatch-contract.test.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/test/e2e/support/jetson-dispatch-contract.test.ts b/test/e2e/support/jetson-dispatch-contract.test.ts index 4cb2da35866..2e31bd66cdc 100644 --- a/test/e2e/support/jetson-dispatch-contract.test.ts +++ b/test/e2e/support/jetson-dispatch-contract.test.ts @@ -416,14 +416,11 @@ describe("Jetson single-device lifecycle", () => { const stateDirectory = temporaryDirectory(); const cleanup = vi.fn(async () => {}); const unlinkSync = fs.unlinkSync.bind(fs); - let rejectLockRemoval = true; - vi.spyOn(fs, "unlinkSync").mockImplementation((file) => { - if (rejectLockRemoval) { - rejectLockRemoval = false; + vi.spyOn(fs, "unlinkSync") + .mockImplementationOnce(() => { throw new Error("lock filesystem unavailable"); - } - return unlinkSync(file); - }); + }) + .mockImplementation(unlinkSync); const dispatch = coordinator(stateDirectory, worker({ cleanup })); await dispatch.initialize(); const accepted = dispatch.dispatch(REQUEST, identity()); From 96689df8f61de8f6426ae9fd5d72392de457890c Mon Sep 17 00:00:00 2001 From: San Dang Date: Tue, 11 Aug 2026 00:51:52 +0700 Subject: [PATCH 18/34] feat(e2e): deploy Colossus Jetson dispatcher releases Signed-off-by: San Dang --- test/e2e/docs/jetson-colossus-dispatch.md | 222 +++++++- .../colossus-jetson-dispatch-deploy.test.ts | 498 ++++++++++++++++++ .../support/jetson-dispatch-worker.test.ts | 182 ++++++- test/helpers/vitest-watch-triggers.ts | 4 + test/vitest-watch-triggers.test.ts | 4 + tools/e2e/colossus-jetson-dispatch-deploy.sh | 438 +++++++++++++++ tools/e2e/jetson-dispatch-worker.mts | 24 +- 7 files changed, 1336 insertions(+), 36 deletions(-) create mode 100644 test/e2e/support/colossus-jetson-dispatch-deploy.test.ts create mode 100755 tools/e2e/colossus-jetson-dispatch-deploy.sh diff --git a/test/e2e/docs/jetson-colossus-dispatch.md b/test/e2e/docs/jetson-colossus-dispatch.md index 98145f596f6..32f51c9c729 100644 --- a/test/e2e/docs/jetson-colossus-dispatch.md +++ b/test/e2e/docs/jetson-colossus-dispatch.md @@ -154,14 +154,13 @@ The cleanup program must not change or remove any resource outside its allowlist Review its command construction and target resolution before deployment. Do not use broad process termination, Docker pruning, wildcard paths, or host-wide package removal. -## Create the Colossus Dispatcher Account +## Create the Colossus Dispatcher Account and Bootstrap Deployment Run these commands on Colossus. -Replace the checkout path if the host uses a managed deployment location. The dispatcher requires `/usr/bin/node` 22.19.0 or later. -Replace `REVIEWED_COMMIT_SHA` with the full lowercase 40-character SHA of the reviewed commit to deploy. ```bash +set -euo pipefail /usr/bin/node --version /usr/bin/node -e ' const [major, minor] = process.versions.node.split(".").map(Number); @@ -172,22 +171,48 @@ sudo useradd --system --create-home \ --shell /usr/sbin/nologin nemoclaw-jetson-dispatch sudo install -d -o nemoclaw-jetson-dispatch -g nemoclaw-jetson-dispatch -m 0700 \ /var/lib/nemoclaw-jetson-dispatch /etc/nemoclaw-jetson-dispatch +``` + +Bootstrap the deployment command from a separately reviewed checkout of `https://github.com/NVIDIA/NemoClaw.git`. +Replace both placeholder SHAs with full lowercase 40-character reviewed commit SHAs: + +```bash +set -euo pipefail +REVIEWED_BOOTSTRAP_SHA=0000000000000000000000000000000000000000 +test "$(git remote get-url origin)" = https://github.com/NVIDIA/NemoClaw.git +test "$(git rev-parse HEAD)" = "$REVIEWED_BOOTSTRAP_SHA" +test -z "$(git status --short)" +sudo install -o root -g root -m 0755 \ + tools/e2e/colossus-jetson-dispatch-deploy.sh \ + /usr/local/sbin/nemoclaw-colossus-jetson-dispatch-deploy + +test "$(systemctl show --property=LoadState --value \ + nemoclaw-jetson-dispatch.service)" = not-found +sudo test ! -e /var/lib/nemoclaw-jetson-dispatch/state/device.lock +sudo test ! -L /var/lib/nemoclaw-jetson-dispatch/state/device.lock REVIEWED_COMMIT_SHA=0000000000000000000000000000000000000000 -sudo install -d -o root -g root -m 0755 /opt/nemoclaw-jetson-dispatch -sudo git -C /opt/nemoclaw-jetson-dispatch init -sudo git -C /opt/nemoclaw-jetson-dispatch remote add origin \ - https://github.com/NVIDIA/NemoClaw.git -sudo git -C /opt/nemoclaw-jetson-dispatch fetch --depth=1 --no-tags origin \ - "$REVIEWED_COMMIT_SHA" -sudo git -C /opt/nemoclaw-jetson-dispatch checkout --detach FETCH_HEAD -test "$(sudo git -C /opt/nemoclaw-jetson-dispatch rev-parse HEAD)" = \ - "$REVIEWED_COMMIT_SHA" -test -z "$(sudo git -C /opt/nemoclaw-jetson-dispatch status --short)" -``` - -The two final checks must pass before the dispatcher service starts. -Do not deploy a branch reference or automatically update this checkout. -The Colossus service runs the dispatcher files from this trusted commit. +sudo /usr/local/sbin/nemoclaw-colossus-jetson-dispatch-deploy \ + --commit "$REVIEWED_COMMIT_SHA" +test "$(sudo readlink /opt/nemoclaw-jetson-dispatch/current)" = \ + "/opt/nemoclaw-jetson-dispatch/releases/$REVIEWED_COMMIT_SHA" +sudo test -L /usr/local/libexec/nemoclaw-jetson-cleanup +test "$(sudo readlink /usr/local/libexec/nemoclaw-jetson-cleanup)" = \ + /opt/nemoclaw-jetson-dispatch/current/tools/e2e/jetson-dispatch-cleanup.sh +``` + +The deployment command requires root and accepts only `--commit `. +It fetches only that commit from the fixed `https://github.com/NVIDIA/NemoClaw.git` origin. +It stores each verified release at `/opt/nemoclaw-jetson-dispatch/releases/`. +Each release directory must be owned by `root:root` with mode `0755`. +The command verifies the origin, commit, unmodified worktree, and bundled cleanup file before selection. +It installs one root-owned stable symbolic link from `/usr/local/libexec/nemoclaw-jetson-cleanup` to `/opt/nemoclaw-jetson-dispatch/current/tools/e2e/jetson-dispatch-cleanup.sh`. +It then selects the dispatcher and cleanup program together with one atomic absolute `/opt/nemoclaw-jetson-dispatch/current` symbolic-link switch. +The initial deployment requires the systemd service and `device.lock` to be absent. +It installs the release selection and cleanup link without starting a service. +The command does not update its installed copy. +Install a reviewed deployment-command revision separately when that command changes. + +The Colossus service runs the dispatcher files from the selected reviewed release. The GitHub-hosted controller runs the client from the trusted workflow commit. The Colossus service never checks out candidate code. @@ -221,14 +246,14 @@ Do not accept a changed host key without reconciling it through the serial conso ## Define the Cleanup Program -Install the bundled cleanup program from the trusted checkout: - -```bash -sudo install -d -o root -g root -m 0755 /usr/local/libexec -sudo install -o root -g root -m 0755 \ - /opt/nemoclaw-jetson-dispatch/tools/e2e/jetson-dispatch-cleanup.sh \ - /usr/local/libexec/nemoclaw-jetson-cleanup -``` +The deployment command installs `/usr/local/libexec/nemoclaw-jetson-cleanup` as a root-owned stable symbolic link to `/opt/nemoclaw-jetson-dispatch/current/tools/e2e/jetson-dispatch-cleanup.sh`. +The selected target file is owned by `root:root` with mode `0755`. +One atomic `current` switch selects both the dispatcher code and cleanup program, so an interruption cannot select them from different releases. +The deployed worker configuration must name that exact cleanup path. +The worker accepts the symbolic link only when root owns it, its target is the exact managed `current` cleanup program, and that target passes the regular executable ownership and write-permission checks. +It rejects arbitrary cleanup symbolic links and an unsafe managed target. +The deployment command accepts no cleanup path, resource selector, or cleanup-scope override. +Review a release that changes the cleanup allowlist separately before deployment. It must accept no arguments and must not be group- or world-writable. It must derive the lowercase 64-character job ID from the private dispatcher `device.lock`. @@ -355,7 +380,7 @@ Type=simple User=nemoclaw-jetson-dispatch Group=nemoclaw-jetson-dispatch UMask=0077 -WorkingDirectory=/opt/nemoclaw-jetson-dispatch +WorkingDirectory=/opt/nemoclaw-jetson-dispatch/current EnvironmentFile=/etc/nemoclaw-jetson-dispatch/environment ExecStart=/usr/bin/node --experimental-strip-types --no-warnings tools/e2e/jetson-dispatch-service.mts Restart=on-failure @@ -383,7 +408,8 @@ sudo ss -ltnp | grep '127.0.0.1:8787' An anonymous request must fail: ```bash -curl --fail-with-body -X POST http://127.0.0.1:8787/v1/jobs \ +curl --disable --noproxy '*' --fail-with-body \ + -X POST http://127.0.0.1:8787/v1/jobs \ -H 'Content-Type: application/json' \ --data '{"schemaVersion":1,"target":"jetson-nvmap-gpu","candidateSha":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","workflowRunId":"1","workflowRunAttempt":1}' ``` @@ -391,6 +417,119 @@ curl --fail-with-body -X POST http://127.0.0.1:8787/v1/jobs \ The expected result is HTTP `401`. A malformed request returns HTTP `400`, and an unknown route returns HTTP `404`. +## Deploy a Later Reviewed Commit + +This procedure applies after the tunnel has been published once. +Use the installed deployment command for each later reviewed release: + +```bash +( + set -euo pipefail + tunnel_verified=0 + stop_unverified_tunnel() { + original_status=$? + trap - EXIT + if [ "$tunnel_verified" = 1 ]; then + exit "$original_status" + fi + + set +e + sudo systemctl stop nemoclaw-jetson-tunnel.service + stop_status=$? + observed_state="$(sudo systemctl show --property=ActiveState --value \ + nemoclaw-jetson-tunnel.service)" + inspection_status=$? + set -e + + exit_status=$original_status + if [ "$exit_status" -eq 0 ]; then + exit_status=1 + fi + if [ "$inspection_status" -ne 0 ]; then + state_report=unknown + elif [ -n "$observed_state" ]; then + state_report=$observed_state + else + state_report=empty + fi + if [ "$stop_status" -ne 0 ] || [ "$inspection_status" -ne 0 ] || \ + [ "$observed_state" != inactive ]; then + printf 'PUBLIC INGRESS CONTAINMENT FAILED: tunnel stop status=%s; ActiveState=%s; inspection status=%s\n' \ + "$stop_status" "$state_report" "$inspection_status" >&2 + fi + exit "$exit_status" + } + trap stop_unverified_tunnel EXIT + + REVIEWED_COMMIT_SHA=0000000000000000000000000000000000000000 + sudo systemctl stop nemoclaw-jetson-tunnel.service + test "$(sudo systemctl show --property=ActiveState --value \ + nemoclaw-jetson-tunnel.service)" = inactive + sudo /usr/local/sbin/nemoclaw-colossus-jetson-dispatch-deploy \ + --commit "$REVIEWED_COMMIT_SHA" + sudo systemctl start nemoclaw-jetson-tunnel.service + test "$(sudo systemctl show --property=ActiveState --value \ + nemoclaw-jetson-tunnel.service)" = active + PUBLIC_HTTP_CODE="$( + curl --disable --noproxy '*' --silent --show-error --output /dev/null \ + --write-out '%{http_code}' --max-time 10 --request POST \ + --header 'Content-Type: application/json' \ + --data '{"schemaVersion":1,"target":"jetson-nvmap-gpu","candidateSha":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","workflowRunId":"1","workflowRunAttempt":1}' \ + https://jetson-e2e.example.com/v1/jobs + )" + test "$PUBLIC_HTTP_CODE" = 401 + tunnel_verified=1 +) +``` + +The tunnel stop and exact `ActiveState=inactive` check happen before the deployer can change the dispatcher release. +The subshell installs an `EXIT` trap before tunnel operations and leaves its `tunnel_verified` sentinel unset until every check succeeds. +On any earlier exit, the trap disables itself, records the tunnel stop status, and independently inspects `ActiveState`. +Only a successful stop, successful inspection, and exact `ActiveState=inactive` confirm local public-ingress containment. +The trap preserves the original nonzero status, or returns `1` for an otherwise successful unverified exit. +When it cannot confirm containment, it reports `PUBLIC INGRESS CONTAINMENT FAILED` with the stop status and observed or unknown state. +The deployer completes only after the dispatcher starts and its local loopback bind and anonymous HTTP `401` checks pass. +Only after that successful return does the block start the tunnel, require `ActiveState=active`, and repeat a config-free, direct anonymous HTTP `401` check through the public endpoint. +The tunnel remains running only when the block sets `tunnel_verified=1` after all three checks succeed. + +It accepts only systemd `LoadState` values `loaded` and `not-found`. +Both cases require `device.lock` to be absent before release preparation. +A loaded service is eligible only when `current` selects one managed release and the stable cleanup link follows `current`. +For a loaded service, the command performs these actions: + +1. Stop the service. +2. Query `ActiveState` and require the exact value `inactive`. +3. Refuse deployment when `/var/lib/nemoclaw-jetson-dispatch/state/device.lock` remains. +4. Validate the managed `current` release and stable cleanup link, then prepare and verify the requested release. +5. Atomically switch `current`, selecting the requested dispatcher code and cleanup program together. +6. Start the service. +7. Verify that only `127.0.0.1:8787` listens and make a config-free, direct request with `curl --disable --noproxy '*'`; the anonymous job request must return HTTP `401`. + +If the post-stop state cannot be read, is not `inactive`, or `device.lock` remains, the command exits with the service stopped and does not prepare or select a release. +Do not remove the lock. +Complete the recovery procedure on this page before you rerun deployment. + +An interruption before the atomic `current` switch leaves the previous dispatcher and cleanup program selected; an interruption after it selects both from the requested release. +If activation, start, or loopback verification fails for a loaded service, rollback must first stop the service successfully, require `ActiveState=inactive`, and require `device.lock` to be absent. +Only then does it atomically restore the prior `current` selection, which restores both the dispatcher and cleanup program. +If rollback cannot prove those three conditions after the requested pair is selected, it leaves that new code and cleanup pair selected and reports rollback failure. +When an earlier selected release exists, it restarts that release and repeats the loopback verification. +When no prior selection exists, rollback removes the new `current` and stable cleanup link. +If rollback cannot restore a verified service, the command exits with an explicit rollback failure. +When the trap confirms `ActiveState=inactive`, keep the tunnel stopped while you complete dispatcher recovery. +If it reports `PUBLIC INGRESS CONTAINMENT FAILED`, do not assume that the tunnel stopped. +Immediately disable or delete the public ingress through the approved Cloudflare administrator path and confirm that the public endpoint is unavailable. +Only after that external containment proof should you recover the dispatcher locally. +Do not restart it until the dispatcher again binds only to `127.0.0.1:8787` and a config-free, direct anonymous request returns HTTP `401` locally. +Then rerun the complete later-deployment subshell. +Its exit trap keeps the tunnel stopped unless `ActiveState=active` and the config-free, direct public HTTP `401` proof both succeed. + +The command does not modify the dispatcher environment, systemd unit, SSH credentials, or Cloudflare credentials. +It does not update itself. +Normal deployment requires the selected release to preserve the documented cleanup allowlist. +A cleanup-scope change requires separate review and a corresponding runbook update before deployment. +After every later deployment, repeat the authenticated successful, controlled-failure, and cancellation proof jobs under [Configure GitHub and Run a Proof Job](#configure-github-and-run-a-proof-job). + ## Publish the Dispatcher With Cloudflare Tunnel Install `cloudflared` from the approved package source for Colossus. @@ -479,6 +618,14 @@ Confirm the public endpoint also rejects an anonymous request with HTTP `401`. Confirm Colossus has outbound HTTPS access to GitHub's OIDC key endpoint: ```bash +PUBLIC_HTTP_CODE="$( + curl --disable --noproxy '*' --silent --show-error --output /dev/null \ + --write-out '%{http_code}' --max-time 10 --request POST \ + --header 'Content-Type: application/json' \ + --data '{"schemaVersion":1,"target":"jetson-nvmap-gpu","candidateSha":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","workflowRunId":"1","workflowRunAttempt":1}' \ + https://jetson-e2e.example.com/v1/jobs +)" +test "$PUBLIC_HTTP_CODE" = 401 curl --fail-with-body \ https://token.actions.githubusercontent.com/.well-known/jwks ``` @@ -936,8 +1083,25 @@ sudo rm -- \ /usr/local/libexec/nemoclaw-jetson-cleanup \ /var/lib/nemoclaw-jetson-dispatch/known_hosts sudo test ! -e /usr/local/libexec/nemoclaw-jetson-cleanup +sudo test ! -L /usr/local/libexec/nemoclaw-jetson-cleanup sudo test ! -e /var/lib/nemoclaw-jetson-dispatch/known_hosts ``` After the required retention period, remove the private job state and logs. -Remove the dispatcher environment, service unit, and trusted checkout when no investigation, recovery, or retention requirement remains. +When no investigation, recovery, or retention requirement remains, remove these remaining deployment files: + +```bash +sudo rm -- \ + /etc/nemoclaw-jetson-dispatch/environment \ + /etc/systemd/system/nemoclaw-jetson-dispatch.service \ + /usr/local/sbin/nemoclaw-colossus-jetson-dispatch-deploy +sudo rm -rf -- /opt/nemoclaw-jetson-dispatch +sudo systemctl daemon-reload +sudo test ! -e /etc/nemoclaw-jetson-dispatch/environment +sudo test ! -e /etc/systemd/system/nemoclaw-jetson-dispatch.service +sudo test ! -e /usr/local/sbin/nemoclaw-colossus-jetson-dispatch-deploy +sudo test ! -e /opt/nemoclaw-jetson-dispatch +sudo test ! -L /opt/nemoclaw-jetson-dispatch +test "$(systemctl show --property=LoadState --value \ + nemoclaw-jetson-dispatch.service)" = not-found +``` diff --git a/test/e2e/support/colossus-jetson-dispatch-deploy.test.ts b/test/e2e/support/colossus-jetson-dispatch-deploy.test.ts new file mode 100644 index 00000000000..db3f623b6db --- /dev/null +++ b/test/e2e/support/colossus-jetson-dispatch-deploy.test.ts @@ -0,0 +1,498 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import { execFileSync, 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 DEPLOY_SCRIPT = path.join(process.cwd(), "tools/e2e/colossus-jetson-dispatch-deploy.sh"); +const FIXED_ORIGIN = "https://github.com/NVIDIA/NemoClaw.git"; +const temporaryDirectories: string[] = []; + +const HARNESS = String.raw` +set -euo pipefail +source "$DEPLOY_SCRIPT" + +deploy_root="$TEST_ROOT/opt/nemoclaw-jetson-dispatch" +releases_directory="$deploy_root/releases" +current_link="$deploy_root/current" +deploy_lock="$deploy_root/deploy.lock" +cleanup_executable="$TEST_ROOT/usr/local/libexec/nemoclaw-jetson-cleanup" +cleanup_link_target="$current_link/$cleanup_relative" +state_directory="$TEST_ROOT/var/lib/nemoclaw-jetson-dispatch/state" +device_lock="$state_directory/device.lock" + +mkdir -p "$state_directory" +[ "$SERVICE_LOAD_STATE" != loaded ] || : >"$TEST_ROOT/service-active" +[ "$INITIAL_DEVICE_LOCK" != 1 ] || printf '%064d\n' 0 >"$device_lock" + +effective_uid() { + printf '%s\n' "$FAKE_UID" +} + +install_directory() { + /usr/bin/install -d -m "$2" "$1" +} + +install_file() { + /usr/bin/install -m "$3" "$1" "$2" +} + +require_root_owned_directory() { + [ -d "$1" ] && [ ! -L "$1" ] +} + +require_root_owned_file() { + [ -f "$1" ] && [ ! -L "$1" ] +} + +symlink_owner() { + printf '0:0\n' +} + +acquire_deploy_lock() { + : +} + +move_replace() { + if [ "$2" = "$current_link" ] && [ -n "$FAIL_SELECT_SHA" ]; then + candidate="$(/usr/bin/readlink "$1")" + [ "${"$"}{candidate##*/}" != "$FAIL_SELECT_SHA" ] || return 1 + fi + "$NODE_EXECUTABLE" -e 'require("node:fs").renameSync(process.argv[1], process.argv[2])' "$1" "$2" +} + +move_directory() { + /bin/mv "$1" "$2" +} + +copy_file_preserving_metadata() { + /bin/cp -p "$1" "$2" +} + +files_match() { + /usr/bin/cmp -s "$1" "$2" +} + +git_exec() { + { + printf 'git' + printf '\t%s' "$@" + printf '\n' + } >>"$TEST_ROOT/git.log" + case "${"$"}{3:-}" in + fetch) + /usr/bin/git -c protocol.file.allow=always -C "$2" fetch \ + --depth=1 --no-tags "$FIXTURE_REPOSITORY" "${"$"}{!#}" + ;; + *) /usr/bin/git "$@" ;; + esac +} + +service_load_state() { + printf '%s\n' "$SERVICE_LOAD_STATE" +} + +service_active_state() { + [ "$ACTIVE_STATE_ERROR" != 1 ] || return 1 + if [ -f "$TEST_ROOT/service-active" ]; then + printf 'active\n' + else + printf 'inactive\n' + fi +} + +current_sha() { + /usr/bin/readlink "$current_link" 2>/dev/null | /usr/bin/awk -F/ '{print $NF}' +} + +systemctl_exec() { + printf 'systemctl\t%s\n' "$*" >>"$TEST_ROOT/service.log" + case "$1" in + stop) + stop_count="$(cat "$TEST_ROOT/stop-count" 2>/dev/null || printf '0')" + stop_count="$((stop_count + 1))" + printf '%s\n' "$stop_count" >"$TEST_ROOT/stop-count" + if [ "$FAIL_ROLLBACK_STOP" = 1 ] && [ "$stop_count" -gt 1 ]; then + return 1 + fi + /bin/rm -f "$TEST_ROOT/service-active" + if [ "$LEAVE_DEVICE_LOCK" = 1 ]; then + printf '%064d\n' 0 >"$device_lock" + else + /bin/rm -f "$device_lock" + fi + ;; + start) + selected="$(current_sha)" + printf 'start-sha\t%s\n' "$selected" >>"$TEST_ROOT/service.log" + [ "$selected" != "$FAIL_START_SHA" ] || return 1 + : >"$TEST_ROOT/service-active" + ;; + is-active) [ -f "$TEST_ROOT/service-active" ] ;; + *) return 1 ;; + esac +} + +ss_exec() { + if [ "$(current_sha)" = "$FAIL_VERIFY_SHA" ]; then + printf 'LISTEN 0 511 0.0.0.0:8787 0.0.0.0:*\n' + else + printf 'LISTEN 0 511 127.0.0.1:8787 0.0.0.0:*\n' + fi +} + +curl_exec() { + { + printf 'curl' + printf '\t%s' "$@" + printf '\n' + } >>"$TEST_ROOT/curl.log" + if [ "$(current_sha)" = "$FAIL_VERIFY_SHA" ]; then + printf '503' + else + printf '401' + fi +} + +sleep_exec() { + : +} + +main "$@" +`; + +interface Fixture { + directory: string; + repository: string; + firstSha: string; + secondSha: string; +} + +interface DeployOptions { + activeStateError?: boolean; + fakeUid?: string; + failRollbackStop?: boolean; + failSelectSha?: string; + serviceLoadState?: "loaded" | "not-found"; + failStartSha?: string; + failVerifySha?: string; + initialDeviceLock?: boolean; + leaveDeviceLock?: boolean; +} + +afterEach(() => { + for (const directory of temporaryDirectories.splice(0)) { + fs.rmSync(directory, { force: true, recursive: true }); + } +}); + +function git(repository: string, ...args: string[]): string { + return execFileSync("/usr/bin/git", ["-C", repository, ...args], { + encoding: "utf8", + }).trim(); +} + +function createFixture(): Fixture { + const directory = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-colossus-deploy-")); + temporaryDirectories.push(directory); + const repository = path.join(directory, "origin"); + fs.mkdirSync(path.join(repository, "tools/e2e"), { recursive: true }); + execFileSync("/usr/bin/git", ["init", "--quiet", repository]); + git(repository, "config", "user.name", "NemoClaw Test"); + git(repository, "config", "user.email", "test@example.com"); + const cleanup = path.join(repository, "tools/e2e/jetson-dispatch-cleanup.sh"); + fs.writeFileSync(cleanup, "#!/usr/bin/env bash\necho first-release\n", { mode: 0o755 }); + git(repository, "add", cleanup); + git(repository, "commit", "--quiet", "-m", "first release"); + const firstSha = git(repository, "rev-parse", "HEAD"); + fs.writeFileSync(cleanup, "#!/usr/bin/env bash\necho second-release\n", { mode: 0o755 }); + git(repository, "add", cleanup); + git(repository, "commit", "--quiet", "-m", "second release"); + return { directory, repository, firstSha, secondSha: git(repository, "rev-parse", "HEAD") }; +} + +function runDeploy( + fixture: Fixture, + args: string[], + options: DeployOptions = {}, +): ReturnType { + return spawnSync("/bin/bash", ["-c", HARNESS, "deploy-harness", ...args], { + cwd: process.cwd(), + encoding: "utf8", + env: { + ...process.env, + ACTIVE_STATE_ERROR: options.activeStateError ? "1" : "0", + DEPLOY_SCRIPT, + FAIL_ROLLBACK_STOP: options.failRollbackStop ? "1" : "0", + FAIL_SELECT_SHA: options.failSelectSha ?? "", + FAIL_START_SHA: options.failStartSha ?? "", + FAIL_VERIFY_SHA: options.failVerifySha ?? "", + FAKE_UID: options.fakeUid ?? "0", + FIXTURE_REPOSITORY: fixture.repository, + INITIAL_DEVICE_LOCK: options.initialDeviceLock ? "1" : "0", + LEAVE_DEVICE_LOCK: options.leaveDeviceLock ? "1" : "0", + NODE_EXECUTABLE: process.execPath, + SERVICE_LOAD_STATE: options.serviceLoadState ?? "not-found", + TEST_ROOT: fixture.directory, + }, + }); +} + +function deploymentPaths(fixture: Fixture) { + const root = path.join(fixture.directory, "opt/nemoclaw-jetson-dispatch"); + return { + cleanup: path.join(fixture.directory, "usr/local/libexec/nemoclaw-jetson-cleanup"), + current: path.join(root, "current"), + releases: path.join(root, "releases"), + serviceLog: path.join(fixture.directory, "service.log"), + }; +} + +function readIfPresent(file: string): string { + return fs.existsSync(file) ? fs.readFileSync(file, "utf8") : ""; +} + +describe("Colossus Jetson dispatcher deployment", () => { + it("deploys an exact commit from the fixed origin before the service is installed (#8142)", () => { + const fixture = createFixture(); + const result = runDeploy(fixture, ["--commit", fixture.firstSha]); + const paths = deploymentPaths(fixture); + + expect(result.status).toBe(0); + expect(fs.readlinkSync(paths.current)).toBe(path.join(paths.releases, fixture.firstSha)); + expect(fs.readlinkSync(paths.cleanup)).toBe( + path.join(paths.current, "tools/e2e/jetson-dispatch-cleanup.sh"), + ); + expect(fs.readFileSync(paths.cleanup, "utf8")).toContain("first-release"); + expect(fs.readdirSync(paths.releases)).toEqual([fixture.firstSha]); + expect(readIfPresent(paths.serviceLog)).toBe(""); + expect(fs.readFileSync(path.join(fixture.directory, "git.log"), "utf8")).toContain( + `remote\tadd\torigin\t${FIXED_ORIGIN}`, + ); + }); + + it("stops, switches, starts, and verifies an installed loopback service (#8142)", () => { + const fixture = createFixture(); + expect(runDeploy(fixture, ["--commit", fixture.firstSha]).status).toBe(0); + + const result = runDeploy(fixture, ["--commit", fixture.secondSha], { + serviceLoadState: "loaded", + }); + const serviceLog = fs.readFileSync(deploymentPaths(fixture).serviceLog, "utf8"); + const curlLog = fs.readFileSync(path.join(fixture.directory, "curl.log"), "utf8"); + + expect(result.status).toBe(0); + expect(serviceLog).toMatch( + /systemctl\tstop nemoclaw-jetson-dispatch\.service[\s\S]*start-sha\t[0-9a-f]{40}/u, + ); + expect(result.stdout).toContain("verified its loopback service"); + expect(curlLog).toContain("curl\t--disable\t--noproxy\t*\t--silent"); + }); + + it.each([ + ["a branch", ["--commit", "main"]], + ["a tag", ["--commit", "v0.1.0"]], + ["a URL", ["--commit", FIXED_ORIGIN]], + ["an abbreviated SHA", ["--commit", "a".repeat(12)]], + ["an uppercase SHA", ["--commit", "A".repeat(40)]], + ["an extra argument", ["--commit", "a".repeat(40), "extra"]], + ["a missing flag", ["a".repeat(40)]], + ])("rejects %s before deployment (#8142)", (_name, args) => { + const result = runDeploy(createFixture(), args); + + expect(result.status).toBe(2); + expect(result.stderr).toContain("--commit "); + }); + + it("rejects deployment by a non-root caller (#8142)", () => { + const fixture = createFixture(); + const result = runDeploy(fixture, ["--commit", fixture.firstSha], { fakeUid: "1000" }); + + expect(result.status).toBe(1); + expect(result.stderr).toContain("this command requires root"); + }); + + it("rejects a release whose configured origin is not the fixed repository (#8142)", () => { + const fixture = createFixture(); + const paths = deploymentPaths(fixture); + expect(runDeploy(fixture, ["--commit", fixture.firstSha]).status).toBe(0); + git( + path.join(paths.releases, fixture.firstSha), + "remote", + "set-url", + "origin", + "https://example.test/other.git", + ); + + const result = runDeploy(fixture, ["--commit", fixture.firstSha]); + + expect(result.status).toBe(1); + expect(result.stderr).toContain(`release origin is not ${FIXED_ORIGIN}`); + expect(fs.readlinkSync(paths.current)).toBe(path.join(paths.releases, fixture.firstSha)); + }); + + it("rejects a modified release checkout (#8142)", () => { + const fixture = createFixture(); + const paths = deploymentPaths(fixture); + expect(runDeploy(fixture, ["--commit", fixture.firstSha]).status).toBe(0); + fs.appendFileSync( + path.join(paths.releases, fixture.firstSha, "tools/e2e/jetson-dispatch-cleanup.sh"), + "modified\n", + ); + + const result = runDeploy(fixture, ["--commit", fixture.firstSha]); + + expect(result.status).toBe(1); + expect(result.stderr).toContain("release checkout is modified"); + }); + + it("rejects a current link that does not select one managed release (#8142)", () => { + const fixture = createFixture(); + const paths = deploymentPaths(fixture); + expect(runDeploy(fixture, ["--commit", fixture.firstSha]).status).toBe(0); + fs.unlinkSync(paths.current); + fs.symlinkSync(fixture.repository, paths.current); + + const result = runDeploy(fixture, ["--commit", fixture.secondSha]); + + expect(result.status).toBe(1); + expect(result.stderr).toContain("does not select one managed release"); + expect(fs.readlinkSync(paths.current)).toBe(fixture.repository); + }); + + it("rolls back code and cleanup when service startup fails (#8142)", () => { + const fixture = createFixture(); + const paths = deploymentPaths(fixture); + expect(runDeploy(fixture, ["--commit", fixture.firstSha]).status).toBe(0); + + const result = runDeploy(fixture, ["--commit", fixture.secondSha], { + failStartSha: fixture.secondSha, + serviceLoadState: "loaded", + }); + + expect(result.status).toBe(1); + expect(result.stderr).toContain("previous deployment state was restored"); + expect(fs.readlinkSync(paths.current)).toBe(path.join(paths.releases, fixture.firstSha)); + expect(fs.readFileSync(paths.cleanup, "utf8")).toContain("first-release"); + }); + + it("rejects an inconclusive service state after stopping (#8142)", () => { + const fixture = createFixture(); + const paths = deploymentPaths(fixture); + expect(runDeploy(fixture, ["--commit", fixture.firstSha]).status).toBe(0); + + const result = runDeploy(fixture, ["--commit", fixture.secondSha], { + activeStateError: true, + serviceLoadState: "loaded", + }); + + expect(result.status).toBe(1); + expect(result.stderr).toContain( + "could not inspect nemoclaw-jetson-dispatch.service after stop", + ); + expect(fs.readlinkSync(paths.current)).toBe(path.join(paths.releases, fixture.firstSha)); + }); + + it("does not switch releases when service cleanup leaves the device lock (#8142)", () => { + const fixture = createFixture(); + const paths = deploymentPaths(fixture); + expect(runDeploy(fixture, ["--commit", fixture.firstSha]).status).toBe(0); + + const result = runDeploy(fixture, ["--commit", fixture.secondSha], { + leaveDeviceLock: true, + serviceLoadState: "loaded", + }); + + expect(result.status).toBe(1); + expect(result.stderr).toContain("recover cleanup before deployment"); + expect(fs.readlinkSync(paths.current)).toBe(path.join(paths.releases, fixture.firstSha)); + expect(fs.readFileSync(paths.cleanup, "utf8")).toContain("first-release"); + }); + + it("rejects bootstrap when a stale device lock remains (#8142)", () => { + const fixture = createFixture(); + const paths = deploymentPaths(fixture); + + const result = runDeploy(fixture, ["--commit", fixture.firstSha], { + initialDeviceLock: true, + }); + + expect(result.status).toBe(1); + expect(result.stderr).toContain("recover cleanup before deployment"); + expect(fs.existsSync(paths.current)).toBe(false); + expect(fs.existsSync(paths.cleanup)).toBe(false); + expect(fs.existsSync(paths.releases)).toBe(true); + expect(fs.readdirSync(paths.releases)).toEqual([]); + }); + + it("redeploys the selected commit without creating another release (#8142)", () => { + const fixture = createFixture(); + const paths = deploymentPaths(fixture); + + expect(runDeploy(fixture, ["--commit", fixture.firstSha]).status).toBe(0); + expect(runDeploy(fixture, ["--commit", fixture.firstSha]).status).toBe(0); + + expect(fs.readdirSync(paths.releases)).toEqual([fixture.firstSha]); + expect(fs.readlinkSync(paths.current)).toBe(path.join(paths.releases, fixture.firstSha)); + expect(fs.readFileSync(paths.cleanup, "utf8")).toContain("first-release"); + }); + + it("rolls back code and cleanup when loopback verification fails (#8142)", () => { + const fixture = createFixture(); + const paths = deploymentPaths(fixture); + expect(runDeploy(fixture, ["--commit", fixture.firstSha]).status).toBe(0); + + const result = runDeploy(fixture, ["--commit", fixture.secondSha], { + failVerifySha: fixture.secondSha, + serviceLoadState: "loaded", + }); + const serviceLog = fs.readFileSync(paths.serviceLog, "utf8"); + + expect(result.status).toBe(1); + expect(result.stderr).toContain("previous deployment state was restored"); + expect(fs.readlinkSync(paths.current)).toBe(path.join(paths.releases, fixture.firstSha)); + expect(fs.readFileSync(paths.cleanup, "utf8")).toContain("first-release"); + expect(serviceLog).toContain(`start-sha\t${fixture.secondSha}`); + expect(serviceLog).toContain(`start-sha\t${fixture.firstSha}`); + }); + + it("keeps code and cleanup on the prior release when selection fails (#8142)", () => { + const fixture = createFixture(); + const paths = deploymentPaths(fixture); + expect(runDeploy(fixture, ["--commit", fixture.firstSha]).status).toBe(0); + + const result = runDeploy(fixture, ["--commit", fixture.secondSha], { + failSelectSha: fixture.secondSha, + serviceLoadState: "loaded", + }); + + expect(result.status).toBe(1); + expect(result.stderr).toContain("previous deployment state was restored"); + expect(fs.readlinkSync(paths.current)).toBe(path.join(paths.releases, fixture.firstSha)); + expect(fs.readlinkSync(paths.cleanup)).toBe( + path.join(paths.current, "tools/e2e/jetson-dispatch-cleanup.sh"), + ); + expect(fs.readFileSync(paths.cleanup, "utf8")).toContain("first-release"); + }); + + it("keeps the new code and cleanup paired when rollback cannot stop the service (#8142)", () => { + const fixture = createFixture(); + const paths = deploymentPaths(fixture); + expect(runDeploy(fixture, ["--commit", fixture.firstSha]).status).toBe(0); + + const result = runDeploy(fixture, ["--commit", fixture.secondSha], { + failRollbackStop: true, + failVerifySha: fixture.secondSha, + serviceLoadState: "loaded", + }); + + expect(result.status).toBe(1); + expect(result.stderr).toContain("rollback did not restore a verified service"); + expect(fs.readlinkSync(paths.current)).toBe(path.join(paths.releases, fixture.secondSha)); + expect(fs.readFileSync(paths.cleanup, "utf8")).toContain("second-release"); + }); +}); diff --git a/test/e2e/support/jetson-dispatch-worker.test.ts b/test/e2e/support/jetson-dispatch-worker.test.ts index eb366227406..01cf8301673 100644 --- a/test/e2e/support/jetson-dispatch-worker.test.ts +++ b/test/e2e/support/jetson-dispatch-worker.test.ts @@ -1,6 +1,7 @@ // 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"; @@ -108,19 +109,116 @@ function loadConfig(files = deploymentFiles()) { } describe("Colossus SSH worker deployment boundary", () => { - it("pins dispatcher deployment to one reviewed commit before service startup (#8142)", () => { - const verification = 'test "$(sudo git -C /opt/nemoclaw-jetson-dispatch rev-parse HEAD)" ='; + it("uses the fixed deployment command before service startup (#8142)", () => { + const deployment = + 'sudo /usr/local/sbin/nemoclaw-colossus-jetson-dispatch-deploy \\\n --commit "$REVIEWED_COMMIT_SHA"'; expect(dispatcherRunbook).toContain( - 'fetch --depth=1 --no-tags origin \\\n "$REVIEWED_COMMIT_SHA"', + "tools/e2e/colossus-jetson-dispatch-deploy.sh \\\n /usr/local/sbin/nemoclaw-colossus-jetson-dispatch-deploy", ); - expect(dispatcherRunbook).toContain("checkout --detach FETCH_HEAD"); - expect(dispatcherRunbook).toContain(verification); - expect(dispatcherRunbook.indexOf(verification)).toBeLessThan( + expect(dispatcherRunbook).toContain(deployment); + expect(dispatcherRunbook).toContain("WorkingDirectory=/opt/nemoclaw-jetson-dispatch/current"); + expect(dispatcherRunbook.indexOf(deployment)).toBeLessThan( dispatcherRunbook.indexOf("## Configure the Dispatcher Service"), ); + expect(dispatcherRunbook).not.toContain("sudo git -C /opt/nemoclaw-jetson-dispatch init"); expect(dispatcherRunbook).not.toContain("git clone --branch main"); }); + it("keeps public ingress stopped until a later release passes local verification (#8142)", () => { + const section = dispatcherRunbook.slice( + dispatcherRunbook.indexOf("## Deploy a Later Reviewed Commit"), + dispatcherRunbook.indexOf("## Publish the Dispatcher With Cloudflare Tunnel"), + ); + const stopTunnel = "sudo systemctl stop nemoclaw-jetson-tunnel.service"; + const deploy = "sudo /usr/local/sbin/nemoclaw-colossus-jetson-dispatch-deploy"; + const startTunnel = "sudo systemctl start nemoclaw-jetson-tunnel.service"; + const publicProof = 'test "$PUBLIC_HTTP_CODE" = 401'; + + expect(section).toContain("set -euo pipefail"); + expect(section.indexOf(stopTunnel)).toBeLessThan(section.indexOf(deploy)); + expect(section.indexOf(deploy)).toBeLessThan(section.indexOf(startTunnel)); + expect(section.indexOf(startTunnel)).toBeLessThan(section.indexOf(publicProof)); + expect(section.indexOf(publicProof)).toBeLessThan(section.indexOf("tunnel_verified=1")); + expect(section).toContain("trap stop_unverified_tunnel EXIT"); + expect(section).toContain("curl --disable --noproxy '*'"); + }); + + it.each([ + { + expectedLog: ["stop", "deploy", "start", "stop"], + expectedState: "inactive\n", + failContainmentStop: false, + name: "stops public ingress when the public proof fails", + }, + { + expectedLog: ["stop", "deploy", "start", "stop-failed"], + expectedState: "active\n", + failContainmentStop: true, + name: "reports when public-ingress containment fails", + }, + ])("$name (#8142)", ({ expectedLog, expectedState, failContainmentStop }) => { + const section = dispatcherRunbook.slice( + dispatcherRunbook.indexOf("## Deploy a Later Reviewed Commit"), + dispatcherRunbook.indexOf("## Publish the Dispatcher With Cloudflare Tunnel"), + ); + const block = section.match(/```bash\n([\s\S]*?)\n```/u)?.[1]; + expect(block).toBeDefined(); + const directory = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-tunnel-deploy-test-")); + temporaryDirectories.push(directory); + const log = path.join(directory, "service.log"); + const state = path.join(directory, "tunnel.state"); + const stopCount = path.join(directory, "stop.count"); + fs.writeFileSync(state, "active\n"); + fs.writeFileSync( + path.join(directory, "sudo"), + `#!/bin/sh +set -eu +case "$1:$2" in + systemctl:stop) + count="$(cat "$STOP_COUNT" 2>/dev/null || printf '0')" + count="$((count + 1))" + printf '%s\\n' "$count" >"$STOP_COUNT" + if [ "$FAIL_CONTAINMENT_STOP" = 1 ] && [ "$count" -gt 1 ]; then + printf 'stop-failed\\n' >>"$SERVICE_LOG" + exit 5 + fi + printf 'stop\\n' >>"$SERVICE_LOG" + printf 'inactive\\n' >"$TUNNEL_STATE" + ;; + systemctl:start) printf 'start\\n' >>"$SERVICE_LOG"; printf 'active\\n' >"$TUNNEL_STATE" ;; + systemctl:show) cat "$TUNNEL_STATE" ;; + /usr/local/sbin/nemoclaw-colossus-jetson-dispatch-deploy:--commit) printf 'deploy\\n' >>"$SERVICE_LOG" ;; + *) exit 1 ;; +esac +`, + { mode: 0o755 }, + ); + fs.writeFileSync(path.join(directory, "curl"), "#!/bin/sh\nprintf '503'\n", { mode: 0o755 }); + + const result = spawnSync("/bin/bash", ["-c", block!], { + encoding: "utf8", + env: { + ...process.env, + FAIL_CONTAINMENT_STOP: failContainmentStop ? "1" : "0", + PATH: `${directory}:${process.env.PATH ?? ""}`, + SERVICE_LOG: log, + STOP_COUNT: stopCount, + TUNNEL_STATE: state, + }, + }); + + expect(result.status).not.toBe(0); + expect(fs.readFileSync(log, "utf8").trim().split("\n")).toEqual(expectedLog); + expect(fs.readFileSync(state, "utf8")).toBe(expectedState); + if (failContainmentStop) { + expect(result.stderr).toContain( + "PUBLIC INGRESS CONTAINMENT FAILED: tunnel stop status=5; ActiveState=active", + ); + } else { + expect(result.stderr).not.toContain("PUBLIC INGRESS CONTAINMENT FAILED"); + } + }); + it("loads fixed SSH, host-key, timeout, and cleanup configuration (#8142)", () => { const files = deploymentFiles(); expect(loadConfig(files)).toEqual({ @@ -295,6 +393,78 @@ describe("Colossus SSH worker deployment boundary", () => { ).toThrow("must be a regular file"); }); + it("accepts only the exact root-owned current-release cleanup link (#8142)", () => { + const files = deploymentFiles(); + const cleanupExecutable = "/usr/local/libexec/nemoclaw-jetson-cleanup"; + const cleanupTarget = + "/opt/nemoclaw-jetson-dispatch/current/tools/e2e/jetson-dispatch-cleanup.sh"; + const localLink = path.join(files.stateDirectory, "managed-cleanup-link"); + fs.symlinkSync(files.cleanupExecutable, localLink); + const realLstatSync = fs.lstatSync.bind(fs); + const realReadlinkSync = fs.readlinkSync.bind(fs); + const localLinkStat = realLstatSync(localLink); + const rootLinkStat = Object.assign( + Object.create(Object.getPrototypeOf(localLinkStat)), + localLinkStat, + { uid: 0 }, + ) as fs.Stats; + const nonRootLinkStat = Object.assign( + Object.create(Object.getPrototypeOf(localLinkStat)), + localLinkStat, + { uid: 1000 }, + ) as fs.Stats; + const secureTargetStat = realLstatSync(files.cleanupExecutable); + const unsafeTargetStat = Object.assign( + Object.create(Object.getPrototypeOf(secureTargetStat)), + secureTargetStat, + { mode: secureTargetStat.mode | 0o022 }, + ) as fs.Stats; + let selectedTarget = "/tmp/unmanaged-cleanup"; + let managedLinkStat = rootLinkStat; + let managedTargetStat = secureTargetStat; + const lstat = vi.spyOn(fs, "lstatSync").mockImplementation((candidate, options) => { + if (String(candidate) === cleanupExecutable) return managedLinkStat; + if (String(candidate) === cleanupTarget) return managedTargetStat; + return realLstatSync(candidate, options as never); + }); + const readlink = vi + .spyOn(fs, "readlinkSync") + .mockImplementation(((candidate, options) => + String(candidate) === cleanupExecutable + ? selectedTarget + : realReadlinkSync(candidate, options as never)) as typeof fs.readlinkSync); + + try { + const env = { + ...environment(files), + JETSON_DISPATCH_CLEANUP_EXECUTABLE: cleanupExecutable, + }; + expect(() => + loadSshJetsonWorkerConfig({ stateDirectory: files.stateDirectory }, env), + ).toThrow("must select the managed current-release cleanup program"); + + selectedTarget = cleanupTarget; + managedLinkStat = nonRootLinkStat; + expect(() => + loadSshJetsonWorkerConfig({ stateDirectory: files.stateDirectory }, env), + ).toThrow("symbolic link must be owned by root"); + + managedLinkStat = rootLinkStat; + managedTargetStat = unsafeTargetStat; + expect(() => + loadSshJetsonWorkerConfig({ stateDirectory: files.stateDirectory }, env), + ).toThrow("must not be group- or world-writable"); + + managedTargetStat = secureTargetStat; + expect( + loadSshJetsonWorkerConfig({ stateDirectory: files.stateDirectory }, env), + ).toMatchObject({ cleanupExecutable }); + } finally { + readlink.mockRestore(); + lstat.mockRestore(); + } + }); + it("invokes the fixed cleanup executable without request-controlled arguments (#8142)", async () => { const files = deploymentFiles(); const jobId = "b".repeat(64); diff --git a/test/helpers/vitest-watch-triggers.ts b/test/helpers/vitest-watch-triggers.ts index 02f1ff0403b..37a36a65018 100644 --- a/test/helpers/vitest-watch-triggers.ts +++ b/test/helpers/vitest-watch-triggers.ts @@ -96,6 +96,10 @@ export const vitestWatchTriggerPatterns: VitestWatchTriggerPattern[] = [ pattern: /(?:^|\/)tools\/e2e\/jetson-dispatch-cleanup\.sh$/, testsToRun: runTests("test/e2e/support/jetson-dispatch-worker.test.ts"), }, + { + pattern: /(?:^|\/)tools\/e2e\/colossus-jetson-dispatch-deploy\.sh$/, + testsToRun: runTests("test/e2e/support/colossus-jetson-dispatch-deploy.test.ts"), + }, { pattern: /(?:^|\/)(?:\.github\/workflows\/base-image\.yaml|scripts\/export-managed-base-image-contract\.sh)$/, diff --git a/test/vitest-watch-triggers.test.ts b/test/vitest-watch-triggers.test.ts index a325a740e29..c18de59bf04 100644 --- a/test/vitest-watch-triggers.test.ts +++ b/test/vitest-watch-triggers.test.ts @@ -62,6 +62,7 @@ const OPAQUE_INPUTS = [ "test/e2e/lib/ci-compatible-inference.sh", "scripts/setup-jetson.sh", "tools/e2e/jetson-dispatch-cleanup.sh", + "tools/e2e/colossus-jetson-dispatch-deploy.sh", ".github/workflows/base-image.yaml", "scripts/export-managed-base-image-contract.sh", "scripts/checks/validate-managed-base-index.sh", @@ -129,6 +130,9 @@ describe("Vitest opaque-input watch triggers", () => { expect(triggeredBy("tools/e2e/jetson-dispatch-cleanup.sh")).toEqual([ "test/e2e/support/jetson-dispatch-worker.test.ts", ]); + expect(triggeredBy("tools/e2e/colossus-jetson-dispatch-deploy.sh")).toEqual([ + "test/e2e/support/colossus-jetson-dispatch-deploy.test.ts", + ]); expect(triggeredBy(".github/workflows/base-image.yaml")).toEqual([ "test/managed-base-image-contract.test.ts", "test/managed-image-publication-workflow.test.ts", diff --git a/tools/e2e/colossus-jetson-dispatch-deploy.sh b/tools/e2e/colossus-jetson-dispatch-deploy.sh new file mode 100755 index 00000000000..3b8ce48a1f0 --- /dev/null +++ b/tools/e2e/colossus-jetson-dispatch-deploy.sh @@ -0,0 +1,438 @@ +#!/usr/bin/env bash +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set -euo pipefail + +PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin +export PATH +umask 022 + +fixed_origin=https://github.com/NVIDIA/NemoClaw.git +deploy_root=/opt/nemoclaw-jetson-dispatch +releases_directory="$deploy_root/releases" +current_link="$deploy_root/current" +deploy_lock="$deploy_root/deploy.lock" +cleanup_relative=tools/e2e/jetson-dispatch-cleanup.sh +cleanup_executable=/usr/local/libexec/nemoclaw-jetson-cleanup +cleanup_link_target="$current_link/$cleanup_relative" +state_directory=/var/lib/nemoclaw-jetson-dispatch/state +device_lock="$state_directory/device.lock" +service_name=nemoclaw-jetson-dispatch.service +service_port=8787 + +staging_directory="" +temporary_link="" +cleanup_stage="" + +usage() { + echo "Usage: nemoclaw-colossus-jetson-dispatch-deploy --commit " >&2 +} + +fail() { + echo "Colossus Jetson dispatcher deployment failed: $*" >&2 + exit 1 +} + +effective_uid() { + /usr/bin/id -u +} + +git_exec() { + /usr/bin/env \ + -u GIT_ALTERNATE_OBJECT_DIRECTORIES \ + -u GIT_COMMON_DIR \ + -u GIT_CONFIG_PARAMETERS \ + -u GIT_DIR \ + -u GIT_EXEC_PATH \ + -u GIT_OBJECT_DIRECTORY \ + -u GIT_PROXY_COMMAND \ + -u GIT_SSH \ + -u GIT_SSH_COMMAND \ + -u GIT_SSL_NO_VERIFY \ + -u GIT_TEMPLATE_DIR \ + -u GIT_WORK_TREE \ + GIT_CONFIG_COUNT=0 \ + GIT_CONFIG_GLOBAL=/dev/null \ + GIT_CONFIG_NOSYSTEM=1 \ + HOME=/nonexistent \ + /usr/bin/git \ + -c core.hooksPath=/dev/null \ + -c credential.helper= \ + -c http.sslVerify=true \ + -c protocol.ext.allow=never \ + -c protocol.file.allow=never \ + "$@" +} + +systemctl_exec() { + /usr/bin/systemctl "$@" +} + +ss_exec() { + /usr/bin/ss "$@" +} + +curl_exec() { + /usr/bin/curl "$@" +} + +sleep_exec() { + /usr/bin/sleep "$@" +} + +symlink_owner() { + /usr/bin/stat -c '%u:%g' "$1" +} + +install_directory() { + local path="$1" mode="$2" + /usr/bin/install -d -o root -g root -m "$mode" "$path" +} + +move_replace() { + /usr/bin/mv -Tf -- "$1" "$2" +} + +move_directory() { + /usr/bin/mv -- "$1" "$2" +} + +require_root_owned_directory() { + local path="$1" expected_mode="$2" metadata + [ -d "$path" ] && [ ! -L "$path" ] || fail "$path must be a directory, not a symbolic link" + metadata="$(/usr/bin/stat -c '%u:%g:%a' "$path")" || fail "could not inspect $path" + if [ "$metadata" != "0:0:$expected_mode" ]; then + fail "$path must be owned by root:root with mode $expected_mode" + fi +} + +require_root_owned_file() { + local path="$1" expected_mode="$2" metadata + [ -f "$path" ] && [ ! -L "$path" ] || fail "$path must be a regular file, not a symbolic link" + metadata="$(/usr/bin/stat -c '%u:%g:%a' "$path")" || fail "could not inspect $path" + if [ "$metadata" != "0:0:$expected_mode" ]; then + fail "$path must be owned by root:root with mode $expected_mode" + fi +} + +cleanup_temporary_paths() { + if [ -n "$staging_directory" ] && [[ "$staging_directory" == "$releases_directory"/.* ]]; then + rm -rf -- "$staging_directory" + fi + if [ -n "$temporary_link" ] && [[ "$temporary_link" == "$deploy_root"/.current.* ]]; then + rm -f -- "$temporary_link" + fi + if [ -n "$cleanup_stage" ] && [[ "$cleanup_stage" == "${cleanup_executable%/*}"/.nemoclaw-jetson-cleanup.* ]]; then + rm -f -- "$cleanup_stage" + fi +} + +trap cleanup_temporary_paths EXIT + +require_root() { + [ "$(effective_uid)" = 0 ] || fail "this command requires root" +} + +parse_commit() { + [ "$#" -eq 2 ] && [ "$1" = "--commit" ] && [[ "$2" =~ ^[a-f0-9]{40}$ ]] || { + usage + exit 2 + } + printf '%s\n' "$2" +} + +ensure_layout() { + install_directory "$deploy_root" 0755 + install_directory "$releases_directory" 0755 + install_directory "${cleanup_executable%/*}" 0755 + require_root_owned_directory "$deploy_root" 755 + require_root_owned_directory "$releases_directory" 755 + require_root_owned_directory "${cleanup_executable%/*}" 755 +} + +acquire_deploy_lock() { + if [ -e "$deploy_lock" ] || [ -L "$deploy_lock" ]; then + require_root_owned_file "$deploy_lock" 600 + else + (umask 077 && : >"$deploy_lock") + chown root:root "$deploy_lock" || fail "could not set deployment-lock ownership" + chmod 0600 "$deploy_lock" || fail "could not set deployment-lock permissions" + fi + exec 9<>"$deploy_lock" + /usr/bin/flock -n 9 || fail "another deployment is running" +} + +verify_release() { + local release="$1" sha="$2" observed + require_root_owned_directory "$release" 755 + if ! observed="$(git_exec -C "$release" config --get remote.origin.url)"; then + fail "could not read the release origin" + fi + [ "$observed" = "$fixed_origin" ] || fail "release origin is not $fixed_origin" + if ! observed="$(git_exec -C "$release" rev-parse --verify HEAD)"; then + fail "could not read the release commit" + fi + [ "$observed" = "$sha" ] || fail "release commit does not match $sha" + if ! observed="$(git_exec -C "$release" status --porcelain=v1 --untracked-files=all)"; then + fail "could not inspect the release checkout" + fi + [ -z "$observed" ] || fail "release checkout is modified" + require_root_owned_file "$release/$cleanup_relative" 755 +} + +prepare_release() { + local sha="$1" + local release="$releases_directory/$sha" + if [ -e "$release" ] || [ -L "$release" ]; then + verify_release "$release" "$sha" + printf '%s\n' "$release" + return + fi + + staging_directory="$(/usr/bin/mktemp -d "$releases_directory/.${sha}.XXXXXX")" + chmod 0755 "$staging_directory" || fail "could not set release-directory permissions" + git_exec -C "$staging_directory" init --quiet || fail "could not initialize the release checkout" + if ! git_exec -C "$staging_directory" remote add origin "$fixed_origin"; then + fail "could not set the fixed release origin" + fi + if ! git_exec -C "$staging_directory" fetch --depth=1 --no-tags origin "$sha"; then + fail "could not fetch commit $sha from the fixed origin" + fi + if ! git_exec -C "$staging_directory" checkout --detach --quiet FETCH_HEAD; then + fail "could not check out commit $sha" + fi + verify_release "$staging_directory" "$sha" + move_directory "$staging_directory" "$release" || fail "could not install release $sha" + staging_directory="" + verify_release "$release" "$sha" + printf '%s\n' "$release" +} + +service_load_state() { + systemctl_exec show --property=LoadState --value "$service_name" +} + +service_active_state() { + systemctl_exec show --property=ActiveState --value "$service_name" +} + +device_lock_is_absent() { + [ ! -e "$device_lock" ] && [ ! -L "$device_lock" ] +} + +require_device_lock_absent() { + device_lock_is_absent || fail "cleanup left $device_lock; recover cleanup before deployment" +} + +stop_installed_service() { + local active_state + systemctl_exec stop "$service_name" || fail "could not stop $service_name" + if ! active_state="$(service_active_state)"; then + fail "could not inspect $service_name after stop" + fi + [ "$active_state" = inactive ] || fail "$service_name has unexpected state after stop: $active_state" + require_device_lock_absent +} + +selected_release() { + local target sha + if [ ! -e "$current_link" ] && [ ! -L "$current_link" ]; then + return 1 + fi + [ -L "$current_link" ] || fail "$current_link must be a symbolic link" + target="$(/usr/bin/readlink "$current_link")" || fail "could not read $current_link" + sha="${target##*/}" + if [[ ! "$sha" =~ ^[a-f0-9]{40}$ ]] || [ "$target" != "$releases_directory/$sha" ]; then + fail "$current_link does not select one managed release" + fi + verify_release "$target" "$sha" + printf '%s\n' "$target" +} + +cleanup_link_matches() { + local metadata target + [ -L "$cleanup_executable" ] || return 1 + target="$(/usr/bin/readlink "$cleanup_executable")" || return 1 + [ "$target" = "$cleanup_link_target" ] || return 1 + metadata="$(symlink_owner "$cleanup_executable")" || return 1 + [ "$metadata" = 0:0 ] +} + +validate_prior_cleanup_selection() { + local previous_release="$1" + if [ -n "$previous_release" ]; then + cleanup_link_matches || fail "$cleanup_executable does not select the managed current release" + return + fi + if [ ! -e "$cleanup_executable" ] && [ ! -L "$cleanup_executable" ]; then + return + fi + cleanup_link_matches || fail "$cleanup_executable exists without one managed current release" +} + +atomic_install_cleanup_link() { + cleanup_link_matches && return 0 + if [ -e "$cleanup_executable" ] || [ -L "$cleanup_executable" ]; then + return 1 + fi + cleanup_stage="$(/usr/bin/mktemp "${cleanup_executable%/*}/.nemoclaw-jetson-cleanup.XXXXXX")" + rm -f -- "$cleanup_stage" + ln -s -- "$cleanup_link_target" "$cleanup_stage" || return 1 + move_replace "$cleanup_stage" "$cleanup_executable" || { + rm -f -- "$cleanup_stage" + cleanup_stage="" + return 1 + } + cleanup_stage="" + cleanup_link_matches +} + +atomic_select_release() { + local release="$1" + temporary_link="$deploy_root/.current.${release##*/}.$$" + [ ! -e "$temporary_link" ] && [ ! -L "$temporary_link" ] || return 1 + ln -s -- "$release" "$temporary_link" || { + temporary_link="" + return 1 + } + move_replace "$temporary_link" "$current_link" || { + rm -f -- "$temporary_link" + temporary_link="" + return 1 + } + temporary_link="" + [ -L "$current_link" ] && [ "$(/usr/bin/readlink "$current_link")" = "$release" ] +} + +loopback_service_responds() { + local listeners http_code + systemctl_exec is-active --quiet "$service_name" || return 1 + listeners="$(ss_exec -H -ltn "sport = :$service_port")" || return 1 + [ -n "$listeners" ] || return 1 + printf '%s\n' "$listeners" | /usr/bin/awk -v expected="127.0.0.1:$service_port" ' + NF < 4 || $4 != expected { invalid = 1 } + END { exit invalid || NR == 0 } + ' || return 1 + http_code="$( + curl_exec \ + --disable \ + --noproxy '*' \ + --silent \ + --show-error \ + --output /dev/null \ + --write-out '%{http_code}' \ + --max-time 5 \ + --request POST \ + --header 'Content-Type: application/json' \ + --data '{"schemaVersion":1,"target":"jetson-nvmap-gpu","candidateSha":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","workflowRunId":"1","workflowRunAttempt":1}' \ + "http://127.0.0.1:$service_port/v1/jobs" + )" || return 1 + [ "$http_code" = 401 ] +} + +verify_loopback_service() { + local _ + for _ in {1..20}; do + loopback_service_responds && return 0 + sleep_exec 0.25 + done + return 1 +} + +start_and_verify_service() { + systemctl_exec start "$service_name" || return 1 + verify_loopback_service +} + +restore_cleanup_selection() { + local cleanup_was_present="$1" + if [ "$cleanup_was_present" = 1 ]; then + cleanup_link_matches + else + rm -f -- "$cleanup_executable" + fi +} + +restore_release_selection() { + local previous_release="$1" + if [ -n "$previous_release" ]; then + atomic_select_release "$previous_release" + return + fi + if [ -L "$current_link" ]; then + rm -f -- "$current_link" + elif [ -e "$current_link" ]; then + return 1 + fi +} + +rollback_deployment() { + local previous_release="$1" cleanup_was_present="$2" service_installed="$3" rollback_failed=0 active_state + if [ "$service_installed" = 1 ]; then + systemctl_exec stop "$service_name" || return 1 + active_state="$(service_active_state)" || return 1 + [ "$active_state" = inactive ] || return 1 + device_lock_is_absent || return 1 + fi + restore_release_selection "$previous_release" || rollback_failed=1 + restore_cleanup_selection "$cleanup_was_present" || rollback_failed=1 + if [ "$service_installed" = 1 ] && [ -n "$previous_release" ]; then + start_and_verify_service || rollback_failed=1 + fi + [ "$rollback_failed" = 0 ] +} + +activate_release() { + local release="$1" service_installed="$2" + atomic_install_cleanup_link || return 1 + atomic_select_release "$release" || return 1 + cleanup_link_matches || return 1 + [ "$(/usr/bin/readlink "$current_link")" = "$release" ] || return 1 + if [ "$service_installed" = 1 ]; then + start_and_verify_service || return 1 + fi +} + +main() { + local sha release load_state service_installed=0 previous_release="" cleanup_was_present=0 + require_root + sha="$(parse_commit "$@")" + ensure_layout + acquire_deploy_lock + + load_state="$(service_load_state)" || fail "could not inspect $service_name" + if [ "$load_state" = loaded ]; then + service_installed=1 + stop_installed_service + elif [ "$load_state" != not-found ]; then + fail "$service_name has unsupported load state: $load_state" + else + require_device_lock_absent + fi + + previous_release="$(selected_release || true)" + validate_prior_cleanup_selection "$previous_release" + [ -n "$previous_release" ] && cleanup_was_present=1 + if [ "$service_installed" = 1 ] && [ -z "$previous_release" ]; then + fail "$service_name is installed without one managed current release" + fi + release="$(prepare_release "$sha")" + + if ! activate_release "$release" "$service_installed"; then + if rollback_deployment "$previous_release" "$cleanup_was_present" "$service_installed"; then + fail "release $sha activation or verification failed; the previous deployment state was restored" + fi + fail "release $sha activation or verification failed, and rollback did not restore a verified service" + fi + + if [ "$service_installed" = 1 ]; then + echo "Deployed Colossus Jetson dispatcher release $sha and verified its loopback service" + else + echo "Deployed Colossus Jetson dispatcher release $sha; install the systemd service before starting it" + fi +} + +if [[ "${BASH_SOURCE[0]}" = "$0" ]]; then + main "$@" +fi diff --git a/tools/e2e/jetson-dispatch-worker.mts b/tools/e2e/jetson-dispatch-worker.mts index 5a3d8a8537b..677532d80cb 100644 --- a/tools/e2e/jetson-dispatch-worker.mts +++ b/tools/e2e/jetson-dispatch-worker.mts @@ -17,6 +17,9 @@ import { readPrivateRegularFile, writePrivateRegularFile } from "./private-file. const MAX_PROCESS_OUTPUT_BYTES = 4 * 1024 * 1024; const JETSON_SSH_DESTINATION = "nvidia@192.168.55.1"; +const JETSON_CLEANUP_EXECUTABLE = "/usr/local/libexec/nemoclaw-jetson-cleanup"; +const JETSON_CLEANUP_TARGET = + "/opt/nemoclaw-jetson-dispatch/current/tools/e2e/jetson-dispatch-cleanup.sh"; const SAFE_PROCESS_ENV = { LANG: "C.UTF-8", PATH: "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", @@ -323,6 +326,25 @@ function requireSecureFile( } } +function requireSecureCleanupExecutable(file: string): void { + if (file !== JETSON_CLEANUP_EXECUTABLE) { + requireSecureFile(file, { executable: true }); + return; + } + const linkStat = fs.lstatSync(file); + if (!linkStat.isSymbolicLink()) { + requireSecureFile(file, { executable: true }); + return; + } + if (linkStat.uid !== 0) { + throw new Error(`${file} symbolic link must be owned by root`); + } + if (fs.readlinkSync(file) !== JETSON_CLEANUP_TARGET) { + throw new Error(`${file} must select the managed current-release cleanup program`); + } + requireSecureFile(JETSON_CLEANUP_TARGET, { executable: true }); +} + function positiveIntegerEnvironment( value: string | undefined, name: string, @@ -355,7 +377,7 @@ export function loadSshJetsonWorkerConfig( const cleanupExecutable = env.JETSON_DISPATCH_CLEANUP_EXECUTABLE ?? ""; requireSecureFile(identityFile, { private: true }); requireSecureFile(knownHostsFile, {}); - requireSecureFile(cleanupExecutable, { executable: true }); + requireSecureCleanupExecutable(cleanupExecutable); return { cleanupExecutable, destination, From 938473af6a9820568d4701182b6b45a12f35cba5 Mon Sep 17 00:00:00 2001 From: San Dang Date: Tue, 11 Aug 2026 01:57:55 +0700 Subject: [PATCH 19/34] fix(e2e): make Colossus deploy checks explicit --- .../support/jetson-dispatch-worker.test.ts | 33 ++++++++++++------- tools/e2e/colossus-jetson-dispatch-deploy.sh | 16 ++++++--- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/test/e2e/support/jetson-dispatch-worker.test.ts b/test/e2e/support/jetson-dispatch-worker.test.ts index 01cf8301673..fba7969c53d 100644 --- a/test/e2e/support/jetson-dispatch-worker.test.ts +++ b/test/e2e/support/jetson-dispatch-worker.test.ts @@ -145,18 +145,27 @@ describe("Colossus SSH worker deployment boundary", () => { it.each([ { + expectedContainmentDiagnostics: [], expectedLog: ["stop", "deploy", "start", "stop"], expectedState: "inactive\n", failContainmentStop: false, name: "stops public ingress when the public proof fails", }, { + expectedContainmentDiagnostics: [ + "PUBLIC INGRESS CONTAINMENT FAILED: tunnel stop status=5; ActiveState=active; inspection status=0", + ], expectedLog: ["stop", "deploy", "start", "stop-failed"], expectedState: "active\n", failContainmentStop: true, name: "reports when public-ingress containment fails", }, - ])("$name (#8142)", ({ expectedLog, expectedState, failContainmentStop }) => { + ])("$name (#8142)", ({ + expectedContainmentDiagnostics, + expectedLog, + expectedState, + failContainmentStop, + }) => { const section = dispatcherRunbook.slice( dispatcherRunbook.indexOf("## Deploy a Later Reviewed Commit"), dispatcherRunbook.indexOf("## Publish the Dispatcher With Cloudflare Tunnel"), @@ -210,13 +219,11 @@ esac expect(result.status).not.toBe(0); expect(fs.readFileSync(log, "utf8").trim().split("\n")).toEqual(expectedLog); expect(fs.readFileSync(state, "utf8")).toBe(expectedState); - if (failContainmentStop) { - expect(result.stderr).toContain( - "PUBLIC INGRESS CONTAINMENT FAILED: tunnel stop status=5; ActiveState=active", - ); - } else { - expect(result.stderr).not.toContain("PUBLIC INGRESS CONTAINMENT FAILED"); - } + expect( + result.stderr + .split("\n") + .filter((line) => line.startsWith("PUBLIC INGRESS CONTAINMENT FAILED:")), + ).toEqual(expectedContainmentDiagnostics); }); it("loads fixed SSH, host-key, timeout, and cleanup configuration (#8142)", () => { @@ -422,10 +429,14 @@ esac let selectedTarget = "/tmp/unmanaged-cleanup"; let managedLinkStat = rootLinkStat; let managedTargetStat = secureTargetStat; + const lstatOverrides = new Map([ + [cleanupExecutable, () => managedLinkStat], + [cleanupTarget, () => managedTargetStat], + ]); const lstat = vi.spyOn(fs, "lstatSync").mockImplementation((candidate, options) => { - if (String(candidate) === cleanupExecutable) return managedLinkStat; - if (String(candidate) === cleanupTarget) return managedTargetStat; - return realLstatSync(candidate, options as never); + return ( + lstatOverrides.get(String(candidate))?.() ?? realLstatSync(candidate, options as never) + ); }); const readlink = vi .spyOn(fs, "readlinkSync") diff --git a/tools/e2e/colossus-jetson-dispatch-deploy.sh b/tools/e2e/colossus-jetson-dispatch-deploy.sh index 3b8ce48a1f0..81f9a1f0820 100755 --- a/tools/e2e/colossus-jetson-dispatch-deploy.sh +++ b/tools/e2e/colossus-jetson-dispatch-deploy.sh @@ -100,7 +100,9 @@ move_directory() { require_root_owned_directory() { local path="$1" expected_mode="$2" metadata - [ -d "$path" ] && [ ! -L "$path" ] || fail "$path must be a directory, not a symbolic link" + if [ ! -d "$path" ] || [ -L "$path" ]; then + fail "$path must be a directory, not a symbolic link" + fi metadata="$(/usr/bin/stat -c '%u:%g:%a' "$path")" || fail "could not inspect $path" if [ "$metadata" != "0:0:$expected_mode" ]; then fail "$path must be owned by root:root with mode $expected_mode" @@ -109,7 +111,9 @@ require_root_owned_directory() { require_root_owned_file() { local path="$1" expected_mode="$2" metadata - [ -f "$path" ] && [ ! -L "$path" ] || fail "$path must be a regular file, not a symbolic link" + if [ ! -f "$path" ] || [ -L "$path" ]; then + fail "$path must be a regular file, not a symbolic link" + fi metadata="$(/usr/bin/stat -c '%u:%g:%a' "$path")" || fail "could not inspect $path" if [ "$metadata" != "0:0:$expected_mode" ]; then fail "$path must be owned by root:root with mode $expected_mode" @@ -135,10 +139,10 @@ require_root() { } parse_commit() { - [ "$#" -eq 2 ] && [ "$1" = "--commit" ] && [[ "$2" =~ ^[a-f0-9]{40}$ ]] || { + if [ "$#" -ne 2 ] || [ "$1" != "--commit" ] || [[ ! "$2" =~ ^[a-f0-9]{40}$ ]]; then usage exit 2 - } + fi printf '%s\n' "$2" } @@ -291,7 +295,9 @@ atomic_install_cleanup_link() { atomic_select_release() { local release="$1" temporary_link="$deploy_root/.current.${release##*/}.$$" - [ ! -e "$temporary_link" ] && [ ! -L "$temporary_link" ] || return 1 + if [ -e "$temporary_link" ] || [ -L "$temporary_link" ]; then + return 1 + fi ln -s -- "$release" "$temporary_link" || { temporary_link="" return 1 From 4212484228e495e26d78ddae663d5fd347320ce6 Mon Sep 17 00:00:00 2001 From: San Dang Date: Tue, 11 Aug 2026 02:24:44 +0700 Subject: [PATCH 20/34] fix(e2e): restore completed Jetson dispatches --- test/e2e/docs/jetson-colossus-dispatch.md | 55 ++++++- .../support/jetson-dispatch-contract.test.ts | 62 ++++++-- tools/e2e/jetson-dispatch-lifecycle.mts | 138 +++++++++++++++++- 3 files changed, 234 insertions(+), 21 deletions(-) diff --git a/test/e2e/docs/jetson-colossus-dispatch.md b/test/e2e/docs/jetson-colossus-dispatch.md index 32f51c9c729..37ea5210325 100644 --- a/test/e2e/docs/jetson-colossus-dispatch.md +++ b/test/e2e/docs/jetson-colossus-dispatch.md @@ -746,7 +746,13 @@ jq -e --slurpfile dispatch "$DISPATCH_JSON" ' It must also contain `jetson-e2e-artifacts.tar.gz`. The dispatcher creates that archive from the remote E2E artifact directory before it removes the candidate workspace. It rejects an artifact directory or compressed archive larger than 1 MiB. -Before a restarted dispatcher replays the same deterministic job ID, it removes the earlier log and archive so evidence cannot cross executions. +During initialization, the dispatcher validates the schema, request, job ID, and state in every private file whose basename matches `^[a-f0-9]{64}\.json$`. +For a completed record, it also validates the terminal fields. +It ignores valid queued or running records and restores only the 128 newest completed statuses to memory. +An invalid matching file fails initialization before the dispatcher accepts work, and the error names its exact `.json` basename. +Status and artifact requests both restore an evicted completed status from its private file. +Only an artifact request returns the persisted log and archive. +A repeated deterministic dispatch returns the persisted completed status without rerunning candidate code or clearing its evidence. After the workflow completes, independently verify every allowlisted resource is absent. Require the private `.cleanup.json` file and verify every recorded volume and process ID is absent. @@ -785,6 +791,47 @@ Stop that retry loop before investigation or repair: sudo systemctl stop nemoclaw-jetson-dispatch.service ``` +An invalid matching `.json` file also fails startup and enters the same retry loop. +Set `JOB_ID` from the exact basename in the startup error. +For this failure, preserve and inspect the named private file under the approved incident-retention policy; treat its JSON as private candidate output. +The following command validates the exact basename, stops the retry loop, requires `ActiveState=inactive`, and proves `device.lock` absent before quarantine. +It rejects a symbolic link or non-directory quarantine parent and verifies `root:root` mode `0700` without following links. +It then moves the exact object without overwriting retained evidence and restarts the service. +After it returns, repeat the loopback-bind and anonymous HTTP `401` checks under [Configure the Dispatcher Service](#configure-the-dispatcher-service) before accepting work. + +```bash +set -euo pipefail +JOB_ID=0000000000000000000000000000000000000000000000000000000000000000 +[[ "$JOB_ID" =~ ^[a-f0-9]{64}$ ]] +state=/var/lib/nemoclaw-jetson-dispatch/state +status_file="$state/$JOB_ID.json" +quarantine=/var/lib/nemoclaw-jetson-status-quarantine +quarantine_file="$quarantine/$JOB_ID.json.invalid" +sudo systemctl stop nemoclaw-jetson-dispatch.service +test "$(sudo systemctl show --property=ActiveState --value \ + nemoclaw-jetson-dispatch.service)" = inactive +sudo stat -- "$status_file" +sudo test ! -e "$state/device.lock" +sudo test ! -L "$state/device.lock" +sudo test ! -L "$quarantine" +if sudo test -e "$quarantine"; then + test "$(sudo stat --format='%F:%u:%g:%a' -- "$quarantine")" = \ + directory:0:0:700 +else + sudo install -d -o root -g root -m 0700 "$quarantine" +fi +test "$(sudo stat --format='%F:%u:%g:%a' -- "$quarantine")" = \ + directory:0:0:700 +sudo test ! -e "$quarantine_file" +sudo test ! -L "$quarantine_file" +sudo mv -- "$status_file" "$quarantine_file" +sudo test ! -e "$status_file" +sudo test ! -L "$status_file" +sudo systemctl start nemoclaw-jetson-dispatch.service +test "$(sudo systemctl show --property=ActiveState --value \ + nemoclaw-jetson-dispatch.service)" = active +``` + Do not delete `device.lock` to bypass recovery. For `cleanup: "failed"`, inspect the recorded error before choosing a recovery action. Repair the cleanup program or allowlisted resource state only when that named operation failed. @@ -1095,13 +1142,17 @@ sudo rm -- \ /etc/nemoclaw-jetson-dispatch/environment \ /etc/systemd/system/nemoclaw-jetson-dispatch.service \ /usr/local/sbin/nemoclaw-colossus-jetson-dispatch-deploy -sudo rm -rf -- /opt/nemoclaw-jetson-dispatch +sudo rm -rf -- \ + /opt/nemoclaw-jetson-dispatch \ + /var/lib/nemoclaw-jetson-status-quarantine sudo systemctl daemon-reload sudo test ! -e /etc/nemoclaw-jetson-dispatch/environment sudo test ! -e /etc/systemd/system/nemoclaw-jetson-dispatch.service sudo test ! -e /usr/local/sbin/nemoclaw-colossus-jetson-dispatch-deploy sudo test ! -e /opt/nemoclaw-jetson-dispatch sudo test ! -L /opt/nemoclaw-jetson-dispatch +sudo test ! -e /var/lib/nemoclaw-jetson-status-quarantine +sudo test ! -L /var/lib/nemoclaw-jetson-status-quarantine test "$(systemctl show --property=LoadState --value \ nemoclaw-jetson-dispatch.service)" = not-found ``` diff --git a/test/e2e/support/jetson-dispatch-contract.test.ts b/test/e2e/support/jetson-dispatch-contract.test.ts index 2e31bd66cdc..adde6a1a0e2 100644 --- a/test/e2e/support/jetson-dispatch-contract.test.ts +++ b/test/e2e/support/jetson-dispatch-contract.test.ts @@ -440,30 +440,58 @@ describe("Jetson single-device lifecycle", () => { expect(fs.existsSync(path.join(stateDirectory, "device.lock"))).toBe(false); }); - it("does not return an archive from an earlier replay after restart (#8142)", async () => { + it("restores completed evidence without replaying the job after restart (#8142)", async () => { const stateDirectory = temporaryDirectory(); const first = coordinator(stateDirectory, worker()); await first.initialize(); const firstAccepted = first.dispatch(REQUEST, identity()); - await waitForCompletion(first, firstAccepted.jobId); + const firstCompleted = await waitForCompletion(first, firstAccepted.jobId); expect(first.artifact(firstAccepted.jobId).artifactArchiveBase64).toBe(ARTIFACT_ARCHIVE_BASE64); - const replay = coordinator( - stateDirectory, - worker({ run: async () => Promise.reject(new Error("replayed candidate failed")) }), - ); - await replay.initialize(); - const replayAccepted = replay.dispatch(REQUEST, identity()); - const replayCompleted = await waitForCompletion(replay, replayAccepted.jobId); - const replayArtifact = replay.artifact(replayAccepted.jobId); + const replayRun = vi.fn(worker().run); + const restarted = coordinator(stateDirectory, worker({ run: replayRun })); + await restarted.initialize(); + const restoredStatus = restarted.status(firstAccepted.jobId); + const restoredArtifact = restarted.artifact(firstAccepted.jobId); + const replayAccepted = restarted.dispatch(REQUEST, identity()); expect(replayAccepted.jobId).toBe(firstAccepted.jobId); - expect(replayCompleted).toMatchObject({ conclusion: "failure", cleanup: "succeeded" }); - expect(replayArtifact.log).toBe(""); - expect(replayArtifact).not.toHaveProperty("artifactArchiveBase64"); + expect(replayAccepted).toEqual(firstCompleted); + expect(restoredStatus).toEqual(firstCompleted); + expect(restoredArtifact).toMatchObject({ + artifactArchiveBase64: ARTIFACT_ARCHIVE_BASE64, + log: "passed\n", + status: firstCompleted, + }); + expect(replayRun).not.toHaveBeenCalled(); }); - it("bounds retained in-memory job status while preserving private evidence (#8142)", async () => { + it("rejects initialization when a completed status record is invalid (#8142)", async () => { + const stateDirectory = temporaryDirectory(); + const first = coordinator(stateDirectory, worker()); + await first.initialize(); + const accepted = first.dispatch(REQUEST, identity()); + await waitForCompletion(first, accepted.jobId); + const statusPath = path.join(stateDirectory, `${accepted.jobId}.json`); + const persisted = JSON.parse(fs.readFileSync(statusPath, "utf8")); + const invalidRecords = [ + { + contents: `${JSON.stringify({ ...persisted, jobId: "f".repeat(64) })}\n`, + error: "persisted Jetson dispatch status does not match its job ID", + }, + { contents: "{", error: "persisted Jetson dispatch status is not valid JSON" }, + { contents: " ".repeat(16 * 1024 + 1), error: "exceeds 16384 bytes" }, + ]; + + for (const record of invalidRecords) { + fs.writeFileSync(statusPath, record.contents); + await expect(coordinator(stateDirectory, worker()).initialize()).rejects.toThrow( + new RegExp(`Jetson dispatch status ${accepted.jobId}\\.json is invalid: .*${record.error}`), + ); + } + }); + + it("restores private completed status after in-memory eviction (#8142)", async () => { const stateDirectory = temporaryDirectory(); const dispatch = coordinator(stateDirectory, worker()); await dispatch.initialize(); @@ -477,8 +505,12 @@ describe("Jetson single-device lifecycle", () => { await waitForCompletion(dispatch, accepted.jobId); } - expect(() => dispatch.status(firstJobId)).toThrow(JetsonDispatchNotFoundError); + expect(dispatch.status(firstJobId)).toMatchObject({ state: "completed" }); expect(fs.existsSync(path.join(stateDirectory, `${firstJobId}.json`))).toBe(true); + fs.writeFileSync(path.join(stateDirectory, `${firstJobId}.json`), "{"); + await expect(coordinator(stateDirectory, worker()).initialize()).rejects.toThrow( + `Jetson dispatch status ${firstJobId}.json is invalid`, + ); }); it("keeps the device locked when cleanup fails (#8142)", async () => { diff --git a/tools/e2e/jetson-dispatch-lifecycle.mts b/tools/e2e/jetson-dispatch-lifecycle.mts index 8d09c96a827..52cb347308e 100644 --- a/tools/e2e/jetson-dispatch-lifecycle.mts +++ b/tools/e2e/jetson-dispatch-lifecycle.mts @@ -4,7 +4,11 @@ import { createHash } from "node:crypto"; import fs from "node:fs"; import path from "node:path"; -import type { GitHubOidcIdentity, JetsonDispatchRequest } from "./jetson-dispatch-contract.mts"; +import { + type GitHubOidcIdentity, + type JetsonDispatchRequest, + parseJetsonDispatchRequest, +} from "./jetson-dispatch-contract.mts"; import { createPrivateRegularFile, readPrivateRegularFile, @@ -13,6 +17,9 @@ import { export const MAX_JETSON_DISPATCH_LOG_BYTES = 4 * 1024 * 1024; const MAX_RETAINED_JOB_STATUSES = 128; +const MAX_JETSON_DISPATCH_STATUS_BYTES = 16 * 1024; +const JOB_ID_PATTERN = /^[a-f0-9]{64}$/u; +const STATUS_FILE_PATTERN = /^([a-f0-9]{64})\.json$/u; export const MAX_JETSON_ARTIFACT_ARCHIVE_BYTES = 1024 * 1024; const MAX_JETSON_ARTIFACT_ARCHIVE_BASE64_CHARACTERS = Math.ceil(MAX_JETSON_ARTIFACT_ARCHIVE_BYTES / 3) * 4; @@ -139,6 +146,90 @@ function dispatchJobId(request: JetsonDispatchRequest): string { .digest("hex"); } +function parseTimestamp(value: unknown, name: string): string { + if ( + typeof value !== "string" || + value.length !== 24 || + Number.isNaN(Date.parse(value)) || + new Date(value).toISOString() !== value + ) { + throw new Error(`${name} must be an ISO timestamp`); + } + return value; +} + +function parseDeviceIdentity(value: unknown): JetsonDeviceIdentity | undefined { + if (value === undefined) return undefined; + if (!value || typeof value !== "object" || Array.isArray(value)) { + throw new Error("device must be an object"); + } + const device = value as Record; + const fields = ["jetpackVersion", "jetsonLinuxRelease", "kernel", "model"]; + if (fields.some((field) => typeof device[field] !== "string")) { + throw new Error("device fields are invalid"); + } + return { + model: device.model as string, + jetpackVersion: device.jetpackVersion as string, + jetsonLinuxRelease: device.jetsonLinuxRelease as string, + kernel: device.kernel as string, + }; +} + +function parsePersistedCompletedStatus( + contents: string, + expectedJobId: string, +): JetsonDispatchStatus | null { + let value: unknown; + try { + value = JSON.parse(contents); + } catch { + throw new Error("persisted Jetson dispatch status is not valid JSON"); + } + if (!value || typeof value !== "object" || Array.isArray(value)) { + throw new Error("persisted Jetson dispatch status must be an object"); + } + const status = value as Record; + const request = parseJetsonDispatchRequest(status.request); + if ( + status.schemaVersion !== 1 || + status.jobId !== expectedJobId || + dispatchJobId(request) !== expectedJobId + ) { + throw new Error("persisted Jetson dispatch status does not match its job ID"); + } + if (status.state === "queued" || status.state === "running") return null; + if (status.state !== "completed") { + throw new Error("persisted Jetson dispatch status has an invalid state"); + } + if ( + !["cancelled", "cleanup-failed", "failure", "success", "timed-out"].includes( + status.conclusion as string, + ) || + !["failed", "succeeded"].includes(status.cleanup as string) || + (status.error !== undefined && typeof status.error !== "string") + ) { + throw new Error("persisted Jetson dispatch result fields are invalid"); + } + const createdAt = parseTimestamp(status.createdAt, "createdAt"); + const startedAt = parseTimestamp(status.startedAt, "startedAt"); + const completedAt = parseTimestamp(status.completedAt, "completedAt"); + const device = parseDeviceIdentity(status.device); + return { + schemaVersion: 1, + jobId: expectedJobId, + request, + state: "completed", + conclusion: status.conclusion as JetsonDispatchConclusion, + createdAt, + startedAt, + completedAt, + ...(device === undefined ? {} : { device }), + cleanup: status.cleanup as "failed" | "succeeded", + ...(status.error === undefined ? {} : { error: status.error as string }), + }; +} + function withTimeout( timeoutMs: number, operation: (signal: AbortSignal) => Promise, @@ -209,6 +300,7 @@ export class JetsonDispatchCoordinator { ); fs.unlinkSync(this.#lockPath); } + this.#restoreCompletedStatuses(); this.#initialized = true; } @@ -221,7 +313,7 @@ export class JetsonDispatchCoordinator { throw new Error("dispatch identity does not match the workflow run"); } const jobId = dispatchJobId(request); - const existing = this.#jobs.get(jobId); + const existing = this.#findStatus(jobId); if (existing) return structuredClone(existing); if (this.#activeJobId) { throw new JetsonDispatchBusyError("Jetson device is already running another job"); @@ -259,7 +351,7 @@ export class JetsonDispatchCoordinator { status(jobId: string): JetsonDispatchStatus { this.#requireInitialized(); - const status = this.#jobs.get(jobId); + const status = this.#findStatus(jobId); if (!status) throw new JetsonDispatchNotFoundError("Jetson dispatch job was not found"); return structuredClone(status); } @@ -269,7 +361,8 @@ export class JetsonDispatchCoordinator { } cancel(jobId: string): JetsonDispatchStatus { - const status = this.#jobs.get(jobId); + this.#requireInitialized(); + const status = this.#findStatus(jobId); if (!status) throw new JetsonDispatchNotFoundError("Jetson dispatch job was not found"); if (status.state !== "completed" && this.#activeJobId === jobId) { this.#cancelRequested = true; @@ -417,6 +510,43 @@ export class JetsonDispatchCoordinator { fs.rmSync(this.#artifactPath(jobId), { force: true }); } + #findStatus(jobId: string): JetsonDispatchStatus | undefined { + const existing = this.#jobs.get(jobId); + if (existing || !JOB_ID_PATTERN.test(jobId)) return existing; + const restored = this.#readCompletedStatus(jobId); + if (restored) { + this.#evictOldestCompletedJob(); + this.#jobs.set(jobId, restored); + } + return restored ?? undefined; + } + + #readCompletedStatus(jobId: string): JetsonDispatchStatus | null { + try { + const contents = readPrivateRegularFile(this.#statusPath(jobId), { + allowMissing: true, + maxBytes: MAX_JETSON_DISPATCH_STATUS_BYTES, + }); + return contents === null ? null : parsePersistedCompletedStatus(contents, jobId); + } catch (error) { + throw new Error(`Jetson dispatch status ${jobId}.json is invalid: ${safeError(error)}`); + } + } + + #restoreCompletedStatuses(): void { + const completed = fs + .readdirSync(this.#stateDirectory) + .flatMap((name) => { + const match = STATUS_FILE_PATTERN.exec(name); + if (!match) return []; + const status = this.#readCompletedStatus(match[1]!); + return status === null ? [] : [status]; + }) + .sort((left, right) => left.completedAt!.localeCompare(right.completedAt!)) + .slice(-MAX_RETAINED_JOB_STATUSES); + for (const status of completed) this.#jobs.set(status.jobId, status); + } + #evictOldestCompletedJob(): void { if (this.#jobs.size < MAX_RETAINED_JOB_STATUSES) return; for (const [jobId, status] of this.#jobs) { From 4ad5e19106d35654af4016fcf9cfc07790634847 Mon Sep 17 00:00:00 2001 From: San Dang Date: Tue, 11 Aug 2026 03:04:53 +0700 Subject: [PATCH 21/34] fix(e2e): retain Jetson lock until result persists --- test/e2e/docs/jetson-colossus-dispatch.md | 20 ++++- .../support/jetson-dispatch-contract.test.ts | 60 +++++++++++++ tools/e2e/jetson-dispatch-lifecycle.mts | 90 +++++++++++++------ 3 files changed, 138 insertions(+), 32 deletions(-) diff --git a/test/e2e/docs/jetson-colossus-dispatch.md b/test/e2e/docs/jetson-colossus-dispatch.md index 37ea5210325..53163824035 100644 --- a/test/e2e/docs/jetson-colossus-dispatch.md +++ b/test/e2e/docs/jetson-colossus-dispatch.md @@ -753,6 +753,8 @@ An invalid matching file fails initialization before the dispatcher accepts work Status and artifact requests both restore an evicted completed status from its private file. Only an artifact request returns the persisted log and archive. A repeated deterministic dispatch returns the persisted completed status without rerunning candidate code or clearing its evidence. +The dispatcher persists terminal status before it removes `device.lock`. +If that persistence fails, it reports a completed in-memory failure and retains the lock. After the workflow completes, independently verify every allowlisted resource is absent. Require the private `.cleanup.json` file and verify every recorded volume and process ID is absent. @@ -773,6 +775,9 @@ They do not attest that cleanup reversed every possible host change made by cand The dispatcher permits one active job. A process interruption leaves `device.lock` in the state directory. On startup, the dispatcher invokes the cleanup program before it removes that stale lock or accepts more work. +After successful cleanup, a valid queued or running record for the locked job becomes a durable completed failure with `cleanup: "succeeded"` and error `Jetson dispatcher restarted before terminal status was persisted`. +Only then does the dispatcher remove the lock; if this recovery persistence fails, the lock remains. +A repeated deterministic dispatch returns that recovered failure without rerunning candidate code. If cleanup fails, startup fails or the completed job reports `conclusion: "cleanup-failed"` with `cleanup: "failed"`. If cleanup succeeds but lock removal fails, the completed job reports `conclusion: "cleanup-failed"` with `cleanup: "succeeded"`. The lock remains in either case. @@ -794,9 +799,11 @@ sudo systemctl stop nemoclaw-jetson-dispatch.service An invalid matching `.json` file also fails startup and enters the same retry loop. Set `JOB_ID` from the exact basename in the startup error. For this failure, preserve and inspect the named private file under the approved incident-retention policy; treat its JSON as private candidate output. -The following command validates the exact basename, stops the retry loop, requires `ActiveState=inactive`, and proves `device.lock` absent before quarantine. +The following command validates the exact basename, stops the retry loop, requires `ActiveState=inactive`, and accepts either no `device.lock` or the service-owned, mode `0600`, single-link regular lock whose exact contents are `JOB_ID` plus its terminating newline. +A mismatched, nonregular, or symbolic-link lock blocks recovery. It rejects a symbolic link or non-directory quarantine parent and verifies `root:root` mode `0700` without following links. It then moves the exact object without overwriting retained evidence and restarts the service. +For a matching lock, startup reruns cleanup and removes the lock only after cleanup succeeds; never remove the lock manually. After it returns, repeat the loopback-bind and anonymous HTTP `401` checks under [Configure the Dispatcher Service](#configure-the-dispatcher-service) before accepting work. ```bash @@ -807,12 +814,19 @@ state=/var/lib/nemoclaw-jetson-dispatch/state status_file="$state/$JOB_ID.json" quarantine=/var/lib/nemoclaw-jetson-status-quarantine quarantine_file="$quarantine/$JOB_ID.json.invalid" +lock="$state/device.lock" +dispatcher_uid="$(id -u nemoclaw-jetson-dispatch)" +dispatcher_gid="$(id -g nemoclaw-jetson-dispatch)" sudo systemctl stop nemoclaw-jetson-dispatch.service test "$(sudo systemctl show --property=ActiveState --value \ nemoclaw-jetson-dispatch.service)" = inactive sudo stat -- "$status_file" -sudo test ! -e "$state/device.lock" -sudo test ! -L "$state/device.lock" +sudo test ! -L "$lock" +if sudo test -e "$lock"; then + test "$(sudo stat --format='%F:%u:%g:%a:%h' -- "$lock")" = \ + "regular file:$dispatcher_uid:$dispatcher_gid:600:1" + printf '%s\n' "$JOB_ID" | sudo cmp --silent -- "$lock" - +fi sudo test ! -L "$quarantine" if sudo test -e "$quarantine"; then test "$(sudo stat --format='%F:%u:%g:%a' -- "$quarantine")" = \ diff --git a/test/e2e/support/jetson-dispatch-contract.test.ts b/test/e2e/support/jetson-dispatch-contract.test.ts index adde6a1a0e2..7d7acc35af6 100644 --- a/test/e2e/support/jetson-dispatch-contract.test.ts +++ b/test/e2e/support/jetson-dispatch-contract.test.ts @@ -440,6 +440,66 @@ describe("Jetson single-device lifecycle", () => { expect(fs.existsSync(path.join(stateDirectory, "device.lock"))).toBe(false); }); + it("keeps the lock until restart persists a terminal result (#8142)", async () => { + const stateDirectory = temporaryDirectory(); + const expectedResult = await worker().run(REQUEST, { + jobId: "e".repeat(64), + signal: new AbortController().signal, + }); + let finishRun!: () => void; + const run = vi.fn(async () => { + await new Promise((resolve) => { + finishRun = resolve; + }); + return expectedResult; + }); + const first = coordinator(stateDirectory, worker({ run })); + await first.initialize(); + const accepted = first.dispatch(REQUEST, identity()); + await vi.waitFor(() => expect(run).toHaveBeenCalledOnce()); + const statusPath = path.join(stateDirectory, `${accepted.jobId}.json`); + const runningStatus = fs.readFileSync(statusPath, "utf8"); + fs.rmSync(statusPath); + fs.mkdirSync(statusPath); + + finishRun(); + const failedPersistence = await waitForCompletion(first, accepted.jobId); + + expect(failedPersistence).toMatchObject({ + cleanup: "succeeded", + conclusion: "failure", + error: expect.stringContaining("Final status persistence failed"), + }); + expect(fs.existsSync(path.join(stateDirectory, "device.lock"))).toBe(true); + + const recoveryCleanup = vi.fn(async () => {}); + await expect( + coordinator(stateDirectory, worker({ cleanup: recoveryCleanup })).initialize(), + ).rejects.toThrow(`Jetson dispatch status ${accepted.jobId}.json is invalid`); + expect(recoveryCleanup).toHaveBeenCalledOnce(); + expect(fs.existsSync(path.join(stateDirectory, "device.lock"))).toBe(true); + + fs.rmSync(statusPath, { recursive: true }); + fs.writeFileSync(statusPath, runningStatus, { mode: 0o600 }); + const replayRun = vi.fn(worker().run); + const restarted = coordinator( + stateDirectory, + worker({ cleanup: recoveryCleanup, run: replayRun }), + ); + await restarted.initialize(); + + expect(restarted.status(accepted.jobId)).toMatchObject({ + cleanup: "succeeded", + conclusion: "failure", + error: "Jetson dispatcher restarted before terminal status was persisted", + state: "completed", + }); + expect(fs.existsSync(path.join(stateDirectory, "device.lock"))).toBe(false); + expect(recoveryCleanup).toHaveBeenCalledTimes(2); + expect(restarted.dispatch(REQUEST, identity()).state).toBe("completed"); + expect(replayRun).not.toHaveBeenCalled(); + }); + it("restores completed evidence without replaying the job after restart (#8142)", async () => { const stateDirectory = temporaryDirectory(); const first = coordinator(stateDirectory, worker()); diff --git a/tools/e2e/jetson-dispatch-lifecycle.mts b/tools/e2e/jetson-dispatch-lifecycle.mts index 52cb347308e..bb0bc9b03d1 100644 --- a/tools/e2e/jetson-dispatch-lifecycle.mts +++ b/tools/e2e/jetson-dispatch-lifecycle.mts @@ -176,10 +176,7 @@ function parseDeviceIdentity(value: unknown): JetsonDeviceIdentity | undefined { }; } -function parsePersistedCompletedStatus( - contents: string, - expectedJobId: string, -): JetsonDispatchStatus | null { +function parsePersistedStatus(contents: string, expectedJobId: string): JetsonDispatchStatus { let value: unknown; try { value = JSON.parse(contents); @@ -198,7 +195,23 @@ function parsePersistedCompletedStatus( ) { throw new Error("persisted Jetson dispatch status does not match its job ID"); } - if (status.state === "queued" || status.state === "running") return null; + const createdAt = parseTimestamp(status.createdAt, "createdAt"); + if (status.state === "queued" || status.state === "running") { + if (status.cleanup !== "pending") { + throw new Error("persisted incomplete Jetson dispatch cleanup is invalid"); + } + return { + schemaVersion: 1, + jobId: expectedJobId, + request, + state: status.state, + createdAt, + ...(status.state === "running" + ? { startedAt: parseTimestamp(status.startedAt, "startedAt") } + : {}), + cleanup: "pending", + }; + } if (status.state !== "completed") { throw new Error("persisted Jetson dispatch status has an invalid state"); } @@ -211,7 +224,6 @@ function parsePersistedCompletedStatus( ) { throw new Error("persisted Jetson dispatch result fields are invalid"); } - const createdAt = parseTimestamp(status.createdAt, "createdAt"); const startedAt = parseTimestamp(status.startedAt, "startedAt"); const completedAt = parseTimestamp(status.completedAt, "completedAt"); const device = parseDeviceIdentity(status.device); @@ -298,6 +310,16 @@ export class JetsonDispatchCoordinator { await withTimeout(this.#cleanupTimeoutMs, (signal) => this.#worker.cleanup({ jobId, signal }), ); + const recoveredStatus = this.#readStatus(jobId); + if (recoveredStatus && recoveredStatus.state !== "completed") { + recoveredStatus.state = "completed"; + recoveredStatus.conclusion = "failure"; + recoveredStatus.startedAt ??= recoveredStatus.createdAt; + recoveredStatus.completedAt = new Date().toISOString(); + recoveredStatus.cleanup = "succeeded"; + recoveredStatus.error = "Jetson dispatcher restarted before terminal status was persisted"; + this.#persist(recoveredStatus); + } fs.unlinkSync(this.#lockPath); } this.#restoreCompletedStatuses(); @@ -463,29 +485,39 @@ export class JetsonDispatchCoordinator { : cleanupError; conclusion = "cleanup-failed"; } - if (status.cleanup === "succeeded") { - try { - fs.unlinkSync(this.#lockPath); - } catch (error) { - const lockError = `Jetson lock removal failed: ${safeError(error)}`; - status.error = status.error ? `${status.error}; ${lockError}`.slice(0, 500) : lockError; - conclusion = "cleanup-failed"; - } - } status.conclusion = conclusion; status.state = "completed"; status.completedAt = new Date().toISOString(); + let terminalStatusPersisted = false; try { this.#persist(status); + terminalStatusPersisted = true; } catch (error) { - status.error = `Final status persistence failed: ${safeError(error)}`; - status.conclusion = "failure"; - } finally { - this.#activeAbort = undefined; - this.#activeRun = undefined; - this.#activeJobId = undefined; - this.#cancelRequested = false; + const persistenceError = `Final status persistence failed: ${safeError(error)}`; + status.error = status.error + ? `${status.error}; ${persistenceError}`.slice(0, 500) + : persistenceError; + if (status.conclusion !== "cleanup-failed") status.conclusion = "failure"; + } + if (status.cleanup === "succeeded" && terminalStatusPersisted) { + try { + fs.unlinkSync(this.#lockPath); + } catch (error) { + const lockError = `Jetson lock removal failed: ${safeError(error)}`; + status.error = status.error ? `${status.error}; ${lockError}`.slice(0, 500) : lockError; + status.conclusion = "cleanup-failed"; + try { + this.#persist(status); + } catch (persistError) { + const persistenceError = `Lock failure persistence failed: ${safeError(persistError)}`; + status.error = `${status.error}; ${persistenceError}`.slice(0, 500); + } + } } + this.#activeAbort = undefined; + this.#activeRun = undefined; + this.#activeJobId = undefined; + this.#cancelRequested = false; } } @@ -513,21 +545,21 @@ export class JetsonDispatchCoordinator { #findStatus(jobId: string): JetsonDispatchStatus | undefined { const existing = this.#jobs.get(jobId); if (existing || !JOB_ID_PATTERN.test(jobId)) return existing; - const restored = this.#readCompletedStatus(jobId); - if (restored) { + const restored = this.#readStatus(jobId); + if (restored?.state === "completed") { this.#evictOldestCompletedJob(); this.#jobs.set(jobId, restored); } - return restored ?? undefined; + return restored?.state === "completed" ? restored : undefined; } - #readCompletedStatus(jobId: string): JetsonDispatchStatus | null { + #readStatus(jobId: string): JetsonDispatchStatus | null { try { const contents = readPrivateRegularFile(this.#statusPath(jobId), { allowMissing: true, maxBytes: MAX_JETSON_DISPATCH_STATUS_BYTES, }); - return contents === null ? null : parsePersistedCompletedStatus(contents, jobId); + return contents === null ? null : parsePersistedStatus(contents, jobId); } catch (error) { throw new Error(`Jetson dispatch status ${jobId}.json is invalid: ${safeError(error)}`); } @@ -539,8 +571,8 @@ export class JetsonDispatchCoordinator { .flatMap((name) => { const match = STATUS_FILE_PATTERN.exec(name); if (!match) return []; - const status = this.#readCompletedStatus(match[1]!); - return status === null ? [] : [status]; + const status = this.#readStatus(match[1]!); + return status?.state === "completed" ? [status] : []; }) .sort((left, right) => left.completedAt!.localeCompare(right.completedAt!)) .slice(-MAX_RETAINED_JOB_STATUSES); From 61770170a6ee28fcc80a30ed6936387a19c1a80a Mon Sep 17 00:00:00 2001 From: San Dang Date: Tue, 11 Aug 2026 03:25:59 +0700 Subject: [PATCH 22/34] test(e2e): remove stale Jetson import --- test/e2e/support/jetson-dispatch-contract.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/test/e2e/support/jetson-dispatch-contract.test.ts b/test/e2e/support/jetson-dispatch-contract.test.ts index 7d7acc35af6..128729ae0bc 100644 --- a/test/e2e/support/jetson-dispatch-contract.test.ts +++ b/test/e2e/support/jetson-dispatch-contract.test.ts @@ -24,7 +24,6 @@ import { import { JetsonDispatchBusyError, JetsonDispatchCoordinator, - JetsonDispatchNotFoundError, type JetsonDispatchStatus, type JetsonDispatchWorker, MAX_JETSON_ARTIFACT_ARCHIVE_BYTES, From c458c5c34f83013b628c07ac442acb6ccc53269f Mon Sep 17 00:00:00 2001 From: San Dang Date: Tue, 11 Aug 2026 10:05:18 +0700 Subject: [PATCH 23/34] fix(e2e): plan Jetson dispatch without shared targets --- .github/workflows/e2e.yaml | 2 +- .../support/e2e-operations-workflow-boundary.test.ts | 11 ++++++----- test/e2e/support/workflow-plan.test.ts | 12 ++++++++++++ tools/e2e/workflow-boundary.mts | 2 +- tools/e2e/workflow-plan.mts | 12 ++++++++++++ 5 files changed, 32 insertions(+), 7 deletions(-) diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index fdb41a9030d..5973c09d7da 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -179,7 +179,7 @@ jobs: matrix='[{"id":"ubuntu-policy-custom-missing-presets-negative","runner":"ubuntu-latest"},{"id":"ubuntu-repo-cloud-langchain-deepagents-code","runner":"ubuntu-latest"},{"id":"ubuntu-repo-cloud-openclaw","runner":"ubuntu-latest"},{"id":"ubuntu-repo-docker-post-reboot-recovery","runner":"ubuntu-latest"}]' test_matrix='[{"id":"onboard-managed-image-buildless-e2e","file":"test/onboard-managed-image-buildless-e2e.test.ts","project":"integration"},{"id":"vllm-docker-storage","file":"test/vllm-docker-storage.test.ts","project":"integration"}]' ;; - inference-routing: | managed-image-protected-runtime:) + inference-routing: | managed-image-protected-runtime: | :jetson-nvmap-gpu) matrix='[]' ;; :ubuntu-repo-cloud-langchain-deepagents-code) diff --git a/test/e2e/support/e2e-operations-workflow-boundary.test.ts b/test/e2e/support/e2e-operations-workflow-boundary.test.ts index 17e5ce8f227..8cbef3c970b 100644 --- a/test/e2e/support/e2e-operations-workflow-boundary.test.ts +++ b/test/e2e/support/e2e-operations-workflow-boundary.test.ts @@ -413,9 +413,10 @@ const interpolatedNeeds = \${{ toJSON ( needs ) }}; }); it.each([ - "inference-routing", - "managed-image-protected-runtime", - ])("selects no shared targets for the %s job selector", (jobSelector) => { + ["inference-routing job", "inference-routing", ""], + ["managed-image-protected-runtime job", "managed-image-protected-runtime", ""], + ["jetson-nvmap-gpu target", "", "jetson-nvmap-gpu"], + ])("selects no shared targets for the %s selector", (_name, jobSelector, targetSelector) => { const workflow = readE2eOperationsWorkflow(); const controller = workflow.jobs["generate-matrix"].steps!.find( (step) => step.name === "Build trusted controller target matrix", @@ -439,7 +440,7 @@ const interpolatedNeeds = \${{ toJSON ( needs ) }}; ...process.env, GITHUB_OUTPUT: output, JOBS: jobSelector, - TARGETS: "", + TARGETS: targetSelector, }, }, ); @@ -462,7 +463,7 @@ const interpolatedNeeds = \${{ toJSON ( needs ) }}; GITHUB_STEP_SUMMARY: summary, INFERENCE_MODE: "mock", JOBS: jobSelector, - TARGETS: "", + TARGETS: targetSelector, }, }, ); diff --git a/test/e2e/support/workflow-plan.test.ts b/test/e2e/support/workflow-plan.test.ts index 9378e7b6de4..06172fbf2ef 100644 --- a/test/e2e/support/workflow-plan.test.ts +++ b/test/e2e/support/workflow-plan.test.ts @@ -243,6 +243,18 @@ describe("E2E workflow plan", () => { } }); + it.each([ + "jobs", + "targets", + ] as const)("emits an empty shared plan for the Jetson dispatch %s selector (#8142)", (selector) => { + expect(buildE2eWorkflowPlan({ [selector]: "jetson-nvmap-gpu" })).toEqual({ + matrix: [], + testMatrix: [], + hermesSelected: false, + explicitOnlyJobs: readFreeStandingJobsInventory().explicitOnlyJobs, + }); + }); + it("emits an empty matrix for retired free-standing rebuild selectors (#7615)", () => { const directory = mkdtempSync(path.join(tmpdir(), "nemoclaw-workflow-plan-cli-")); const output = path.join(directory, "github-output"); diff --git a/tools/e2e/workflow-boundary.mts b/tools/e2e/workflow-boundary.mts index a7fe97d657b..32cedf12cc2 100644 --- a/tools/e2e/workflow-boundary.mts +++ b/tools/e2e/workflow-boundary.mts @@ -4590,7 +4590,7 @@ export function validateE2eWorkflow(workflowValue: unknown): string[] { `matrix='[${defaultMappings}]'`, `test_matrix='[${defaultTestMappings}]'`, ";;", - "inference-routing: | managed-image-protected-runtime:)", + "inference-routing: | managed-image-protected-runtime: | :jetson-nvmap-gpu)", "matrix='[]'", ";;", `:${deepAgentsTarget})`, diff --git a/tools/e2e/workflow-plan.mts b/tools/e2e/workflow-plan.mts index f3356f82f6f..bbe2c25cce3 100644 --- a/tools/e2e/workflow-plan.mts +++ b/tools/e2e/workflow-plan.mts @@ -10,6 +10,7 @@ import { type CredentialFreeTestMatrixRow, discoverCredentialFreeTests, } from "./credential-free-tests.mts"; +import { JETSON_DISPATCH_TARGET } from "./jetson-dispatch-contract.mts"; import { selectedRetiredControllerJobs } from "./retired-selector-compatibility.mts"; import { normalizeE2eSelectorIds } from "./selector-aliases.mts"; import { readFreeStandingJobsInventory } from "./workflow-boundary.mts"; @@ -197,6 +198,17 @@ export function buildE2eWorkflowPlan(selectors: WorkflowPlanSelectors = {}): E2e const targets = selectorIds(selectors.targets, "targets"); const inventory = readFreeStandingJobsInventory(); + const jetsonDispatchSelected = + (jobs.length === 1 && jobs[0] === JETSON_DISPATCH_TARGET && targets.length === 0) || + (targets.length === 1 && targets[0] === JETSON_DISPATCH_TARGET && jobs.length === 0); + if (jetsonDispatchSelected) { + return { + matrix: [], + testMatrix: [], + hermesSelected: false, + explicitOnlyJobs: [...inventory.explicitOnlyJobs], + }; + } const credentialFreeTests = discoverCredentialFreeTests(); if (jobs.length > 0) { From 95201e81c5e787caf25f03522c17f88203b21a41 Mon Sep 17 00:00:00 2001 From: San Dang Date: Tue, 11 Aug 2026 10:14:32 +0700 Subject: [PATCH 24/34] fix(installer): restore preflight CI contracts --- scripts/install.sh | 8 ++++---- test/package-contract/installer-host-preflight.test.ts | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index 8856ce09a6a..107dc0ede89 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -3100,9 +3100,9 @@ run_installer_host_preflight() { if (host.isWsl) { infoLines.push("Running under WSL"); } + const findingIds = admission.admitted ? [] : stableIds(admission.findingIds); + const capabilityIds = admission.admitted ? [] : stableIds(admission.capabilityIds); if (!admission.admitted) { - const findingIds = stableIds(admission.findingIds); - const capabilityIds = stableIds(admission.capabilityIds); if (findingIds.length > 0) { actionLines.push(`Admission finding IDs: ${findingIds.join(", ")}`); } @@ -3123,7 +3123,7 @@ run_installer_host_preflight() { finding, ]) ); - for (const findingId of admission.findingIds || []) { + for (const findingId of findingIds) { const finding = findingById.get(findingId); actionLines.push( finding?.summary @@ -3131,7 +3131,7 @@ run_installer_host_preflight() { : `- Readiness finding: ${findingId}` ); } - for (const capabilityId of admission.capabilityIds || []) { + for (const capabilityId of capabilityIds) { actionLines.push( `- NemoClaw could not confirm the required readiness capability ${capabilityId}.` ); diff --git a/test/package-contract/installer-host-preflight.test.ts b/test/package-contract/installer-host-preflight.test.ts index 69f24f452b7..48a8acfdb56 100644 --- a/test/package-contract/installer-host-preflight.test.ts +++ b/test/package-contract/installer-host-preflight.test.ts @@ -98,6 +98,10 @@ exports.evaluateOnboardReadinessAdmission = (report, options) => { }; `, ); + fs.writeFileSync( + path.join(onboardDir, "gateway-management.js"), + `exports.loadGatewayManagementDeclaration = () => ({ ok: true, declaration: null });\n`, + ); writeNodeStub(fakeBin); const result = spawnSync( From 122034511327d01a3eeeee2395ebcba3de1e9834 Mon Sep 17 00:00:00 2001 From: San Dang Date: Tue, 11 Aug 2026 11:04:00 +0700 Subject: [PATCH 25/34] feat(e2e): bootstrap Colossus dispatcher service --- test/e2e/docs/jetson-colossus-dispatch.md | 168 +++++------ .../colossus-jetson-dispatch-deploy.test.ts | 269 +++++++++++++++++- .../support/jetson-dispatch-worker.test.ts | 29 +- test/helpers/vitest-watch-triggers.ts | 8 + tools/e2e/colossus-jetson-dispatch-deploy.sh | 257 ++++++++++++++++- .../e2e/colossus-jetson-dispatch.environment | 13 + tools/e2e/nemoclaw-jetson-dispatch.service | 27 ++ 7 files changed, 654 insertions(+), 117 deletions(-) create mode 100644 tools/e2e/colossus-jetson-dispatch.environment create mode 100644 tools/e2e/nemoclaw-jetson-dispatch.service diff --git a/test/e2e/docs/jetson-colossus-dispatch.md b/test/e2e/docs/jetson-colossus-dispatch.md index 53163824035..a1263bf28da 100644 --- a/test/e2e/docs/jetson-colossus-dispatch.md +++ b/test/e2e/docs/jetson-colossus-dispatch.md @@ -154,7 +154,7 @@ The cleanup program must not change or remove any resource outside its allowlist Review its command construction and target resolution before deployment. Do not use broad process termination, Docker pruning, wildcard paths, or host-wide package removal. -## Create the Colossus Dispatcher Account and Bootstrap Deployment +## Prepare the Colossus Dispatcher Account and Deployment Command Run these commands on Colossus. The dispatcher requires `/usr/bin/node` 22.19.0 or later. @@ -170,11 +170,11 @@ sudo useradd --system --create-home \ --home-dir /var/lib/nemoclaw-jetson-dispatch \ --shell /usr/sbin/nologin nemoclaw-jetson-dispatch sudo install -d -o nemoclaw-jetson-dispatch -g nemoclaw-jetson-dispatch -m 0700 \ - /var/lib/nemoclaw-jetson-dispatch /etc/nemoclaw-jetson-dispatch + /var/lib/nemoclaw-jetson-dispatch ``` Bootstrap the deployment command from a separately reviewed checkout of `https://github.com/NVIDIA/NemoClaw.git`. -Replace both placeholder SHAs with full lowercase 40-character reviewed commit SHAs: +Replace the placeholder with the full lowercase 40-character SHA of that reviewed checkout: ```bash set -euo pipefail @@ -185,30 +185,13 @@ test -z "$(git status --short)" sudo install -o root -g root -m 0755 \ tools/e2e/colossus-jetson-dispatch-deploy.sh \ /usr/local/sbin/nemoclaw-colossus-jetson-dispatch-deploy - -test "$(systemctl show --property=LoadState --value \ - nemoclaw-jetson-dispatch.service)" = not-found -sudo test ! -e /var/lib/nemoclaw-jetson-dispatch/state/device.lock -sudo test ! -L /var/lib/nemoclaw-jetson-dispatch/state/device.lock -REVIEWED_COMMIT_SHA=0000000000000000000000000000000000000000 -sudo /usr/local/sbin/nemoclaw-colossus-jetson-dispatch-deploy \ - --commit "$REVIEWED_COMMIT_SHA" -test "$(sudo readlink /opt/nemoclaw-jetson-dispatch/current)" = \ - "/opt/nemoclaw-jetson-dispatch/releases/$REVIEWED_COMMIT_SHA" -sudo test -L /usr/local/libexec/nemoclaw-jetson-cleanup -test "$(sudo readlink /usr/local/libexec/nemoclaw-jetson-cleanup)" = \ - /opt/nemoclaw-jetson-dispatch/current/tools/e2e/jetson-dispatch-cleanup.sh +test "$(sudo stat --format='%F:%u:%g:%a' -- \ + /usr/local/sbin/nemoclaw-colossus-jetson-dispatch-deploy)" = \ + 'regular file:0:0:755' ``` The deployment command requires root and accepts only `--commit `. -It fetches only that commit from the fixed `https://github.com/NVIDIA/NemoClaw.git` origin. -It stores each verified release at `/opt/nemoclaw-jetson-dispatch/releases/`. -Each release directory must be owned by `root:root` with mode `0755`. -The command verifies the origin, commit, unmodified worktree, and bundled cleanup file before selection. -It installs one root-owned stable symbolic link from `/usr/local/libexec/nemoclaw-jetson-cleanup` to `/opt/nemoclaw-jetson-dispatch/current/tools/e2e/jetson-dispatch-cleanup.sh`. -It then selects the dispatcher and cleanup program together with one atomic absolute `/opt/nemoclaw-jetson-dispatch/current` symbolic-link switch. -The initial deployment requires the systemd service and `device.lock` to be absent. -It installs the release selection and cleanup link without starting a service. +It rejects any additional argument. The command does not update its installed copy. Install a reviewed deployment-command revision separately when that command changes. @@ -241,7 +224,7 @@ sudo install -o nemoclaw-jetson-dispatch -g nemoclaw-jetson-dispatch -m 0600 \ rm /tmp/jetson_known_hosts ``` -Treat the verified SSH host identity as part of the protected baseline. +The pinned `known_hosts` file validates the SSH host identity separately from the persisted cleanup baseline. Do not accept a changed host key without reconciling it through the serial console or another trusted channel. ## Define the Cleanup Program @@ -325,96 +308,89 @@ After the helper succeeds, the worker independently verifies these conditions ov The worker reports cleanup failure when any helper or independent verification step fails. The dispatcher runs the cleanup program as `nemoclaw-jetson-dispatch`. -The service unit below prevents privilege elevation. +The managed service unit prevents privilege elevation. Do not remove that protection or grant the dispatcher account passwordless `sudo` access. -Test cleanup-program access and the SSH path as the service account: - -```bash -sudo -u nemoclaw-jetson-dispatch test -x \ - /usr/local/libexec/nemoclaw-jetson-cleanup -sudo -u nemoclaw-jetson-dispatch ssh -F /dev/null -o BatchMode=yes \ - -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes \ - -o UserKnownHostsFile=/var/lib/nemoclaw-jetson-dispatch/known_hosts \ - -i /var/lib/nemoclaw-jetson-dispatch/id_ed25519 \ - nvidia@192.168.55.1 'uname -m' -``` +## Configure the Dispatcher Service -Do not invoke the cleanup program manually without the dispatcher-created device lock and baseline record. -The proof-job procedure below exercises cleanup and verifies its result. +Review these fixed files in the selected commit before deployment: -## Configure the Dispatcher Service +- `tools/e2e/colossus-jetson-dispatch.environment` +- `tools/e2e/nemoclaw-jetson-dispatch.service` -Get the immutable GitHub repository ID: +The environment fixes the repository ID, state path, timeouts, Jetson SSH destination, pinned SSH files, and cleanup executable. +The unit fixes the service account, selected-release working directory, Node.js command, restart policy, and filesystem restrictions. +It sets `TimeoutStopSec=360` so systemd allows the bounded cleanup interval during service stop. -```bash -gh api repos/NVIDIA/NemoClaw --jq .id -``` +For an initial deployment, the dispatcher service must have `LoadState=not-found`. +The device lock, destination environment file, and destination unit file must be absent. +The Cloudflare Tunnel service must be absent or both disabled and inactive. -Create `/etc/nemoclaw-jetson-dispatch/environment` as a root-owned file with mode `0600`. -Substitute the repository ID returned above: +Replace the placeholder with the full lowercase 40-character SHA of the reviewed release, then run one command: -```text -JETSON_DISPATCH_STATE_DIRECTORY=/var/lib/nemoclaw-jetson-dispatch/state -JETSON_DISPATCH_GITHUB_REPOSITORY_ID=REPOSITORY_ID -JETSON_DISPATCH_PORT=8787 -JETSON_DISPATCH_EXECUTION_TIMEOUT_SECONDS=3000 -JETSON_DISPATCH_CLEANUP_TIMEOUT_SECONDS=300 -JETSON_DISPATCH_TEST_TIMEOUT_SECONDS=2700 -JETSON_DISPATCH_SSH_DESTINATION=nvidia@192.168.55.1 -JETSON_DISPATCH_SSH_IDENTITY_FILE=/var/lib/nemoclaw-jetson-dispatch/id_ed25519 -JETSON_DISPATCH_SSH_KNOWN_HOSTS_FILE=/var/lib/nemoclaw-jetson-dispatch/known_hosts -JETSON_DISPATCH_CLEANUP_EXECUTABLE=/usr/local/libexec/nemoclaw-jetson-cleanup +```bash +sudo nemoclaw-colossus-jetson-dispatch-deploy --commit 0000000000000000000000000000000000000000 ``` -Install `/etc/systemd/system/nemoclaw-jetson-dispatch.service`: +The command reports five stages: -```ini -[Unit] -Description=NemoClaw Jetson dispatcher -After=network-online.target -Wants=network-online.target +1. Validate the request, service-owned home, dispatcher account, SSH key, pinned host key, and Node.js version. +2. Verify the absent service, device lock, destination files, and public ingress. +3. Fetch and verify the exact commit from `https://github.com/NVIDIA/NemoClaw.git`. +4. Select the dispatcher and cleanup code with one atomic `current` switch. +5. Install, enable, start, and verify the dispatcher service. -[Service] -Type=simple -User=nemoclaw-jetson-dispatch -Group=nemoclaw-jetson-dispatch -UMask=0077 -WorkingDirectory=/opt/nemoclaw-jetson-dispatch/current -EnvironmentFile=/etc/nemoclaw-jetson-dispatch/environment -ExecStart=/usr/bin/node --experimental-strip-types --no-warnings tools/e2e/jetson-dispatch-service.mts -Restart=on-failure -RestartSec=5 -TimeoutStopSec=360 -NoNewPrivileges=true -PrivateTmp=true -ProtectHome=true -ProtectSystem=strict -ReadWritePaths=/var/lib/nemoclaw-jetson-dispatch - -[Install] -WantedBy=multi-user.target -``` - -Start the service and confirm that it listens only on the loopback address: +The command accepts an absent cleanup link or verifies the exact managed link before release selection. +It stores each verified release at `/opt/nemoclaw-jetson-dispatch/releases/`. +Each release directory must be owned by `root:root` with mode `0755`. +The command verifies the fixed origin, exact commit, unmodified worktree, cleanup program, environment, and unit before selection. +It installs `/etc/nemoclaw-jetson-dispatch/environment` as `root:root` mode `0600`. +It installs `/etc/systemd/system/nemoclaw-jetson-dispatch.service` as `root:root` mode `0644`. +It runs `systemctl daemon-reload` and `systemctl enable --now nemoclaw-jetson-dispatch.service`. +Before success, it requires the service to listen only on `127.0.0.1:8787`, an anonymous job request to return HTTP `401`, and the Cloudflare Tunnel service to remain disabled and inactive. + +If initial startup or verification fails after enablement, the command disables and stops the service before rollback. +It requires exact `ActiveState=inactive` and an absent device lock before it restores the prior release and cleanup selection. +An earlier selection or configuration-installation failure restores the prior selection and removes only files or links created by the attempt. +Rollback removes any environment and unit that the attempt installed, reloads systemd, and requires `LoadState=not-found`. +If it cannot establish these conditions, it reports rollback failure. +The command never enables or starts the Cloudflare Tunnel service. +It accepts no cleanup override and does not change the cleanup allowlist. + +After the command returns, test cleanup-program access and the SSH path as the service account: ```bash -sudo systemctl daemon-reload -sudo systemctl enable --now nemoclaw-jetson-dispatch.service -sudo systemctl status nemoclaw-jetson-dispatch.service -sudo ss -ltnp | grep '127.0.0.1:8787' +sudo -u nemoclaw-jetson-dispatch test -x \ + /usr/local/libexec/nemoclaw-jetson-cleanup +sudo -u nemoclaw-jetson-dispatch ssh -F /dev/null -o BatchMode=yes \ + -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes \ + -o UserKnownHostsFile=/var/lib/nemoclaw-jetson-dispatch/known_hosts \ + -i /var/lib/nemoclaw-jetson-dispatch/id_ed25519 \ + nvidia@192.168.55.1 'uname -m' ``` -An anonymous request must fail: +Do not invoke the cleanup program manually without the dispatcher-created device lock and baseline record. +The proof-job procedure below exercises cleanup and verifies its result. + +For independent verification or recovery, repeat the command's loopback checks: ```bash -curl --disable --noproxy '*' --fail-with-body \ - -X POST http://127.0.0.1:8787/v1/jobs \ - -H 'Content-Type: application/json' \ - --data '{"schemaVersion":1,"target":"jetson-nvmap-gpu","candidateSha":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","workflowRunId":"1","workflowRunAttempt":1}' +set -euo pipefail +test "$(sudo systemctl show --property=ActiveState --value \ + nemoclaw-jetson-dispatch.service)" = active +listeners="$(sudo ss -H -ltn 'sport = :8787')" +test -n "$listeners" +printf '%s\n' "$listeners" | awk '$4 != "127.0.0.1:8787" { exit 1 }' +HTTP_CODE="$( + curl --disable --noproxy '*' --silent --show-error --output /dev/null \ + --write-out '%{http_code}' --max-time 5 --request POST \ + --header 'Content-Type: application/json' \ + --data '{"schemaVersion":1,"target":"jetson-nvmap-gpu","candidateSha":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","workflowRunId":"1","workflowRunAttempt":1}' \ + http://127.0.0.1:8787/v1/jobs +)" +test "$HTTP_CODE" = 401 ``` -The expected result is HTTP `401`. A malformed request returns HTTP `400`, and an unknown route returns HTTP `404`. ## Deploy a Later Reviewed Commit @@ -524,7 +500,7 @@ Do not restart it until the dispatcher again binds only to `127.0.0.1:8787` and Then rerun the complete later-deployment subshell. Its exit trap keeps the tunnel stopped unless `ActiveState=active` and the config-free, direct public HTTP `401` proof both succeed. -The command does not modify the dispatcher environment, systemd unit, SSH credentials, or Cloudflare credentials. +A later deployment does not modify the dispatcher environment, systemd unit, SSH credentials, or Cloudflare credentials. It does not update itself. Normal deployment requires the selected release to preserve the documented cleanup allowlist. A cleanup-scope change requires separate review and a corresponding runbook update before deployment. diff --git a/test/e2e/support/colossus-jetson-dispatch-deploy.test.ts b/test/e2e/support/colossus-jetson-dispatch-deploy.test.ts index db3f623b6db..2b84b14d7c5 100644 --- a/test/e2e/support/colossus-jetson-dispatch-deploy.test.ts +++ b/test/e2e/support/colossus-jetson-dispatch-deploy.test.ts @@ -9,7 +9,12 @@ import path from "node:path"; import { afterEach, describe, expect, it } from "vitest"; const DEPLOY_SCRIPT = path.join(process.cwd(), "tools/e2e/colossus-jetson-dispatch-deploy.sh"); +const ENVIRONMENT_SOURCE = path.join( + process.cwd(), + "tools/e2e/colossus-jetson-dispatch.environment", +); const FIXED_ORIGIN = "https://github.com/NVIDIA/NemoClaw.git"; +const UNIT_SOURCE = path.join(process.cwd(), "tools/e2e/nemoclaw-jetson-dispatch.service"); const temporaryDirectories: string[] = []; const HARNESS = String.raw` @@ -22,10 +27,18 @@ current_link="$deploy_root/current" deploy_lock="$deploy_root/deploy.lock" cleanup_executable="$TEST_ROOT/usr/local/libexec/nemoclaw-jetson-cleanup" cleanup_link_target="$current_link/$cleanup_relative" -state_directory="$TEST_ROOT/var/lib/nemoclaw-jetson-dispatch/state" +service_home="$TEST_ROOT/var/lib/nemoclaw-jetson-dispatch" +state_directory="$service_home/state" device_lock="$state_directory/device.lock" - -mkdir -p "$state_directory" +ssh_identity_file="$service_home/id_ed25519" +ssh_known_hosts_file="$service_home/known_hosts" +node_executable="$NODE_EXECUTABLE" +environment_file="$TEST_ROOT/etc/nemoclaw-jetson-dispatch/environment" +unit_file="$TEST_ROOT/etc/systemd/system/$service_name" + +mkdir -p "$state_directory" "${"$"}{environment_file%/*}" "${"$"}{unit_file%/*}" +printf 'test-private-key\n' >"$ssh_identity_file" +printf 'test-known-host\n' >"$ssh_known_hosts_file" [ "$SERVICE_LOAD_STATE" != loaded ] || : >"$TEST_ROOT/service-active" [ "$INITIAL_DEVICE_LOCK" != 1 ] || printf '%064d\n' 0 >"$device_lock" @@ -33,6 +46,32 @@ effective_uid() { printf '%s\n' "$FAKE_UID" } +id_exec() { + [ "$MISSING_ACCOUNT" != 1 ] || return 1 + printf '1001\n' +} + +require_service_owned_file() { + [ -f "$1" ] && [ ! -L "$1" ] +} + +require_service_owned_directory() { + [ "$INVALID_SERVICE_HOME" != 1 ] || fail "$1 must be a directory, not a symbolic link" + [ -d "$1" ] && [ ! -L "$1" ] +} + +ssh_identity_is_valid() { + [ "$INVALID_SSH_KEY" != 1 ] +} + +known_hosts_has_jetson() { + [ "$INVALID_KNOWN_HOSTS" != 1 ] +} + +node_version_is_supported() { + [ "$UNSUPPORTED_NODE" != 1 ] +} + install_directory() { /usr/bin/install -d -m "$2" "$1" } @@ -49,6 +88,10 @@ require_root_owned_file() { [ -f "$1" ] && [ ! -L "$1" ] } +root_owned_file_matches() { + [ -f "$1" ] && [ ! -L "$1" ] +} + symlink_owner() { printf '0:0\n' } @@ -93,7 +136,11 @@ git_exec() { } service_load_state() { - printf '%s\n' "$SERVICE_LOAD_STATE" + if [ -f "$unit_file" ]; then + printf 'loaded\n' + else + printf '%s\n' "$SERVICE_LOAD_STATE" + fi } service_active_state() { @@ -109,9 +156,37 @@ current_sha() { /usr/bin/readlink "$current_link" 2>/dev/null | /usr/bin/awk -F/ '{print $NF}' } +tunnel_is_active() { + tunnel_check_count="$(cat "$TEST_ROOT/tunnel-check-count" 2>/dev/null || printf '0')" + [ "$TUNNEL_ACTIVE" = 1 ] || + { [ "$TUNNEL_ACTIVATE_AFTER_FIRST_CHECK" = 1 ] && [ "$tunnel_check_count" -gt 1 ]; } +} + systemctl_exec() { printf 'systemctl\t%s\n' "$*" >>"$TEST_ROOT/service.log" case "$1" in + show) + if [ "${"$"}{!#}" = "$tunnel_service_name" ]; then + case "$2" in + --property=LoadState) + tunnel_check_count="$(cat "$TEST_ROOT/tunnel-check-count" 2>/dev/null || printf '0')" + tunnel_check_count="$((tunnel_check_count + 1))" + printf '%s\n' "$tunnel_check_count" >"$TEST_ROOT/tunnel-check-count" + if tunnel_is_active; then printf 'loaded\n'; else printf 'not-found\n'; fi + ;; + --property=ActiveState) + if tunnel_is_active; then printf 'active\n'; else printf 'inactive\n'; fi + ;; + --property=UnitFileState) + if tunnel_is_active; then printf 'enabled\n'; else printf 'disabled\n'; fi + ;; + *) return 1 ;; + esac + else + return 1 + fi + ;; + daemon-reload) : ;; stop) stop_count="$(cat "$TEST_ROOT/stop-count" 2>/dev/null || printf '0')" stop_count="$((stop_count + 1))" @@ -126,6 +201,16 @@ systemctl_exec() { /bin/rm -f "$device_lock" fi ;; + enable) + selected="$(current_sha)" + printf 'enable-sha\t%s\n' "$selected" >>"$TEST_ROOT/service.log" + [ "$selected" != "$FAIL_START_SHA" ] || return 1 + : >"$TEST_ROOT/service-active" + ;; + disable) + [ "$FAIL_INITIAL_ROLLBACK_DISABLE" != 1 ] || return 1 + /bin/rm -f "$TEST_ROOT/service-active" + ;; start) selected="$(current_sha)" printf 'start-sha\t%s\n' "$selected" >>"$TEST_ROOT/service.log" @@ -175,13 +260,21 @@ interface Fixture { interface DeployOptions { activeStateError?: boolean; fakeUid?: string; + failInitialRollbackDisable?: boolean; failRollbackStop?: boolean; failSelectSha?: string; serviceLoadState?: "loaded" | "not-found"; failStartSha?: string; failVerifySha?: string; initialDeviceLock?: boolean; + invalidKnownHosts?: boolean; + invalidServiceHome?: boolean; + invalidSshKey?: boolean; leaveDeviceLock?: boolean; + missingAccount?: boolean; + tunnelActive?: boolean; + tunnelActivatesAfterFirstCheck?: boolean; + unsupportedNode?: boolean; } afterEach(() => { @@ -205,8 +298,12 @@ function createFixture(): Fixture { git(repository, "config", "user.name", "NemoClaw Test"); git(repository, "config", "user.email", "test@example.com"); const cleanup = path.join(repository, "tools/e2e/jetson-dispatch-cleanup.sh"); + const environment = path.join(repository, "tools/e2e/colossus-jetson-dispatch.environment"); + const unit = path.join(repository, "tools/e2e/nemoclaw-jetson-dispatch.service"); fs.writeFileSync(cleanup, "#!/usr/bin/env bash\necho first-release\n", { mode: 0o755 }); - git(repository, "add", cleanup); + fs.writeFileSync(environment, "JETSON_DISPATCH_PORT=8787\n"); + fs.writeFileSync(unit, "[Service]\nEnvironmentFile=/etc/nemoclaw-jetson-dispatch/environment\n"); + git(repository, "add", "tools/e2e"); git(repository, "commit", "--quiet", "-m", "first release"); const firstSha = git(repository, "rev-parse", "HEAD"); fs.writeFileSync(cleanup, "#!/usr/bin/env bash\necho second-release\n", { mode: 0o755 }); @@ -227,6 +324,7 @@ function runDeploy( ...process.env, ACTIVE_STATE_ERROR: options.activeStateError ? "1" : "0", DEPLOY_SCRIPT, + FAIL_INITIAL_ROLLBACK_DISABLE: options.failInitialRollbackDisable ? "1" : "0", FAIL_ROLLBACK_STOP: options.failRollbackStop ? "1" : "0", FAIL_SELECT_SHA: options.failSelectSha ?? "", FAIL_START_SHA: options.failStartSha ?? "", @@ -234,10 +332,17 @@ function runDeploy( FAKE_UID: options.fakeUid ?? "0", FIXTURE_REPOSITORY: fixture.repository, INITIAL_DEVICE_LOCK: options.initialDeviceLock ? "1" : "0", + INVALID_KNOWN_HOSTS: options.invalidKnownHosts ? "1" : "0", + INVALID_SERVICE_HOME: options.invalidServiceHome ? "1" : "0", + INVALID_SSH_KEY: options.invalidSshKey ? "1" : "0", LEAVE_DEVICE_LOCK: options.leaveDeviceLock ? "1" : "0", + MISSING_ACCOUNT: options.missingAccount ? "1" : "0", NODE_EXECUTABLE: process.execPath, SERVICE_LOAD_STATE: options.serviceLoadState ?? "not-found", TEST_ROOT: fixture.directory, + TUNNEL_ACTIVE: options.tunnelActive ? "1" : "0", + TUNNEL_ACTIVATE_AFTER_FIRST_CHECK: options.tunnelActivatesAfterFirstCheck ? "1" : "0", + UNSUPPORTED_NODE: options.unsupportedNode ? "1" : "0", }, }); } @@ -247,8 +352,10 @@ function deploymentPaths(fixture: Fixture) { return { cleanup: path.join(fixture.directory, "usr/local/libexec/nemoclaw-jetson-cleanup"), current: path.join(root, "current"), + environment: path.join(fixture.directory, "etc/nemoclaw-jetson-dispatch/environment"), releases: path.join(root, "releases"), serviceLog: path.join(fixture.directory, "service.log"), + unit: path.join(fixture.directory, "etc/systemd/system/nemoclaw-jetson-dispatch.service"), }; } @@ -257,24 +364,170 @@ function readIfPresent(file: string): string { } describe("Colossus Jetson dispatcher deployment", () => { - it("deploys an exact commit from the fixed origin before the service is installed (#8142)", () => { + it("ships the fixed dispatcher environment and restricted systemd unit (#8142)", () => { + const environment = fs.readFileSync(ENVIRONMENT_SOURCE, "utf8"); + const unit = fs.readFileSync(UNIT_SOURCE, "utf8"); + + expect(environment).toContain("JETSON_DISPATCH_GITHUB_REPOSITORY_ID=1182547092"); + expect(environment).toContain("JETSON_DISPATCH_SSH_DESTINATION=nvidia@192.168.55.1"); + expect(environment).toContain( + "JETSON_DISPATCH_CLEANUP_EXECUTABLE=/usr/local/libexec/nemoclaw-jetson-cleanup", + ); + expect(environment).not.toContain("=REPOSITORY_ID"); + expect(unit).toContain("EnvironmentFile=/etc/nemoclaw-jetson-dispatch/environment"); + expect(unit).toContain("WorkingDirectory=/opt/nemoclaw-jetson-dispatch/current"); + expect(unit).toContain("NoNewPrivileges=true"); + expect(unit).not.toContain("nemoclaw-jetson-tunnel.service"); + }); + + it("installs and verifies an exact release when the service is absent (#8142)", () => { const fixture = createFixture(); const result = runDeploy(fixture, ["--commit", fixture.firstSha]); const paths = deploymentPaths(fixture); - expect(result.status).toBe(0); + expect(result.status, String(result.stderr)).toBe(0); expect(fs.readlinkSync(paths.current)).toBe(path.join(paths.releases, fixture.firstSha)); expect(fs.readlinkSync(paths.cleanup)).toBe( path.join(paths.current, "tools/e2e/jetson-dispatch-cleanup.sh"), ); expect(fs.readFileSync(paths.cleanup, "utf8")).toContain("first-release"); expect(fs.readdirSync(paths.releases)).toEqual([fixture.firstSha]); - expect(readIfPresent(paths.serviceLog)).toBe(""); + expect(fs.readFileSync(paths.environment, "utf8")).toBe("JETSON_DISPATCH_PORT=8787\n"); + expect(fs.readFileSync(paths.unit, "utf8")).toContain( + "EnvironmentFile=/etc/nemoclaw-jetson-dispatch/environment", + ); + expect(readIfPresent(paths.serviceLog)).toMatch( + /systemctl\tdaemon-reload[\s\S]*systemctl\tenable --now nemoclaw-jetson-dispatch\.service/u, + ); + expect(result.stdout).toMatch( + /\[1\/5\].*[\s\S]*\[2\/5\].*[\s\S]*\[3\/5\].*[\s\S]*\[4\/5\].*[\s\S]*\[5\/5\]/u, + ); + expect(result.stdout).toContain("public ingress remains disabled"); + expect(readIfPresent(paths.serviceLog)).not.toContain( + "enable --now nemoclaw-jetson-tunnel.service", + ); + expect(fs.readFileSync(path.join(fixture.directory, "curl.log"), "utf8")).toContain( + "curl\t--disable\t--noproxy\t*\t--silent", + ); expect(fs.readFileSync(path.join(fixture.directory, "git.log"), "utf8")).toContain( `remote\tadd\torigin\t${FIXED_ORIGIN}`, ); }); + it.each([ + ["dispatcher account", { missingAccount: true }, "account is required"], + ["service home", { invalidServiceHome: true }, "must be a directory"], + ["SSH identity", { invalidSshKey: true }, "is not a readable OpenSSH private key"], + ["pinned host key", { invalidKnownHosts: true }, "does not contain the pinned Jetson"], + ["Node.js version", { unsupportedNode: true }, "must be Node.js 22.19.0 or later"], + ] satisfies Array< + [string, DeployOptions, string] + >)("rejects initial deployment when the prepared %s is invalid (#8142)", (_name, options, error) => { + const fixture = createFixture(); + const result = runDeploy(fixture, ["--commit", fixture.firstSha], options); + const paths = deploymentPaths(fixture); + + expect(result.status).toBe(1); + expect(result.stderr).toContain(error); + expect(fs.existsSync(paths.current)).toBe(false); + expect(fs.existsSync(paths.environment)).toBe(false); + expect(fs.existsSync(paths.unit)).toBe(false); + }); + + it("rejects an unmanaged cleanup path before initial deployment (#8142)", () => { + const fixture = createFixture(); + const paths = deploymentPaths(fixture); + fs.mkdirSync(path.dirname(paths.cleanup), { recursive: true }); + fs.writeFileSync(paths.cleanup, "unmanaged\n"); + + const result = runDeploy(fixture, ["--commit", fixture.firstSha]); + + expect(result.status).toBe(1); + expect(result.stderr).toContain("exists without one managed current release"); + expect(fs.readFileSync(paths.cleanup, "utf8")).toBe("unmanaged\n"); + expect(fs.existsSync(paths.environment)).toBe(false); + expect(fs.existsSync(paths.unit)).toBe(false); + }); + + it("rejects an unmanaged current link before initial deployment (#8142)", () => { + const fixture = createFixture(); + const paths = deploymentPaths(fixture); + fs.mkdirSync(path.dirname(paths.current), { recursive: true }); + fs.symlinkSync(fixture.repository, paths.current); + + const result = runDeploy(fixture, ["--commit", fixture.firstSha]); + + expect(result.status).toBe(1); + expect(result.stderr).toContain("does not select one managed release"); + expect(fs.readlinkSync(paths.current)).toBe(fixture.repository); + expect(fs.existsSync(paths.cleanup)).toBe(false); + expect(fs.existsSync(paths.environment)).toBe(false); + expect(fs.existsSync(paths.unit)).toBe(false); + }); + + it("rejects initial deployment while public ingress is active (#8142)", () => { + const fixture = createFixture(); + const paths = deploymentPaths(fixture); + const result = runDeploy(fixture, ["--commit", fixture.firstSha], { + tunnelActive: true, + }); + + expect(result.status).toBe(1); + expect(result.stderr).toContain("must be disabled and inactive"); + expect(fs.existsSync(paths.current)).toBe(false); + expect(fs.existsSync(paths.environment)).toBe(false); + expect(fs.existsSync(paths.unit)).toBe(false); + }); + + it("rolls back initial deployment when public ingress becomes active (#8142)", () => { + const fixture = createFixture(); + const paths = deploymentPaths(fixture); + const result = runDeploy(fixture, ["--commit", fixture.firstSha], { + tunnelActivatesAfterFirstCheck: true, + }); + + expect(result.status).toBe(1); + expect(result.stderr).toContain("release, unit, and environment were rolled back"); + expect(fs.existsSync(paths.current)).toBe(false); + expect(fs.existsSync(paths.cleanup)).toBe(false); + expect(fs.existsSync(paths.environment)).toBe(false); + expect(fs.existsSync(paths.unit)).toBe(false); + }); + + it("rolls back the initial release, unit, and environment when verification fails (#8142)", () => { + const fixture = createFixture(); + const paths = deploymentPaths(fixture); + const result = runDeploy(fixture, ["--commit", fixture.firstSha], { + failVerifySha: fixture.firstSha, + }); + + expect(result.status).toBe(1); + expect(result.stderr).toContain("release, unit, and environment were rolled back"); + expect(fs.existsSync(paths.current)).toBe(false); + expect(fs.existsSync(paths.cleanup)).toBe(false); + expect(fs.existsSync(paths.environment)).toBe(false); + expect(fs.existsSync(paths.unit)).toBe(false); + expect(readIfPresent(paths.serviceLog)).toMatch( + /systemctl\tenable --now nemoclaw-jetson-dispatch\.service[\s\S]*systemctl\tdisable --now nemoclaw-jetson-dispatch\.service[\s\S]*systemctl\tdaemon-reload/u, + ); + }); + + it("reports when initial rollback cannot disable the service (#8142)", () => { + const fixture = createFixture(); + const paths = deploymentPaths(fixture); + const result = runDeploy(fixture, ["--commit", fixture.firstSha], { + failInitialRollbackDisable: true, + failVerifySha: fixture.firstSha, + }); + + expect(result.status).toBe(1); + expect(result.stderr).toContain("rollback did not restore the prepared host"); + expect(fs.readlinkSync(paths.current)).toBe(path.join(paths.releases, fixture.firstSha)); + expect(fs.readFileSync(paths.cleanup, "utf8")).toContain("first-release"); + expect(fs.existsSync(paths.environment)).toBe(true); + expect(fs.existsSync(paths.unit)).toBe(true); + }); + it("stops, switches, starts, and verifies an installed loopback service (#8142)", () => { const fixture = createFixture(); expect(runDeploy(fixture, ["--commit", fixture.firstSha]).status).toBe(0); diff --git a/test/e2e/support/jetson-dispatch-worker.test.ts b/test/e2e/support/jetson-dispatch-worker.test.ts index fba7969c53d..76518b75396 100644 --- a/test/e2e/support/jetson-dispatch-worker.test.ts +++ b/test/e2e/support/jetson-dispatch-worker.test.ts @@ -22,6 +22,10 @@ const cleanupProgram = fs.readFileSync( path.join(process.cwd(), "tools/e2e/jetson-dispatch-cleanup.sh"), "utf8", ); +const dispatcherServiceUnit = fs.readFileSync( + path.join(process.cwd(), "tools/e2e/nemoclaw-jetson-dispatch.service"), + "utf8", +); const workerProgram = fs.readFileSync( path.join(process.cwd(), "tools/e2e/jetson-dispatch-worker.mts"), "utf8", @@ -109,21 +113,36 @@ function loadConfig(files = deploymentFiles()) { } describe("Colossus SSH worker deployment boundary", () => { - it("uses the fixed deployment command before service startup (#8142)", () => { + it("uses one fixed command for initial service deployment (#8142)", () => { const deployment = - 'sudo /usr/local/sbin/nemoclaw-colossus-jetson-dispatch-deploy \\\n --commit "$REVIEWED_COMMIT_SHA"'; + "sudo nemoclaw-colossus-jetson-dispatch-deploy --commit 0000000000000000000000000000000000000000"; + const configure = dispatcherRunbook.indexOf("## Configure the Dispatcher Service"); expect(dispatcherRunbook).toContain( "tools/e2e/colossus-jetson-dispatch-deploy.sh \\\n /usr/local/sbin/nemoclaw-colossus-jetson-dispatch-deploy", ); expect(dispatcherRunbook).toContain(deployment); - expect(dispatcherRunbook).toContain("WorkingDirectory=/opt/nemoclaw-jetson-dispatch/current"); + expect(dispatcherRunbook).toContain("tools/e2e/colossus-jetson-dispatch.environment"); + expect(dispatcherRunbook).toContain("tools/e2e/nemoclaw-jetson-dispatch.service"); + expect(dispatcherServiceUnit).toContain( + "WorkingDirectory=/opt/nemoclaw-jetson-dispatch/current", + ); + expect(dispatcherRunbook.indexOf(deployment)).toBeGreaterThan(configure); expect(dispatcherRunbook.indexOf(deployment)).toBeLessThan( - dispatcherRunbook.indexOf("## Configure the Dispatcher Service"), + dispatcherRunbook.indexOf("## Deploy a Later Reviewed Commit"), ); expect(dispatcherRunbook).not.toContain("sudo git -C /opt/nemoclaw-jetson-dispatch init"); expect(dispatcherRunbook).not.toContain("git clone --branch main"); }); + it("distinguishes pinned SSH identity from the persisted cleanup baseline (#8142)", () => { + expect(dispatcherRunbook).toContain( + "The pinned `known_hosts` file validates the SSH host identity separately from the persisted cleanup baseline.", + ); + expect(dispatcherRunbook).not.toContain( + "Treat the verified SSH host identity as part of the protected baseline.", + ); + }); + it("keeps public ingress stopped until a later release passes local verification (#8142)", () => { const section = dispatcherRunbook.slice( dispatcherRunbook.indexOf("## Deploy a Later Reviewed Commit"), @@ -854,7 +873,7 @@ esac "Remove the dedicated Jetson public key and the Colossus SSH private key.", ); - expect(dispatcherRunbook).toContain("TimeoutStopSec=360"); + expect(dispatcherServiceUnit).toContain("TimeoutStopSec=360"); expect(stopTunnel).toBeGreaterThan(-1); expect(waitForLock).toBeGreaterThan(stopTunnel); expect(verifyCleanup).toBeGreaterThan(waitForLock); diff --git a/test/helpers/vitest-watch-triggers.ts b/test/helpers/vitest-watch-triggers.ts index 9b22c55391d..592ab5f4d4c 100644 --- a/test/helpers/vitest-watch-triggers.ts +++ b/test/helpers/vitest-watch-triggers.ts @@ -100,6 +100,14 @@ export const vitestWatchTriggerPatterns: VitestWatchTriggerPattern[] = [ pattern: /(?:^|\/)tools\/e2e\/colossus-jetson-dispatch-deploy\.sh$/, testsToRun: runTests("test/e2e/support/colossus-jetson-dispatch-deploy.test.ts"), }, + { + pattern: + /(?:^|\/)tools\/e2e\/(?:colossus-jetson-dispatch\.environment|nemoclaw-jetson-dispatch\.service)$/, + testsToRun: runTests( + "test/e2e/support/colossus-jetson-dispatch-deploy.test.ts", + "test/e2e/support/jetson-dispatch-worker.test.ts", + ), + }, { pattern: /(?:^|\/)(?:\.github\/workflows\/base-image\.yaml|scripts\/export-managed-base-image-contract\.sh)$/, diff --git a/tools/e2e/colossus-jetson-dispatch-deploy.sh b/tools/e2e/colossus-jetson-dispatch-deploy.sh index 81f9a1f0820..92bd0c4b880 100755 --- a/tools/e2e/colossus-jetson-dispatch-deploy.sh +++ b/tools/e2e/colossus-jetson-dispatch-deploy.sh @@ -14,16 +14,32 @@ releases_directory="$deploy_root/releases" current_link="$deploy_root/current" deploy_lock="$deploy_root/deploy.lock" cleanup_relative=tools/e2e/jetson-dispatch-cleanup.sh +environment_relative=tools/e2e/colossus-jetson-dispatch.environment +unit_relative=tools/e2e/nemoclaw-jetson-dispatch.service cleanup_executable=/usr/local/libexec/nemoclaw-jetson-cleanup cleanup_link_target="$current_link/$cleanup_relative" -state_directory=/var/lib/nemoclaw-jetson-dispatch/state +service_user=nemoclaw-jetson-dispatch +service_group=nemoclaw-jetson-dispatch +service_home=/var/lib/nemoclaw-jetson-dispatch +state_directory="$service_home/state" device_lock="$state_directory/device.lock" +ssh_identity_file="$service_home/id_ed25519" +ssh_known_hosts_file="$service_home/known_hosts" +node_executable=/usr/bin/node service_name=nemoclaw-jetson-dispatch.service +environment_file=/etc/nemoclaw-jetson-dispatch/environment +unit_file="/etc/systemd/system/$service_name" +tunnel_service_name=nemoclaw-jetson-tunnel.service service_port=8787 staging_directory="" temporary_link="" cleanup_stage="" +managed_file_stage="" +bootstrap_environment_installed=0 +bootstrap_unit_installed=0 +bootstrap_daemon_reloaded=0 +bootstrap_enable_attempted=0 usage() { echo "Usage: nemoclaw-colossus-jetson-dispatch-deploy --commit " >&2 @@ -81,6 +97,22 @@ sleep_exec() { /usr/bin/sleep "$@" } +id_exec() { + /usr/bin/id "$@" +} + +ssh_keygen_exec() { + /usr/bin/ssh-keygen "$@" +} + +install_file() { + /usr/bin/install -o root -g root -m "$3" "$1" "$2" +} + +files_match() { + /usr/bin/cmp -s "$1" "$2" +} + symlink_owner() { /usr/bin/stat -c '%u:%g' "$1" } @@ -120,6 +152,71 @@ require_root_owned_file() { fi } +root_owned_file_matches() { + local path="$1" expected_mode="$2" metadata + [ -f "$path" ] && [ ! -L "$path" ] || return 1 + metadata="$(/usr/bin/stat -c '%u:%g:%a' "$path")" || return 1 + [ "$metadata" = "0:0:$expected_mode" ] +} + +require_service_owned_file() { + local path="$1" expected_mode="$2" uid gid metadata + uid="$(id_exec -u "$service_user")" || fail "could not inspect the $service_user account" + gid="$(id_exec -g "$service_user")" || fail "could not inspect the $service_group group" + if [ ! -f "$path" ] || [ -L "$path" ]; then + fail "$path must be a regular file, not a symbolic link" + fi + metadata="$(/usr/bin/stat -c '%u:%g:%a' "$path")" || fail "could not inspect $path" + [ "$metadata" = "$uid:$gid:$expected_mode" ] \ + || fail "$path must be owned by $service_user:$service_group with mode $expected_mode" +} + +require_service_owned_directory() { + local path="$1" expected_mode="$2" uid gid metadata + uid="$(id_exec -u "$service_user")" || fail "could not inspect the $service_user account" + gid="$(id_exec -g "$service_user")" || fail "could not inspect the $service_group group" + if [ ! -d "$path" ] || [ -L "$path" ]; then + fail "$path must be a directory, not a symbolic link" + fi + metadata="$(/usr/bin/stat -c '%u:%g:%a' "$path")" || fail "could not inspect $path" + [ "$metadata" = "$uid:$gid:$expected_mode" ] \ + || fail "$path must be owned by $service_user:$service_group with mode $expected_mode" +} + +ssh_identity_is_valid() { + ssh_keygen_exec -y -P '' -f "$ssh_identity_file" >/dev/null 2>&1 +} + +known_hosts_has_jetson() { + ssh_keygen_exec -F 192.168.55.1 -f "$ssh_known_hosts_file" >/dev/null 2>&1 +} + +node_version_is_supported() { + "$node_executable" -e ' + const [major, minor] = process.versions.node.split(".").map(Number); + if (major < 22 || (major === 22 && minor < 19)) process.exit(1); + ' +} + +validate_dispatcher_prerequisites() { + local uid gid + uid="$(id_exec -u "$service_user")" || fail "the $service_user account is required" + gid="$(id_exec -g "$service_user")" || fail "the $service_group group is required" + [[ "$uid" =~ ^[1-9][0-9]*$ ]] || fail "$service_user must not use UID 0" + [[ "$gid" =~ ^[1-9][0-9]*$ ]] || fail "$service_group must not use GID 0" + + require_service_owned_directory "$service_home" 700 + require_service_owned_file "$ssh_identity_file" 600 + ssh_identity_is_valid \ + || fail "$ssh_identity_file is not a readable OpenSSH private key" + require_service_owned_file "$ssh_known_hosts_file" 600 + known_hosts_has_jetson \ + || fail "$ssh_known_hosts_file does not contain the pinned Jetson host key" + + [ -x "$node_executable" ] || fail "$node_executable is required" + node_version_is_supported || fail "$node_executable must be Node.js 22.19.0 or later" +} + cleanup_temporary_paths() { if [ -n "$staging_directory" ] && [[ "$staging_directory" == "$releases_directory"/.* ]]; then rm -rf -- "$staging_directory" @@ -130,6 +227,13 @@ cleanup_temporary_paths() { if [ -n "$cleanup_stage" ] && [[ "$cleanup_stage" == "${cleanup_executable%/*}"/.nemoclaw-jetson-cleanup.* ]]; then rm -f -- "$cleanup_stage" fi + if [ -n "$managed_file_stage" ]; then + case "$managed_file_stage" in + "${environment_file%/*}"/.environment.* | "${unit_file%/*}"/.nemoclaw-jetson-dispatch.service.*) + rm -f -- "$managed_file_stage" + ;; + esac + fi } trap cleanup_temporary_paths EXIT @@ -146,13 +250,20 @@ parse_commit() { printf '%s\n' "$2" } +print_stage() { + printf '[%s/5] %s\n' "$1" "$2" +} + ensure_layout() { install_directory "$deploy_root" 0755 install_directory "$releases_directory" 0755 install_directory "${cleanup_executable%/*}" 0755 + install_directory "${environment_file%/*}" 0755 require_root_owned_directory "$deploy_root" 755 require_root_owned_directory "$releases_directory" 755 require_root_owned_directory "${cleanup_executable%/*}" 755 + require_root_owned_directory "${environment_file%/*}" 755 + require_root_owned_directory "${unit_file%/*}" 755 } acquire_deploy_lock() { @@ -183,6 +294,8 @@ verify_release() { fi [ -z "$observed" ] || fail "release checkout is modified" require_root_owned_file "$release/$cleanup_relative" 755 + require_root_owned_file "$release/$environment_relative" 644 + require_root_owned_file "$release/$unit_relative" 644 } prepare_release() { @@ -275,6 +388,45 @@ validate_prior_cleanup_selection() { cleanup_link_matches || fail "$cleanup_executable exists without one managed current release" } +require_public_ingress_disabled() { + public_ingress_is_disabled || fail "$public_ingress_error" +} + +public_ingress_is_disabled() { + local load_state active_state unit_file_state + public_ingress_error="" + if ! load_state="$(systemctl_exec show --property=LoadState --value "$tunnel_service_name")"; then + public_ingress_error="could not inspect $tunnel_service_name" + return 1 + fi + if [ "$load_state" = not-found ]; then + return + fi + if [ "$load_state" != loaded ]; then + public_ingress_error="$tunnel_service_name has unsupported load state: $load_state" + return 1 + fi + if ! active_state="$(systemctl_exec show --property=ActiveState --value "$tunnel_service_name")"; then + public_ingress_error="could not inspect $tunnel_service_name activity" + return 1 + fi + if ! unit_file_state="$(systemctl_exec show --property=UnitFileState --value "$tunnel_service_name")"; then + public_ingress_error="could not inspect $tunnel_service_name enablement" + return 1 + fi + if [ "$active_state" != inactive ] || [ "$unit_file_state" != disabled ]; then + public_ingress_error="$tunnel_service_name must be disabled and inactive" + return 1 + fi +} + +require_bootstrap_destinations_absent() { + [ ! -e "$environment_file" ] && [ ! -L "$environment_file" ] \ + || fail "$environment_file exists while $service_name is not loaded" + [ ! -e "$unit_file" ] && [ ! -L "$unit_file" ] \ + || fail "$unit_file exists while $service_name is not loaded" +} + atomic_install_cleanup_link() { cleanup_link_matches && return 0 if [ -e "$cleanup_executable" ] || [ -L "$cleanup_executable" ]; then @@ -311,6 +463,35 @@ atomic_select_release() { [ -L "$current_link" ] && [ "$(/usr/bin/readlink "$current_link")" = "$release" ] } +install_managed_file() { + local source="$1" destination="$2" mode="$3" prefix="$4" + managed_file_stage="$(/usr/bin/mktemp "${destination%/*}/.${prefix}.XXXXXX")" || return 1 + if ! install_file "$source" "$managed_file_stage" "$mode"; then + rm -f -- "$managed_file_stage" + managed_file_stage="" + return 1 + fi + if ! root_owned_file_matches "$managed_file_stage" "$mode" \ + || ! files_match "$source" "$managed_file_stage" \ + || ! move_replace "$managed_file_stage" "$destination"; then + rm -f -- "$managed_file_stage" + managed_file_stage="" + return 1 + fi + managed_file_stage="" + root_owned_file_matches "$destination" "$mode" && files_match "$source" "$destination" +} + +install_bootstrap_files() { + local release="$1" + install_managed_file "$release/$environment_relative" "$environment_file" 600 environment \ + || return 1 + bootstrap_environment_installed=1 + install_managed_file "$release/$unit_relative" "$unit_file" 644 nemoclaw-jetson-dispatch.service \ + || return 1 + bootstrap_unit_installed=1 +} + loopback_service_responds() { local listeners http_code systemctl_exec is-active --quiet "$service_name" || return 1 @@ -351,6 +532,17 @@ start_and_verify_service() { verify_loopback_service } +enable_and_verify_initial_service() { + local load_state + systemctl_exec daemon-reload || return 1 + bootstrap_daemon_reloaded=1 + load_state="$(service_load_state)" || return 1 + [ "$load_state" = loaded ] || return 1 + bootstrap_enable_attempted=1 + systemctl_exec enable --now "$service_name" || return 1 + verify_loopback_service +} + restore_cleanup_selection() { local cleanup_was_present="$1" if [ "$cleanup_was_present" = 1 ]; then @@ -389,43 +581,78 @@ rollback_deployment() { [ "$rollback_failed" = 0 ] } +rollback_initial_deployment() { + local previous_release="$1" cleanup_was_present="$2" active_state load_state rollback_failed=0 + if [ "$bootstrap_enable_attempted" = 1 ]; then + systemctl_exec disable --now "$service_name" || return 1 + active_state="$(service_active_state)" || return 1 + [ "$active_state" = inactive ] || return 1 + device_lock_is_absent || return 1 + fi + + restore_release_selection "$previous_release" || rollback_failed=1 + restore_cleanup_selection "$cleanup_was_present" || rollback_failed=1 + + if [ "$bootstrap_unit_installed" = 1 ]; then + root_owned_file_matches "$unit_file" 644 || return 1 + rm -f -- "$unit_file" || return 1 + fi + if [ "$bootstrap_environment_installed" = 1 ]; then + root_owned_file_matches "$environment_file" 600 || return 1 + rm -f -- "$environment_file" || return 1 + fi + if [ "$bootstrap_daemon_reloaded" = 1 ]; then + systemctl_exec daemon-reload || return 1 + load_state="$(service_load_state)" || return 1 + [ "$load_state" = not-found ] || return 1 + fi + [ "$rollback_failed" = 0 ] +} + activate_release() { - local release="$1" service_installed="$2" + local release="$1" atomic_install_cleanup_link || return 1 atomic_select_release "$release" || return 1 cleanup_link_matches || return 1 [ "$(/usr/bin/readlink "$current_link")" = "$release" ] || return 1 - if [ "$service_installed" = 1 ]; then - start_and_verify_service || return 1 - fi } main() { local sha release load_state service_installed=0 previous_release="" cleanup_was_present=0 require_root sha="$(parse_commit "$@")" + print_stage 1 "Validate request and prepared host" + validate_dispatcher_prerequisites ensure_layout acquire_deploy_lock load_state="$(service_load_state)" || fail "could not inspect $service_name" if [ "$load_state" = loaded ]; then service_installed=1 + print_stage 2 "Stop and verify the dispatcher" stop_installed_service elif [ "$load_state" != not-found ]; then fail "$service_name has unsupported load state: $load_state" else + print_stage 2 "Verify initial deployment state" require_device_lock_absent + require_public_ingress_disabled + require_bootstrap_destinations_absent fi - previous_release="$(selected_release || true)" + if [ -e "$current_link" ] || [ -L "$current_link" ]; then + previous_release="$(selected_release)" || fail "could not validate $current_link" + fi validate_prior_cleanup_selection "$previous_release" [ -n "$previous_release" ] && cleanup_was_present=1 if [ "$service_installed" = 1 ] && [ -z "$previous_release" ]; then fail "$service_name is installed without one managed current release" fi + print_stage 3 "Fetch and verify the release" release="$(prepare_release "$sha")" - if ! activate_release "$release" "$service_installed"; then + print_stage 4 "Select dispatcher and cleanup code" + if ! activate_release "$release"; then if rollback_deployment "$previous_release" "$cleanup_was_present" "$service_installed"; then fail "release $sha activation or verification failed; the previous deployment state was restored" fi @@ -433,9 +660,23 @@ main() { fi if [ "$service_installed" = 1 ]; then + print_stage 5 "Start and verify the dispatcher" + if ! start_and_verify_service; then + if rollback_deployment "$previous_release" "$cleanup_was_present" "$service_installed"; then + fail "release $sha activation or verification failed; the previous deployment state was restored" + fi + fail "release $sha activation or verification failed, and rollback did not restore a verified service" + fi echo "Deployed Colossus Jetson dispatcher release $sha and verified its loopback service" else - echo "Deployed Colossus Jetson dispatcher release $sha; install the systemd service before starting it" + print_stage 5 "Install, enable, and verify the dispatcher" + if ! install_bootstrap_files "$release" || ! enable_and_verify_initial_service || ! public_ingress_is_disabled; then + if rollback_initial_deployment "$previous_release" "$cleanup_was_present"; then + fail "release $sha initial deployment failed; the release, unit, and environment were rolled back" + fi + fail "release $sha initial deployment failed, and rollback did not restore the prepared host" + fi + echo "Deployed Colossus Jetson dispatcher release $sha and verified its loopback service; public ingress remains disabled" fi } diff --git a/tools/e2e/colossus-jetson-dispatch.environment b/tools/e2e/colossus-jetson-dispatch.environment new file mode 100644 index 00000000000..a3fa0a8e618 --- /dev/null +++ b/tools/e2e/colossus-jetson-dispatch.environment @@ -0,0 +1,13 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +JETSON_DISPATCH_STATE_DIRECTORY=/var/lib/nemoclaw-jetson-dispatch/state +JETSON_DISPATCH_GITHUB_REPOSITORY_ID=1182547092 +JETSON_DISPATCH_PORT=8787 +JETSON_DISPATCH_EXECUTION_TIMEOUT_SECONDS=3000 +JETSON_DISPATCH_CLEANUP_TIMEOUT_SECONDS=300 +JETSON_DISPATCH_TEST_TIMEOUT_SECONDS=2700 +JETSON_DISPATCH_SSH_DESTINATION=nvidia@192.168.55.1 +JETSON_DISPATCH_SSH_IDENTITY_FILE=/var/lib/nemoclaw-jetson-dispatch/id_ed25519 +JETSON_DISPATCH_SSH_KNOWN_HOSTS_FILE=/var/lib/nemoclaw-jetson-dispatch/known_hosts +JETSON_DISPATCH_CLEANUP_EXECUTABLE=/usr/local/libexec/nemoclaw-jetson-cleanup diff --git a/tools/e2e/nemoclaw-jetson-dispatch.service b/tools/e2e/nemoclaw-jetson-dispatch.service new file mode 100644 index 00000000000..9c5834aae6b --- /dev/null +++ b/tools/e2e/nemoclaw-jetson-dispatch.service @@ -0,0 +1,27 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +[Unit] +Description=NemoClaw Jetson dispatcher +After=network-online.target +Wants=network-online.target + +[Service] +Type=simple +User=nemoclaw-jetson-dispatch +Group=nemoclaw-jetson-dispatch +UMask=0077 +WorkingDirectory=/opt/nemoclaw-jetson-dispatch/current +EnvironmentFile=/etc/nemoclaw-jetson-dispatch/environment +ExecStart=/usr/bin/node --experimental-strip-types --no-warnings tools/e2e/jetson-dispatch-service.mts +Restart=on-failure +RestartSec=5 +TimeoutStopSec=360 +NoNewPrivileges=true +PrivateTmp=true +ProtectHome=true +ProtectSystem=strict +ReadWritePaths=/var/lib/nemoclaw-jetson-dispatch + +[Install] +WantedBy=multi-user.target From d24ee49926dc689f53fb9a06d003504f04c787d7 Mon Sep 17 00:00:00 2001 From: San Dang Date: Tue, 11 Aug 2026 11:47:51 +0700 Subject: [PATCH 26/34] fix(e2e): clarify deployment guard control flow --- tools/e2e/colossus-jetson-dispatch-deploy.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tools/e2e/colossus-jetson-dispatch-deploy.sh b/tools/e2e/colossus-jetson-dispatch-deploy.sh index 92bd0c4b880..3d5711904d0 100755 --- a/tools/e2e/colossus-jetson-dispatch-deploy.sh +++ b/tools/e2e/colossus-jetson-dispatch-deploy.sh @@ -421,10 +421,12 @@ public_ingress_is_disabled() { } require_bootstrap_destinations_absent() { - [ ! -e "$environment_file" ] && [ ! -L "$environment_file" ] \ - || fail "$environment_file exists while $service_name is not loaded" - [ ! -e "$unit_file" ] && [ ! -L "$unit_file" ] \ - || fail "$unit_file exists while $service_name is not loaded" + if [ -e "$environment_file" ] || [ -L "$environment_file" ]; then + fail "$environment_file exists while $service_name is not loaded" + fi + if [ -e "$unit_file" ] || [ -L "$unit_file" ]; then + fail "$unit_file exists while $service_name is not loaded" + fi } atomic_install_cleanup_link() { From 586ef747645b5a0efe5bc6bbc1f657dfed863f9a Mon Sep 17 00:00:00 2001 From: San Dang Date: Tue, 11 Aug 2026 13:47:28 +0700 Subject: [PATCH 27/34] fix(e2e): incorporate Jetson POC findings --- .github/workflows/e2e.yaml | 6 +- scripts/install.sh | 2 - test/e2e/docs/jetson-colossus-dispatch.md | 66 ++- .../e2e-operations-workflow-boundary.test.ts | 3 +- test/e2e/support/e2e-workflow.test.ts | 2 + .../support/jetson-dispatch-contract.test.ts | 114 ++++- .../support/jetson-dispatch-worker.test.ts | 433 +++++++++++++++++- .../support/jetson-workflow-boundary.test.ts | 15 + tools/e2e/cli-artifact-workflow-boundary.mts | 2 +- tools/e2e/jetson-dispatch-cleanup.sh | 124 ++++- tools/e2e/jetson-dispatch-lifecycle.mts | 34 +- tools/e2e/jetson-dispatch-worker.mts | 215 ++++++++- tools/e2e/operations-workflow-boundary.mts | 7 +- tools/e2e/workflow-boundary.mts | 18 +- 14 files changed, 949 insertions(+), 92 deletions(-) diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index 5973c09d7da..abe58ecf09a 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -92,7 +92,7 @@ permissions: concurrency: group: e2e-${{ github.ref }}-${{ inputs.checkout_sha != '' && format('pr-{0}', inputs.pr_number) || (inputs.include_staging_brev_launchable && inputs.jobs == '' && inputs.targets == '' && format('full-{0}', github.run_id)) || inputs.targets || 'supported' }}-${{ inputs.checkout_sha != '' && 'manual-pr' || inputs.jobs || 'all-jobs' }} - cancel-in-progress: ${{ inputs.checkout_sha != '' }} + cancel-in-progress: ${{ inputs.checkout_sha != '' && !inputs.allow_jetson_dispatch }} env: NEMOCLAW_E2E_EXPECTED_SHA: ${{ inputs.checkout_sha }} @@ -4923,6 +4923,10 @@ jobs: jetson-nvmap-gpu: needs: generate-matrix if: ${{ inputs.allow_jetson_dispatch && github.repository == 'NVIDIA/NemoClaw' && github.ref == 'refs/heads/main' && github.event_name == 'workflow_dispatch' && (inputs.checkout_repository == '' || inputs.checkout_repository == github.repository) && ((inputs.jobs == '' && inputs.targets == '') || contains(format(',{0},', inputs.jobs), ',jetson-nvmap-gpu,') || contains(format(',{0},', inputs.targets), ',jetson-nvmap-gpu,')) }} + concurrency: + group: jetson-nvmap-gpu-colossus + queue: max + cancel-in-progress: false runs-on: ubuntu-latest timeout-minutes: 60 permissions: diff --git a/scripts/install.sh b/scripts/install.sh index 88b9cffa282..012851cc9a9 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -3102,8 +3102,6 @@ run_installer_host_preflight() { if (host.isWsl) { infoLines.push("Running under WSL"); } - const findingIds = admission.admitted ? [] : stableIds(admission.findingIds); - const capabilityIds = admission.admitted ? [] : stableIds(admission.capabilityIds); if (!admission.admitted) { if (findingIds.length > 0) { actionLines.push(`Admission finding IDs: ${findingIds.join(", ")}`); diff --git a/test/e2e/docs/jetson-colossus-dispatch.md b/test/e2e/docs/jetson-colossus-dispatch.md index a1263bf28da..3943bec4325 100644 --- a/test/e2e/docs/jetson-colossus-dispatch.md +++ b/test/e2e/docs/jetson-colossus-dispatch.md @@ -98,9 +98,11 @@ The worker creates `/var/tmp/nemoclaw-jetson-e2e/` and sets these job-loc - `XDG_DATA_HOME=/home/.local/share` - `XDG_STATE_HOME=/home/.local/state` - `XDG_BIN_HOME=/home/.local/bin` +- `XDG_RUNTIME_DIR=/runtime` - `npm_config_prefix=/npm-prefix` - `PATH=$XDG_BIN_HOME:/npm-prefix/bin:$PATH` +The worker unsets `DBUS_SESSION_BUS_ADDRESS` so onboarding uses OpenShell's existing standalone fallback when the job-local systemd user service cannot load. The worker must not set `NEMOCLAW_DEFER_OPENSHELL_INSTALL`. It must not invoke `scripts/install-openshell.sh`. The existing live E2E runs `bash install.sh --non-interactive`. @@ -127,11 +129,16 @@ Before candidate execution, the worker records this protected tool and model bas - The resolved Node.js path and version. - The resolved npm path and version. -- The resolved Ollama path and a SHA-256 digest of the sorted Ollama model names and IDs. +- The resolved Ollama path and the sorted pre-existing Ollama model names and IDs. - The required absence of host-level `openshell`, `openshell-gateway`, and `openshell-sandbox` binaries. +The Ollama list accepts at most 64 sorted, unique model name and ID rows whose decoded content is at most 3 KiB. +The SSH probe output is limited to 4 KiB, while the persisted baseline record and its reader are limited to 8 KiB. +Before candidate execution, the worker serializes the baseline and rejects it if persistence would exceed that 8 KiB read bound. The dispatcher stores the recorded values in a private `.baseline.json` state file. -After cleanup, the worker repeats the probes and compares them with that record. +After cleanup, the worker repeats the probes and requires every pre-existing Ollama model name and ID to remain. +Additional models installed by the job, such as `qwen3.5:9b`, are allowed only while the post-cleanup list stays within the same row and size bounds. +An oversized post-cleanup list fails cleanup and retains the device lock without removing any model. Before and after candidate execution, the worker also requires `/dev/nvmap` and the Docker NVIDIA runtime to be available. The worker keeps the record through cleanup and device-lock release so startup recovery can repeat the same comparison. The host retention policy may remove it only after no device lock exists. @@ -151,6 +158,7 @@ These other host resources also remain outside the cleanup allowlist: - Colossus credentials, service configuration, and job evidence. The cleanup program must not change or remove any resource outside its allowlist. +It never removes Ollama models. Review its command construction and target resolution before deployment. Do not use broad process termination, Docker pruning, wildcard paths, or host-wide package removal. @@ -255,6 +263,8 @@ It accepts a helper or forward PID only when its environment has the exact job ` - `openshell forward` - `cloudflared` +Discovery, worker absence verification, and the teardown probe fail closed when the owner, environment, or command of a live same-user process cannot be read from `/proc`. +A process that disappears during inspection or is identified as owned by a different user is ignored. It merges them into a mode-`0600` private `.cleanup.json` record on Colossus. The record survives retries so stale-lock recovery can clean and verify the same identities. The cleanup program must not execute OpenShell or any other executable installed in the job workspace. @@ -265,7 +275,7 @@ The destructive phase must perform these bounded actions: 2. Remove the exact labeled sandbox containers and exact gateway container. 3. Remove the recorded volumes and reserved test image tags. 4. Remove the helper-service directory and `/var/tmp/nemoclaw-jetson-e2e/` workspace for the locked job. -5. Independently verify that the allowlisted resources are absent, host OpenShell remains absent, and the host baseline matches. +5. Independently verify that the allowlisted resources are absent, host OpenShell remains absent, the protected tools match, and every pre-existing Ollama model name and ID remains. The cleanup program must be idempotent. It must treat an already absent allowlisted resource as success. @@ -301,7 +311,7 @@ After the helper succeeds, the worker independently verifies these conditions ov - The `openshell-cluster-nemoclaw` gateway container and volume are absent. - No `nemoclaw-sandbox-local` image has a tag that begins with `e2e-jetson-nvmap-`. - Every Docker volume and process ID in the merged cleanup record is absent. -- Every recorded Node.js, npm, Ollama, and Ollama model baseline value matches. +- Every recorded Node.js, npm, and Ollama tool value matches, and every pre-existing Ollama model name and ID remains. - No host-level `openshell`, `openshell-gateway`, or `openshell-sandbox` binary resolves or exists in a checked host binary path. - `/dev/nvmap` exists, and Docker still reports the NVIDIA runtime. @@ -652,6 +662,9 @@ gh workflow run .github/workflows/e2e.yaml --repo NVIDIA/NemoClaw --ref main \ -f review_reason='Reviewed this PR commit for the isolated Jetson E2E.' ``` +The `jetson-nvmap-gpu` job uses the fixed `jetson-nvmap-gpu-colossus` concurrency group. +`queue: max` queues every dispatch, and `cancel-in-progress: false` prevents automatic cancellation. + The controller must run on `ubuntu-latest`. The GitHub controller log must show one `Jetson dispatch accepted as ` line. The Colossus journal must not contain a bearer token. @@ -757,6 +770,7 @@ A repeated deterministic dispatch returns that recovered failure without rerunni If cleanup fails, startup fails or the completed job reports `conclusion: "cleanup-failed"` with `cleanup: "failed"`. If cleanup succeeds but lock removal fails, the completed job reports `conclusion: "cleanup-failed"` with `cleanup: "succeeded"`. The lock remains in either case. +Bounded status error text retains the newest cleanup, persistence, or lock-removal error. If the service stops before durable persistence completes, destructive cleanup has not started. If it stops after durable persistence, the cleanup record and device lock remain for startup recovery. @@ -992,10 +1006,48 @@ if printf '%s\n' "$volume_names" | grep -Fqx openshell-cluster-nemoclaw; then echo 'The job-owned gateway volume remains' >&2 exit 1 fi +read_proc_uid() { + awk '/^Uid:/ { print $2; found = 1; exit } END { exit found ? 0 : 1 }' \ + "$1/status" 2>/dev/null +} +read_proc_environment() { + dd if="$1/environ" status=none 2>/dev/null | tr '\000' '\n' +} +read_proc_command() { + dd if="$1/cmdline" status=none 2>/dev/null | tr '\000' ' ' +} +handle_proc_read_failure() { + local proc_dir="$1" field="$2" process_uid directory_uid + [ -d "$proc_dir" ] || return 0 + if process_uid="$(read_proc_uid "$proc_dir")"; then + [ "$process_uid" = "$(id -u)" ] || return 0 + else + [ -d "$proc_dir" ] || return 0 + if ! directory_uid="$(stat -c %u "$proc_dir" 2>/dev/null)"; then + [ -d "$proc_dir" ] || return 0 + echo "Unable to verify the owner of a live process after a failed $field read" >&2 + exit 1 + fi + [ "$directory_uid" = "$(id -u)" ] || return 0 + fi + echo "Unable to inspect $field for a live same-user process" >&2 + exit 1 +} for proc_dir in /proc/[0-9]*; do - [ -r "$proc_dir/environ" ] || continue - tr '\000' '\n' <"$proc_dir/environ" | grep -Fqx "HOME=$job_home" || continue - cmdline="$(tr '\000' ' ' <"$proc_dir/cmdline")" + if ! process_uid="$(read_proc_uid "$proc_dir")"; then + handle_proc_read_failure "$proc_dir" owner + continue + fi + [ "$process_uid" = "$(id -u)" ] || continue + if ! environment="$(read_proc_environment "$proc_dir")"; then + handle_proc_read_failure "$proc_dir" environment + continue + fi + printf '%s\n' "$environment" | grep -Fqx "HOME=$job_home" || continue + if ! cmdline="$(read_proc_command "$proc_dir")"; then + handle_proc_read_failure "$proc_dir" command + continue + fi case "$cmdline" in *ollama-auth-proxy.*|*openshell-gateway*|*openshell-forward*|*openshell\ forward*|*cloudflared*) echo "A job-owned helper process remains: ${proc_dir##*/}" >&2 diff --git a/test/e2e/support/e2e-operations-workflow-boundary.test.ts b/test/e2e/support/e2e-operations-workflow-boundary.test.ts index 8cbef3c970b..9a789dd6a82 100644 --- a/test/e2e/support/e2e-operations-workflow-boundary.test.ts +++ b/test/e2e/support/e2e-operations-workflow-boundary.test.ts @@ -14,6 +14,7 @@ import { validateE2eOperationsWorkflowBoundary, } from "../../../tools/e2e/operations-workflow-boundary.mts"; import { validateE2eWorkflow } from "../../../tools/e2e/workflow-boundary.mts"; +import { testTimeoutOptions } from "../../helpers/timeouts.ts"; const AsyncFunction = Object.getPrototypeOf(async () => undefined).constructor as new ( ...parameters: string[] @@ -26,7 +27,7 @@ function workflowScript(jobName: string, stepName: string): string { return step?.with?.script as string; } -describe("E2E operations workflow boundary", () => { +describe("E2E operations workflow boundary", testTimeoutOptions(15_000), () => { it("accepts the checked-in workflow and rejects aggregation, permission, and secret-scope drift", () => { expect(validateE2eOperationsWorkflowBoundary()).toEqual([]); diff --git a/test/e2e/support/e2e-workflow.test.ts b/test/e2e/support/e2e-workflow.test.ts index 9775e6a96be..1b3b06790d3 100644 --- a/test/e2e/support/e2e-workflow.test.ts +++ b/test/e2e/support/e2e-workflow.test.ts @@ -197,11 +197,13 @@ describe("e2e workflow boundary", () => { }; workflow.concurrency.group = "e2e-${{ github.ref }}-${{ inputs.checkout_sha != '' && format('pr-{0}', inputs.pr_number) || inputs.targets || 'supported' }}-${{ inputs.checkout_sha != '' && 'pr-gate' || inputs.jobs || 'all-jobs' }}"; + workflow.concurrency["cancel-in-progress"] = "${{ inputs.checkout_sha != '' }}"; delete workflow.jobs["staging-brev-launchable"]!.concurrency!.queue; expect(validateE2eWorkflow(workflow)).toEqual( expect.arrayContaining([ "workflow concurrency must isolate each full dispatch with github.run_id", + "workflow concurrency must not cancel an active Jetson dispatch", "staging-brev-launchable concurrency must queue all pending Launchable E2E runs without cancellation", ]), ); diff --git a/test/e2e/support/jetson-dispatch-contract.test.ts b/test/e2e/support/jetson-dispatch-contract.test.ts index 128729ae0bc..1c3fde3387a 100644 --- a/test/e2e/support/jetson-dispatch-contract.test.ts +++ b/test/e2e/support/jetson-dispatch-contract.test.ts @@ -31,6 +31,7 @@ import { MAX_JETSON_DISPATCH_LOG_BYTES, } from "../../../tools/e2e/jetson-dispatch-lifecycle.mts"; import { createJetsonDispatchServer } from "../../../tools/e2e/jetson-dispatch-service.mts"; +import { testTimeoutOptions } from "../../helpers/timeouts.ts"; const NOW_SECONDS = 1_800_000_000; const REPOSITORY_ID = "987654321"; @@ -550,33 +551,42 @@ describe("Jetson single-device lifecycle", () => { } }); - it("restores private completed status after in-memory eviction (#8142)", async () => { - const stateDirectory = temporaryDirectory(); - const dispatch = coordinator(stateDirectory, worker()); - await dispatch.initialize(); - let firstJobId = ""; - for (let index = 0; index < 129; index += 1) { - const accepted = dispatch.dispatch( - { ...REQUEST, candidateSha: index.toString(16).padStart(40, "0") }, - identity(), + it( + "restores private completed status after in-memory eviction (#8142)", + testTimeoutOptions(10_000), + async () => { + const stateDirectory = temporaryDirectory(); + const dispatch = coordinator(stateDirectory, worker()); + await dispatch.initialize(); + let firstJobId = ""; + for (let index = 0; index < 129; index += 1) { + const accepted = dispatch.dispatch( + { ...REQUEST, candidateSha: index.toString(16).padStart(40, "0") }, + identity(), + ); + firstJobId ||= accepted.jobId; + await waitForCompletion(dispatch, accepted.jobId); + } + + expect(dispatch.status(firstJobId)).toMatchObject({ state: "completed" }); + expect(fs.existsSync(path.join(stateDirectory, `${firstJobId}.json`))).toBe(true); + fs.writeFileSync(path.join(stateDirectory, `${firstJobId}.json`), "{"); + await expect(coordinator(stateDirectory, worker()).initialize()).rejects.toThrow( + `Jetson dispatch status ${firstJobId}.json is invalid`, ); - firstJobId ||= accepted.jobId; - await waitForCompletion(dispatch, accepted.jobId); - } - - expect(dispatch.status(firstJobId)).toMatchObject({ state: "completed" }); - expect(fs.existsSync(path.join(stateDirectory, `${firstJobId}.json`))).toBe(true); - fs.writeFileSync(path.join(stateDirectory, `${firstJobId}.json`), "{"); - await expect(coordinator(stateDirectory, worker()).initialize()).rejects.toThrow( - `Jetson dispatch status ${firstJobId}.json is invalid`, - ); - }); + }, + ); - it("keeps the device locked when cleanup fails (#8142)", async () => { + it("keeps the device locked when cleanup loses a pre-existing Ollama model (#8142)", async () => { const stateDirectory = temporaryDirectory(); const dispatch = coordinator( stateDirectory, - worker({ cleanup: async () => Promise.reject(new Error("cleanup helper failed")) }), + worker({ + cleanup: async () => + Promise.reject( + new Error("Jetson cleanup did not preserve every pre-existing Ollama model"), + ), + }), ); await dispatch.initialize(); const accepted = dispatch.dispatch(REQUEST, identity()); @@ -613,6 +623,66 @@ describe("Jetson single-device lifecycle", () => { expect(fs.existsSync(path.join(stateDirectory, "device.lock"))).toBe(true); }); + it("keeps a cleanup failure visible after a 500-character execution error (#8142)", async () => { + const stateDirectory = temporaryDirectory(); + const dispatch = coordinator( + stateDirectory, + worker({ + cleanup: async () => Promise.reject(new Error("cleanup verification failed")), + run: async () => Promise.reject(new Error("x".repeat(500))), + }), + ); + await dispatch.initialize(); + const accepted = dispatch.dispatch(REQUEST, identity()); + const completed = await waitForCompletion(dispatch, accepted.jobId); + + expect(completed.error).toContain("Jetson cleanup failed: cleanup verification failed"); + expect(completed.error).toHaveLength(500); + expect(fs.existsSync(path.join(stateDirectory, "device.lock"))).toBe(true); + }); + + it("keeps a final persistence failure visible after a 500-character execution error (#8142)", async () => { + const stateDirectory = temporaryDirectory(); + let rejectRun!: (error: Error) => void; + const run = vi.fn( + () => + new Promise((_resolve, reject) => { + rejectRun = reject; + }), + ); + const dispatch = coordinator(stateDirectory, worker({ run })); + await dispatch.initialize(); + const accepted = dispatch.dispatch(REQUEST, identity()); + await vi.waitFor(() => expect(run).toHaveBeenCalledOnce()); + const statusPath = path.join(stateDirectory, `${accepted.jobId}.json`); + fs.rmSync(statusPath); + fs.mkdirSync(statusPath); + rejectRun(new Error("x".repeat(500))); + const completed = await waitForCompletion(dispatch, accepted.jobId); + + expect(completed.error).toContain("Final status persistence failed:"); + expect(completed.error).toHaveLength(500); + expect(fs.existsSync(path.join(stateDirectory, "device.lock"))).toBe(true); + }); + + it("keeps a lock-removal failure visible after a 500-character execution error (#8142)", async () => { + const stateDirectory = temporaryDirectory(); + vi.spyOn(fs, "unlinkSync").mockImplementationOnce(() => { + throw new Error("lock filesystem unavailable"); + }); + const dispatch = coordinator( + stateDirectory, + worker({ run: async () => Promise.reject(new Error("x".repeat(500))) }), + ); + await dispatch.initialize(); + const accepted = dispatch.dispatch(REQUEST, identity()); + const completed = await waitForCompletion(dispatch, accepted.jobId); + + expect(completed.error).toContain("Jetson lock removal failed: lock filesystem unavailable"); + expect(completed.error).toHaveLength(500); + expect(fs.existsSync(path.join(stateDirectory, "device.lock"))).toBe(true); + }); + it("cleans a stale lock before accepting work after restart (#8142)", async () => { const stateDirectory = temporaryDirectory(); const staleJobId = "d".repeat(64); diff --git a/test/e2e/support/jetson-dispatch-worker.test.ts b/test/e2e/support/jetson-dispatch-worker.test.ts index 76518b75396..5f59b29bc9c 100644 --- a/test/e2e/support/jetson-dispatch-worker.test.ts +++ b/test/e2e/support/jetson-dispatch-worker.test.ts @@ -5,6 +5,7 @@ import { spawnSync } from "node:child_process"; import fs from "node:fs"; import os from "node:os"; import path from "node:path"; +import { pathToFileURL } from "node:url"; import { afterEach, describe, expect, it, vi } from "vitest"; @@ -41,13 +42,24 @@ const BASELINE = { npmPath: "/usr/bin/npm", npmVersion: "10.9.3", ollamaPath: "/usr/local/bin/ollama", - ollamaModelsSha256: "a".repeat(64), + ollamaModels: [{ name: "existing:latest", id: "a".repeat(12) }], openshellState: "absent", }; function baselineOutput(overrides: Partial = {}): string { const baseline = { ...BASELINE, ...overrides }; - return `${Object.entries(baseline) + const ollamaModelsBase64 = Buffer.from( + baseline.ollamaModels.map((model) => `${model.name}\t${model.id}`).join("\n"), + ).toString("base64"); + return `${Object.entries({ + nodePath: baseline.nodePath, + nodeVersion: baseline.nodeVersion, + npmPath: baseline.npmPath, + npmVersion: baseline.npmVersion, + ollamaPath: baseline.ollamaPath, + ollamaModelsBase64, + openshellState: baseline.openshellState, + }) .map(([key, value]) => `${key}\t${value}`) .join("\n")}\n`; } @@ -80,6 +92,68 @@ function persistCleanupEvidence( return file; } +function cleanupProcessFixture( + options: { + command?: string; + deny?: "cmdline" | "environ"; + disappear?: "cmdline" | "environ"; + home?: string; + uid?: number; + } = {}, +) { + const directory = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-jetson-proc-")); + temporaryDirectories.push(directory); + const procRoot = path.join(directory, "proc"); + const procDirectory = path.join(procRoot, "1234"); + const binDirectory = path.join(directory, "bin"); + fs.mkdirSync(procDirectory, { recursive: true }); + fs.mkdirSync(binDirectory); + fs.writeFileSync( + path.join(procDirectory, "status"), + `Name:\ttest\nUid:\t${options.uid ?? process.getuid!()}\t0\t0\t0\n`, + ); + fs.writeFileSync( + path.join(procDirectory, "environ"), + Buffer.from(`HOME=${options.home ?? "/job/home"}\0PATH=/usr/bin\0`), + ); + fs.writeFileSync( + path.join(procDirectory, "cmdline"), + Buffer.from(`${options.command ?? "node ollama-auth-proxy.mjs"}\0`), + ); + fs.writeFileSync( + path.join(binDirectory, "dd"), + `#!/usr/bin/env bash +set -eu +input= +for argument in "$@"; do + case "$argument" in if=*) input="${"${argument#if=}"}" ;; esac +done +if [ "${"${DENY_PROC_FILE:-}"}" = "$input" ]; then exit 1; fi +if [ "${"${DISAPPEAR_PROC_FILE:-}"}" = "$input" ]; then rm -rf -- "${"${input%/*}"}"; exit 1; fi +/bin/cat "$input" +`, + { mode: 0o700 }, + ); + const functionsStart = cleanupProgram.indexOf("read_proc_uid() {"); + const functionsEnd = cleanupProgram.indexOf("\nauth_proxy_pid=", functionsStart); + if (functionsStart < 0 || functionsEnd < 0) + throw new Error("cleanup process functions are absent"); + const functions = cleanupProgram + .slice(functionsStart, functionsEnd) + .replace('proc_dir="/proc/$pid"', 'proc_dir="$PROC_ROOT/$pid"'); + return { + environment: { + ...process.env, + DENY_PROC_FILE: options.deny ? path.join(procDirectory, options.deny) : "", + DISAPPEAR_PROC_FILE: options.disappear ? path.join(procDirectory, options.disappear) : "", + PATH: `${binDirectory}:${process.env.PATH ?? ""}`, + PROC_ROOT: procRoot, + }, + functions, + procRoot, + }; +} + afterEach(() => { for (const directory of temporaryDirectories.splice(0)) { fs.rmSync(directory, { force: true, recursive: true }); @@ -113,6 +187,26 @@ function loadConfig(files = deploymentFiles()) { } describe("Colossus SSH worker deployment boundary", () => { + it("loads the dispatcher service with direct Node.js type stripping (#8142)", () => { + const service = pathToFileURL( + path.join(process.cwd(), "tools/e2e/jetson-dispatch-service.mts"), + ).href; + const result = spawnSync( + "node", + [ + "--experimental-strip-types", + "--no-warnings", + "--input-type=module", + "--eval", + `await import(${JSON.stringify(service)})`, + ], + { encoding: "utf8" }, + ); + + expect(result.status, result.stderr).toBe(0); + expect(result.stderr).not.toContain("does not provide an export named JetsonDeviceIdentity"); + }); + it("uses one fixed command for initial service deployment (#8142)", () => { const deployment = "sudo nemoclaw-colossus-jetson-dispatch-deploy --commit 0000000000000000000000000000000000000000"; @@ -300,6 +394,11 @@ esac "major < 22 || (major === 22 && minor < 19)", ); expect(processRunner.mock.calls[2]![0].input).toContain("npm_major >= 10"); + expect(processRunner.mock.calls[2]![0].input).toContain('"$workspace/runtime"'); + expect(processRunner.mock.calls[2]![0].input).toContain( + 'export XDG_RUNTIME_DIR="$workspace/runtime"', + ); + expect(processRunner.mock.calls[2]![0].input).toContain("unset DBUS_SESSION_BUS_ADDRESS"); expect(JSON.parse(fs.readFileSync(baselinePath, "utf8"))).toEqual(BASELINE); expect(processRunner.mock.calls[2]![0].input).not.toContain("trap cleanup EXIT"); expect(processRunner.mock.calls[3]![0].input).not.toContain("trap cleanup EXIT"); @@ -582,7 +681,6 @@ esac ["Node.js", { nodeVersion: "v22.20.0" }], ["npm", { npmVersion: "11.0.0" }], ["Ollama executable", { ollamaPath: "/tmp/ollama" }], - ["Ollama models", { ollamaModelsSha256: "c".repeat(64) }], ])("rejects cleanup when the protected %s baseline changes (#8142)", async (_name, change) => { const files = deploymentFiles(); const jobId = "b".repeat(64); @@ -596,11 +694,151 @@ esac const worker = new SshJetsonDispatchWorker(loadConfig(files), processRunner); await expect(worker.cleanup({ jobId, signal: new AbortController().signal })).rejects.toThrow( - "Jetson protected tool or Ollama model baseline differs after cleanup", + "Jetson protected tool baseline differs after cleanup", ); expect(fs.existsSync(baselinePath)).toBe(true); }); + it.each([ + { + name: "an initially empty model set followed by the onboarding model", + initial: [], + final: [{ name: "qwen3.5:9b", id: "b".repeat(12) }], + }, + { + name: "a pre-existing model plus a newly installed model", + initial: [{ name: "existing:latest", id: "a".repeat(12) }], + final: [ + { name: "existing:latest", id: "a".repeat(12) }, + { name: "qwen3.5:9b", id: "b".repeat(12) }, + ], + }, + ])("allows $name after cleanup (#8142)", async ({ initial, final }) => { + const files = deploymentFiles(); + const jobId = "b".repeat(64); + fs.writeFileSync( + path.join(files.stateDirectory, `${jobId}.baseline.json`), + `${JSON.stringify({ ...BASELINE, ollamaModels: initial })}\n`, + { mode: 0o600 }, + ); + persistCleanupEvidence(files, jobId, { schemaVersion: 1, volumes: [], processIds: [] }); + const processRunner = vi + .fn() + .mockResolvedValueOnce({ stdout: cleanupOutput(), stderr: "" }) + .mockResolvedValueOnce({ stdout: baselineOutput({ ollamaModels: final }), stderr: "" }); + const worker = new SshJetsonDispatchWorker(loadConfig(files), processRunner); + + await expect( + worker.cleanup({ jobId, signal: new AbortController().signal }), + ).resolves.toBeUndefined(); + }); + + it("keeps a maximum accepted Ollama baseline readable after persistence (#8142)", async () => { + const files = deploymentFiles(); + const jobId = "b".repeat(64); + const models = Array.from({ length: 64 }, (_value, index) => ({ + name: `model-${index.toString().padStart(2, "0")}-${"x".repeat(22)}`, + id: index.toString(16).padStart(12, "0"), + })); + const processRunner = vi + .fn() + .mockResolvedValueOnce({ stdout: baselineOutput({ ollamaModels: models }), stderr: "" }) + .mockResolvedValueOnce({ + stdout: + "model\tNVIDIA Jetson AGX Thor Developer Kit\njetpackVersion\t7.2.2\njetsonLinuxRelease\tR38\nkernel\t6.8.12-tegra\n", + stderr: "", + }) + .mockResolvedValueOnce({ stdout: "test passed\n", stderr: "" }) + .mockResolvedValueOnce({ stdout: Buffer.from("archive").toString("base64"), stderr: "" }) + .mockResolvedValueOnce({ stdout: cleanupOutput(), stderr: "" }) + .mockResolvedValueOnce({ stdout: baselineOutput({ ollamaModels: models }), stderr: "" }); + const worker = new SshJetsonDispatchWorker(loadConfig(files), processRunner); + + await worker.run( + { + schemaVersion: 1, + target: "jetson-nvmap-gpu", + candidateSha: "a".repeat(40), + workflowRunId: "123", + workflowRunAttempt: 1, + }, + { jobId, signal: new AbortController().signal }, + ); + const baselinePath = path.join(files.stateDirectory, `${jobId}.baseline.json`); + expect(fs.statSync(baselinePath).size).toBeGreaterThan(4 * 1024); + persistCleanupEvidence(files, jobId, { schemaVersion: 1, volumes: [], processIds: [] }); + + await expect( + worker.cleanup({ jobId, signal: new AbortController().signal }), + ).resolves.toBeUndefined(); + }); + + it.each([ + { + name: "a pre-existing model is removed", + final: [], + }, + { + name: "a pre-existing model ID changes", + final: [{ name: "existing:latest", id: "c".repeat(12) }], + }, + ])("fails cleanup when $name (#8142)", async ({ final }) => { + const files = deploymentFiles(); + const jobId = "b".repeat(64); + const baselinePath = path.join(files.stateDirectory, `${jobId}.baseline.json`); + fs.writeFileSync(baselinePath, `${JSON.stringify(BASELINE)}\n`, { mode: 0o600 }); + persistCleanupEvidence(files, jobId, { schemaVersion: 1, volumes: [], processIds: [] }); + const processRunner = vi + .fn() + .mockResolvedValueOnce({ stdout: cleanupOutput(), stderr: "" }) + .mockResolvedValueOnce({ stdout: baselineOutput({ ollamaModels: final }), stderr: "" }); + const worker = new SshJetsonDispatchWorker(loadConfig(files), processRunner); + + await expect(worker.cleanup({ jobId, signal: new AbortController().signal })).rejects.toThrow( + "Jetson cleanup did not preserve every pre-existing Ollama model", + ); + expect(fs.existsSync(baselinePath)).toBe(true); + }); + + it.each([ + { + name: "malformed model data", + encoded: Buffer.from("qwen3.5:9b\tnot-an-id").toString("base64"), + }, + { + name: "duplicate model names", + encoded: Buffer.from(`qwen3.5:9b\t${"a".repeat(12)}\nqwen3.5:9b\t${"b".repeat(12)}`).toString( + "base64", + ), + }, + { + name: "oversized model data", + encoded: Buffer.from( + Array.from( + { length: 65 }, + (_value, index) => `model-${index}:latest\t${index.toString(16).padStart(12, "0")}`, + ).join("\n"), + ).toString("base64"), + }, + ])("rejects $name in the protected baseline (#8142)", async ({ encoded }) => { + const files = deploymentFiles(); + const jobId = "b".repeat(64); + persistCleanupEvidence(files, jobId, { schemaVersion: 1, volumes: [], processIds: [] }); + const malformedOutput = baselineOutput().replace( + /^ollamaModelsBase64\t.*$/mu, + `ollamaModelsBase64\t${encoded}`, + ); + const processRunner = vi + .fn() + .mockResolvedValueOnce({ stdout: cleanupOutput(), stderr: "" }) + .mockResolvedValueOnce({ stdout: malformedOutput, stderr: "" }); + const worker = new SshJetsonDispatchWorker(loadConfig(files), processRunner); + + await expect(worker.cleanup({ jobId, signal: new AbortController().signal })).rejects.toThrow( + /Jetson protected-baseline Ollama model data/u, + ); + }); + it("rejects cleanup unless OpenShell returns to the absent baseline (#8142)", async () => { const files = deploymentFiles(); const jobId = "b".repeat(64); @@ -767,11 +1005,178 @@ esac ).rejects.toThrow("Jetson cleanup evidence is missing"); }); + it("ignores permission denial while inspecting an unrelated process (#8142)", () => { + const fixture = cleanupProcessFixture({ + deny: "environ", + uid: process.getuid!() + 1, + }); + const result = spawnSync( + "/bin/bash", + [ + "-c", + `set -euo pipefail +${fixture.functions} +job_home=/job/home +for proc_dir in "$PROC_ROOT"/*; do + if ! process_uid="$(read_proc_uid "$proc_dir")"; then + handle_proc_read_failure "$proc_dir" owner + continue + fi + [ "$process_uid" = "$(id -u)" ] || continue + if ! environment="$(read_proc_environment "$proc_dir")"; then + handle_proc_read_failure "$proc_dir" environment + continue + fi + printf '%s\n' "$environment" | grep -Fqx "HOME=$job_home" || continue + if ! cmdline="$(read_proc_command "$proc_dir")"; then + handle_proc_read_failure "$proc_dir" command + continue + fi +done +printf 'inspection-complete\n' +`, + ], + { encoding: "utf8", env: fixture.environment }, + ); + + expect(result.status, result.stderr).toBe(0); + expect(result.stdout).toBe("inspection-complete\n"); + }); + + it("rejects an unreadable live same-user process during discovery (#8142)", () => { + const fixture = cleanupProcessFixture({ deny: "environ" }); + const result = spawnSync( + "/bin/bash", + [ + "-c", + `set -euo pipefail +${fixture.functions} +job_home=/job/home +for proc_dir in "$PROC_ROOT"/*; do + if ! process_uid="$(read_proc_uid "$proc_dir")"; then + handle_proc_read_failure "$proc_dir" owner + continue + fi + [ "$process_uid" = "$(id -u)" ] || continue + if ! environment="$(read_proc_environment "$proc_dir")"; then + handle_proc_read_failure "$proc_dir" environment + continue + fi +done +`, + ], + { encoding: "utf8", env: fixture.environment }, + ); + + expect(result.status).toBe(1); + expect(result.stderr).toContain("Unable to inspect environment for a live same-user process"); + }); + + it("ignores a recorded process that disappears during inspection (#8142)", () => { + const fixture = cleanupProcessFixture({ disappear: "cmdline" }); + const result = spawnSync( + "/bin/bash", + [ + "-c", + `set -euo pipefail +${fixture.functions} +kill() { [ "$1" = -0 ] && [ -d "$PROC_ROOT/$2" ]; } +job_home=/job/home +validate_recorded_pid 1234 ollama-auth-proxy. +`, + ], + { encoding: "utf8", env: fixture.environment }, + ); + + expect(result.status, result.stderr).toBe(0); + }); + + it("rejects a live recorded PID whose owner cannot be verified (#8142)", () => { + const fixture = cleanupProcessFixture(); + fs.rmSync(path.join(fixture.procRoot, "1234", "status")); + const result = spawnSync( + "/bin/bash", + [ + "-c", + `set -euo pipefail +${fixture.functions} +kill() { [ "$1" = -0 ] && [ -d "$PROC_ROOT/$2" ]; } +job_home=/job/home +validate_recorded_pid 1234 ollama-auth-proxy. +`, + ], + { encoding: "utf8", env: fixture.environment }, + ); + + expect(result.status).toBe(1); + expect(result.stderr).toContain("owner cannot be verified"); + }); + + it.each([ + { + name: "owner", + options: { uid: process.getuid!() + 1 }, + error: "owned by another user", + }, + { + name: "HOME", + options: { home: "/unrelated/home" }, + error: "outside the job home", + }, + { + name: "command", + options: { command: "node unrelated-service.mjs" }, + error: "unexpected command", + }, + ])("rejects a recorded PID with an unexpected $name (#8142)", ({ error, options }) => { + const fixture = cleanupProcessFixture(options); + const result = spawnSync( + "/bin/bash", + [ + "-c", + `set -euo pipefail +${fixture.functions} +kill() { [ "$1" = -0 ] && [ -d "$PROC_ROOT/$2" ]; } +job_home=/job/home +validate_recorded_pid 1234 ollama-auth-proxy. +`, + ], + { encoding: "utf8", env: fixture.environment }, + ); + + expect(result.status).toBe(1); + expect(result.stderr).toContain(error); + }); + + it("accepts a recorded PID with the expected owner, HOME, and command (#8142)", () => { + const fixture = cleanupProcessFixture(); + const result = spawnSync( + "/bin/bash", + [ + "-c", + `set -euo pipefail +${fixture.functions} +kill() { [ "$1" = -0 ] && [ -d "$PROC_ROOT/$2" ]; } +job_home=/job/home +validate_recorded_pid 1234 ollama-auth-proxy. +`, + ], + { encoding: "utf8", env: fixture.environment }, + ); + + expect(result.status, result.stderr).toBe(0); + }); + it("keeps cleanup targets fixed and preserves the Jetson baseline (#8142)", () => { const fileFsync = cleanupProgram.indexOf("fs.fsyncSync(descriptor)"); const atomicRename = cleanupProgram.indexOf("fs.renameSync(temporaryFile, cleanupFile)"); const directoryFsync = cleanupProgram.indexOf("fs.fsyncSync(directoryDescriptor)"); const destructivePhase = cleanupProgram.indexOf("<<'JETSON_CLEANUP'"); + const stopFunctionStart = cleanupProgram.lastIndexOf("stop_recorded_pid()"); + const stopFunction = cleanupProgram.slice( + stopFunctionStart, + cleanupProgram.indexOf('for pid in "${recorded_process_ids[@]}"', stopFunctionStart), + ); expect(cleanupProgram).toContain("sandbox_name=e2e-jetson-nvmap"); expect(cleanupProgram).toContain("gateway_container=openshell-cluster-nemoclaw"); expect(cleanupProgram).toContain("destination=nvidia@192.168.55.1"); @@ -781,11 +1186,28 @@ esac expect(cleanupProgram).toContain('require_plain_directory_if_present "$service_directory"'); expect(cleanupProgram).toContain('rm -rf -- "$workspace"'); expect(cleanupProgram).toContain("ollama-auth-proxy.pid"); - expect(cleanupProgram).toContain('process_uid="$(awk'); + expect(cleanupProgram).toContain("read_proc_uid()"); + expect(cleanupProgram).toContain('dd if="$1/environ"'); + expect(cleanupProgram).toContain('dd if="$1/cmdline"'); + expect( + cleanupProgram.match(/handle_proc_read_failure "\$proc_dir" environment/gu), + ).toHaveLength(2); + expect(cleanupProgram.match(/handle_proc_read_failure "\$proc_dir" command/gu)).toHaveLength(2); + expect(workerProgram).toContain('handle_proc_read_failure "$proc_dir" environment'); + expect(workerProgram).toContain('handle_proc_read_failure "$proc_dir" command'); expect(cleanupProgram).toContain('grep -Fqx "HOME=$job_home"'); expect(cleanupProgram).toContain("*openshell-forward*"); expect(cleanupProgram).toContain("*openshell\\ forward*"); expect(cleanupProgram).toContain('kill "$pid"'); + expect(stopFunction.indexOf('process_uid="$(read_proc_uid')).toBeLessThan( + stopFunction.indexOf('kill "$pid"'), + ); + expect(stopFunction.indexOf('cmdline="$(read_proc_command')).toBeLessThan( + stopFunction.indexOf('kill "$pid"'), + ); + expect(stopFunction.indexOf('grep -Fqx "HOME=$job_home"')).toBeLessThan( + stopFunction.indexOf('kill "$pid"'), + ); expect(cleanupProgram).toContain("label=openshell.ai/sandbox-name=$sandbox_name"); expect(cleanupProgram).toContain("image_repository=nemoclaw-sandbox-local"); expect(cleanupProgram).toContain('docker image rm "$image"'); @@ -815,6 +1237,7 @@ esac expect(cleanupProgram).not.toMatch(/pkill|pgrep|docker (?:system|container|volume) prune/u); expect(cleanupProgram).not.toContain('rm -rf -- "$workspace_root"'); expect(cleanupProgram).not.toContain("ollama serve"); + expect(cleanupProgram).not.toMatch(/ollama (?:rm|delete)/u); expect(cleanupProgram).not.toMatch(/apt(?:-get)?|boardctl|reboot|shutdown|nvidia-l4t/u); expect(cleanupProgram).not.toMatch(/npm uninstall|uninstall\.sh|rm .*ollama/u); }); diff --git a/test/e2e/support/jetson-workflow-boundary.test.ts b/test/e2e/support/jetson-workflow-boundary.test.ts index e933288bdf7..2e3a8a9476c 100644 --- a/test/e2e/support/jetson-workflow-boundary.test.ts +++ b/test/e2e/support/jetson-workflow-boundary.test.ts @@ -51,6 +51,21 @@ describe("Jetson nvmap GPU E2E workflow boundary", () => { ); }); + it("queues every Jetson dispatch on one fixed device without cancellation (#8142)", () => { + const workflow = readWorkflow(); + const job = (workflow.jobs as Record)["jetson-nvmap-gpu"] as { + concurrency?: Record; + }; + job.concurrency = { + group: "jetson-${{ github.ref }}", + queue: 1, + "cancel-in-progress": true, + }; + expect(validateJetsonDispatchBoundary(workflow)).toContain( + "jetson-nvmap-gpu concurrency must queue every dispatch on one fixed device without cancellation", + ); + }); + it("rejects candidate execution or credential-bearing controller steps (#8142)", () => { const errors = validateWorkflowMutation((workflow) => { const job = (workflow.jobs as Record)["jetson-nvmap-gpu"] as { diff --git a/tools/e2e/cli-artifact-workflow-boundary.mts b/tools/e2e/cli-artifact-workflow-boundary.mts index fdd43d6d6aa..3ba5eed8ca1 100644 --- a/tools/e2e/cli-artifact-workflow-boundary.mts +++ b/tools/e2e/cli-artifact-workflow-boundary.mts @@ -39,7 +39,7 @@ const CLI_ARTIFACT_PROVENANCE_STEP = "Record CLI artifact provenance"; const CANDIDATE_CHECKOUT_STEP_CONTENT_SHA256 = "3578a053cede863f7aa4814d8399b4ca21ea0b77cee712e6d549c684818f11dd"; const CLI_ARTIFACT_WORKFLOW_CONTRACT_SHA256 = - "827680cf3570fda59d20b8a50973740ef9d14bfe186e2e269e171a6170fa98b0"; + "6b9110770f2a6f5370910054d40eee6935161eb8fc5ee4ed3afec808cf536e89"; type WorkflowRecord = Record; type WorkflowStep = WorkflowRecord & { diff --git a/tools/e2e/jetson-dispatch-cleanup.sh b/tools/e2e/jetson-dispatch-cleanup.sh index fecc42750af..a7a78655d87 100755 --- a/tools/e2e/jetson-dispatch-cleanup.sh +++ b/tools/e2e/jetson-dispatch-cleanup.sh @@ -160,22 +160,65 @@ read_recorded_pid() { printf '%s\n' "$pid" } +read_proc_uid() { + awk '/^Uid:/ { print $2; found = 1; exit } END { exit found ? 0 : 1 }' "$1/status" 2>/dev/null +} + +read_proc_environment() { + dd if="$1/environ" status=none 2>/dev/null | tr '\000' '\n' +} + +read_proc_command() { + dd if="$1/cmdline" status=none 2>/dev/null | tr '\000' ' ' +} + +handle_proc_read_failure() { + local proc_dir="$1" field="$2" process_uid directory_uid + [ -d "$proc_dir" ] || return 0 + if process_uid="$(read_proc_uid "$proc_dir")"; then + [ "$process_uid" = "$(id -u)" ] || return 0 + else + [ -d "$proc_dir" ] || return 0 + if ! directory_uid="$(stat -c %u "$proc_dir" 2>/dev/null)"; then + [ -d "$proc_dir" ] || return 0 + echo "Unable to verify the owner of a live process after a failed $field read" >&2 + exit 1 + fi + [ "$directory_uid" = "$(id -u)" ] || return 0 + fi + echo "Unable to inspect $field for a live same-user process" >&2 + exit 1 +} + validate_recorded_pid() { local pid="$1" marker="$2" [ -n "$pid" ] || return 0 kill -0 "$pid" 2>/dev/null || return 0 - local process_uid cmdline - process_uid="$(awk '/^Uid:/ { print $2; exit }' "/proc/$pid/status")" + local process_uid cmdline environment proc_dir="/proc/$pid" + if ! process_uid="$(read_proc_uid "$proc_dir")"; then + kill -0 "$pid" 2>/dev/null || return 0 + echo "Refusing to record a live process whose owner cannot be verified" >&2 + exit 1 + fi [ "$process_uid" = "$(id -u)" ] || { echo "Refusing to record a process owned by another user" >&2 exit 1 } - cmdline="$(tr '\000' ' ' <"/proc/$pid/cmdline")" + if ! cmdline="$(read_proc_command "$proc_dir")"; then + kill -0 "$pid" 2>/dev/null || return 0 + echo "Refusing to record a live process whose command cannot be verified" >&2 + exit 1 + fi case "$cmdline" in *"$marker"*) ;; *) echo "Refusing to record a PID with an unexpected command" >&2; exit 1 ;; esac - if ! tr '\000' '\n' <"/proc/$pid/environ" | grep -Fqx "HOME=$job_home"; then + if ! environment="$(read_proc_environment "$proc_dir")"; then + kill -0 "$pid" 2>/dev/null || return 0 + echo "Refusing to record a live process whose environment cannot be verified" >&2 + exit 1 + fi + if ! printf '%s\n' "$environment" | grep -Fqx "HOME=$job_home"; then echo "Refusing to record a process outside the job home" >&2 exit 1 fi @@ -198,11 +241,20 @@ for pid in "$auth_proxy_pid" "$gateway_pid" "$cloudflared_pid"; do fi done for proc_dir in /proc/[0-9]*; do - [ -r "$proc_dir/status" ] && [ -r "$proc_dir/environ" ] && [ -r "$proc_dir/cmdline" ] || continue - process_uid="$(awk '/^Uid:/ { print $2; exit }' "$proc_dir/status")" + if ! process_uid="$(read_proc_uid "$proc_dir")"; then + handle_proc_read_failure "$proc_dir" owner + continue + fi [ "$process_uid" = "$(id -u)" ] || continue - tr '\000' '\n' <"$proc_dir/environ" | grep -Fqx "HOME=$job_home" || continue - cmdline="$(tr '\000' ' ' <"$proc_dir/cmdline")" + if ! environment="$(read_proc_environment "$proc_dir")"; then + handle_proc_read_failure "$proc_dir" environment + continue + fi + printf '%s\n' "$environment" | grep -Fqx "HOME=$job_home" || continue + if ! cmdline="$(read_proc_command "$proc_dir")"; then + handle_proc_read_failure "$proc_dir" command + continue + fi case "$cmdline" in *ollama-auth-proxy.* | *openshell-gateway* | *openshell-forward* | *openshell\ forward* | *cloudflared*) printf 'processId\t%s\n' "${proc_dir##*/}" @@ -336,25 +388,54 @@ if [ -n "$cleanup_rows" ]; then done <<<"$cleanup_rows" fi +read_proc_uid() { + awk '/^Uid:/ { print $2; found = 1; exit } END { exit found ? 0 : 1 }' "$1/status" 2>/dev/null +} + +read_proc_environment() { + dd if="$1/environ" status=none 2>/dev/null | tr '\000' '\n' +} + +read_proc_command() { + dd if="$1/cmdline" status=none 2>/dev/null | tr '\000' ' ' +} + stop_recorded_pid() { local pid="$1" kill -0 "$pid" 2>/dev/null || return 0 - local process_uid cmdline - process_uid="$(awk '/^Uid:/ { print $2; exit }' "/proc/$pid/status")" + local process_uid cmdline environment proc_dir="/proc/$pid" + if ! process_uid="$(read_proc_uid "$proc_dir")"; then + kill -0 "$pid" 2>/dev/null || return 0 + echo "Refusing to stop a live process whose owner cannot be verified" >&2 + exit 1 + fi [ "$process_uid" = "$(id -u)" ] || { echo "Refusing to stop a process owned by another user" >&2 exit 1 } - cmdline="$(tr '\000' ' ' <"/proc/$pid/cmdline")" + if ! cmdline="$(read_proc_command "$proc_dir")"; then + kill -0 "$pid" 2>/dev/null || return 0 + echo "Refusing to stop a live process whose command cannot be verified" >&2 + exit 1 + fi case "$cmdline" in *ollama-auth-proxy.* | *openshell-gateway* | *openshell-forward* | *openshell\ forward* | *cloudflared*) ;; *) echo "Refusing to stop a recorded PID with an unexpected command" >&2; exit 1 ;; esac - if ! tr '\000' '\n' <"/proc/$pid/environ" | grep -Fqx "HOME=$job_home"; then + if ! environment="$(read_proc_environment "$proc_dir")"; then + kill -0 "$pid" 2>/dev/null || return 0 + echo "Refusing to stop a live process whose environment cannot be verified" >&2 + exit 1 + fi + if ! printf '%s\n' "$environment" | grep -Fqx "HOME=$job_home"; then echo "Refusing to stop a process outside the job home" >&2 exit 1 fi - kill "$pid" + if ! kill "$pid" 2>/dev/null; then + kill -0 "$pid" 2>/dev/null || return 0 + echo "Unable to stop a validated cleanup process" >&2 + exit 1 + fi for _attempt in 1 2 3 4 5 6 7 8 9 10; do kill -0 "$pid" 2>/dev/null || return 0 sleep 0.2 @@ -484,9 +565,20 @@ for pid in "${recorded_process_ids[@]}"; do fi done for proc_dir in /proc/[0-9]*; do - [ -r "$proc_dir/environ" ] && [ -r "$proc_dir/cmdline" ] || continue - tr '\000' '\n' <"$proc_dir/environ" | grep -Fqx "HOME=$job_home" || continue - cmdline="$(tr '\000' ' ' <"$proc_dir/cmdline")" + if ! process_uid="$(read_proc_uid "$proc_dir")"; then + handle_proc_read_failure "$proc_dir" owner + continue + fi + [ "$process_uid" = "$(id -u)" ] || continue + if ! environment="$(read_proc_environment "$proc_dir")"; then + handle_proc_read_failure "$proc_dir" environment + continue + fi + printf '%s\n' "$environment" | grep -Fqx "HOME=$job_home" || continue + if ! cmdline="$(read_proc_command "$proc_dir")"; then + handle_proc_read_failure "$proc_dir" command + continue + fi case "$cmdline" in *ollama-auth-proxy.* | *openshell-gateway* | *openshell-forward* | *openshell\ forward* | *cloudflared*) echo "A job-owned helper process remains" >&2 diff --git a/tools/e2e/jetson-dispatch-lifecycle.mts b/tools/e2e/jetson-dispatch-lifecycle.mts index bb0bc9b03d1..c6373832f45 100644 --- a/tools/e2e/jetson-dispatch-lifecycle.mts +++ b/tools/e2e/jetson-dispatch-lifecycle.mts @@ -86,6 +86,22 @@ function safeError(error: unknown): string { return message.replace(/[\u0000-\u001f\u007f]/gu, " ").slice(0, 500); } +function appendBoundedError(previous: string | undefined, newest: string): string { + const latest = newest.replace(/[\u0000-\u001f\u007f]/gu, " ").slice(0, 500); + if (!previous) return latest; + const separator = "; "; + const available = 500 - separator.length - latest.length; + if (available <= 0) return latest; + const earlier = previous.replace(/[\u0000-\u001f\u007f]/gu, " "); + const boundedEarlier = + earlier.length <= available + ? earlier + : available > 3 + ? `${earlier.slice(0, available - 3)}...` + : earlier.slice(0, available); + return `${boundedEarlier}${separator}${latest}`; +} + function workerErrorLog(error: unknown): string | undefined { if (!error || typeof error !== "object" || !("log" in error)) return undefined; const log = (error as { log?: unknown }).log; @@ -467,8 +483,10 @@ export class JetsonDispatchCoordinator { writePrivateRegularFile(this.#artifactPath(status.jobId), artifactArchiveBase64); } } catch (resultError) { - status.error = - `${status.error}; result persistence failed: ${safeError(resultError)}`.slice(0, 500); + status.error = appendBoundedError( + status.error, + `Result persistence failed: ${safeError(resultError)}`, + ); } } finally { clearTimeout(timer); @@ -480,9 +498,7 @@ export class JetsonDispatchCoordinator { } catch (error) { status.cleanup = "failed"; const cleanupError = `Jetson cleanup failed: ${safeError(error)}`; - status.error = status.error - ? `${status.error}; ${cleanupError}`.slice(0, 500) - : cleanupError; + status.error = appendBoundedError(status.error, cleanupError); conclusion = "cleanup-failed"; } status.conclusion = conclusion; @@ -494,9 +510,7 @@ export class JetsonDispatchCoordinator { terminalStatusPersisted = true; } catch (error) { const persistenceError = `Final status persistence failed: ${safeError(error)}`; - status.error = status.error - ? `${status.error}; ${persistenceError}`.slice(0, 500) - : persistenceError; + status.error = appendBoundedError(status.error, persistenceError); if (status.conclusion !== "cleanup-failed") status.conclusion = "failure"; } if (status.cleanup === "succeeded" && terminalStatusPersisted) { @@ -504,13 +518,13 @@ export class JetsonDispatchCoordinator { fs.unlinkSync(this.#lockPath); } catch (error) { const lockError = `Jetson lock removal failed: ${safeError(error)}`; - status.error = status.error ? `${status.error}; ${lockError}`.slice(0, 500) : lockError; + status.error = appendBoundedError(status.error, lockError); status.conclusion = "cleanup-failed"; try { this.#persist(status); } catch (persistError) { const persistenceError = `Lock failure persistence failed: ${safeError(persistError)}`; - status.error = `${status.error}; ${persistenceError}`.slice(0, 500); + status.error = appendBoundedError(status.error, persistenceError); } } } diff --git a/tools/e2e/jetson-dispatch-worker.mts b/tools/e2e/jetson-dispatch-worker.mts index 677532d80cb..d0c517bc556 100644 --- a/tools/e2e/jetson-dispatch-worker.mts +++ b/tools/e2e/jetson-dispatch-worker.mts @@ -6,11 +6,13 @@ import fs from "node:fs"; import path from "node:path"; import type { JetsonDispatchRequest } from "./jetson-dispatch-contract.mts"; -import { - decodeJetsonArtifactArchive, +import type { JetsonDeviceIdentity, JetsonDispatchWorker, JetsonWorkerResult, +} from "./jetson-dispatch-lifecycle.mts"; +import { + decodeJetsonArtifactArchive, MAX_JETSON_ARTIFACT_ARCHIVE_BYTES, } from "./jetson-dispatch-lifecycle.mts"; import { readPrivateRegularFile, writePrivateRegularFile } from "./private-file.mts"; @@ -24,7 +26,10 @@ const SAFE_PROCESS_ENV = { LANG: "C.UTF-8", PATH: "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", }; -const MAX_BASELINE_BYTES = 4 * 1024; +const MAX_BASELINE_OUTPUT_BYTES = 4 * 1024; +const MAX_BASELINE_RECORD_BYTES = 8 * 1024; +const MAX_OLLAMA_MODELS = 64; +const MAX_OLLAMA_MODELS_BYTES = 3 * 1024; const MAX_CLEANUP_EVIDENCE_BYTES = 64 * 1024; const CLEANUP_EVIDENCE_BEGIN = "nemoclaw-cleanup-evidence-v1-begin"; const CLEANUP_EVIDENCE_END = "nemoclaw-cleanup-evidence-v1-end"; @@ -85,7 +90,12 @@ case "$docker_runtimes" in *nvidia*) ;; *) echo "Docker does not report the NVIDIA runtime" >&2; exit 1 ;; esac -ollama_models_sha256="$(ollama list | awk 'NR > 1 && NF >= 2 { print $1 "\t" $2 }' | sort | sha256sum | cut -d ' ' -f 1)" +ollama_models_base64="$( + ollama list | + awk 'NR == 1 { if ($1 != "NAME" || $2 != "ID") exit 1; next } { if (NF < 2) exit 1; print $1 "\t" $2 } END { if (NR == 0) exit 1 }' | + LC_ALL=C sort | + base64 --wrap=0 +)" test_owned_images="$(docker image ls nemoclaw-sandbox-local --format '{{.Repository}}\t{{.Tag}}' | awk '$1 == "nemoclaw-sandbox-local" && index($2, "e2e-jetson-nvmap-") == 1 { print $1 ":" $2 }')" [ -z "$test_owned_images" ] || { echo "A test-owned Jetson image remains before dispatch" >&2; exit 1; } printf 'nodePath\t'; printf '%s' "$node_path" | clean_line @@ -93,7 +103,7 @@ printf '\nnodeVersion\t'; printf '%s' "$node_version" | clean_line printf '\nnpmPath\t'; printf '%s' "$npm_path" | clean_line printf '\nnpmVersion\t'; printf '%s' "$npm_version" | clean_line printf '\nollamaPath\t'; printf '%s' "$ollama_path" | clean_line -printf '\nollamaModelsSha256\t'; printf '%s' "$ollama_models_sha256" | clean_line +printf '\nollamaModelsBase64\t'; printf '%s' "$ollama_models_base64" | clean_line printf '\nopenshellState\tabsent' printf '\n' `; @@ -164,10 +174,47 @@ for pid in "${"${recorded_process_ids[@]}"}"; do exit 1 fi done +read_proc_uid() { + awk '/^Uid:/ { print $2; found = 1; exit } END { exit found ? 0 : 1 }' "$1/status" 2>/dev/null +} +read_proc_environment() { + dd if="$1/environ" status=none 2>/dev/null | tr '\000' '\n' +} +read_proc_command() { + dd if="$1/cmdline" status=none 2>/dev/null | tr '\000' ' ' +} +handle_proc_read_failure() { + local proc_dir="$1" field="$2" process_uid directory_uid + [ -d "$proc_dir" ] || return 0 + if process_uid="$(read_proc_uid "$proc_dir")"; then + [ "$process_uid" = "$(id -u)" ] || return 0 + else + [ -d "$proc_dir" ] || return 0 + if ! directory_uid="$(stat -c %u "$proc_dir" 2>/dev/null)"; then + [ -d "$proc_dir" ] || return 0 + echo "Unable to verify the owner of a live process after a failed $field read" >&2 + exit 1 + fi + [ "$directory_uid" = "$(id -u)" ] || return 0 + fi + echo "Unable to inspect $field for a live same-user process" >&2 + exit 1 +} for proc_dir in /proc/[0-9]*; do - [ -r "$proc_dir/environ" ] && [ -r "$proc_dir/cmdline" ] || continue - tr '\000' '\n' <"$proc_dir/environ" | grep -Fqx "HOME=$job_home" || continue - cmdline="$(tr '\000' ' ' <"$proc_dir/cmdline")" + if ! process_uid="$(read_proc_uid "$proc_dir")"; then + handle_proc_read_failure "$proc_dir" owner + continue + fi + [ "$process_uid" = "$(id -u)" ] || continue + if ! environment="$(read_proc_environment "$proc_dir")"; then + handle_proc_read_failure "$proc_dir" environment + continue + fi + printf '%s\n' "$environment" | grep -Fqx "HOME=$job_home" || continue + if ! cmdline="$(read_proc_command "$proc_dir")"; then + handle_proc_read_failure "$proc_dir" command + continue + fi case "$cmdline" in *ollama-auth-proxy.* | *openshell-gateway* | *openshell-forward* | *openshell\ forward* | *cloudflared*) echo "A job-owned helper process remains" >&2 @@ -205,6 +252,7 @@ install -d -m 0700 \ "$workspace/home/.local/share" \ "$workspace/home/.local/state" \ "$workspace/npm-prefix" \ + "$workspace/runtime" \ "$workspace/tmp" export HOME="$workspace/home" @@ -214,10 +262,11 @@ export XDG_CONFIG_HOME="$workspace/home/.config" export XDG_DATA_HOME="$workspace/home/.local/share" export XDG_STATE_HOME="$workspace/home/.local/state" export XDG_BIN_HOME="$workspace/home/.local/bin" +export XDG_RUNTIME_DIR="$workspace/runtime" export npm_config_prefix="$workspace/npm-prefix" export PATH="$XDG_BIN_HOME:$workspace/npm-prefix/bin:$PATH" export NEMOCLAW_JETSON_WORKSPACE="$workspace" -unset NEMOCLAW_OPENSHELL_BIN NEMOCLAW_OPENSHELL_GATEWAY_BIN +unset DBUS_SESSION_BUS_ADDRESS NEMOCLAW_OPENSHELL_BIN NEMOCLAW_OPENSHELL_GATEWAY_BIN if [ -w /usr/local/bin ] || [ -w /usr/bin ]; then echo "Jetson job user must not be able to install OpenShell into a host binary directory" >&2 @@ -517,12 +566,91 @@ interface JetsonPreservedBaseline { npmPath: string; npmVersion: string; ollamaPath: string; - ollamaModelsSha256: string; + ollamaModels: JetsonOllamaModel[]; openshellState: "absent"; } +interface JetsonOllamaModel { + name: string; + id: string; +} + +function parseOllamaModelsBase64(value: string): JetsonOllamaModel[] { + if (!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/u.test(value)) { + throw new Error("Jetson protected-baseline Ollama model data is malformed"); + } + const decoded = Buffer.from(value, "base64"); + if ( + decoded.length > MAX_OLLAMA_MODELS_BYTES || + decoded.toString("base64") !== value || + decoded.includes(0) + ) { + throw new Error("Jetson protected-baseline Ollama model data is malformed or oversized"); + } + const rows = decoded.length === 0 ? [] : decoded.toString("utf8").trimEnd().split("\n"); + if (rows.length > MAX_OLLAMA_MODELS) { + throw new Error("Jetson protected-baseline Ollama model data is malformed or oversized"); + } + const models = rows.map((row) => { + const fields = row.split("\t"); + if ( + fields.length !== 2 || + !/^[A-Za-z0-9][A-Za-z0-9._/:@-]{0,254}$/u.test(fields[0]!) || + !/^[a-f0-9]{12,64}$/u.test(fields[1]!) + ) { + throw new Error("Jetson protected-baseline Ollama model data is malformed"); + } + return { name: fields[0]!, id: fields[1]! }; + }); + const sorted = [...models].sort((left, right) => { + if (left.name !== right.name) return left.name < right.name ? -1 : 1; + if (left.id === right.id) return 0; + return left.id < right.id ? -1 : 1; + }); + const names = new Set(); + if ( + models.some((model) => { + if (names.has(model.name)) return true; + names.add(model.name); + return false; + }) || + models.some( + (model, index) => model.name !== sorted[index]!.name || model.id !== sorted[index]!.id, + ) + ) { + throw new Error("Jetson protected-baseline Ollama model data is duplicate or ambiguous"); + } + return models; +} + +function validateOllamaModels(value: unknown): JetsonOllamaModel[] { + if (!Array.isArray(value) || value.length > MAX_OLLAMA_MODELS) { + throw new Error("Jetson protected-baseline Ollama model record is malformed or oversized"); + } + const serialized = value + .map((model) => { + if (!model || typeof model !== "object" || Array.isArray(model)) { + throw new Error("Jetson protected-baseline Ollama model record is malformed"); + } + const record = model as Record; + if ( + Object.keys(record).sort().join(",") !== "id,name" || + typeof record.name !== "string" || + typeof record.id !== "string" + ) { + throw new Error("Jetson protected-baseline Ollama model record is malformed"); + } + return `${record.name}\t${record.id}`; + }) + .join("\n"); + if (Buffer.byteLength(serialized) > MAX_OLLAMA_MODELS_BYTES) { + throw new Error("Jetson protected-baseline Ollama model record is malformed or oversized"); + } + return parseOllamaModelsBase64(Buffer.from(serialized).toString("base64")); +} + function parsePreservedBaseline(output: string): JetsonPreservedBaseline { - if (Buffer.byteLength(output) > MAX_BASELINE_BYTES) { + if (Buffer.byteLength(output) > MAX_BASELINE_OUTPUT_BYTES) { throw new Error("Jetson protected-baseline output is too large"); } const entries = new Map(); @@ -531,7 +659,11 @@ function parsePreservedBaseline(output: string): JetsonPreservedBaseline { if (separator < 1) throw new Error("Jetson protected-baseline output is malformed"); const key = line.slice(0, separator); const value = line.slice(separator + 1); - if (entries.has(key) || value.length === 0 || /[\u0000-\u001f\u007f]/u.test(value)) { + if ( + entries.has(key) || + (value.length === 0 && key !== "ollamaModelsBase64") || + /[\u0000-\u001f\u007f]/u.test(value) + ) { throw new Error("Jetson protected-baseline output is malformed"); } entries.set(key, value); @@ -542,7 +674,7 @@ function parsePreservedBaseline(output: string): JetsonPreservedBaseline { "npmPath", "npmVersion", "ollamaPath", - "ollamaModelsSha256", + "ollamaModelsBase64", "openshellState", ] as const; if (entries.size !== expected.length || expected.some((key) => !entries.has(key))) { @@ -554,20 +686,20 @@ function parsePreservedBaseline(output: string): JetsonPreservedBaseline { npmPath: entries.get("npmPath")!, npmVersion: entries.get("npmVersion")!, ollamaPath: entries.get("ollamaPath")!, - ollamaModelsSha256: entries.get("ollamaModelsSha256")!, + ollamaModels: parseOllamaModelsBase64(entries.get("ollamaModelsBase64")!), openshellState: entries.get("openshellState") as "absent", }; if (baseline.openshellState !== "absent") { throw new Error("Jetson protected-baseline OpenShell state is malformed"); } - if (!/^[a-f0-9]{64}$/u.test(baseline.ollamaModelsSha256)) { - throw new Error("Jetson protected-baseline Ollama model digest is malformed"); + if (Buffer.byteLength(`${JSON.stringify(baseline)}\n`) > MAX_BASELINE_RECORD_BYTES) { + throw new Error("Jetson protected-baseline record is too large"); } return baseline; } function parsePreservedBaselineJson(output: string): JetsonPreservedBaseline { - if (Buffer.byteLength(output) > MAX_BASELINE_BYTES) { + if (Buffer.byteLength(output) > MAX_BASELINE_RECORD_BYTES) { throw new Error("Jetson protected-baseline record is too large"); } let parsed: unknown; @@ -586,16 +718,50 @@ function parsePreservedBaselineJson(output: string): JetsonPreservedBaseline { "npmPath", "npmVersion", "ollamaPath", - "ollamaModelsSha256", + "ollamaModels", "openshellState", ]; if ( Object.keys(record).length !== expected.length || - expected.some((key) => typeof record[key] !== "string") + expected.some((key) => key !== "ollamaModels" && typeof record[key] !== "string") ) { throw new Error("Jetson protected-baseline record is incomplete"); } - return parsePreservedBaseline(expected.map((key) => `${key}\t${record[key]}`).join("\n")); + const ollamaModels = validateOllamaModels(record.ollamaModels); + const baselineOutput = [ + `nodePath\t${record.nodePath}`, + `nodeVersion\t${record.nodeVersion}`, + `npmPath\t${record.npmPath}`, + `npmVersion\t${record.npmVersion}`, + `ollamaPath\t${record.ollamaPath}`, + `ollamaModelsBase64\t${Buffer.from( + ollamaModels.map((model) => `${model.name}\t${model.id}`).join("\n"), + ).toString("base64")}`, + `openshellState\t${record.openshellState}`, + ].join("\n"); + return parsePreservedBaseline(baselineOutput); +} + +function protectedHostBaselineMatches( + expected: JetsonPreservedBaseline, + actual: JetsonPreservedBaseline, +): boolean { + return ( + expected.nodePath === actual.nodePath && + expected.nodeVersion === actual.nodeVersion && + expected.npmPath === actual.npmPath && + expected.npmVersion === actual.npmVersion && + expected.ollamaPath === actual.ollamaPath && + expected.openshellState === actual.openshellState + ); +} + +function preservesOllamaModels( + expected: JetsonPreservedBaseline, + actual: JetsonPreservedBaseline, +): boolean { + const actualModels = new Map(actual.ollamaModels.map((model) => [model.name, model.id])); + return expected.ollamaModels.every((model) => actualModels.get(model.name) === model.id); } function validateCleanupEvidence(value: unknown): JetsonCleanupEvidence { @@ -827,7 +993,7 @@ export class SshJetsonDispatchWorker implements JetsonDispatchWorker { const serializedEvidence = `${JSON.stringify(persistedEvidence)}\n`; const expectedRaw = readPrivateRegularFile(this.#baselinePath(options.jobId), { allowMissing: true, - maxBytes: MAX_BASELINE_BYTES, + maxBytes: MAX_BASELINE_RECORD_BYTES, }); const verification = await this.#runProcess({ executable: "ssh", @@ -846,8 +1012,11 @@ export class SshJetsonDispatchWorker implements JetsonDispatchWorker { const actual = parsePreservedBaseline(verification.stdout); if (expectedRaw === null) return; const expected = parsePreservedBaselineJson(expectedRaw); - if (JSON.stringify(actual) !== JSON.stringify(expected)) { - throw new Error("Jetson protected tool or Ollama model baseline differs after cleanup"); + if (!protectedHostBaselineMatches(expected, actual)) { + throw new Error("Jetson protected tool baseline differs after cleanup"); + } + if (!preservesOllamaModels(expected, actual)) { + throw new Error("Jetson cleanup did not preserve every pre-existing Ollama model"); } } diff --git a/tools/e2e/operations-workflow-boundary.mts b/tools/e2e/operations-workflow-boundary.mts index 90acb592bd1..4ca631b2e3e 100644 --- a/tools/e2e/operations-workflow-boundary.mts +++ b/tools/e2e/operations-workflow-boundary.mts @@ -241,8 +241,11 @@ function validateManualPrDispatch(errors: string[], workflow: OperationsWorkflow ) { errors.push("Manual PR E2E concurrency must be scoped to its pull request"); } - if (workflow.concurrency?.["cancel-in-progress"] !== "${{ inputs.checkout_sha != '' }}") { - errors.push("Manual PR E2E concurrency must cancel obsolete runs"); + if ( + workflow.concurrency?.["cancel-in-progress"] !== + "${{ inputs.checkout_sha != '' && !inputs.allow_jetson_dispatch }}" + ) { + errors.push("Manual PR E2E concurrency must not cancel an active Jetson dispatch"); } const matrixJob = workflow.jobs["generate-matrix"] ?? {}; diff --git a/tools/e2e/workflow-boundary.mts b/tools/e2e/workflow-boundary.mts index 32cedf12cc2..12d565143e7 100644 --- a/tools/e2e/workflow-boundary.mts +++ b/tools/e2e/workflow-boundary.mts @@ -3997,6 +3997,17 @@ function validateJetsonControllerBoundary(errors: string[], jobs: WorkflowRecord } if (job["timeout-minutes"] !== 60) errors.push("jetson-nvmap-gpu controller timeout must be 60 minutes"); + if ( + !isDeepStrictEqual(asRecord(job.concurrency), { + group: "jetson-nvmap-gpu-colossus", + queue: "max", + "cancel-in-progress": false, + }) + ) { + errors.push( + "jetson-nvmap-gpu concurrency must queue every dispatch on one fixed device without cancellation", + ); + } if (!isDeepStrictEqual(asRecord(job.permissions), { contents: "read", "id-token": "write" })) { errors.push("jetson-nvmap-gpu controller must grant only contents:read and id-token:write"); } @@ -4110,8 +4121,11 @@ function validateFullE2eConcurrency(errors: string[], workflow: WorkflowRecord): if (concurrency.group !== expectedGroup) { errors.push("workflow concurrency must isolate each full dispatch with github.run_id"); } - if (concurrency["cancel-in-progress"] !== "${{ inputs.checkout_sha != '' }}") { - errors.push("workflow concurrency must cancel only superseded PR gate runs"); + if ( + concurrency["cancel-in-progress"] !== + "${{ inputs.checkout_sha != '' && !inputs.allow_jetson_dispatch }}" + ) { + errors.push("workflow concurrency must not cancel an active Jetson dispatch"); } } From 888005cd56fac95fce42687b8364bd7b53febbb7 Mon Sep 17 00:00:00 2001 From: San Dang Date: Tue, 11 Aug 2026 14:13:20 +0700 Subject: [PATCH 28/34] test(e2e): keep Jetson helper linear --- test/e2e/support/jetson-dispatch-worker.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/e2e/support/jetson-dispatch-worker.test.ts b/test/e2e/support/jetson-dispatch-worker.test.ts index 5f59b29bc9c..ae931240582 100644 --- a/test/e2e/support/jetson-dispatch-worker.test.ts +++ b/test/e2e/support/jetson-dispatch-worker.test.ts @@ -1,6 +1,7 @@ // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 +import assert from "node:assert/strict"; import { spawnSync } from "node:child_process"; import fs from "node:fs"; import os from "node:os"; @@ -136,8 +137,7 @@ if [ "${"${DISAPPEAR_PROC_FILE:-}"}" = "$input" ]; then rm -rf -- "${"${input%/* ); const functionsStart = cleanupProgram.indexOf("read_proc_uid() {"); const functionsEnd = cleanupProgram.indexOf("\nauth_proxy_pid=", functionsStart); - if (functionsStart < 0 || functionsEnd < 0) - throw new Error("cleanup process functions are absent"); + assert.ok(functionsStart >= 0 && functionsEnd >= 0, "cleanup process functions are absent"); const functions = cleanupProgram .slice(functionsStart, functionsEnd) .replace('proc_dir="/proc/$pid"', 'proc_dir="$PROC_ROOT/$pid"'); From b759dfde274d720bcc3c974b2d4f4abbac3c6fe8 Mon Sep 17 00:00:00 2001 From: San Dang Date: Tue, 11 Aug 2026 15:54:31 +0700 Subject: [PATCH 29/34] fix(e2e): define cleanup phase process guard --- .../support/jetson-dispatch-worker.test.ts | 43 +++++++++++++++++++ tools/e2e/jetson-dispatch-cleanup.sh | 18 ++++++++ 2 files changed, 61 insertions(+) diff --git a/test/e2e/support/jetson-dispatch-worker.test.ts b/test/e2e/support/jetson-dispatch-worker.test.ts index ae931240582..f5dfc8e6302 100644 --- a/test/e2e/support/jetson-dispatch-worker.test.ts +++ b/test/e2e/support/jetson-dispatch-worker.test.ts @@ -142,6 +142,7 @@ if [ "${"${DISAPPEAR_PROC_FILE:-}"}" = "$input" ]; then rm -rf -- "${"${input%/* .slice(functionsStart, functionsEnd) .replace('proc_dir="/proc/$pid"', 'proc_dir="$PROC_ROOT/$pid"'); return { + binDirectory, environment: { ...process.env, DENY_PROC_FILE: options.deny ? path.join(procDirectory, options.deny) : "", @@ -1091,6 +1092,48 @@ validate_recorded_pid 1234 ollama-auth-proxy. expect(result.status, result.stderr).toBe(0); }); + it("completes the destructive cleanup phase when a process disappears during inspection (#8142)", () => { + const fixture = cleanupProcessFixture({ disappear: "environ" }); + fs.writeFileSync(path.join(fixture.binDirectory, "docker"), "#!/bin/sh\nexit 0\n", { + mode: 0o700, + }); + const marker = "<<'JETSON_CLEANUP'\n"; + const phaseStart = cleanupProgram.indexOf(marker); + const phaseEnd = cleanupProgram.indexOf("\nJETSON_CLEANUP", phaseStart + marker.length); + assert.ok(phaseStart >= 0 && phaseEnd >= 0, "destructive cleanup phase is absent"); + const script = cleanupProgram + .slice(phaseStart + marker.length, phaseEnd) + .replace("set -euo pipefail", "set -eo pipefail") + .replace( + "workspace_root=/var/tmp/nemoclaw-jetson-e2e", + 'workspace_root="$TEST_WORKSPACE_ROOT"', + ) + .replace( + 'service_directory="/tmp/nemoclaw-services-$sandbox_name"', + 'service_directory="$TEST_SERVICE_DIRECTORY"', + ) + .replace("for proc_dir in /proc/[0-9]*; do", 'for proc_dir in "$PROC_ROOT"/*; do') + .replace( + 'remaining_job_images="$(list_test_owned_images)"', + "printf 'destructive-phase-complete\\n'\nexit 0\nremaining_job_images=\"$(list_test_owned_images)\"", + ); + const evidence = Buffer.from( + JSON.stringify({ schemaVersion: 1, volumes: [], processIds: [] }), + ).toString("base64"); + const result = spawnSync("/bin/bash", ["-s", "--", "b".repeat(64), evidence], { + encoding: "utf8", + env: { + ...fixture.environment, + TEST_SERVICE_DIRECTORY: path.join(fixture.procRoot, "service"), + TEST_WORKSPACE_ROOT: path.join(fixture.procRoot, "workspace"), + }, + input: script, + }); + + expect(result.status, result.stderr).toBe(0); + expect(result.stdout).toBe("destructive-phase-complete\n"); + }); + it("rejects a live recorded PID whose owner cannot be verified (#8142)", () => { const fixture = cleanupProcessFixture(); fs.rmSync(path.join(fixture.procRoot, "1234", "status")); diff --git a/tools/e2e/jetson-dispatch-cleanup.sh b/tools/e2e/jetson-dispatch-cleanup.sh index a7a78655d87..44b1563e47e 100755 --- a/tools/e2e/jetson-dispatch-cleanup.sh +++ b/tools/e2e/jetson-dispatch-cleanup.sh @@ -400,6 +400,24 @@ read_proc_command() { dd if="$1/cmdline" status=none 2>/dev/null | tr '\000' ' ' } +handle_proc_read_failure() { + local proc_dir="$1" field="$2" process_uid directory_uid + [ -d "$proc_dir" ] || return 0 + if process_uid="$(read_proc_uid "$proc_dir")"; then + [ "$process_uid" = "$(id -u)" ] || return 0 + else + [ -d "$proc_dir" ] || return 0 + if ! directory_uid="$(stat -c %u "$proc_dir" 2>/dev/null)"; then + [ -d "$proc_dir" ] || return 0 + echo "Unable to verify the owner of a live process after a failed $field read" >&2 + exit 1 + fi + [ "$directory_uid" = "$(id -u)" ] || return 0 + fi + echo "Unable to inspect $field for a live same-user process" >&2 + exit 1 +} + stop_recorded_pid() { local pid="$1" kill -0 "$pid" 2>/dev/null || return 0 From 032694d24743e4171b78d0b99fcf5f05d8779fa7 Mon Sep 17 00:00:00 2001 From: San Dang Date: Tue, 11 Aug 2026 16:33:45 +0700 Subject: [PATCH 30/34] fix(e2e): bound Jetson teardown probes --- test/e2e/docs/jetson-colossus-dispatch.md | 32 ++++++++---- .../support/jetson-dispatch-worker.test.ts | 52 +++++++++++++++++++ 2 files changed, 75 insertions(+), 9 deletions(-) diff --git a/test/e2e/docs/jetson-colossus-dispatch.md b/test/e2e/docs/jetson-colossus-dispatch.md index 3943bec4325..52d07652de5 100644 --- a/test/e2e/docs/jetson-colossus-dispatch.md +++ b/test/e2e/docs/jetson-colossus-dispatch.md @@ -225,11 +225,16 @@ from="192.168.55.100",restrict ssh-ed25519 AAAA... Capture the Jetson host key and verify its fingerprint through the serial console or another trusted channel: ```bash -ssh-keyscan -H 192.168.55.1 >/tmp/jetson_known_hosts -ssh-keygen -lf /tmp/jetson_known_hosts +set -euo pipefail +umask 077 +known_hosts_tmp="$(mktemp /tmp/nemoclaw-jetson-known-hosts.XXXXXX)" +trap 'rm -f -- "$known_hosts_tmp"' EXIT +ssh-keyscan -T 10 -H 192.168.55.1 >"$known_hosts_tmp" +ssh-keygen -lf "$known_hosts_tmp" sudo install -o nemoclaw-jetson-dispatch -g nemoclaw-jetson-dispatch -m 0600 \ - /tmp/jetson_known_hosts /var/lib/nemoclaw-jetson-dispatch/known_hosts -rm /tmp/jetson_known_hosts + "$known_hosts_tmp" /var/lib/nemoclaw-jetson-dispatch/known_hosts +rm -f -- "$known_hosts_tmp" +trap - EXIT ``` The pinned `known_hosts` file validates the SSH host identity separately from the persisted cleanup baseline. @@ -937,8 +942,10 @@ while IFS=$'\t' read -r identity_kind identity; do esac done <<<"$cleanup_identities" for volume in "${cleanup_volumes[@]}"; do - sudo -u nemoclaw-jetson-dispatch ssh -F /dev/null -T \ + timeout --kill-after=5 120 \ + sudo -u nemoclaw-jetson-dispatch ssh -F /dev/null -T \ -o BatchMode=yes -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes \ + -o ConnectTimeout=10 -o ServerAliveInterval=5 -o ServerAliveCountMax=3 \ -o UserKnownHostsFile=/var/lib/nemoclaw-jetson-dispatch/known_hosts \ -i /var/lib/nemoclaw-jetson-dispatch/id_ed25519 \ nvidia@192.168.55.1 bash -s -- "$volume" <<'VERIFY_RECORDED_VOLUME' @@ -954,8 +961,10 @@ fi VERIFY_RECORDED_VOLUME done for process_id in "${cleanup_process_ids[@]}"; do - sudo -u nemoclaw-jetson-dispatch ssh -F /dev/null -T \ + timeout --kill-after=5 120 \ + sudo -u nemoclaw-jetson-dispatch ssh -F /dev/null -T \ -o BatchMode=yes -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes \ + -o ConnectTimeout=10 -o ServerAliveInterval=5 -o ServerAliveCountMax=3 \ -o UserKnownHostsFile=/var/lib/nemoclaw-jetson-dispatch/known_hosts \ -i /var/lib/nemoclaw-jetson-dispatch/id_ed25519 \ nvidia@192.168.55.1 bash -s -- "$process_id" <<'VERIFY_RECORDED_PROCESS' @@ -966,8 +975,10 @@ if [ -e "/proc/$1" ]; then fi VERIFY_RECORDED_PROCESS done -sudo -u nemoclaw-jetson-dispatch ssh -F /dev/null -T \ +timeout --kill-after=5 120 \ + sudo -u nemoclaw-jetson-dispatch ssh -F /dev/null -T \ -o BatchMode=yes -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes \ + -o ConnectTimeout=10 -o ServerAliveInterval=5 -o ServerAliveCountMax=3 \ -o UserKnownHostsFile=/var/lib/nemoclaw-jetson-dispatch/known_hosts \ -i /var/lib/nemoclaw-jetson-dispatch/id_ed25519 \ nvidia@192.168.55.1 bash -s -- "$LAST_JOB_ID" <<'VERIFY_JETSON_IDLE' @@ -1062,7 +1073,7 @@ image_rows="$(docker image ls nemoclaw-sandbox-local --format '{{.Repository}}\t test -z "$(printf '%s\n' "$image_rows" | awk '$1 == "nemoclaw-sandbox-local" && index($2, "e2e-jetson-nvmap-") == 1 { print $1 ":" $2 }')" command -v node npm ollama -ollama list >/dev/null +timeout --kill-after=5 30 ollama list >/dev/null for openshell_component in openshell openshell-gateway openshell-sandbox; do if command -v "$openshell_component" >/dev/null 2>&1; then echo "A host-level OpenShell binary remains after cleanup: $openshell_component" >&2 @@ -1127,6 +1138,7 @@ Remove the dedicated Jetson public key and the Colossus SSH private key. Encode the exact authorized-key line so the space-containing value remains one remote-command argument, then verify that exact line is absent before deleting the Colossus key: ```bash +set -euo pipefail JETSON_PUBLIC_KEY="$(sudo cat /var/lib/nemoclaw-jetson-dispatch/id_ed25519.pub)" case "$JETSON_PUBLIC_KEY" in ssh-ed25519\ *) ;; @@ -1134,8 +1146,10 @@ case "$JETSON_PUBLIC_KEY" in esac JETSON_AUTHORIZED_KEY_LINE="from=\"192.168.55.100\",restrict $JETSON_PUBLIC_KEY" JETSON_AUTHORIZED_KEY_B64="$(printf '%s' "$JETSON_AUTHORIZED_KEY_LINE" | base64 --wrap=0)" -sudo -u nemoclaw-jetson-dispatch ssh -F /dev/null -T \ +timeout --kill-after=5 120 \ + sudo -u nemoclaw-jetson-dispatch ssh -F /dev/null -T \ -o BatchMode=yes -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes \ + -o ConnectTimeout=10 -o ServerAliveInterval=5 -o ServerAliveCountMax=3 \ -o UserKnownHostsFile=/var/lib/nemoclaw-jetson-dispatch/known_hosts \ -i /var/lib/nemoclaw-jetson-dispatch/id_ed25519 \ nvidia@192.168.55.1 bash -s -- "$JETSON_AUTHORIZED_KEY_B64" <<'REMOVE_DISPATCH_KEY' diff --git a/test/e2e/support/jetson-dispatch-worker.test.ts b/test/e2e/support/jetson-dispatch-worker.test.ts index f5dfc8e6302..bb92ec1c4c7 100644 --- a/test/e2e/support/jetson-dispatch-worker.test.ts +++ b/test/e2e/support/jetson-dispatch-worker.test.ts @@ -1317,6 +1317,58 @@ validate_recorded_pid 1234 ollama-auth-proxy. expect(dispatcherRunbook).toContain("ollama list"); }); + it("uses a private temporary file for the pinned Jetson host key (#8142)", () => { + const hostKeySection = dispatcherRunbook.slice( + dispatcherRunbook.indexOf("Capture the Jetson host key"), + dispatcherRunbook.indexOf("## Define the Cleanup Program"), + ); + const temporary = hostKeySection.indexOf( + 'known_hosts_tmp="$(mktemp /tmp/nemoclaw-jetson-known-hosts.XXXXXX)"', + ); + const cleanupTrap = hostKeySection.indexOf("trap 'rm -f -- \"$known_hosts_tmp\"' EXIT"); + const keyScan = hostKeySection.indexOf("ssh-keyscan -T 10"); + const install = hostKeySection.indexOf("sudo install"); + + expect(hostKeySection).toContain("umask 077"); + expect(temporary).toBeGreaterThan(-1); + expect(cleanupTrap).toBeGreaterThan(temporary); + expect(keyScan).toBeGreaterThan(cleanupTrap); + expect(install).toBeGreaterThan(keyScan); + expect(hostKeySection).not.toContain("/tmp/jetson_known_hosts"); + }); + + it("bounds every Jetson teardown SSH probe and the Ollama model query (#8142)", () => { + const teardown = dispatcherRunbook.slice( + dispatcherRunbook.indexOf("## Recover or Disable the Deployment"), + ); + const sshProbes = teardown.match(/sudo -u nemoclaw-jetson-dispatch ssh/gmu) ?? []; + const boundedSshProbes = + teardown.match( + /timeout --kill-after=5 120 \\\n\s+sudo -u nemoclaw-jetson-dispatch ssh -F \/dev\/null -T \\\n\s+-o BatchMode=yes -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes \\\n\s+-o ConnectTimeout=10 -o ServerAliveInterval=5 -o ServerAliveCountMax=3/gmu, + ) ?? []; + + expect(sshProbes).toHaveLength(4); + expect(boundedSshProbes).toHaveLength(sshProbes.length); + expect(teardown).toContain("timeout --kill-after=5 30 ollama list >/dev/null"); + }); + + it("stops credential teardown when the Jetson key-removal probe fails (#8142)", () => { + const credentialTeardown = dispatcherRunbook.slice( + dispatcherRunbook.indexOf("Remove the dedicated Jetson public key"), + dispatcherRunbook.indexOf("Remove the cleanup executable and pinned SSH host-key file"), + ); + const strictMode = credentialTeardown.indexOf("set -euo pipefail"); + const keyRemovalProbe = credentialTeardown.indexOf("timeout --kill-after=5 120"); + const privateKeyRemoval = credentialTeardown.indexOf( + "sudo rm -- \\\n /var/lib/nemoclaw-jetson-dispatch/id_ed25519", + ); + + expect(strictMode).toBeGreaterThan(-1); + expect(keyRemovalProbe).toBeGreaterThan(strictMode); + expect(privateKeyRemoval).toBeGreaterThan(keyRemovalProbe); + expect(credentialTeardown.slice(keyRemovalProbe, privateKeyRemoval)).not.toContain("|| true"); + }); + it("keeps recovery credentials until idle teardown verification succeeds (#8142)", () => { const stopTunnel = dispatcherRunbook.indexOf( "sudo systemctl disable --now nemoclaw-jetson-tunnel.service", From f9fbd309a5cba6f9d581f82f75c815c14e98a969 Mon Sep 17 00:00:00 2001 From: San Dang Date: Tue, 11 Aug 2026 16:40:09 +0700 Subject: [PATCH 31/34] docs(e2e): clarify Jetson key removal failure --- test/e2e/docs/jetson-colossus-dispatch.md | 4 ++++ test/e2e/support/jetson-dispatch-worker.test.ts | 3 +++ 2 files changed, 7 insertions(+) diff --git a/test/e2e/docs/jetson-colossus-dispatch.md b/test/e2e/docs/jetson-colossus-dispatch.md index 52d07652de5..703fea65db2 100644 --- a/test/e2e/docs/jetson-colossus-dispatch.md +++ b/test/e2e/docs/jetson-colossus-dispatch.md @@ -1179,6 +1179,10 @@ sudo test ! -e /var/lib/nemoclaw-jetson-dispatch/id_ed25519 sudo test ! -e /var/lib/nemoclaw-jetson-dispatch/id_ed25519.pub ``` +An SSH transport failure keeps the Colossus SSH key and pinned host-key files. +The Jetson `authorized_keys` result is inconclusive in this case. +Use the serial console to confirm that the exact key line is absent before you continue credential removal. + Remove the cleanup executable and pinned SSH host-key file, then verify their absence: ```bash diff --git a/test/e2e/support/jetson-dispatch-worker.test.ts b/test/e2e/support/jetson-dispatch-worker.test.ts index bb92ec1c4c7..b352a9818ab 100644 --- a/test/e2e/support/jetson-dispatch-worker.test.ts +++ b/test/e2e/support/jetson-dispatch-worker.test.ts @@ -1367,6 +1367,9 @@ validate_recorded_pid 1234 ollama-auth-proxy. expect(keyRemovalProbe).toBeGreaterThan(strictMode); expect(privateKeyRemoval).toBeGreaterThan(keyRemovalProbe); expect(credentialTeardown.slice(keyRemovalProbe, privateKeyRemoval)).not.toContain("|| true"); + expect(dispatcherRunbook).toContain( + "Use the serial console to confirm that the exact key line is absent", + ); }); it("keeps recovery credentials until idle teardown verification succeeds (#8142)", () => { From 77f0410152ffb2fc3190736d95e02988403669ed Mon Sep 17 00:00:00 2001 From: Prekshi Vyas Date: Tue, 11 Aug 2026 10:15:51 -0700 Subject: [PATCH 32/34] fix(e2e): preserve Jetson dispatch containment Signed-off-by: Prekshi Vyas --- test/e2e/docs/jetson-colossus-dispatch.md | 2 +- .../colossus-jetson-dispatch-deploy.test.ts | 55 +++++++++++- .../support/jetson-dispatch-contract.test.ts | 83 +++++++++++++++++++ tools/e2e/colossus-jetson-dispatch-deploy.sh | 12 ++- tools/e2e/jetson-dispatch-lifecycle.mts | 39 ++++++++- 5 files changed, 181 insertions(+), 10 deletions(-) diff --git a/test/e2e/docs/jetson-colossus-dispatch.md b/test/e2e/docs/jetson-colossus-dispatch.md index 703fea65db2..4a3d0536cef 100644 --- a/test/e2e/docs/jetson-colossus-dispatch.md +++ b/test/e2e/docs/jetson-colossus-dispatch.md @@ -664,7 +664,7 @@ gh workflow run .github/workflows/e2e.yaml --repo NVIDIA/NemoClaw --ref main \ -f "checkout_repository=$CANDIDATE_REPOSITORY" \ -f "base_sha=$BASE_SHA" \ -f "workflow_sha=$WORKFLOW_SHA" \ - -f review_reason='Reviewed this PR commit for the isolated Jetson E2E.' + -f review_reason='Reviewed the commit under review for the isolated Jetson E2E.' ``` The `jetson-nvmap-gpu` job uses the fixed `jetson-nvmap-gpu-colossus` concurrency group. diff --git a/test/e2e/support/colossus-jetson-dispatch-deploy.test.ts b/test/e2e/support/colossus-jetson-dispatch-deploy.test.ts index 2b84b14d7c5..6f6c67fb3d4 100644 --- a/test/e2e/support/colossus-jetson-dispatch-deploy.test.ts +++ b/test/e2e/support/colossus-jetson-dispatch-deploy.test.ts @@ -158,8 +158,13 @@ current_sha() { tunnel_is_active() { tunnel_check_count="$(cat "$TEST_ROOT/tunnel-check-count" 2>/dev/null || printf '0')" - [ "$TUNNEL_ACTIVE" = 1 ] || - { [ "$TUNNEL_ACTIVATE_AFTER_FIRST_CHECK" = 1 ] && [ "$tunnel_check_count" -gt 1 ]; } + if [ "$TUNNEL_ACTIVE" = 1 ]; then + return 0 + fi + if [ "$TUNNEL_ACTIVATE_AFTER_FIRST_CHECK" = 1 ] && [ "$tunnel_check_count" -gt 1 ]; then + return 0 + fi + [ "$TUNNEL_ACTIVATE_AFTER_START" = 1 ] && [ "$tunnel_check_count" -gt 2 ] } systemctl_exec() { @@ -274,6 +279,7 @@ interface DeployOptions { missingAccount?: boolean; tunnelActive?: boolean; tunnelActivatesAfterFirstCheck?: boolean; + tunnelActivatesAfterStart?: boolean; unsupportedNode?: boolean; } @@ -342,6 +348,7 @@ function runDeploy( TEST_ROOT: fixture.directory, TUNNEL_ACTIVE: options.tunnelActive ? "1" : "0", TUNNEL_ACTIVATE_AFTER_FIRST_CHECK: options.tunnelActivatesAfterFirstCheck ? "1" : "0", + TUNNEL_ACTIVATE_AFTER_START: options.tunnelActivatesAfterStart ? "1" : "0", UNSUPPORTED_NODE: options.unsupportedNode ? "1" : "0", }, }); @@ -546,6 +553,50 @@ describe("Colossus Jetson dispatcher deployment", () => { expect(curlLog).toContain("curl\t--disable\t--noproxy\t*\t--silent"); }); + it("rejects a later dispatcher deployment while public ingress is active (#8142)", () => { + const fixture = createFixture(); + const paths = deploymentPaths(fixture); + expect(runDeploy(fixture, ["--commit", fixture.firstSha]).status).toBe(0); + const serviceLogBeforeDeployment = fs.readFileSync(paths.serviceLog, "utf8"); + + const result = runDeploy(fixture, ["--commit", fixture.secondSha], { + serviceLoadState: "loaded", + tunnelActive: true, + }); + + expect(result.status).toBe(1); + expect(result.stderr).toContain("must be disabled and inactive"); + expect(fs.readlinkSync(paths.current)).toBe(path.join(paths.releases, fixture.firstSha)); + const deploymentServiceLog = fs + .readFileSync(paths.serviceLog, "utf8") + .slice(serviceLogBeforeDeployment.length); + expect(deploymentServiceLog).not.toContain("systemctl\tstop"); + expect(deploymentServiceLog).not.toContain("start-sha"); + }); + + it("leaves the installed dispatcher stopped when public ingress activates during a later deployment (#8142)", () => { + const fixture = createFixture(); + const paths = deploymentPaths(fixture); + expect(runDeploy(fixture, ["--commit", fixture.firstSha]).status).toBe(0); + fs.rmSync(path.join(fixture.directory, "tunnel-check-count")); + const serviceLogBeforeDeployment = fs.readFileSync(paths.serviceLog, "utf8"); + + const result = runDeploy(fixture, ["--commit", fixture.secondSha], { + serviceLoadState: "loaded", + tunnelActivatesAfterStart: true, + }); + + expect(result.status).toBe(1); + expect(result.stderr).toContain("rollback did not restore a verified service"); + expect(fs.readlinkSync(paths.current)).toBe(path.join(paths.releases, fixture.firstSha)); + expect(fs.existsSync(path.join(fixture.directory, "service-active"))).toBe(false); + const deploymentServiceLog = fs + .readFileSync(paths.serviceLog, "utf8") + .slice(serviceLogBeforeDeployment.length); + expect(deploymentServiceLog).toContain(`start-sha\t${fixture.secondSha}`); + expect(deploymentServiceLog).not.toContain(`start-sha\t${fixture.firstSha}`); + }); + it.each([ ["a branch", ["--commit", "main"]], ["a tag", ["--commit", "v0.1.0"]], diff --git a/test/e2e/support/jetson-dispatch-contract.test.ts b/test/e2e/support/jetson-dispatch-contract.test.ts index 1c3fde3387a..527ce5a583b 100644 --- a/test/e2e/support/jetson-dispatch-contract.test.ts +++ b/test/e2e/support/jetson-dispatch-contract.test.ts @@ -364,6 +364,56 @@ describe("Jetson single-device lifecycle", () => { await waitForCompletion(dispatch, accepted.jobId); }); + it("persists the lock and queued status before worker execution (#8142)", async () => { + const stateDirectory = temporaryDirectory(); + const syncEvents: Array<"directory" | "file"> = []; + let eventsBeforeRun: Array<"directory" | "file"> = []; + const fsyncSync = fs.fsyncSync.bind(fs); + vi.spyOn(fs, "fsyncSync").mockImplementation((descriptor) => { + syncEvents.push(fs.fstatSync(descriptor).isDirectory() ? "directory" : "file"); + fsyncSync(descriptor); + }); + const expectedResult = await worker().run(REQUEST, { + jobId: "e".repeat(64), + signal: new AbortController().signal, + }); + const run = vi.fn(async () => { + eventsBeforeRun = [...syncEvents]; + return expectedResult; + }); + const dispatch = coordinator(stateDirectory, worker({ run })); + await dispatch.initialize(); + + const accepted = dispatch.dispatch(REQUEST, identity()); + await waitForCompletion(dispatch, accepted.jobId); + + expect(eventsBeforeRun).toEqual(["file", "file", "directory", "file"]); + expect(syncEvents.filter((event) => event === "directory")).toHaveLength(2); + }); + + it("does not start the worker when state directory persistence fails (#8142)", async () => { + const stateDirectory = temporaryDirectory(); + const fsyncSync = fs.fsyncSync.bind(fs); + vi.spyOn(fs, "fsyncSync").mockImplementation((descriptor) => { + if (fs.fstatSync(descriptor).isDirectory()) { + throw new Error("state directory persistence failed"); + } + fsyncSync(descriptor); + }); + const run = vi.fn(worker().run); + const cleanup = vi.fn(async () => {}); + const dispatch = coordinator(stateDirectory, worker({ cleanup, run })); + await dispatch.initialize(); + + expect(() => dispatch.dispatch(REQUEST, identity())).toThrow( + "state directory persistence failed", + ); + + expect(run).not.toHaveBeenCalled(); + expect(cleanup).not.toHaveBeenCalled(); + expect(fs.existsSync(path.join(stateDirectory, "device.lock"))).toBe(true); + }); + it("cancels the worker and still cleans the device with a fresh signal (#8142)", async () => { let runSignal: AbortSignal | undefined; let cleanupSignal: AbortSignal | undefined; @@ -440,6 +490,39 @@ describe("Jetson single-device lifecycle", () => { expect(fs.existsSync(path.join(stateDirectory, "device.lock"))).toBe(false); }); + it("restores the device lock when directory fsync fails after removal (#8142)", async () => { + const stateDirectory = temporaryDirectory(); + const cleanup = vi.fn(async () => {}); + const fsyncSync = fs.fsyncSync.bind(fs); + let directorySyncCount = 0; + vi.spyOn(fs, "fsyncSync").mockImplementation((descriptor) => { + if (fs.fstatSync(descriptor).isDirectory()) { + directorySyncCount += 1; + if (directorySyncCount === 2) { + throw new Error("lock directory persistence failed"); + } + } + fsyncSync(descriptor); + }); + const dispatch = coordinator(stateDirectory, worker({ cleanup })); + await dispatch.initialize(); + const accepted = dispatch.dispatch(REQUEST, identity()); + const completed = await waitForCompletion(dispatch, accepted.jobId); + + expect(completed).toMatchObject({ + conclusion: "cleanup-failed", + error: "Jetson lock removal failed: lock directory persistence failed", + cleanup: "succeeded", + }); + expect(fs.existsSync(path.join(stateDirectory, "device.lock"))).toBe(true); + + const restarted = coordinator(stateDirectory, worker({ cleanup })); + await restarted.initialize(); + + expect(cleanup).toHaveBeenCalledTimes(2); + expect(fs.existsSync(path.join(stateDirectory, "device.lock"))).toBe(false); + }); + it("keeps the lock until restart persists a terminal result (#8142)", async () => { const stateDirectory = temporaryDirectory(); const expectedResult = await worker().run(REQUEST, { diff --git a/tools/e2e/colossus-jetson-dispatch-deploy.sh b/tools/e2e/colossus-jetson-dispatch-deploy.sh index 3d5711904d0..67e1df62cde 100755 --- a/tools/e2e/colossus-jetson-dispatch-deploy.sh +++ b/tools/e2e/colossus-jetson-dispatch-deploy.sh @@ -530,8 +530,10 @@ verify_loopback_service() { } start_and_verify_service() { + public_ingress_is_disabled || return 1 systemctl_exec start "$service_name" || return 1 - verify_loopback_service + verify_loopback_service || return 1 + public_ingress_is_disabled } enable_and_verify_initial_service() { @@ -540,9 +542,11 @@ enable_and_verify_initial_service() { bootstrap_daemon_reloaded=1 load_state="$(service_load_state)" || return 1 [ "$load_state" = loaded ] || return 1 + public_ingress_is_disabled || return 1 bootstrap_enable_attempted=1 systemctl_exec enable --now "$service_name" || return 1 - verify_loopback_service + verify_loopback_service || return 1 + public_ingress_is_disabled } restore_cleanup_selection() { @@ -627,6 +631,7 @@ main() { validate_dispatcher_prerequisites ensure_layout acquire_deploy_lock + require_public_ingress_disabled load_state="$(service_load_state)" || fail "could not inspect $service_name" if [ "$load_state" = loaded ]; then @@ -638,7 +643,6 @@ main() { else print_stage 2 "Verify initial deployment state" require_device_lock_absent - require_public_ingress_disabled require_bootstrap_destinations_absent fi @@ -672,7 +676,7 @@ main() { echo "Deployed Colossus Jetson dispatcher release $sha and verified its loopback service" else print_stage 5 "Install, enable, and verify the dispatcher" - if ! install_bootstrap_files "$release" || ! enable_and_verify_initial_service || ! public_ingress_is_disabled; then + if ! install_bootstrap_files "$release" || ! enable_and_verify_initial_service; then if rollback_initial_deployment "$previous_release" "$cleanup_was_present"; then fail "release $sha initial deployment failed; the release, unit, and environment were rolled back" fi diff --git a/tools/e2e/jetson-dispatch-lifecycle.mts b/tools/e2e/jetson-dispatch-lifecycle.mts index c6373832f45..8f93c0f5101 100644 --- a/tools/e2e/jetson-dispatch-lifecycle.mts +++ b/tools/e2e/jetson-dispatch-lifecycle.mts @@ -153,6 +153,21 @@ function ensurePrivateDirectory(directory: string): void { fs.chmodSync(directory, 0o700); } +function fsyncDirectory(directory: string): void { + const descriptor = fs.openSync( + directory, + fs.constants.O_RDONLY | (fs.constants.O_DIRECTORY ?? 0) | (fs.constants.O_NOFOLLOW ?? 0), + ); + try { + if (!fs.fstatSync(descriptor).isDirectory()) { + throw new Error(`${directory} must be a directory`); + } + fs.fsyncSync(descriptor); + } finally { + fs.closeSync(descriptor); + } +} + function dispatchJobId(request: JetsonDispatchRequest): string { return createHash("sha256") .update( @@ -336,7 +351,7 @@ export class JetsonDispatchCoordinator { recoveredStatus.error = "Jetson dispatcher restarted before terminal status was persisted"; this.#persist(recoveredStatus); } - fs.unlinkSync(this.#lockPath); + this.#removeDeviceLock(jobId); } this.#restoreCompletedStatuses(); this.#initialized = true; @@ -377,8 +392,9 @@ export class JetsonDispatchCoordinator { try { this.#clearPriorResultFiles(jobId); this.#persist(status); + fsyncDirectory(this.#stateDirectory); } catch (error) { - fs.unlinkSync(this.#lockPath); + this.#removeDeviceLock(jobId); throw error; } this.#jobs.set(jobId, status); @@ -515,7 +531,7 @@ export class JetsonDispatchCoordinator { } if (status.cleanup === "succeeded" && terminalStatusPersisted) { try { - fs.unlinkSync(this.#lockPath); + this.#removeDeviceLock(status.jobId); } catch (error) { const lockError = `Jetson lock removal failed: ${safeError(error)}`; status.error = appendBoundedError(status.error, lockError); @@ -539,6 +555,23 @@ export class JetsonDispatchCoordinator { writePrivateRegularFile(this.#statusPath(status.jobId), `${JSON.stringify(status, null, 2)}\n`); } + #removeDeviceLock(jobId: string): void { + fs.unlinkSync(this.#lockPath); + try { + fsyncDirectory(this.#stateDirectory); + } catch (error) { + try { + createPrivateRegularFile(this.#lockPath, `${jobId}\n`); + fsyncDirectory(this.#stateDirectory); + } catch (restoreError) { + throw new Error( + `${safeError(error)}; Jetson lock restoration failed: ${safeError(restoreError)}`, + ); + } + throw error; + } + } + #statusPath(jobId: string): string { return path.join(this.#stateDirectory, `${jobId}.json`); } From fcfe7dc2ea14fb40721ed64ef14328cfc3e8ce34 Mon Sep 17 00:00:00 2001 From: Prekshi Vyas Date: Tue, 11 Aug 2026 10:34:51 -0700 Subject: [PATCH 33/34] test(e2e): keep dispatch recovery tests linear Signed-off-by: Prekshi Vyas --- .../support/jetson-dispatch-contract.test.ts | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/test/e2e/support/jetson-dispatch-contract.test.ts b/test/e2e/support/jetson-dispatch-contract.test.ts index 527ce5a583b..9fca2679699 100644 --- a/test/e2e/support/jetson-dispatch-contract.test.ts +++ b/test/e2e/support/jetson-dispatch-contract.test.ts @@ -62,6 +62,10 @@ function temporaryDirectory(): string { return directory; } +function failTest(message: string): never { + throw new Error(message); +} + function claims(overrides: Record = {}): Record { return { iss: "https://token.actions.githubusercontent.com", @@ -394,12 +398,11 @@ describe("Jetson single-device lifecycle", () => { it("does not start the worker when state directory persistence fails (#8142)", async () => { const stateDirectory = temporaryDirectory(); const fsyncSync = fs.fsyncSync.bind(fs); - vi.spyOn(fs, "fsyncSync").mockImplementation((descriptor) => { - if (fs.fstatSync(descriptor).isDirectory()) { - throw new Error("state directory persistence failed"); - } - fsyncSync(descriptor); - }); + vi.spyOn(fs, "fsyncSync").mockImplementation((descriptor) => + fs.fstatSync(descriptor).isDirectory() + ? failTest("state directory persistence failed") + : fsyncSync(descriptor), + ); const run = vi.fn(worker().run); const cleanup = vi.fn(async () => {}); const dispatch = coordinator(stateDirectory, worker({ cleanup, run })); @@ -496,13 +499,11 @@ describe("Jetson single-device lifecycle", () => { const fsyncSync = fs.fsyncSync.bind(fs); let directorySyncCount = 0; vi.spyOn(fs, "fsyncSync").mockImplementation((descriptor) => { - if (fs.fstatSync(descriptor).isDirectory()) { - directorySyncCount += 1; - if (directorySyncCount === 2) { - throw new Error("lock directory persistence failed"); - } - } - fsyncSync(descriptor); + const isDirectory = fs.fstatSync(descriptor).isDirectory(); + directorySyncCount += Number(isDirectory); + return isDirectory && directorySyncCount === 2 + ? failTest("lock directory persistence failed") + : fsyncSync(descriptor); }); const dispatch = coordinator(stateDirectory, worker({ cleanup })); await dispatch.initialize(); From 540c9c08d48e0b461dec856f56cc47b9910bc4fa Mon Sep 17 00:00:00 2001 From: San Dang Date: Wed, 12 Aug 2026 00:36:58 +0700 Subject: [PATCH 34/34] fix(e2e): complete Jetson dispatch containment Signed-off-by: San Dang --- test/e2e/docs/jetson-colossus-dispatch.md | 44 ++++++--- .../colossus-jetson-dispatch-deploy.test.ts | 61 ++++++++++--- .../support/jetson-dispatch-contract.test.ts | 91 +++++++++++++++---- tools/e2e/colossus-jetson-dispatch-deploy.sh | 24 ++++- tools/e2e/jetson-dispatch-lifecycle.mts | 37 +++++--- 5 files changed, 199 insertions(+), 58 deletions(-) diff --git a/test/e2e/docs/jetson-colossus-dispatch.md b/test/e2e/docs/jetson-colossus-dispatch.md index 4a3d0536cef..87ad9e1d0b1 100644 --- a/test/e2e/docs/jetson-colossus-dispatch.md +++ b/test/e2e/docs/jetson-colossus-dispatch.md @@ -362,13 +362,16 @@ The command verifies the fixed origin, exact commit, unmodified worktree, cleanu It installs `/etc/nemoclaw-jetson-dispatch/environment` as `root:root` mode `0600`. It installs `/etc/systemd/system/nemoclaw-jetson-dispatch.service` as `root:root` mode `0644`. It runs `systemctl daemon-reload` and `systemctl enable --now nemoclaw-jetson-dispatch.service`. -Before success, it requires the service to listen only on `127.0.0.1:8787`, an anonymous job request to return HTTP `401`, and the Cloudflare Tunnel service to remain disabled and inactive. +It requires the Cloudflare Tunnel service to be absent or disabled and inactive immediately before the dispatcher starts, immediately after it starts, and after loopback verification. +Before success, it also requires the dispatcher to listen only on `127.0.0.1:8787` and an anonymous job request to return HTTP `401`. -If initial startup or verification fails after enablement, the command disables and stops the service before rollback. -It requires exact `ActiveState=inactive` and an absent device lock before it restores the prior release and cleanup selection. +If initial startup or verification fails after enablement, the command attempts to disable and stop the service before rollback. +It restores the prior release and cleanup selection only after proving exact `ActiveState=inactive` and an absent device lock. An earlier selection or configuration-installation failure restores the prior selection and removes only files or links created by the attempt. Rollback removes any environment and unit that the attempt installed, reloads systemd, and requires `LoadState=not-found`. If it cannot establish these conditions, it reports rollback failure. +If initial activation detects public ingress and rollback cannot disable and stop the dispatcher, its state is inconclusive. +Immediately disable or delete public ingress through the approved Cloudflare administrator path and prove that the public endpoint is unavailable before local recovery. The command never enables or starts the Cloudflare Tunnel service. It accepts no cleanup override and does not change the cleanup allowlist. @@ -488,31 +491,37 @@ Both cases require `device.lock` to be absent before release preparation. A loaded service is eligible only when `current` selects one managed release and the stable cleanup link follows `current`. For a loaded service, the command performs these actions: -1. Stop the service. -2. Query `ActiveState` and require the exact value `inactive`. +1. Require the Cloudflare Tunnel service to be disabled and inactive, then stop the dispatcher. +2. Query dispatcher `ActiveState` and require the exact value `inactive`. 3. Refuse deployment when `/var/lib/nemoclaw-jetson-dispatch/state/device.lock` remains. 4. Validate the managed `current` release and stable cleanup link, then prepare and verify the requested release. -5. Atomically switch `current`, selecting the requested dispatcher code and cleanup program together. -6. Start the service. +5. Require the tunnel to remain disabled and inactive, then atomically switch `current`, selecting the requested dispatcher code and cleanup program together. +6. Require the tunnel to remain disabled and inactive immediately before and after starting the dispatcher. 7. Verify that only `127.0.0.1:8787` listens and make a config-free, direct request with `curl --disable --noproxy '*'`; the anonymous job request must return HTTP `401`. +8. Require the tunnel to remain disabled and inactive after loopback verification. -If the post-stop state cannot be read, is not `inactive`, or `device.lock` remains, the command exits with the service stopped and does not prepare or select a release. +If the stop or post-stop inspection cannot prove `inactive`, dispatcher state is inconclusive and the command does not prepare or select a release. +If `device.lock` remains after a proven stop, the command exits with the service stopped and does not prepare or select a release. Do not remove the lock. Complete the recovery procedure on this page before you rerun deployment. +If the loaded service's pre-stop public-ingress check fails, the previously verified dispatcher remains running and unchanged. An interruption before the atomic `current` switch leaves the previous dispatcher and cleanup program selected; an interruption after it selects both from the requested release. If activation, start, or loopback verification fails for a loaded service, rollback must first stop the service successfully, require `ActiveState=inactive`, and require `device.lock` to be absent. Only then does it atomically restore the prior `current` selection, which restores both the dispatcher and cleanup program. If rollback cannot prove those three conditions after the requested pair is selected, it leaves that new code and cleanup pair selected and reports rollback failure. When an earlier selected release exists, it restarts that release and repeats the loopback verification. +That rollback restart passes the same tunnel checks before and after start and after loopback verification. +If public ingress activates after a dispatcher start, the command attempts to stop it and does not restart either release while ingress remains active. +If that stop, the `ActiveState` inspection, or the device-lock check fails, dispatcher state is inconclusive. When no prior selection exists, rollback removes the new `current` and stable cleanup link. If rollback cannot restore a verified service, the command exits with an explicit rollback failure. When the trap confirms `ActiveState=inactive`, keep the tunnel stopped while you complete dispatcher recovery. If it reports `PUBLIC INGRESS CONTAINMENT FAILED`, do not assume that the tunnel stopped. Immediately disable or delete the public ingress through the approved Cloudflare administrator path and confirm that the public endpoint is unavailable. -Only after that external containment proof should you recover the dispatcher locally. -Do not restart it until the dispatcher again binds only to `127.0.0.1:8787` and a config-free, direct anonymous request returns HTTP `401` locally. -Then rerun the complete later-deployment subshell. +Keep the dispatcher stopped until the tunnel is confirmed disabled and inactive and the public endpoint is unavailable. +Then rerun the complete later-deployment subshell instead of starting the dispatcher manually. +The deployer repeats the ingress gates and local bind and authentication verification before the subshell can publish the tunnel again. Its exit trap keeps the tunnel stopped unless `ActiveState=active` and the config-free, direct public HTTP `401` proof both succeed. A later deployment does not modify the dispatcher environment, systemd unit, SSH credentials, or Cloudflare credentials. @@ -747,8 +756,14 @@ An invalid matching file fails initialization before the dispatcher accepts work Status and artifact requests both restore an evicted completed status from its private file. Only an artifact request returns the persisted log and archive. A repeated deterministic dispatch returns the persisted completed status without rerunning candidate code or clearing its evidence. +Before worker execution, the dispatcher creates `device.lock`, persists the queued status, and synchronizes the Colossus state directory. +If queued-state persistence or that directory synchronization fails, candidate code does not run and the dispatcher does not unlink the exact live job lock. +Because a failed directory synchronization cannot prove reboot durability, inspect the live state and restart the dispatcher service to invoke startup cleanup without rebooting the Colossus host. The dispatcher persists terminal status before it removes `device.lock`. -If that persistence fails, it reports a completed in-memory failure and retains the lock. +After removing the lock, it synchronizes the state directory. +If terminal-status persistence fails, it reports a completed in-memory failure and retains the lock. +If the lock-removal directory synchronization fails and restoration succeeds, it re-establishes the exact same job lock, synchronizes the directory again, and reports the lock-removal failure. +If restoration fails, lock state is inconclusive; the dispatcher sets an in-memory recovery barrier, blocks later dispatches, and reports that operator recovery is required during shutdown. After the workflow completes, independently verify every allowlisted resource is absent. Require the private `.cleanup.json` file and verify every recorded volume and process ID is absent. @@ -774,7 +789,8 @@ Only then does the dispatcher remove the lock; if this recovery persistence fail A repeated deterministic dispatch returns that recovered failure without rerunning candidate code. If cleanup fails, startup fails or the completed job reports `conclusion: "cleanup-failed"` with `cleanup: "failed"`. If cleanup succeeds but lock removal fails, the completed job reports `conclusion: "cleanup-failed"` with `cleanup: "succeeded"`. -The lock remains in either case. +The lock remains after a cleanup failure or successful lock restoration. +A lock-restoration failure does not prove whether the lock exists. Bounded status error text retains the newest cleanup, persistence, or lock-removal error. If the service stops before durable persistence completes, destructive cleanup has not started. @@ -846,6 +862,8 @@ For `cleanup: "failed"`, inspect the recorded error before choosing a recovery a Repair the cleanup program or allowlisted resource state only when that named operation failed. If the protected tool or Ollama model baseline differs after cleanup, investigate candidate activity and external host drift without assigning the change to cleanup. For `cleanup: "succeeded"` with a lock-removal error, repair the state-directory filesystem or permissions. +If the error also reports lock-restoration failure, stop the dispatcher and treat the exact `device.lock` state as inconclusive. +Use the ownership, file-type, mode, and exact job-ID checks above to inspect it without following links; do not accept more work until approved recovery and a service restart complete startup cleanup. Start the dispatcher after the named condition is fixed: ```bash diff --git a/test/e2e/support/colossus-jetson-dispatch-deploy.test.ts b/test/e2e/support/colossus-jetson-dispatch-deploy.test.ts index 6f6c67fb3d4..365642f4fbd 100644 --- a/test/e2e/support/colossus-jetson-dispatch-deploy.test.ts +++ b/test/e2e/support/colossus-jetson-dispatch-deploy.test.ts @@ -158,13 +158,9 @@ current_sha() { tunnel_is_active() { tunnel_check_count="$(cat "$TEST_ROOT/tunnel-check-count" 2>/dev/null || printf '0')" - if [ "$TUNNEL_ACTIVE" = 1 ]; then - return 0 - fi - if [ "$TUNNEL_ACTIVATE_AFTER_FIRST_CHECK" = 1 ] && [ "$tunnel_check_count" -gt 1 ]; then - return 0 - fi - [ "$TUNNEL_ACTIVATE_AFTER_START" = 1 ] && [ "$tunnel_check_count" -gt 2 ] + [ "$TUNNEL_ACTIVE" = 1 ] || + { [ "$TUNNEL_ACTIVATE_AFTER_CHECK" -gt 0 ] && + [ "$tunnel_check_count" -gt "$TUNNEL_ACTIVATE_AFTER_CHECK" ]; } } systemctl_exec() { @@ -278,8 +274,7 @@ interface DeployOptions { leaveDeviceLock?: boolean; missingAccount?: boolean; tunnelActive?: boolean; - tunnelActivatesAfterFirstCheck?: boolean; - tunnelActivatesAfterStart?: boolean; + tunnelActivatesAfterCheck?: number; unsupportedNode?: boolean; } @@ -347,8 +342,7 @@ function runDeploy( SERVICE_LOAD_STATE: options.serviceLoadState ?? "not-found", TEST_ROOT: fixture.directory, TUNNEL_ACTIVE: options.tunnelActive ? "1" : "0", - TUNNEL_ACTIVATE_AFTER_FIRST_CHECK: options.tunnelActivatesAfterFirstCheck ? "1" : "0", - TUNNEL_ACTIVATE_AFTER_START: options.tunnelActivatesAfterStart ? "1" : "0", + TUNNEL_ACTIVATE_AFTER_CHECK: String(options.tunnelActivatesAfterCheck ?? 0), UNSUPPORTED_NODE: options.unsupportedNode ? "1" : "0", }, }); @@ -490,7 +484,7 @@ describe("Colossus Jetson dispatcher deployment", () => { const fixture = createFixture(); const paths = deploymentPaths(fixture); const result = runDeploy(fixture, ["--commit", fixture.firstSha], { - tunnelActivatesAfterFirstCheck: true, + tunnelActivatesAfterCheck: 1, }); expect(result.status).toBe(1); @@ -535,6 +529,22 @@ describe("Colossus Jetson dispatcher deployment", () => { expect(fs.existsSync(paths.unit)).toBe(true); }); + it("reports inconclusive containment when ingress activates and initial disable fails (#8142)", () => { + const fixture = createFixture(); + const paths = deploymentPaths(fixture); + const result = runDeploy(fixture, ["--commit", fixture.firstSha], { + failInitialRollbackDisable: true, + tunnelActivatesAfterCheck: 2, + }); + + expect(result.status).toBe(1); + expect(result.stderr).toContain("rollback did not restore the prepared host"); + expect(fs.existsSync(path.join(fixture.directory, "service-active"))).toBe(true); + expect(fs.readlinkSync(paths.current)).toBe(path.join(paths.releases, fixture.firstSha)); + expect(fs.existsSync(paths.environment)).toBe(true); + expect(fs.existsSync(paths.unit)).toBe(true); + }); + it("stops, switches, starts, and verifies an installed loopback service (#8142)", () => { const fixture = createFixture(); expect(runDeploy(fixture, ["--commit", fixture.firstSha]).status).toBe(0); @@ -574,16 +584,19 @@ describe("Colossus Jetson dispatcher deployment", () => { expect(deploymentServiceLog).not.toContain("start-sha"); }); - it("leaves the installed dispatcher stopped when public ingress activates during a later deployment (#8142)", () => { + it.each([ + ["after the dispatcher starts", 3], + ["after loopback verification", 4], + ])("leaves the dispatcher stopped when public ingress activates %s (#8142)", (_phase, check) => { const fixture = createFixture(); const paths = deploymentPaths(fixture); expect(runDeploy(fixture, ["--commit", fixture.firstSha]).status).toBe(0); - fs.rmSync(path.join(fixture.directory, "tunnel-check-count")); + fs.rmSync(path.join(fixture.directory, "tunnel-check-count"), { force: true }); const serviceLogBeforeDeployment = fs.readFileSync(paths.serviceLog, "utf8"); const result = runDeploy(fixture, ["--commit", fixture.secondSha], { serviceLoadState: "loaded", - tunnelActivatesAfterStart: true, + tunnelActivatesAfterCheck: check, }); expect(result.status).toBe(1); @@ -597,6 +610,24 @@ describe("Colossus Jetson dispatcher deployment", () => { expect(deploymentServiceLog).not.toContain(`start-sha\t${fixture.firstSha}`); }); + it("reports inconclusive dispatcher state when ingress containment cannot stop it (#8142)", () => { + const fixture = createFixture(); + const paths = deploymentPaths(fixture); + expect(runDeploy(fixture, ["--commit", fixture.firstSha]).status).toBe(0); + fs.rmSync(path.join(fixture.directory, "tunnel-check-count"), { force: true }); + + const result = runDeploy(fixture, ["--commit", fixture.secondSha], { + failRollbackStop: true, + serviceLoadState: "loaded", + tunnelActivatesAfterCheck: 3, + }); + + expect(result.status).toBe(1); + expect(result.stderr).toContain("rollback did not restore a verified service"); + expect(fs.readlinkSync(paths.current)).toBe(path.join(paths.releases, fixture.secondSha)); + expect(fs.existsSync(path.join(fixture.directory, "service-active"))).toBe(true); + }); + it.each([ ["a branch", ["--commit", "main"]], ["a tag", ["--commit", "v0.1.0"]], diff --git a/test/e2e/support/jetson-dispatch-contract.test.ts b/test/e2e/support/jetson-dispatch-contract.test.ts index 9fca2679699..287452a0e44 100644 --- a/test/e2e/support/jetson-dispatch-contract.test.ts +++ b/test/e2e/support/jetson-dispatch-contract.test.ts @@ -370,20 +370,26 @@ describe("Jetson single-device lifecycle", () => { it("persists the lock and queued status before worker execution (#8142)", async () => { const stateDirectory = temporaryDirectory(); - const syncEvents: Array<"directory" | "file"> = []; - let eventsBeforeRun: Array<"directory" | "file"> = []; + const events: string[] = []; const fsyncSync = fs.fsyncSync.bind(fs); vi.spyOn(fs, "fsyncSync").mockImplementation((descriptor) => { - syncEvents.push(fs.fstatSync(descriptor).isDirectory() ? "directory" : "file"); + events.push(fs.fstatSync(descriptor).isDirectory() ? "directory-fsync" : "file-fsync"); fsyncSync(descriptor); }); - const expectedResult = await worker().run(REQUEST, { - jobId: "e".repeat(64), - signal: new AbortController().signal, + const unlinkSync = fs.unlinkSync.bind(fs); + vi.spyOn(fs, "unlinkSync").mockImplementation((file) => { + events.push(file === path.join(stateDirectory, "device.lock") ? "lock-unlink" : "unlink"); + unlinkSync(file); }); - const run = vi.fn(async () => { - eventsBeforeRun = [...syncEvents]; - return expectedResult; + const run = vi.fn(async (_request, options) => { + events.push("worker-run"); + expect(fs.readFileSync(path.join(stateDirectory, "device.lock"), "utf8")).toBe( + `${options.jobId}\n`, + ); + expect( + JSON.parse(fs.readFileSync(path.join(stateDirectory, `${options.jobId}.json`), "utf8")), + ).toMatchObject({ jobId: options.jobId, state: "queued" }); + return worker().run(_request, options); }); const dispatch = coordinator(stateDirectory, worker({ run })); await dispatch.initialize(); @@ -391,18 +397,21 @@ describe("Jetson single-device lifecycle", () => { const accepted = dispatch.dispatch(REQUEST, identity()); await waitForCompletion(dispatch, accepted.jobId); - expect(eventsBeforeRun).toEqual(["file", "file", "directory", "file"]); - expect(syncEvents.filter((event) => event === "directory")).toHaveLength(2); + expect(events.indexOf("directory-fsync")).toBeLessThan(events.indexOf("worker-run")); + expect(events.indexOf("worker-run")).toBeLessThan(events.indexOf("lock-unlink")); + expect(events.indexOf("lock-unlink")).toBeLessThan(events.lastIndexOf("directory-fsync")); }); it("does not start the worker when state directory persistence fails (#8142)", async () => { const stateDirectory = temporaryDirectory(); const fsyncSync = fs.fsyncSync.bind(fs); - vi.spyOn(fs, "fsyncSync").mockImplementation((descriptor) => - fs.fstatSync(descriptor).isDirectory() - ? failTest("state directory persistence failed") - : fsyncSync(descriptor), - ); + let rejectDirectoryFsync = true; + vi.spyOn(fs, "fsyncSync").mockImplementation((descriptor) => { + const isDirectory = fs.fstatSync(descriptor).isDirectory(); + const shouldReject = rejectDirectoryFsync && isDirectory; + rejectDirectoryFsync = rejectDirectoryFsync && !isDirectory; + return shouldReject ? failTest("state directory persistence failed") : fsyncSync(descriptor); + }); const run = vi.fn(worker().run); const cleanup = vi.fn(async () => {}); const dispatch = coordinator(stateDirectory, worker({ cleanup, run })); @@ -415,6 +424,13 @@ describe("Jetson single-device lifecycle", () => { expect(run).not.toHaveBeenCalled(); expect(cleanup).not.toHaveBeenCalled(); expect(fs.existsSync(path.join(stateDirectory, "device.lock"))).toBe(true); + + const restarted = coordinator(stateDirectory, worker({ cleanup, run })); + await restarted.initialize(); + + expect(cleanup).toHaveBeenCalledOnce(); + expect(run).not.toHaveBeenCalled(); + expect(fs.existsSync(path.join(stateDirectory, "device.lock"))).toBe(false); }); it("cancels the worker and still cleans the device with a fresh signal (#8142)", async () => { @@ -515,7 +531,10 @@ describe("Jetson single-device lifecycle", () => { error: "Jetson lock removal failed: lock directory persistence failed", cleanup: "succeeded", }); - expect(fs.existsSync(path.join(stateDirectory, "device.lock"))).toBe(true); + expect(directorySyncCount).toBe(3); + expect(fs.readFileSync(path.join(stateDirectory, "device.lock"), "utf8")).toBe( + `${accepted.jobId}\n`, + ); const restarted = coordinator(stateDirectory, worker({ cleanup })); await restarted.initialize(); @@ -524,6 +543,44 @@ describe("Jetson single-device lifecycle", () => { expect(fs.existsSync(path.join(stateDirectory, "device.lock"))).toBe(false); }); + it("blocks later dispatch when lock restoration cannot recreate the lock (#8142)", async () => { + const stateDirectory = temporaryDirectory(); + const lockPath = path.join(stateDirectory, "device.lock"); + const fsyncSync = fs.fsyncSync.bind(fs); + let directorySyncCount = 0; + vi.spyOn(fs, "fsyncSync").mockImplementation((descriptor) => { + const isDirectory = fs.fstatSync(descriptor).isDirectory(); + directorySyncCount += Number(isDirectory); + return isDirectory && directorySyncCount === 2 + ? failTest("lock directory persistence failed") + : fsyncSync(descriptor); + }); + const run = vi.fn(worker().run); + const dispatch = coordinator(stateDirectory, worker({ run })); + await dispatch.initialize(); + const openSync = fs.openSync.bind(fs); + let lockOpenCount = 0; + vi.spyOn(fs, "openSync").mockImplementation((file, flags, mode) => { + const isLock = file === lockPath; + lockOpenCount += Number(isLock); + return isLock && lockOpenCount === 2 + ? failTest("lock restoration unavailable") + : openSync(file, flags, mode); + }); + const accepted = dispatch.dispatch(REQUEST, identity()); + const completed = await waitForCompletion(dispatch, accepted.jobId); + + expect(completed.error).toContain("lock restoration failed: lock restoration unavailable"); + expect(fs.existsSync(lockPath)).toBe(false); + expect(() => + dispatch.dispatch({ ...REQUEST, candidateSha: "c".repeat(40) }, identity()), + ).toThrow("Jetson device lock requires recovery"); + expect(run).toHaveBeenCalledOnce(); + await expect(dispatch.shutdown()).rejects.toThrow( + "Jetson device lock state requires operator recovery", + ); + }); + it("keeps the lock until restart persists a terminal result (#8142)", async () => { const stateDirectory = temporaryDirectory(); const expectedResult = await worker().run(REQUEST, { diff --git a/tools/e2e/colossus-jetson-dispatch-deploy.sh b/tools/e2e/colossus-jetson-dispatch-deploy.sh index 67e1df62cde..9adae79c93a 100755 --- a/tools/e2e/colossus-jetson-dispatch-deploy.sh +++ b/tools/e2e/colossus-jetson-dispatch-deploy.sh @@ -532,8 +532,15 @@ verify_loopback_service() { start_and_verify_service() { public_ingress_is_disabled || return 1 systemctl_exec start "$service_name" || return 1 + if ! public_ingress_is_disabled; then + stop_unverified_service || return 1 + return 1 + fi verify_loopback_service || return 1 - public_ingress_is_disabled + if ! public_ingress_is_disabled; then + stop_unverified_service || return 1 + return 1 + fi } enable_and_verify_initial_service() { @@ -545,10 +552,19 @@ enable_and_verify_initial_service() { public_ingress_is_disabled || return 1 bootstrap_enable_attempted=1 systemctl_exec enable --now "$service_name" || return 1 + public_ingress_is_disabled || return 1 verify_loopback_service || return 1 public_ingress_is_disabled } +stop_unverified_service() { + local active_state + systemctl_exec stop "$service_name" || return 1 + active_state="$(service_active_state)" || return 1 + [ "$active_state" = inactive ] || return 1 + device_lock_is_absent +} + restore_cleanup_selection() { local cleanup_was_present="$1" if [ "$cleanup_was_present" = 1 ]; then @@ -631,18 +647,19 @@ main() { validate_dispatcher_prerequisites ensure_layout acquire_deploy_lock - require_public_ingress_disabled load_state="$(service_load_state)" || fail "could not inspect $service_name" if [ "$load_state" = loaded ]; then service_installed=1 print_stage 2 "Stop and verify the dispatcher" + require_public_ingress_disabled stop_installed_service elif [ "$load_state" != not-found ]; then fail "$service_name has unsupported load state: $load_state" else print_stage 2 "Verify initial deployment state" require_device_lock_absent + require_public_ingress_disabled require_bootstrap_destinations_absent fi @@ -658,6 +675,9 @@ main() { release="$(prepare_release "$sha")" print_stage 4 "Select dispatcher and cleanup code" + if [ "$service_installed" = 1 ]; then + require_public_ingress_disabled + fi if ! activate_release "$release"; then if rollback_deployment "$previous_release" "$cleanup_was_present" "$service_installed"; then fail "release $sha activation or verification failed; the previous deployment state was restored" diff --git a/tools/e2e/jetson-dispatch-lifecycle.mts b/tools/e2e/jetson-dispatch-lifecycle.mts index 8f93c0f5101..35cd03a0a79 100644 --- a/tools/e2e/jetson-dispatch-lifecycle.mts +++ b/tools/e2e/jetson-dispatch-lifecycle.mts @@ -295,6 +295,7 @@ export class JetsonDispatchCoordinator { #activeRun: Promise | undefined; #cancelRequested = false; #initialized = false; + #lockRecoveryRequired = false; constructor(options: { stateDirectory: string; @@ -359,6 +360,9 @@ export class JetsonDispatchCoordinator { dispatch(request: JetsonDispatchRequest, identity: GitHubOidcIdentity): JetsonDispatchStatus { this.#requireInitialized(); + if (this.#lockRecoveryRequired) { + throw new JetsonDispatchBusyError("Jetson device lock requires recovery"); + } if ( identity.runId !== request.workflowRunId || identity.runAttempt !== request.workflowRunAttempt @@ -389,14 +393,9 @@ export class JetsonDispatchCoordinator { createdAt: new Date().toISOString(), cleanup: "pending", }; - try { - this.#clearPriorResultFiles(jobId); - this.#persist(status); - fsyncDirectory(this.#stateDirectory); - } catch (error) { - this.#removeDeviceLock(jobId); - throw error; - } + this.#clearPriorResultFiles(jobId); + this.#persist(status); + fsyncDirectory(this.#stateDirectory); this.#jobs.set(jobId, status); this.#activeJobId = jobId; this.#activeRun = this.#run(status); @@ -428,6 +427,9 @@ export class JetsonDispatchCoordinator { async shutdown(): Promise { if (this.#activeJobId) this.cancel(this.#activeJobId); await this.#activeRun; + if (this.#lockRecoveryRequired) { + throw new Error("Jetson device lock state requires operator recovery"); + } if ( readPrivateRegularFile(this.#lockPath, { allowMissing: true, @@ -561,17 +563,30 @@ export class JetsonDispatchCoordinator { fsyncDirectory(this.#stateDirectory); } catch (error) { try { - createPrivateRegularFile(this.#lockPath, `${jobId}\n`); - fsyncDirectory(this.#stateDirectory); + this.#restoreDeviceLock(jobId); } catch (restoreError) { + this.#lockRecoveryRequired = true; throw new Error( - `${safeError(error)}; Jetson lock restoration failed: ${safeError(restoreError)}`, + `Jetson lock directory persistence failed: ${safeError(error)}; lock restoration failed: ${safeError(restoreError)}`, ); } throw error; } } + #restoreDeviceLock(jobId: string): void { + try { + createPrivateRegularFile(this.#lockPath, `${jobId}\n`); + } catch (error) { + if ((error as NodeJS.ErrnoException).code !== "EEXIST") throw error; + const existing = readPrivateRegularFile(this.#lockPath, { maxBytes: 1024 }); + if (existing !== `${jobId}\n`) { + throw new Error("Jetson device lock changed while durability was restored"); + } + } + fsyncDirectory(this.#stateDirectory); + } + #statusPath(jobId: string): string { return path.join(this.#stateDirectory, `${jobId}.json`); }