From 36d9eb0c3c6b9ca5234432b97349dc7317cfa916 Mon Sep 17 00:00:00 2001 From: Dotta Date: Thu, 8 Oct 2026 07:33:16 -0500 Subject: [PATCH] fix: preserve release lanes and ship a portable Linux daemon Build the npm Linux daemon as static musl and validate its ELF load contract. Keep the Docker daemon and provider-pack image authority separate. Preserve asset assembly when unrelated workflow ancestors are skipped, and reuse the release verifier for a bounded Linux-only check. Co-Authored-By: Paperclip --- .github/workflows/release-verify.yml | 82 ++++++++++++++----- .github/workflows/release.yml | 4 +- doc/plans/2026-10-06-default-agent-runner.md | 13 ++- packages/paperclip-runner/README.md | 7 ++ .../scripts/release-provider-pack.test.mjs | 56 +++++++++++-- .../release-verify-workflow.test.mjs | 59 +++++++++++-- scripts/release-runner-artifacts.mjs | 47 +++++++++-- 7 files changed, 227 insertions(+), 41 deletions(-) diff --git a/.github/workflows/release-verify.yml b/.github/workflows/release-verify.yml index 47aa308f921..b60d8ceba37 100644 --- a/.github/workflows/release-verify.yml +++ b/.github/workflows/release-verify.yml @@ -1,6 +1,20 @@ name: Release Verify on: + workflow_dispatch: + inputs: + ref: + description: Full immutable source SHA for the provider-free portable Linux daemon check + required: true + type: string + runner_assets_only: + description: Use the existing release producers instead of full source verification + type: boolean + default: true + portable_linux_only: + description: Build and probe only the portable Linux daemon, without images, macOS or assembly + type: boolean + default: true workflow_call: inputs: ref: @@ -11,6 +25,10 @@ on: description: Build only the release daemon/provider-pack data after the caller's source gate type: boolean default: false + portable_linux_only: + description: Restrict the existing release producer to its portable Linux daemon + type: boolean + default: false outputs: runner_assets_artifact: description: Run-bound verified release daemon/provider-pack data @@ -21,14 +39,14 @@ on: # The organization group also restricts these workflow files to master. jobs: runner_chaos_evals: - if: ${{ !inputs.runner_assets_only }} + if: ${{ !inputs.runner_assets_only && !inputs.portable_linux_only }} name: Pre-release Runner chaos evals uses: ./.github/workflows/runner-chaos-evals.yml with: ref: ${{ inputs.ref }} typecheck: - if: ${{ !inputs.runner_assets_only }} + if: ${{ !inputs.runner_assets_only && !inputs.portable_linux_only }} name: Typecheck runs-on: ${{ vars.AWS_POST_MERGE_CI_ENABLED == 'true' && github.repository == 'paperclipai/paperclip' && github.repository_id == '1170821064' && github.ref == 'refs/heads/master' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.sha != '' && inputs.ref == github.sha && 'runs-on/fleet=paperclip-post-merge-x64/env=public-ci' || 'ubuntu-latest' }} timeout-minutes: 20 @@ -107,7 +125,7 @@ jobs: run: pnpm -r typecheck general_tests: - if: ${{ !inputs.runner_assets_only }} + if: ${{ !inputs.runner_assets_only && !inputs.portable_linux_only }} name: General tests (${{ matrix.group_label }}) runs-on: ${{ vars.AWS_POST_MERGE_CI_ENABLED == 'true' && github.repository == 'paperclipai/paperclip' && github.repository_id == '1170821064' && github.ref == 'refs/heads/master' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.sha != '' && inputs.ref == github.sha && 'runs-on/fleet=paperclip-post-merge-x64/env=public-ci' || 'ubuntu-latest' }} timeout-minutes: 20 @@ -215,7 +233,7 @@ jobs: fi serialized_tests: - if: ${{ !inputs.runner_assets_only }} + if: ${{ !inputs.runner_assets_only && !inputs.portable_linux_only }} name: Serialized tests (${{ matrix.shard_label }}) runs-on: ${{ vars.AWS_POST_MERGE_CI_ENABLED == 'true' && github.repository == 'paperclipai/paperclip' && github.repository_id == '1170821064' && github.ref == 'refs/heads/master' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.sha != '' && inputs.ref == github.sha && 'runs-on/fleet=paperclip-post-merge-x64/env=public-ci' || 'ubuntu-latest' }} timeout-minutes: 20 @@ -265,7 +283,7 @@ jobs: run: pnpm test:run:serialized -- --shard-index ${{ matrix.shard_index }} --shard-count ${{ matrix.shard_count }} runner_workflow_evals: - if: ${{ !inputs.runner_assets_only }} + if: ${{ !inputs.runner_assets_only && !inputs.portable_linux_only }} name: Runner workflow eval scorer contract runs-on: ${{ vars.AWS_POST_MERGE_CI_ENABLED == 'true' && github.repository == 'paperclipai/paperclip' && github.repository_id == '1170821064' && github.ref == 'refs/heads/master' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.sha != '' && inputs.ref == github.sha && 'runs-on/fleet=paperclip-post-merge-x64/env=public-ci' || 'ubuntu-latest' }} timeout-minutes: 10 @@ -296,7 +314,7 @@ jobs: run: pnpm test:runner-workflow-evals verify_paperclip_runner: - if: ${{ !inputs.runner_assets_only }} + if: ${{ !inputs.runner_assets_only && !inputs.portable_linux_only }} name: Verify Paperclip Runner (${{ matrix.lane }}) runs-on: ${{ vars.AWS_POST_MERGE_CI_ENABLED == 'true' && github.repository == 'paperclipai/paperclip' && github.repository_id == '1170821064' && github.ref == 'refs/heads/master' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.sha != '' && inputs.ref == github.sha && 'runs-on/fleet=paperclip-post-merge-x64/env=public-ci' || 'ubuntu-latest' }} timeout-minutes: 20 @@ -410,7 +428,7 @@ jobs: run: pnpm --filter @paperclipai/paperclip-runner build:rust build: - if: ${{ !inputs.runner_assets_only }} + if: ${{ !inputs.runner_assets_only && !inputs.portable_linux_only }} name: Build runs-on: ${{ vars.AWS_POST_MERGE_CI_ENABLED == 'true' && github.repository == 'paperclipai/paperclip' && github.repository_id == '1170821064' && github.ref == 'refs/heads/master' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.sha != '' && inputs.ref == github.sha && 'runs-on/fleet=paperclip-post-merge-x64/env=public-ci' || 'ubuntu-latest' }} timeout-minutes: 20 @@ -444,18 +462,15 @@ jobs: # caller; these unprivileged jobs neither publish nor receive provider secrets. runner_release_binaries: needs: runner_release_request - if: inputs.runner_assets_only + if: >- + !cancelled() && inputs.runner_assets_only && needs.runner_release_request.result == 'success' name: Release daemon (${{ matrix.target }}) permissions: contents: read strategy: fail-fast: false matrix: - include: - - target: darwin-arm64 - runner: macos-15 - - target: darwin-x64 - runner: macos-15-intel + include: ${{ fromJSON(inputs.portable_linux_only && '[{"target":"linux-x64","runner":"ubuntu-latest"}]' || '[{"target":"darwin-arm64","runner":"macos-15"},{"target":"darwin-x64","runner":"macos-15-intel"},{"target":"linux-x64","runner":"ubuntu-latest"}]') }} runs-on: ${{ matrix.runner }} timeout-minutes: 30 steps: @@ -470,19 +485,37 @@ jobs: working-directory: packages/paperclip-runner env: SOURCE_SHA: ${{ inputs.ref }} + TARGET: ${{ matrix.target }} run: | set -euo pipefail [[ "$SOURCE_SHA" =~ ^[a-f0-9]{40}$ ]] test "$(git rev-parse HEAD)" = "$SOURCE_SHA" rustup show - cargo build --release --manifest-path runner/Cargo.toml --locked -p paperclip-runner-core --bin paperclip-runnerd + if [[ "$TARGET" == linux-x64 ]]; then + # npm hosts follow Node's Linux floor, not this image's glibc. + # Build a static daemon; recording independently rejects dynamic ELF. + sudo apt-get update + sudo apt-get install -y --no-install-recommends musl-tools cmake + rustup target add x86_64-unknown-linux-musl + CC_x86_64_unknown_linux_musl=musl-gcc \ + CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER=musl-gcc \ + RUSTFLAGS='-C target-feature=+crt-static' \ + cargo build --release --manifest-path runner/Cargo.toml --locked \ + --target x86_64-unknown-linux-musl -p paperclip-runner-core --bin paperclip-runnerd + else + cargo build --release --manifest-path runner/Cargo.toml --locked -p paperclip-runner-core --bin paperclip-runnerd + fi - name: Record native architecture, checksum and executable metadata env: SOURCE_SHA: ${{ inputs.ref }} TARGET: ${{ matrix.target }} run: | + binary="$GITHUB_WORKSPACE/packages/paperclip-runner/runner/target/release/paperclip-runnerd" + if [[ "$TARGET" == linux-x64 ]]; then + binary="$GITHUB_WORKSPACE/packages/paperclip-runner/runner/target/x86_64-unknown-linux-musl/release/paperclip-runnerd" + fi node scripts/release-runner-artifacts.mjs record-binary "$SOURCE_SHA" "$TARGET" \ - "$GITHUB_WORKSPACE/packages/paperclip-runner/runner/target/release/paperclip-runnerd" \ + "$binary" \ "$RUNNER_TEMP/runner-release/$TARGET" - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 with: @@ -493,8 +526,9 @@ jobs: runner_release_pack: needs: runner_release_request - if: inputs.runner_assets_only - name: Actual release image Linux daemon and provider-pack identity + if: >- + !cancelled() && inputs.runner_assets_only && !inputs.portable_linux_only && needs.runner_release_request.result == 'success' + name: Actual release image provider-pack identity and Docker daemon readiness permissions: contents: read runs-on: ubuntu-latest @@ -545,7 +579,7 @@ jobs: test "$(docker inspect --format '{{.State.ExitCode}}' "$owner")" = 0 node scripts/release-runner-artifacts.mjs record-image-binary "$SOURCE_SHA" \ "$RUNNER_TEMP/runner-release-input/paperclip-runnerd" "$RUNNER_TEMP/runner-release-input/daemon-metadata.json" \ - "$RUNNER_TEMP/runner-release-input/image.json" "$RUNNER_TEMP/runner-release/linux-x64" + "$RUNNER_TEMP/runner-release-input/image.json" "$RUNNER_TEMP/runner-release-input/image-linux-x64" node scripts/release-runner-artifacts.mjs record-pack "$SOURCE_SHA" \ "$RUNNER_TEMP/runner-release-input/provider-pack.json" "$RUNNER_TEMP/runner-release-input/image.json" \ "$RUNNER_TEMP/runner-release/provider-pack" @@ -557,7 +591,9 @@ jobs: retention-days: 7 runner_release_assemble: - if: inputs.runner_assets_only + if: >- + !cancelled() && inputs.runner_assets_only && !inputs.portable_linux_only && + needs.runner_release_binaries.result == 'success' && needs.runner_release_pack.result == 'success' name: Assemble verified release runner data needs: [runner_release_binaries, runner_release_pack] permissions: @@ -602,7 +638,8 @@ jobs: retention-days: 7 runner_release_request: - if: inputs.runner_assets_only + if: >- + !cancelled() && (inputs.runner_assets_only || inputs.portable_linux_only) name: Validate immutable runner producer inputs permissions: {} runs-on: ubuntu-latest @@ -611,6 +648,11 @@ jobs: - name: Reject mutable sources before any producer checkout env: SOURCE_SHA: ${{ inputs.ref }} + RUNNER_ASSETS_ONLY: ${{ inputs.runner_assets_only }} + PORTABLE_LINUX_ONLY: ${{ inputs.portable_linux_only }} run: | set -euo pipefail [[ "$SOURCE_SHA" =~ ^[a-f0-9]{40}$ ]] + if [[ "$PORTABLE_LINUX_ONLY" == true ]]; then + test "$RUNNER_ASSETS_ONLY" = true + fi diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a03c60e3b96..685bf21c294 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1698,7 +1698,9 @@ jobs: release_runner_assets: needs: pin_runner_release_source - if: needs.pin_runner_release_source.outputs.required == 'true' + if: >- + !cancelled() && needs.pin_runner_release_source.result == 'success' && + needs.pin_runner_release_source.outputs.required == 'true' permissions: contents: read uses: ./.github/workflows/release-verify.yml diff --git a/doc/plans/2026-10-06-default-agent-runner.md b/doc/plans/2026-10-06-default-agent-runner.md index d6837b2256f..4d6a798b19e 100644 --- a/doc/plans/2026-10-06-default-agent-runner.md +++ b/doc/plans/2026-10-06-default-agent-runner.md @@ -43,13 +43,16 @@ The large execution and setup changes stay in the later slices. | Gate | Status | Evidence | | --- | --- | --- | | Preserve original implementation | Passed | Original branch and commit above | -| Extract only first-slice behavior | Passed | 30 files; separate branch; independent packaging/release review | +| Extract only first-slice behavior | Passed | 31 files; separate branch; independent packaging/release review | | Installer and packaging tests | Passed | Existing installer suite: 26 tests; existing packaging suite: 24 tests | | Login and transport controls | Passed | Login: 13/13; focused Codex/transport selection: 21 passed, 185 outside the focused filter | | Release-transfer controls | Passed | Release workflow, transfer, and sandbox suites: 38/38; actionlint and Node/shell syntax checks passed | | Token gates | Passed | All three commands in `check:token-gates` passed | | Package and module contracts | Passed | Release package manifest and feature module boundary checks passed | -| Clean installed Codex version probe | Hosted qualification | Existing Linux npm consumer sandbox in the linked PR checks | +| Clean installed Codex version probe | Passed on initial candidate; final-head rerun required | Existing Linux npm consumer sandbox resolved and launched Codex 0.160.0, preserved consumer hooks, and made no provider calls | +| Initial hosted checks | 46 passed; one fixture timeout repaired | Candidate `6e5e20379449cfdfbd6ca5f6043492f91e698b62`; real issue-route bootstrap moved to a bounded suite hook, original agent denials unchanged, board control added; 3/3 local cases passed | +| Release review fixes | Local checks passed; hosted producer pending | Explicit status guards preserve release assembly with skipped lanes; static musl npm Linux daemon; 32/32 focused checks and original-source portability rejection control | +| Portable Linux producer | Hosted qualification | One bounded Linux-only dispatch of the existing release verifier; no local Rust/Docker build, providers, image build, or publication | | Full checks and fresh review | Hosted qualification | Require green checks and fresh 5/5 review on the linked PR's final head | | All-harness live onboarding and cloud qualification | Deferred | Owned by later slices; prior evidence does not prove this revision | @@ -58,6 +61,12 @@ No provider-backed runs or new disposable environments are needed for this slice. The original $250 cost ceiling and cleanup obligations still apply. Existing login credentials and running user previews must remain untouched. +The initial clean-install CI job checked out the candidate-equivalent merge tree +at `296097827eeb4005950134ec7f10ce4022706ef8`, then the normal release workflow +generated a lock-only producer commit at `3e1df4472b56f04ecb029008e47cd276afdb5c6d`. +The installed verifier reports that producer stamp. This is distinct from the +product source candidate; no lockfile is committed to this PR. + Focused test commands use Node 24 and a single worker: `node --test --test-concurrency=1 scripts/acpx-patch-packaging.test.mjs` and, from `cli/`, `node ../node_modules/vitest/vitest.mjs run src/__tests__/install-command.test.ts diff --git a/packages/paperclip-runner/README.md b/packages/paperclip-runner/README.md index b6c9fc3b491..2c0c3f5ebb4 100644 --- a/packages/paperclip-runner/README.md +++ b/packages/paperclip-runner/README.md @@ -72,6 +72,13 @@ pinned package version and host architecture. Release assembly also checks the source revision and runner binary identities before publication. This packaging does not change agent defaults or the selected runner of an existing agent. +The npm Linux daemon is built for `x86_64-unknown-linux-musl` with static linking. +Release validation rejects an ELF interpreter or required shared libraries, then +the native producer executes the bounded build-metadata check. The Docker image +keeps its GNU daemon. Its provider-pack identity remains tied to that exact source +and image; it does not supply the npm host daemon. The existing release verifier +offers a provider-free portable Linux check without image builds or publication. + Every ACPX harness accepts an explicit caller-selected model without a Paperclip model allowlist. The adapter sends that ID unchanged and verifies the provider's effective model before prompting. An incomplete discovery catalog does not block diff --git a/packages/paperclip-runner/scripts/release-provider-pack.test.mjs b/packages/paperclip-runner/scripts/release-provider-pack.test.mjs index bba8b7f8687..d5133f13057 100644 --- a/packages/paperclip-runner/scripts/release-provider-pack.test.mjs +++ b/packages/paperclip-runner/scripts/release-provider-pack.test.mjs @@ -9,7 +9,7 @@ import test from "node:test"; import profiles from "../acpx-profiles.json" with { type: "json" }; import distributions from "../cursor-distributions.json" with { type: "json" }; import { verifyReleaseProviderPack } from "./release-provider-pack.mjs"; -import { makeRunnerReleaseArchive, readRunnerReleaseArchive, verifyReleaseDaemonMetadata, verifyRunnerReleaseData } from "../../../scripts/release-runner-artifacts.mjs"; +import { makeRunnerReleaseArchive, readRunnerReleaseArchive, verifyPortableLinuxDaemon, verifyReleaseDaemonMetadata, verifyRunnerReleaseData } from "../../../scripts/release-runner-artifacts.mjs"; import { gzipSync, gunzipSync } from "node:zlib"; const revision = "a".repeat(40); @@ -46,12 +46,43 @@ test('release daemon compatibility rejects lookalikes, incompatible contracts an ]) assert.throws(() => verifyReleaseDaemonMetadata({ ...daemonMetadata(), ...mismatch })); }); +function linuxElf(types = [1]) { + const bytes = Buffer.alloc(64 + types.length * 56 + 32); + bytes.set([0x7f, 0x45, 0x4c, 0x46, 2, 1, 1]); + bytes.writeUInt16LE(3, 16); bytes.writeUInt16LE(62, 18); bytes.writeUInt32LE(1, 20); + bytes.writeBigUInt64LE(64n, 32); bytes.writeUInt16LE(64, 52); bytes.writeUInt16LE(56, 54); + bytes.writeUInt16LE(types.length, 56); + for (const [index, type] of types.entries()) { + const header = 64 + index * 56; + bytes.writeUInt32LE(type, header); bytes.writeUInt32LE(5, header + 4); + if (type === 2) { + bytes.writeBigUInt64LE(BigInt(64 + types.length * 56), header + 8); + bytes.writeBigUInt64LE(32n, header + 32); + } + } + return bytes; +} + +test('portable Linux release daemons reject interpreters, shared libraries and malformed static ELF claims', () => { + assert.deepEqual(verifyPortableLinuxDaemon(linuxElf()), { buildTarget: 'x86_64-unknown-linux-musl', linkage: 'static' }); + assert.equal(verifyPortableLinuxDaemon(linuxElf([1, 2])).linkage, 'static', 'Static PIE may retain its own terminated relocation table'); + assert.throws(() => verifyPortableLinuxDaemon(linuxElf([1, 3])), /libc interpreter/); + const dynamic = linuxElf([1, 2]); dynamic.writeBigUInt64LE(1n, 176); + assert.throws(() => verifyPortableLinuxDaemon(dynamic), /shared library/); + const truncated = linuxElf().subarray(0, 64); + assert.throws(() => verifyPortableLinuxDaemon(truncated), /invalid program table/); + const overflow = linuxElf(); overflow.writeBigUInt64LE(2n ** 63n, 32); + assert.throws(() => verifyPortableLinuxDaemon(overflow), /invalid program table/); + assert.throws(() => verifyPortableLinuxDaemon(linuxElf([2])), /executable load/); + const unterminated = linuxElf([1, 2]); unterminated.writeBigUInt64LE(7n, 176); unterminated.writeBigUInt64LE(7n, 192); + assert.throws(() => verifyPortableLinuxDaemon(unterminated), /unterminated dynamic table/); +}); + function releaseData() { const files = new Map(), platforms = {}; for (const target of ["darwin-arm64", "darwin-x64", "linux-x64"]) { - const bytes = Buffer.alloc(64); - if (target === "linux-x64") { bytes.set([0x7f, 0x45, 0x4c, 0x46, 2, 1]); bytes.writeUInt16LE(62, 18); } - else { bytes.writeUInt32LE(0xfeedfacf, 0); bytes.writeUInt32LE(target === "darwin-arm64" ? 0x0100000c : 0x01000007, 4); } + const bytes = target === 'linux-x64' ? linuxElf() : Buffer.alloc(64); + if (target !== 'linux-x64') { bytes.writeUInt32LE(0xfeedfacf, 0); bytes.writeUInt32LE(target === "darwin-arm64" ? 0x0100000c : 0x01000007, 4); } files.set(`bin/${target}/paperclip-runnerd`, bytes); platforms[target] = { path: `${target}/paperclip-runnerd`, sha256: `sha256:${createHash("sha256").update(bytes).digest("hex")}` }; } @@ -63,7 +94,7 @@ function releaseData() { sourcePins: { profiles: `sha256:${createHash("sha256").update(readFileSync(new URL('../acpx-profiles.json', import.meta.url))).digest('hex')}`, distributions: `sha256:${createHash("sha256").update(readFileSync(new URL('../cursor-distributions.json', import.meta.url))).digest('hex')}` }, providerImage: { sourceRevision: revision, platform: "linux/amd64", imageId: digest }, - linuxDaemonImage: { sourceRevision: revision, platform: "linux/amd64", imageId: digest }, + linuxDaemon: { sourceRevision: revision, buildTarget: 'x86_64-unknown-linux-musl', linkage: 'static' }, daemonMetadata: Object.fromEntries(Object.keys(platforms).map(target => [target, daemonMetadata()])), files: Object.fromEntries([...files].map(([path, bytes]) => [path, `sha256:${createHash("sha256").update(bytes).digest("hex")}`])) }))); return files; @@ -163,9 +194,20 @@ test("release data rejects rehashed wrong targets and provider-image provenance" incompatible.set('assembly-receipt.json', Buffer.from(JSON.stringify(incompatibleReceipt))); assert.throws(() => verifyRunnerReleaseData(incompatible, revision), /Incompatible daemon nativeExecutionVersion/); const mixed = releaseData(), mixedReceipt = JSON.parse(mixed.get('assembly-receipt.json')); - mixedReceipt.linuxDaemonImage.imageId = `sha256:${'c'.repeat(64)}`; + mixedReceipt.linuxDaemon.sourceRevision = 'c'.repeat(40); mixed.set('assembly-receipt.json', Buffer.from(JSON.stringify(mixedReceipt))); - assert.throws(() => verifyRunnerReleaseData(mixed, revision), /same verified image/); + assert.throws(() => verifyRunnerReleaseData(mixed, revision), /portable exact-source/); + const unportable = releaseData(), executable = linuxElf([1, 3]); + unportable.set('bin/linux-x64/paperclip-runnerd', executable); + const manifest = JSON.parse(unportable.get('bin/release-manifest.json')); + const unportableReceipt = JSON.parse(unportable.get('assembly-receipt.json')); + const hash = `sha256:${createHash('sha256').update(executable).digest('hex')}`; + manifest.platforms['linux-x64'].sha256 = hash; + unportableReceipt.files['bin/linux-x64/paperclip-runnerd'] = hash; + unportable.set('bin/release-manifest.json', Buffer.from(JSON.stringify(manifest))); + unportableReceipt.files['bin/release-manifest.json'] = `sha256:${createHash('sha256').update(unportable.get('bin/release-manifest.json')).digest('hex')}`; + unportable.set('assembly-receipt.json', Buffer.from(JSON.stringify(unportableReceipt))); + assert.throws(() => verifyRunnerReleaseData(unportable, revision), /libc interpreter/, 'Rehashed GNU binary must not inherit a static claim'); }); test("release transfer binds qualification JSON snapshots to the selected source", () => { diff --git a/scripts/__tests__/release-verify-workflow.test.mjs b/scripts/__tests__/release-verify-workflow.test.mjs index 71df7871ce3..5527e69f6fd 100644 --- a/scripts/__tests__/release-verify-workflow.test.mjs +++ b/scripts/__tests__/release-verify-workflow.test.mjs @@ -21,24 +21,36 @@ function job(workflow, name) { function condition(block, needs, github = {}, inputs = {}, isCancelled = false) { const expression = block.match(/ if: >-\n((?: .+\n)+)/)?.[1]?.trim(); assert.ok(expression, 'Routing must use an explicit condition, including skipped ancestors'); - return Function('needs', 'github', 'inputs', 'cancelled', `return (${expression})`)(needs, github, inputs, () => isCancelled); + assert.match(expression, /!cancelled\(\)/, 'Suppress implicit success() from unrelated skipped ancestors'); + return Boolean(Function('needs', 'github', 'inputs', 'cancelled', `return (${expression})`)(needs, github, inputs, () => isCancelled)); } test('release producer mode validates immutable data inputs and adds only the missing native target jobs', () => { const workflow = readWorkflow('release-verify.yml'); assert.match(workflow, /runner_assets_only:[\s\S]*?default: false/); + const dispatch = workflow.split(' workflow_dispatch:\n')[1].split(' workflow_call:\n')[0]; + const call = workflow.split(' workflow_call:\n')[1].split('\n# Caller-provided')[0]; + assert.match(dispatch, /portable_linux_only:[\s\S]*?default: true/); + assert.match(dispatch, /runner_assets_only:[\s\S]*?default: true/); + assert.match(call, /portable_linux_only:[\s\S]*?default: false/); for (const name of ['runner_chaos_evals', 'typecheck', 'general_tests', 'serialized_tests', 'runner_workflow_evals', 'verify_paperclip_runner', 'build']) { // The default source gate keeps all its prior checks. Producer-only mode // must not create a second broad suite or repeat paid eval authorization. - assert.match(job(workflow, name), /if: \$\{\{ !inputs\.runner_assets_only \}\}/, name); + assert.match(job(workflow, name), /if: \$\{\{ !inputs\.runner_assets_only && !inputs\.portable_linux_only \}\}/, name); } const request = job(workflow, 'runner_release_request'); assert.doesNotMatch(request, /uses: actions\/checkout|secrets\./); + assert.equal(condition(request, {}, {}, { runner_assets_only: true }), true); + assert.equal(condition(request, {}, {}, { runner_assets_only: false }), false); + assert.equal(condition(request, {}, {}, { runner_assets_only: true }, true), false); const validation = request.split(' run: |\n')[1]; assert.ok(validation); const source = 'a'.repeat(40); - for (const [SOURCE_SHA, expected] of [[source, 0], ['master', 1], ['', 1]]) { - const result = spawnSync('bash', ['-c', validation], { env: { ...process.env, SOURCE_SHA }, encoding: 'utf8' }); + for (const [SOURCE_SHA, RUNNER_ASSETS_ONLY, PORTABLE_LINUX_ONLY, expected] of [ + [source, 'true', 'true', 0], [source, 'true', 'false', 0], [source, 'false', 'true', 1], + ['master', 'true', 'true', 1], ['', 'true', 'true', 1], + ]) { + const result = spawnSync('bash', ['-c', validation], { env: { ...process.env, SOURCE_SHA, RUNNER_ASSETS_ONLY, PORTABLE_LINUX_ONLY }, encoding: 'utf8' }); assert.equal(result.status, expected, result.stderr); } for (const name of ['runner_release_binaries', 'runner_release_pack']) { @@ -47,10 +59,37 @@ test('release producer mode validates immutable data inputs and adds only the mi assert.match(producer, /contents: read/); assert.doesNotMatch(producer, /secrets\.|contents: write|id-token: write|packages: write|--push|--password/); assert.match(producer, /test "\$\(git rev-parse HEAD\)" = "\$SOURCE_SHA"/); + const ready = { runner_release_request: { result: 'success' }, unrelated_lane: { result: 'skipped' } }; + assert.equal(condition(producer, ready, {}, { runner_assets_only: true }), true, name); + assert.equal(condition(producer, ready, {}, { runner_assets_only: false }), false, name); + assert.equal(condition(producer, ready, {}, { runner_assets_only: true }, true), false, name); + assert.equal(condition(producer, ready, { event_name: 'workflow_dispatch' }, { runner_assets_only: true, portable_linux_only: false }), true, `${name}/manual release caller`); + assert.equal(condition(producer, ready, {}, { runner_assets_only: true, portable_linux_only: true }), name === 'runner_release_binaries', `${name}/portable only`); + for (const result of ['failure', 'cancelled', 'skipped']) { + assert.equal(condition(producer, { ...ready, runner_release_request: { result } }, {}, { runner_assets_only: true }), false, `${name}/${result}`); + } + } + const assemble = job(workflow, 'runner_release_assemble'); + const produced = { runner_release_binaries: { result: 'success' }, runner_release_pack: { result: 'success' }, unrelated_lane: { result: 'skipped' } }; + assert.equal(condition(assemble, produced, {}, { runner_assets_only: true }), true); + assert.equal(condition(assemble, produced, {}, { runner_assets_only: false }), false); + assert.equal(condition(assemble, produced, {}, { runner_assets_only: true }, true), false); + assert.equal(condition(assemble, produced, {}, { runner_assets_only: true, portable_linux_only: true }), false, 'Portable-only check has no assembler or publisher'); + for (const name of ['runner_release_binaries', 'runner_release_pack']) for (const result of ['failure', 'cancelled', 'skipped']) { + assert.equal(condition(assemble, { ...produced, [name]: { result } }, {}, { runner_assets_only: true }), false, `${name}/${result}`); } const binaries = job(workflow, 'runner_release_binaries'); - assert.deepEqual([...binaries.matchAll(/- target: (.+)/g)].map(match => match[1]), ['darwin-arm64', 'darwin-x64']); + const matrix = binaries.match(/include: \$\{\{ fromJSON\(inputs\.portable_linux_only && '([^']+)' \|\| '([^']+)'\) \}\}/); + assert.ok(matrix, 'Use the same producer with explicit portable-only target selection'); + assert.deepEqual(JSON.parse(matrix[1]), [{ target: 'linux-x64', runner: 'ubuntu-latest' }]); + assert.deepEqual(JSON.parse(matrix[2]), [{ target: 'darwin-arm64', runner: 'macos-15' }, { target: 'darwin-x64', runner: 'macos-15-intel' }, { target: 'linux-x64', runner: 'ubuntu-latest' }]); assert.match(binaries, /cargo build --release.*--locked/); + assert.match(binaries, /rustup target add x86_64-unknown-linux-musl/); + assert.match(binaries, /musl-tools cmake/); + assert.match(binaries, /CC_x86_64_unknown_linux_musl=musl-gcc/); + assert.match(binaries, /RUSTFLAGS='-C target-feature=\+crt-static'/); + assert.match(binaries, /--target x86_64-unknown-linux-musl/); + assert.match(binaries, /target\/x86_64-unknown-linux-musl\/release\/paperclip-runnerd/); assert.match(binaries, /record-binary/); const pack = job(workflow, 'runner_release_pack'); assert.doesNotMatch(pack, /docker pull|IMAGE_DIGEST/); @@ -61,6 +100,8 @@ test('release producer mode validates immutable data inputs and adds only the mi assert.match(pack, /docker cp "\$owner:\$daemon_path"/); assert.match(pack, /timeout 30s docker start --attach "\$owner"/); assert.match(pack, /record-image-binary/); + assert.match(pack, /"\$RUNNER_TEMP\/runner-release-input\/image-linux-x64"/); + assert.doesNotMatch(pack, /"\$RUNNER_TEMP\/runner-release\/linux-x64"/, 'Image GNU daemon is diagnostics, never the npm Linux payload'); assert.match(pack, /trap 'docker rm -f "\$owner"/); const helper = readFileSync(path.join(repoRoot, 'scripts/release-runner-artifacts.mjs'), 'utf8'); assert.match(helper, /stage-release-runner-binaries\.mjs/); @@ -87,6 +128,14 @@ test('channel assembly routing preserves skipped promotions and blocks incomplet assert.equal(condition(pin, stable, { event_name: 'workflow_dispatch' }), false); assert.match(pin, /git show "\$source_sha:scripts\/release\.sh" \| grep -F 'PAPERCLIP_RELEASE_RUNNER_ASSETS'/); assert.match(pin, /git cat-file -e "\$source_sha:scripts\/release-runner-artifacts\.mjs"/); + const assets = job(workflow, 'release_runner_assets'); + const pinned = { ...base(), pin_runner_release_source: { result: 'success', outputs: { required: 'true' } } }; + assert.equal(condition(assets, pinned), true, 'A verified pin must produce assets despite unrelated skipped lanes'); + assert.equal(condition(assets, pinned, {}, {}, true), false); + for (const result of ['failure', 'cancelled', 'skipped']) { + assert.equal(condition(assets, { ...pinned, pin_runner_release_source: { result, outputs: { required: 'true' } } }), false, result); + } + assert.equal(condition(assets, { ...pinned, pin_runner_release_source: { result: 'success', outputs: { required: 'false' } } }), false); const ready = { verify_canary: { result: 'success' }, select_nightly: { result: 'success', outputs: { proceed: 'true' } }, smoke_nightly: { result: 'success' }, diff --git a/scripts/release-runner-artifacts.mjs b/scripts/release-runner-artifacts.mjs index c695bf79252..aad9a51b009 100644 --- a/scripts/release-runner-artifacts.mjs +++ b/scripts/release-runner-artifacts.mjs @@ -12,6 +12,7 @@ import { verifyReleaseProviderPack } from '../packages/paperclip-runner/scripts/ const repo = resolve(dirname(fileURLToPath(import.meta.url)), '..'); export const RELEASE_RUNNER_TARGETS = ['darwin-arm64', 'darwin-x64', 'linux-x64']; +const portableLinuxBuildTarget = 'x86_64-unknown-linux-musl'; const dataPaths = [...RELEASE_RUNNER_TARGETS.map(target => `bin/${target}/paperclip-runnerd`), 'bin/release-manifest.json', 'remote-provider-packs/linux-x64/provider-pack.json']; const archivePaths = [...dataPaths, 'assembly-receipt.json']; @@ -94,6 +95,35 @@ export function verifyReleaseDaemonMetadata(metadata) { } return metadata; } +// npm hosts need not use the Docker image's libc. Validate the executable's +// actual load contract, rather than trusting a producer's static-link claim. +export function verifyPortableLinuxDaemon(bytes) { + assert.ok(bytes.length >= 64 && bytes.length <= maxBinary && runnerBinaryTarget(bytes) === 'linux-x64' + && bytes[4] === 2 && bytes[5] === 1 && bytes[6] === 1 && [2, 3].includes(bytes.readUInt16LE(16)) + && bytes.readUInt16LE(52) === 64, 'Portable Linux daemon requires a complete x64 ELF header'); + const offset = Number(bytes.readBigUInt64LE(32)), size = bytes.readUInt16LE(54), count = bytes.readUInt16LE(56); + assert.ok(Number.isSafeInteger(offset) && offset >= 64 && size === 56 && count > 0 && count <= 256 + && offset + size * count <= bytes.length, 'Portable Linux daemon has an invalid program table'); + let executableLoad = false; + for (let index = 0; index < count; index++) { + const header = offset + index * size, type = bytes.readUInt32LE(header); + assert.notEqual(type, 3, 'Portable Linux daemon cannot require a libc interpreter'); + if (type === 1 && bytes.readUInt32LE(header + 4) & 1) executableLoad = true; + if (type !== 2) continue; + const start = Number(bytes.readBigUInt64LE(header + 8)), length = Number(bytes.readBigUInt64LE(header + 32)); + assert.ok(Number.isSafeInteger(start) && Number.isSafeInteger(length) && length > 0 && length <= 1024 * 1024 + && length % 16 === 0 && start >= 64 && start + length <= bytes.length, 'Portable Linux daemon has an invalid dynamic table'); + let terminated = false; + for (let entry = start; entry < start + length; entry += 16) { + const tag = bytes.readBigUInt64LE(entry); + assert.notEqual(tag, 1n, 'Portable Linux daemon cannot require a shared library'); + if (tag === 0n) { terminated = true; break; } + } + assert.ok(terminated, 'Portable Linux daemon has an unterminated dynamic table'); + } + assert.ok(executableLoad, 'Portable Linux daemon requires an executable load segment'); + return { buildTarget: portableLinuxBuildTarget, linkage: 'static' }; +} export function verifyRunnerReleaseData(files, sourceRevision, pins = sourcePins()) { revision(sourceRevision); assert.deepEqual([...files.keys()].sort(), [...archivePaths].sort(), 'Release archive must contain exactly the known data files'); @@ -128,7 +158,8 @@ export function verifyRunnerReleaseData(files, sourceRevision, pins = sourcePins assert.match(receipt.providerImage.requestedImage, /^ghcr\.io\/paperclipai\/paperclip@sha256:[a-f0-9]{64}$/); assert.ok(receipt.providerImage.repoDigests?.includes(receipt.providerImage.requestedImage), 'Provider image digest mismatch'); } - assert.deepEqual(receipt.linuxDaemonImage, receipt.providerImage, 'Linux daemon and provider pack must come from the same verified image'); + assert.deepEqual(receipt.linuxDaemon, { sourceRevision, ...verifyPortableLinuxDaemon(files.get('bin/linux-x64/paperclip-runnerd')) }, + 'Linux npm daemon must bind the portable exact-source build'); return receipt; } @@ -198,10 +229,12 @@ async function main() { assert.ok(RELEASE_RUNNER_TARGETS.includes(target) && !extra.length); const bytes = file(binary); assert.equal(runnerBinaryTarget(bytes), target); assert.equal(`${process.platform}-${process.arch}`, target, 'Execute metadata only on the daemon native target'); + const portable = target === 'linux-x64' ? verifyPortableLinuxDaemon(bytes) : undefined; const metadata = JSON.parse(execFileSync(binary, ['--build-metadata'], { timeout: 15_000, maxBuffer: 128 * 1024 })); verifyReleaseDaemonMetadata(metadata); newDirectory(output); writeFileSync(join(output, 'paperclip-runnerd'), bytes, { mode: 0o755 }); - writeJson(join(output, 'receipt.json'), { sourceRevision, target, sha256: digest(bytes), metadata }); + writeJson(join(output, 'receipt.json'), { sourceRevision, target, sha256: digest(bytes), metadata, + ...(portable ? { linuxDaemon: { sourceRevision, ...portable } } : {}) }); } else if (mode === 'record-image-binary') { const [binary, metadataPath, imageMetadata, output, requestedImage = '', ...extra] = args; assert.equal(extra.length, 0); @@ -221,21 +254,23 @@ async function main() { } else if (mode === 'assemble') { const [artifacts, output, ...extra] = args; assert.equal(extra.length, 0); const platforms = {}, daemonMetadata = {}; - let linuxDaemonImage; + let linuxDaemon; assert.deepEqual((await import('node:fs')).readdirSync(artifacts).sort(), [...RELEASE_RUNNER_TARGETS, 'provider-pack'].sort()); for (const target of RELEASE_RUNNER_TARGETS) { const path = join(artifacts, target, 'paperclip-runnerd'), bytes = inside(artifacts, `${target}/paperclip-runnerd`); const receipt = JSON.parse(inside(artifacts, `${target}/receipt.json`, 128 * 1024)); assert.equal(receipt.sourceRevision, sourceRevision); assert.equal(receipt.target, target); daemonMetadata[target] = verifyReleaseDaemonMetadata(receipt.metadata); - if (target === 'linux-x64') linuxDaemonImage = receipt.providerImage; + if (target === 'linux-x64') { + linuxDaemon = { sourceRevision, ...verifyPortableLinuxDaemon(bytes) }; + assert.deepEqual(receipt.linuxDaemon, linuxDaemon, 'Linux producer must bind the portable exact-source build'); + } assert.equal(receipt.sha256, digest(bytes)); assert.equal(runnerBinaryTarget(bytes), target); platforms[target] = { path: resolve(path), sha256: receipt.sha256 }; } const packPath = join(artifacts, 'provider-pack/provider-pack.json'), bytes = inside(artifacts, 'provider-pack/provider-pack.json', 512 * 1024); const packReceipt = JSON.parse(inside(artifacts, 'provider-pack/receipt.json', 128 * 1024)); assert.equal(packReceipt.sourceRevision, sourceRevision); assert.equal(packReceipt.sha256, digest(bytes)); - assert.deepEqual(linuxDaemonImage, packReceipt.providerImage, 'Linux daemon and provider pack must come from the same verified image'); verifyReleaseProviderPack(JSON.parse(bytes), sourceRevision); newDirectory(output); const manifestPath = join(output, 'assembler-input.json'); @@ -247,7 +282,7 @@ async function main() { const pins = sourcePins(); const receipt = { schema: 'paperclip.runner.release-assembly.v1', sourceRevision, sourcePins: { profiles: digest(pins.profiles), distributions: digest(pins.distributions) }, daemonMetadata, - providerImage: packReceipt.providerImage, linuxDaemonImage, files: Object.fromEntries([...files].map(([path, bytes]) => [path, digest(bytes)])) }; + providerImage: packReceipt.providerImage, linuxDaemon, files: Object.fromEntries([...files].map(([path, bytes]) => [path, digest(bytes)])) }; files.set('assembly-receipt.json', Buffer.from(JSON.stringify(receipt, null, 2) + '\n')); const archive = makeRunnerReleaseArchive(files, sourceRevision); writeFileSync(join(output, 'runner-release-assets.tar.gz'), archive);