diff --git a/.github/workflows/openclaw-build-test.yml b/.github/workflows/openclaw-build-test.yml new file mode 100644 index 000000000000..922443249a85 --- /dev/null +++ b/.github/workflows/openclaw-build-test.yml @@ -0,0 +1,342 @@ +name: P6 native Linux x64 AOT compilers + +on: + workflow_dispatch: + inputs: + mode: + description: P6 compiler, application, same-host comparison, or Teams follow-on + type: choice + default: compiler + options: + - compiler + - app + - benchmark + - teams + app_variants: + description: Application variants (Teams requires explicit js-c2 or ts) + type: choice + default: all + options: + - all + - js-c2 + - ts + app_run_id: + description: Completed originating app run ID (benchmark or Teams) + type: string + app_run_attempt: + description: Exact originating app run attempt + type: string + app_workflow_head: + description: Exact originating app workflow commit + type: string + app_workflow_id: + description: Exact originating app workflow ID + type: string + app_repository_id: + description: Exact originating repository ID + type: string + app_artifact_id: + description: Exact originating app artifact ID + type: string + app_artifact_name: + description: Exact originating app artifact name + type: string + app_zip_sha256: + description: Exact originating artifact ZIP SHA256 + type: string + app_zip_bytes: + description: Exact originating artifact ZIP byte count + type: string + +permissions: + contents: read + +concurrency: + group: p6-native-linux-x64-compilers + cancel-in-progress: false + +jobs: + linux-x64: + if: github.repository == 'openclaw/bun' && github.ref == 'refs/heads/openclaw/aot-rd-P6' && (inputs.mode == 'compiler' || inputs.mode == '') + runs-on: blacksmith-32vcpu-ubuntu-2404 + timeout-minutes: 240 + defaults: + run: + shell: bash + steps: + - name: Establish work deadline + run: | + { + echo "P6_DEADLINE_EPOCH=$(( $(date +%s) + 12600 ))" + echo "P6_WORK=$RUNNER_TEMP/p6-aot-$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT" + echo "P6_CONTAINER=p6-aot-$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT" + } >> "$GITHUB_ENV" + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + sparse-checkout: scripts/openclaw-p6 + - name: Stage exact source and bootstrap native Docker toolchain + run: | + mkdir -p "$P6_WORK" + bash scripts/openclaw-p6/host.sh bootstrap + - name: Build and preserve standard compiler + id: build_standard + run: bash scripts/openclaw-p6/host.sh cb-standard + - name: Export standard compiler + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: p6-linux-x64-standard-${{ github.sha }}-attempt${{ github.run_attempt }} + path: ${{ env.P6_WORK }}/data/rd150c-x64-highmem-deadline-v1/preserved-cb-standard/ + if-no-files-found: error + compression-level: 0 + retention-days: 7 + - name: Build and preserve physical ShadowRealm-off compiler + id: build_shadowrealm_off + run: bash scripts/openclaw-p6/host.sh cb-compat + - name: Export ShadowRealm-off compiler + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: p6-linux-x64-shadowrealm-off-${{ github.sha }}-attempt${{ github.run_attempt }} + path: ${{ env.P6_WORK }}/data/rd150c-x64-highmem-deadline-v1/preserved-cb-compat/ + if-no-files-found: error + compression-level: 0 + retention-days: 7 + - name: Stop and remove owned container + if: always() + run: bash scripts/openclaw-p6/host.sh cleanup + - name: Export UNQUALIFIED FAILED standard compiler diagnostics + if: failure() && steps.build_standard.outcome == 'failure' + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: p6-linux-x64-UNQUALIFIED-FAILED-standard-${{ github.sha }}-attempt${{ github.run_attempt }} + path: | + ${{ env.P6_WORK }}/data/rd150c-x64-highmem-deadline-v1/build-standard/bun + ${{ env.P6_WORK }}/data/rd150c-x64-highmem-deadline-v1/build-standard/configure.json + if-no-files-found: warn + compression-level: 0 + retention-days: 7 + - name: Export UNQUALIFIED FAILED ShadowRealm-off compiler diagnostics + if: failure() && steps.build_shadowrealm_off.outcome == 'failure' + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: p6-linux-x64-UNQUALIFIED-FAILED-shadowrealm-off-${{ github.sha }}-attempt${{ github.run_attempt }} + path: | + ${{ env.P6_WORK }}/data/rd150c-x64-highmem-deadline-v1/build-c2/bun + ${{ env.P6_WORK }}/data/rd150c-x64-highmem-deadline-v1/build-c2/configure.json + if-no-files-found: warn + compression-level: 0 + retention-days: 7 + - name: Export compiler receipts, including failures + if: always() + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: p6-linux-x64-receipts-${{ github.sha }}-attempt${{ github.run_attempt }} + path: | + ${{ env.P6_WORK }}/data/proof/ + ${{ env.P6_WORK }}/data/rd150c-x64-highmem-deadline-v1/receipts/ + ${{ env.P6_WORK }}/data/rd150c-x64-highmem-deadline-v1/source-ready.json + ${{ env.P6_WORK }}/data/rd150c-x64-highmem-deadline-v1/raw-cb-*/ + ${{ env.P6_WORK }}/container-final.json + ${{ env.P6_WORK }}/containers-after-cleanup.txt + if-no-files-found: warn + compression-level: 0 + retention-days: 7 + linux-x64-app: + if: github.repository == 'openclaw/bun' && github.ref == 'refs/heads/openclaw/aot-rd-P6' && inputs.mode == 'app' + runs-on: blacksmith-32vcpu-ubuntu-2404 + timeout-minutes: 240 + permissions: + contents: read + actions: read + env: + P6_APP_VARIANTS: ${{ inputs.app_variants }} + defaults: + run: + shell: bash + steps: + - name: Establish bounded application work deadline + run: | + { + echo "P6_DEADLINE_EPOCH=$(( $(date +%s) + 13800 ))" + echo "P6_WORK=$RUNNER_TEMP/p6-app-$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT" + echo "P6_CONTAINER=p6-app-$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT" + } >> "$GITHUB_ENV" + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + sparse-checkout: scripts/openclaw-p6 + - name: Initialize isolated native x64 application container + run: bash scripts/openclaw-p6/app/host.sh bootstrap + - name: Import the exact verified compiler pair + env: + GH_TOKEN: ${{ github.token }} + run: python3 -B scripts/openclaw-p6/app/download.py + - name: Prepare fresh frozen source, dependencies, dist and plugins + id: prepare + run: bash scripts/openclaw-p6/app/host.sh prepare + - name: Activate execution-bound encrypted task paging + id: paging + run: bash scripts/openclaw-p6/app/host.sh paging + - name: Build and qualify JS AOT + if: steps.prepare.outcome == 'success' && steps.paging.outcome == 'success' && !cancelled() && inputs.app_variants != 'ts' + id: js + continue-on-error: true + run: bash scripts/openclaw-p6/app/host.sh variant js + - name: Build and qualify physical ShadowRealm-off C2 AOT + if: steps.prepare.outcome == 'success' && steps.paging.outcome == 'success' && !cancelled() && inputs.app_variants != 'ts' + id: c2 + continue-on-error: true + run: bash scripts/openclaw-p6/app/host.sh variant c2-off + - name: Build and qualify TypeScript source AOT + if: steps.prepare.outcome == 'success' && steps.paging.outcome == 'success' && !cancelled() && inputs.app_variants != 'js-c2' + id: ts + continue-on-error: true + run: bash scripts/openclaw-p6/app/host.sh variant ts + - name: Attempt actual application guest MDWE on the available native KVM device + if: steps.prepare.outcome == 'success' && steps.paging.outcome == 'success' && !cancelled() && inputs.app_variants != 'ts' + continue-on-error: true + run: bash scripts/openclaw-p6/app/host.sh guest + - name: Stop owned workloads and remove encrypted task paging + if: always() + run: bash scripts/openclaw-p6/app/host.sh cleanup + - name: Select explicit application artifacts and synthetic receipts + if: always() + run: sudo -n env -i PATH=/usr/bin:/bin P6_WORK="$P6_WORK" python3 -B scripts/openclaw-p6/app/export.py + - name: Export bounded application attempt + if: always() + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: p6-linux-x64-app-${{ github.sha }}-attempt${{ github.run_attempt }} + path: ${{ env.P6_WORK }}/export/ + if-no-files-found: error + compression-level: 0 + retention-days: 7 + - name: Require completed requested variants + if: always() + run: python3 -B scripts/openclaw-p6/app/export.py --require-complete + linux-x64-benchmark: + if: github.repository == 'openclaw/bun' && github.ref == 'refs/heads/openclaw/aot-rd-P6' && inputs.mode == 'benchmark' + runs-on: blacksmith-32vcpu-ubuntu-2404 + timeout-minutes: 240 + permissions: + contents: read + actions: read + defaults: + run: + shell: bash + env: + P6_EXECUTION_MODE: benchmark + steps: + - name: Establish bounded benchmark work deadline + run: | + { + echo "P6_DEADLINE_EPOCH=$(( $(date +%s) + 13800 ))" + echo "P6_WORK=$RUNNER_TEMP/p6-benchmark-$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT" + echo "P6_CONTAINER=p6-benchmark-$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT" + } >> "$GITHUB_ENV" + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + sparse-checkout: scripts/openclaw-p6 + - name: Bind exact completed app attempt and artifact + env: + P6_APP_RUN_ID: ${{ inputs.app_run_id }} + P6_APP_RUN_ATTEMPT: ${{ inputs.app_run_attempt }} + P6_APP_WORKFLOW_HEAD: ${{ inputs.app_workflow_head }} + P6_APP_WORKFLOW_ID: ${{ inputs.app_workflow_id }} + P6_APP_REPOSITORY_ID: ${{ inputs.app_repository_id }} + P6_APP_ARTIFACT_ID: ${{ inputs.app_artifact_id }} + P6_APP_ARTIFACT_NAME: ${{ inputs.app_artifact_name }} + P6_APP_ZIP_SHA256: ${{ inputs.app_zip_sha256 }} + P6_APP_ZIP_BYTES: ${{ inputs.app_zip_bytes }} + run: python3 -B scripts/openclaw-p6/app/benchmark/initialize.py inputs + - name: Download exact compiler pair and completed app artifact + env: + GH_TOKEN: ${{ github.token }} + run: python3 -B scripts/openclaw-p6/app/benchmark/host.py download + - name: Initialize fresh native x64 benchmark container without paging + run: python3 -B scripts/openclaw-p6/app/benchmark/host.py bootstrap + - name: Restore admitted apps and run complete selected-cell comparison + run: python3 -B scripts/openclaw-p6/app/benchmark/host.py run + - name: Stop owned benchmark workloads + if: always() + run: bash scripts/openclaw-p6/app/host.sh cleanup + - name: Select benchmark and untimed qualification evidence + if: always() + run: sudo -n env -i PATH=/usr/bin:/bin P6_WORK="$P6_WORK" python3 -B scripts/openclaw-p6/app/benchmark/export.py + - name: Export benchmark attempt including failures + if: always() + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: p6-linux-x64-benchmark-${{ github.sha }}-attempt${{ github.run_attempt }} + path: ${{ env.P6_WORK }}/benchmark-export/ + if-no-files-found: error + compression-level: 0 + retention-days: 7 + - name: Require complete comparison, backup proof and cleanup + if: always() + run: python3 -B scripts/openclaw-p6/app/benchmark/export.py --require-complete + + linux-x64-teams: + if: github.repository == 'openclaw/bun' && github.ref == 'refs/heads/openclaw/aot-rd-P6' && inputs.mode == 'teams' + runs-on: blacksmith-32vcpu-ubuntu-2404 + timeout-minutes: 100 + permissions: + contents: read + actions: read + defaults: + run: + shell: bash + env: + P6_EXECUTION_MODE: teams + P6_APP_VARIANTS: ${{ inputs.app_variants }} + steps: + - name: Establish bounded Teams work deadline + run: | + { + echo "P6_DEADLINE_EPOCH=$(( $(date +%s) + 5700 ))" + echo "P6_WORK=$RUNNER_TEMP/p6-teams-$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT" + echo "P6_CONTAINER=p6-teams-$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT" + } >> "$GITHUB_ENV" + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + sparse-checkout: scripts/openclaw-p6 + - name: Bind current Teams identity and exact completed app inputs + env: + P6_APP_RUN_ID: ${{ inputs.app_run_id }} + P6_APP_RUN_ATTEMPT: ${{ inputs.app_run_attempt }} + P6_APP_WORKFLOW_HEAD: ${{ inputs.app_workflow_head }} + P6_APP_WORKFLOW_ID: ${{ inputs.app_workflow_id }} + P6_APP_REPOSITORY_ID: ${{ inputs.app_repository_id }} + P6_APP_ARTIFACT_ID: ${{ inputs.app_artifact_id }} + P6_APP_ARTIFACT_NAME: ${{ inputs.app_artifact_name }} + P6_APP_ZIP_SHA256: ${{ inputs.app_zip_sha256 }} + P6_APP_ZIP_BYTES: ${{ inputs.app_zip_bytes }} + run: python3 -B scripts/openclaw-p6/app/teams-mode/initialize.py inputs + - name: Download and verify only the originating app artifact + env: + GH_TOKEN: ${{ github.token }} + run: python3 -B scripts/openclaw-p6/app/teams-mode/host.py download + - name: Initialize isolated Teams container without paging + run: python3 -B scripts/openclaw-p6/app/teams-mode/host.py bootstrap + - name: Restore selected artifacts and run untimed Teams proof + run: python3 -B scripts/openclaw-p6/app/teams-mode/host.py run + - name: Stop and remove owned Teams workloads + if: always() + run: bash scripts/openclaw-p6/app/host.sh cleanup + - name: Select Teams evidence and failures + if: always() + run: sudo -n env -i PATH=/usr/bin:/bin P6_WORK="$P6_WORK" python3 -B scripts/openclaw-p6/app/teams-mode/export.py + - name: Export selected Teams follow-on evidence + if: always() + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: p6-linux-x64-teams-${{ github.sha }}-attempt${{ github.run_attempt }} + path: ${{ env.P6_WORK }}/teams-export/ + if-no-files-found: error + compression-level: 0 + retention-days: 7 + - name: Require selected Teams proof and cleanup + if: always() + run: python3 -B scripts/openclaw-p6/app/teams-mode/export.py --require-complete diff --git a/CHANGELOG.md b/CHANGELOG.md index bf5168acb7dd..718e79873cd5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,8 +2,17 @@ ## Unreleased +- Stop AOT qualification after a measurement timeout or signal exit while retaining ordinary failure reporting. + +- Resolve extensionless package names through runtime plugin hooks, including Plugin SDK imports from external AOT code. + +- Accept hardened GNU builds whose fortified memory copies inline, while retaining stack-protector and checked-formatting import checks. + - Cover source-less generated helper entry counters in AOT image-map regression tests. +- Recognize macOS SIGBUS when entering removed AOT code, and retain the external-script runtime when `compile.trim.allow` includes `"run"`. +- Preserve SharedArrayBuffer when a JIT-free AOT executable runs external scripts as Bun on macOS. + - Resolve literal embedded module paths against prepared AOT entry points, including TypeScript and custom output names. - Add `Bun.Terminal.pause()` and `resume()` for PTY output backpressure without blocking the event loop. diff --git a/docs/bundler/aot-size.mdx b/docs/bundler/aot-size.mdx index 54ad015177ea..77684b1b7490 100644 --- a/docs/bundler/aot-size.mdx +++ b/docs/bundler/aot-size.mdx @@ -52,6 +52,17 @@ Every size on this page is for Linux x64. Two things do use the tools: `BUN_BE_BUN=1`, and `Bun.build` with `check` or `compile.aot`. With `BUN_BE_BUN=1` the executable tells you to run `bun` instead, and exits with code `70`. A program that calls `Bun.build` keeps the type checker, the compiler and the JIT compilers, unless you pass `--trim`. `install.auto` in `bunfig.toml` has no effect, because the package manager is part of the command line. +To run external JavaScript with `BUN_BE_BUN=1`, explicitly retain `"run"` when building: + +```ts +await Bun.build({ + entrypoints: ["./app.ts"], + compile: { outfile: "./app", aot: true, trim: { allow: ["run"] } }, +}); +``` + +The compiled application still runs ahead of time. `BUN_BE_BUN=1 ./app script.cjs` runs the disk script in the interpreter. Keeping `"run"` also keeps the runtime APIs, built-in module sources and locale data that arbitrary disk scripts can use; these cannot be inferred from the compiled application. It does not retain the JIT or Bun's package manager. A JavaScript package manager such as npm can run from its own disk entry point. Disk scripts that use `bun:ffi`, including custom SQLite library loaders, also need `"jit"` in `allow`. Explicit removals still apply. + ### APIs `bun compile` reads the whole program, including dependencies. It knows which globals, which members of `Bun` and `process`, which built-in modules and which methods of built-in objects your code uses. Bun removes every feature that nothing uses. You don't list anything: a program that imports `bun:sqlite` gets SQLite, and a program that doesn't ships without it. diff --git a/scripts/build/binary-expectations.ts b/scripts/build/binary-expectations.ts index ac00b4023c52..e1c3158b638b 100644 --- a/scripts/build/binary-expectations.ts +++ b/scripts/build/binary-expectations.ts @@ -291,7 +291,8 @@ function requiredImports(cfg: Config): string[] { if (!cfg.hardened) return []; return [ "__stack_chk_fail", - ...(cfg.abi === "gnu" && cfg.release && !cfg.asan ? ["__memcpy_chk", "__snprintf_chk"] : []), + // Copies with known bounds inline even with _FORTIFY_SOURCE=2; formatted output retains its checked call. + ...(cfg.abi === "gnu" && cfg.release && !cfg.asan ? ["__snprintf_chk"] : []), ]; } diff --git a/scripts/openclaw-p6/app/README.md b/scripts/openclaw-p6/app/README.md new file mode 100644 index 000000000000..705bf542a3b3 --- /dev/null +++ b/scripts/openclaw-p6/app/README.md @@ -0,0 +1,137 @@ +# P6 native x64 application attempt + +This is a bounded qualification attempt for OpenClaw +`4fa442e332745f1f58ccedd27106abdafcf4e019` using the compiler pair from Actions +run `40214829538`, attempt 1, wrapper head +`f9fa08790bf45b3e995280f6eb249e14fd9191c1`. It never builds the compiler itself. +Both compiler artifacts must have reviewed IDs, ZIP digests, compiler digests, +transport digests and archive digests in `compiler-pins.json` before dispatch. + +The existing registered workflow defaults to compiler mode. Its app mode has +the same P6 branch guard, its own job and no dependency on the skipped compiler +job. The app job's 230-minute deadline leaves 20 minutes for workload shutdown, +paging evacuation and upload before the 240-minute job limit. Native preparation +and each JS, physical ShadowRealm-off C2 and TypeScript attempt use the existing +owners. Every build gets a fresh live paging verification. Variant timeouts and +failures stop the container before cleanup; a later variant restarts only the +same identity-labelled container after its E2E resources are gone. All +phase ceilings do not fit in the job budget. Missing/failed/skipped proof remains +unqualified and the final job check fails unless all requested phases passed. +Build and preservation are prerequisites. Runtime phase failures are collected +while later independent phases continue; owning-controller cancellation, +deadline and signal exits stop the variant. A bounded, reaped guest-test timeout +remains an ordinary failed case. Docker dependents retain their existing image-receipt guards. +Any failed phase makes the variant return nonzero. + +The container gets only the task trees, a read-only recipe, public execution +identity, the Docker client/Buildx plugin and the dedicated runner's Docker socket. The GitHub +token is used only by the host downloader and is removed on artifact redirects. +The original Docker E2E lanes create the application containers; a thin client +adapter labels created containers/networks with the actual Actions run/attempt. +Cleanup stops the app container, removes only that label's resources and verifies +their absence before paging cleanup. It never prunes the Docker host. + +`packet/payload` is a P6-derived public input projection, not a byte-identical P0 +index clone. Its selected CB11 record retains the exact source, signed status, +qualified status, executable hash and compiler facts of the private frozen +reference. That reference is historical provenance only. It supplies no Linux +application or performance qualification. The original capsule and P0 index are +unchanged; their hashes are provenance in `packet/input-projection.json`. +Unrelated CB4/CB5 history, local paths and private operational notes are excluded. +All executable owners except `runtime-controller.py` and `native-prep.py` are +unchanged from the accepted capsule. Native preparation exposes pnpm through a +task-local executable shim that runs the pinned Node and official `pnpm.mjs`, +avoiding the archive's shebang-less native placeholder. The official tarball +integrity, signed native download and Linux x64 ELF checks remain unchanged. +The runtime controller preserves terminal exit classifications +after evidence collection and uses a shorter generated guest label so C2's QMP +socket path fits Linux's 107-byte limit. The original capsule is unchanged. +The source proof +retains the exact R4 tree, all 29 required ancestors and dependency/source file +hashes; native clone, frozen install, runtime build, boundary generation and plugin +selection still run afresh. + +`export.py` is the sole upload selection owner. It copies only explicitly named +build results, synthetic runtime archives and the preservation owner's app +archives. It does not export paging backing, private paging state, approval +directories, credentials, kernel keys, source trees or dependency caches. +The summary always leaves `applicationQualified` and `shipReady` false. This job +does not provide the post-run raw-trace Worker/strict zero-disk-JS assessment, +live provider evidence, or same-machine +Node/JIT versus AOT Gateway-ready/first-turn/RSS/CPU comparison backed by a fresh +npm installation. Old N1 measurements are not current evidence. The scheduled +native zero-JS and Worker diagnostic phases preserve their raw evidence for that +assessment; a zero exit from this workflow means only its named phases completed. + +After heavy builds, the available host `/dev/kvm` is passed to the app container. +With at least 1900 seconds left before the reserve, the unchanged prerequisite +owner installs the pinned guest tools/image, then the actual-app guest +owner tests each built JS/C2 artifact while at least 950 seconds remain. Missing +KVM, prerequisites, artifact/version receipts, failures and insufficient budget +are recorded as explicit gaps. This uses native KVM only; it adds no emulated +timings. The guest phase covers the actual app's main-thread MDWE boundary, not +Gateway or Worker guest behavior. Policy analysis selects the exact admitted +`--version` or `p6-mdwe` invocation, preserving same-binary SQLite child traces +and the separate version trace. Missing or duplicate matching invocations fail; +the selected root still must satisfy the existing exit and memory-policy checks. + +The comparison follow-on consumes the exact completed app run/attempt and +artifact digest, plus the compiler pair above. The exported admissions, +build/core/controller receipts, plugin selection and projected reference facts +retain their native relative paths. On one fresh native x64 runner, recreate +the exact R4 source and canonical runtime with the existing preparation owner; +package with `scripts/package-openclaw-for-docker.mts`; install into a new prefix +using the source's exact lifecycle policy; then run the existing comparison +owner with one warmup and six alternating measured sweeps. No build-host sample +is reused. The separately prepared comparator capsule is +`46057637d4872e3660aa7ca7a2e8b5610e84da8f8ff4065fab82bb933c5c5420`; +its dedicated dispatch adapter requires separate review before execution. + +R4 uses the root freeze at `2026-10-25T22:30:39.990290+00:00`, including landed PR183822 typed resolver expression unwrapping and the later main runtime changes. Fresh frozen installation, canonical build, boundary artifacts, plugin selection and qualification are required. Prior plugin counts, worker counts and dependency caches are not qualification evidence. + +## Selected builtin and native-worker preparation gate + +Shared application and comparison preparation runs `preflight.py` immediately after +fresh plugin selection. It reuses the frozen static builtin census, actual native +namespace query, and maintained source/plugin/worker projection. Both imported +compiler profiles must pass; missing selected exports, unmapped workers and plugin +worker declarations block further work. Full-dist findings outside the selected +owner inputs remain visible diagnostics. + +`compatibility/source-binding.json` binds the reviewed R4 commit/tree, all listed +owner hashes, and the classic TypeScript6.0.3 package/entry hashes. Fresh native +preparation must match each of these facts before execution. +The unchanged input and command templates are evidence, not executable shell +strings. The runtime owner fills actual source/preparation/selection/Node/compiler +facts and checks them before and after the bounded600-second phase. It uses the +existing deadline/process-group owner, clean synthetic state, and nice10; it does +not build an application. + +`prep-receipts/compatibility/result.json` is required by application admission and +again before paging activation. Admission records its hash. Reuse requires both +successful profiles, complete command evidence and unchanged source/dist, +selection, execution identity, parser and compiler bytes. Shared benchmark +preparation uses the same gate. Named reports and failures are exported; the +preflight's HOME/tmp/cache directories are excluded. This is selected emitted-JS +and native-worker preflight, not final transformed TS/link or runtime qualification. + +## Explicit application variant selection + +`mode=app` accepts `app_variants=all` (the default), `js-c2`, or `ts`. +Each attempt records its requested variants in the execution identity. Admission +rejects unselected builds. A JS+C2 attempt finishes its normal guest, cleanup and +export phases without starting TS; only after its exact uploaded artifact is +verified should a separate TS-only attempt be considered. + +The summary lists unselected variants explicitly. `scheduledPhasesComplete` +requires every selected build/runtime phase, compatibility and cleanup to pass; +`fullVariantMatrixComplete` additionally requires all three variants. Missing or +invalid selection cannot pass. Application qualification and ship readiness stay +false until the separate required evidence exists. No runtime/security deadline +or cleanup rule changes with a smaller selection. + +The existing benchmark can consume a verified JS+C2 export with TS unavailable. +A TS-only export cannot provide its mandatory JS baseline, and binaries from +separate runs are not combined into one comparison. This splits later TS risk +from an already exported JS+C2 attempt; it does not prevent evidence loss if the +first runner itself disappears before upload. diff --git a/scripts/openclaw-p6/app/admit.py b/scripts/openclaw-p6/app/admit.py new file mode 100644 index 000000000000..73526a4c6cde --- /dev/null +++ b/scripts/openclaw-p6/app/admit.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python3 +"""Bind one prepared template to the facts produced by this native CI run.""" +import hashlib +import json +import os +from pathlib import Path +import sys +import time +from preflight import verify_completed +from selection import requested_variants + +ROOT = Path('/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1') + + +def read(path): + return json.loads(path.read_text()) + + +def sha(path): + with path.open('rb') as stream: + return hashlib.file_digest(stream, 'sha256').hexdigest() + + +def main(): + variant = sys.argv[1] + assert variant in ['js', 'c2-off', 'ts'] + execution = read(Path(os.environ['P6_WORK']) / 'execution.json') + assert variant in requested_variants(execution), 'Application variant not selected for this execution' + compatibility = verify_completed(ROOT, Path(os.environ['P6_WORK'])) + template = read(ROOT / 'admission-templates' / (variant + '.json')) + records = read(ROOT / 'admission-inputs/compiler-records.json') + assert records['status'] == 'native-compilers-adopted-not-app-admitted' + prepared = read(ROOT / 'prep-receipts/plugins/result.json') + assert prepared['status'] == 'PASS' + assert execution['identity']['repository'] == 'openclaw/bun' and execution['identity']['job'] == 'linux-x64-app' + assert execution['sourceCommit'] == template['linuxCut']['commit'] + assert compatibility['sourceCommit'] == template['linuxCut']['commit'] + remaining = int(float(os.environ['P6_DEADLINE_EPOCH']) - time.time() - 1200) + assert remaining >= 120, 'No bounded build window remains' + template['decision'] = 'build-linux' + template['nativeCompatibility'] = compatibility + template['execution'] = execution + template['referenceRole'] = 'historical-provenance-only; no current-platform qualification transfer' + template['linuxCut']['mainRefSha'] = prepared['nativeSource']['mainRefSha'] + template['distBuildInfoSha256'] = prepared['distBuildInfoSha256'] + template['compiler']['sha256'] = records[template['compiler']['profile']]['sha256'] + template['buildNode'] = {key: prepared['buildNode'][key] for key in ['path', 'sha256']} + template['pluginsSha256'] = sha(Path(template['pluginsFile'])) + template['timeoutSeconds'] = min(7200, remaining) + directory = ROOT / 'admissions' + directory.mkdir(exist_ok=True) + path = directory / (variant + '.json') + with path.open('x') as stream: + json.dump(template, stream, indent=2) + stream.write('\n') + print(sha(path)) + + +if __name__ == '__main__': + main() diff --git a/scripts/openclaw-p6/app/benchmark/INTEGRATION.md b/scripts/openclaw-p6/app/benchmark/INTEGRATION.md new file mode 100644 index 000000000000..cbebc7166186 --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/INTEGRATION.md @@ -0,0 +1,62 @@ +# Workflow integration + +`mode=benchmark` is a separate job on the existing native Linux x64 runner. Its +nine app inputs are all required by the input binder. They identify a completed +app run, exact attempt and workflow head, repository/workflow IDs, and exact +artifact ID/name/ZIP SHA256/size. An empty input or inconsistent attempt is an +error; no app run is inferred from the latest Actions row. + +The compiler and app downloads run on the host under the existing absolute +230-minute work deadline. The token exists only in the download step. The fresh +container has a read-only mount for the app import and execution identity. The +shared bootstrap keeps its default app behavior; benchmark mode skips cryptsetup +and paging, and rejects direct app build/variant phases. Native preparation still +clones, installs and builds the exact source using its existing owners. Restored +AOT artifacts must pass the accepted transport and native contract before use. + +Every measured phase runs with umask 077, a clean container environment, nice10, +and the shared deadline/process-group owner with a 1200-second reserve. An +ordinary backup failure permits the independent comparison only after the host +reconciliation check succeeds. Deadline/signal exits stop the sequence. A complete +comparison cannot turn failed backup or original qualification evidence into a +pass; the final job gate requires the new comparison, backup and cleanup receipts. +Application qualification and ship readiness remain false. + +The host quiet helper inspects the real process/container state immediately before +the complete cohort. It never invents a lease or stops unrelated work. An admitted +cohort keeps its one warmup and six measured sweeps; exit78 preserves an +insufficient-window result without shortening the experiment. +It also samples aggregate and per-process CPU activity over one second, subtracts +only the inspector's measured work, and records a noise allowance of 0.10 CPU +seconds per wall second. Competing activity, substantial I/O wait, process churn, +and invalid counters reject admission even when executable names are unfamiliar. + +The exporter selects named receipts, synthetic provider/CLI logs and measurement +outputs. It excludes installed trees, source/package copies, HOME, cache, tmp, +backup database/archive fixtures and paging material. The original app summary is +retained through availability and comparison metadata. Export and the result gate +run after cleanup even when an earlier step fails. + +Local preparation checks are synthetic only: + +``` +python3.12 -B -m unittest discover -s scripts/openclaw-p6/app/benchmark -p 'test*.py' +``` + +The accepted benchmark payload and its hash manifest are unchanged. This wrapper +adds workflow identity, host orchestration, cleanup and export; it does not supply +native execution results. + +The untimed functional phase runs a separate fresh `--knowledge-control` for +each restored AOT variant that passes the ordinary functional probe. It creates +an operator/direct session, then runs the admitted agent through `tool_search`, +`tool_describe`, and `dispatch_action`. A strict synthetic Responses provider +requires exactly four requests and consumes each actual tool output. Operator +RPC status and ontology results must match the agent's store and fingerprint. +Direct HTTP tool invocation is not used because that surface has no memory +audience. The existing core runner owns all processes and cleanup. + +Normal AOT/Node/Bun functional probes and every timed cohort omit this flag. +Knowledge failures remain in `work/knowledge-controls.json` without changing +performance availability; exported completion still requires the controls to +pass. Only named proof files and logs are exported, never state or credentials. diff --git a/scripts/openclaw-p6/app/benchmark/README.md b/scripts/openclaw-p6/app/benchmark/README.md new file mode 100644 index 000000000000..cf804301fd4e --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/README.md @@ -0,0 +1,99 @@ +# Dedicated native x64 benchmark mode + +This folder is a preparation for a later `mode=benchmark` on the already-registered P6 workflow. It does not alter or delay initial app dispatch. No native app, build, package/install, lease or GitHub write ran during preparation. The workflow/shared-bootstrap/export owner must review and integrate the files and API below. + +Use the same native x64 32 GB runner/provider as app mode, with a fresh empty ROOT and 240-minute job budget. ROOT remains `/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1`. The job consumes one explicit, **completed** app run/attempt and exact artifact. Failure of the overall app job is acceptable; each reused application cell must independently have its complete successful build, admission, original core/controller and preservation proof. No original execution result becomes a new performance sample. + +`app-inputs.template.json` is filled only after app export exists: repository ID, workflow ID, app run ID, attempt, workflow head, artifact ID/name/ZIP SHA256/ZIP bytes. Keep the artifact name's exact attempt binding. `download.py --pins FILE --out DIR` runs on the host with its existing GitHub token and strips Authorization on redirects; neither token nor token-bearing environment enters the container. It verifies exact run/repository/workflow/head/attempt, artifact metadata, ZIP hash/length, safe paths/types and a complete content index. Completed success or failure is accepted. Cancelled/timed-out runs additionally require an indexed cleanup receipt matching the exported summary and the reviewed host cleanup ordering (owned workloads are removed before paging cleanup); absent or failed cleanup rejects the import. The container repeats verification of the already-downloaded ZIP and exported files before restoring anything. + +The shared bootstrap owns the fresh native container and compiler download, with a benchmark-specific execution identity. It must not call app initialization unchanged because that initializer requires job `linux-x64-app`. Compiler adoption, exact R4 source clone/frozen install/canonical runtime/boundary/selection still run through the existing native-prep owners. No AOT or compiler build runs in this mode. Do not copy the original prep receipts over those new receipts. + +After native preparation, run `stage.py` to place the unchanged runtime/measurement owners and thin adapters at ROOT/benchmark-prep. `restore.py --download DIR` checks both original and new compiler records and plugin selections, and invokes the unchanged `preserve.py verify` against each complete usable app archive. Its native plan/result/transport bytes stay unchanged. The verified application directory is moved into the original ROOT/artifacts/ path; only the verification owner creates a derived local-check plan. Original core results remain clearly identified with the originating app run. + +Missing/failed/unpreserved JS/C2/TS are written to `availability.json` as **unavailable** with a reason and `performanceQualified:false`. They are never fabricated as zero measurements or passes. A valid JS AOT is required as the declared baseline; unavailable C2 or TS does not block the remaining selected comparison. Present but contradictory identities fail restoration. `bind-inputs.py` enables only available variants. The existing cohort owner already supports an arbitrary selected cell list and is unchanged. + +The package/install path reuses the previous prepared comparator owners: private copy of the freshly built source, canonical package owner, source-selected extra bundles, a fresh npm prefix/cache/HOME and all19 exact source allow/deny decisions plus the exact tarball file alias. The install is labeled **npm lifecycle with source allowScripts policy**, with strict hook admission. It records tarball hash/size, actual lock SRI, source stamp, schema, package contents, installed logical bytes/files, ELF inventory, entry hash and measured installation CPU/RSS/wall. There is no incremental install, pruning or relaxed hook policy. + +Run `run-functional.py` once after installation/inventory. It uses the existing measurement/core owners for each currently available AOT and Node/Bun JIT baseline with fresh state. An optional C2/TS functional failure is preserved and explicitly excludes that cell; failure of JS, Node or Bun stops comparison. The adapter rebinds available inputs after any optional failure. Cancellation is never treated as an optional-cell failure. These functional timings are scheduler evidence only, not performance rows. + +`prepare-window.py` computes the entire unchanged cohort budget from this runner's measured probes: **7 × sum(selected-cell elapsed seconds) × 2 + 300 seconds**, representing one warmup plus six measured sweeps, 2× timing headroom and five minutes for controller/cleanup variation. It compares against the absolute job deadline minus the existing1200-second cleanup reserve. The prior functional measurements were roughly34 seconds for Node and91 seconds for Bun JIT including Doctor; they justify measuring whole probe cost, not just Gateway readiness. Those old ARM64/d754 results remain excluded from R4 performance. No fixed7200-second start gate remains. If the complete budget cannot fit, exit78 records `cohort-budget.json` as insufficient; do not cut sweeps. + +The host owner then reconciles all build/install hooks, containers/guest work and other workloads, writes a current `quiet-admission.json` from the template with the computed reservation, and binds a sanitized task-only host receipt. Avoid arbitrary process command-line dumps in exported evidence. `check-window.py` requires a recent receipt on the same boot and the complete reservation immediately before launch. The existing absolute deadline owner remains responsible for cancellation/cleanup; the estimate is not a guaranteed upper bound. + +Use the phase sequence and exact argv in `integration.json`. Every executable phase stays behind the shared deadline owner. For cohort, use the existing `run-phase.sh cohort`, which rechecks all source/receipt/runtime/entry hashes and uses `stream-cohort.py` to retain completed row progress. At completion `summarize.py` requires one warmup plus exactly six measured rows per selected cell. Its result is `partial-comparison-passed` when an original requested variant is unavailable; `fullRequestedMatrixComplete` remains false. Original app results, exported inputs and new measurements remain distinguishable. + +Report Gateway readiness, first streamed delta, completed first turn, root/tree RSS and CPU with medians/quartiles/min/max and paired ratios. Results are same-machine deployment comparisons with recorded plugin-content differences, warm shared file caches and a synthetic streaming provider. They are not cold-cache, live-provider or compiler-only claims. A Worker census is not complete Worker lifecycle qualification. `summarize.py` includes the explicit unavailable cells beside successful statistics. + +`test_contract.py` is pure synthetic transport/selection proof: completed failed run acceptance, wrong attempt/ZIP rejection, changed exported bytes, path traversal, unavailable TS and independent valid JS with missing TS. Run it under Python3.12 (matching the native environment). The cohort invocation remains unchanged. The opt-in Knowledge control below changes only untimed AOT functional cells; local checks do not establish native results or an autoreview verdict. + + +## Untimed backup qualification in version2 + +After install/inventory and before functional probes/the quiet barrier, `run-backup.py` exercises the existing synthetic backup owner for canonical Node and Bun JIT controls plus every admitted available AOT cell. This does not alter `core-runner`, its timed workload or its six measured sweeps. Each backup invocation retains the original 120-second per-command limit and an outer 300-second controller bound. Previous controls completed create+verify in roughly3.6 seconds on Node and2.3 seconds on Bun; these are scheduling context only, not R4 proof. + +The only change to the previously reviewed backup harness itself is its SOURCE constant. `backup/SOURCE-AUDIT.md` records the exact source audit, including the changed PostgreSQL-only discovery branch. AOT still needs admitted lineage, now supplied by the native restored-cell metadata verification. JIT backup controls use ROOT/source/openclaw.mjs because the packaged npm launcher does not carry the required dist/.buildstamp. No stamp is fabricated and no guard is removed. + +Backup results remain their own qualification evidence. Missing TS remains unavailable. Every failed backup exits nonzero and records failed status, never pass. The workflow owner may explicitly continue to collect independent performance after reconciling those child processes; `comparison-summary.json` then includes the failed backup summary beside any successful performance. The overall application remains unqualified by this performance job. + +Version3 preserves the complete originating qualification summary, including strict-zero-JS and other failures, beside performance results. A per-cell benchmark pass never erases those failures. + +## R4 source freeze + +This packet binds source4fa442e332745f1f58ccedd27106abdafcf4e019, tree5409457bc1b8a901b00193469a3c2b7a74dc2f30, frozen2026-10-25T22:30:39.990290+00:00. It includes the landed typed resolver repair PR183822 and later main runtime changes. Source-contract entries, package/lock/workspace and source npm policy are freshly audited against immutable R4 blobs. Actual selection, compiler/runtime hashes, installed contents and AOT facts still require new native receipts; no prior counts, binaries or originating runs are reused. + +## Untimed Knowledge control + +Each available AOT variant gets a fresh dedicated Knowledge control under the +existing runtime owner. Operator RPC checks unprovisioned status and creates an +operator/direct session without starting a run. An admitted agent then consumes +exactly four scripted provider requests: tool search, tool description, actual +ontology dispatch, and the final marker. Operator status/ontology must show the +same ready store and fingerprint, with registry, store and vault files present. +There is no direct HTTP tool call or fabricated memory audience. + +Normal functional runs and timed cohorts are unchanged. A failed Knowledge +control is reported independently and prevents scheduled completion; it does +not rewrite performance availability. Actual artifact qualification remains +pending execution. The former direct-HTTP fixture was invalid and is removed. + +## Untimed restored-artifact requalification + +Before backup/functional preparation and the existing quiet admission, the benchmark +job reuses the runtime controller for JS and C2 native-worker diagnostics, Docker +image preparation, gateway-network, and kitchen-sink. It never builds an AOT app. +The original exported core/build/admission/transport records stay unchanged. +New controller receipts/raw archives export under `requalification/`, with current +execution and original export identities in `requalification.json`. + +Ordinary failure is retained and permits the comparator only after the existing +label-scoped child cleanup, backup reconciliation, quiet gate, and fresh core proof. +Timeout/signal exits stop work. A failed or absent requalification prevents +`scheduledWorkComplete`; comparator success never promotes full qualification. + +The owned outer container installs SHA256-pinned Git 2.56.0 before source preparation, +retaining Git's no-lazy-fetch guard. Kitchen-sink uses a hash-bound read-only assertion +overlay to accept its explicit `/opt/p6-artifact/runtime` SDK host instead of `/app`. +The original source and artifact are untouched; symlink and dependency isolation +checks remain in the overlay. + +The replay phase count derives from restored JS/C2 availability. Unavailable +variants remain explicit; an otherwise valid JS-only comparison stays usable. +The existing cleanup owner records each labelled child's running state before +removal. A live-child recovery keeps effective requalification and scheduled +completion failed, even after an empty census; comparator proof may proceed only +through subsequent clean reconciliation and quiet admission. Raw phase replay is +marked pending cleanup until the exporter combines both owners' receipts. +The assertion mount applies only when the actual Docker image token equals the +verified AOT image tag; unrelated fixture images retain their normal mounts. + +Package preparation preserves the private clone's generated +`.artifacts/extension-package-boundary` tree outside the package source before +checking links. This retains the declaration fixture's intentional absolute +dependency links without touching canonical source or weakening the guard for +any remaining package input. Symlinked fixture paths and existing preservation +destinations fail before movement. + +Package preparation uses distinct empty npm user and global configuration files +under its task temporary directory. This ignores ambient home/global npm settings +without asking npm 11 to load the same `/dev/null` path twice. The integration test +exercises this setup with an offline, dependency-free lockfile operation. diff --git a/scripts/openclaw-p6/app/benchmark/app-inputs.template.json b/scripts/openclaw-p6/app/benchmark/app-inputs.template.json new file mode 100644 index 000000000000..6eb91cc5d14d --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/app-inputs.template.json @@ -0,0 +1,10 @@ +{ + "repository": "openclaw/bun", + "repositoryId": null, + "runId": null, + "runAttempt": null, + "workflowId": null, + "headSha": null, + "artifact": { "id": null, "name": null, "zipSha256": null, "zipBytes": null }, + "maxUnpackedBytes": 8589934592 +} diff --git a/scripts/openclaw-p6/app/benchmark/app_contract.py b/scripts/openclaw-p6/app/benchmark/app_contract.py new file mode 100644 index 000000000000..3f53b3290a1f --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/app_contract.py @@ -0,0 +1,91 @@ +"""Exact completed app-run transport contract; contains no network or app execution.""" +import hashlib,json,stat,zipfile +from pathlib import Path,PurePosixPath +CUT='4fa442e332745f1f58ccedd27106abdafcf4e019' +ROOT=Path('/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1') +VARIANTS=('js','c2-off','ts') +def load(p):return json.loads(Path(p).read_text()) +def sha(p): + with Path(p).open('rb') as f:return hashlib.file_digest(f,'sha256').hexdigest() +def dump(p,x): + with Path(p).open('x') as f:json.dump(x,f,indent=2);f.write('\n') +def pins_ok(p): + assert p['repository']=='openclaw/bun' + for k in ['repositoryId','runId','runAttempt','workflowId']:assert type(p[k]) is int and p[k]>0,k + assert len(p['headSha'])==40 and all(c in '0123456789abcdef' for c in p['headSha']) + a=p['artifact'];assert type(a['id']) is int and a['id']>0 + assert a['name']==f"p6-linux-x64-app-{p['headSha']}-attempt{p['runAttempt']}" + assert type(a['zipBytes']) is int and a['zipBytes']>0 + assert len(a['zipSha256'])==64 and all(c in '0123456789abcdef' for c in a['zipSha256']) + assert type(p['maxUnpackedBytes']) is int and 0>16;assert not stat.S_ISLNK(mode) and (m.is_dir() or stat.S_IFMT(mode) in (0,stat.S_IFREG)) + size+=m.file_size + assert size<=pins['maxUnpackedBytes'] + files={m.filename for m in rows if not m.is_dir()} + assert {'index.json','summary.json','host/execution.json'}<=files + assert z.getinfo('index.json').file_size<=16*1024**2 and z.getinfo('summary.json').file_size<=16*1024**2 and z.getinfo('host/execution.json').file_size<=1024**2 + index=json.loads(z.read('index.json'));assert isinstance(index,list) + indexed={r['path'] for r in index};assert len(indexed)==len(index) + assert files==indexed|{'index.json','summary.json'} + if existing: + for name in ['index.json','summary.json']: + target=out/name + assert target.is_file() and not target.is_symlink() and target.read_bytes()==z.read(name),name + for row in index: + with z.open(row['path']) as stream: digest=hashlib.file_digest(stream,'sha256').hexdigest() + assert z.getinfo(row['path']).file_size==row['bytes'] and digest==row['sha256'],row['path'] + if existing: + target=out/row['path'];assert target.is_file() and not target.is_symlink() and target.stat().st_size==row['bytes'] and sha(target)==digest,row['path'] + execution=json.loads(z.read('host/execution.json'));identity=execution['identity'] + assert identity=={'repository':pins['repository'],'runId':str(pins['runId']),'runAttempt':str(pins['runAttempt']),'job':'linux-x64-app'} + assert execution['workflowHead']==pins['headSha'] and execution['sourceCommit']==CUT + summary=json.loads(z.read('summary.json'));assert summary['sourceCommit']==CUT + if run['conclusion'] in ['cancelled','timed_out']: + assert 'host/paging-cleanup.json' in indexed,'Interrupted run requires explicit exported cleanup proof' + cleanup=json.loads(z.read('host/paging-cleanup.json')) + assert cleanup==summary['pagingCleanup'],'Interrupted cleanup summary differs from the indexed receipt' + if cleanup.get('status')=='not-activated': + assert cleanup.get('resourcesAbsent') is True + else: + assert cleanup['action']=='cleanup' and cleanup['operationExitCode']==0 and cleanup.get('interruptedBySignal') is None + assert cleanup['identity']==identity and cleanup['executionSha256']==hashlib.sha256(z.read('host/execution.json')).hexdigest() + assert cleanup['metadata']['phase']=='cleaned' and cleanup['metadata']['sourceCommit']==CUT + assert not cleanup['metadata'].get('cleanupErrorPresent') + + if not existing:out.mkdir(parents=True);z.extractall(out) + return {'status':'exact-completed-app-export-verified','sourceCommit':CUT,'runId':pins['runId'],'runAttempt':pins['runAttempt'],'workflowHead':pins['headSha'],'artifactId':a['id'],'artifactZipSha256':a['zipSha256'],'fileCount':len(files),'unpackedBytes':size,'runConclusion':run['conclusion'],'interruptedCleanupRequired':run['conclusion'] in ['cancelled','timed_out']} + +def classify(export,variant): + export=Path(export) + paths={'build':export/f'build-receipts/{variant}/result.json','plan':export/f'build-receipts/{variant}/plan.json','admission':export/f'admissions/{variant}.json','core':export/f'qualification-results/{variant}-core/run/result.json','controller':export/f'runtime-results/{variant}-core/result.json','transport':export/f'preserved/{variant}/transport.json','archive':export/f'preserved/{variant}/artifact.tar'} + missing=[k for k,p in paths.items() if not p.is_file()] + if missing:return {'status':'unavailable','reason':'missing exported '+','.join(missing),'performanceQualified':False} + b=load(paths['build']);c=load(paths['core']);controller=load(paths['controller']) + if b.get('status')!='built-unsigned' or b.get('phase')!='complete':return {'status':'unavailable','reason':'app build did not complete successfully','buildStatus':b.get('status'),'performanceQualified':False} + if c.get('qualification')!='passed' or controller.get('status')!='phase-passed':return {'status':'unavailable','reason':'original core qualification did not pass','coreStatus':c.get('qualification'),'controllerStatus':controller.get('status'),'performanceQualified':False} + assert load(paths['plan'])==b['plan'] and b['plan']['sourceProof']['commit']==CUT + assert b['plan']['variant']==('c2' if variant=='c2-off' else variant) + assert b['measurement']['exitCode']==0 and controller['sourceCommit']==CUT + assert controller['actualBuildReceiptSha256']==sha(paths['build']) + assert controller['rootBuildAdmissionSha256']==sha(paths['admission']) + return {'status':'available-pending-native-restoration','paths':{k:str(p) for k,p in paths.items()},'performanceQualified':False} diff --git a/scripts/openclaw-p6/app/benchmark/download.py b/scripts/openclaw-p6/app/benchmark/download.py new file mode 100644 index 000000000000..9e7059f17e14 --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/download.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 +"""Host-only exact Actions download; the GitHub token never enters the container.""" +import argparse,json,os,urllib.request +from pathlib import Path +from app_contract import dump,load,pins_ok,verify_export +class Redirect(urllib.request.HTTPRedirectHandler): + def redirect_request(self,request,fp,code,message,headers,newurl): + redirected=super().redirect_request(request,fp,code,message,headers,newurl) + if redirected is not None:redirected.remove_header('Authorization') + return redirected + +def main(): + p=argparse.ArgumentParser();p.add_argument('--pins',type=Path,required=True);p.add_argument('--out',type=Path,required=True);a=p.parse_args() + pins=load(a.pins);pins_ok(pins);assert not a.out.exists();a.out.mkdir(parents=True) + def fetch(path,target=None,limit=None): + req=urllib.request.Request('https://api.github.com/repos/openclaw/bun/'+path,headers={'Authorization':'Bearer '+os.environ['GH_TOKEN'],'Accept':'application/vnd.github+json','X-GitHub-Api-Version':'2022-11-28'}) + with urllib.request.build_opener(Redirect).open(req,timeout=60) as response: + if target is None:return json.load(response) + count=0 + with target.open('xb') as f: + while block:=response.read(1024*1024): + count+=len(block);assert count<=limit;f.write(block) + assert count==limit + run=fetch(f"actions/runs/{pins['runId']}/attempts/{pins['runAttempt']}") + metadata=fetch(f"actions/artifacts/{pins['artifact']['id']}") + dump(a.out/'pins.json',pins);dump(a.out/'run.json',run);dump(a.out/'artifact.json',metadata) + archive=a.out/'app.zip';fetch(f"actions/artifacts/{pins['artifact']['id']}/zip",archive,pins['artifact']['zipBytes']) + verified=verify_export(pins,run,metadata,archive,a.out/'export') + dump(a.out/'verification.json',verified);print(json.dumps(verified)) +if __name__=='__main__':main() diff --git a/scripts/openclaw-p6/app/benchmark/export.py b/scripts/openclaw-p6/app/benchmark/export.py new file mode 100644 index 000000000000..c92eb4a26569 --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/export.py @@ -0,0 +1,166 @@ +#!/usr/bin/env python3 +"""Select synthetic benchmark proof without copying installed packages or state.""" +import json +import os +from pathlib import Path +import re +import shutil +import stat +import sys + +from app_contract import CUT, ROOT, dump, load, sha +sys.path.insert(0, str(Path(__file__).resolve().parents[1])) +from preflight import export_selections + +VARIANTS = ['js', 'c2-off', 'ts'] +CORE_FILES = ['result.json', 'history.json', 'events.jsonl', 'provider-requests.jsonl', 'zero-js.json'] +KNOWLEDGE_FILES = ['result.json', 'status-before.json', 'session-create.json', 'turn.json', + 'provider.json', 'status-after.json', 'ontology-after.json'] + + +def tree_files(directory): + if not directory.exists(): + return + assert directory.is_dir() and not directory.is_symlink(), directory + for child in sorted(directory.iterdir()): + assert not child.is_symlink(), child + if child.is_dir(): + yield from tree_files(child) + else: + assert stat.S_ISREG(child.lstat().st_mode), child + yield child + + +def core_files(directory): + for name in CORE_FILES: + yield directory / name + for name in ['logs', 'traces']: + yield from tree_files(directory / name) + yield directory / 'provider.json' + for name in KNOWLEDGE_FILES: + yield directory / 'knowledge' / name + + +def selections(work, root): + yield from export_selections(work, root) + prep = root / 'benchmark-prep' + for name in ['execution.json', 'resources.json', 'app-inputs.json', 'terminal.json', + 'benchmark-cleanup.json', 'benchmark-run.json', 'git-prerequisite-version.txt', + 'requalification-child-cleanup.json']: + yield work / name, Path('host') / name + for path in tree_files(work / 'benchmark-phases'): + yield path, Path('host/phases') / path.relative_to(work / 'benchmark-phases') + for name in ['verification.json', 'pins.json', 'run.json', 'artifact.json']: + yield work / 'benchmark-download' / name, Path('host/download') / name + for name in ['availability.json', 'native-inputs.json', 'cohort-budget.json', + 'quiet-admission.json', 'host-reconciliation.json', 'post-backup-reconciliation.json', + 'comparison-summary.json', 'requalification.json']: + yield prep / name, Path(name) + for name in ['producer-receipt.json', 'producer.stdout', 'producer.stderr', 'pack.json', 'bundles.json']: + yield prep / 'package' / name, Path('package') / name + for name in ['package-plan.json', 'installed-receipt.json', 'functional-timings.json', 'knowledge-controls.json', 'cohort-config.json']: + yield prep / 'work' / name, Path('work') / name + for name in ['install-command', 'functional-measurements']: + for path in tree_files(prep / 'work' / name): + yield path, Path('work') / path.relative_to(prep / 'work') + for cell in ['node-core', 'bun-core', 'js-core', 'c2-off-core', 'ts-core', + 'js-knowledge', 'c2-off-knowledge', 'ts-knowledge']: + for path in core_files(prep / 'work' / cell): + yield path, Path('work') / path.relative_to(prep / 'work') + cohort = prep / 'work/cohort' + yield cohort / 'cohort.json', Path('work/cohort/cohort.json') + if cohort.exists(): + assert not cohort.is_symlink() + for path in sorted(cohort.iterdir()): + if re.fullmatch(r'(warmup|sweep-[0-9]+)-[a-z0-9-]+\.(stdout|stderr)', path.name): + yield path, Path('work/cohort') / path.name + elif re.fullmatch(r'(warmup|sweep-[0-9]+)-[a-z0-9-]+', path.name): + for selected in core_files(path): + yield selected, Path('work/cohort') / selected.relative_to(cohort) + for variant in ('js', 'c2-off'): + for phase in ('node-vm-native-workers', 'docker-image', 'docker-gateway-network', 'docker-kitchen-sink'): + label = variant + '-' + phase + for name in ('result.json', 'raw-index.json', 'raw-evidence.tar.gz'): + yield root / 'runtime-results' / label / name, Path('requalification/runtime-results') / label / name + yield root / 'backup-results/summary.json', Path('backup-results/summary.json') + for variant in VARIANTS: + yield root / 'restored-app' / variant / 'verification.json', Path('restored-app') / variant / 'verification.json' + for cell in ['node', 'bun-jit', *VARIANTS]: + for name in ['result.json', 'create/receipt.json', 'create/stdout.txt', 'create/stderr.txt', + 'create/time.txt', 'verify/receipt.json', 'verify/stdout.txt', 'verify/stderr.txt', 'verify/time.txt']: + yield root / 'backup-results' / cell / name, Path('backup-results') / cell / name + for path in tree_files(root / 'backup-results' / (cell + '-controller')): + yield path, Path('backup-results') / path.relative_to(root / 'backup-results') + + +def facts(path): + try: + return load(path) + except (OSError, ValueError): + return {'status': 'not-run-or-invalid'} + + +def summary(work, root): + compatibility = facts(root / 'prep-receipts/compatibility/result.json') + comparison = facts(root / 'benchmark-prep/comparison-summary.json') + backup = facts(root / 'backup-results/summary.json') + cleanup = facts(work / 'benchmark-cleanup.json') + execution = facts(work / 'execution.json') + knowledge = facts(root / 'benchmark-prep/work/knowledge-controls.json') + requalification = facts(root / 'benchmark-prep/requalification.json') + child_cleanup = facts(work / 'requalification-child-cleanup.json') + requalification = {**requalification, 'childCleanup': child_cleanup, 'status': 'passed' if ( + requalification.get('status') == 'phases-passed-pending-cleanup' and + child_cleanup.get('status') == 'children-removed' and child_cleanup.get('forcedRecovery') is False and + child_cleanup.get('identity') == execution.get('identity') and + child_cleanup.get('executionSha256') == sha(work / 'execution.json')) else 'failed'} + complete = (requalification['status'] == 'passed' and compatibility.get('status') == 'PASS' and comparison.get('performanceQualified') is True and + comparison.get('status') in ['comparison-passed', 'partial-comparison-passed'] and + facts(work / 'benchmark-run.json').get('status') == 'completed' and + backup.get('status') == 'passed' and knowledge.get('sourceCommit') == CUT and + knowledge.get('status') == 'passed' and cleanup.get('status') == 'owned-workloads-removed' and + cleanup.get('identity') == execution.get('identity') and + cleanup.get('pagingActivated') is False and not (work / 'terminal.json').exists()) + return {'sourceCommit': CUT, 'execution': execution, 'comparison': comparison, + 'nativeCompatibility': {'status': compatibility.get('status', 'not-run')}, + 'untimedBackup': backup, 'untimedKnowledge': knowledge, 'untimedRequalification': requalification, 'cleanup': cleanup, 'scheduledWorkComplete': complete, + 'applicationQualified': False, 'shipReady': False} + + +def export(work, root): + out = work / 'benchmark-export' + out.mkdir(exist_ok=False) + index = [] + for source, relative in selections(work, root): + if not source.exists(): + continue + assert stat.S_ISREG(source.lstat().st_mode), source + boundary = root if source.is_relative_to(root) else work + assert source.resolve(strict=True).is_relative_to(boundary.resolve(strict=True)), source + # Reject symlinked ancestors even when their targets remain within the task root. + for parent in source.parents: + assert not parent.is_symlink(), parent + if parent == boundary: + break + target = out / relative + target.parent.mkdir(parents=True, exist_ok=True) + shutil.copyfile(source, target) + index.append({'path': str(relative), 'bytes': target.stat().st_size, 'sha256': sha(target)}) + dump(out / 'index.json', index) + dump(out / 'summary.json', summary(work, root)) + + +def main(): + os.umask(0o022) + work = Path(os.environ['P6_WORK']) + if sys.argv[1:] == ['--require-complete']: + result = load(work / 'benchmark-export/summary.json') + print(json.dumps(result, indent=2)) + return 0 if result['scheduledWorkComplete'] else 1 + assert not sys.argv[1:] + export(work, ROOT) + return 0 + + +if __name__ == '__main__': + raise SystemExit(main()) diff --git a/scripts/openclaw-p6/app/benchmark/host.py b/scripts/openclaw-p6/app/benchmark/host.py new file mode 100644 index 000000000000..944921b5ae62 --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/host.py @@ -0,0 +1,147 @@ +#!/usr/bin/env python3 +"""Run benchmark phases with one absolute deadline and explicit failure ownership.""" +import importlib.util +import json +import os +from pathlib import Path +import subprocess +import sys + +from app_contract import ROOT, dump, load, sha + +HERE = Path(__file__).resolve().parent +SPEC = importlib.util.spec_from_file_location('p6_deadline', HERE.parents[1] / 'deadline_process.py') +DEADLINE = importlib.util.module_from_spec(SPEC) +SPEC.loader.exec_module(DEADLINE) + + +def normalized(code): + return code if code >= 0 else 128 - code + + +def terminal(code): + return code == 124 or code >= 128 + + +def sequence(phase, reconcile, cleanup): + """Ordinary untimed failures may continue only through owned cleanup and quiet gates.""" + before = [('prepare', ['bash', '/p6-recipe/app/prepare.sh']), + ('stage', ['python3', '-B', '/p6-recipe/app/benchmark/stage.py']), + ('restore', ['python3', '-B', '/p6-recipe/app/benchmark/restore.py', '--download', + os.environ['P6_WORK'] + '/benchmark-download']), + ('package', ['bash', str(ROOT / 'benchmark-prep/prepare-package.sh')]), + ('bind', ['python3', '-B', str(ROOT / 'benchmark-prep/bind-inputs.py'), '--root-admit'])] + for name in ['plan', 'install', 'inventory']: + before.append((name, ['bash', str(ROOT / 'benchmark-prep/run-phase.sh'), name])) + for name, command in before: + code = phase(name, command) + if code: + return code + code = phase('requalification', ['python3', '-B', '/p6-recipe/app/benchmark/requalify.py']) + if terminal(code): + return code + code = cleanup() + if code: + return code + code = phase('backup-untimed', ['python3', '-B', str(ROOT / 'benchmark-prep/run-backup.py')]) + if terminal(code): + return code + # Reconcile even a passing owner; its descendants must be gone before continuing. + reconciled = reconcile(True) + if reconciled: + return reconciled + after = [('functional', ['python3', '-B', str(ROOT / 'benchmark-prep/run-functional.py')]), + ('config', ['bash', str(ROOT / 'benchmark-prep/run-phase.sh'), 'config']), + ('budget', ['python3', '-B', str(ROOT / 'benchmark-prep/prepare-window.py')])] + for name, command in after: + code = phase(name, command) + if code: + return code + code = reconcile(False) + if code: + return code + for name, command in [('window', ['python3', '-B', str(ROOT / 'benchmark-prep/check-window.py')]), + ('cohort', ['bash', str(ROOT / 'benchmark-prep/run-phase.sh'), 'cohort']), + ('summary', ['python3', '-B', str(ROOT / 'benchmark-prep/summarize.py')])]: + code = phase(name, command) + if code: + return code + return 0 + + +def main(): + os.umask(0o077) + work = Path(os.environ['P6_WORK']) + logs = work / 'benchmark-phases' + logs.mkdir(parents=True, exist_ok=True) + deadline = int(os.environ['P6_DEADLINE_EPOCH']) + assert os.environ['P6_EXECUTION_MODE'] == 'benchmark' + action = sys.argv[1] + assert action in ['download', 'bootstrap', 'run'] + + def bounded(name, command, env=None): + with (logs / (name + '.stdout')).open('xb') as out, (logs / (name + '.stderr')).open('xb') as err: + result, facts = DEADLINE.run_bounded(command, deadline_epoch=deadline, + reserve_seconds=1200, cleanup_grace=30, env=env, stdout=out, stderr=err) + code = normalized(result.returncode) + facts['exitCode'] = code + dump(logs / (name + '.json'), facts) + print(json.dumps({'phase': name, 'exitCode': code}), flush=True) + if terminal(code) and (work / 'execution.json').exists(): + subprocess.run([sys.executable, '-B', str(HERE / 'initialize.py'), 'terminal', str(code)], check=True) + return code + + if action == 'bootstrap': + return bounded('bootstrap', ['bash', str(HERE.parent / 'host.sh'), 'bootstrap']) + if action == 'download': + for name, command in [ + ('download-compilers', [sys.executable, '-B', str(HERE.parent / 'download.py')]), + ('download-app', [sys.executable, '-B', str(HERE / 'download.py'), '--pins', + str(work / 'app-inputs.json'), '--out', str(work / 'benchmark-download')])]: + code = bounded(name, command) + if code: + return code + return 0 + assert 'GH_TOKEN' not in os.environ and 'GITHUB_TOKEN' not in os.environ + execution = load(work / 'execution.json') + assert execution['identity']['job'] == 'linux-x64-benchmark' + assert execution['workflowHead'] == os.environ['GITHUB_SHA'] + assert not (work / 'terminal.json').exists() + container = os.environ['P6_CONTAINER'] + inspected = subprocess.check_output(['docker', 'inspect', '--format', + '{{index .Config.Labels "openclaw.p6.owner"}}', container], text=True, timeout=30).strip() + assert inspected == os.environ['GITHUB_RUN_ID'] + '-' + os.environ['GITHUB_RUN_ATTEMPT'] + + def phase(name, command): + return bounded(name, ['docker', 'exec', container, 'nice', '-n', '10', 'env', '-i', + 'HOME=/home/runner', 'PATH=/usr/bin:/bin', 'P6_WORK=' + str(work), + 'P6_DEADLINE_EPOCH=' + str(deadline), 'PYTHONDONTWRITEBYTECODE=1', + 'bash', '-c', 'umask 077; exec "$@"', 'p6-benchmark', *command]) + + def reconcile(only): + command = ['sudo', '-n', 'env', '-i', 'PATH=/usr/sbin:/usr/bin:/sbin:/bin', + 'P6_WORK=' + str(work), 'P6_CONTAINER=' + container, + 'P6_DEADLINE_EPOCH=' + str(deadline)] + command += [key + '=' + os.environ[key] for key in + ['GITHUB_REPOSITORY', 'GITHUB_RUN_ID', 'GITHUB_RUN_ATTEMPT', 'GITHUB_JOB', 'GITHUB_SHA']] + command += ['python3', '-B', str(HERE / 'quiet.py'), '--identity', str(work / 'execution.json'), + '--identity-sha256', sha(work / 'execution.json'), '--container', container] + if only: + command += ['--reconcile-only'] + return bounded('reconcile-backup' if only else 'quiet-admission', command) + + def cleanup(): + return bounded('requalification-children-cleanup', ['bash', str(HERE.parent / 'host.sh'), 'reconcile-children']) + + code = sequence(phase, reconcile, cleanup) + dump(work / 'benchmark-run.json', {'status': 'completed' if code == 0 else 'failed', 'exitCode': code, + 'applicationQualified': False, 'shipReady': False}) + if code: + # The deadline owner reaps the Docker client; stop the container to reap its workload. + subprocess.run(['timeout', '--kill-after=5s', '30s', 'docker', 'stop', '--time', '15', container], + stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=False) + return code + + +if __name__ == '__main__': + raise SystemExit(main()) diff --git a/scripts/openclaw-p6/app/benchmark/initialize.py b/scripts/openclaw-p6/app/benchmark/initialize.py new file mode 100644 index 000000000000..a58b6b996072 --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/initialize.py @@ -0,0 +1,81 @@ +#!/usr/bin/env python3 +"""Bind explicit app inputs and a fresh native benchmark execution identity.""" +import json +import os +from pathlib import Path +import platform +import re +import resource +import shutil +import sys +import time + +from app_contract import CUT, ROOT, dump, load, pins_ok, sha + + +def identity(env): + result = {'repository': env['GITHUB_REPOSITORY'], 'runId': env['GITHUB_RUN_ID'], + 'runAttempt': env['GITHUB_RUN_ATTEMPT'], 'job': env['GITHUB_JOB']} + assert result['repository'] == 'openclaw/bun' and result['job'] == 'linux-x64-benchmark' + assert all(re.fullmatch('[1-9][0-9]*', result[k]) for k in ['runId', 'runAttempt']) + assert re.fullmatch('[0-9a-f]{40}', env['GITHUB_SHA']) + return result + + +def app_inputs(env): + def number(key): + value = env[key] + assert re.fullmatch('[1-9][0-9]*', value), key + return int(value) + result = {'repository': 'openclaw/bun', 'repositoryId': number('P6_APP_REPOSITORY_ID'), + 'runId': number('P6_APP_RUN_ID'), 'runAttempt': number('P6_APP_RUN_ATTEMPT'), + 'workflowId': number('P6_APP_WORKFLOW_ID'), 'headSha': env['P6_APP_WORKFLOW_HEAD'], + 'artifact': {'id': number('P6_APP_ARTIFACT_ID'), 'name': env['P6_APP_ARTIFACT_NAME'], + 'zipSha256': env['P6_APP_ZIP_SHA256'], 'zipBytes': number('P6_APP_ZIP_BYTES')}, + 'maxUnpackedBytes': 8 * 1024**3} + pins_ok(result) + assert result['runId'] != int(identity(env)['runId']), 'Origin must be a different completed app run' + return result + + +def main(): + os.umask(0o077) + resource.setrlimit(resource.RLIMIT_CORE, (0, 0)) + work = Path(os.environ['P6_WORK']) + actual = identity(os.environ) + action = sys.argv[1] if len(sys.argv) > 1 else 'bootstrap' + if action == 'inputs': + work.mkdir(parents=True, exist_ok=True) + dump(work / 'app-inputs.json', app_inputs(os.environ)) + return + if action in ['terminal', 'cleanup']: + record = load(work / 'execution.json') + assert record['identity'] == actual and record['workflowHead'] == os.environ['GITHUB_SHA'] + if action == 'terminal': + code = int(sys.argv[2]) + assert code == 124 or code >= 128 + if not (work / 'terminal.json').exists(): + dump(work / 'terminal.json', {'status': 'terminal', 'exitCode': code, 'identity': actual}) + else: + dump(work / 'benchmark-cleanup.json', {'status': 'owned-workloads-removed', + 'identity': actual, 'pagingActivated': False, 'completedEpoch': time.time()}) + return + assert action == 'bootstrap' + assert platform.system() == 'Linux' and platform.machine() == 'x86_64' + pins_ok(load(work / 'app-inputs.json')) + dump(work / 'execution.json', {'schemaVersion': 1, 'identity': actual, + 'workflowHead': os.environ['GITHUB_SHA'], 'sourceCommit': CUT, + 'appInputsSha256': sha(work / 'app-inputs.json'), 'startedEpoch': time.time(), + 'hostBootId': Path('/proc/sys/kernel/random/boot_id').read_text().strip()}) + memory = int(next(row.split()[1] for row in Path('/proc/meminfo').read_text().splitlines() + if row.startswith('MemTotal:'))) * 1024 + facts = {'memTotalBytes': memory, 'cpus': len(os.sched_getaffinity(0)), + 'diskFreeBytes': shutil.disk_usage(ROOT.parent).free, 'kernel': platform.release(), + 'applicationFitQualified': False, 'pagingActivated': False} + dump(work / 'resources.json', facts) + assert memory >= 30_000_000_000 and facts['cpus'] >= 2 + assert facts['diskFreeBytes'] >= 57 * 1024**3, '25GiB floor + 32GiB work headroom required' + + +if __name__ == '__main__': + main() diff --git a/scripts/openclaw-p6/app/benchmark/payload/backup/SOURCE-AUDIT.md b/scripts/openclaw-p6/app/benchmark/payload/backup/SOURCE-AUDIT.md new file mode 100644 index 000000000000..2d045ab1e9a5 --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/payload/backup/SOURCE-AUDIT.md @@ -0,0 +1,13 @@ +# Backup owner rebind to R3 + +The previously exercised backup harness is unchanged except its SOURCE constant moves from57e6 to4fa442e332745f1f58ccedd27106abdafcf4e019. Its measurement helper remains byte-identical. Every one of the original eight source-contract files is byte-identical between those cuts: SQLite header worker and probe, worker URL, snapshot owners, backup creation, verification and CLI registration. + +The additional backup-record.ts change adds an explicit TypeScript type to an existing object and removes a literal cast. It changes no emitted behavior. backup-database-discovery.ts adds a PostgreSQL pool initializer conditional on a configured PostgreSQL family; this fixture clears its environment and configures only SQLite/plugin resources. The schema-migration backup table changes add empty entries for PostgreSQL-only migrations. Their exact R3 bytes and the public plugin-backup contract are included in source-contract.json for native audit. + +JIT controls use the fresh canonical ROOT/source/openclaw.mjs and its .buildstamp. The npm package does not ship that stamp; no compatibility bypass is added. Timed Node/Bun comparisons continue to use the fresh npm installation. + +The real CLI creates and independently verifies a backup with an included managed .db resource, checks archived live rows/integrity/deleted-page compaction and unchanged source payloads, and rejects plugin runtime execution. This remains synthetic, credentialless and providerless. AOT receives only hash-admitted binaries from available native cells. Missing TS is explicitly not run. Results do not qualify restore activation, live writer locking, global/agent schema sanitization or comparative performance. + +For the R3 freeze, all12 source-contract entries were rechecked against immutable59baf4a blobs and are byte-identical to the preceding R2 cut670a7ab. Fresh native receipts remain required. + +For R4, all12 entries were checked against immutable4fa442e blobs and remain unchanged from R3. Source/current-root labels are rebound; no previous backup execution result transfers. diff --git a/scripts/openclaw-p6/app/benchmark/payload/backup/measure-command.py b/scripts/openclaw-p6/app/benchmark/payload/backup/measure-command.py new file mode 100755 index 000000000000..ff23ea2f12d6 --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/payload/backup/measure-command.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 +"""Linux only; collect direct-executable wall/CPU/peak RSS without asserting application correctness.""" +import argparse, datetime, hashlib, json, os, pathlib, platform, signal, subprocess, time +p=argparse.ArgumentParser() +p.add_argument('--label',required=True) +p.add_argument('--out',required=True) +p.add_argument('--timeout',type=float,default=180) +p.add_argument('command',nargs=argparse.REMAINDER) +a=p.parse_args() +cmd=a.command[1:] if a.command[:1]==['--'] else a.command +if platform.system()!='Linux' or not cmd: p.error('requires Linux and a command after --') +out=pathlib.Path(a.out).resolve() +out.mkdir(parents=True,exist_ok=False) +timefile=out/'time.txt' +exe=pathlib.Path(cmd[0]) +receipt={'label':a.label,'at':datetime.datetime.now(datetime.timezone.utc).isoformat(), + 'arch':platform.machine(),'kernel':platform.release(),'command':cmd, + 'executableSha256':hashlib.file_digest(exe.open('rb'),'sha256').hexdigest() if exe.is_file() else None, + 'scope':'GNU time -v command plus reaped descendants; not exclusive gateway CPU'} +def signal_group(pgid, sig): + try: os.killpg(pgid,sig) + except ProcessLookupError: pass + +def stop_group(child, grace=5): + # GNU time may exit on TERM while its workload ignores it. Keep group custody + # for the full bounded grace, then send KILL independently of wrapper state. + signal_group(child.pid,signal.SIGTERM) + deadline=time.monotonic()+grace + while time.monotonic() row.gatewayReadySeconds, + firstDeltaSeconds: row => row.turn?.firstDeltaSeconds, + turnSeconds: row => row.turn?.seconds, + readyOwnRssBytes: row => row.readyOwnRssBytes, + turnOwnRssBytes: row => row.turnOwnRssBytes, + readyOwnCpuSeconds: row => row.readyOwnCpuSeconds, + turnOwnCpuSeconds: row => row.turnOwnCpuSeconds, + readyTreeRssBytes: row => row.readyTreeRssBytes, + turnTreeRssBytes: row => row.turnTreeRssBytes, + readyTreeCpuSeconds: row => row.readyTreeCpuSeconds, + turnTreeCpuSeconds: row => row.turnTreeCpuSeconds, +}; + +export function quantile(values, p) { + assert(values.length && values.every(Number.isFinite)); + const sorted = [...values].sort((a, b) => a - b); + const index = (sorted.length - 1) * p; + const low = Math.floor(index); + return sorted[low] + (sorted[Math.ceil(index)] - sorted[low]) * (index - low); +} + +function describe(values) { + return { n: values.length, median: quantile(values, 0.5), q1: quantile(values, 0.25), + q3: quantile(values, 0.75), min: Math.min(...values), max: Math.max(...values) }; +} + +export function summarize(rows, ids, baseline) { + const measured = rows.filter(row => !row.warmup); + const cells = {}; + for (const id of ids) { + const own = measured.filter(row => row.id === id); + assert(own.length, `missing measured rows for ${id}`); + cells[id] = {}; + for (const [name, get] of Object.entries(metrics)) { + const values = own.map(row => get(row.result)); + assert(values.every(Number.isFinite), `${id}: missing ${name}`); + const pairs = own.flatMap(row => { + const reference = measured.find(item => item.sweep === row.sweep && item.id === baseline); + assert(reference, `missing baseline for sweep ${row.sweep}`); + const denominator = get(reference.result); + return denominator > 0 ? [get(row.result) / denominator] : []; + }); + cells[id][name] = { ...describe(values), ratioToBaseline: pairs.length ? describe(pairs) : null, + omittedZeroDenominatorPairs: own.length - pairs.length }; + } + } + return { baseline, policy: 'all completed measured rows; no outlier deletion; linear inclusive quartiles', cells }; +} + +export function sweepOrder(ids, sweep) { + return sweep % 2 === 0 ? [...ids] : [...ids].reverse(); +} diff --git a/scripts/openclaw-p6/app/benchmark/payload/benchmark/core-runner.proposed.mjs b/scripts/openclaw-p6/app/benchmark/payload/benchmark/core-runner.proposed.mjs new file mode 100644 index 000000000000..15bb75ba22f6 --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/payload/benchmark/core-runner.proposed.mjs @@ -0,0 +1,262 @@ +#!/usr/bin/env node +// Direct-artifact qualification. Source imports below are test owners, never the app under test. +import assert from 'node:assert/strict'; +import { readGatewayStopBudget, stopProcess, shutdownFailure } from '../harness/process-stop.mjs'; +import { resolveLaunchTarget, launchArguments } from './launch-target.mjs'; +import { readProcStat as procIdentity, snapshotProcessTree } from './process-tree.mjs'; +import { qualifyConfigRoundtrip } from '../harness/config-roundtrip.mjs'; +import { coreFixtureConfig } from '../harness/fixture-config.mjs'; +import { hasGatewayReadyLog,isGatewayReadyResponse } from '../harness/gateway-readiness.mjs'; +import { spawn, spawnSync } from 'node:child_process'; +import { createHash, randomUUID } from 'node:crypto'; +import fs from 'node:fs'; +import net from 'node:net'; +import path from 'node:path'; +import { setTimeout as delay } from 'node:timers/promises'; +import { fileURLToPath, pathToFileURL } from 'node:url'; + +const argv = process.argv.slice(2); +if (argv.includes('--help')) { + console.log('Usage: node core-runner.mjs (--artifact | --runtime --entry ) --source --out [--zero-js] [--knowledge-control] [--timeout-seconds 180]'); + process.exit(0); +} +const options = {}; +for (let i=0;iout===root || out.startsWith(root+path.sep)),'--out must be outside source and artifact'); +assert(!out.startsWith(path.join(process.env.HOME??'','.openclaw')),'invalid output'); +const timeoutMs=Number(options['timeout-seconds']??180)*1000; +assert(Number.isFinite(timeoutMs)&&timeoutMs>=1000&&timeoutMs<=3600000,'invalid timeout'); +if (options.zeroJs) { + assert.equal(launch.kind,'standalone','--zero-js requires a standalone artifact'); + assert(process.platform==='linux','--zero-js requires native Linux strace'); + assert(spawnSync('strace',['--version'],{stdio:'ignore'}).status===0,'strace is required'); +} +fs.mkdirSync(out); +for (const part of ['tmp','home','.xdg','workspace','logs','traces']) fs.mkdirSync(path.join(out,part)); +const stateDir=path.join(out,'home','.openclaw'); +fs.mkdirSync(stateDir); +const configPath=path.join(stateDir,'openclaw.json'); +const token=`p6-synthetic-${randomUUID()}`, marker=`P6_STREAM_${randomUUID().replaceAll('-','')}`; +const env={PATH:process.env.PATH??'/usr/local/bin:/usr/bin:/bin',LANG:'C.UTF-8',TZ:'UTC', + HOME:path.join(out,'home'),USERPROFILE:path.join(out,'home'),OPENCLAW_HOME:path.join(out,'home'), + XDG_CONFIG_HOME:path.join(out,'.xdg'),TMPDIR:path.join(out,'tmp'), + OPENCLAW_STATE_DIR:stateDir,OPENCLAW_CONFIG_PATH:configPath, + OPENCLAW_TEST_WORKSPACE_DIR:path.join(out,'workspace'), + OPENAI_API_KEY:'p6-synthetic-local-fixture-only',OPENCLAW_GATEWAY_TOKEN:token, + OPENCLAW_DISABLE_BONJOUR:'1',OPENCLAW_NO_AUTO_UPDATE:'1',OPENCLAW_SKIP_CHANNELS:'1', + OPENCLAW_SKIP_GMAIL_WATCHER:'1',OPENCLAW_SKIP_CRON:'1',OPENCLAW_SKIP_CANVAS_HOST:'1', + NO_COLOR:'1',TERM:'dumb',SUCCESS_MARKER:marker,MOCK_PORT:'0', + OPENCLAW_MOCK_OPENAI_REQUEST_LOG_BODY_MAX_BYTES:'4194304',MOCK_RESPONSE_CHUNK_DELAY_MS:'100',MOCK_REQUEST_LOG:path.join(out,'provider-requests.jsonl')}; +const binaryHasher=createHash('sha256'); +for await (const chunk of fs.createReadStream(binary)) binaryHasher.update(chunk); +const result={schema:1,at:new Date().toISOString(),artifact,source,binary,platform:process.platform,arch:process.arch, + binarySha256:binaryHasher.digest('hex'),launchKind:launch.kind,entry, + entrySha256:entry?createHash('sha256').update(fs.readFileSync(entry)).digest('hex'):null, + qualification:'incomplete',syntheticOnly:true,checks:{},commands:[],processes:[],cleanup:{}, + limits:['Worker pool census is not proof of every worker lifecycle.','No live provider credentials or live-model proof.','Timing with --zero-js includes tracing overhead; own process counters then refer to strace, not the app.']}; +if (artifact && fs.existsSync(path.join(artifact,'manifest.json'))) result.manifest=JSON.parse(fs.readFileSync(path.join(artifact,'manifest.json'),'utf8')); +if(options.knowledgeControl) result.performanceEligible=false; +const children=[],observed=new Map(),stopReceipts=new Map(); +const clk=Number(spawnSync('getconf',['CLK_TCK'],{encoding:'utf8'}).stdout?.trim()); +const pageSize=Number(spawnSync('getconf',['PAGESIZE'],{encoding:'utf8'}).stdout?.trim()); +result.processCounters={clockTicksPerSecond:clk,pageSizeBytes:pageSize}; +const log=(name,value)=>fs.writeFileSync(path.join(out,name),JSON.stringify(value,null,2)+'\n'); +function census() { + if (process.platform!=='linux') return; + const all=[]; + for (const name of fs.readdirSync('/proc')) if (/^\d+$/.test(name)) { const value=procIdentity(Number(name)); if(value) all.push(value); } + const ids=new Set(children.map(child=>child.pid)); + let changed=true; + while(changed) { changed=false; for(const item of all) if(ids.has(item.ppid)&&!ids.has(item.pid)){ids.add(item.pid);changed=true;} } + for(const item of all) if(ids.has(item.pid)) observed.set(`${item.pid}:${item.start}`,item); +} +const sampler=setInterval(census,100); +sampler.unref(); +function start(label,command,args,{trace=false,extraEnv={}}={}) { + const stdout=path.join(out,'logs',label+'.stdout'),stderr=path.join(out,'logs',label+'.stderr'); + const outfd=fs.openSync(stdout,'w'),errfd=fs.openSync(stderr,'w'); + const actual=trace&&options.zeroJs?['strace','-ff','-yy','-s','256','-o',path.join(out,'traces',label),'-e','trace=openat,openat2,read,readv,pread64,preadv,preadv2,mmap,execve,sendfile,splice,copy_file_range,io_uring_setup,io_uring_enter,io_uring_register',command,...args]:[command,...args]; + const child=spawn(actual[0],actual.slice(1),{cwd:source,env:{...env,...extraEnv},detached:true,stdio:['ignore',outfd,errfd]}); + fs.closeSync(outfd);fs.closeSync(errfd); + child.receipt={label,command:[command,...args],actual,pid:child.pid,stdout,stderr,started:performance.now(),spawnError:null}; + child.once('error',error=>{child.receipt.spawnError=String(error);}); + children.push(child);result.commands.push(child.receipt); + child.done=new Promise(resolve=>child.once('close',(code,signal)=>{Object.assign(child.receipt,{code,signal,elapsedSeconds:(performance.now()-child.receipt.started)/1000});resolve(child.receipt);})); + return child; +} +function signalGroup(child,signal) { if(child.pid) try {process.kill(-child.pid,signal);} catch(error){if(error.code!=='ESRCH') throw error;} } +async function stop(child) { + if (!child?.pid) return; + const shutdown=await stopProcess(child,{graceMs:child===gateway?result.gatewayStopBudget.serviceStopTimeoutMs:10000}); + stopReceipts.set(child,{label:child.receipt.label,...shutdown}); + return shutdown; +} +async function command(label,args,limit=timeoutMs) { + const child=start(label,binary,launchArguments(launch,args),{trace:true}); + const complete=await Promise.race([child.done,delay(limit,undefined,{ref:false}).then(()=>null)]); + if(!complete){await stop(child);throw new Error(`${label} timed out`);} + assert.equal(complete.spawnError,null,`${label} could not start`); + assert.equal(complete.code,0,`${label} failed; see ${complete.stderr}`); + return fs.readFileSync(complete.stdout,'utf8'); +} +async function freePort() { + const server=net.createServer();await new Promise((resolve,reject)=>{server.once('error',reject);server.listen(0,'127.0.0.1',resolve);}); + const port=server.address().port;await new Promise(resolve=>server.close(resolve));return port; +} +let client,mock,gateway; +let interrupted=false; +const interrupt=()=>{interrupted=true;void stop(gateway).catch(error=>{result.stopError=String(error);});for(const child of children) if(child!==gateway) signalGroup(child,'SIGTERM');}; +process.on('SIGINT',interrupt);process.on('SIGTERM',interrupt); +const sourceImport=relative=>import(pathToFileURL(path.join(source,relative)).href); +const knowledgeOwner=options.knowledgeControl?await import('../harness/knowledge-agent.mjs'):null; +try { + result.gatewayStopBudget=await readGatewayStopBudget(source); + const [{applyMockOpenAiModelConfig},{createGatewayWsClient},{resolveGatewaySuccessPayload},{PROTOCOL_VERSION},{assertOpenAiRequestLogUsed}]=await Promise.all([ + sourceImport('scripts/e2e/lib/fixtures/mock-openai-config.mjs'),sourceImport('scripts/lib/gateway-ws-client.ts'), + sourceImport('scripts/e2e/lib/gateway-frame-payload.mjs'),sourceImport('packages/gateway-protocol/src/version.ts'), + sourceImport('scripts/e2e/lib/agent-turn-output.mjs')]); + mock=options.knowledgeControl + ?start('knowledge-provider','/usr/bin/python3',[fileURLToPath(new URL('../harness/knowledge-provider.py',import.meta.url)), + '--receipt',path.join(out,'provider.json'),'--model',knowledgeOwner.KNOWLEDGE_MODEL,'--marker',knowledgeOwner.KNOWLEDGE_MARKER]) + :start('mock-provider',process.execPath,[path.join(source,'scripts/e2e/mock-openai-server.mjs')]); + let mockPort; + const mockDeadline=Date.now()+timeoutMs; + while(Date.now(){ + const observed={at:performance.now(),...event};events.push(observed); + fs.appendFileSync(path.join(out,'events.jsonl'),JSON.stringify(observed)+'\n'); + }}); + const request=async(method,params={},limit=timeoutMs)=>{const frame=await client.request(method,params,limit); + assert.equal(frame.ok,true,`${method}: ${JSON.stringify(frame.error)}`);return resolveGatewaySuccessPayload(frame);}; + await client.waitOpen(); + result.hello=await request('connect',{minProtocol:PROTOCOL_VERSION,maxProtocol:PROTOCOL_VERSION, + client:{id:'gateway-client',displayName:'p6-direct-aot',version:'1.0.0',platform:process.platform,mode:'backend'}, + role:'operator',scopes:['operator.read','operator.write','operator.admin'],caps:[],auth:{token}}); + result.lanesBefore=await request('diagnostics.lanes'); + const sessionKey=`agent:main:p6-${randomUUID()}`; + const turnBefore=procIdentity(gateway.pid); + result.beforeTurnTree=snapshotProcessTree(gateway.pid,{clockTicks:clk,pageSize,expectedStart:result.readyTree.root.start}); + const turnStart=performance.now(); + const started=await request('chat.send',{sessionKey,message:`Return marker ${marker}.`,idempotencyKey:randomUUID(),deliver:false}); + assert.equal(started.status,'started','chat.send status');assert.equal(typeof started.runId,'string','chat.send runId'); + result.started=started; + const waited=await request('agent.wait',{runId:started.runId,timeoutMs},timeoutMs+5000); + assert.equal(waited.status,'ok','agent.wait status');result.waited=waited; + const history=await request('chat.history',{sessionKey,limit:20});log('history.json',history); + const assistant=history.messages?.findLast(item=>item.role==='assistant'); + const answer=typeof assistant?.content==='string'?assistant.content:(assistant?.content??[]).filter(part=>part.type==='text').map(part=>part.text).join('\n'); + assert(answer.includes(marker),'chat.history assistant marker missing'); + const deadline=Date.now()+5000; + const matching=()=>events.filter(event=>event.payload?.runId===started.runId); + const isDelta=event=>(event.event==='chat'&&event.payload?.state==='delta')||(event.event==='agent'&&event.payload?.stream==='assistant'&&typeof event.payload?.data?.delta==='string'&&event.payload.data.delta.length>0); + const isFinal=event=>event.event==='chat'&&event.payload?.state==='final'; + while(Date.now()JSON.parse(line)); + assert(requests.some(row=>{try {const body=typeof row.body==='string'?JSON.parse(row.body):row.body;return /\/v1\/(responses|chat\/completions)/.test(row.path)&&body?.stream===true&&JSON.stringify(body).includes(marker);}catch{return false;}}),'provider log lacks actual streaming inference request with this turn marker'); + result.turnProcessSnapshot=procIdentity(gateway.pid); + if(turnBefore && result.turnProcessSnapshot && Number.isFinite(clk)) result.turnOwnCpuSeconds=(result.turnProcessSnapshot.cpuTicks-turnBefore.cpuTicks)/clk; + if(result.turnProcessSnapshot && Number.isFinite(pageSize)) result.turnOwnRssBytes=result.turnProcessSnapshot.rssPages*pageSize; + result.afterTurnTree=snapshotProcessTree(gateway.pid,{clockTicks:clk,pageSize,expectedStart:result.readyTree.root.start}); + result.turnTreeRssBytes=result.afterTurnTree.rssBytes; + result.turnTreeCpuSeconds=(result.afterTurnTree.cpuTicks-result.beforeTurnTree.cpuTicks)/clk; + assert(result.turnTreeCpuSeconds>=0,'tree CPU counter decreased across non-atomic snapshots; cohort metric invalid'); + result.checks.streamedTurn=true; + result.sessionDescription=await request('sessions.describe',{key:sessionKey,includeLastMessage:true}); + assert(result.sessionDescription.session,'sessions.describe omitted completed session'); + result.lanesAfter=await request('diagnostics.lanes'); + result.workerObservation={kind:'public-pool-census-plus-returned-session-read',before:result.lanesBefore.workerCount,after:result.lanesAfter.workerCount,perWorkerCompletion:'not-exposed-by-this-RPC'}; + } + result.qualification='passed'; +} catch(error) {result.error=error?.stack??String(error);result.qualification='failed';} +finally { + try{client?.close();}catch{} + await stop(gateway);await stop(mock); + for(const child of children) await stop(child); + if(options.knowledgeControl) knowledgeOwner.finalizeKnowledgeProvider(result,path.join(out,'provider.json')); + census();clearInterval(sampler); + let live=[]; + const cleanupDeadline=Date.now()+10000; + do { + live=[]; + for(const item of observed.values()) {const current=procIdentity(item.pid);if(current?.start===item.start&¤t.state!=='Z') live.push(current);} + if(!live.length) break; + await delay(100); + } while(Date.now(){const current=procIdentity(item.pid);return current?.start===item.start&¤t.state!=='Z';}); + result.processes=[...observed.values()];result.cleanup={observedPids:observed.size,requiredForcedCleanup:live.map(item=>item.pid),survivors,stops:[...stopReceipts.values()]}; + const stopFailure=result.stopError??shutdownFailure(result.cleanup.stops,gateway?.receipt); + if(stopFailure){result.qualification='failed';result.cleanup.error=stopFailure;} + if(survivors.length||live.length){result.qualification='failed';result.cleanup.error='Task process survived normal shutdown';} + if(options.zeroJs) { + const analyzer=path.join(path.dirname(fileURLToPath(import.meta.url)),'../harness/analyze-zero-js.py'); + const traceResult=spawnSync('python3',[analyzer,'--trace-dir',path.join(out,'traces'),'--binary',binary,'--out',path.join(out,'zero-js.json')],{encoding:'utf8',env}); + result.zeroJs={exitCode:traceResult.status,stdout:traceResult.stdout,stderr:traceResult.stderr}; + if(traceResult.status!==0)result.qualification='failed'; + } + if(interrupted){result.qualification='failed';result.interrupted=true;} + process.off('SIGINT',interrupt);process.off('SIGTERM',interrupt); + log('result.json',result); +} +console.log(JSON.stringify({qualification:result.qualification,result:path.join(out,'result.json'),error:result.error??result.cleanup.error})); +process.exitCode=result.qualification==='passed'?0:1; diff --git a/scripts/openclaw-p6/app/benchmark/payload/benchmark/launch-target.mjs b/scripts/openclaw-p6/app/benchmark/payload/benchmark/launch-target.mjs new file mode 100644 index 000000000000..d25641971241 --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/payload/benchmark/launch-target.mjs @@ -0,0 +1,26 @@ +import assert from 'node:assert/strict'; +import fs from 'node:fs'; +import path from 'node:path'; + +export function resolveLaunchTarget(options) { + const usingRuntime = Boolean(options.runtime || options.entry); + assert(Boolean(options.artifact) !== usingRuntime, + 'select either --artifact or the --runtime/--entry pair'); + if (usingRuntime) { + assert(options.runtime && options.entry, '--runtime and --entry are required together'); + const binary = fs.realpathSync(options.runtime); + const entry = fs.realpathSync(options.entry); + fs.accessSync(binary, fs.constants.X_OK); + assert(fs.statSync(entry).isFile(), '--entry must be a file'); + return { kind: 'runtime-entry', artifact: null, binary, entry, prefix: [entry] }; + } + const artifact = fs.realpathSync(options.artifact); + const binary = path.join(artifact, 'openclaw'); + fs.accessSync(binary, fs.constants.X_OK); + assert(fs.statSync(path.join(artifact, 'runtime')).isDirectory(), 'artifact runtime/ is missing'); + return { kind: 'standalone', artifact, binary, entry: null, prefix: [] }; +} + +export function launchArguments(target, args) { + return [...target.prefix, ...args]; +} diff --git a/scripts/openclaw-p6/app/benchmark/payload/benchmark/process-tree.mjs b/scripts/openclaw-p6/app/benchmark/payload/benchmark/process-tree.mjs new file mode 100644 index 000000000000..4344793db454 --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/payload/benchmark/process-tree.mjs @@ -0,0 +1,55 @@ +import assert from 'node:assert/strict'; +import fs from 'node:fs'; + +export function readProcStat(pid) { + try { + const text = fs.readFileSync(`/proc/${pid}/stat`, 'utf8'); + const fields = text.slice(text.lastIndexOf(')') + 2).split(' '); + return { pid, ppid: Number(fields[1]), state: fields[0], start: fields[19], + cpuTicks: Number(fields[11]) + Number(fields[12]), + reapedChildCpuTicks: Number(fields[13]) + Number(fields[14]), rssPages: Number(fields[21]) }; + } catch { + return null; + } +} + +export function snapshotProcessTree(rootPid, { clockTicks, pageSize, expectedStart } = {}) { + assert.equal(process.platform, 'linux'); + assert(Number.isFinite(clockTicks) && clockTicks > 0); + assert(Number.isFinite(pageSize) && pageSize > 0); + const started = performance.now(); + const all = []; + for (const name of fs.readdirSync('/proc')) { + if (!/^\d+$/.test(name)) continue; + const row = readProcStat(Number(name)); + if (row) all.push(row); + } + const root = all.find(row => row.pid === rootPid); + assert(root && root.state !== 'Z', 'Gateway root is missing or exited during tree snapshot'); + if (expectedStart !== undefined) assert.equal(root.start, expectedStart, 'Gateway root PID was reused'); + const ids = new Set([rootPid]); + let changed = true; + while (changed) { + changed = false; + for (const row of all) { + if (ids.has(row.ppid) && !ids.has(row.pid)) { + ids.add(row.pid); + changed = true; + } + } + } + const processes = all.filter(row => ids.has(row.pid)); + const live = processes.filter(row => row.state !== 'Z'); + // Reaped CPU belongs to the waiting ancestor; an unreaped zombie still owns + // its counters. Each visible node contributes once at this census boundary. + const cpuTicks = processes.reduce((sum, row) => sum + row.cpuTicks + row.reapedChildCpuTicks, 0); + return { at: new Date().toISOString(), collectionMilliseconds: performance.now() - started, + root: { pid: rootPid, start: root.start }, processes, + liveProcessCount: live.length, zombieProcessCount: processes.length - live.length, + rssBytes: live.reduce((sum, row) => sum + row.rssPages * pageSize, 0), + cpuTicks, cpuSeconds: cpuTicks / clockTicks, + scope: 'Gateway root and current PPID descendants; RSS sums non-zombies; CPU sums own plus reaped-child user/system ticks, including visible zombies', + limits: ['Non-atomic /proc census: process churn during collection can move CPU between records.', + 'RSS sums process RSS and can count shared pages more than once; it is not PSS or unique physical memory.', + 'Descendants that escape through reparenting are outside this snapshot; no peak or lifetime RSS claim.'] }; +} diff --git a/scripts/openclaw-p6/app/benchmark/payload/benchmark/run-cohort.mjs b/scripts/openclaw-p6/app/benchmark/payload/benchmark/run-cohort.mjs new file mode 100644 index 000000000000..2fb3bd2da128 --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/payload/benchmark/run-cohort.mjs @@ -0,0 +1,116 @@ +#!/usr/bin/env node +import assert from 'node:assert/strict'; +import fs from 'node:fs'; +import os from 'node:os'; +import path from 'node:path'; +import { createHash } from 'node:crypto'; +import { spawn } from 'node:child_process'; +import { fileURLToPath } from 'node:url'; +import { resolveLaunchTarget } from './launch-target.mjs'; +import { summarize, sweepOrder } from './cohort-stats.mjs'; + +const [configName, outName] = process.argv.slice(2); +assert(configName && outName, 'Usage: node run-cohort.mjs config.json fresh-output-directory'); +assert.equal(process.platform, 'linux', 'measurements require native Linux'); +const config = JSON.parse(fs.readFileSync(configName, 'utf8')); +const source = fs.realpathSync(config.source); +assert(/^[a-f0-9]{40}$/.test(config.mainSha), 'mainSha must be the externally admitted full source SHA'); +assert(config.admissionReceipt, 'P0 admission receipt is required'); +const hash = async filename => { + const digest = createHash('sha256'); + for await (const bytes of fs.createReadStream(filename)) digest.update(bytes); + return digest.digest('hex'); +}; +const admissionReceipt = fs.realpathSync(config.admissionReceipt); +const admissionReceiptSha256 = await hash(admissionReceipt); +assert(Array.isArray(config.cells) && config.cells.length >= 2); +const ids = config.cells.map(cell => cell.id); +assert.equal(new Set(ids).size, ids.length); +assert(ids.every(id => /^[a-z0-9-]+$/.test(id)), 'cell IDs must be path-safe'); +assert(ids.includes(config.baseline), 'baseline must name one cell'); +const sweeps = config.sweeps ?? 6; +assert(Number.isInteger(sweeps) && sweeps >= 2 && sweeps <= 20); +const inputs = []; +for (const cell of config.cells) { + const target = resolveLaunchTarget(cell); + const binarySha256 = await hash(target.binary); + assert.equal(binarySha256, cell.binarySha256, `${cell.id}: binary differs from admitted hash`); + const entrySha256 = target.entry ? await hash(target.entry) : null; + if (target.entry) assert.equal(entrySha256, cell.entrySha256, `${cell.id}: entry differs from admitted hash`); + inputs.push({ ...cell, ...target, binarySha256, entrySha256 }); +} +const out = path.resolve(outName); +assert(!fs.existsSync(out), 'output must be fresh'); +for (const protectedPath of [source, ...inputs.flatMap(cell => [cell.artifact, cell.entry && path.dirname(cell.entry)]).filter(Boolean)]) { + assert(out !== protectedPath && !out.startsWith(protectedPath + path.sep), 'output must be outside source/artifacts'); +} +fs.mkdirSync(out, { recursive: true }); +fs.mkdirSync(path.join(out, 'controller-home')); +fs.mkdirSync(path.join(out, 'controller-tmp')); +const runner = path.join(path.dirname(fileURLToPath(import.meta.url)), 'core-runner.proposed.mjs'); +const receipt = { schema: 1, started: new Date().toISOString(), mainSha: config.mainSha, + admissionReceipt, admissionReceiptSha256, source, inputs, baseline: config.baseline, sweeps, + runnerSha256: await hash(runner), machine: { platform: process.platform, arch: process.arch, + kernel: os.release(), cpus: os.cpus().length, totalMemoryBytes: os.totalmem() }, + limits: ['Native architecture must also be confirmed by the operator; no emulator detection is claimed.', + 'Source/lock/plugin equivalence is an admission prerequisite recorded by P0, not inferred from this config.', + 'Own CPU/RSS cover the Gateway root; tree fields include current descendants, with reaped-child CPU. Tree RSS sums per-process RSS, not PSS; see raw snapshots for limits.', + 'Fresh isolated state per sample; preceding CLI checks warm shared code pages; not cold-cache measurements.', + 'Synthetic streaming provider; not live-model latency.'], rows: [] }; +const save = () => fs.writeFileSync(path.join(out, 'cohort.json'), JSON.stringify(receipt, null, 2) + '\n'); +save(); +let active; +let interrupted = false; +const stop = () => { interrupted = true; active?.kill('SIGTERM'); }; +process.on('SIGINT', stop); +process.on('SIGTERM', stop); +try { + // One complete warmup sweep is retained separately, then measured sweeps alternate order. + for (let sweep = -1; sweep < sweeps; sweep++) { + for (const id of sweepOrder(ids, sweep < 0 ? 0 : sweep)) { + assert(!interrupted, 'cohort interrupted'); + const cell = inputs.find(item => item.id === id); + const label = `${sweep < 0 ? 'warmup' : `sweep-${sweep + 1}`}-${id}`; + const rowOut = path.join(out, label); + const args = [runner, '--source', source, '--out', rowOut]; + if (cell.artifact) args.push('--artifact', cell.artifact); + else args.push('--runtime', cell.binary, '--entry', cell.entry); + const stdout = fs.openSync(path.join(out, `${label}.stdout`), 'w'); + const stderr = fs.openSync(path.join(out, `${label}.stderr`), 'w'); + const row = { id, sweep, warmup: sweep < 0, out: rowOut, started: new Date().toISOString(), + loadBefore: os.loadavg(), freeMemoryBefore: os.freemem() }; + receipt.rows.push(row); + save(); + active = spawn(process.execPath, args, { stdio: ['ignore', stdout, stderr], + env: { PATH: process.env.PATH, HOME: path.join(out, 'controller-home'), + TMPDIR: path.join(out, 'controller-tmp'), LANG: 'C.UTF-8', TZ: 'UTC' } }); + fs.closeSync(stdout); + fs.closeSync(stderr); + const exit = await new Promise((resolve, reject) => { + active.once('error', reject); + active.once('close', (code, signal) => resolve({ code, signal })); + }); + active = null; + Object.assign(row, exit, { finished: new Date().toISOString(), loadAfter: os.loadavg(), freeMemoryAfter: os.freemem() }); + const resultName = path.join(rowOut, 'result.json'); + if (fs.existsSync(resultName)) row.result = JSON.parse(fs.readFileSync(resultName, 'utf8')); + save(); + assert.equal(exit.code, 0, `${label} failed; no selective continuation`); + assert.equal(row.result?.qualification, 'passed'); + assert.equal(row.result.binarySha256, cell.binarySha256, `${label}: binary changed during cohort`); + assert.equal(row.result.entrySha256, cell.entrySha256, `${label}: entry changed during cohort`); + } + } + receipt.summary = summarize(receipt.rows, ids, config.baseline); + receipt.status = 'passed'; +} catch (error) { + receipt.status = 'failed'; + receipt.error = error.stack ?? String(error); + process.exitCode = 1; +} finally { + receipt.finished = new Date().toISOString(); + save(); + process.off('SIGINT', stop); + process.off('SIGTERM', stop); +} +console.log(JSON.stringify({ status: receipt.status, out })); diff --git a/scripts/openclaw-p6/app/benchmark/payload/bind-inputs.py b/scripts/openclaw-p6/app/benchmark/payload/bind-inputs.py new file mode 100644 index 000000000000..1dcbba62b4ed --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/payload/bind-inputs.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 +"""Bind only observed native files; metadata remains the admission verifier.""" +import hashlib,json,sys +from pathlib import Path +assert sys.argv[1:]==['--root-admit'], 'Explicit comparator-owner handoff required' +here=Path(__file__).resolve().parent +p=here/'native-inputs.template.json';x=json.loads(p.read_text());root=Path(x['nativeRoot']) +assert here==root/'benchmark-prep' +def load(p): return json.loads(Path(p).read_text()) +def sha(p): + h=hashlib.sha256() + with Path(p).open('rb') as f: + for b in iter(lambda:f.read(1024*1024),b''):h.update(b) + return h.hexdigest() +for ref in x['receipts'].values(): ref['sha256']=sha(ref['path']) +toolchain=load(x['receipts']['toolchain']['path']);assert toolchain['status']=='PASS' +x['node']=toolchain['buildNode'] +producer=here/'package/producer-receipt.json';receipt=load(producer) +assert receipt['status']=='package-owner-passed' and receipt['sourceCommit']==x['sourceCommit'] +assert receipt['tarball']==x['tarball']['path'] +x['tarball'].update(sha256=sha(receipt['tarball']),bytes=Path(receipt['tarball']).stat().st_size,producerReceipt={'path':str(producer),'sha256':sha(producer)}) +assert x['tarball']['sha256']==receipt['sha256'] and x['tarball']['bytes']==receipt['bytes'] +x['npm'].update(sha256=sha(x['npm']['path']),manifestSha256=sha(root/'opt/node/lib/node_modules/npm/package.json')) +assert load(root/'opt/node/lib/node_modules/npm/package.json')['version']==x['npm']['version'] +availability=load(here/'availability.json') +assert availability['status']=='restored' +x['requestedVariants']=availability['availableVariants'] +x['campaignRequestedVariants']=availability['requestedVariants'] +x['unavailableVariants']={name:value for name,value in availability['variants'].items() if value['status']=='unavailable'} +x['sourceAppExport']={'path':str(here/'availability.json'),'sha256':sha(here/'availability.json')} +for name,refs in x['variants'].items(): + if name not in x['requestedVariants']:continue + for key,ref in refs.items(): + if isinstance(ref,dict):ref['sha256']=sha(ref['path']) + assert load(refs['build']['path'])['status']=='built-unsigned',name + assert load(refs['core']['path'])['qualification']=='passed',name + assert load(refs['coreController']['path'])['status']=='phase-passed',name + refs['enabled']=True +x['decision']='benchmark-linux' +(here/'native-inputs.json').write_text(json.dumps(x,indent=2)+'\n') +print(json.dumps({'status':'bound-pending-metadata-verification','nativeInputsSha256':sha(here/'native-inputs.json')})) diff --git a/scripts/openclaw-p6/app/benchmark/payload/check-window.py b/scripts/openclaw-p6/app/benchmark/payload/check-window.py new file mode 100644 index 000000000000..0f03360fff9e --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/payload/check-window.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python3 +"""Bind a fresh host quiet receipt to the complete same-host measured budget.""" +import hashlib,json,os,time +from pathlib import Path +HERE=Path(__file__).resolve().parent +ROOT=Path('/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1') +budget=json.loads((HERE/'cohort-budget.json').read_text());q=json.loads((HERE/'quiet-admission.json').read_text()) +assert q['decision']=='run-complete-selected-cell-cohort' and q['sourceCommit']=='4fa442e332745f1f58ccedd27106abdafcf4e019' and q['nativeRoot']==str(ROOT) +assert q['hostBootId']==Path('/proc/sys/kernel/random/boot_id').read_text().strip() +assert 0<=time.time()-q['observedAtEpoch']<=300 +assert all(q[k] is True for k in ['heavyBuildsReconciled','nativeHooksReconciled','dockerAndGuestWorkReconciled','otherBenchmarksStopped','sameNativeMachineAllCells','exclusiveBenchmarkInterval']) +assert q['reservationSeconds']>=budget['requiredSeconds'] +assert budget['remainingSecondsAfterCleanupReserve']>=budget['requiredSeconds'] +assert int(os.environ['P6_DEADLINE_EPOCH'])-time.time()-1200>=budget['requiredSeconds'] +evidence=Path(q['hostReconciliation']['path']);assert ROOT in evidence.resolve().parents +assert hashlib.sha256(evidence.read_bytes()).hexdigest()==q['hostReconciliation']['sha256'] +print(json.dumps({'status':'complete-cohort-admitted','requiredSeconds':budget['requiredSeconds'],'cells':budget['cells']})) diff --git a/scripts/openclaw-p6/app/benchmark/payload/harness/analyze-zero-js.py b/scripts/openclaw-p6/app/benchmark/payload/harness/analyze-zero-js.py new file mode 100755 index 000000000000..75682e56120a --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/payload/harness/analyze-zero-js.py @@ -0,0 +1,81 @@ +#!/usr/bin/env python3 +"""Analyze strace -ff -yy output from a DIRECT AOT subtree, never from Node fixture helpers. + +A successful open is inventoried only. Positive-byte read/pread/readv and readable +file mappings are separate evidence. Any readable source mapping fails admission +conservatively; mmap success does not prove that the pages were actually touched. +""" +import argparse, hashlib, json, pathlib, re +p=argparse.ArgumentParser() +p.add_argument('--trace-dir',required=True) +p.add_argument('--out',required=True) +p.add_argument('--binary',required=True) +a=p.parse_args() +root=pathlib.Path(a.trace_dir) +assert root.is_dir(), 'trace directory missing' +source=re.compile(r'\.[cm]?[jt]sx?(?:\s+\(deleted\))?$',re.I) +call=re.compile(r'^([A-Za-z_][A-Za-z_0-9]*)\(') +resumed=re.compile(r'^<\.\.\. ([A-Za-z_][A-Za-z_0-9]*) resumed>') +reads={'read','readv','pread64','preadv','preadv2','sendfile','splice','copy_file_range'} +result={'schema':1,'traceFiles':[],'sourceOpens':[],'positiveSourceReads':[], + 'readableSourceMappings':[],'executions':[],'parseUnfinished':[],'unresolvedIoUring':[], + 'expectedBinary':str(pathlib.Path(a.binary).resolve()),'expectedBinarySeen':False, + 'claim':'No positive-byte disk JS/TS reads and no readable JS/TS mappings in the traced AOT subtree.', + 'limits':['An mmap with read permission is conservatively rejected; it does not prove a page was touched.', + 'A successful open alone is not a successful read.','Only processes actually traced by this invocation are covered.']} +operations=0 +for file in sorted(root.iterdir()): + if not file.is_file(): continue + digest=hashlib.sha256() + pending={} + with file.open('rb') as handle: + for number, raw in enumerate(handle,1): + digest.update(raw) + line=raw.decode('utf8','replace').strip() + rm=resumed.match(line) + if rm: + prefix=pending.pop(rm.group(1),None) + if prefix is None: + result['parseUnfinished'].append({'file':file.name,'line':number,'reason':'resume without start'}) + continue + line=prefix+line[rm.end():] + cm=call.match(line) + if not cm: continue + syscall=cm.group(1) + if '' in line: + pending[syscall]=line.replace('','') + continue + rm=re.search(r'\)\s+=\s+(0x[0-9a-fA-F]+|-?\d+)',line) + if not rm: continue + operations+=1 + value=int(rm.group(1),16) if rm.group(1).startswith('0x') else int(rm.group(1)) + if syscall=='execve' and value==0: + result['executions'].append({'file':file.name,'line':number,'record':line}) + executable=re.search(r'^execve\(("(?:\\.|[^"\\])*")',line) + if executable and json.loads(executable.group(1))==result['expectedBinary']: result['expectedBinarySeen']=True + if value<0: continue + if syscall=='io_uring_enter' and value>0: + result['unresolvedIoUring'].append({'file':file.name,'line':number,'record':line}) + paths=re.findall(r'\d+<([^>]+)>',line) + sources=[name for name in paths if source.search(name)] + if syscall in {'open','openat','openat2'} and value>=0: + quoted=re.findall(r'"((?:\\.|[^"\\])*)"',line) + names=[name for name in quoted if source.search(name)] + for name in names: result['sourceOpens'].append({'file':file.name,'line':number,'path':name}) + if syscall in reads and value>0 and sources: + result['positiveSourceReads'].append({'file':file.name,'line':number,'bytes':value,'paths':sources,'record':line}) + if syscall in {'mmap','mmap2'} and ('PROT_READ' in line or 'PROT_EXEC' in line) and sources and rm.group(1).startswith('0x'): + result['readableSourceMappings'].append({'file':file.name,'line':number,'paths':sources,'record':line}) + result['traceFiles'].append({'path':str(file),'sha256':digest.hexdigest()}) + for name,line in pending.items(): + # A final blocked read without completion cannot prove a successful source read; + # keep it explicit and refuse a completeness claim if a source fd was involved. + if any(source.search(name) for name in re.findall(r'\d+<([^>]+)>',line)): + result['parseUnfinished'].append({'file':file.name,'syscall':name,'record':line}) +result['operations']=operations +result['passed']=bool(result['traceFiles']) and operations>0 and result['expectedBinarySeen'] and not any(result[key] for key in ['positiveSourceReads','readableSourceMappings','parseUnfinished','unresolvedIoUring']) +pathlib.Path(a.out).write_text(json.dumps(result,indent=2)+'\n') +print(json.dumps({'passed':result['passed'],'traceFiles':len(result['traceFiles']),'operations':operations, + 'successfulSourceOpens':len(result['sourceOpens']),'positiveSourceReads':len(result['positiveSourceReads']), + 'readableSourceMappings':len(result['readableSourceMappings']),'incomplete':len(result['parseUnfinished'])})) +raise SystemExit(0 if result['passed'] else 1) diff --git a/scripts/openclaw-p6/app/benchmark/payload/harness/config-roundtrip.mjs b/scripts/openclaw-p6/app/benchmark/payload/harness/config-roundtrip.mjs new file mode 100644 index 000000000000..4ada6db6b4e4 --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/payload/harness/config-roundtrip.mjs @@ -0,0 +1,15 @@ +import assert from 'node:assert/strict'; + +// Prove a state change from the seeded false value, then restore the Gateway policy. +export async function qualifyConfigRoundtrip(command) { + await command('config-enable',['config','set','gateway.controlUi.enabled','true']); + const enabled=(await command('config-read-enabled',['config','get','gateway.controlUi.enabled'])).trim(); + try { + assert.equal(enabled,'true','config get did not observe the changed true value'); + } finally { + await command('config-disable',['config','set','gateway.controlUi.enabled','false']); + const restored=(await command('config-read-restored',['config','get','gateway.controlUi.enabled'])).trim(); + assert.equal(restored,'false','config get did not observe restored false before Gateway'); + } + return {changedTo:true,restoredTo:false}; +} diff --git a/scripts/openclaw-p6/app/benchmark/payload/harness/fixture-config.mjs b/scripts/openclaw-p6/app/benchmark/payload/harness/fixture-config.mjs new file mode 100644 index 000000000000..900b2467ee61 --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/payload/harness/fixture-config.mjs @@ -0,0 +1,28 @@ +// Pure fixture construction shared by runners and direct current-schema checks. +function baseConfig({workspace,port,token}) { + return {gateway:{mode:'local',bind:'loopback',port,auth:{mode:'token',token},controlUi:{enabled:false}}, + agents:{defaults:{workspace},entries:{main:{}}},browser:{enabled:false},update:{checkOnStart:false}}; +} +export function coreFixtureConfig({workspace,port,token,mockPort,applyMockOpenAiModelConfig,knowledgeControl=false}) { + const cfg=baseConfig({workspace,port,token}); + cfg.tools={allow:[],deny:['*']}; + applyMockOpenAiModelConfig(cfg,{mockPort,modelRef:'openai/p6-deterministic'}); + if(knowledgeControl) { + cfg.plugins={enabled:true,allow:['knowledge','openai'],slots:{memory:'knowledge'},entries:{ + openai:{enabled:true},knowledge:{enabled:true,config:{maintenance:{enabled:false}}}}}; + cfg.tools={allow:['knowledge_status','knowledge_ontology','tool_search','tool_describe','dispatch_action']}; + cfg.skills={allowBundled:[]}; + } + return cfg; +} +export function capabilityFixtureConfig({workspace,port,token,scenario,mockPort,applyMockOpenAiModelConfig}) { + const cfg=baseConfig({workspace,port,token}); + Object.assign(cfg.agents.defaults,{skipBootstrap:true,utilityModel:'',sandbox:{mode:'off'}}); + cfg.plugins={enabled:true}; + if(scenario!=='plugin') { + applyMockOpenAiModelConfig(cfg,{mockPort,modelRef:'openai/p6-capability'}); + cfg.models.mode='replace';cfg.models.catalogRefresh={enabled:false}; + cfg.tools={profile:'full',loopDetection:{enabled:true},codeMode:{enabled:scenario==='node-vm',executor:'node'},exec:{host:'gateway',mode:'full'}}; + } + return cfg; +} diff --git a/scripts/openclaw-p6/app/benchmark/payload/harness/gateway-readiness.mjs b/scripts/openclaw-p6/app/benchmark/payload/harness/gateway-readiness.mjs new file mode 100644 index 000000000000..a0a32555cafe --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/payload/harness/gateway-readiness.mjs @@ -0,0 +1,8 @@ +// Same log pattern and gateway-ready HTTP contract as openclaw-e2e-instance.sh. +export function hasGatewayReadyLog(text) { + return /\[gateway\] (ready|http server listening)/.test(text); +} +export async function isGatewayReadyResponse(response) { + if(response.status!==200)return false; + try{return (await response.json())?.ready===true;}catch{return false;} +} diff --git a/scripts/openclaw-p6/app/benchmark/payload/harness/knowledge-agent.mjs b/scripts/openclaw-p6/app/benchmark/payload/harness/knowledge-agent.mjs new file mode 100644 index 000000000000..71f75dffe383 --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/payload/harness/knowledge-agent.mjs @@ -0,0 +1,74 @@ +// Admitted agent and operator RPC proof; the existing core runner owns all processes. +import assert from 'node:assert/strict'; +import fs from 'node:fs'; +import path from 'node:path'; +export const KNOWLEDGE_MODEL='p6-deterministic'; +export const KNOWLEDGE_MARKER='P6_KNOWLEDGE_AGENT_PROOF_OK'; +const fingerprint=value=>{ + assert(value.available===true&&value.total>0,'Knowledge ontology unavailable'); + assert.match(value.fingerprint,/^[0-9a-f]{64}$/,'Knowledge fingerprint missing'); + return value.fingerprint; +}; +function readProvider(file) { + const provider=JSON.parse(fs.readFileSync(file,'utf8')); + assert.equal(provider.model,KNOWLEDGE_MODEL);assert.equal(provider.marker,KNOWLEDGE_MARKER); + assert.equal(provider.requests.length,4);assert.deepEqual(provider.errors,[]); + assert.deepEqual(provider.requests.map(row=>row.index),[0,1,2,3]); + assert(provider.requests.every(row=>row.path==='/v1/responses'&&row.stream===true&&row.model===KNOWLEDGE_MODEL)); + assert.deepEqual(provider.outputs.map(row=>row.callId),['call_p6_0','call_p6_1','call_p6_2']); + fingerprint(provider.ontology);return provider; +} +export function finalizeKnowledgeProvider(result,file) { + try { + readProvider(file);result.knowledgeProviderFinal={status:'passed',requests:4}; + } catch(error) { + result.qualification='failed'; + result.knowledgeProviderFinal={status:'failed',error:error.stack??String(error)}; + result.error??='Knowledge provider final receipt failed'; + } +} +export async function qualifyKnowledgeAgent({command,port,token,stateDir,out,providerReceipt}) { + const proof=path.join(out,'knowledge');fs.mkdirSync(proof); + const result={status:'failed',boundary:'admitted-agent-and-operator-rpc',errors:[]}; + const save=(name,value)=>fs.writeFileSync(path.join(proof,name+'.json'),JSON.stringify(value,null,2)+'\n'); + const rpc=async(method,params,label)=>{ + const text=await command('knowledge-'+label,['gateway','call',method,'--url',`ws://127.0.0.1:${port}`, + '--token',token,'--timeout','120000','--params',JSON.stringify(params),'--json']); + const value=JSON.parse(text);save(label,value);assert.equal(value.ok,true,method+' rejected');return value; + }; + const action=async(name,label)=>(await rpc('plugins.sessionAction',{pluginId:'knowledge',actionId:name,payload:{}},label)).result; + try { + result.statusBefore=await action('status','status-before'); + assert.equal(result.statusBefore.agent,'main');assert.equal(result.statusBefore.store,'unprovisioned'); + const created=await rpc('sessions.create',{agentId:'main'},'session-create'); + assert.equal(created.entry.chatType,'direct');assert.equal(created.entry.createdVia,'operator'); + assert.equal(created.runStarted,false);assert.equal(typeof created.key,'string'); + result.sessionKey=created.key; + const turn=JSON.parse(await command('knowledge-turn',['agent','--session-key',created.key, + '--message',`Inspect Knowledge ontology using its tool, then reply exactly ${KNOWLEDGE_MARKER}`, + '--json','--timeout','180'],240000));save('turn',turn); + assert.equal(turn.status,'ok');assert.equal(turn.summary,'completed'); + assert(turn.result?.payloads?.some(item=>item.text===KNOWLEDGE_MARKER),'Agent marker missing'); + const turnStderr=fs.readFileSync(path.join(out,'logs/knowledge-turn.stderr'),'utf8'); + assert(!turnStderr.toLowerCase().includes('falling back'),'Agent fell back from Gateway'); + const provider=readProvider(providerReceipt);save('provider',provider); + const agentFingerprint=fingerprint(provider.ontology); + result.statusAfter=await action('status','status-after'); + result.operatorOntology=await action('ontology','ontology-after'); + assert.equal(result.statusAfter.agent,'main');assert.equal(result.statusAfter.store,'ready'); + assert.equal(result.statusAfter.ontologyAvailable,true);assert(result.statusAfter.definitions>0); + assert.equal(result.statusAfter.ontologyFingerprint,agentFingerprint); + assert.equal(fingerprint(result.operatorOntology),agentFingerprint); + const stores=fs.realpathSync(path.join(stateDir,'knowledge/stores')); + const store=fs.realpathSync(path.join(stores,result.statusAfter.vault)); + assert.equal(path.dirname(store),stores,'Store escaped isolated state'); + result.files=['knowledge/registry.sqlite',path.relative(stateDir,path.join(store,'state.sqlite')), + path.relative(stateDir,path.join(store,'vault/vault.json'))].map(relative=>{ + const file=path.join(stateDir,relative);assert(fs.statSync(file).isFile()); + const sizeBytes=fs.statSync(file).size;assert(sizeBytes>0);return {path:relative,sizeBytes}; + }); + assert.equal(JSON.parse(fs.readFileSync(path.join(store,'vault/vault.json'),'utf8')).vaultId,result.statusAfter.vault); + result.providerRequests=4;result.status='passed-operations-only';return result; + } catch(error) {result.errors.push(error.stack??String(error));throw error;} + finally {save('result',result);} +} diff --git a/scripts/openclaw-p6/app/benchmark/payload/harness/knowledge-provider.py b/scripts/openclaw-p6/app/benchmark/payload/harness/knowledge-provider.py new file mode 100644 index 000000000000..6921cdb84c9b --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/payload/harness/knowledge-provider.py @@ -0,0 +1,147 @@ +"""Scripted Knowledge provider; the existing runtime controller owns this process.""" +import argparse +from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer +import json +from pathlib import Path +import threading +import traceback + +TARGET = "knowledge_ontology" +CALLS = (("tool_search", {"query": TARGET}), + ("tool_describe", {"id": TARGET}), + ("dispatch_action", {"id": TARGET, "args": {}})) + + +def ontology_result(value): + assert value.get("available") is True and value.get("total", 0) > 0 + fingerprint = value.get("fingerprint") + assert isinstance(fingerprint, str) and len(fingerprint) == 64 + return fingerprint + + +class ScriptedProvider: + def __init__(self, receipt, model, marker): + self.receipt = Path(receipt) + self.model = model + self.marker = marker + self.requests = [] + self.errors = [] + self.outputs = [] + self.ontology = None + self.lock = threading.Lock() + + def events(self, body, path): + index = len(self.requests) + self.requests.append({"index": index, "path": path, "model": body.get("model"), + "stream": body.get("stream")}) + assert index < 4, "Unexpected extra provider request; no retries are accepted" + assert path == "/v1/responses" and body.get("model") == self.model + assert body.get("stream") is True + if index == 0: + assert self.marker in json.dumps(body.get("input")), "Synthetic prompt marker missing" + else: + expected = f"call_p6_{index - 1}" + outputs = [item for item in body.get("input", []) + if item.get("type") == "function_call_output" and item.get("call_id") == expected] + assert len(outputs) == 1, f"Expected actual output for {expected}" + value = json.loads(outputs[0]["output"]) + self.outputs.append({"callId": expected, "value": value}) + assert not isinstance(value, dict) or not (value.get("error") or value.get("isError")) + if index == 1: + assert isinstance(value, list) and any(item.get("name") == TARGET for item in value) + elif index == 2: + assert value.get("name") == TARGET and isinstance(value.get("parameters"), dict) + else: + assert value["tool"]["name"] == TARGET + result = value["result"] + assert result.get("isError") is not True and not result.get("error") + texts = [item["text"] for item in result["content"] if item.get("type") == "text"] + assert len(texts) == 1, "Expected the actual Knowledge JSON result" + self.ontology = json.loads(texts[0]) + ontology_result(self.ontology) + if index < 3: + name, args = CALLS[index] + assert any(tool.get("name") == name for tool in body.get("tools", [])), f"{name} is unavailable" + call = {"type": "function_call", "id": f"fc_p6_{index}", + "call_id": f"call_p6_{index}", "name": name, + "arguments": json.dumps(args), "status": "completed"} + events = [ + {"type": "response.output_item.added", "output_index": 0, + "item": {**call, "arguments": "", "status": "in_progress"}}, + {"type": "response.function_call_arguments.delta", "output_index": 0, + "item_id": call["id"], "delta": call["arguments"]}, + {"type": "response.function_call_arguments.done", "output_index": 0, + "item_id": call["id"], "arguments": call["arguments"]}, + {"type": "response.output_item.done", "output_index": 0, "item": call}, + ] + output = [call] + else: + message = {"type": "message", "id": "msg_p6_knowledge", "role": "assistant", "status": "completed", + "content": [{"type": "output_text", "text": self.marker, "annotations": []}]} + events = [ + {"type": "response.output_item.added", "output_index": 0, + "item": {**message, "status": "in_progress", "content": []}}, + {"type": "response.output_text.delta", "output_index": 0, + "item_id": message["id"], "content_index": 0, "delta": self.marker}, + {"type": "response.output_text.done", "output_index": 0, + "item_id": message["id"], "content_index": 0, "text": self.marker}, + {"type": "response.output_item.done", "output_index": 0, "item": message}, + ] + output = [message] + events.append({"type": "response.completed", "response": { + "id": f"resp_p6_knowledge_{index}", "status": "completed", "output": output, + "usage": {"input_tokens": 1, "output_tokens": 1, "total_tokens": 2}}}) + return events + + def save(self): + self.receipt.write_text(json.dumps({"requests": self.requests, "outputs": self.outputs, + "ontology": self.ontology, "errors": self.errors, "usesRealProvider": False, + "model": self.model, "marker": self.marker}, indent=2) + "\n") + + def start(self): + owner = self + + class Handler(BaseHTTPRequestHandler): + def log_message(self, *_args): + pass + + def do_GET(self): + self.send_response(200 if self.path == "/health" else 404) + self.end_headers() + + def do_POST(self): + with owner.lock: + try: + body = json.loads(self.rfile.read(int(self.headers.get("Content-Length", "0")))) + events = owner.events(body, self.path) + except BaseException: + owner.errors.append(traceback.format_exc()) + owner.save() + self.send_error(400, "Synthetic Knowledge replay contract failed") + return + owner.save() + data = ("".join("data: " + json.dumps(event) + "\n\n" for event in events) + + "data: [DONE]\n\n").encode() + self.send_response(200) + self.send_header("Content-Type", "text/event-stream") + self.send_header("Content-Length", str(len(data))) + self.end_headers() + self.wfile.write(data) + + server = ThreadingHTTPServer(("127.0.0.1", 0), Handler) + thread = threading.Thread(target=server.serve_forever, daemon=True) + thread.start() + return server, thread + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--receipt", required=True) + parser.add_argument("--model", required=True) + parser.add_argument("--marker", required=True) + args = parser.parse_args() + provider = ScriptedProvider(args.receipt, args.model, args.marker) + provider.save() + server, thread = provider.start() + print(f"mock-openai listening on {server.server_port}", flush=True) + thread.join() diff --git a/scripts/openclaw-p6/app/benchmark/payload/harness/measurement-owner.py b/scripts/openclaw-p6/app/benchmark/payload/harness/measurement-owner.py new file mode 100644 index 000000000000..f198a7689791 --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/payload/harness/measurement-owner.py @@ -0,0 +1,472 @@ +#!/usr/bin/env python3 +"""Admitted native P6 standalone build. Default is read-only preflight/dry-run.""" +import argparse +import datetime +import hashlib +import json +import os +from pathlib import Path +import platform +import re +import runpy +import shutil +import signal +import subprocess +import sys +import traceback + +BUN_PIN = 'fd40ba44187c721ee023062fa153a6a27560e6b1' +WEBKIT_PIN = 'aaa690bfbf34c9d50775716ac2fc3c7d0573e0b8' +CB_BUN_PIN = 'b838e73072227c2652a41c689299284f1965cdc6' +COHORTS = { + 'baseline-fd40': {'bun': BUN_PIN, 'webkit': WEBKIT_PIN, 'profiles': { + 'standard': {'shadowRealm': True, 'hardened': False}, + 'c2': {'shadowRealm': False, 'hardened': False}, + 'c2-linux-hardened': {'shadowRealm': False, 'hardened': True}, + }}, + 'cb-b838': {'bun': CB_BUN_PIN, 'webkit': WEBKIT_PIN, 'profiles': { + 'cb-standard': {'shadowRealm': True, 'hardened': False}, + 'cb-compat': {'shadowRealm': False, 'hardened': False}, + 'cb-linux-hardened': {'shadowRealm': False, 'hardened': True}, + }}, +} +MEASURE_SHA = '2fa495f4727a351f6cee078b403ac064610ce90ed339311f55c40a567463e4b7' +FLAGS = { + 'js': ['--compile-aot', '--explain=statistics'], + 'c2': ['--compile-aot', '--no-compile-function-source', + '--disallow-code-generation-from-strings', '--explain=statistics'], + 'ts': ['--aot-source', '--explain=statistics'], + 'strong': ['--compile-aot', '--no-compile-function-source', + '--disallow-code-generation-from-strings', '--explain=statistics'], + 'jit': [], +} +PROFILES = {'js': 'standard', 'ts': 'standard', 'jit': 'standard', + 'c2': 'c2', 'strong': 'c2-linux-hardened'} + + +def now(): + return datetime.datetime.now(datetime.timezone.utc).isoformat() + + +def require(condition, message): + if not condition: + raise ValueError(message) + + +def sha(filename): + digest = hashlib.sha256() + with Path(filename).open('rb') as stream: + for data in iter(lambda: stream.read(8 << 20), b''): + digest.update(data) + return digest.hexdigest() + + +def load(filename): + return json.loads(Path(filename).read_text()) + + +def write(filename, value): + with Path(filename).open('x') as stream: + json.dump(value, stream, indent=2) + stream.write('\n') + + +def beneath(root, value): + path = Path(value) + require(path.is_absolute(), f'Absolute path required: {value}') + path = path.resolve() + require(path != root and root in path.parents, f'Path must be inside P6 root {root}: {path}') + return path + + +def git(source, *args): + result = subprocess.run(['git', '-c', f'safe.directory={source}', '-C', str(source), *args], + env={'PATH': '/usr/local/bin:/usr/bin:/bin', 'HOME': str(source.parent), + 'GIT_CONFIG_NOSYSTEM': '1'}, capture_output=True, text=True) + require(result.returncode == 0, f'git {args[0]} failed: {result.stderr.strip()}') + return result.stdout.strip() + + +def native_elf(executable, arch): + require(os.access(executable, os.X_OK), f'Not executable: {executable}') + with executable.open('rb') as stream: + header = stream.read(20) + machine = 183 if arch == 'arm64' else 62 + require(header[:6] == b'\x7fELF\x02\x01' and int.from_bytes(header[18:20], 'little') == machine, + f'ELF architecture differs from native Linux target: {executable}') + + +class BuildInterrupted(Exception): + pass + + +def interrupted(signum, _frame): + # subprocess/select treats InterruptedError as a syscall retry, not cancellation. + raise BuildInterrupted(f'Build driver interrupted by signal {signum}') + + +def run_probe(command, *, env, cwd, timeout): + child = subprocess.Popen(command, env=env, cwd=cwd, stdin=subprocess.DEVNULL, + stdout=subprocess.PIPE, stderr=subprocess.PIPE, + text=True, start_new_session=True) + try: + stdout, stderr = child.communicate(timeout=timeout) + return subprocess.CompletedProcess(command, child.returncode, stdout, stderr) + finally: + if child.poll() is None: + try: + os.killpg(child.pid, signal.SIGKILL) + except ProcessLookupError: + pass + child.communicate() + + +def admitted(admission): + require(admission.get('schemaVersion') == 1 and admission.get('lane') == 'P6' and + admission.get('decision') == 'build-linux', 'Explicit root P6 build admission required') + + +def cohort(name): + require(name in COHORTS, 'Explicit supported compiler/reference cohort required') + return COHORTS[name] + + +def retained_capabilities(root, admission, compiler_cohort, variant): + allow = admission.get('compileTrimAllow') + if compiler_cohort == 'baseline-fd40' or variant == 'jit': + require(allow is None, 'Baseline and untrimmed JIT use no retained-capability option') + return None, None + require(allow in [['run'], ['run', 'jit']], 'CB AOT requires explicit compileTrimAllow:[run] or [run,jit]') + reason = None + if 'jit' in allow: + proof = admission.get('jitRetentionProof', {}) + require(isinstance(proof.get('reason'), str) and proof['reason'].strip(), + 'JIT retention requires a named observed runtime failure') + filename = beneath(root, proof['failureReceipt']) + require(sha(filename) == proof['sha256'], 'JIT-retention failure receipt changed') + reason = {**proof, 'failureReceipt': str(filename)} + return allow, reason + + +def source_retention_contract(node, source, root, output, flags, plugins, allow): + if allow is None: + return None + script = ('const owner=await import(process.argv[1]); ' + 'console.log(JSON.stringify(owner.parseStandaloneArguments(process.argv.slice(2))));') + checked = run_probe([str(node), '--no-warnings', '--input-type=module', '--eval', script, + (source / 'scripts/lib/bun-standalone-contract.mjs').as_uri(), str(output), + *flags, '--trim-allow', ','.join(allow), '--plugins', ','.join(plugins)], + cwd=root, env={'PATH': f'{node.parent}:/usr/bin:/bin', 'HOME': str(root), + 'TMPDIR': str(root), 'LANG': 'C.UTF-8'}, timeout=30) + require(checked.returncode == 0, + 'Retained-capability build blocked: admitted landed source must implement --trim-allow. ' + + checked.stderr.strip()) + parsed = json.loads(checked.stdout) + trim = parsed.get('aotCompileOptions', {}).get('trim') + require(parsed.get('mode') == 'aot' and isinstance(trim, dict) and trim.get('allow') == allow and + bool(parsed.get('source')) == ('--aot-source' in flags), + 'Retained-capability build blocked: source parser did not preserve the requested allow list') + return parsed + + +def execution_paths(root, admission, reserved_receipt=None): + source = beneath(root, admission['source']) + output = beneath(root, admission['output']) + receipt = beneath(root, admission['receiptDirectory']) + for path in [output, receipt]: + if path != reserved_receipt: + require(not path.exists(), f'Fresh path required: {path}') + require(source not in path.parents and source != path, 'Output/receipt must be outside source') + require(output != receipt and output not in receipt.parents and receipt not in output.parents, + 'Artifact and receipt directories must be separate') + return source, output, receipt + + +def source_proof(source, cut): + commit = cut['commit'] + require(re.fullmatch('[0-9a-f]{40}', commit), 'Full Linux source commit required') + require(cut['status'] == 'landed-main', 'Linux cut must explicitly be landed-main') + require(cut['mainRef'] in ['refs/remotes/origin/main', 'refs/heads/main'], 'Explicit main ref required') + require(re.fullmatch('[0-9a-f]{40}', cut['mainRefSha']), 'Full observed-main SHA required') + require(isinstance(cut['frozenAt'], str) and cut['frozenAt'], 'Root campaign freeze timestamp required') + datetime.datetime.fromisoformat(cut['frozenAt'].replace('Z', '+00:00')) + require(git(source, 'rev-parse', 'HEAD') == commit, 'Source HEAD differs from admitted Linux cut') + require(git(source, 'rev-parse', cut['mainRef']) == cut['mainRefSha'], 'Local main ref differs from admission') + git(source, 'merge-base', '--is-ancestor', commit, cut['mainRefSha']) + require(not git(source, 'status', '--porcelain', '--untracked-files=no'), 'Tracked source is dirty') + ancestors = cut['requiredAncestors'] + require(isinstance(ancestors, list), 'requiredAncestors must be explicit') + for ancestor in ancestors: + require(re.fullmatch('[0-9a-f]{40}', ancestor), 'Full required-ancestor SHA required') + git(source, 'merge-base', '--is-ancestor', ancestor, commit) + info = load(source / 'dist/build-info.json') + package = load(source / 'package.json') + require(info.get('commit') == commit, 'dist/build-info.json belongs to another source commit') + require(info.get('version') == package['version'], 'dist/build-info.json version is stale') + require((source / 'dist/cli-startup-metadata.json').is_file(), 'Complete pnpm build first') + return {'commit': commit, 'mainRef': cut['mainRef'], 'mainRefSha': cut['mainRefSha'], + 'frozenAt': cut['frozenAt'], 'requiredAncestors': ancestors, + 'version': package['version'], 'distBuildInfo': info, + 'hashes': {name: sha(source / name) for name in ['dist/build-info.json', + 'package.json', 'pnpm-lock.yaml', 'scripts/build-bun-standalone.mjs', + 'scripts/lib/bun-standalone-contract.mjs', + 'scripts/lib/bun-standalone-source-parser.mjs']}} + + +def prepare(root, admission_file, measurement, reserved_receipt=None): + require(platform.system() == 'Linux', 'Driver requires native Linux') + arch = {'aarch64': 'arm64', 'x86_64': 'x64'}.get(platform.machine()) + require(arch, 'Only Linux arm64/x64 supported') + admission = load(admission_file) + admitted(admission) + variant = admission['variant'] + require(variant in FLAGS, 'Unknown variant') + source, output, receipt = execution_paths(root, admission, reserved_receipt) + proof = source_proof(source, admission['linuxCut']) + require(proof['hashes']['dist/build-info.json'] == admission['distBuildInfoSha256'], + 'Admitted dist/build-info.json bytes differ') + reference = admission['p0Reference'] + reference_cohort = cohort(reference.get('cohort')) + index = beneath(root, reference['manifest']) + require(index.name == 'P0-artifacts.json' and index.is_file(), 'P0 manifest clone is required') + require(sha(index) == reference['manifestSha256'], 'P0 manifest clone differs from admission') + state = load(index) + require(state.get('schemaVersion') == 1 and state.get('lane') == 'P0', 'Invalid P0 manifest') + entries = [row for row in state['artifacts'] if row['variant'] == reference['variant'] and + row['sourceCommit'] == reference['sourceCommit'] and + row['sha256'] == reference['executableSha256']] + require(len(entries) == 1, 'P0 reference does not identify one immutable artifact') + p0 = entries[0] + require(p0.get('signed') is True, 'P0 reference must be an indexed signed artifact') + require(p0['compilerPins']['bun'] == reference_cohort['bun'] and + p0['compilerPins']['webkit'] == reference_cohort['webkit'], + 'P0 reference uses different compiler pins') + if reference['cohort'] == 'cb-b838': + require(p0['compilerPins']['shadowRealm'] == 'retained' and + p0['compilerPins']['historicalC2Equivalent'] is False, + 'CB P0 reference must preserve its retained-ShadowRealm distinction') + require(p0['sourceStatus'] in ['main', 'main-plus-open-pr'], 'Unknown P0 source status') + if p0['sourceStatus'] == 'main': + require(p0['mainSha'] == p0['sourceCommit'], 'P0 main artifact has inconsistent identity') + if p0['sourceCommit'] != proof['commit']: + require(admission['linuxCut']['requiredAncestors'] and + admission['linuxCut'].get('p0DifferenceRationale', '').strip(), + 'Different P0/Linux cuts require explicit root rationale and landed-repair ancestry') + compiler = admission['compiler'] + selected_cohort = cohort(compiler.get('cohort')) + executable = beneath(root, compiler['path']) + allowed_profiles = [PROFILES[variant]] if compiler['cohort'] == 'baseline-fd40' else ( + ['cb-linux-hardened'] if variant == 'strong' else + ['cb-standard', 'cb-compat'] if variant == 'c2' else ['cb-standard']) + require(compiler['profile'] in allowed_profiles, 'Compiler engine profile differs from cohort/variant') + expected_features = selected_cohort['profiles'][compiler['profile']] + require(compiler.get('engineFeatures') == expected_features and + all(type(value) is bool for value in compiler['engineFeatures'].values()), + 'Compiler engine features differ from the explicit cohort/profile') + require(compiler['bunCommit'] == selected_cohort['bun'] and + compiler['webkitCommit'] == selected_cohort['webkit'], + 'Compiler provenance uses different pins') + require(sha(executable) == compiler['sha256'], 'Compiler bytes differ from admission') + native_elf(executable, arch) + node = admission['buildNode'] + node_path = beneath(root, node['path']) + require(node_path.name == 'node', 'Build Node must be named node for the source parser fallback') + require(sha(node_path) == node['sha256'], 'Build Node bytes differ from admission') + native_elf(node_path, arch) + strip_probe = '''import {stripTypeScriptTypes} from 'node:module'; +const input='const f = true ? async (x: number): Promise => x : null;'; +const output=stripTypeScriptTypes(input,{mode:'strip'}); +console.log(JSON.stringify({platform:process.platform,arch:process.arch,version:process.version, + offsetsPreserved:output.length===input.length,typesRemoved:!output.includes('number')}));''' + probed = run_probe([str(node_path), '--no-warnings', '--input-type=module', '--eval', strip_probe], + cwd=root, env={'PATH': f'{node_path.parent}:/usr/bin:/bin', 'HOME': str(root), + 'TMPDIR': str(root), 'LANG': 'C.UTF-8'}, timeout=30) + require(probed.returncode == 0, f'Build Node type-stripper preflight failed: {probed.stderr}') + node_probe = json.loads(probed.stdout) + require(node_probe['platform'] == 'linux' and node_probe['arch'] == arch and + node_probe['offsetsPreserved'] and node_probe['typesRemoved'], + f'Build Node type-stripper contract failed: {node_probe}') + plugins_file = beneath(root, admission['pluginsFile']) + require(sha(plugins_file) == admission['pluginsSha256'], 'Plugin selection differs from admission') + plugins = load(plugins_file) + require(isinstance(plugins, list) and plugins and plugins == sorted(set(plugins)) and + all(isinstance(item, str) and re.fullmatch('[a-z0-9][a-z0-9._-]*', item) for item in plugins), + 'Plugin IDs must be a nonempty sorted unique JSON array') + allow, retention_proof = retained_capabilities(root, admission, compiler['cohort'], variant) + source_contract = source_retention_contract(node_path, source, root, output, FLAGS[variant], plugins, allow) + retention_flags = ['--trim-allow', ','.join(allow)] if allow is not None else [] + measurement = beneath(root, str(measurement)) + require(sha(measurement) == MEASURE_SHA, 'Reviewed measurement utility bytes changed') + command = ['/usr/bin/nice', '-n', '10', str(executable), '--no-env-file', '--no-install', + str(source / 'scripts/build-bun-standalone.mjs'), str(output), + *FLAGS[variant], *retention_flags, '--plugins', ','.join(plugins)] + timeout = admission.get('timeoutSeconds', 12 * 3600) + require(type(timeout) is int and 1 <= timeout <= 24 * 3600, 'Invalid build timeout') + return {'operation': 'build-linux', 'variant': variant, 'platform': 'linux', 'arch': arch, + 'kernel': platform.release(), 'source': str(source), 'sourceProof': proof, + 'linuxCut': admission['linuxCut'], 'p0Reference': p0, + 'p0ReferenceCohort': reference['cohort'], + 'p0ManifestClone': str(index), 'p0ManifestSha256': reference['manifestSha256'], + 'compiler': compiler, 'buildNode': node, 'buildNodeProbe': node_probe, + 'compileTrimAllow': allow, 'jitRetentionProof': retention_proof, + 'sourceRetentionContract': source_contract, + 'policyLabel': '/'.join([compiler['cohort'], compiler['profile'], variant, + '+'.join(allow) if allow is not None else 'default']), + 'c2ApplicationHardening': variant in ['c2', 'strong'], + 'historicalC2Equivalent': variant == 'c2' and compiler['cohort'] == 'baseline-fd40', + 'plugins': plugins, 'pluginsFile': str(plugins_file), + 'pluginsSha256': admission['pluginsSha256'], 'output': str(output), + 'receiptDirectory': str(receipt), 'command': command, + 'measurementUtility': str(measurement), 'measurementUtilitySha256': MEASURE_SHA, + 'admissionFile': str(admission_file), 'admissionSha256': sha(admission_file), + 'driverSha256': sha(__file__), + 'artifactCheckerSha256': sha(Path(__file__).with_name('artifact-contract.mjs')), + 'buildEnvironmentOverrides': {'UV_THREADPOOL_SIZE': '2'}, + 'timeoutSeconds': timeout} + + +def reject_competing_builds(): + active = [] + for item in Path('/proc').iterdir(): + if not item.name.isdigit() or int(item.name) == os.getpid(): + continue + try: + argv = (item / 'cmdline').read_bytes().decode(errors='replace').rstrip('\0').split('\0') + except (FileNotFoundError, ProcessLookupError, PermissionError): + continue + builder = any(Path(arg).name == 'build-bun-standalone.mjs' for arg in argv) + bun_compile = (len(argv) > 1 and Path(argv[0]).name == 'bun' and argv[1] == 'build' and + any(arg.startswith(('--compile', '--aot')) for arg in argv[2:])) + if builder or bun_compile: + active.append({'pid': int(item.name), 'argv': argv}) + require(not active, f'Competing actual standalone compiler process: {active}') + + +def environment(receipt, compiler, node): + state = receipt / 'state' + for name in ['home', 'tmp', 'cache', 'workspace']: + (state / name).mkdir(parents=True) + return {'PATH': f'{Path(node).parent}:{Path(compiler).parent}:/usr/local/bin:/usr/bin:/bin', + 'HOME': str(state / 'home'), 'TMPDIR': str(state / 'tmp'), + 'TMP': str(state / 'tmp'), 'TEMP': str(state / 'tmp'), + 'XDG_CACHE_HOME': str(state / 'cache'), 'LANG': 'C.UTF-8', 'LC_ALL': 'C.UTF-8', + 'SHELL': '/bin/bash', 'USER': 'p6-synthetic', 'NO_COLOR': '1', 'TERM': 'dumb', + 'CI': '1', 'UV_THREADPOOL_SIZE': '2', 'NODE_DISABLE_COMPILE_CACHE': '1', + 'OPENCLAW_STATE_DIR': str(state), 'OPENCLAW_CONFIG_PATH': str(state / 'openclaw.json'), + 'OPENCLAW_NO_RESPAWN': '1', 'OPENCLAW_SUPERVISOR_MODE': 'external', + 'OPENCLAW_SERVICE_REPAIR_POLICY': 'external'} + + +def measure(plan, env, receipt): + # Execute the reviewed owner in this process so SIGINT/TERM raises through + # its existing finally block and kills/reaps its isolated compiler group. + old_argv, old_env, old_cwd = sys.argv, dict(os.environ), Path.cwd() + old_signals = {sig: signal.signal(sig, interrupted) for sig in [signal.SIGINT, signal.SIGTERM]} + try: + sys.argv = [plan['measurementUtility'], '--label', plan['variant'], '--out', + str(receipt / 'measurement'), '--timeout', str(plan['timeoutSeconds']), + *(['--cleanup-grace-seconds', str(plan['cleanupGraceSeconds'])] + if 'cleanupGraceSeconds' in plan else []), '--', *plan['command']] + os.environ.clear() + os.environ.update(env) + os.chdir(plan['source']) + try: + runpy.run_path(plan['measurementUtility'], run_name='__main__') + except SystemExit as exit_result: + code = exit_result.code + if isinstance(code, int) and (code == 124 or code < 0 or code >= 128): + raise + require(code in [None, 0], f'Build command exited {code}') + finally: + os.chdir(old_cwd) + os.environ.clear() + os.environ.update(old_env) + sys.argv = old_argv + for sig, handler in old_signals.items(): + signal.signal(sig, handler) + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--root', required=True, help='P6 external-volume root as mounted on Linux') + parser.add_argument('--admission', required=True) + parser.add_argument('--measure-command', required=True) + parser.add_argument('--run', action='store_true') + args = parser.parse_args() + root = Path(args.root).resolve(strict=True) + admission_file = beneath(root, args.admission) + if not args.run: + old_signals = {sig: signal.signal(sig, interrupted) for sig in [signal.SIGINT, signal.SIGTERM]} + try: + plan = prepare(root, admission_file, Path(args.measure_command)) + print(json.dumps({'status': 'dry-run', **plan}, indent=2)) + finally: + for sig, handler in old_signals.items(): + signal.signal(sig, handler) + return + admission = load(admission_file) + admitted(admission) + _, _, receipt = execution_paths(root, admission) + receipt.mkdir(parents=True) + result = {'status': 'failed', 'startedAt': now(), 'phase': 'preflight', + 'admissionFile': str(admission_file), 'admissionSha256': sha(admission_file), + 'applicationQualified': False} + old_signals = {sig: signal.signal(sig, interrupted) for sig in [signal.SIGINT, signal.SIGTERM]} + try: + plan = prepare(root, admission_file, Path(args.measure_command), reserved_receipt=receipt) + result['plan'] = plan + require(shutil.disk_usage(root).free >= 25 * 1024**3, 'Linux volume below 25 GiB floor') + reject_competing_builds() + env = environment(receipt, plan['compiler']['path'], plan['buildNode']['path']) + result['phase'] = 'compiler-identity' + identity = run_probe([plan['compiler']['path'], '--no-env-file', '--no-install', '-p', + 'JSON.stringify({platform:process.platform,arch:process.arch,bun:Bun.revision,webkit:process.versions.webkit})'], + env=env, cwd=receipt / 'state/home', timeout=30) + result['compilerIdentityProbe'] = {'exitCode': identity.returncode, + 'stdout': identity.stdout, 'stderr': identity.stderr} + require(identity.returncode == 0, f'Compiler identity probe failed: {identity.stderr}') + identity = json.loads(identity.stdout) + require(identity == {'platform': 'linux', 'arch': plan['arch'], + 'bun': plan['compiler']['bunCommit'], 'webkit': plan['compiler']['webkitCommit']}, + f'Compiler runtime provenance mismatch: {identity}') + result['compilerRuntimeIdentity'] = identity + write(receipt / 'plan.json', plan) + reject_competing_builds() + result['phase'] = 'build' + measure(plan, env, receipt) + result['measurement'] = load(receipt / 'measurement/receipt.json') + result['phase'] = 'post-build-source-check' + require(source_proof(Path(plan['source']), plan['linuxCut']) == plan['sourceProof'], + 'Source or package build identity changed during compilation') + require(sha(admission_file) == plan['admissionSha256'] and + sha(plan['pluginsFile']) == plan['pluginsSha256'] and + sha(plan['buildNode']['path']) == plan['buildNode']['sha256'] and + sha(plan['compiler']['path']) == plan['compiler']['sha256'], + 'Admitted inputs changed during build') + result['phase'] = 'artifact-contract' + inspector = Path(__file__).with_name('artifact-contract.mjs') + check = run_probe(['/usr/bin/nice', '-n', '10', plan['compiler']['path'], + '--no-env-file', '--no-install', str(inspector), + str(receipt / 'plan.json')], env=env, + cwd=receipt / 'state/home', timeout=1800) + (receipt / 'artifact-contract.stdout').write_text(check.stdout) + (receipt / 'artifact-contract.stderr').write_text(check.stderr) + require(check.returncode == 0, f'Artifact contract failed: {check.stderr}') + result['artifact'] = json.loads(check.stdout) + result['status'] = 'built-unsigned' + result['phase'] = 'complete' + except BaseException: + result['error'] = traceback.format_exc() + if (receipt / 'measurement/receipt.json').exists(): + result['measurement'] = load(receipt / 'measurement/receipt.json') + raise + finally: + result['finishedAt'] = now() + write(receipt / 'result.json', result) + print(json.dumps({'status': result['status'], 'phase': result['phase'], 'receipt': str(receipt)})) + for sig, handler in old_signals.items(): + signal.signal(sig, handler) + + +if __name__ == '__main__': + main() diff --git a/scripts/openclaw-p6/app/benchmark/payload/harness/process-stop.mjs b/scripts/openclaw-p6/app/benchmark/payload/harness/process-stop.mjs new file mode 100644 index 000000000000..877e3fc0fc47 --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/payload/harness/process-stop.mjs @@ -0,0 +1,66 @@ +// Canonical P6 process-stop owner; payload copies are generated by sync-process-stop.py. +import assert from 'node:assert/strict'; +import path from 'node:path'; +import { pathToFileURL } from 'node:url'; + +export async function readGatewayStopBudget(source) { + const filename = path.join(source, 'gateway-shutdown-budget.mjs'); + const policy = await import(pathToFileURL(filename).href); + const shutdownTimeoutMs = policy.GATEWAY_SHUTDOWN_TIMEOUT_MS; + const serviceStopTimeoutMs = policy.GATEWAY_SERVICE_STOP_TIMEOUT_MS; + assert(Number.isSafeInteger(shutdownTimeoutMs) && shutdownTimeoutMs > 0, + 'Source must export a positive GATEWAY_SHUTDOWN_TIMEOUT_MS'); + assert(Number.isSafeInteger(serviceStopTimeoutMs) && serviceStopTimeoutMs >= shutdownTimeoutMs, + 'Source must export a GATEWAY_SERVICE_STOP_TIMEOUT_MS covering shutdown'); + return { source: filename, shutdownTimeoutMs, serviceStopTimeoutMs }; +} + +const stopping = new WeakMap(); +function signalGroup(child, signal) { + try { process.kill(-child.pid, signal); } + catch (error) { if (error.code !== 'ESRCH') throw error; } +} +async function exitedWithin(child, timeoutMs) { + let timer; + try { + return await Promise.race([child.done.then(() => true), + new Promise(resolve => { timer = setTimeout(() => resolve(false), timeoutMs); })]); + } finally { clearTimeout(timer); } +} + +export function stopProcess(child, { graceMs = 10_000, killWaitMs = 5_000 } = {}) { + if (!child?.pid) return Promise.resolve(null); + if (stopping.has(child)) return stopping.get(child); + const operation = (async () => { + const started = performance.now(); + const receipt = { pid: child.pid, graceMs, killWaitMs, sentTerm: false, forced: false }; + if (child.exitCode === null && child.signalCode === null) { + signalGroup(child, 'SIGTERM'); + receipt.sentTerm = true; + } + receipt.exitObserved = await exitedWithin(child, graceMs); + if (!receipt.exitObserved) { + receipt.forced = true; + signalGroup(child, 'SIGKILL'); + receipt.exitObserved = await exitedWithin(child, killWaitMs); + } + return { ...receipt, elapsedMs: performance.now() - started, + exitCode: child.exitCode, exitSignal: child.signalCode }; + })(); + stopping.set(child, operation); + return operation; +} + +export function shutdownFailure(stops, gatewayExit) { + if (stops.some(stop => stop.forced || !stop.exitObserved)) return 'Process required forced stop'; + if (gatewayExit && (gatewayExit.code !== 0 || gatewayExit.signal !== null)) { + return 'Gateway did not exit normally'; + } + return null; +} + +if (import.meta.main) { + assert.equal(process.argv[2], '--gateway-budget'); + assert.equal(process.argv.length, 4, 'Usage: node process-stop.mjs --gateway-budget SOURCE'); + console.log(JSON.stringify(await readGatewayStopBudget(path.resolve(process.argv[3])))); +} diff --git a/scripts/openclaw-p6/app/benchmark/payload/measure-command.reference.py b/scripts/openclaw-p6/app/benchmark/payload/measure-command.reference.py new file mode 100755 index 000000000000..76c458785259 --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/payload/measure-command.reference.py @@ -0,0 +1,106 @@ +#!/usr/bin/env python3 +"""Linux only; collect direct-executable wall/CPU/peak RSS without asserting application correctness.""" +import argparse, datetime, hashlib, json, math, os, pathlib, platform, signal, subprocess, time +p=argparse.ArgumentParser() +p.add_argument('--label',required=True) +p.add_argument('--out',required=True) +p.add_argument('--timeout',type=float,default=180) +p.add_argument('--cleanup-grace-seconds',type=float) +p.add_argument('command',nargs=argparse.REMAINDER) +a=p.parse_args() +cmd=a.command[1:] if a.command[:1]==['--'] else a.command +if platform.system()!='Linux' or not cmd: p.error('requires Linux and a command after --') +if a.cleanup_grace_seconds is not None and not (math.isfinite(a.cleanup_grace_seconds) and 0 < a.cleanup_grace_seconds <= 3600): + p.error('cleanup grace must be finite and between 0 and 3600 seconds') +out=pathlib.Path(a.out).resolve() +out.mkdir(parents=True,exist_ok=False) +timefile=out/'time.txt' +exe=pathlib.Path(cmd[0]) +receipt={'label':a.label,'at':datetime.datetime.now(datetime.timezone.utc).isoformat(), + 'arch':platform.machine(),'kernel':platform.release(),'command':cmd, + 'executableSha256':hashlib.file_digest(exe.open('rb'),'sha256').hexdigest() if exe.is_file() else None, + 'scope':'GNU time -v command plus reaped descendants; not exclusive gateway CPU'} +def signal_group(pgid, sig): + try: os.killpg(pgid,sig) + except ProcessLookupError: pass + +def live_group(pgid): + # An orphaned zombie can retain the group ID under a non-reaping container + # init; it has no work left to stop and must not trigger a false forced kill. + for process in pathlib.Path('/proc').iterdir(): + if not process.name.isdigit():continue + try: fields=(process/'stat').read_text().rsplit(') ',1)[1].split() + except (FileNotFoundError,ProcessLookupError):continue + if int(fields[2])==pgid and fields[0] not in ['Z','X']:return True + return False + +def stop_group(child, grace=5): + # GNU time may exit on TERM while its workload ignores it. Keep group custody + # for the full bounded grace, then send KILL independently of wrapper state. + signal_group(child.pid,signal.SIGTERM) + deadline=time.monotonic()+grace + while time.monotonic() JSON.parse(fs.readFileSync(filename, 'utf8')); +const write = (filename, value) => fs.writeFileSync(filename, JSON.stringify(value, null, 2) + '\n', { flag: 'wx' }); +const hash = async filename => { + const digest = createHash('sha256'); + for await (const bytes of fs.createReadStream(filename)) digest.update(bytes); + return digest.digest('hex'); +}; +const inputs = read(path.join(here, 'native-inputs.json')); +const inputsSha256 = await hash(path.join(here, 'native-inputs.json')); +assert.equal(inputs.decision, 'benchmark-linux', 'Template is not admitted; bind actual native facts first'); +assert.equal(inputs.schemaVersion, 1); +assert.equal(inputs.sourceCommit, CUT); +assert.equal(inputs.nativeRoot, ROOT); +assert.equal(inputs.nativeSource, ROOT + '/source'); +assert.equal(process.platform, 'linux'); +assert.equal(process.arch, 'x64'); +assert.equal(process.umask(), 0o077, 'Set umask 077 before creating any test state'); +assert.equal(fs.realpathSync(here), ROOT + '/benchmark-prep'); +const root = ROOT, source = ROOT + '/source', work = here + '/work'; +const installed = work + '/installed/node_modules/openclaw'; +const entry = installed + '/openclaw.mjs'; +const [action] = process.argv.slice(2); +assert(['plan', 'installed', 'cohort', 'verify', 'baseline'].includes(action)); +for (const [name, digest] of Object.entries(read(here + '/payload-manifest.json'))) { + assert.match(digest, /^[a-f0-9]{64}$/); + assert.equal(await hash(path.join(here, name)), digest, name); +} +const git = (...args) => execFileSync('git', ['-C', source, ...args], { encoding: 'utf8' }).trim(); +assert.equal(git('rev-parse', 'HEAD'), CUT); +assert.equal(git('status', '--porcelain', '--untracked-files=no'), '', 'Tracked source changed'); +const sourceContract = read(here + '/source-contract.json'); +assert.equal(sourceContract.sourceCommit, CUT); +for (const [name, digest] of Object.entries(sourceContract.files)) assert.equal(await hash(source + '/' + name), digest, name); +const npm = inputs.npm; +assert.equal(npm.path, root + '/opt/node/lib/node_modules/npm/bin/npm-cli.js'); +assert.equal(npm.version, '11.20.0'); +assert.equal(await hash(npm.path), npm.sha256); +assert.equal(await hash(root + '/opt/node/lib/node_modules/npm/package.json'), npm.manifestSha256); +assert.equal(read(root + '/opt/node/lib/node_modules/npm/package.json').version, npm.version); +const policy = read(here + '/project-package.manifest.json'); +const policyText = fs.readFileSync(source + '/pnpm-workspace.yaml', 'utf8').split('\nallowBuilds:\n')[1].split('\n\n')[0]; +const allowed = Object.fromEntries(policyText.trimEnd().split('\n').map(line => { + const match = line.match(/^ (?:"([^"]+)"|([^:]+)): (true|false)$/); + assert(match, 'Unexpected source allowBuilds entry: ' + line); + return [match[1] ?? match[2], match[3] === 'true']; +})); +assert.equal(allowed.openclaw, true); +assert.deepEqual(policy.allowScripts, { ...allowed, ['file:' + inputs.tarball.path]: true }); +const installCommand = [nodePath(), npm.path, 'install', '--prefix', work + '/installed', inputs.tarball.path, + '--strict-allow-scripts', '--no-audit', '--no-fund', '--foreground-scripts', '--fetch-retries=0']; +function nodePath() { return root + '/opt/node/bin/node'; } + +async function receipt(ref, exactPath) { + assert(ref && typeof ref.path === 'string' && path.isAbsolute(ref.path)); + assert(ref.path.startsWith(root + '/'), 'Receipt must remain inside the isolated native root'); + if (exactPath) assert.equal(ref.path, exactPath); + assert.match(ref.sha256, /^[a-f0-9]{64}$/); + assert.equal(await hash(ref.path), ref.sha256, ref.path); + return read(ref.path); +} +const toolchain = await receipt(inputs.receipts.toolchain, root + '/prep-receipts/toolchain/result.json'); +const plugins = await receipt(inputs.receipts.plugins, root + '/prep-receipts/plugins/result.json'); +const compilers = await receipt(inputs.receipts.compilerRecords, root + '/admission-inputs/compiler-records.json'); +assert.equal(toolchain.status, 'PASS'); +assert.equal(plugins.status, 'PASS'); +assert.equal(plugins.sourceCommit, CUT); +const node = toolchain.buildNode, bun = compilers['cb-standard']; +assert.equal(node.path, root + '/opt/node/bin/node'); +assert.deepEqual(inputs.node, node, 'Node must be copied from actual native toolchain receipt'); +assert.equal(await hash(node.path), node.sha256); +assert.equal(node.version, '26.12.1'); +assert.equal(bun.path, root + '/compilers/standard/bun'); +assert.equal(bun.cohort, 'rd-p6-150c'); +assert.equal(bun.bunCommit, '150c9620c53710060186b8b0cd50985e035408b0'); +assert.equal(bun.webkitCommit, 'aaa690bfbf34c9d50775716ac2fc3c7d0573e0b8'); +assert.deepEqual(bun.engineFeatures, { shadowRealm: true, hardened: false }); +assert.equal(await hash(bun.path), bun.sha256); +for (const [file, digest] of [['build.json', bun.buildReceiptSha256], ['transport.json', bun.preservationReceiptSha256]]) { + assert.equal(await hash(path.join(path.dirname(bun.path), file)), digest); +} +const selected = read(root + '/admission-inputs/plugins/desktop.json'); +assert(Array.isArray(selected) && selected.length && new Set(selected).size === selected.length); +assert.equal(await hash(source + '/dist/build-info.json'), plugins.distBuildInfoSha256); +assert.equal(read(source + '/dist/build-info.json').commit, CUT); +assert.equal(inputs.tarball.packagingSourceCommit, CUT); +assert(inputs.tarball.path.startsWith(here + '/package/'), 'Stage the package in the isolated package directory'); +assert.match(inputs.tarball.sha256, /^[a-f0-9]{64}$/); +assert(Number.isSafeInteger(inputs.tarball.bytes) && inputs.tarball.bytes > 0); +assert.equal(await hash(inputs.tarball.path), inputs.tarball.sha256); +assert.equal(fs.statSync(inputs.tarball.path).size, inputs.tarball.bytes); +assert(inputs.tarball.producerReceipt.path?.startsWith(root + '/'), 'Package producer receipt must be staged in the isolated native root'); +assert.match(inputs.tarball.producerReceipt.sha256, /^[a-f0-9]{64}$/); +assert.equal(await hash(inputs.tarball.producerReceipt.path), inputs.tarball.producerReceipt.sha256); +const packedBuild = JSON.parse(execFileSync('python3', ['-c', + 'import sys,tarfile; t=tarfile.open(sys.argv[1]); print(t.extractfile("package/dist/build-info.json").read().decode())', + inputs.tarball.path], { encoding: 'utf8', maxBuffer: 1024 * 1024 })); +assert.equal(packedBuild.commit, CUT, 'Tarball is not the current source build'); +assert.equal(packedBuild.version, read(source + '/package.json').version); + +async function admittedCells() { + const availability = await receipt(inputs.sourceAppExport, here + '/availability.json'); + assert.equal(availability.status, 'restored'); + assert.deepEqual(inputs.requestedVariants, availability.availableVariants); + assert.deepEqual(inputs.campaignRequestedVariants, ['js', 'c2-off', 'ts']); + assert.deepEqual(inputs.unavailableVariants, Object.fromEntries(Object.entries(availability.variants).filter(([, value]) => value.status === 'unavailable'))); + assert(Array.isArray(inputs.requestedVariants) && inputs.requestedVariants.length); + assert.equal(new Set(inputs.requestedVariants).size, inputs.requestedVariants.length); + assert(inputs.requestedVariants.includes('js'), 'JS AOT is the declared baseline'); + const cells = []; + for (const variant of inputs.requestedVariants) { + assert(['js', 'c2-off', 'ts'].includes(variant)); + const refs = inputs.variants[variant]; + assert.equal(refs.enabled, true, variant + ': optional cell is not admitted'); + const admission = await receipt(refs.admission, root + '/admissions/' + variant + '.json'); + const build = await receipt(refs.build, root + '/build-receipts/' + variant + '/result.json'); + const core = await receipt(refs.core, root + '/qualification-results/' + variant + '-core/run/result.json'); + const controller = await receipt(refs.coreController, root + '/runtime-results/' + variant + '-core/result.json'); + const preserved = await receipt(refs.preservation, root + '/preserved/' + variant + '/transport.json'); + assert.equal(preserved.status, 'preserved-not-downloaded'); + assert.equal(preserved.sourceCommit, CUT); + assert.equal(preserved.nativeResultSha256, refs.build.sha256); + assert.equal(admission.decision, 'build-linux'); + assert.equal(admission.linuxCut.commit, CUT); + assert.equal(build.status, 'built-unsigned'); + assert.equal(build.phase, 'complete'); + assert.equal(build.measurement.exitCode, 0); + assert.equal(build.plan.admissionSha256, refs.admission.sha256); + assert.equal(build.plan.sourceProof.commit, CUT); + assert.equal(build.plan.variant, variant === 'c2-off' ? 'c2' : variant); + assert.equal(build.plan.compiler.cohort, 'rd-p6-150c'); + assert.equal(build.plan.source, source); + assert.deepEqual(build.plan.plugins, selected, 'Baseline and AOT selection differ'); + const compiler = compilers[variant === 'c2-off' ? 'cb-compat' : 'cb-standard']; + assert.equal(compiler.cohort, 'rd-p6-150c'); + assert.equal(compiler.bunCommit, bun.bunCommit); + assert.equal(compiler.webkitCommit, bun.webkitCommit); + assert.deepEqual(compiler.engineFeatures, { shadowRealm: variant !== 'c2-off', hardened: false }); + for (const [file, digest] of [['build.json', compiler.buildReceiptSha256], ['transport.json', compiler.preservationReceiptSha256]]) { + assert.equal(await hash(path.join(path.dirname(compiler.path), file)), digest); + } + assert.equal(build.plan.compiler.sha256, compiler.sha256); + assert.equal(await hash(compiler.path), compiler.sha256); + const artifact = root + '/artifacts/' + variant; + assert.equal(build.plan.output, artifact); + const planFile = root + '/build-receipts/' + variant + '/plan.json'; + assert.equal(await hash(planFile), preserved.nativePlanSha256); + assert.deepEqual(read(planFile), build.plan); + const checked = JSON.parse(execFileSync(node.path, [root + '/build-prep/artifact-contract.mjs', planFile], { encoding: 'utf8', maxBuffer: 1024 * 1024 })); + const binarySha256 = await hash(artifact + '/openclaw'); + const manifestSha256 = await hash(artifact + '/manifest.json'); + assert.equal(checked.executable.sha256, binarySha256); + assert.equal(checked.manifestSha256, manifestSha256); + assert.equal(preserved.manifestSha256, manifestSha256); + assert.equal(preserved.executable.sha256, binarySha256); + assert.equal(preserved.runtime.sha256, checked.runtime.sha256); + assert.equal(build.artifact.executable.sha256, binarySha256); + assert.equal(build.artifact.manifestSha256, manifestSha256); + assert.equal(core.qualification, 'passed'); + assert.equal(core.source, source); + assert.equal(core.artifact, artifact); + assert.equal(core.platform, 'linux'); + assert.equal(core.arch, 'x64'); + assert.equal(core.binarySha256, binarySha256); + assert.equal(controller.status, 'phase-passed'); + assert.equal(controller.variant, variant); + assert.equal(controller.phase, 'core'); + assert.equal(controller.sourceCommit, CUT); + assert.equal(controller.actualBuildReceiptSha256, refs.build.sha256); + assert.equal(controller.rootBuildAdmissionSha256, refs.admission.sha256); + assert.equal(controller.binarySha256, binarySha256); + assert.equal(controller.manifestSha256, manifestSha256); + cells.push({ id: variant + '-aot', artifact, binarySha256, manifestSha256, + buildReceiptSha256: refs.build.sha256, coreReceiptSha256: refs.core.sha256, + policyLabel: build.plan.policyLabel, embeddedPlugins: read(artifact + '/manifest.json').plugins.embedded, + executableBytes: checked.executable.sizeBytes, runtimeBytes: checked.runtime.sizeBytes }); + } + return cells; +} + +if (action === 'baseline') { + console.log(JSON.stringify({ status: 'baseline-inputs-verified', sourceCommit: CUT })); +} else if (action === 'plan') { + write(work + '/package-plan.json', { status: 'planned', sourceCommit: CUT, source, node, bun, inputsSha256, + sourceBuildInfoSha256: plugins.distBuildInfoSha256, package: inputs.tarball, + launchUmask: '0077', packagingMeasuredOnX64: false, + installLabel: 'npm lifecycle with source allowScripts policy', npm, + policySha256: await hash(here + '/project-package.manifest.json'), command: installCommand }); +} else if (action === 'installed') { + assert.equal(read(work + '/package-plan.json').package.sha256, inputs.tarball.sha256); + assert.deepEqual(read(work + '/package-plan.json').node, node); + assert.equal(read(work + '/install-command/result.json').status, 'complete'); + assert.equal(read(work + '/install-command/measurement/receipt.json').exitCode, 0); + assert.equal(read(installed + '/dist/build-info.json').commit, CUT); + assert.deepEqual(read(work + '/installed/package.json').allowScripts, policy.allowScripts); + const lock = read(work + '/installed/package-lock.json'); + const locked = lock.packages['node_modules/openclaw']; + assert(locked, 'Installed root package absent from npm lock'); + const expectedIntegrity = execFileSync('python3', ['-c', 'import base64,hashlib,sys; print("sha512-"+base64.b64encode(hashlib.file_digest(open(sys.argv[1],"rb"),"sha512").digest()).decode())', inputs.tarball.path], { encoding: 'utf8' }).trim(); + assert.equal(locked.integrity, expectedIntegrity, 'Installed package SRI differs from the exact tarball'); + assert.equal(read(installed + '/dist/build-info.json').version, packedBuild.version); + assert.deepEqual(read(installed + '/package.json').openclaw.schemaVersions, read(source + '/package.json').openclaw.schemaVersions); + const inventory = inspectPackageExtensions(installed); + const ids = inventory.plugins.map(plugin => plugin.id); + assert.equal(new Set(ids).size, ids.length, 'Duplicate installed plugin IDs'); + const missing = selected.filter(id => !ids.includes(id)); + assert.deepEqual(missing, [], 'Installed package omitted selected plugins'); + const piTui = work + '/installed/node_modules/@earendil-works/pi-tui'; + assert.equal(read(piTui + '/package.json').version, '1.3.0'); + assert.equal(await hash(piTui + '/dist/native-platform.js'), 'bd3deaa60d547941511128f7bcf40083cff0130a836bd3baf168baee370ccdf2'); + const inactivePath = 'node_modules/@earendil-works/pi-tui/native/linux/prebuilds/linux-arm64/linux-platform-x11.node'; + const selectedPath = 'node_modules/@earendil-works/pi-tui/native/linux/prebuilds/linux-x64/linux-platform-x11.node'; + const nativeFiles = [], inactiveArchitectureAssets = [], links = []; + const installedSize = { regularFiles: 0, logicalBytes: 0, directories: 0 }; + const visit = async directory => { + for (const item of fs.readdirSync(directory, { withFileTypes: true })) { + const filename = path.join(directory, item.name); + if (item.isDirectory()) { installedSize.directories++; await visit(filename); continue; } + if (item.isFile()) { installedSize.regularFiles++; installedSize.logicalBytes += fs.statSync(filename).size; } + if (item.isSymbolicLink()) { + const resolved = fs.realpathSync(filename); + assert(resolved.startsWith(work + '/installed/'), 'Installed link escapes package tree'); + links.push({ path: path.relative(work + '/installed', filename), target: fs.readlinkSync(filename) }); + if (!fs.statSync(filename).isFile()) continue; + } else if (!item.isFile()) continue; + const fd = fs.openSync(filename, 'r'), header = Buffer.alloc(20); + try { fs.readSync(fd, header, 0, 20, 0); } finally { fs.closeSync(fd); } + if (!header.subarray(0, 4).equals(Buffer.from([0x7f, 0x45, 0x4c, 0x46]))) continue; + const file = { path: path.relative(work + '/installed', filename), machine: header.readUInt16LE(18), + bytes: fs.statSync(filename).size, sha256: await hash(filename) }; + if (file.path === inactivePath) { + assert.equal(file.machine, 183); + inactiveArchitectureAssets.push({ ...file, selection: 'inactive: verified loader selects process.arch=x64' }); + } else { assert.equal(file.machine, 62, 'Unexpected non-x64 ELF: ' + file.path); nativeFiles.push(file); } + } + }; + await visit(work + '/installed'); + assert(nativeFiles.some(file => file.path === selectedPath), 'Selected pi-tui x64 helper missing'); + write(work + '/installed-receipt.json', { status: 'installed-not-core-qualified', sourceCommit: CUT, node, bun, inputsSha256, + entry, entrySha256: await hash(entry), tarballSha256: inputs.tarball.sha256, tarballIntegrity: expectedIntegrity, + lockSha256: await hash(work + '/installed/package-lock.json'), policySha256: await hash(here + '/project-package.manifest.json'), npm, + sourceBuildInfoSha256: await hash(installed + '/dist/build-info.json'), + plugins: inventory.plugins, nativeFiles, inactiveArchitectureAssets, links, installedSize, + pluginInventory: { selectedCount: selected.length, extensionDirectoryCount: inventory.directories.length, + manifestPluginCount: ids.length, missing, extras: ids.filter(id => !selected.includes(id)), + nonPluginDirectories: inventory.nonPluginDirectories }, + deploymentComparison: 'Unpruned npm deployment; contents may differ from standalone. No compiler-only attribution.', + launchUmask: '0077', performanceQualified: false }); +} else { + const cells = await admittedCells(); + if (action === 'cohort') { + const baseline = read(work + '/installed-receipt.json'); + assert.equal(await hash(entry), baseline.entrySha256); + assert.equal(baseline.tarballSha256, inputs.tarball.sha256); + assert.deepEqual(baseline.node, node); + assert.deepEqual(baseline.bun, bun); + for (const [name, runtime] of [['node-core', node], ['bun-core', bun]]) { + const result = read(work + '/' + name + '/result.json'); + assert.equal(result.qualification, 'passed'); + assert.equal(result.binarySha256, runtime.sha256); + assert.equal(result.entrySha256, baseline.entrySha256); + } + assert.equal(inputs.sweeps, 6, 'Default campaign is six sweeps plus warmup'); + cells.push(...[['node-npm', node], ['bun-jit-npm', bun]].map(([id, runtime]) => ({ id, runtime: runtime.path, + entry, binarySha256: runtime.sha256, entrySha256: baseline.entrySha256 }))); + const js = inputs.variants.js; + write(work + '/cohort-config.json', { source, mainSha: CUT, inputsSha256, admissionReceipt: js.admission.path, + admissionReceiptSha256: js.admission.sha256, baseline: 'js-aot', sweeps: 6, cells, + installedReceiptSha256: await hash(work + '/installed-receipt.json'), + sourceAppExport: inputs.sourceAppExport, unavailableVariants: inputs.unavailableVariants, campaignRequestedVariants: inputs.campaignRequestedVariants, + executionEnvironment: { PATH: '/usr/bin:/bin', umask: '0077' }, + equivalence: 'Deployment comparison only; actual plugin directory and manifest counts are recorded separately. No pruning or compiler-only attribution.' }); + } + console.log(JSON.stringify({ status: 'actual-native-facts-verified', sourceCommit: CUT, cells: cells.map(cell => cell.id) })); +} diff --git a/scripts/openclaw-p6/app/benchmark/payload/native-inputs.json b/scripts/openclaw-p6/app/benchmark/payload/native-inputs.json new file mode 100644 index 000000000000..3009227a0a6b --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/payload/native-inputs.json @@ -0,0 +1,135 @@ +{ + "schemaVersion": 1, + "decision": "pending-native-facts", + "sourceCommit": "4fa442e332745f1f58ccedd27106abdafcf4e019", + "nativeRoot": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1", + "nativeSource": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/source", + "receipts": { + "toolchain": { + "path": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/prep-receipts/toolchain/result.json", + "sha256": null + }, + "plugins": { + "path": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/prep-receipts/plugins/result.json", + "sha256": null + }, + "compilerRecords": { + "path": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admission-inputs/compiler-records.json", + "sha256": null + } + }, + "tarball": { + "path": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/benchmark-prep/package/openclaw.tgz", + "sha256": null, + "bytes": null, + "packagingSourceCommit": "4fa442e332745f1f58ccedd27106abdafcf4e019", + "producerReceipt": { + "path": null, + "sha256": null + } + }, + "requestedVariants": [ + "js", + "c2-off", + "ts" + ], + "variants": { + "js": { + "enabled": false, + "admission": { + "path": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/js.json", + "sha256": null + }, + "build": { + "path": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/build-receipts/js/result.json", + "sha256": null + }, + "core": { + "path": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/qualification-results/js-core/run/result.json", + "sha256": null + }, + "coreController": { + "path": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/runtime-results/js-core/result.json", + "sha256": null + }, + "preservation": { + "path": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/preserved/js/transport.json", + "sha256": null + } + }, + "c2-off": { + "enabled": false, + "admission": { + "path": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/c2-off.json", + "sha256": null + }, + "build": { + "path": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/build-receipts/c2-off/result.json", + "sha256": null + }, + "core": { + "path": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/qualification-results/c2-off-core/run/result.json", + "sha256": null + }, + "coreController": { + "path": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/runtime-results/c2-off-core/result.json", + "sha256": null + }, + "preservation": { + "path": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/preserved/c2-off/transport.json", + "sha256": null + } + }, + "ts": { + "enabled": false, + "admission": { + "path": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/ts.json", + "sha256": null + }, + "build": { + "path": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/build-receipts/ts/result.json", + "sha256": null + }, + "core": { + "path": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/qualification-results/ts-core/run/result.json", + "sha256": null + }, + "coreController": { + "path": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/runtime-results/ts-core/result.json", + "sha256": null + }, + "preservation": { + "path": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/preserved/ts/transport.json", + "sha256": null + } + } + }, + "sweeps": 6, + "node": { + "path": null, + "sha256": null + }, + "ownerFiles": { + "benchmark/cohort-stats.mjs": "18c9c6ac68e7898a0a3bcff4c441626602b96e93c86e733b56c8c2801fd413f0", + "benchmark/core-runner.proposed.mjs": "ed861466e0283ccd630d7a21fae9828254023b1852024cedb7989552ce9f4482", + "benchmark/launch-target.mjs": "549517def60351d5e1fc3e0d175b112dc452a43f93f0fc0f0e64c698302fe7cd", + "benchmark/process-tree.mjs": "f4e43b17f6693753d06099633c056ae022a1fa4c8c139b0dfdcb76a58d828d79", + "benchmark/run-cohort.mjs": "9f162d5815f9263d619b632e8e83cced143db87838bbf892f317d9a5d6599c9f", + "harness/analyze-zero-js.py": "cd5ac0436fa1ffeebcbaa4b760c93f2cdc94e31dfa4c26d9ca6529ac0d43a621", + "harness/config-roundtrip.mjs": "511d9140896da1cff71e116a428a985b7d1f695bd07b0423afebac6f1601d6b0", + "harness/fixture-config.mjs": "1d028bfe83d0906f9fe1a651e5066a09442e850c08470eff584bf6487f4fbcc7", + "harness/gateway-readiness.mjs": "a007aa71fd55a888d0b159ee4ab51cc63a35492586c87769086d95a50e3d0759", + "harness/measurement-owner.py": "c610495003a00a6da6e4b870c752e14c9db55b06d38bda78f376a05c3722c724", + "stream-cohort.py": "534faa35fcaf5f48766323463cf42fc8d3fbf3d75ca442b26fc548483c16abb3", + "package-inventory.mjs": "c406013d6d33cdff0776833c0ab7e027683c361700af4633dc3cfd84ef1a7978", + "measure-install.py": "5b8aaf5d7b0c8d839ad3089b9e83e48e7c4a8d4ed7cca5e1e6ab330c9a381cef", + "harness/knowledge-provider.py": "f144aaa440e3bac9aeb9edeb5f44402a5df0bbe32c4c7a1adb391970499a089f", + "harness/knowledge-agent.mjs": "16abb14fd436e60c6ab59816184d78b2e765dcc964f8104b09f0f1235d77dd6b" + }, + "npm": { + "path": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/opt/node/lib/node_modules/npm/bin/npm-cli.js", + "sha256": null, + "manifestSha256": null, + "version": "11.20.0" + } +} diff --git a/scripts/openclaw-p6/app/benchmark/payload/native-inputs.template.json b/scripts/openclaw-p6/app/benchmark/payload/native-inputs.template.json new file mode 100644 index 000000000000..8c99af776e0d --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/payload/native-inputs.template.json @@ -0,0 +1,136 @@ +{ + "schemaVersion": 1, + "decision": "pending-native-facts", + "sourceCommit": "4fa442e332745f1f58ccedd27106abdafcf4e019", + "nativeRoot": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1", + "nativeSource": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/source", + "receipts": { + "toolchain": { + "path": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/prep-receipts/toolchain/result.json", + "sha256": null + }, + "plugins": { + "path": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/prep-receipts/plugins/result.json", + "sha256": null + }, + "compilerRecords": { + "path": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admission-inputs/compiler-records.json", + "sha256": null + } + }, + "tarball": { + "path": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/benchmark-prep/package/openclaw.tgz", + "sha256": null, + "bytes": null, + "packagingSourceCommit": "4fa442e332745f1f58ccedd27106abdafcf4e019", + "producerReceipt": { + "path": null, + "sha256": null + } + }, + "requestedVariants": [ + "js", + "c2-off", + "ts" + ], + "variants": { + "js": { + "enabled": false, + "admission": { + "path": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/js.json", + "sha256": null + }, + "build": { + "path": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/build-receipts/js/result.json", + "sha256": null + }, + "core": { + "path": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/qualification-results/js-core/run/result.json", + "sha256": null + }, + "coreController": { + "path": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/runtime-results/js-core/result.json", + "sha256": null + }, + "preservation": { + "path": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/preserved/js/transport.json", + "sha256": null + } + }, + "c2-off": { + "enabled": false, + "admission": { + "path": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/c2-off.json", + "sha256": null + }, + "build": { + "path": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/build-receipts/c2-off/result.json", + "sha256": null + }, + "core": { + "path": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/qualification-results/c2-off-core/run/result.json", + "sha256": null + }, + "coreController": { + "path": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/runtime-results/c2-off-core/result.json", + "sha256": null + }, + "preservation": { + "path": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/preserved/c2-off/transport.json", + "sha256": null + } + }, + "ts": { + "enabled": false, + "admission": { + "path": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/ts.json", + "sha256": null + }, + "build": { + "path": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/build-receipts/ts/result.json", + "sha256": null + }, + "core": { + "path": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/qualification-results/ts-core/run/result.json", + "sha256": null + }, + "coreController": { + "path": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/runtime-results/ts-core/result.json", + "sha256": null + }, + "preservation": { + "path": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/preserved/ts/transport.json", + "sha256": null + } + } + }, + "sweeps": 6, + "node": { + "path": null, + "sha256": null + }, + "ownerFiles": { + "benchmark/cohort-stats.mjs": "18c9c6ac68e7898a0a3bcff4c441626602b96e93c86e733b56c8c2801fd413f0", + "benchmark/core-runner.proposed.mjs": "ed861466e0283ccd630d7a21fae9828254023b1852024cedb7989552ce9f4482", + "benchmark/launch-target.mjs": "549517def60351d5e1fc3e0d175b112dc452a43f93f0fc0f0e64c698302fe7cd", + "benchmark/process-tree.mjs": "f4e43b17f6693753d06099633c056ae022a1fa4c8c139b0dfdcb76a58d828d79", + "benchmark/run-cohort.mjs": "9f162d5815f9263d619b632e8e83cced143db87838bbf892f317d9a5d6599c9f", + "harness/analyze-zero-js.py": "cd5ac0436fa1ffeebcbaa4b760c93f2cdc94e31dfa4c26d9ca6529ac0d43a621", + "harness/config-roundtrip.mjs": "511d9140896da1cff71e116a428a985b7d1f695bd07b0423afebac6f1601d6b0", + "harness/fixture-config.mjs": "1d028bfe83d0906f9fe1a651e5066a09442e850c08470eff584bf6487f4fbcc7", + "harness/gateway-readiness.mjs": "a007aa71fd55a888d0b159ee4ab51cc63a35492586c87769086d95a50e3d0759", + "harness/measurement-owner.py": "784af301b728e9563c1551f5bce8295e0884a240f379c5314f6e6d9e58c51d44", + "stream-cohort.py": "534faa35fcaf5f48766323463cf42fc8d3fbf3d75ca442b26fc548483c16abb3", + "package-inventory.mjs": "c406013d6d33cdff0776833c0ab7e027683c361700af4633dc3cfd84ef1a7978", + "measure-install.py": "5b8aaf5d7b0c8d839ad3089b9e83e48e7c4a8d4ed7cca5e1e6ab330c9a381cef", + "harness/knowledge-provider.py": "f144aaa440e3bac9aeb9edeb5f44402a5df0bbe32c4c7a1adb391970499a089f", + "harness/knowledge-agent.mjs": "16abb14fd436e60c6ab59816184d78b2e765dcc964f8104b09f0f1235d77dd6b", + "harness/process-stop.mjs": "68c2e651f829a424a7fc2c2b7d44a05caa23bc2c4f6a047296ca5529f3afdaec" + }, + "npm": { + "path": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/opt/node/lib/node_modules/npm/bin/npm-cli.js", + "sha256": null, + "manifestSha256": null, + "version": "11.20.0" + } +} diff --git a/scripts/openclaw-p6/app/benchmark/payload/package-inventory.mjs b/scripts/openclaw-p6/app/benchmark/payload/package-inventory.mjs new file mode 100644 index 000000000000..f838a561b331 --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/payload/package-inventory.mjs @@ -0,0 +1,18 @@ +import fs from 'node:fs'; +import path from 'node:path'; +import { createHash } from 'node:crypto'; + +export function inspectPackageExtensions(packageRoot) { + const root = path.join(packageRoot, 'dist/extensions'); + const directories = fs.readdirSync(root, { withFileTypes: true }) + .filter(entry => entry.isDirectory()).map(entry => entry.name).sort(); + const plugins = [], nonPluginDirectories = []; + for (const directory of directories) { + const filename = path.join(root, directory, 'openclaw.plugin.json'); + if (!fs.existsSync(filename)) { nonPluginDirectories.push(directory); continue; } + const bytes = fs.readFileSync(filename); + plugins.push({ directory, id: JSON.parse(bytes).id, + manifestSha256: createHash('sha256').update(bytes).digest('hex') }); + } + return { directories, plugins, nonPluginDirectories }; +} diff --git a/scripts/openclaw-p6/app/benchmark/payload/payload-manifest.json b/scripts/openclaw-p6/app/benchmark/payload/payload-manifest.json new file mode 100644 index 000000000000..3db8b49bdfef --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/payload/payload-manifest.json @@ -0,0 +1,36 @@ +{ + "backup/SOURCE-AUDIT.md": "8546eae17a521da03b007dda66d146e492e77a6936edd2b7eae043dd7ffc7925", + "backup/measure-command.py": "373b56ced3b931233bc15a1d97c634f486602b3c9e5a02d75e0688d2f5552a5a", + "backup/run.py": "57f1df7521ca5817a29f3fb95084221fa0190c0ce8dfe7a9ab9db45e97ae736b", + "backup/source-contract.json": "8aa57fa3911c10a8350a7b3cc69fd13031899b987805b609c2a9c7476459693c", + "benchmark/cohort-stats.mjs": "18c9c6ac68e7898a0a3bcff4c441626602b96e93c86e733b56c8c2801fd413f0", + "benchmark/core-runner.proposed.mjs": "ed861466e0283ccd630d7a21fae9828254023b1852024cedb7989552ce9f4482", + "benchmark/launch-target.mjs": "549517def60351d5e1fc3e0d175b112dc452a43f93f0fc0f0e64c698302fe7cd", + "benchmark/process-tree.mjs": "f4e43b17f6693753d06099633c056ae022a1fa4c8c139b0dfdcb76a58d828d79", + "benchmark/run-cohort.mjs": "9f162d5815f9263d619b632e8e83cced143db87838bbf892f317d9a5d6599c9f", + "bind-inputs.py": "c886763029c2aed49971a0e15d9c0c1baec310c4b6d3deb504ef7f7d6d95db23", + "check-window.py": "5914c1f047b3bbe671f8ed717ff30417138682f1b3cb90da8368c7afba6418f9", + "harness/analyze-zero-js.py": "cd5ac0436fa1ffeebcbaa4b760c93f2cdc94e31dfa4c26d9ca6529ac0d43a621", + "harness/config-roundtrip.mjs": "511d9140896da1cff71e116a428a985b7d1f695bd07b0423afebac6f1601d6b0", + "harness/fixture-config.mjs": "1d028bfe83d0906f9fe1a651e5066a09442e850c08470eff584bf6487f4fbcc7", + "harness/gateway-readiness.mjs": "a007aa71fd55a888d0b159ee4ab51cc63a35492586c87769086d95a50e3d0759", + "harness/measurement-owner.py": "784af301b728e9563c1551f5bce8295e0884a240f379c5314f6e6d9e58c51d44", + "measure-command.reference.py": "2fa495f4727a351f6cee078b403ac064610ce90ed339311f55c40a567463e4b7", + "measure-install.py": "5b8aaf5d7b0c8d839ad3089b9e83e48e7c4a8d4ed7cca5e1e6ab330c9a381cef", + "metadata.mjs": "4eeb7f4fe4768f9daa0c06b61849e72401f967da63431c9b7389b1fd45f30c89", + "native-inputs.template.json": "7d4a683c7f02f7ed226bcc3314f25e87d1f089e3a37e2c9100745bb7f0e55fff", + "package-inventory.mjs": "c406013d6d33cdff0776833c0ab7e027683c361700af4633dc3cfd84ef1a7978", + "prepare-package.sh": "cd78b6b1d3176cd079047826b6ee49e9d54e7b44303789d6fee470c185340eaa", + "prepare-window.py": "7fa1149aa6a0015f15010f20f56bb5b77dd0cd63fa9b1de430e3382f826932a3", + "project-package.manifest.json": "35c016b93524610121f8cebb541a09c7f365af015c324ac136a36020bdcbb05d", + "quiet-admission.template.json": "1b208c9312d1bcefeb01461e91eb770ed9905a56df6a866fcaac5e47f3ab6430", + "run-backup.py": "bfb8aa08a00552d8634437a2ff056883864f92924c8261a7617a1fbba0c3f217", + "run-functional.py": "a1e9dd290fb4cdf486602f65a4b89ceccc2ba1de249019e875c9f8d6ca7b34d5", + "run-phase.sh": "3b27da42db0a4996227e6287672f696c0b698775b4e057ad8cbb2c4346564fa8", + "source-contract.json": "1dc869110051b8fe88dffd0a027dff69f9830989040c8c60d2b2d536df2227ca", + "stream-cohort.py": "534faa35fcaf5f48766323463cf42fc8d3fbf3d75ca442b26fc548483c16abb3", + "summarize.py": "13b91df698e6438c46e276f5722d37556fe530f8989684ceee6d7c0ed0de69fd", + "harness/knowledge-provider.py": "f144aaa440e3bac9aeb9edeb5f44402a5df0bbe32c4c7a1adb391970499a089f", + "harness/knowledge-agent.mjs": "16abb14fd436e60c6ab59816184d78b2e765dcc964f8104b09f0f1235d77dd6b", + "harness/process-stop.mjs": "68c2e651f829a424a7fc2c2b7d44a05caa23bc2c4f6a047296ca5529f3afdaec" +} diff --git a/scripts/openclaw-p6/app/benchmark/payload/prepare-package.sh b/scripts/openclaw-p6/app/benchmark/payload/prepare-package.sh new file mode 100644 index 000000000000..11e6d5919552 --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/payload/prepare-package.sh @@ -0,0 +1,73 @@ +#!/usr/bin/env bash +set -euo pipefail +umask 077 +root=/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1 +here=$(cd "$(dirname "$0")" && pwd -P) +[[ "$here" == "$root/benchmark-prep" && $(uname -s) == Linux && $(uname -m) == x86_64 ]] +[[ ! -e "$here/package-source" && ! -e "$here/package" ]] +export HOME="$here/package-home" TMPDIR="$here/package-tmp" XDG_CACHE_HOME="$here/package-cache" +export PATH="$root/opt/node/bin:$root/opt/bin:/usr/bin:/bin" LANG=C.UTF-8 TZ=UTC +mkdir -p "$HOME" "$TMPDIR" "$XDG_CACHE_HOME" +NPM_CONFIG_USERCONFIG=$(mktemp "$TMPDIR/npm-user.XXXXXX") +NPM_CONFIG_GLOBALCONFIG=$(mktemp "$TMPDIR/npm-global.XXXXXX") +export NPM_CONFIG_USERCONFIG NPM_CONFIG_GLOBALCONFIG NPM_CONFIG_CACHE="$here/package-cache/npm" +python3 - "$root" "$here" <<'PY' +import hashlib,json,subprocess,sys +from pathlib import Path +root,here=map(Path,sys.argv[1:]);source=root/'source';contract=json.loads((here/'source-contract.json').read_text()) +assert subprocess.check_output(['git','-C',str(source),'rev-parse','HEAD'],text=True).strip()==contract['sourceCommit'] +assert not subprocess.check_output(['git','-C',str(source),'status','--porcelain','--untracked-files=no'],text=True).strip() +for name,digest in contract['files'].items(): assert hashlib.sha256((source/name).read_bytes()).hexdigest()==digest,name +for phase in ['clone','toolchain','install','runtime','boundary','plugins']: + assert json.loads((root/f'prep-receipts/{phase}/result.json').read_text())['status']=='PASS',phase +assert json.loads((source/'dist/build-info.json').read_text())['commit']==contract['sourceCommit'] +PY +cp --reflink=auto -a "$root/source" "$here/package-source" +python3 - "$here/package-source" <<'PY' +import os,sys +from pathlib import Path +root=Path(sys.argv[1]).resolve() +boundary=root/'.artifacts/extension-package-boundary' +if boundary.exists() or boundary.is_symlink(): + # The declaration fixture has absolute dependency links; retain it outside only this private clone. + assert not (root/'.artifacts').is_symlink() and not boundary.is_symlink() and boundary.is_dir(), 'Unexpected generated boundary path' + preserved=root.parent/'package-boundary-preserved' + assert not preserved.exists() and not preserved.is_symlink(), 'Private boundary preservation already exists' + boundary.rename(preserved) + print(f'Preserved private generated declaration boundary: {preserved}') +for directory,dirs,files in os.walk(root,followlinks=False): + for name in dirs+files: + p=Path(directory)/name + if p.is_symlink(): + target=p.resolve(strict=True) + assert target==root or root in target.parents, f'Private package clone has external link: {p}' +PY +mkdir "$here/package" +cd "$here/package-source" +"$root/opt/node/bin/node" --input-type=module - "$root/admission-inputs/plugins/desktop.json" "$here/package/bundles.json" <<'JS' +import fs from 'node:fs'; +import {collectRootPackageExcludedExtensionDirs} from './scripts/lib/root-package-bundled-plugin-excludes.mjs'; +const selected=JSON.parse(fs.readFileSync(process.argv[2],'utf8')); +const excluded=collectRootPackageExcludedExtensionDirs(); +fs.writeFileSync(process.argv[3],JSON.stringify(selected.filter(id=>excluded.has(id)))+'\n',{flag:'wx'}); +JS +mapfile -t bundles < <(python3 - "$here/package/bundles.json" <<'PY' +import json,sys +for value in json.load(open(sys.argv[1])): print(value) +PY +) +args=() +for bundle in "${bundles[@]}"; do args+=(--bundle-plugin "$bundle"); done +/usr/bin/nice -n 10 "$root/opt/node/bin/node" --import ./scripts/tsx.mjs scripts/package-openclaw-for-docker.mts \ + --skip-build --allow-unreleased-changelog --source-dir "$here/package-source" \ + --output-dir "$here/package" --output-name openclaw.tgz --pack-json "$here/package/pack.json" \ + "${args[@]}" > "$here/package/producer.stdout" 2> "$here/package/producer.stderr" +python3 - "$root" "$here" <<'PY' +import hashlib,json,sys,tarfile +from pathlib import Path +root,here=map(Path,sys.argv[1:]);p=here/'package/openclaw.tgz' +with tarfile.open(p) as t: build=json.load(t.extractfile('package/dist/build-info.json')) +assert build['commit']=='4fa442e332745f1f58ccedd27106abdafcf4e019' +receipt={'status':'package-owner-passed','sourceCommit':build['commit'],'tarball':str(p),'sha256':hashlib.sha256(p.read_bytes()).hexdigest(),'bytes':p.stat().st_size,'buildInfo':build,'bundles':json.loads((here/'package/bundles.json').read_text()),'performanceEligible':False} +(here/'package/producer-receipt.json').write_text(json.dumps(receipt,indent=2)+'\n') +PY diff --git a/scripts/openclaw-p6/app/benchmark/payload/prepare-window.py b/scripts/openclaw-p6/app/benchmark/payload/prepare-window.py new file mode 100644 index 000000000000..c0354bcc65de --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/payload/prepare-window.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 +"""Reserve all seven complete sweeps from this host's actual functional probes.""" +import json,math,os,time +from pathlib import Path +HERE=Path(__file__).resolve().parent +x=json.loads((HERE/'native-inputs.json').read_text()) +rows=json.loads((HERE/'work/functional-timings.json').read_text()) +ids=[v+'-aot' for v in x['requestedVariants']]+['node-npm','bun-jit-npm'] +accepted=[row for row in rows if row['id'] in ids] +assert len(accepted)==len(ids) and all(row['status']=='passed' for row in accepted) +assert x['sweeps']==6 +one=sum(row['wallSeconds'] for row in accepted) +# Functionals are scheduling evidence, not performance samples. Allow twice their +# elapsed time for every row, plus five minutes for controller/cleanup variation. +required=math.ceil(7*one*2+300) +remaining=int(os.environ['P6_DEADLINE_EPOCH'])-int(time.time())-1200 +result={'status':'window-available' if remaining>=required else 'insufficient-window','sourceCommit':x['sourceCommit'],'cells':ids,'warmupSweeps':1,'measuredSweeps':6,'probeSecondsPerSweep':one,'jitterMultiplier':2,'controllerAllowanceSeconds':300,'requiredSeconds':required,'remainingSecondsAfterCleanupReserve':remaining,'performanceEligible':False} +(HERE/'cohort-budget.json').write_text(json.dumps(result,indent=2)+'\n') +print(json.dumps(result)) +raise SystemExit(0 if remaining>=required else 78) diff --git a/scripts/openclaw-p6/app/benchmark/payload/project-package.manifest.json b/scripts/openclaw-p6/app/benchmark/payload/project-package.manifest.json new file mode 100644 index 000000000000..381c01bdc17b --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/payload/project-package.manifest.json @@ -0,0 +1,26 @@ +{ + "name": "p6-final-r4-comparator", + "private": true, + "allowScripts": { + "onnxruntime-node": false, + "@google/genai": true, + "@lydell/node-pty": true, + "@matrix-org/matrix-sdk-crypto-nodejs": true, + "@tloncorp/api": true, + "@tloncorp/tlon-skill": true, + "baileys": true, + "authenticate-pam": true, + "@discordjs/opus": false, + "esbuild": true, + "koffi": false, + "protobufjs": true, + "tree-sitter-bash": false, + "openclaw": true, + "@openclaw/proxyline": true, + "clawpdf": true, + "@openclaw/crabline": true, + "rastermill": true, + "node-pty": true, + "file:/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/benchmark-prep/package/openclaw.tgz": true + } +} diff --git a/scripts/openclaw-p6/app/benchmark/payload/quiet-admission.template.json b/scripts/openclaw-p6/app/benchmark/payload/quiet-admission.template.json new file mode 100644 index 000000000000..98cbc16d333d --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/payload/quiet-admission.template.json @@ -0,0 +1,15 @@ +{ + "decision": "pending-host-reconciliation", + "sourceCommit": "4fa442e332745f1f58ccedd27106abdafcf4e019", + "nativeRoot": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1", + "hostBootId": null, + "observedAtEpoch": null, + "heavyBuildsReconciled": false, + "nativeHooksReconciled": false, + "dockerAndGuestWorkReconciled": false, + "otherBenchmarksStopped": false, + "sameNativeMachineAllCells": false, + "exclusiveBenchmarkInterval": false, + "reservationSeconds": null, + "hostReconciliation": { "path": null, "sha256": null } +} diff --git a/scripts/openclaw-p6/app/benchmark/payload/run-backup.py b/scripts/openclaw-p6/app/benchmark/payload/run-backup.py new file mode 100644 index 000000000000..496e39e8dab6 --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/payload/run-backup.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 +"""Untimed synthetic backup qualification using the existing CLI owner.""" +import hashlib,importlib.util,json,os,signal,subprocess,sys +from pathlib import Path +HERE=Path(__file__).resolve().parent +ROOT=Path('/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1') +assert HERE==ROOT/'benchmark-prep';os.umask(0o077) +def load(p):return json.loads(Path(p).read_text()) +def sha(p): + with Path(p).open('rb') as f:return hashlib.file_digest(f,'sha256').hexdigest() +x=load(HERE/'native-inputs.json');contract=load(HERE/'backup/source-contract.json') +assert contract['sourceCommit']==x['sourceCommit'] +for name,digest in contract['files'].items():assert sha(ROOT/'source'/name)==digest,name +assert sha(HERE/'harness/measurement-owner.py')==x['ownerFiles']['harness/measurement-owner.py'] +spec=importlib.util.spec_from_file_location('p6_measurement_owner',HERE/'harness/measurement-owner.py');owner=importlib.util.module_from_spec(spec);spec.loader.exec_module(owner) +assert sha(ROOT/'measure-command.py')==owner.MEASURE_SHA +subprocess.run([x['node']['path'],str(HERE/'metadata.mjs'),'verify'],check=True) +entry=ROOT/'source/openclaw.mjs';stamp=load(entry.parent/'dist/.buildstamp') +assert stamp['head']==x['sourceCommit'] and stamp['inputsClean'] is True +out=ROOT/'backup-results';out.mkdir() +controls=[('node','jit-node',Path(x['node']['path']),True),('bun-jit','jit-bun',ROOT/'compilers/standard/bun',True)] +cells=controls+[(v,'aot',ROOT/'artifacts'/v/'openclaw',False) for v in x['requestedVariants']] +results=[] +for label,mode,binary,is_control in cells: + receipt=out/(label+'-controller');receipt.mkdir();cell=out/label + args=[sys.executable,'-B',str(HERE/'backup/run.py'),'--task-root',str(ROOT),'--out',str(cell),'--mode',mode,'--runtime',str(binary),'--runtime-sha256',sha(binary)] + if is_control:args+=['--entry',str(entry),'--entry-sha256',sha(entry)] + error=None;old=signal.signal(signal.SIGHUP,owner.interrupted) + try: + owner.measure({'measurementUtility':str(ROOT/'measure-command.py'),'variant':'backup-'+label,'source':str(ROOT/'source'),'timeoutSeconds':300,'command':args},{'PATH':'/usr/bin:/bin','HOME':str(HERE/'work/home'),'TMPDIR':str(HERE/'work/tmp'),'LANG':'C.UTF-8','TZ':'UTC'},receipt) + except BaseException as e: + if isinstance(e,(owner.BuildInterrupted,KeyboardInterrupt,SystemExit)):raise + error=str(e) + finally:signal.signal(signal.SIGHUP,old) + proof=load(cell/'result.json') if (cell/'result.json').exists() else None + passed=error is None and proof is not None and proof.get('pass') is True + results.append({'cell':label,'mode':mode,'status':'passed' if passed else 'failed','error':error,'resultPath':str(cell/'result.json') if proof else None,'resultSha256':sha(cell/'result.json') if proof else None,'performanceEligible':False}) + summary={'status':'passed' if all(r['status']=='passed' for r in results) else 'failed','sourceCommit':x['sourceCommit'],'cells':results,'unavailableVariants':x['unavailableVariants'],'performanceEligible':False,'applicationQualified':False,'scope':'Untimed real backup create/verify CLI with synthetic plugin-managed SQLite archive'} + (out/'summary.json').write_text(json.dumps(summary,indent=2)+'\n') +print(json.dumps(summary));raise SystemExit(0 if summary['status']=='passed' else 1) diff --git a/scripts/openclaw-p6/app/benchmark/payload/run-functional.py b/scripts/openclaw-p6/app/benchmark/payload/run-functional.py new file mode 100644 index 000000000000..e71fc953f659 --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/payload/run-functional.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python3 +"""Use the accepted measurement/core owners to size the complete next cohort.""" +import importlib.util,json,os,signal,subprocess,sys,time +from pathlib import Path +HERE=Path(__file__).resolve().parent +sys.path.insert(0,str(HERE.parent)) +ROOT=Path('/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1') +assert HERE==ROOT/'benchmark-prep' +os.umask(0o077) +def load(p):return json.loads(Path(p).read_text()) +def save(p,x):Path(p).write_text(json.dumps(x,indent=2)+'\n') +def sha(p): + import hashlib + with Path(p).open('rb') as f:return hashlib.file_digest(f,'sha256').hexdigest() +x=load(HERE/'native-inputs.json');availability=load(HERE/'availability.json');node=x['node']['path'];work=HERE/'work' +assert sha(HERE/'harness/measurement-owner.py')==x['ownerFiles']['harness/measurement-owner.py'] +spec=importlib.util.spec_from_file_location('p6_measurement_owner',HERE/'harness/measurement-owner.py');owner=importlib.util.module_from_spec(spec);spec.loader.exec_module(owner) +assert sha(ROOT/'measure-command.py')==owner.MEASURE_SHA +subprocess.run([node,str(HERE/'metadata.mjs'),'baseline'],check=True) +entry=str(work/'installed/node_modules/openclaw/openclaw.mjs') +cells=[(v+'-aot',['--artifact',str(ROOT/'artifacts'/v)],work/(v+'-core'),v) for v in x['requestedVariants']] +cells += [('node-npm',['--runtime',node,'--entry',entry],work/'node-core',None),('bun-jit-npm',['--runtime',str(ROOT/'compilers/standard/bun'),'--entry',entry],work/'bun-core',None)] +measurements=work/'functional-measurements';measurements.mkdir();timings=[] +knowledge={'sourceCommit':x['sourceCommit'],'status':'incomplete','expectedVariants':list(x['requestedVariants']), + 'variants':{v:{'status':'not-run'} for v in x['requestedVariants']},'performanceEligible':False} +save(work/'knowledge-controls.json',knowledge) +env={'PATH':'/usr/bin:/bin','HOME':str(work/'home'),'TMPDIR':str(work/'tmp'),'LANG':'C.UTF-8','TZ':'UTC'} +shutdown=json.loads(subprocess.check_output([node,str(HERE/'harness/process-stop.mjs'), + '--gateway-budget',str(ROOT/'source')],env=env,text=True,timeout=30)) +# Allow Gateway reap (5s), provider stop/reap (10s+5s), and final census (10s). +cleanup_grace=shutdown['serviceStopTimeoutMs']/1000+30 +for cell,args,out,variant in cells: + receipt=measurements/cell;receipt.mkdir();started=time.monotonic();error=None + old=signal.signal(signal.SIGHUP,owner.interrupted) + try: + owner.measure({'measurementUtility':str(ROOT/'measure-command.py'),'variant':'preflight-'+cell,'source':str(ROOT/'source'),'timeoutSeconds':900,'cleanupGraceSeconds':cleanup_grace,'command':[node,str(HERE/'benchmark/core-runner.proposed.mjs'),'--source',str(ROOT/'source'),'--out',str(out),*args]},env,receipt) + result=load(out/'result.json');assert result['qualification']=='passed' + except BaseException as e: + if isinstance(e,(owner.BuildInterrupted,KeyboardInterrupt,SystemExit)):raise + error=str(e) + finally:signal.signal(signal.SIGHUP,old) + row={'id':cell,'wallSeconds':time.monotonic()-started,'status':'passed' if error is None else 'failed','error':error,'receipt':str(receipt),'output':str(out),'performanceEligible':False};timings.append(row) + save(work/'functional-timings.json',timings) + if error is not None: + if variant not in ['c2-off','ts']:raise RuntimeError(cell+' required baseline functional failed: '+error) + availability['variants'][variant]={'status':'unavailable','reason':'new-host functional failed','functional':row,'performanceQualified':False} + availability['availableVariants'].remove(variant) + save(HERE/'availability.json',availability) +# Knowledge runs in fresh state and never changes ordinary functional/timing availability. +for variant in x['requestedVariants']: + if variant not in availability['availableVariants']: + knowledge['variants'][variant]={'status':'not-run','reason':'ordinary functional cell unavailable'} + save(work/'knowledge-controls.json',knowledge) + continue + receipt=measurements/(variant+'-knowledge');receipt.mkdir();out=work/(variant+'-knowledge');error=None + old=signal.signal(signal.SIGHUP,owner.interrupted) + try: + owner.measure({'measurementUtility':str(ROOT/'measure-command.py'),'variant':'knowledge-'+variant, + 'source':str(ROOT/'source'),'timeoutSeconds':900,'cleanupGraceSeconds':cleanup_grace,'command':[node,str(HERE/'benchmark/core-runner.proposed.mjs'), + '--source',str(ROOT/'source'),'--out',str(out),'--artifact',str(ROOT/'artifacts'/variant),'--knowledge-control']},env,receipt) + result=load(out/'result.json');assert result['qualification']=='passed' + assert result['checks']['knowledge']['status']=='passed-operations-only' + except BaseException as e: + if isinstance(e,(owner.BuildInterrupted,KeyboardInterrupt,SystemExit)):raise + error=str(e) + finally:signal.signal(signal.SIGHUP,old) + knowledge['variants'][variant]={'status':'passed' if error is None else 'failed','error':error, + 'proof':str(out/'knowledge/result.json'),'coreResult':str(out/'result.json')} + states=[row['status'] for row in knowledge['variants'].values()] + knowledge['status']='passed' if all(value=='passed' for value in states) else 'failed' if 'failed' in states else 'incomplete' + save(work/'knowledge-controls.json',knowledge) +# Refresh the existing fact binder after an optional AOT cell failed on this host. +subprocess.run([sys.executable,'-B',str(HERE/'bind-inputs.py'),'--root-admit'],check=True) +print(json.dumps({'status':'functional-probes-complete','timings':timings,'availableVariants':availability['availableVariants']})) diff --git a/scripts/openclaw-p6/app/benchmark/payload/run-phase.sh b/scripts/openclaw-p6/app/benchmark/payload/run-phase.sh new file mode 100644 index 000000000000..6981f170b40b --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/payload/run-phase.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash +set -euo pipefail +umask 077 +[[ $# -eq 1 ]] || { echo 'Usage: run-phase.sh plan|install|inventory|node-core|bun-core|config|cohort' >&2; exit 2; } +phase=$1 +case "$phase" in plan|install|inventory|node-core|bun-core|config|cohort) ;; *) exit 2;; esac +root=/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1 +here="$(cd "$(dirname "$0")" && pwd -P)" +[[ "$here" == "$root/benchmark-prep" && $(uname -s) == Linux && $(uname -m) == x86_64 ]] +node="$root/opt/node/bin/node" +bun="$root/compilers/standard/bun" +work="$here/work" +if [[ "$phase" == plan ]]; then + [[ ! -e "$work" ]] + mkdir -p "$work/home" "$work/tmp" "$work/cache" "$work/npm-cache" "$work/installed" + : > "$work/empty.npmrc" + cp "$here/project-package.manifest.json" "$work/installed/package.json" +else + [[ -d "$work" ]] +fi +entry="$work/installed/node_modules/openclaw/openclaw.mjs" +clean() { exec env -i HOME="$work/home" TMPDIR="$work/tmp" XDG_CACHE_HOME="$work/cache" NPM_CONFIG_CACHE="$work/npm-cache" NPM_CONFIG_USERCONFIG="$work/empty.npmrc" NPM_CONFIG_GLOBALCONFIG=/dev/null PATH="$root/opt/node/bin:$root/opt/bin:/usr/local/bin:/usr/bin:/bin" LANG=C.UTF-8 TZ=UTC "$@"; } +runtime() { exec env -i HOME="$work/home" TMPDIR="$work/tmp" PATH=/usr/bin:/bin LANG=C.UTF-8 TZ=UTC "$@"; } +case "$phase" in + install|node-core|bun-core) + env -i HOME="$work/home" TMPDIR="$work/tmp" PATH=/usr/bin:/bin LANG=C.UTF-8 TZ=UTC "$node" "$here/metadata.mjs" baseline + ;; +esac +case "$phase" in + plan) clean "$node" "$here/metadata.mjs" plan ;; + install) clean python3 "$here/measure-install.py" ;; + inventory) clean "$node" "$here/metadata.mjs" installed ;; + node-core) runtime "$node" "$here/benchmark/core-runner.proposed.mjs" --source "$root/source" --runtime "$node" --entry "$entry" --out "$work/node-core" ;; + bun-core) runtime "$node" "$here/benchmark/core-runner.proposed.mjs" --source "$root/source" --runtime "$bun" --entry "$entry" --out "$work/bun-core" ;; + config) clean "$node" "$here/metadata.mjs" cohort ;; + cohort) + env -i HOME="$work/home" TMPDIR="$work/tmp" PATH=/usr/bin:/bin LANG=C.UTF-8 TZ=UTC "$node" "$here/metadata.mjs" verify + runtime python3 "$here/stream-cohort.py" "$work/cohort" -- "$node" "$here/benchmark/run-cohort.mjs" "$work/cohort-config.json" "$work/cohort" + ;; +esac diff --git a/scripts/openclaw-p6/app/benchmark/payload/source-contract.json b/scripts/openclaw-p6/app/benchmark/payload/source-contract.json new file mode 100644 index 000000000000..66d5dc186154 --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/payload/source-contract.json @@ -0,0 +1,33 @@ +{ + "sourceCommit": "4fa442e332745f1f58ccedd27106abdafcf4e019", + "files": { + "scripts/e2e/lib/fixtures/mock-openai-config.mjs": "26986b7a44259220a98ba616e20297888502a6ec9f0cb89f9306159b544ebfb1", + "scripts/lib/gateway-ws-client.ts": "5dfcd0f4904475a249b19d6c4d2d22270d2e76c8d79da3377011a38eb30ed34d", + "scripts/e2e/lib/gateway-frame-payload.mjs": "58b22e42570402b553f0912f3f679edf49b242c17cf06365b58ce9fc08b94dc9", + "packages/gateway-protocol/src/version.ts": "7e115c318086327828e8bc1f2cb35656504a42b7fa580005b3bba3e8a8b7da0f", + "scripts/e2e/lib/agent-turn-output.mjs": "98544ca7ba561f371ce05300904ca89e4ff3134cb97a7754a223004b3b8c5cfa", + "scripts/e2e/mock-openai-server.mjs": "e68f6ce4b4024aa0c04d0504dbe403f2e310be1fd2e2a51c907244e31dbf1820", + "scripts/e2e/lib/fixtures/plugins.mjs": "e3f5abbe82a70425fd542d9c2651d56ea3fa6f81fdc360d63be38bfb1f522ec1", + "scripts/lib/openclaw-e2e-instance.sh": "bd6cf54ea310f96a891f12ec55ed282d29de8370b3505482ec1ab7626e6eb08e", + "scripts/e2e/Dockerfile": "2c15fa9c06d96b55306ed0ac865c363f1319e4bcd927605bf7a4bdf9e3228409", + "scripts/e2e/gateway-network-docker.sh": "9b6ad7070a433d0ca2292a70e0d1fb0359f1c5601dae7299b63117eaf045a5c7", + "scripts/e2e/kitchen-sink-plugin-docker.sh": "b17f83fcfb8478188f7e4e9bdd2ea50db81b160fcac7000d847a222e981d54f0", + "scripts/e2e/cron-cli-docker.sh": "6abf5cf3e174992d313c1f69f863565ebad078a17dae89723fb817ec6ae33245", + "scripts/lib/docker-e2e-image.sh": "b1227189675dff51e3a0218edc2715fad01b771668f1a402a9effba28aec49b1", + "scripts/lib/docker-e2e-container.sh": "7ae9be2f95729d17913413189790973aa97e8bd6ba24ff0fbddf2ad450a40fe0", + "scripts/lib/docker-e2e-package.sh": "88a00beb30de0aee79e679d33d504c4058335b433166eb35a5c9d9bc14bab575", + "scripts/lib/docker-build.sh": "db292501abb1397faeadb114204a3957649a9a7aad0971235d2e9c77f4a16bfd", + "scripts/e2e/lib/kitchen-sink-plugin/sweep.sh": "c8eb4b45a5507bb414d4972c7d814bfbfbc5aea34003fa7f1f32cbf743f4e0aa", + "scripts/e2e/lib/kitchen-sink-plugin/assertions.mjs": "c58bef14859757e449dc893d9fe63fddf90b1f06de32d74aecf979b76b8fddb2", + "package.json": "afe1412c6470a96cb9ae33d4b79a4584f69c19de3afc9556958fb9cbf1fc2ad8", + "pnpm-lock.yaml": "6711dcbef4e6504260a6cd0ba5dfe09f91d49b1414bd64f48e2dab55759c2aba", + "scripts/lib/bun-standalone-contract.mjs": "7fadadc2f96e948cc2e18865e5df2bb6e5a334348ea913165485e9eaaf263b7c", + "packages/gateway-client/src/websocket-data.ts": "4900275c9deeea33baf7953dcb081a454916173677814839c96137938f41767e", + "pnpm-workspace.yaml": "331a1990bfba6a4bf33c982fbf3e47477a1f3a3d2bc8d3c83e919b9c9d1717f9", + "scripts/package-openclaw-for-docker.mts": "3a21e738f0d70c7ef7b45800e830ff404c59b1dbe6e20634839837cc2a5230dd", + "scripts/lib/root-package-bundled-plugin-excludes.mjs": "6336b0bdd4f8b2ab1767f0b72b47c49da209ed10cc99102ab07280c8fbde4b3c", + "scripts/check-openclaw-package-tarball.mjs": "5b5be1e75fafde5c87d193c6ec48ca319e91777dcf3a7feb06c6e2058bee7690", + "scripts/lib/bun-standalone-native.mjs": "f9a1f75d68afe4173ac134f770677fa3ade21f33f2cba7dcf30748a358d3db00", + "gateway-shutdown-budget.mjs": "02757141fd71a0e03ee885d952edbcd664395a420b26c6b7ba596529336baa3a" + } +} diff --git a/scripts/openclaw-p6/app/benchmark/payload/stream-cohort.py b/scripts/openclaw-p6/app/benchmark/payload/stream-cohort.py new file mode 100644 index 000000000000..4ee799d41c6a --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/payload/stream-cohort.py @@ -0,0 +1,130 @@ +#!/usr/bin/env python3 +"""Read-only progress from the existing cohort owner, on its stdout transport.""" +import base64 +import hashlib +import json +import os +from pathlib import Path +import re +import signal +import subprocess +import sys +import time + +PREFIX = 'P6_PROGRESS ' +MAX_ROW_BYTES = 8 * 1024 * 1024 + + +def emit(value): + print(PREFIX + json.dumps(value, separators=(',', ':')), flush=True) + + +if sys.argv[1:] == ['--probe']: + emit({'event': 'probe', 'stage': 'first'}) + time.sleep(3) + emit({'event': 'probe', 'stage': 'second'}) + raise SystemExit(0) + +out = Path(sys.argv[1]).resolve() +assert sys.argv[2] == '--' and len(sys.argv) > 3 +assert not out.exists(), 'fresh cohort output required' +here = Path(__file__).resolve().parent +node = json.loads((here / 'native-inputs.json').read_text())['node']['path'] +budget = json.loads(subprocess.check_output([node, str(here / 'harness/process-stop.mjs'), + '--gateway-budget', str(here.parent / 'source')], text=True, timeout=30)) +cleanup_grace = budget['serviceStopTimeoutMs'] / 1000 + 30 +child = subprocess.Popen(sys.argv[3:], start_new_session=True) +cancelled_at = None +cancelled_signal = None +forced = False + + +def forward(signum, _frame): + global cancelled_at, cancelled_signal + if cancelled_at is not None: + return + cancelled_at = time.monotonic() + cancelled_signal = signum + if child.poll() is None: + try: + child.send_signal(signal.SIGTERM if signum == signal.SIGHUP else signum) + except ProcessLookupError: + pass + + +for sig in [signal.SIGINT, signal.SIGTERM, signal.SIGHUP]: + signal.signal(sig, forward) + +seen = {} +last_status = None +last_signature = None + + +def collect(): + global last_status, last_signature + filename = out / 'cohort.json' + if not filename.exists(): + return + stat = filename.stat() + signature = (stat.st_mtime_ns, stat.st_size) + if signature == last_signature: + return + assert stat.st_size <= 16 * 1024 * 1024, 'cohort receipt exceeded progress bound' + raw = filename.read_bytes() + try: + receipt = json.loads(raw) + except json.JSONDecodeError: + return # The owner rewrites this file; the next poll reads the completed save. + last_signature = signature + for row in receipt.get('rows', []): + if 'finished' not in row: + continue + label = Path(row['out']).name + assert re.fullmatch(r'(warmup|sweep-[0-9]+)-[a-z0-9-]+', label), 'unsafe row label' + row_out = Path(row['out']).resolve() + assert row_out == out / label, 'row receipt escaped cohort output' + result = row_out / 'result.json' + if not result.exists(): + continue + assert result.stat().st_size <= MAX_ROW_BYTES, 'row receipt exceeded progress bound' + data = result.read_bytes() + digest = hashlib.sha256(data).hexdigest() + if label in seen: + assert seen[label] == digest, 'completed row changed' + continue + emit({'event': 'row', 'label': label, 'sha256': digest, + 'resultBase64': base64.b64encode(data).decode('ascii'), + 'row': {key: value for key, value in row.items() if key != 'result'}}) + seen[label] = digest + status = (receipt.get('status', 'running'), len(receipt.get('rows', [])), len(seen)) + if status != last_status: + emit({'event': 'cohort', 'status': status[0], 'rowsStarted': status[1], + 'rowsPreserved': status[2], 'cohortSha256': hashlib.sha256(raw).hexdigest(), + 'machine': receipt.get('machine')}) + last_status = status + + +try: + while child.poll() is None: + collect() + if cancelled_at is not None and not forced and time.monotonic() - cancelled_at > cleanup_grace: + try: + os.killpg(child.pid, signal.SIGKILL) + except ProcessLookupError: + pass + forced = True + time.sleep(0.25) + collect() + code = child.wait() + emit({'event': 'owner-exit', 'code': code, 'rowsPreserved': len(seen), + 'interruptedBySignal': cancelled_signal, 'forcedCleanup': forced, + 'cleanupGraceSeconds': cleanup_grace}) +finally: + if child.poll() is None: + forward(signal.SIGTERM, None) + try: + child.wait(timeout=max(0, cancelled_at + cleanup_grace - time.monotonic())) + except subprocess.TimeoutExpired: + os.killpg(child.pid, signal.SIGKILL) + child.wait() +raise SystemExit(128 + cancelled_signal if cancelled_signal is not None else code if code >= 0 else 128 - code) diff --git a/scripts/openclaw-p6/app/benchmark/payload/summarize.py b/scripts/openclaw-p6/app/benchmark/payload/summarize.py new file mode 100644 index 000000000000..c88f13f36b5c --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/payload/summarize.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python3 +"""Report successful selected cells and explicit unavailable requested cells.""" +import json +from pathlib import Path +HERE=Path(__file__).resolve().parent +x=json.loads((HERE/'native-inputs.json').read_text());a=json.loads((HERE/'availability.json').read_text()) +config=json.loads((HERE/'work/cohort-config.json').read_text()) +cohort=json.loads((HERE/'work/cohort/cohort.json').read_text()) +ids=[c['id'] for c in config['cells']] +complete=cohort.get('status')=='passed' and cohort['mainSha']==x['sourceCommit'] and cohort['sweeps']==6 +for cell in ids: + rows=[r for r in cohort['rows'] if r['id']==cell] + complete=complete and len(rows)==7 and sum(not r['warmup'] for r in rows)==6 and all(r.get('result',{}).get('qualification')=='passed' for r in rows) +unavailable={v:r for v,r in a['variants'].items() if r['status']=='unavailable'} +backupPath=HERE.parent/'backup-results/summary.json' +backup=json.loads(backupPath.read_text()) if backupPath.exists() else {'status':'not-run'} +result={'untimedBackup':backup,'applicationQualified':False,'shipReady':False,'status':('partial-comparison-passed' if unavailable else 'comparison-passed') if complete else 'comparison-incomplete','sourceCommit':x['sourceCommit'],'performanceQualified':complete,'fullRequestedMatrixComplete':complete and not unavailable,'availableCells':ids,'unavailableVariants':unavailable,'sourceAppExport':a['sourceAppExport'],'sourceQualificationSummary':a['sourceQualificationSummary'],'summary':cohort.get('summary') if complete else None,'limits':cohort['limits']} +(HERE/'comparison-summary.json').write_text(json.dumps(result,indent=2)+'\n');print(json.dumps(result)) +raise SystemExit(0 if complete else 1) diff --git a/scripts/openclaw-p6/app/benchmark/preserve.py b/scripts/openclaw-p6/app/benchmark/preserve.py new file mode 100644 index 000000000000..b1a6f747cd94 --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/preserve.py @@ -0,0 +1,218 @@ +#!/usr/bin/env python3 +"""Preserve a successful P6 native artifact, then verify its relocated copy.""" +import argparse +import copy +import hashlib +import json +import os +from pathlib import Path, PurePosixPath +import stat +import subprocess +import tarfile + +SOURCE_COMMIT = '4fa442e332745f1f58ccedd27106abdafcf4e019' + + +def require(ok, message): + if not ok: + raise ValueError(message) + + +def sha(filename): + digest = hashlib.sha256() + with Path(filename).open('rb') as stream: + for chunk in iter(lambda: stream.read(1024 * 1024), b''): + digest.update(chunk) + return digest.hexdigest() + + +def read_pinned(filename, digest): + data = Path(filename).read_bytes() + require(hashlib.sha256(data).hexdigest() == digest, 'Input hash mismatch: ' + str(filename)) + return data + + +def write_json(filename, value): + Path(filename).write_text(json.dumps(value, indent=2) + '\n') + + +def contained(root, child): + try: + Path(child).relative_to(root) + return True + except ValueError: + return False + + +def inventory(root): + """Transport metadata only; content/tree hashes remain with the source owner.""" + rows = [{'path': '.', 'kind': 'directory', 'mode': stat.S_IMODE(root.stat().st_mode)}] + def visit(directory): + for item in sorted(directory.iterdir(), key=lambda p: p.name): + info = item.lstat() + row = {'path': item.relative_to(root).as_posix(), 'mode': stat.S_IMODE(info.st_mode)} + if stat.S_ISLNK(info.st_mode): + row.update(kind='symlink', target=os.readlink(item)) + require(not Path(row['target']).is_absolute() and contained(root, item.resolve(strict=True)), + 'Artifact link is not relocatable: ' + row['path']) + elif stat.S_ISDIR(info.st_mode): + row['kind'] = 'directory' + elif stat.S_ISREG(info.st_mode): + row.update(kind='file', size=info.st_size) + else: + raise ValueError('Unsupported artifact member: ' + row['path']) + rows.append(row) + if row['kind'] == 'directory': + visit(item) + visit(root) + return rows + + +def inputs(plan_file, plan_sha, result_file, result_sha): + plan_data = read_pinned(plan_file, plan_sha) + result_data = read_pinned(result_file, result_sha) + plan, result = json.loads(plan_data), json.loads(result_data) + require(result['status'] == 'built-unsigned' and result['phase'] == 'complete' and + result['measurement']['exitCode'] == 0, 'No successful completed native build') + require(result['plan'] == plan, 'Result does not contain the exact native plan') + require(plan['platform'] == 'linux' and plan['arch'] == 'x64' and + plan['sourceProof']['commit'] == SOURCE_COMMIT, 'Wrong native target or final source cut') + return plan_data, result_data, plan, result + + +def check_artifact(plan_file, plan, result, checker, node, logs): + checker, node = Path(checker).resolve(), Path(node).resolve() + require(sha(checker) == plan['artifactCheckerSha256'], 'Artifact checker changed') + owner = Path(plan['source']) / 'scripts/lib/bun-standalone-contract.mjs' + require(sha(owner) == result['artifact']['contractOwnerSha256'], 'Source contract owner changed') + env = {'PATH': str(node.parent) + ':/usr/bin:/bin', 'HOME': str(logs), + 'TMPDIR': str(logs), 'LANG': 'C.UTF-8', 'NODE_NO_WARNINGS': '1'} + process = subprocess.run([str(node), str(checker), str(plan_file)], env=env, + cwd=logs, capture_output=True, text=True, timeout=1800) + (logs / 'checker.stdout').write_text(process.stdout) + (logs / 'checker.stderr').write_text(process.stderr) + require(process.returncode == 0, 'Artifact owner check failed; see checker.stderr') + actual = json.loads(process.stdout) + require(actual == result['artifact'], 'Relocated owner facts differ from native result') + return actual + + +def fresh_output(output, protected): + output = Path(output).resolve() + require(not output.exists(), 'Output already exists') + require(all(not contained(Path(root).resolve(), output) for root in protected), + 'Preservation output must be outside source and artifact') + output.mkdir(parents=True) + return output + + +def pack(args): + plan_data, result_data, plan, result = inputs(args.plan, args.plan_sha256, + args.result, args.result_sha256) + artifact = Path(plan['output']).resolve(strict=True) + require(artifact.is_dir() and not Path(plan['output']).is_symlink(), 'Artifact root is not a directory') + require(sha(plan['buildNode']['path']) == plan['buildNode']['sha256'], 'Admitted native Node changed') + output = fresh_output(args.out, [artifact, plan['source']]) + for name, data in [('native-plan.json', plan_data), ('native-result.json', result_data)]: + (output / name).write_bytes(data) + facts = check_artifact(output / 'native-plan.json', plan, result, args.checker, + plan['buildNode']['path'], output) + metadata = inventory(artifact) + write_json(output / 'artifact-metadata.json', metadata) + archive = output / 'artifact.tar' + with tarfile.open(archive, 'w', dereference=False, format=tarfile.PAX_FORMAT) as bundle: + bundle.add(artifact, arcname='artifact', recursive=True) + for name in ['native-plan.json', 'native-result.json', 'artifact-metadata.json']: + bundle.add(output / name, arcname=name, recursive=False) + require(sha(args.plan) == args.plan_sha256 and sha(args.result) == args.result_sha256, + 'Native plan/result changed during preservation') + receipt = {'status': 'preserved-not-downloaded', 'sourceCommit': SOURCE_COMMIT, + 'archive': str(archive), 'archiveSha256': sha(archive), + 'archiveBytes': archive.stat().st_size, 'helperSha256': sha(__file__), + 'nativePlanSha256': args.plan_sha256, 'nativeResultSha256': args.result_sha256, + 'checkerSha256': plan['artifactCheckerSha256'], + 'contractOwnerSha256': facts['contractOwnerSha256'], + 'manifestSha256': facts['manifestSha256'], 'executable': facts['executable'], + 'runtime': facts['runtime'], 'artifactMetadataSha256': sha(output / 'artifact-metadata.json')} + write_json(output / 'transport.json', receipt) + return receipt + + +def validate_members(members): + names, links = set(), set() + allowed = {'native-plan.json', 'native-result.json', 'artifact-metadata.json'} + for member in members: + name = PurePosixPath(member.name) + require(not name.is_absolute() and '..' not in name.parts and member.name not in names, + 'Unsafe or duplicate archive path') + require(name.parts and (name.parts[0] == 'artifact' or str(name) in allowed), 'Unexpected archive root') + require(member.isdir() or member.isfile() or member.issym() or member.islnk(), 'Special archive member') + names.add(member.name) + if member.issym(): + target = PurePosixPath(member.linkname) + require(not target.is_absolute(), 'Absolute archive symlink') + normalized = os.path.normpath(str(name.parent / target)) + require(normalized == 'artifact' or normalized.startswith('artifact/'), 'Escaping archive symlink') + links.add(member.name) + if member.islnk(): + target = PurePosixPath(member.linkname) + require(not target.is_absolute() and '..' not in target.parts and target.parts[0] == 'artifact', + 'Escaping archive hardlink') + for name in names: + require(not any(str(parent) in links for parent in PurePosixPath(name).parents), + 'Archive member traverses a symlink') + + +def verify(args): + receipt = json.loads(read_pinned(args.transport, args.transport_sha256)) + require(receipt['status'] == 'preserved-not-downloaded' and + receipt['sourceCommit'] == SOURCE_COMMIT and receipt['helperSha256'] == sha(__file__), + 'Wrong transport receipt or helper') + require(args.archive_sha256 == receipt['archiveSha256'] and + sha(args.archive) == receipt['archiveSha256'] and + Path(args.archive).stat().st_size == receipt['archiveBytes'], 'Archive transfer differs') + source = Path(args.source).resolve(strict=True) + head = subprocess.check_output(['git', '-C', str(source), 'rev-parse', 'HEAD'], text=True).strip() + require(head == SOURCE_COMMIT, 'Local carrier is not the final source cut') + output = fresh_output(args.out, [source]) + with tarfile.open(args.archive, 'r:') as bundle: + validate_members(bundle.getmembers()) + # Validated paths and links above; retain exact modes across Python defaults. + if hasattr(tarfile, 'fully_trusted_filter'): + bundle.extractall(output, filter=tarfile.fully_trusted_filter) + else: + bundle.extractall(output) + plan_data, result_data, native_plan, result = inputs(output / 'native-plan.json', receipt['nativePlanSha256'], + output / 'native-result.json', receipt['nativeResultSha256']) + require(sha(output / 'artifact-metadata.json') == receipt['artifactMetadataSha256'], 'Metadata transfer differs') + require(inventory(output / 'artifact') == json.loads((output / 'artifact-metadata.json').read_text()), + 'Artifact paths, kinds, modes, sizes, or link targets changed') + derived = copy.deepcopy(native_plan) + derived['source'], derived['output'] = str(source), str(output / 'artifact') + write_json(output / 'local-check-plan.json', derived) + facts = check_artifact(output / 'local-check-plan.json', derived, result, args.checker, args.node, output) + report = {'status': 'downloaded-and-verified', 'applicationQualified': False, + 'sourceCommit': SOURCE_COMMIT, 'archiveSha256': receipt['archiveSha256'], + 'nativePlanSha256': receipt['nativePlanSha256'], 'nativeResultSha256': receipt['nativeResultSha256'], + 'localCheckPlanSha256': sha(output / 'local-check-plan.json'), + 'derivedPlanChangedKeys': ['source', 'output'], 'facts': facts, + 'artifact': str(output / 'artifact'), 'localNodeSha256': sha(args.node)} + write_json(output / 'verification.json', report) + return report + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + commands = parser.add_subparsers(dest='mode', required=True) + native = commands.add_parser('pack') + for name in ['plan', 'plan-sha256', 'result', 'result-sha256', 'checker', 'out']: + native.add_argument('--' + name, required=True) + local = commands.add_parser('verify') + for name in ['archive', 'archive-sha256', 'transport', 'transport-sha256', 'source', 'checker', 'node', 'out']: + local.add_argument('--' + name, required=True) + args = parser.parse_args() + print(json.dumps(pack(args) if args.mode == 'pack' else verify(args), indent=2)) + + +if __name__ == '__main__': + main() diff --git a/scripts/openclaw-p6/app/benchmark/quiet.py b/scripts/openclaw-p6/app/benchmark/quiet.py new file mode 100644 index 000000000000..b96b126889e2 --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/quiet.py @@ -0,0 +1,225 @@ +#!/usr/bin/env python3 +"""Inspect host quietness and bind sanitized evidence to the full cohort window.""" +import argparse,hashlib,json,math,os,platform,re,subprocess,time +from pathlib import Path + +ROOT=Path('/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1') +SOURCE='4fa442e332745f1f58ccedd27106abdafcf4e019' +HERE=Path(__file__).resolve().parent +GH={'repository':'GITHUB_REPOSITORY','runId':'GITHUB_RUN_ID','runAttempt':'GITHUB_RUN_ATTEMPT','job':'GITHUB_JOB'} +FLAGS=['heavyBuildsReconciled','nativeHooksReconciled','dockerAndGuestWorkReconciled','otherBenchmarksStopped','sameNativeMachineAllCells','exclusiveBenchmarkInterval'] +BUILDERS={'ninja','make','gmake','cmake','cc','c++','gcc','g++','clang','clang++','rustc','cargo','zig','cc1','cc1plus','ld','ld.lld','lld','ar','as','go'} +RUNTIMES={'node','nodejs','bun','npm','npx','pnpm','ruby','perl'} +SHELLS={'sh','bash','dash','zsh'} +SAMPLE_SECONDS=1.0 +NOISE_CPU_SECONDS_PER_SECOND=0.10 + +def need(ok,message): + if not ok:raise ValueError(message) +def sha(path):return hashlib.sha256(Path(path).read_bytes()).hexdigest() +def load(path):return json.loads(Path(path).read_text()) +def write(path,data): + temporary=path.with_name(path.name+'.next') + with temporary.open('w') as stream:json.dump(data,stream,indent=2);stream.write('\n') + temporary.chmod(0o644);temporary.replace(path) + +def execution(path,expected,env): + need(re.fullmatch('[0-9a-f]{64}',expected) is not None and sha(path)==expected,'Execution hash differs') + data=load(path);identity=data.get('identity') + need(data.get('schemaVersion')==1 and data.get('sourceCommit')==SOURCE,'Execution source/schema differs') + need(isinstance(identity,dict) and set(identity)==set(GH),'Complete actual execution identity required') + need(identity['repository']=='openclaw/bun' and identity['job']=='linux-x64-benchmark','Wrong benchmark repository/job') + for key,name in GH.items(): + need(isinstance(identity[key],str) and env.get(name)==identity[key],'Actual GitHub identity differs') + for key in ['runId','runAttempt']:need(re.fullmatch('[1-9][0-9]*',identity[key]) is not None,'Positive decimal run identity required') + head=data.get('workflowHead');need(isinstance(head,str) and re.fullmatch('[0-9a-f]{40}',head) is not None and env.get('GITHUB_SHA')==head,'Actual workflow head differs') + return data + +def proc_stat(raw): + end=raw.rfind(')');need(end>0,'Invalid proc stat');pid=int(raw[:raw.index('(')].strip());fields=raw[end+2:].split() + return {'pid':pid,'state':fields[0],'ppid':int(fields[1]),'startTicks':int(fields[19]),'cpuTicks':int(fields[11])+int(fields[12]),'comm':raw[raw.index('(')+1:end]} + +def read_processes(proc=Path('/proc')): + rows={};errors=[] + for directory in proc.iterdir(): + if not directory.name.isdecimal():continue + pid=int(directory.name) + try: + row=proc_stat((directory/'stat').read_text());args=(directory/'cmdline').read_bytes().split(b'\0');row['args']=[v.decode('utf8','replace') for v in args if v] + try:row['exe']=os.readlink(directory/'exe') + except FileNotFoundError:row['exe']='' + try:row['cwd']=os.readlink(directory/'cwd') + except FileNotFoundError:row['cwd']='' + after=proc_stat((directory/'stat').read_text());need(row['startTicks']==after['startTicks'] and row['pid']==pid,'Process changed during inspection') + rows[pid]=row + except FileNotFoundError:errors.append({'pid':pid,'classification':'process-inspection-race'}) + except (OSError,ValueError,IndexError):errors.append({'pid':pid,'classification':'process-inspection-failed'}) + return rows,errors + +def cpu_point(proc=Path('/proc')): + row=proc_stat((proc/str(os.getpid())/'stat').read_text()) + fields=(proc/'stat').read_text().splitlines()[0].split() + need(fields[0]=='cpu' and len(fields)>=9,'Host CPU counters unavailable') + ticks=list(map(int,fields[1:9]));need(all(v>=0 for v in ticks),'Invalid host CPU counters') + return {'monotonic':time.monotonic(),'hostTicks':ticks,'selfTicks':row['cpuTicks'],'selfStartTicks':row['startTicks']} + +def cpu_activity(first,last,before,after,self_pid,hz): + elapsed=last['monotonic']-first['monotonic'] + need(0.5<=elapsed<=5.0 and hz>0,'CPU sampling interval invalid') + need(first['selfStartTicks']==last['selfStartTicks'],'Inspector identity changed') + delta=[b-a for a,b in zip(first['hostTicks'],last['hostTicks'])] + need(len(delta)==8 and all(v>=0 for v in delta) and sum(delta)>0,'Host CPU counters changed or unavailable') + busy=sum(delta)-delta[3]-delta[4];own=last['selfTicks']-first['selfTicks'] + need(0<=own<=busy+2,'Inspector CPU counters inconsistent') + added=sorted(set(after)-set(before));removed=sorted(set(before)-set(after));reused=[];errors=[];activity=[] + for pid in sorted(set(before)&set(after)): + a,b=before[pid],after[pid] + if a['startTicks']!=b['startTicks']: + reused.append(pid);continue + ticks=b['cpuTicks']-a['cpuTicks'] + if ticks<0:errors.append(pid);continue + if pid!=self_pid and ticks: + activity.append({'pid':pid,'cpuTicks':ticks,'classification':category(b,str(ROOT.parent)) or 'unclassified-host-cpu'}) + allowance=max(1,math.ceil(hz*elapsed*NOISE_CPU_SECONDS_PER_SECOND)) + unexplained=max(0,busy-own);process_ticks=sum(v['cpuTicks'] for v in activity) + clean=not (added or removed or reused or errors) and max(unexplained,process_ticks,delta[4])<=allowance + return {'pass':clean,'intervalSeconds':elapsed,'clockTicksPerSecond':hz,'noiseAllowanceCpuSeconds':allowance/hz, + 'noiseAllowanceTicks':allowance,'hostBusyTicks':busy,'hostBusyCpuSeconds':busy/hz, + 'inspectorCpuTicksExcluded':own,'inspectorCorrectionCpuSeconds':own/hz,'inspectorCorrectionRoundingBoundTicks':2, + 'unexplainedHostBusyTicks':unexplained,'observedOtherProcessTicks':process_ticks,'iowaitTicks':delta[4], + 'processActivity':activity,'addedPids':added,'removedPids':removed,'reusedPids':reused,'counterErrorPids':errors} + +DOCKER_FORMAT='{"id":{{json .Id}},"name":{{json .Name}},"pid":{{json .State.Pid}},"running":{{json .State.Running}},"paused":{{json .State.Paused}},"restarting":{{json .State.Restarting}},"owner":{{json (index .Config.Labels "openclaw.p6.owner")}},"command":{{json .Config.Cmd}},"entrypoint":{{json .Config.Entrypoint}}}' +def read_containers(): + result=subprocess.run(['docker','ps','-aq','--no-trunc'],capture_output=True,text=True,timeout=30,check=True) + ids=result.stdout.split();need(len(ids)==len(set(ids)) and all(re.fullmatch('[0-9a-f]{64}',v) for v in ids),'Invalid Docker inventory') + if not ids:return [] + result=subprocess.run(['docker','inspect','--format',DOCKER_FORMAT,*ids],capture_output=True,text=True,timeout=30,check=True) + rows=[json.loads(v) for v in result.stdout.splitlines() if v.strip()] + need(len(rows)==len(ids) and {v['id'] for v in rows}==set(ids),'Docker inventory changed') + return rows + +def ancestry(rows,pid): + result=set();seen=set() + while pid in rows: + need(pid not in seen,'Process ancestry cycle');seen.add(pid);result.add(pid);pid=rows[pid]['ppid'] + return result + +def descendants(rows,pid): + found={pid} + while True: + expanded=found|{p for p,row in rows.items() if row['ppid'] in found} + if expanded==found:return found + found=expanded + +def idle_main(rows,container): + pid=container['pid'];need(type(pid) is int and pid>0 and pid in rows,'Main container host PID absent') + need(container['running'] is True and not container['paused'] and not container['restarting'],'Main container not running normally') + need(container['command']==['sleep','infinity'] and container['entrypoint'] in [None,[]],'Main container command differs') + ids=descendants(rows,pid);root=rows[pid];args=root['args'];name=Path(root['exe'] or (args[0] if args else root['comm'])).name + if name=='sleep':need(args[1:]==['infinity'] and ids=={pid},'Main sleep has unexpected arguments/children') + else: + need(name in ['docker-init','tini'] and args[1:]==['--','sleep','infinity'],'Main init differs') + children=[row for row in rows.values() if row['ppid']==pid];need(len(children)==1 and ids=={pid,children[0]['pid']},'Main container has task descendants') + child=children[0];need(child['args'] and Path(child['args'][0]).name=='sleep' and child['args'][1:]==['infinity'],'Main child is not idle sleep') + need(all(rows[v]['state'] in ['S','I'] for v in ids),'Main container is not idle') + return ids + +def has_path(row,path): + for arg in row['args'][1:]: + if Path(arg).name!=path.name:continue + actual=Path(arg) if Path(arg).is_absolute() else Path(row.get('cwd','/'))/arg + if actual.resolve()==path.resolve():return True + return False + +def controller(row,ancestors,self_pid,script,controller_files): + pid=row['pid'];args=row['args'];name=Path(row['exe'] or (args[0] if args else row['comm'])).name + if pid==self_pid:return 'quiet-inspector' + if pid not in ancestors or row['state'] not in ['S','I']:return None + if name in SHELLS:return 'waiting-ancestor-shell' + if name in ['sudo','env','timeout'] and has_path(row,script):return 'quiet-wrapper' + if name.startswith('python'): + if has_path(row,script):return 'quiet-wrapper' + if any(has_path(row,path) for path in controller_files):return 'verified-host-controller' + return None + +def category(row,task_root): + args=row['args'];name=Path(row['exe'] or (args[0] if args else row['comm'])).name;joined=' '.join(args) + if name in BUILDERS or any(v in joined for v in ['build-bun-standalone','build-linux.py','scripts/build.ts','native_phase.py']):return 'heavy-build' + if name.startswith(('qemu','firecracker')) or name in ['cloud-localds','mkfs.ext4','docker','docker-buildx']:return 'docker-or-guest-work' + if name in ['openclaw','openclaw-gateway'] or any(v in joined for v in ['run-cohort','stream-cohort','core-runner','run-functional','run-backup','measure-command','benchmark-prep','quiet.py']):return 'other-benchmark' + if name in RUNTIMES or name.startswith(('python','pip')) or any(v in joined for v in ['node-gyp','node-pre-gyp','postinstall','prepare-package','npm install','pnpm install']):return 'native-hook-or-runtime' + if task_root in joined or row.get('cwd','').startswith(task_root+'/') or '/p6-recipe' in joined or 'openclaw-p6' in joined:return 'task-process' + if name in SHELLS or name in ['stress','stress-ng','sysbench','fio','iperf','iperf3']:return 'unreconciled-host-work' + return None + +def classify(rows,containers,*,self_pid,main_name,identity,script,controller_files=(),errors=()): + allowed={};blocked=list(errors);container_facts=[] + if self_pid not in rows:blocked.append({'classification':'quiet-inspector-not-in-census'}) + own=identity['runId']+'-'+identity['runAttempt'];main=[] + for item in containers: + expected=item['name'].lstrip('/')==main_name and item['owner']==own + container_facts.append({'id':item['id'],'ownedMain':expected,'running':item['running']}) + if expected:main.append(item) + else:blocked.append({'classification':'other-container','containerId':item['id']}) + if len(main)!=1:blocked.append({'classification':'owned-main-container-missing-or-ambiguous'}) + else: + try: + for pid in idle_main(rows,main[0]):allowed[pid]='idle-owned-main' + except (ValueError,KeyError,IndexError):blocked.append({'classification':'owned-main-not-idle','pid':main[0].get('pid')}) + ancestors=ancestry(rows,self_pid) + for pid,row in rows.items(): + reason=controller(row,ancestors,self_pid,script,controller_files) + if reason:allowed[pid]=reason + for pid,row in rows.items(): + if pid in allowed:continue + label='uninterruptible-host-work' if row['state']=='D' else category(row,str(ROOT.parent)) + if label:blocked.append({'pid':pid,'ppid':row['ppid'],'startTicks':row['startTicks'],'classification':label}) + return {'quiet':not blocked,'blocking':blocked,'allowed':[{'pid':pid,'classification':value} for pid,value in sorted(allowed.items())],'containers':container_facts,'hostProcessCount':len(rows)} + +def budget_window(budget,deadline,now): + need(budget.get('sourceCommit')==SOURCE and budget.get('status')=='window-available','Complete measured cohort budget required') + required=budget.get('requiredSeconds');need(type(required) is int and required>0,'Positive required cohort seconds required') + need(budget.get('warmupSweeps')==1 and budget.get('measuredSweeps')==6,'Complete seven-sweep cohort required') + cells=budget.get('cells');need(isinstance(cells,list) and all(isinstance(v,str) for v in cells) and len(cells)==len(set(cells)) and set(cells)>={'js-aot','node-npm','bun-jit-npm'} and set(cells)<={'js-aot','c2-off-aot','ts-aot','node-npm','bun-jit-npm'},'Selected complete cohort cells differ') + need(budget['remainingSecondsAfterCleanupReserve']>=required,'Recorded cohort window insufficient') + return required,deadline-now-1200>=required + +def main(): + parser=argparse.ArgumentParser(description=__doc__);parser.add_argument('--identity',type=Path,required=True);parser.add_argument('--identity-sha256',required=True);parser.add_argument('--container',required=True);parser.add_argument('--reconcile-only',action='store_true');args=parser.parse_args() + need(platform.system()=='Linux' and platform.machine()=='x86_64' and os.geteuid()==0,'Host native x64 privileged inspection required') + current=execution(args.identity,args.identity_sha256,os.environ);identity=current['identity'];deadline=int(os.environ['P6_DEADLINE_EPOCH']) + target=ROOT/'benchmark-prep';need(target.is_dir() and not target.is_symlink(),'Existing task benchmark-prep required') + boot=Path('/proc/sys/kernel/random/boot_id').read_text().strip();need(re.fullmatch('[0-9a-f-]{36}',boot) is not None,'Host boot identity unavailable') + need(current.get('hostBootId')==boot,'Execution belongs to a different host boot') + template={'decision':'pending-host-reconciliation','sourceCommit':SOURCE,'nativeRoot':str(ROOT),'hostBootId':boot,'observedAtEpoch':time.time(),'reservationSeconds':None,'hostReconciliation':{'path':None,'sha256':None},**{v:False for v in FLAGS}} + if not args.reconcile_only or (target/'quiet-admission.json').exists():write(target/'quiet-admission.json',template) + evidence=target/('post-backup-reconciliation.json' if args.reconcile_only else 'host-reconciliation.json') + record={'schemaVersion':1,'status':'inspection-failed','identity':identity,'executionSha256':args.identity_sha256,'sourceCommit':SOURCE,'nativeRoot':str(ROOT),'hostBootId':boot,'resourceMutation':False,'rawArgvOrEnvironmentStored':False,'observations':[]} + code=1 + try: + controller_files=[v for v in [HERE/'host.py',HERE.parents[1]/'deadline_process.py'] if v.is_file()] + record['controllerSources']=[{'role':v.name,'sha256':sha(v)} for v in controller_files] + containers_before=read_containers();before,errors_before=read_processes() + first=cpu_point();time.sleep(SAMPLE_SECONDS);last=cpu_point() + after,errors_after=read_processes();containers_after=read_containers() + for rows,errors,containers in [(before,errors_before,containers_before),(after,errors_after,containers_after)]: + record['observations'].append(classify(rows,containers,self_pid=os.getpid(),main_name=args.container,identity=identity,script=Path(__file__).resolve(),controller_files=controller_files,errors=errors)) + record['cpuSampling']=cpu_activity(first,last,before,after,os.getpid(),os.sysconf('SC_CLK_TCK')) + quiet=all(v['quiet'] for v in record['observations']) and record['cpuSampling']['pass'];record['status']='quiet' if quiet else 'not-quiet' + if quiet: + now=time.time() + if args.reconcile_only: + code=0 if deadline-now-1200>0 else 78 + else: + budget=load(target/'cohort-budget.json');required,fits=budget_window(budget,deadline,now);record['cohortBudget']={'requiredSeconds':required,'cells':budget['cells'],'remainingSecondsAfterCleanupReserve':deadline-now-1200};code=0 if fits else 78 + if code==78:record['status']='insufficient-window' + except (OSError,ValueError,KeyError,subprocess.SubprocessError) as error: + record['status']='inspection-failed';record['inspectionErrorType']=type(error).__name__ + record['observedAtEpoch']=time.time();write(evidence,record) + if not args.reconcile_only and code==0: + template.update(decision='run-complete-selected-cell-cohort',observedAtEpoch=record['observedAtEpoch'],reservationSeconds=record['cohortBudget']['requiredSeconds'],hostReconciliation={'path':str(evidence),'sha256':sha(evidence)},executionIdentity=identity,executionSha256=args.identity_sha256) + template.update({v:True for v in FLAGS});write(target/'quiet-admission.json',template) + print(json.dumps({'status':record['status'],'reconciliation':str(evidence),'sha256':sha(evidence),'admitted':not args.reconcile_only and code==0}),flush=True) + return code +if __name__=='__main__':raise SystemExit(main()) diff --git a/scripts/openclaw-p6/app/benchmark/requalify.py b/scripts/openclaw-p6/app/benchmark/requalify.py new file mode 100644 index 000000000000..723b29474ddd --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/requalify.py @@ -0,0 +1,83 @@ +#!/usr/bin/env python3 +"""Replay only missing R4 functional proof on restored artifacts, without builds.""" +import json +import os +from pathlib import Path +import subprocess +import sys + +from app_contract import CUT, ROOT, dump, load, sha + +PHASES = ('node-vm-native-workers', 'docker-image', 'docker-gateway-network', 'docker-kitchen-sink') + + +def replay(root, work, invoke): + available = load(root / 'benchmark-prep/availability.json') + assert available['sourceCommit'] == CUT + execution = load(work / 'execution.json') + assert execution['sourceCommit'] == CUT and execution['identity']['job'] == 'linux-x64-benchmark' + result = {'sourceCommit': CUT, 'status': 'failed', 'applicationQualified': False, + 'performanceEligible': False, 'applicationBuildStarted': False, 'compilerBuildStarted': False, + 'execution': execution, 'executionSha256': sha(work / 'execution.json'), + 'origin': available['sourceAppExport'], 'phases': []} + target = root / 'benchmark-prep/requalification.json' + dump(target, result) + variants = [v for v in ('js', 'c2-off') if v in available['availableVariants']] + result['availableVariants'] = variants + result['unavailableVariants'] = [v for v in ('js', 'c2-off') if v not in variants] + result['requiredPhaseCount'] = len(variants) * len(PHASES) + terminal = 0 + for variant in ('js', 'c2-off'): + if variant not in available['availableVariants']: + result['phases'].append({'variant': variant, 'status': 'artifact-unavailable'}) + continue + assert available['variants'][variant]['status'] == 'artifact-restored-original-core-qualified' + admission = root / 'admissions' / (variant + '.json') + image_passed = False + for phase in PHASES: + entry = {'variant': variant, 'phase': phase, 'status': 'not-run'} + result['phases'].append(entry) + if phase.startswith('docker-') and phase != 'docker-image' and not image_passed: + entry['status'] = 'image-prerequisite-failed' + continue + command = [sys.executable, '-B', str(root / 'runtime-controller.py'), '--variant', variant, + '--phase', phase, '--admission-sha256', sha(admission)] + code = invoke(command) + code = code if code >= 0 else 128 - code + entry['exitCode'] = code + receipt = root / 'runtime-results' / (variant + '-' + phase) / 'result.json' + if receipt.is_file(): + observed = load(receipt) + assert observed['sourceCommit'] == CUT and observed['variant'] == variant and observed['phase'] == phase + assert observed['rootBuildAdmissionSha256'] == sha(admission) + assert observed['actualBuildReceiptSha256'] == sha(root / 'build-receipts' / variant / 'result.json') + entry.update(status=observed['status'], receipt=str(receipt), receiptSha256=sha(receipt)) + if code == 0: + assert observed['status'] == 'phase-passed' + else: + entry['status'] = 'missing-controller-receipt' + if phase == 'docker-image': + image_passed = code == 0 and entry['status'] == 'phase-passed' + if code == 124 or code >= 128: + terminal = code + break + if terminal: + break + actual = [entry for entry in result['phases'] if 'phase' in entry] + passed = bool(variants) and len(actual) == result['requiredPhaseCount'] and all( + entry['status'] == 'phase-passed' and entry.get('exitCode') == 0 for entry in actual) + result['status'] = 'phases-passed-pending-cleanup' if passed else 'failed' + # This task-owned summary evolves while immutable controller receipts remain authoritative. + target.write_text(json.dumps(result, indent=2) + '\n') + return terminal or (0 if passed else 1) + + +def main(): + assert sys.platform == 'linux' + assert 'GH_TOKEN' not in os.environ and 'GITHUB_TOKEN' not in os.environ + return replay(ROOT, Path(os.environ['P6_WORK']), + lambda command: subprocess.run(command, cwd=ROOT, check=False).returncode) + + +if __name__ == '__main__': + raise SystemExit(main()) diff --git a/scripts/openclaw-p6/app/benchmark/restore.py b/scripts/openclaw-p6/app/benchmark/restore.py new file mode 100644 index 000000000000..8d96ca908672 --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/restore.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python3 +"""Restore only successful individual app cells from one exact exported run.""" +import argparse,json,os,platform,shutil,subprocess,sys +from pathlib import Path +from app_contract import CUT,ROOT,VARIANTS,classify,dump,load,sha,verify_export +HERE=Path(__file__).resolve().parent + +def main(): + p=argparse.ArgumentParser();p.add_argument('--download',type=Path,required=True);a=p.parse_args() + assert platform.system()=='Linux' and platform.machine()=='x86_64';os.umask(0o077) + d=a.download;imported=d/'export' + verified=verify_export(load(d/'pins.json'),load(d/'run.json'),load(d/'artifact.json'),d/'app.zip',imported,existing=True) + assert load(d/'verification.json')==verified + assert load(ROOT/'prep-receipts/plugins/result.json')['status']=='PASS' + assert load(imported/'admission-inputs/compiler-records.json')==load(ROOT/'admission-inputs/compiler-records.json') + assert load(imported/'admission-inputs/plugins/desktop.json')==load(ROOT/'admission-inputs/plugins/desktop.json') + helper=ROOT/'preserve.py';assert sha(helper)==sha(HERE/'preserve.py') + records={};base=ROOT/'restored-app';base.mkdir() + for variant in VARIANTS: + entry=classify(imported,variant);records[variant]=entry + if entry['status']=='unavailable':continue + paths={k:Path(v) for k,v in entry['paths'].items()};transport=load(paths['transport']) + assert transport['sourceCommit']==CUT and transport['nativePlanSha256']==sha(paths['plan']) and transport['nativeResultSha256']==sha(paths['build']) + output=base/variant + command=[sys.executable,'-B',str(helper),'verify','--archive',str(paths['archive']),'--archive-sha256',transport['archiveSha256'],'--transport',str(paths['transport']),'--transport-sha256',sha(paths['transport']),'--source',str(ROOT/'source'),'--checker',str(ROOT/'build-prep/artifact-contract.mjs'),'--node',str(ROOT/'opt/node/bin/node'),'--out',str(output)] + subprocess.run(command,check=True,timeout=1800) + (ROOT/'artifacts').mkdir(exist_ok=True);assert not (ROOT/'artifacts'/variant).exists() + (output/'artifact').rename(ROOT/'artifacts'/variant) + for key,relative in [('admission',f'admissions/{variant}.json'),('plan',f'build-receipts/{variant}/plan.json'),('build',f'build-receipts/{variant}/result.json'),('core',f'qualification-results/{variant}-core/run/result.json'),('controller',f'runtime-results/{variant}-core/result.json'),('transport',f'preserved/{variant}/transport.json')]: + dest=ROOT/relative;dest.parent.mkdir(parents=True,exist_ok=True);assert not dest.exists();shutil.copyfile(paths[key],dest) + entry.update(status='artifact-restored-original-core-qualified',restorationReceipt=str(output/'verification.json'),restorationReceiptSha256=sha(output/'verification.json')) + available=[v for v in VARIANTS if records[v]['status']=='artifact-restored-original-core-qualified'] + result={'status':'restored' if 'js' in available else 'no-js-aot-baseline','sourceCommit':CUT,'sourceAppExport':verified,'sourceQualificationSummary':load(imported/'summary.json'),'requestedVariants':list(VARIANTS),'availableVariants':available,'variants':records,'performanceQualified':False} + dump(ROOT/'benchmark-prep/availability.json',result) + print(json.dumps(result)) + if 'js' not in available:raise SystemExit(78) +if __name__=='__main__':main() diff --git a/scripts/openclaw-p6/app/benchmark/stage.py b/scripts/openclaw-p6/app/benchmark/stage.py new file mode 100644 index 000000000000..f6a0ecea02db --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/stage.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python3 +"""Stage the reviewed benchmark payload beside the existing native owners.""" +import hashlib,json,shutil +from pathlib import Path +HERE=Path(__file__).resolve().parent +ROOT=Path('/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1') +assert not (ROOT/'benchmark-prep').exists() +manifest=json.loads((HERE/'payload/payload-manifest.json').read_text()) +for name,digest in manifest.items():assert hashlib.sha256((HERE/'payload'/name).read_bytes()).hexdigest()==digest,name +shutil.copytree(HERE/'payload',ROOT/'benchmark-prep') diff --git a/scripts/openclaw-p6/app/benchmark/test_contract.py b/scripts/openclaw-p6/app/benchmark/test_contract.py new file mode 100644 index 000000000000..b8a4511b8454 --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/test_contract.py @@ -0,0 +1,96 @@ +import hashlib,json,stat,tempfile,unittest,zipfile +from pathlib import Path +from app_contract import CUT,classify,sha,verify_export + +class Contract(unittest.TestCase): + def fixture(self,base,conclusion='failure',cleanup=None,selection=None): + head='a'*40;runid=12 + execution={'identity':{'repository':'openclaw/bun','runId':str(runid),'runAttempt':'2','job':'linux-x64-app'},'workflowHead':head,'sourceCommit':CUT} + rows={'host/execution.json':json.dumps(execution).encode()} + if cleanup is not None:rows['host/paging-cleanup.json']=json.dumps(cleanup).encode() + index=[{'path':k,'sha256':hashlib.sha256(v).hexdigest(),'bytes':len(v)} for k,v in rows.items()] + rows['index.json']=json.dumps(index).encode();rows['summary.json']=json.dumps({'sourceCommit':CUT,'pagingCleanup':cleanup,'unrunRequiredProof':['strict-zero-js'],**(selection or {})}).encode() + archive=base/'app.zip' + with zipfile.ZipFile(archive,'w') as z: + for name,data in rows.items():z.writestr(name,data) + digest=hashlib.sha256(archive.read_bytes()).hexdigest();size=archive.stat().st_size + pins={'repository':'openclaw/bun','repositoryId':3,'runId':runid,'runAttempt':2,'workflowId':4,'headSha':head,'artifact':{'id':5,'name':f'p6-linux-x64-app-{head}-attempt2','zipSha256':digest,'zipBytes':size},'maxUnpackedBytes':100000} + run={'id':runid,'run_attempt':2,'head_sha':head,'workflow_id':4,'path':'.github/workflows/openclaw-build-test.yml','repository':{'id':3,'full_name':'openclaw/bun'},'status':'completed','conclusion':conclusion} + meta={'id':5,'name':pins['artifact']['name'],'expired':False,'workflow_run':{'id':runid,'head_sha':head,'repository_id':3},'size_in_bytes':size,'digest':'sha256:'+digest} + return pins,run,meta,archive + def test_partial_origin_keeps_selection_and_ts_unavailability(self): + with tempfile.TemporaryDirectory() as d: + base=Path(d);selection={'variantSelection':'js-c2','requestedVariants':['js','c2-off'],'unselectedVariants':['ts'],'fullVariantMatrixComplete':False} + p,r,m,z=self.fixture(base,selection=selection) + verify_export(p,r,m,z,base/'out') + summary=json.loads((base/'out/summary.json').read_text()) + self.assertEqual(summary['requestedVariants'],['js','c2-off']) + self.assertFalse(summary['fullVariantMatrixComplete']) + self.assertEqual(classify(base/'out','ts')['status'],'unavailable') + + def test_failed_completed_run_is_allowed_but_exact_attempt_required(self): + with tempfile.TemporaryDirectory() as d: + base=Path(d);p,r,m,z=self.fixture(base) + self.assertEqual(verify_export(p,r,m,z,base/'good')['runConclusion'],'failure') + r['run_attempt']=3 + with self.assertRaises(AssertionError):verify_export(p,r,m,z,base/'bad') + def test_changed_export_fails_native_revalidation(self): + with tempfile.TemporaryDirectory() as d: + base=Path(d);p,r,m,z=self.fixture(base);verify_export(p,r,m,z,base/'out') + (base/'out/host/execution.json').write_text('{}') + with self.assertRaises(AssertionError):verify_export(p,r,m,z,base/'out',existing=True) + def test_wrong_zip_digest_is_rejected(self): + with tempfile.TemporaryDirectory() as d: + base=Path(d);p,r,m,z=self.fixture(base);p['artifact']['zipSha256']='0'*64 + with self.assertRaises(AssertionError):verify_export(p,r,m,z,base/'out') + def test_missing_ts_is_unavailable(self): + with tempfile.TemporaryDirectory() as d: + value=classify(Path(d),'ts');self.assertEqual(value['status'],'unavailable');self.assertFalse(value['performanceQualified']) + def test_failed_ts_is_unavailable_with_complete_export(self): + with tempfile.TemporaryDirectory() as d: + root=Path(d) + values={'build-receipts/ts/result.json':{'status':'failed'},'build-receipts/ts/plan.json':{},'admissions/ts.json':{},'qualification-results/ts-core/run/result.json':{'qualification':'failed'},'runtime-results/ts-core/result.json':{'status':'failed'},'preserved/ts/transport.json':{},'preserved/ts/artifact.tar':{}} + for name,value in values.items(): + p=root/name;p.parent.mkdir(parents=True,exist_ok=True);p.write_text(json.dumps(value)) + self.assertEqual(classify(root,'ts')['status'],'unavailable') + def test_traversal_rejected_before_extraction(self): + with tempfile.TemporaryDirectory() as d: + base=Path(d);p,r,m,z=self.fixture(base) + with zipfile.ZipFile(z,'a') as archive:archive.writestr('../escape',b'x') + digest=sha(z);size=z.stat().st_size;p['artifact'].update(zipSha256=digest,zipBytes=size);m.update(digest='sha256:'+digest,size_in_bytes=size) + with self.assertRaises(AssertionError):verify_export(p,r,m,z,base/'out') + self.assertFalse((base/'out').exists()) + def test_available_js_does_not_require_ts(self): + with tempfile.TemporaryDirectory() as d: + root=Path(d);variant='js';plan={'sourceProof':{'commit':CUT},'variant':variant} + data={'build-receipts/js/result.json':{'status':'built-unsigned','phase':'complete','plan':plan,'measurement':{'exitCode':0}},'build-receipts/js/plan.json':plan,'admissions/js.json':{},'qualification-results/js-core/run/result.json':{'qualification':'passed'},'preserved/js/transport.json':{},'preserved/js/artifact.tar':{}} + for name,value in data.items(): + p=root/name;p.parent.mkdir(parents=True,exist_ok=True);p.write_text(json.dumps(value)) + p=root/'runtime-results/js-core/result.json';p.parent.mkdir(parents=True);p.write_text(json.dumps({'status':'phase-passed','sourceCommit':CUT,'actualBuildReceiptSha256':sha(root/'build-receipts/js/result.json'),'rootBuildAdmissionSha256':sha(root/'admissions/js.json')})) + self.assertEqual(classify(root,'js')['status'],'available-pending-native-restoration') + self.assertEqual(classify(root,'ts')['status'],'unavailable') + broken=json.loads(p.read_text());broken['actualBuildReceiptSha256']='0'*64;p.write_text(json.dumps(broken)) + with self.assertRaises(AssertionError):classify(root,'js') + def test_cancelled_without_cleanup_is_rejected(self): + with tempfile.TemporaryDirectory() as d: + base=Path(d);p,r,m,z=self.fixture(base,conclusion='cancelled') + with self.assertRaises(AssertionError):verify_export(p,r,m,z,base/'out') + def test_cancelled_with_explicit_absent_resources_is_eligible(self): + with tempfile.TemporaryDirectory() as d: + base=Path(d);p,r,m,z=self.fixture(base,conclusion='cancelled',cleanup={'status':'not-activated','resourcesAbsent':True}) + self.assertTrue(verify_export(p,r,m,z,base/'out')['interruptedCleanupRequired']) + def test_unchanged_export_passes_native_revalidation(self): + with tempfile.TemporaryDirectory() as d: + base=Path(d);p,r,m,z=self.fixture(base);expected=verify_export(p,r,m,z,base/'out') + self.assertEqual(verify_export(p,r,m,z,base/'out',existing=True),expected) + def test_cleared_summary_failures_are_rejected(self): + with tempfile.TemporaryDirectory() as d: + base=Path(d);p,r,m,z=self.fixture(base);verify_export(p,r,m,z,base/'out') + target=base/'out/summary.json';summary=json.loads(target.read_text());summary['unrunRequiredProof']=[];target.write_text(json.dumps(summary)) + with self.assertRaises(AssertionError):verify_export(p,r,m,z,base/'out',existing=True) + def test_changed_local_index_is_rejected(self): + with tempfile.TemporaryDirectory() as d: + base=Path(d);p,r,m,z=self.fixture(base);verify_export(p,r,m,z,base/'out') + (base/'out/index.json').write_text('[]') + with self.assertRaises(AssertionError):verify_export(p,r,m,z,base/'out',existing=True) +if __name__=='__main__':unittest.main() diff --git a/scripts/openclaw-p6/app/benchmark/test_integration.py b/scripts/openclaw-p6/app/benchmark/test_integration.py new file mode 100644 index 000000000000..527c0586e916 --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/test_integration.py @@ -0,0 +1,325 @@ +#!/usr/bin/env python3 +"""Synthetic contracts for the workflow integration, without native execution.""" +import importlib.util +import json +import os +import shutil +from pathlib import Path +import tempfile +import subprocess +import sys +import unittest +from unittest.mock import patch + +HERE = Path(__file__).resolve().parent + +def module(name): + spec = importlib.util.spec_from_file_location('benchmark_' + name, HERE / (name + '.py')) + loaded = importlib.util.module_from_spec(spec) + spec.loader.exec_module(loaded) + return loaded + +INIT, HOST, EXPORT, REQUALIFY = module('initialize'), module('host'), module('export'), module('requalify') +BASE_ENV = {'GITHUB_REPOSITORY': 'openclaw/bun', 'GITHUB_RUN_ID': '22', 'GITHUB_RUN_ATTEMPT': '1', + 'GITHUB_JOB': 'linux-x64-benchmark', 'GITHUB_SHA': 'b'*40, 'P6_APP_REPOSITORY_ID': '9', + 'P6_APP_RUN_ID': '11', 'P6_APP_RUN_ATTEMPT': '2', 'P6_APP_WORKFLOW_ID': '8', + 'P6_APP_WORKFLOW_HEAD': 'a'*40, 'P6_APP_ARTIFACT_ID': '10', + 'P6_APP_ARTIFACT_NAME': 'p6-linux-x64-app-'+'a'*40+'-attempt2', + 'P6_APP_ZIP_SHA256': 'c'*64, 'P6_APP_ZIP_BYTES': '4096'} + +class Contracts(unittest.TestCase): + def test_exact_inputs_and_fresh_execution(self): + self.assertEqual(INIT.app_inputs(BASE_ENV)['runAttempt'], 2) + for key, value in [('P6_APP_RUN_ID', ''), ('P6_APP_RUN_ATTEMPT', '0'), + ('P6_APP_RUN_ID', '22'), ('P6_APP_ZIP_BYTES', 'NaN'), + ('P6_APP_ARTIFACT_NAME', 'wrong'), ('P6_APP_ZIP_SHA256', 'x'*64), + ('P6_APP_WORKFLOW_HEAD', 'a'*39), ('GITHUB_JOB', 'linux-x64-app')]: + with self.subTest(key=key, value=value), self.assertRaises((AssertionError, ValueError)): + INIT.app_inputs({**BASE_ENV, key: value}) + + def test_input_cli_rejects_unbound_or_shell_text(self): + with tempfile.TemporaryDirectory() as tmp: + marker = Path(tmp)/'injected' + env = {**os.environ, **BASE_ENV, 'P6_WORK': str(Path(tmp)/'work'), + 'P6_APP_RUN_ID': '$(touch '+str(marker)+')'} + run = subprocess.run([sys.executable, '-B', str(HERE/'initialize.py'), 'inputs'], + env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + self.assertNotEqual(run.returncode, 0) + self.assertFalse(marker.exists()) + self.assertFalse((Path(tmp)/'work/app-inputs.json').exists()) + + def run_sequence(self, failed=None, code=1, reconciliation=0): + seen = [] + def phase(name, command): + seen.append(name) + self.assertNotIn('/p6-recipe/app/variant.sh', command) + self.assertNotIn('paging', command) + return code if name == failed else 0 + def reconcile(only): + seen.append('reconcile' if only else 'quiet') + return reconciliation + def cleanup(): + seen.append('children-cleanup') + return reconciliation + with patch.dict(os.environ, {'P6_WORK': '/synthetic/work'}): + result = HOST.sequence(phase, reconcile, cleanup) + return result, seen + + def test_complete_sequence(self): + code, seen = self.run_sequence() + self.assertEqual(code, 0) + self.assertLess(seen.index('requalification'), seen.index('children-cleanup')) + self.assertLess(seen.index('children-cleanup'), seen.index('backup-untimed')) + self.assertLess(seen.index('backup-untimed'), seen.index('reconcile')) + self.assertLess(seen.index('budget'), seen.index('quiet')) + self.assertEqual(seen[-3:], ['window', 'cohort', 'summary']) + + def test_backup_failure_continues_only_after_reconciliation(self): + code, seen = self.run_sequence('backup-untimed', 1) + self.assertEqual(code, 0) + self.assertIn('functional', seen) + code, seen = self.run_sequence('backup-untimed', 1, 1) + self.assertEqual(code, 1) + self.assertNotIn('functional', seen) + + def test_terminal_and_insufficient_budget_never_continue(self): + for fail, code in [('requalification', 124), ('requalification', 143), ('backup-untimed', 124), ('backup-untimed', 143), + ('functional', 1), ('budget', 78), ('cohort', 137)]: + result, seen = self.run_sequence(fail, code) + self.assertEqual(result, code) + self.assertEqual(seen[-1], fail) + + def test_failed_requalification_keeps_comparator_after_cleanup(self): + code, seen = self.run_sequence('requalification', 1) + self.assertEqual(code, 0) + self.assertIn('children-cleanup', seen) + self.assertIn('functional', seen) + self.assertIn('cohort', seen) + + def test_replay_receipts_and_terminal_failure(self): + for failure, exit_code in [(None, 0), ('js-only',0), ('js-docker-gateway-network', 1), + ('js-docker-image', 1), ('js-node-vm-native-workers', 143)]: + with self.subTest(failure=failure), tempfile.TemporaryDirectory() as tmp: + root, work = Path(tmp)/'root', Path(tmp)/'work' + work.mkdir() + def put(path, value): + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text(json.dumps(value)) + put(work/'execution.json', {'sourceCommit':EXPORT.CUT, 'identity':{'job':'linux-x64-benchmark'}}) + put(root/'benchmark-prep/availability.json', {'sourceCommit':EXPORT.CUT, + 'sourceAppExport':{'runId':11}, 'availableVariants':['js'] if failure == 'js-only' else ['js','c2-off'], + 'variants':{v:{'status':'artifact-restored-original-core-qualified'} for v in ['js','c2-off']}}) + for variant in ['js','c2-off']: + put(root/'admissions'/(variant+'.json'), {'variant':variant}) + put(root/'build-receipts'/variant/'result.json', {'variant':variant}) + called = [] + def invoke(command): + variant, phase = command[command.index('--variant')+1], command[command.index('--phase')+1] + label = variant+'-'+phase + called.append(label) + code = exit_code if label == failure else 0 + put(root/'runtime-results'/label/'result.json', {'sourceCommit':EXPORT.CUT, + 'variant':variant, 'phase':phase, 'status':'phase-passed' if code == 0 else 'phase-failed', + 'rootBuildAdmissionSha256':REQUALIFY.sha(root/'admissions'/(variant+'.json')), + 'actualBuildReceiptSha256':REQUALIFY.sha(root/'build-receipts'/variant/'result.json')}) + return code + code = REQUALIFY.replay(root, work, invoke) + result = REQUALIFY.load(root/'benchmark-prep/requalification.json') + self.assertEqual(code, 0 if failure in [None,'js-only'] else exit_code) + self.assertEqual(result['status'], 'phases-passed-pending-cleanup' if failure in [None,'js-only'] else 'failed') + self.assertFalse(result['applicationBuildStarted']) + if failure == 'js-only': + self.assertEqual(result['requiredPhaseCount'],4) + self.assertEqual(result['unavailableVariants'],['c2-off']) + self.assertEqual(result['phases'][-1],{'variant':'c2-off','status':'artifact-unavailable'}) + if failure == 'js-docker-image': + self.assertNotIn('js-docker-gateway-network', called) + self.assertIn('c2-off-docker-kitchen-sink', called) + if exit_code == 143: + self.assertEqual(called, ['js-node-vm-native-workers']) + if failure == 'js-docker-gateway-network': + self.assertIn('js-docker-kitchen-sink', called) + self.assertIn('c2-off-docker-kitchen-sink', called) + + def test_signal_normalization(self): + self.assertEqual(HOST.normalized(-15), 143) + self.assertTrue(HOST.terminal(HOST.normalized(-9))) + self.assertFalse(HOST.terminal(78)) + + def test_export_excludes_installed_home_cache_and_package_source(self): + with tempfile.TemporaryDirectory() as tmp: + root, work = Path(tmp)/'root', Path(tmp)/'work' + work.mkdir(); root.mkdir() + prep = root/'benchmark-prep' + def put(path, value='synthetic'): + path.parent.mkdir(parents=True, exist_ok=True); path.write_text(value) + put(prep/'work/js-core/result.json', '{}') + put(prep/'work/js-core/logs/gateway.stdout') + put(prep/'work/js-knowledge/knowledge/result.json', '{}') + for relative in ['work/installed/secret', 'work/home/secret', 'work/cache/secret', + 'package-source/secret', 'work/js-core/home/secret', + 'work/js-core/tmp/secret', 'work/cohort/controller-home/secret']: + put(prep/relative) + put(root/'backup-results/js/state/secret') + put(root/'backup-results/js/result.json', '{}') + put(root/'runtime-results/js-docker-kitchen-sink/raw-evidence.tar.gz', 'synthetic raw archive') + EXPORT.export(work, root) + paths = [r['path'] for r in json.loads((work/'benchmark-export/index.json').read_text())] + self.assertIn('work/js-core/result.json', paths) + self.assertIn('work/js-core/logs/gateway.stdout', paths) + self.assertIn('work/js-knowledge/knowledge/result.json', paths) + self.assertIn('backup-results/js/result.json', paths) + self.assertIn('requalification/runtime-results/js-docker-kitchen-sink/raw-evidence.tar.gz', paths) + self.assertFalse(any('secret' in p for p in paths)) + + def test_export_rejects_symlinked_receipt(self): + with tempfile.TemporaryDirectory() as tmp: + root, work = Path(tmp)/'root', Path(tmp)/'work' + work.mkdir(); (root/'benchmark-prep').mkdir(parents=True) + (work/'payload').write_text('{}') + (root/'benchmark-prep/availability.json').symlink_to(work/'payload') + with self.assertRaises(AssertionError): + EXPORT.export(work, root) + + def test_backup_failure_and_terminal_are_not_passing_job(self): + with tempfile.TemporaryDirectory() as tmp: + root, work = Path(tmp)/'root', Path(tmp)/'work' + work.mkdir(); root.mkdir() + def put(path, value): + path.parent.mkdir(parents=True, exist_ok=True); path.write_text(json.dumps(value)) + identity = INIT.identity(BASE_ENV) + put(work/'execution.json', {'identity': identity}) + put(work/'benchmark-run.json', {'status':'completed'}) + put(work/'benchmark-cleanup.json', {'status':'owned-workloads-removed', 'identity':identity, 'pagingActivated':False}) + put(root/'benchmark-prep/comparison-summary.json', {'status':'partial-comparison-passed','performanceQualified':True}) + put(root/'backup-results/summary.json', {'status':'passed'}) + self.assertFalse(EXPORT.summary(work, root)['scheduledWorkComplete']) + put(root/'prep-receipts/compatibility/result.json', {'status':'PASS'}) + self.assertFalse(EXPORT.summary(work, root)['scheduledWorkComplete']) + put(root/'benchmark-prep/work/knowledge-controls.json', {'status':'passed','sourceCommit':EXPORT.CUT}) + self.assertFalse(EXPORT.summary(work, root)['scheduledWorkComplete']) + put(root/'benchmark-prep/requalification.json', {'status':'phases-passed-pending-cleanup'}) + self.assertFalse(EXPORT.summary(work, root)['scheduledWorkComplete']) + put(work/'requalification-child-cleanup.json', {'status':'children-removed', + 'identity':identity,'executionSha256':EXPORT.sha(work/'execution.json'),'forcedRecovery':True}) + self.assertFalse(EXPORT.summary(work, root)['scheduledWorkComplete']) + self.assertEqual(EXPORT.summary(work, root)['untimedRequalification']['status'],'failed') + put(work/'requalification-child-cleanup.json', {'status':'children-removed', + 'identity':identity,'executionSha256':EXPORT.sha(work/'execution.json'),'forcedRecovery':False}) + self.assertTrue(EXPORT.summary(work, root)['scheduledWorkComplete']) + put(root/'benchmark-prep/work/knowledge-controls.json', {'status':'failed','sourceCommit':EXPORT.CUT}) + self.assertFalse(EXPORT.summary(work, root)['scheduledWorkComplete']) + put(root/'benchmark-prep/work/knowledge-controls.json', {'status':'passed','sourceCommit':EXPORT.CUT}) + put(root/'backup-results/summary.json', {'status':'failed'}) + self.assertFalse(EXPORT.summary(work, root)['scheduledWorkComplete']) + put(root/'backup-results/summary.json', {'status':'passed'}) + put(root/'benchmark-prep/requalification.json', {'status':'failed'}) + self.assertFalse(EXPORT.summary(work, root)['scheduledWorkComplete']) + put(root/'benchmark-prep/requalification.json', {'status':'phases-passed-pending-cleanup'}) + put(work/'terminal.json', {'exitCode':124}) + self.assertFalse(EXPORT.summary(work, root)['scheduledWorkComplete']) + +class PackageNpmConfigContracts(unittest.TestCase): + def test_offline_lockfile_ignores_home_config(self): + node, npm = shutil.which('node'), shutil.which('npm') + if not node or not npm: + self.skipTest('Node and npm are required for the offline npm config regression') + npm = Path(npm).resolve() + version = json.loads((npm.parent.parent/'package.json').read_text())['version'] + if version.split('.')[0] != '11': + self.skipTest('The config-loading regression requires npm 11') + script = (HERE/'payload/prepare-package.sh').read_text() + setup = 'export HOME=' + script.split('export HOME=',1)[1].split('\npython3 - ',1)[0] + with tempfile.TemporaryDirectory() as tmp: + root = Path(tmp).resolve() + here = root/'benchmark-prep' + home = here/'package-home' + home.mkdir(parents=True) + ambient = home/'.npmrc' + ambient.write_text('registry=https://ambient.invalid/\n') + package = root/'package' + package.mkdir() + (package/'package.json').write_text('{"name":"p6-npm-config-fixture","version":"1.0.0"}\n') + command = ('set -euo pipefail\numask 077\nroot=$1\nhere=$2\n' + setup + '\n' + 'printf "%s\\n" "$NPM_CONFIG_USERCONFIG" "$NPM_CONFIG_GLOBALCONFIG" "$TMPDIR" > "$here/config-paths"\n' + '"$3" "$4" install --package-lock-only --ignore-scripts --no-audit --no-fund --offline\n' + '"$3" "$4" config get registry > "$here/registry"\n') + result = subprocess.run(['/bin/bash','-c',command,'npm-config-proof',str(root),str(here),node,str(npm)], + cwd=package,env={'PATH':'/usr/bin:/bin'},capture_output=True,text=True,timeout=30) + self.assertEqual(result.returncode,0,result.stderr) + user, global_config, task_tmp = map(Path,(here/'config-paths').read_text().splitlines()) + self.assertNotEqual(user,global_config) + for config in [user,global_config]: + self.assertEqual(config.parent,task_tmp) + self.assertEqual(config.read_bytes(),b'') + self.assertEqual((here/'registry').read_text(),'https://registry.npmjs.org/\n') + self.assertEqual(ambient.read_text(),'registry=https://ambient.invalid/\n') + lock = json.loads((package/'package-lock.json').read_text()) + self.assertEqual(lock['packages']['']['name'],'p6-npm-config-fixture') + + +class PackageCloneContracts(unittest.TestCase): + def run_guard(self, clone, script=None): + script = (HERE/'payload/prepare-package.sh').read_text() if script is None else script + code = script.split('python3 - "$here/package-source" <<\'PY\'\n',1)[1].split('\nPY\n',1)[0] + return subprocess.run([sys.executable,'-B','-c',code,str(clone)],capture_output=True,text=True) + + def fixture(self, root): + source=root/'canonical';boundary=source/'.artifacts/extension-package-boundary' + (boundary/'plugins/matrix').mkdir(parents=True) + external=root/'external-dependencies';external.mkdir() + (external/'sentinel').write_text('unchanged') + (boundary/'plugins/matrix/node_modules').symlink_to(external,target_is_directory=True) + (source/'package.json').write_text('{"fixture":true}') + clone=root/'package-source' + shutil.copytree(source,clone,symlinks=True) + return source,clone,external + + def test_preserves_only_private_boundary_and_keeps_canonical_source(self): + with tempfile.TemporaryDirectory() as tmp: + root=Path(tmp).resolve();source,clone,external=self.fixture(root) + result=self.run_guard(clone) + self.assertEqual(result.returncode,0,result.stderr) + self.assertFalse((clone/'.artifacts/extension-package-boundary').exists()) + preserved=root/'package-boundary-preserved/plugins/matrix/node_modules' + self.assertTrue(preserved.is_symlink()) + self.assertEqual(preserved.resolve(),external) + self.assertTrue((source/'.artifacts/extension-package-boundary/plugins/matrix/node_modules').is_symlink()) + self.assertEqual((source/'package.json').read_bytes(),(clone/'package.json').read_bytes()) + self.assertEqual((external/'sentinel').read_text(),'unchanged') + + def test_other_external_links_still_fail_after_boundary_preservation(self): + for relative in ['extensions/other/node_modules','dist/other-link']: + with self.subTest(relative=relative),tempfile.TemporaryDirectory() as tmp: + root=Path(tmp).resolve();source,clone,external=self.fixture(root) + link=clone/relative;link.parent.mkdir(parents=True);link.symlink_to(external,target_is_directory=True) + result=self.run_guard(clone) + self.assertNotEqual(result.returncode,0) + self.assertIn('Private package clone has external link: '+str(link),result.stderr) + + def test_symlinked_boundary_ancestor_and_existing_preservation_are_rejected(self): + for shape in ['ancestor','boundary','destination']: + with self.subTest(shape=shape),tempfile.TemporaryDirectory() as tmp: + root=Path(tmp).resolve();source,clone,external=self.fixture(root) + if shape=='destination': + (root/'package-boundary-preserved').mkdir() + else: + path=clone/('.artifacts' if shape=='ancestor' else '.artifacts/extension-package-boundary') + shutil.rmtree(path);path.symlink_to(external,target_is_directory=True) + result=self.run_guard(clone) + self.assertNotEqual(result.returncode,0) + self.assertEqual((external/'sentinel').read_text(),'unchanged') + self.assertTrue((source/'.artifacts/extension-package-boundary/plugins/matrix/node_modules').is_symlink()) + + def test_absent_boundary_keeps_internal_links_and_creates_no_preservation(self): + with tempfile.TemporaryDirectory() as tmp: + root=Path(tmp).resolve();clone=root/'package-source';(clone/'node_modules').mkdir(parents=True) + (clone/'internal-link').symlink_to(clone/'node_modules',target_is_directory=True) + result=self.run_guard(clone) + self.assertEqual(result.returncode,0,result.stderr) + self.assertTrue((clone/'internal-link').is_symlink()) + self.assertFalse((root/'package-boundary-preserved').exists()) + + +if __name__ == '__main__': + unittest.main() diff --git a/scripts/openclaw-p6/app/benchmark/test_knowledge.py b/scripts/openclaw-p6/app/benchmark/test_knowledge.py new file mode 100644 index 000000000000..dbe41b9248f2 --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/test_knowledge.py @@ -0,0 +1,150 @@ +"""Synthetic admitted-agent contracts; no OpenClaw process or database is executed.""" +import importlib.util +import json +import os +from pathlib import Path +import subprocess +import tempfile +import unittest +import urllib.error +import urllib.request + +HERE = Path(__file__).resolve().parent +spec = importlib.util.spec_from_file_location('knowledge_provider', HERE/'payload/harness/knowledge-provider.py') +PROVIDER = importlib.util.module_from_spec(spec) +spec.loader.exec_module(PROVIDER) +MODEL = 'p6-deterministic' +MARKER = 'P6_KNOWLEDGE_AGENT_PROOF_OK' +VAULT = '11111111-1111-4111-8111-111111111111' +ONTOLOGY = {'available': True, 'total': 38, 'fingerprint': 'a'*64} + + +def request(index, value=None): + body = {'model': MODEL, 'stream': True, 'tools': [{'name': name} for name, _ in PROVIDER.CALLS]} + body['input'] = MARKER if index == 0 else [{'type': 'function_call_output', + 'call_id': f'call_p6_{index-1}', 'output': json.dumps(value)}] + return body + + +def outputs(): + return [[{'name': 'knowledge_ontology'}], {'name': 'knowledge_ontology', 'parameters': {}}, + {'tool': {'name': 'knowledge_ontology'}, 'result': {'content': [ + {'type': 'text', 'text': json.dumps(ONTOLOGY)}]}}] + + +class KnowledgeControl(unittest.TestCase): + def test_exact_four_request_script_consumes_actual_tool_outputs(self): + with tempfile.TemporaryDirectory() as temp: + provider = PROVIDER.ScriptedProvider(Path(temp)/'provider.json', MODEL, MARKER) + for index, value in enumerate([None, *outputs()]): + events = provider.events(request(index, value), '/v1/responses') + self.assertEqual(events[-1]['type'], 'response.completed') + self.assertEqual(provider.ontology, ONTOLOGY) + self.assertEqual([row['callId'] for row in provider.outputs], ['call_p6_0','call_p6_1','call_p6_2']) + with self.assertRaises(AssertionError): + provider.events(request(4, {}), '/v1/responses') + + def test_invalid_admitted_tool_output_is_rejected(self): + for invalid in [{'error': 'denied'}, [], {'name': 'wrong'}, {'isError': True}]: + with self.subTest(invalid=invalid), tempfile.TemporaryDirectory() as temp: + provider = PROVIDER.ScriptedProvider(Path(temp)/'provider.json', MODEL, MARKER) + provider.events(request(0), '/v1/responses') + with self.assertRaises(AssertionError): + provider.events(request(1, invalid), '/v1/responses') + + def test_wrong_request_identity_or_tools_is_rejected(self): + for patch in [{'model':'wrong'}, {'stream':False}, {'tools':[]}]: + with self.subTest(patch=patch), tempfile.TemporaryDirectory() as temp: + provider = PROVIDER.ScriptedProvider(Path(temp)/'provider.json', MODEL, MARKER) + with self.assertRaises(AssertionError): + provider.events({**request(0), **patch}, '/v1/responses') + + def test_http_failure_is_recorded_and_does_not_fallback(self): + with tempfile.TemporaryDirectory() as temp: + receipt = Path(temp)/'provider.json' + provider = PROVIDER.ScriptedProvider(receipt, MODEL, MARKER) + server, thread = provider.start() + try: + req = urllib.request.Request('http://127.0.0.1:'+str(server.server_port)+'/v1/responses', + data=json.dumps({**request(0), 'model':'wrong'}).encode(), method='POST') + with self.assertRaises(urllib.error.HTTPError) as raised: + urllib.request.urlopen(req, timeout=5) + self.assertEqual(raised.exception.code, 400) + saved = json.loads(receipt.read_text()) + self.assertEqual(len(saved['requests']), 1) + self.assertEqual(len(saved['errors']), 1) + finally: + server.shutdown(); server.server_close(); thread.join(timeout=5) + + def test_operator_and_agent_proof_require_real_admission_and_matching_store(self): + module = (HERE/'payload/harness/knowledge-agent.mjs').as_uri() + script = ''' +import fs from 'node:fs';import path from 'node:path'; +import {qualifyKnowledgeAgent,KNOWLEDGE_MODEL,KNOWLEDGE_MARKER} from MODULE; +const [root,mode]=process.argv.slice(1);const out=path.join(root,'out'),state=path.join(root,'state'); +fs.mkdirSync(path.join(out,'logs'),{recursive:true}); +fs.writeFileSync(path.join(out,'logs/knowledge-turn.stderr'),mode==='fallback'?'falling back':''); +const vault='11111111-1111-4111-8111-111111111111';const store=path.join(state,'knowledge/stores',vault); +fs.mkdirSync(path.join(store,'vault'),{recursive:true}); +for(const file of [path.join(state,'knowledge/registry.sqlite'),path.join(store,'state.sqlite')])fs.writeFileSync(file,'synthetic'); +fs.writeFileSync(path.join(store,'vault/vault.json'),JSON.stringify({vaultId:vault})); +const ontology={available:true,total:38,fingerprint:'a'.repeat(64)}; +const receipt=path.join(root,'provider.json');fs.writeFileSync(receipt,JSON.stringify({model:KNOWLEDGE_MODEL,marker:KNOWLEDGE_MARKER, + requests:[0,1,2,3].map(index=>({index,path:'/v1/responses',stream:true,model:KNOWLEDGE_MODEL})), + outputs:[0,1,2].map(index=>({callId:'call_p6_'+index})),ontology,errors:[]})); +const calls=[];const command=async(label,args)=>{calls.push({label,args}); + if(label==='knowledge-status-before')return JSON.stringify({ok:true,result:{agent:'main',store:'unprovisioned'}}); + if(label==='knowledge-session-create')return JSON.stringify({ok:true,key:'agent:main:admitted',entry:{chatType:mode==='foreign'?'group':'direct',createdVia:'operator'},runStarted:false}); + if(label==='knowledge-turn')return JSON.stringify({status:'ok',summary:'completed',result:{payloads:[{text:KNOWLEDGE_MARKER}]}}); + if(label==='knowledge-status-after')return JSON.stringify({ok:true,result:{agent:'main',store:'ready',ontologyAvailable:true,definitions:38,ontologyFingerprint:'a'.repeat(64),vault}}); + if(label==='knowledge-ontology-after')return JSON.stringify({ok:true,result:{...ontology,fingerprint:(mode==='fingerprint'?'b':'a').repeat(64)}}); + throw new Error(label);}; +try{const result=await qualifyKnowledgeAgent({command,port:23456,token:'p6-synthetic',stateDir:state,out,providerReceipt:receipt});console.log(JSON.stringify({result,calls}));} +catch(error){console.log(JSON.stringify({error:String(error),calls}));process.exitCode=1;} +'''.replace('MODULE', json.dumps(module)) + for mode in ['valid','foreign','fingerprint','fallback']: + with self.subTest(mode=mode), tempfile.TemporaryDirectory() as temp: + run = subprocess.run(['node','--input-type=module','-e',script,temp,mode],capture_output=True,text=True,timeout=10) + value = json.loads(run.stdout) + self.assertEqual(run.returncode, 0 if mode=='valid' else 1) + self.assertTrue(all('/tools/invoke' not in str(call) for call in value['calls'])) + if mode=='valid': + self.assertEqual(value['result']['status'], 'passed-operations-only') + self.assertEqual(value['result']['providerRequests'], 4) + self.assertEqual(value['calls'][1]['args'][2], 'sessions.create') + + def test_late_request_or_missing_final_receipt_cannot_leave_qualification_passed(self): + module = (HERE/'payload/harness/knowledge-agent.mjs').as_uri() + script = """ +import fs from 'node:fs';import path from 'node:path'; +import {finalizeKnowledgeProvider,KNOWLEDGE_MODEL,KNOWLEDGE_MARKER} from MODULE; +const file=path.join(process.argv[1],'provider.json'); +const receipt={model:KNOWLEDGE_MODEL,marker:KNOWLEDGE_MARKER,errors:[], + requests:[0,1,2,3].map(index=>({index,path:'/v1/responses',stream:true,model:KNOWLEDGE_MODEL})), + outputs:[0,1,2].map(index=>({callId:'call_p6_'+index})),ontology:{available:true,total:38,fingerprint:'a'.repeat(64)}}; +fs.writeFileSync(file,JSON.stringify(receipt)); +const before={qualification:'passed'};finalizeKnowledgeProvider(before,file); +receipt.requests.push({index:4});fs.writeFileSync(file,JSON.stringify(receipt)); +const late={qualification:'passed'};finalizeKnowledgeProvider(late,file); +fs.writeFileSync(file,'invalid');const invalid={qualification:'passed'};finalizeKnowledgeProvider(invalid,file); +fs.unlinkSync(file);const missing={qualification:'passed'};finalizeKnowledgeProvider(missing,file); +console.log(JSON.stringify({before,late,invalid,missing})); +""".replace('MODULE',json.dumps(module)) + with tempfile.TemporaryDirectory() as temp: + result=json.loads(subprocess.check_output(['node','--input-type=module','-e',script,temp],text=True)) + self.assertEqual(result['before']['qualification'],'passed') + for name in ['late','invalid','missing']: + self.assertEqual(result[name]['qualification'],'failed') + self.assertEqual(result[name]['knowledgeProviderFinal']['status'],'failed') + + def test_fixture_opt_in_leaves_normal_cohort_configuration_unchanged(self): + module = (HERE/'payload/harness/fixture-config.mjs').as_uri() + script = '''import {coreFixtureConfig} from MODULE; +const args={workspace:'/synthetic',port:1234,token:'p6-synthetic',mockPort:1235,applyMockOpenAiModelConfig:()=>{}}; +console.log(JSON.stringify([coreFixtureConfig(args),coreFixtureConfig({...args,knowledgeControl:true})]));'''.replace('MODULE',json.dumps(module)) + normal,control=json.loads(subprocess.check_output(['node','--input-type=module','-e',script],text=True)) + self.assertEqual(normal['tools'],{'allow':[],'deny':['*']}) + self.assertEqual(control['tools']['allow'],['knowledge_status','knowledge_ontology','tool_search','tool_describe','dispatch_action']) + + +if __name__ == '__main__':unittest.main() diff --git a/scripts/openclaw-p6/app/benchmark/test_quiet.py b/scripts/openclaw-p6/app/benchmark/test_quiet.py new file mode 100644 index 000000000000..f728c38e26cf --- /dev/null +++ b/scripts/openclaw-p6/app/benchmark/test_quiet.py @@ -0,0 +1,119 @@ +"""Pure synthetic host snapshots and receipt boundaries; no Docker/proc workload.""" +import contextlib,copy,hashlib,importlib.util,io,json,os,sys,tempfile,unittest +from pathlib import Path +from unittest.mock import patch +HERE=Path(__file__).resolve().parent +spec=importlib.util.spec_from_file_location('quiet',HERE/'quiet.py');g=importlib.util.module_from_spec(spec);spec.loader.exec_module(g) +BOOT='11111111-2222-3333-4444-555555555555' +IDENTITY={'repository':'openclaw/bun','runId':'21','runAttempt':'1','job':'linux-x64-benchmark'} +def row(pid,ppid,exe,args=None,cwd='/',state='S'): + return {'pid':pid,'ppid':ppid,'exe':exe,'args':args or [exe],'cwd':cwd,'state':state,'startTicks':pid*10,'cpuTicks':0,'comm':Path(exe).name} +def fixture(): + return {1:row(1,0,'/sbin/init'),500:row(500,1,'/usr/bin/bash'),600:row(600,500,'/usr/bin/python3',['python3','/recipe/host.py','run']),700:row(700,600,'/usr/bin/python3',['python3',str(HERE/'quiet.py')]),200:row(200,1,'/sbin/docker-init',['/sbin/docker-init','--','sleep','infinity']),201:row(201,200,'/usr/bin/sleep',['sleep','infinity'])} +def container():return {'id':'a'*64,'name':'/p6-benchmark-21-1','pid':200,'running':True,'paused':False,'restarting':False,'owner':'21-1','command':['sleep','infinity'],'entrypoint':None} +def classify(rows=None,containers=None,errors=()):return g.classify(rows or fixture(),containers if containers is not None else [container()],self_pid=700,main_name='p6-benchmark-21-1',identity=IDENTITY,script=HERE/'quiet.py',controller_files=[Path('/recipe/host.py')],errors=errors) + +class HostContracts(unittest.TestCase): + def test_idle_owned_main_and_verified_ancestor_only(self): + result=classify();self.assertTrue(result['quiet']);self.assertEqual({r['pid'] for r in result['allowed']},{200,201,500,600,700}) + rows=fixture();rows[601]=row(601,1,'/usr/bin/python3',['python3','/recipe/host.py','run']) + self.assertFalse(classify(rows)['quiet']) + rows=fixture();rows[600]['args']=['python3','/unreviewed/controller.py'];self.assertFalse(classify(rows)['quiet']) + def test_build_hook_guest_benchmark_task_and_shell_block(self): + cases=[('heavy-build','/usr/bin/clang',['clang','input.cc'],'/'),('native-hook-or-runtime','/usr/bin/node',['node','install-hook.js'],'/'),('docker-or-guest-work','/usr/bin/qemu-system-x86_64',['qemu-system-x86_64'],'/'),('other-benchmark','/usr/bin/node',['node','run-cohort.mjs'],'/'),('other-benchmark','/usr/local/bin/openclaw',['openclaw','gateway'],'/'),('task-process','/usr/bin/cat',['cat',str(g.ROOT/'source/input')],'/'),('unreconciled-host-work','/usr/bin/bash',['bash','other-task.sh'],'/')] + for expected,exe,args,cwd in cases: + with self.subTest(expected=expected): + rows=fixture();rows[900]=row(900,1,exe,args+['SYNTHETIC-PRIVATE-ARGV'],cwd);result=classify(rows) + self.assertFalse(result['quiet']);self.assertIn(expected,[v['classification'] for v in result['blocking']]);self.assertNotIn('SYNTHETIC-PRIVATE',json.dumps(result));self.assertNotIn('args',json.dumps(result)) + def test_other_containers_or_owned_main_descendants_block(self): + other={**container(),'id':'b'*64,'name':'/other','owner':'other','running':False};self.assertFalse(classify(containers=[container(),other])['quiet']) + rows=fixture();rows[202]=row(202,200,'/usr/bin/sleep',['sleep','100']);self.assertFalse(classify(rows)['quiet']) + self.assertFalse(classify(containers=[{**container(),'owner':'different'}])['quiet']) + self.assertFalse(classify(containers=[{**container(),'command':['bash']}])['quiet']) + def test_failed_inspection_and_busy_ancestor_do_not_admit(self): + self.assertFalse(classify(errors=[{'pid':99,'classification':'process-inspection-failed'}])['quiet']) + rows=fixture();del rows[700];self.assertFalse(classify(rows)['quiet']) + rows=fixture();rows[600]['state']='R';self.assertFalse(classify(rows)['quiet']) + def test_relative_orchestrator_path_is_verified_against_cwd(self): + rows=fixture();rows[600]['args']=['python3','host.py','run'];rows[600]['cwd']='/recipe';self.assertTrue(classify(rows)['quiet']) + def test_dynamic_budget_threshold_and_complete_cells(self): + budget={'sourceCommit':g.SOURCE,'status':'window-available','requiredSeconds':500,'remainingSecondsAfterCleanupReserve':600,'warmupSweeps':1,'measuredSweeps':6,'cells':['js-aot','node-npm','bun-jit-npm']} + self.assertEqual(g.budget_window(budget,2700,1000),(500,True));self.assertEqual(g.budget_window(budget,2699,1000),(500,False)) + with self.assertRaises(ValueError):g.budget_window({**budget,'cells':['node-npm']},2700,1000) + +class ReceiptContracts(unittest.TestCase): + def setUp(self): + self.tmp=tempfile.TemporaryDirectory(dir=HERE);self.addCleanup(self.tmp.cleanup);self.root=Path(self.tmp.name)/'root';self.target=self.root/'benchmark-prep';self.target.mkdir(parents=True) + self.recipe=Path(self.tmp.name)/'recipe/app/benchmark';self.recipe.mkdir(parents=True);(self.recipe/'host.py').write_text('# synthetic host controller\n');(self.recipe.parents[1]/'deadline_process.py').write_text('# synthetic deadline controller\n') + self.execution={'schemaVersion':1,'identity':dict(IDENTITY),'sourceCommit':g.SOURCE,'workflowHead':'a'*40,'hostBootId':BOOT} + self.path=self.root/'execution.json';self.path.write_text(json.dumps(self.execution));self.env={v:IDENTITY[k] for k,v in g.GH.items()};self.env.update(GITHUB_SHA='a'*40,P6_DEADLINE_EPOCH='2700') + self.budget={'sourceCommit':g.SOURCE,'status':'window-available','requiredSeconds':500,'remainingSecondsAfterCleanupReserve':600,'warmupSweeps':1,'measuredSweeps':6,'cells':['js-aot','node-npm','bun-jit-npm']};(self.target/'cohort-budget.json').write_text(json.dumps(self.budget)) + def run_main(self,reconcile=False,second_busy=False,cpu_busy=0): + args=['quiet.py','--identity',str(self.path),'--identity-sha256',hashlib.sha256(self.path.read_bytes()).hexdigest(),'--container','p6-benchmark-21-1']+(['--reconcile-only'] if reconcile else []) + rows=fixture();rows[600]['args']=['python3',str(self.recipe/'host.py'),'run'];second=copy.deepcopy(rows) + if second_busy:second[900]=row(900,1,'/usr/bin/node',['node','run-cohort.mjs','SYNTHETIC-PRIVATE']) + if cpu_busy: + rows[901]=row(901,1,'/opt/custom-native');second[901]=row(901,1,'/opt/custom-native');second[901]['cpuTicks']=cpu_busy + original=Path.read_text + def read(path,*a,**k):return BOOT if str(path)=='/proc/sys/kernel/random/boot_id' else original(path,*a,**k) + with contextlib.ExitStack() as stack: + for obj,key,value in [(g,'ROOT',self.root),(g,'HERE',self.recipe),(g.platform,'system',lambda:'Linux'),(g.platform,'machine',lambda:'x86_64'),(g.os,'geteuid',lambda:0),(g.os,'getpid',lambda:700),(g.time,'time',lambda:1000),(sys,'argv',args)]:stack.enter_context(patch.object(obj,key,value)) + stack.enter_context(patch.dict(os.environ,self.env,clear=True));stack.enter_context(patch.object(Path,'read_text',read));stack.enter_context(patch.object(g,'read_containers',return_value=[container()]));stack.enter_context(patch.object(g,'read_processes',side_effect=[(rows,[]),(second,[])]));stack.enter_context(patch.object(g,'cpu_point',side_effect=[{'monotonic':0.0,'hostTicks':[0,0,0,1000,0,0,0,0],'selfTicks':0,'selfStartTicks':7000},{'monotonic':1.0,'hostTicks':[cpu_busy,0,0,1100-cpu_busy,0,0,0,0],'selfTicks':0,'selfStartTicks':7000}]));stack.enter_context(patch.object(g.time,'sleep'));stack.enter_context(patch.object(g.os,'sysconf',return_value=100));stack.enter_context(contextlib.redirect_stdout(io.StringIO()));return g.main() + def test_actual_identity_hash_and_environment_match(self): + self.assertEqual(g.execution(self.path,hashlib.sha256(self.path.read_bytes()).hexdigest(),self.env)['identity'],IDENTITY) + for field in list(self.env)[:-1]: + with self.subTest(field=field),self.assertRaises(ValueError):g.execution(self.path,hashlib.sha256(self.path.read_bytes()).hexdigest(),{**self.env,field:'changed'}) + with self.assertRaises(ValueError):g.execution(self.path,'0'*64,self.env) + def test_admission_matches_check_window_and_second_snapshot_is_binding(self): + self.assertEqual(self.run_main(),0);q=json.loads((self.target/'quiet-admission.json').read_text());e=Path(q['hostReconciliation']['path']) + self.assertEqual(q['decision'],'run-complete-selected-cell-cohort');self.assertEqual(q['hostBootId'],BOOT);self.assertEqual(q['observedAtEpoch'],1000);self.assertEqual(q['reservationSeconds'],500);self.assertTrue(all(q[k] for k in g.FLAGS));self.assertEqual(hashlib.sha256(e.read_bytes()).hexdigest(),q['hostReconciliation']['sha256']) + self.assertEqual(self.run_main(second_busy=True),1);q=json.loads((self.target/'quiet-admission.json').read_text());self.assertEqual(q['decision'],'pending-host-reconciliation');self.assertFalse(any(q[k] for k in g.FLAGS));self.assertNotIn('SYNTHETIC-PRIVATE', (self.target/'host-reconciliation.json').read_text()) + def test_reconcile_only_requires_no_budget_and_never_admits(self): + (self.target/'cohort-budget.json').unlink();self.assertEqual(self.run_main(reconcile=True),0);self.assertTrue((self.target/'post-backup-reconciliation.json').is_file());self.assertFalse((self.target/'quiet-admission.json').exists()) + def test_unknown_cpu_prevents_admission_despite_idle_names(self): + self.assertEqual(self.run_main(cpu_busy=50),1);self.assertEqual(json.loads((self.target/'host-reconciliation.json').read_text())['status'],'not-quiet');self.assertEqual(json.loads((self.target/'quiet-admission.json').read_text())['decision'],'pending-host-reconciliation') + def test_other_boot_or_insufficient_window_cannot_admit(self): + self.execution['hostBootId']='different';self.path.write_text(json.dumps(self.execution)) + with self.assertRaisesRegex(ValueError,'different host boot'):self.run_main() + self.execution['hostBootId']=BOOT;self.path.write_text(json.dumps(self.execution));self.env['P6_DEADLINE_EPOCH']='2699';self.assertEqual(self.run_main(),78);self.assertEqual(json.loads((self.target/'host-reconciliation.json').read_text())['status'],'insufficient-window') + +class CpuContracts(unittest.TestCase): + def points(self,busy=0,own=0,iowait=0): + return ({'monotonic':0.0,'hostTicks':[0,0,0,1000,0,0,0,0],'selfTicks':0,'selfStartTicks':7000}, + {'monotonic':1.0,'hostTicks':[busy,0,0,4200-busy-iowait,iowait,0,0,0],'selfTicks':own,'selfStartTicks':7000}) + def test_unknown_java_zstd_and_custom_native_cpu_are_rejected(self): + for executable in ['/usr/bin/java','/usr/bin/zstd','/opt/private-native-benchmark']: + with self.subTest(executable=executable): + before=fixture();before[900]=row(900,1,executable);after=copy.deepcopy(before);after[900]['cpuTicks']=100 + self.assertTrue(classify(before)['quiet']) + result=g.cpu_activity(*self.points(busy=102,own=2),before,after,700,100) + self.assertFalse(result['pass']);self.assertEqual(result['observedOtherProcessTicks'],100);self.assertEqual(result['processActivity'][0]['classification'],'unclassified-host-cpu');self.assertNotIn(executable,json.dumps(result)) + def test_idle_unknown_and_only_inspector_overhead_are_allowed(self): + before=fixture();before[900]=row(900,1,'/opt/custom-native');after=copy.deepcopy(before);after[700]['cpuTicks']=50 + result=g.cpu_activity(*self.points(busy=52,own=50),before,after,700,100) + self.assertTrue(result['pass']);self.assertEqual(result['inspectorCpuTicksExcluded'],50);self.assertEqual(result['unexplainedHostBusyTicks'],2);self.assertEqual(result['noiseAllowanceCpuSeconds'],0.1) + def test_allowed_host_controller_cpu_is_not_excluded(self): + before=fixture();after=copy.deepcopy(before);after[600]['cpuTicks']=50 + result=g.cpu_activity(*self.points(busy=50),before,after,700,100);self.assertFalse(result['pass']);self.assertEqual(result['observedOtherProcessTicks'],50) + def test_unattributed_short_lived_cpu_and_iowait_are_rejected(self): + for points in [self.points(busy=100),self.points(iowait=100)]: + self.assertFalse(g.cpu_activity(*points,fixture(),fixture(),700,100)['pass']) + rows=fixture();rows[900]=row(900,1,'/opt/unknown',state='D');self.assertFalse(classify(rows)['quiet']) + def test_process_churn_reuse_and_counter_rollback_fail_closed(self): + for mutation in ['added','removed','reused','rollback']: + before=fixture();before[900]=row(900,1,'/opt/unknown');after=copy.deepcopy(before) + if mutation=='added':after[901]=row(901,1,'/opt/unknown') + elif mutation=='removed':del after[900] + elif mutation=='reused':after[900]['startTicks']+=1 + else:before[900]['cpuTicks']=10 + with self.subTest(mutation=mutation):self.assertFalse(g.cpu_activity(*self.points(),before,after,700,100)['pass']) + first,last=self.points();last['hostTicks'][0]=-1 + with self.assertRaises(ValueError):g.cpu_activity(first,last,fixture(),fixture(),700,100) + first,last=self.points();last['selfTicks']=100 + with self.assertRaises(ValueError):g.cpu_activity(first,last,fixture(),fixture(),700,100) + def test_disappearing_process_during_inspection_is_recorded(self): + with tempfile.TemporaryDirectory(dir=HERE) as directory: + proc=Path(directory);entry=proc/'99';entry.mkdir();fields=['S','1']+['0']*18;fields[19]='900';(entry/'stat').write_text('99 (unknown) '+' '.join(fields)) + rows,errors=g.read_processes(proc);self.assertEqual(rows,{});self.assertEqual(errors,[{'pid':99,'classification':'process-inspection-race'}]) + +if __name__=='__main__':unittest.main() diff --git a/scripts/openclaw-p6/app/compatibility/commands.template.json b/scripts/openclaw-p6/app/compatibility/commands.template.json new file mode 100644 index 000000000000..383206f24ebd --- /dev/null +++ b/scripts/openclaw-p6/app/compatibility/commands.template.json @@ -0,0 +1,113 @@ +{ + "status": "prepared-placeholder-argv-not-executable-admission", + "workingDirectory": "${SOURCE}", + "environment": { + "PATH": "${NODE_DIRECTORY}:/usr/bin:/bin", + "HOME": "${OUTPUT}/home", + "TMPDIR": "${OUTPUT}/tmp", + "XDG_CACHE_HOME": "${OUTPUT}/cache", + "LANG": "C.UTF-8", + "TZ": "UTC", + "GIT_CONFIG_GLOBAL": "/dev/null", + "GIT_CONFIG_SYSTEM": "/dev/null" + }, + "existingOwnerBoundary": "Run only after completed fresh native preparation/selection, before paging/heavy app compile, through existing bounded phase/deadline owner.", + "steps": [ + { + "id": "node-identity", + "argv": [ + "${NODE}", + "-p", + "JSON.stringify({platform:process.platform,arch:process.arch,version:process.version})" + ], + "assert": "Exact Linux native arch and expected pinned Node, hash verified externally." + }, + { + "id": "compiler-identity-per-profile", + "profiles": [ + "standard", + "shadowrealm-off" + ], + "argv": [ + "${BUN}", + "--no-env-file", + "--no-install", + "-p", + "JSON.stringify({platform:process.platform,arch:process.arch,bun:Bun.revision,webkit:process.versions.webkit})" + ], + "assert": "Exact Linux native arch, Bun150c/WebKitaaa and admitted compiler file hash per profile." + }, + { + "id": "full-dist-ast-census", + "argv": [ + "/usr/bin/nice", + "-n", + "10", + "${NODE}", + "${HELPERS}/helpers/scan.cjs" + ], + "extraEnvironment": { + "PROBE_TYPESCRIPT": "${TYPESCRIPT}", + "PROBE_MODULES": "${SOURCE}/dist", + "PROBE_OUTPUT": "${OUTPUT}/full-dist-inventory.json" + }, + "timeoutSeconds": 180, + "effect": "Read source dist and write census; no source edit/build.", + "gate": "Scanner completion and input provenance only; its full-dist missing findings are not selected-build admission." + }, + { + "id": "actual-builtin-namespace-per-profile", + "profiles": [ + "standard", + "shadowrealm-off" + ], + "argv": [ + "/usr/bin/nice", + "-n", + "10", + "${BUN}", + "--no-env-file", + "--no-install", + "${HELPERS}/helpers/runtime.ts", + "${OUTPUT}/full-dist-inventory.json", + "${OUTPUT}/builtin-query-${PROFILE}.json" + ], + "timeoutSeconds": 60, + "gate": "Query completed and recorded exact admitted Bun revision. Full missing list remains diagnostic until projection." + }, + { + "id": "selected-dist-and-worker-gate-per-profile", + "profiles": [ + "standard", + "shadowrealm-off" + ], + "argv": [ + "/usr/bin/nice", + "-n", + "10", + "${BUN}", + "--no-env-file", + "--no-install", + "${HELPERS}/project-selected-builtins.mjs", + "${SOURCE}", + "${SELECTION}", + "${OUTPUT}/full-dist-inventory.json", + "${OUTPUT}/builtin-query-${PROFILE}.json", + "${OUTPUT}/selected-${PROFILE}.json" + ], + "timeoutSeconds": 180, + "gate": "Exit0 and status=passed; selectedMissing=[], unmappedWorkers=[], undeclaredPluginWorkers=[]. Missing outside selected owner inputs is diagnosticOnlyMissing, never silently ignored." + } + ], + "totalPhaseBudgetSeconds": 600, + "nativeCompile": false, + "runBothArchitectures": true, + "artifactsToRetain": [ + "bound-inputs.json", + "identity receipts", + "full-dist-inventory.json", + "builtin-query-{standard,shadowrealm-off}.json", + "selected-{standard,shadowrealm-off}.json", + "phase stdout/stderr/deadline receipt" + ] +} diff --git a/scripts/openclaw-p6/app/compatibility/helpers/load-source-entries-selected.mjs b/scripts/openclaw-p6/app/compatibility/helpers/load-source-entries-selected.mjs new file mode 100644 index 000000000000..cd74e4b92cac --- /dev/null +++ b/scripts/openclaw-p6/app/compatibility/helpers/load-source-entries-selected.mjs @@ -0,0 +1,17 @@ +import fs from 'node:fs'; +import path from 'node:path'; +import {pathToFileURL} from 'node:url'; +const root=fs.realpathSync(process.argv[2]); +const selected=JSON.parse(fs.readFileSync(process.argv[3],'utf8')); +const module=relative=>import(pathToFileURL(path.join(root,relative)).href); +const {planStandalonePlugins}=await module('scripts/lib/bun-standalone-plugins.mjs'); +const {createStandaloneRuntimeProcessEntrypoints}=await module('src/infra/runtime-process-manifest.ts'); +const {discoverStandaloneWorkers}=await module('scripts/lib/bun-standalone-workers.mjs'); +const {loadStandaloneSourceEntries}=await module('scripts/lib/bun-standalone-source-entries.mjs'); +const {createStandaloneSourceParser}=await module('scripts/lib/bun-standalone-source-parser.mjs'); +const plugins=planStandalonePlugins(root,selected); +const workerEntries=discoverStandaloneWorkers({runtimeRoot:root,runtimeEntrypoints:createStandaloneRuntimeProcessEntrypoints(import.meta.url,plugins.embeddedDirs)}); +const entries=await loadStandaloneSourceEntries({sourceRoot:root,workerEntries,parse:createStandaloneSourceParser()}); +const unmapped=entries.unmappedWorkers(workerEntries); +console.log(JSON.stringify({sourceRoot:root,entries:entries.entries.length,workerTargets:workerEntries.length,selectedPlugins:plugins.embedded.length,unmapped},null,2)); +if(unmapped.length)process.exitCode=1; diff --git a/scripts/openclaw-p6/app/compatibility/helpers/plugin-contract-selected.mjs b/scripts/openclaw-p6/app/compatibility/helpers/plugin-contract-selected.mjs new file mode 100644 index 000000000000..20b007d17a76 --- /dev/null +++ b/scripts/openclaw-p6/app/compatibility/helpers/plugin-contract-selected.mjs @@ -0,0 +1,22 @@ +import fs from 'node:fs'; +import path from 'node:path'; +import {pathToFileURL} from 'node:url'; +const root=fs.realpathSync(process.argv[2]); +const owner=await import(pathToFileURL(path.join(root,'scripts/lib/bun-standalone-plugins.mjs'))); +const ids=JSON.parse(fs.readFileSync(process.argv[3],'utf8')); +const selection=owner.planStandalonePlugins(root,ids); +function walk(dir,relative='dist') { + const files=[]; + for(const entry of fs.readdirSync(dir,{withFileTypes:true})) { + if(['node_modules','control-ui','worker-artifacts'].includes(entry.name))continue; + const name=path.posix.join(relative,entry.name); + if(entry.isDirectory()&&!entry.isSymbolicLink())files.push(...walk(path.join(dir,entry.name),name)); + else if(entry.isFile()&&/\.[cm]?js$/.test(entry.name))files.push(name); + } + return files; +} +const inventory=walk(path.join(root,'dist')).toSorted(); +const selected=await owner.selectStandalonePluginModules(root,inventory,selection); +const embeddedPaths=Object.fromEntries(selected.map(entry=>[entry,`/synthetic-image/${entry}`])); +const contract=owner.createStandalonePluginContract({runtimeRoot:root,plugins:selection,embeddedPaths}); +console.log(JSON.stringify({sourceRoot:root,inventory:inventory.length,selected:selected.length,plugins:Object.keys(contract.plugins).length,sdkExports:Object.keys(contract.sdk).length,defaults:Object.fromEntries(['active-memory','device-pair','talk-voice'].map(id=>[id,contract.plugins[id]])),proof:'Real desktop module-selection and plugin-contract owners; synthetic image paths, no native/runtime execution'},null,2)); diff --git a/scripts/openclaw-p6/app/compatibility/helpers/runtime.ts b/scripts/openclaw-p6/app/compatibility/helpers/runtime.ts new file mode 100644 index 000000000000..c78496e3b4b4 --- /dev/null +++ b/scripts/openclaw-p6/app/compatibility/helpers/runtime.ts @@ -0,0 +1,5 @@ +const input=await Bun.file(process.argv[2]).json(); +const rows=[]; +for(const mod of input.modules){try {const value=await import(mod.specifier);const available=Object.keys(value).sort();const missing=mod.names.filter(name=>!Object.prototype.hasOwnProperty.call(value,name));rows.push({...mod,missing,available,undefinedValues:mod.names.filter(name=>value[name]===undefined)});}catch(error){rows.push({...mod,error:String(error),missing:mod.names});}} +const result={revision:Bun.revision,version:Bun.version,execPath:process.execPath,modules:rows,missing:rows.filter(x=>x.error||x.missing.length)}; +await Bun.write(process.argv[3],JSON.stringify(result,null,2)+"\n");console.log(JSON.stringify({version:result.version,missing:result.missing},null,2)); diff --git a/scripts/openclaw-p6/app/compatibility/helpers/scan.cjs b/scripts/openclaw-p6/app/compatibility/helpers/scan.cjs new file mode 100644 index 000000000000..f66d60ae1870 --- /dev/null +++ b/scripts/openclaw-p6/app/compatibility/helpers/scan.cjs @@ -0,0 +1,19 @@ +const fs=require("node:fs"); +const path=require("node:path"); +const {builtinModules}=require("node:module"); +const ts=require(process.env.PROBE_TYPESCRIPT); +const root=process.env.PROBE_MODULES; +const builtin=new Set(builtinModules.flatMap(x=>[x,x.replace(/^node:/,""),"node:"+x.replace(/^node:/,"")])); +const records=[];let files=0,bytes=0; +function walk(dir){for(const e of fs.readdirSync(dir,{withFileTypes:true})){const f=path.join(dir,e.name);if(e.isDirectory())walk(f);else if(e.isFile()&&/\.[cm]?js$/.test(e.name))scan(f);}} +function scan(file){const source=fs.readFileSync(file,"utf8");files++;bytes+=Buffer.byteLength(source);const parsed=ts.createSourceFile(file,source,ts.ScriptTarget.Latest,true,ts.ScriptKind.JS); +for(const node of parsed.statements){let module,names=[]; +if(ts.isImportDeclaration(node)){module=node.moduleSpecifier;if(node.importClause){if(node.importClause.name)names.push("default");const b=node.importClause.namedBindings;if(b&&ts.isNamedImports(b))names.push(...b.elements.map(x=>(x.propertyName??x.name).text));}} +else if(ts.isExportDeclaration(node)&&node.moduleSpecifier){module=node.moduleSpecifier;const b=node.exportClause;if(b&&ts.isNamedExports(b))names.push(...b.elements.map(x=>(x.propertyName??x.name).text));} +if(!module||!ts.isStringLiteral(module))continue;const specifier=module.text;if(!builtin.has(specifier)&&!specifier.startsWith("node:")&&!specifier.startsWith("bun:"))continue; +const line=parsed.getLineAndCharacterOfPosition(node.getStart()).line+1; +records.push({file:path.relative(root,file),line,specifier,names,kind:ts.isImportDeclaration(node)?"import":"export"});}} +walk(root); +const groups={};for(const row of records){const canonical=row.specifier.startsWith("bun:")?row.specifier:"node:"+row.specifier.replace(/^node:/,"");groups[canonical]??={names:new Set(),count:0};for(const name of row.names)groups[canonical].names.add(name);groups[canonical].count++;} +const modules=Object.entries(groups).sort().map(([specifier,x])=>({specifier,names:[...x.names].sort(),sites:x.count})); +const result={root,files,bytes,sites:records.length,modules,records};fs.writeFileSync(process.env.PROBE_OUTPUT,JSON.stringify(result,null,2)+"\n");console.log(JSON.stringify({files,bytes,sites:records.length,modules:modules.length,namedExports:modules.reduce((n,x)=>n+x.names.length,0)})); diff --git a/scripts/openclaw-p6/app/compatibility/inputs.template.json b/scripts/openclaw-p6/app/compatibility/inputs.template.json new file mode 100644 index 000000000000..6c655a15edea --- /dev/null +++ b/scripts/openclaw-p6/app/compatibility/inputs.template.json @@ -0,0 +1,70 @@ +{ + "status": "prepared-unbound-do-not-execute", + "sourceCommit": null, + "sourceTree": null, + "source": null, + "sourceClean": null, + "preparationReceipt": null, + "preparationReceiptSha256": null, + "distBuildInfo": null, + "distBuildInfoSha256": null, + "selection": null, + "selectionSha256": null, + "typescript": null, + "typescriptVersion": null, + "output": null, + "helperRoot": null, + "sourceOwners": { + "scripts/build-bun-standalone.mjs": null, + "scripts/lib/bun-standalone-plugins.mjs": null, + "scripts/lib/bun-standalone-workers.mjs": null, + "scripts/lib/bun-standalone-source-entries.mjs": null, + "scripts/lib/bun-standalone-source-parser.mjs": null, + "scripts/lib/bundled-plugin-build-entries.mjs": null, + "scripts/lib/static-extension-assets.mts": null, + "scripts/lib/bun-standalone-sidecar.mjs": null, + "src/infra/runtime-process-manifest.ts": null, + "src/gateway/worker-environments/node-bootstrap-runtime-chunks.ts": null + }, + "architectures": { + "arm64": { + "platform": "linux", + "arch": "arm64", + "node": null, + "nodeSha256": null, + "compilers": { + "standard": { + "path": null, + "sha256": null + }, + "shadowrealm-off": { + "path": null, + "sha256": null + } + } + }, + "x64": { + "platform": "linux", + "arch": "x64", + "node": null, + "nodeSha256": null, + "compilers": { + "standard": { + "path": null, + "sha256": null + }, + "shadowrealm-off": { + "path": null, + "sha256": null + } + } + } + }, + "expectedCompilerSources": { + "bun": "150c9620c53710060186b8b0cd50985e035408b0", + "webkit": "aaa690bfbf34c9d50775716ac2fc3c7d0573e0b8" + }, + "applicationArtifacts": null, + "nativeCompile": false, + "executionAuthorized": false +} diff --git a/scripts/openclaw-p6/app/compatibility/payload-manifest.json b/scripts/openclaw-p6/app/compatibility/payload-manifest.json new file mode 100644 index 000000000000..ef0dd8c610ee --- /dev/null +++ b/scripts/openclaw-p6/app/compatibility/payload-manifest.json @@ -0,0 +1,10 @@ +{ + "commands.template.json": "4738ea5c2fdc58173434ce89b895e6067bc4af7a9883cea77926d750058d69d2", + "helpers/load-source-entries-selected.mjs": "e929b93b2244df5eaaa64103861905d22608a37101b3cb849e40b272d4608ed9", + "helpers/plugin-contract-selected.mjs": "f1770bd6435b3ffdb337bef3de07c1274117d5617b3228bff3c88ec2eff7d1da", + "helpers/runtime.ts": "fa7d3fc1320b1d3aa75abbbb3cfbc7e9ea97cd4e4ed86100a08a23f2d7b81338", + "helpers/scan.cjs": "0f4022f02c8212141d09569613650838361ffd41e92be85a4414bb86554e9115", + "inputs.template.json": "d3540027cade25ad8a5944ef48b9eacc7a6279d810b25566c354fb283637f76f", + "project-selected-builtins.mjs": "7d4cdd0a4ec09e13a50e2bd288d3b883fa9efa945c88fef78a7b442b823be197", + "source-interfaces.json": "91d48d78f3914210aefae2b2d02cb31094020404866e8a27d3b2a35bd83d30c0" +} diff --git a/scripts/openclaw-p6/app/compatibility/project-selected-builtins.mjs b/scripts/openclaw-p6/app/compatibility/project-selected-builtins.mjs new file mode 100644 index 000000000000..467e1eb67737 --- /dev/null +++ b/scripts/openclaw-p6/app/compatibility/project-selected-builtins.mjs @@ -0,0 +1,81 @@ +// Adapt the frozen P0 census to the maintained selected-dist and worker owners. +import assert from 'node:assert/strict'; +import fs from 'node:fs'; +import path from 'node:path'; +import { pathToFileURL } from 'node:url'; + +const [sourceName, selectionName, inventoryName, runtimeName, outputName] = process.argv.slice(2); +assert(sourceName && selectionName && inventoryName && runtimeName && outputName); +const source = fs.realpathSync(sourceName); +assert.equal(fs.realpathSync(process.cwd()), source); +const read = name => JSON.parse(fs.readFileSync(name, 'utf8')); +const load = relative => import(pathToFileURL(path.join(source, relative)).href); +const pluginsOwner = await load('scripts/lib/bun-standalone-plugins.mjs'); +const { createStandaloneRuntimeProcessEntrypoints } = await load('src/infra/runtime-process-manifest.ts'); +const { discoverStandaloneWorkers } = await load('scripts/lib/bun-standalone-workers.mjs'); +const { loadStandaloneSourceEntries } = await load('scripts/lib/bun-standalone-source-entries.mjs'); +const { createStandaloneSourceParser } = await load('scripts/lib/bun-standalone-source-parser.mjs'); +const { collectSourceCheckoutPluginBuildEntries } = await load('scripts/lib/bundled-plugin-build-entries.mjs'); +const { listPackagedStaticExtensionAssetOutputs } = await load('scripts/lib/static-extension-assets.mts'); +const { standaloneResourceCategory } = await load('scripts/lib/bun-standalone-sidecar.mjs'); +const selection = pluginsOwner.planStandalonePlugins(source, read(selectionName)); +const omitted = new Set(selection.omittedDirs); +const declaredAssets = new Set(listPackagedStaticExtensionAssetOutputs({ rootDir: source })); +const inventory = []; +function visit(directory, relative = 'dist') { + for (const item of fs.readdirSync(directory, { withFileTypes: true })) { + // Same inventory exclusions as build-bun-standalone.mjs::runtimeJavaScriptEntries. + if (['node_modules', 'control-ui', 'worker-artifacts'].includes(item.name)) continue; + const name = path.posix.join(relative, item.name); + if (relative === 'dist/extensions' && omitted.has(item.name)) continue; + if (item.isDirectory() && !item.isSymbolicLink()) visit(path.join(directory, item.name), name); + else if (item.isFile() && /\.[cm]?js$/.test(item.name) && !standaloneResourceCategory(name, declaredAssets)) inventory.push(name); + } +} +visit(path.join(source, 'dist')); +const selected = await pluginsOwner.selectStandalonePluginModules(source, inventory.toSorted(), selection); +const workers = discoverStandaloneWorkers({ runtimeRoot: source, + runtimeEntrypoints: createStandaloneRuntimeProcessEntrypoints(import.meta.url, selection.embeddedDirs) }); +const entries = await loadStandaloneSourceEntries({ sourceRoot: source, workerEntries: workers, + parse: createStandaloneSourceParser() }); +const unmappedWorkers = entries.unmappedWorkers(workers); +const undeclaredPluginWorkers = []; +for (const plugin of collectSourceCheckoutPluginBuildEntries({ cwd: source })) { + if (!selection.embeddedDirs.includes(plugin.id)) continue; + for (const worker of plugin.packageJson?.openclaw?.build?.workerEntries ?? []) { + const filename = path.resolve(source, 'extensions', plugin.id, worker); + const outputs = entries.entries.filter(entry => entry.source === filename).map(entry => entry.output); + if (!outputs.some(output => workers.includes(output))) undeclaredPluginWorkers.push({ plugin: plugin.id, worker, outputs }); + } +} +const nativeDistEntries = new Set([...selected, ...workers].filter(name => name.startsWith('dist/'))); +const census = read(inventoryName), runtime = read(runtimeName); +assert.equal(fs.realpathSync(census.root), path.join(source, 'dist')); +assert.equal(process.platform, 'linux'); +assert(['x64', 'arm64'].includes(process.arch)); +assert.equal(Bun.revision, '150c9620c53710060186b8b0cd50985e035408b0'); +assert.equal(process.versions.webkit, 'aaa690bfbf34c9d50775716ac2fc3c7d0573e0b8'); +assert.equal(runtime.revision, Bun.revision); +assert.equal(runtime.execPath, process.execPath); +const modules = new Map(runtime.modules.map(module => [module.specifier, module])); +const selectedMissing = [], diagnosticOnlyMissing = []; +for (const record of census.records) { + const canonical = record.specifier.startsWith('bun:') ? record.specifier : 'node:' + record.specifier.replace(/^node:/, ''); + const queried = modules.get(canonical); + assert(queried, 'Builtin absent from actual runtime query: ' + canonical); + const missing = record.names.filter(name => !queried.available?.includes(name)); + if (!queried.error && !missing.length) continue; + const row = { ...record, canonical, missing, ...(queried.error ? { error: queried.error } : {}) }; + (nativeDistEntries.has('dist/' + record.file) ? selectedMissing : diagnosticOnlyMissing).push(row); +} +const result = { status: selectedMissing.length || unmappedWorkers.length || undeclaredPluginWorkers.length ? 'failed' : 'passed', + scope: 'Maintained selected emitted-dist/native-worker input projection; no bundling or native compilation', + source, selectedPlugins: selection.embedded, selectedDistEntries: selected.length, workerTargets: workers.length, + nativeDistEntries: [...nativeDistEntries].toSorted(), sourceEntries: entries.entries.length, + unmappedWorkers, undeclaredPluginWorkers, selectedMissing, diagnosticOnlyMissing, + runtimeRevision: runtime.revision, limitations: ['Full-dist missing sites outside owner-selected inputs are diagnostic only.', + 'Does not replace final transformed-source or native link validation; extra native adapter/dependency inputs are not fully enumerated here.'] }; +fs.writeFileSync(outputName, JSON.stringify(result, null, 2) + '\n', { flag: 'wx' }); +console.log(JSON.stringify({ status: result.status, selectedMissing, unmappedWorkers, undeclaredPluginWorkers, + diagnosticOnlyMissingCount: diagnosticOnlyMissing.length })); +if (result.status !== 'passed') process.exitCode = 1; diff --git a/scripts/openclaw-p6/app/compatibility/source-binding.json b/scripts/openclaw-p6/app/compatibility/source-binding.json new file mode 100644 index 000000000000..9f02ece0fe9d --- /dev/null +++ b/scripts/openclaw-p6/app/compatibility/source-binding.json @@ -0,0 +1,24 @@ +{ + "schemaVersion": 1, + "status": "bound-reviewed-r4-cut", + "sourceCommit": "4fa442e332745f1f58ccedd27106abdafcf4e019", + "sourceTree": "5409457bc1b8a901b00193469a3c2b7a74dc2f30", + "sourceOwners": { + "scripts/build-bun-standalone.mjs": "a32d46f7dd6e978834540ba1ca5d173afdd12d5df02acda7779c50b53119e0f0", + "scripts/lib/bun-standalone-plugins.mjs": "dc7a90471099b9ee73f5fdba02cd4c09ff92c8f5866120d6e3c526a18d9cc717", + "scripts/lib/bun-standalone-workers.mjs": "36cad2b9b1832a40336e4f07a864e52526a0bcd5e444847f7b63d3acd9d20107", + "scripts/lib/bun-standalone-source-entries.mjs": "83a99a63ba2a5db69a1c2b99eccc46f2419acee8378539c94d344546bb1b2104", + "scripts/lib/bun-standalone-source-parser.mjs": "ff6e6d31b0e6f32dcbd1bf0dbdcc3ca1ea8b032a88f0f210c373967560dfeb4e", + "scripts/lib/bundled-plugin-build-entries.mjs": "36d9bd72460fd5d76d3e4b33060e49ae710790146db11feffe37df394e1e6a0a", + "scripts/lib/static-extension-assets.mts": "52d60d4b959f54f01b276686a15a69d472788c4dad7be53a097011874f13c974", + "scripts/lib/bun-standalone-sidecar.mjs": "716d7001b44a6edae7979c3b27d236cddefaa53a6de94ce3d4f8b684c4eae858", + "src/infra/runtime-process-manifest.ts": "b421bca8b2cde6fbc3d07ecb5cb48ffcfeecb3bdb757668513f218e53d0b46d6", + "src/gateway/worker-environments/node-bootstrap-runtime-chunks.ts": "84503a5819d57608d85de5e7e66c3b1ba1fc2e782d251981502f1622d9ba7577" + }, + "typescript": { + "relativePath": "node_modules/.pnpm/typescript@6.0.3/node_modules/typescript", + "version": "6.0.3", + "manifestSha256": "9332e97c30d3e53ed54910b89207ed657fb444066484df6e5b6965bf130865e9", + "entrySha256": "569177652966bd528c319171c7dd22860dbf72bde116cbc4f644f1d02bb12e39" + } +} diff --git a/scripts/openclaw-p6/app/compatibility/source-interfaces.json b/scripts/openclaw-p6/app/compatibility/source-interfaces.json new file mode 100644 index 000000000000..111eda535e66 --- /dev/null +++ b/scripts/openclaw-p6/app/compatibility/source-interfaces.json @@ -0,0 +1,65 @@ +{ + "builtinScanner": "Frozen P0 TypeScript createSourceFile + Node builtinModules census; runtime namespace import uses the actual Bun executable.", + "sourceInterfaces": [ + { + "file": "scripts/lib/bun-standalone-plugins.mjs", + "exports": [ + "planStandalonePlugins", + "selectStandalonePluginModules" + ] + }, + { + "file": "src/infra/runtime-process-manifest.ts", + "exports": [ + "createStandaloneRuntimeProcessEntrypoints", + "pluginRuntimeProcessManifest" + ] + }, + { + "file": "scripts/lib/bun-standalone-workers.mjs", + "exports": [ + "discoverStandaloneWorkers" + ] + }, + { + "file": "scripts/lib/bun-standalone-source-entries.mjs", + "exports": [ + "loadStandaloneSourceEntries" + ], + "result": [ + "entries", + "unmappedWorkers" + ] + }, + { + "file": "scripts/lib/bun-standalone-source-parser.mjs", + "exports": [ + "createStandaloneSourceParser" + ] + }, + { + "file": "scripts/lib/bundled-plugin-build-entries.mjs", + "exports": [ + "collectSourceCheckoutPluginBuildEntries" + ] + }, + { + "file": "scripts/lib/static-extension-assets.mts", + "exports": [ + "listPackagedStaticExtensionAssetOutputs" + ] + }, + { + "file": "scripts/lib/bun-standalone-sidecar.mjs", + "exports": [ + "standaloneResourceCategory" + ] + } + ], + "notInvoked": [ + "scripts/build-bun-standalone.mjs", + "Bun.build", + "createStandaloneSourceGraph (materializes inputs)", + "native compiler/linker" + ] +} diff --git a/scripts/openclaw-p6/app/compiler-pins.json b/scripts/openclaw-p6/app/compiler-pins.json new file mode 100644 index 000000000000..baab517521ce --- /dev/null +++ b/scripts/openclaw-p6/app/compiler-pins.json @@ -0,0 +1,27 @@ +{ + "schemaVersion": 1, + "repository": "openclaw/bun", + "runId": 40214829538, + "runAttempt": 1, + "headSha": "f9fa08790bf45b3e995280f6eb249e14fd9191c1", + "artifacts": { + "cb-standard": { + "id": 12608037481, + "name": "p6-linux-x64-standard-f9fa08790bf45b3e995280f6eb249e14fd9191c1-attempt1", + "zipSha256": "659eb35a30ec4b5446e2ef6ea6f182249f2949398d429c72ce2bb2d7f8bf492e", + "compilerSha256": "bc32f99d8c9ebda0de7d3cf0a216052d84afa70b85f011485ed49bae3d3f6d90", + "transportSha256": "2fba572c329a9c7dfdee1d7d0fd4f53492e1dbc508e9e405e4fb767fdfdb6149", + "archiveSha256": "36660357e450c1c6f8762492332828bbbe53ae2048999ff75b8681cda0140dae", + "zipBytes": 131892490 + }, + "cb-compat": { + "id": 12609305181, + "name": "p6-linux-x64-shadowrealm-off-f9fa08790bf45b3e995280f6eb249e14fd9191c1-attempt1", + "zipSha256": "8dca5ea6ba7e73d8b6833be1196e17e6e54ff7b5e3c16686440225579d10f64b", + "compilerSha256": "12abf71cff8b57f633dfc348c1071772b8fa5fb842fd692b69e57d01844889ce", + "transportSha256": "ebc2e022129ea1b2b4629d6829a33d6b1fb0144dca5c3eab25a9d69ead96d0b1", + "archiveSha256": "2a2407b9d1885743f451ba8cf7a8d59f2885a6b3936d98769a12307ab4c91919", + "zipBytes": 131851510 + } + } +} diff --git a/scripts/openclaw-p6/app/docker-client.py b/scripts/openclaw-p6/app/docker-client.py new file mode 100755 index 000000000000..5b57da7ea78f --- /dev/null +++ b/scripts/openclaw-p6/app/docker-client.py @@ -0,0 +1,36 @@ +#!/usr/bin/python3 +"""Label resources created by the unchanged E2E owners for exact task cleanup.""" +import json +import os +from pathlib import Path +import sys + +def image_token(args): + index = 1 + while index < len(args): + token = args[index] + if token == '--': + return args[index + 1] if index + 1 < len(args) else None + if not token.startswith('-'): + return token + if '=' in token or token in ['--rm', '--init', '--read-only', '--privileged'] or ( + token.startswith('-') and not token.startswith('--') and set(token[1:]) <= set('dit')): + index += 1 + else: + index += 2 + return None + + +identity = json.loads(Path('/p6-execution.json').read_text())['identity'] +label = 'openclaw.p6.actions=' + identity['runId'] + '-' + identity['runAttempt'] +args = sys.argv[1:] +if args[:1] in [['run'], ['create']]: + args[1:1] = ['--label', label] + adapter = os.environ.get('P6_DOCKER_CLAWHUB_ASSERTIONS') + expected_image = os.environ.get('P6_DOCKER_CLAWHUB_IMAGE') + if adapter and expected_image and image_token(sys.argv[1:]) == expected_image: + args[1:1] = ['--mount', 'type=bind,src=' + adapter + + ',dst=/app/scripts/e2e/lib/clawhub-artifact-assertions.mjs,readonly'] +elif args[:2] == ['network', 'create']: + args[2:2] = ['--label', label] +os.execv('/p6-host-docker', ['/p6-host-docker', *args]) diff --git a/scripts/openclaw-p6/app/download.py b/scripts/openclaw-p6/app/download.py new file mode 100644 index 000000000000..9beb2f208349 --- /dev/null +++ b/scripts/openclaw-p6/app/download.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python3 +"""Download the reviewed compiler pair; credentials never enter the app container.""" +import hashlib +import json +import os +from pathlib import Path +import shutil +import subprocess +import sys +import urllib.request + +HERE = Path(__file__).resolve().parent + + +class DownloadRedirect(urllib.request.HTTPRedirectHandler): + def redirect_request(self, request, fp, code, message, headers, newurl): + redirected = super().redirect_request(request, fp, code, message, headers, newurl) + if redirected is not None: + redirected.remove_header('Authorization') + return redirected + + +def fetch(path, target=None, expected_bytes=None): + request = urllib.request.Request('https://api.github.com/repos/openclaw/bun/' + path, + headers={'Authorization': 'Bearer ' + os.environ['GH_TOKEN'], + 'Accept': 'application/vnd.github+json', 'X-GitHub-Api-Version': '2022-11-28'}) + with urllib.request.build_opener(DownloadRedirect).open(request, timeout=60) as response: + if target is None: + return json.load(response) + with target.open('xb') as stream: + count = 0 + while block := response.read(1024 * 1024): + count += len(block) + assert count <= expected_bytes, 'Artifact exceeds pinned ZIP size' + stream.write(block) + assert count == expected_bytes, 'Artifact ZIP size differs' + + +def main(): + pins = json.loads((HERE / 'compiler-pins.json').read_text()) + assert all(pins['artifacts'].values()), 'Both reviewed compiler artifact identities required' + work = Path(os.environ['P6_WORK']) + destination = work / 'downloads' + destination.mkdir(parents=True, exist_ok=False) + run = fetch(f"actions/runs/{pins['runId']}/attempts/{pins['runAttempt']}") + assert run['id'] == pins['runId'] and run['head_sha'] == pins['headSha'] + assert run['run_attempt'] == pins['runAttempt'] and run['status'] == 'completed' + assert run['conclusion'] == 'success', 'Incomplete/failed compiler run is not app input' + (destination / 'run.json').write_text(json.dumps(run, indent=2) + '\n') + root = Path('/home/runner/.cache/oc-ty-ext/P6/rd150c-x64-v1') + assert not root.exists(), 'Fresh compiler import root required' + root.mkdir(parents=True) + for profile, expected in pins['artifacts'].items(): + metadata = fetch(f"actions/artifacts/{expected['id']}") + assert metadata['id'] == expected['id'] and metadata['name'] == expected['name'] + assert metadata['digest'] == 'sha256:' + expected['zipSha256'] + assert metadata['size_in_bytes'] == expected['zipBytes'] + metadata_file = destination / (profile + '.json') + metadata_file.write_text(json.dumps(metadata, indent=2) + '\n') + archive = destination / (profile + '.zip') + fetch(f"actions/artifacts/{expected['id']}/zip", archive, expected['zipBytes']) + verified = destination / ('verified-' + profile) + subprocess.run([sys.executable, str(HERE / 'verify-download.py'), '--metadata', + str(metadata_file), '--zip', str(archive), '--profile', profile, + '--out', str(verified)], check=True) + receipt = json.loads((verified / 'adoption-verification.json').read_text()) + assert receipt['compilerSha256'] == expected['compilerSha256'] + assert receipt['transportSha256'] == expected['transportSha256'] + transport = json.loads((verified / 'github-artifact/transport.json').read_text()) + assert transport['archiveSha256'] == expected['archiveSha256'] + directory = 'build-standard' if profile == 'cb-standard' else 'build-c2' + shutil.copytree(verified / 'compiler' / directory, root / directory) + (root / 'receipts').mkdir(exist_ok=True) + for source in (verified / 'compiler/receipts').iterdir(): + assert not (root / 'receipts' / source.name).exists() + shutil.copy2(source, root / 'receipts' / source.name) + preserved = root / ('preserved-' + profile) + preserved.mkdir() + shutil.copy2(verified / 'github-artifact/transport.json', preserved / 'transport.json') + print('P6_COMPILER_PAIR_VERIFIED', flush=True) + + +if __name__ == '__main__': + main() diff --git a/scripts/openclaw-p6/app/export.py b/scripts/openclaw-p6/app/export.py new file mode 100644 index 000000000000..ad94e0f1bf1c --- /dev/null +++ b/scripts/openclaw-p6/app/export.py @@ -0,0 +1,186 @@ +#!/usr/bin/env python3 +"""Export only named synthetic results and preserved app archives, never paging state.""" +import hashlib +import json +import os +from pathlib import Path +import shutil +import stat +import sys +from preflight import export_selections +from selection import VARIANTS, requested_variants + +ROOT = Path('/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1') +PHASES = ['core', 'elf-floor', 'zero-js', 'node-vm', 'node-vm-native-workers', 'pty', + 'plugin', 'docker-image', 'docker-gateway-network', 'docker-kitchen-sink', 'docker-cron'] + +FOLLOW_ON_PHASES = ['teams-fetched'] + + +def load(path): + return json.loads(path.read_text()) + + +def facts(path): + if not path.is_file(): + return {'status': 'not-run'} + try: + return load(path) + except (OSError, ValueError): + return {'status': 'invalid-receipt'} + + +def selections(work, root): + yield from export_selections(work, root) + for name in ['execution.json', 'resources.json', 'paging-activate.json', 'paging-cleanup.json', + 'guest-gaps.json', 'guest-skipped.json', 'terminal.json']: + yield work / name, Path('host') / name + for variant in VARIANTS: + yield root / 'admissions' / (variant + '.json'), Path('admissions') / (variant + '.json') + for name in [variant + '-skipped.json', variant + '-paging-live.json', variant + '-teams-fetched-skipped.json']: + yield work / name, Path('host') / name + for phase in ['preflight', 'build', 'preserve', *PHASES, *FOLLOW_ON_PHASES, 'guest-prerequisites', 'guest-security']: + name = f'{variant}-{phase}-deadline.json' + yield work / name, Path('host') / name + for name in ['plan.json', 'result.json', 'artifact-contract.stdout', 'artifact-contract.stderr', + 'measurement/receipt.json', 'measurement/stdout.txt', 'measurement/stderr.txt', + 'measurement/time.txt']: + yield root / 'build-receipts' / variant / name, Path('build-receipts') / variant / name + for phase in [*PHASES, *FOLLOW_ON_PHASES, 'guest-prerequisites', 'guest-security']: + for name in ['result.json', 'raw-index.json', 'raw-evidence.tar.gz']: + yield root / 'runtime-results' / (variant + '-' + phase) / name, Path('runtime-results') / (variant + '-' + phase) / name + for name in ['verification.json', 'replay-binding.json']: + yield root / 'teams-replay' / variant / name, Path('teams-replay') / variant / name + yield root / 'qualification-results' / (variant + '-core') / 'run/result.json', Path('qualification-results') / (variant + '-core') / 'run/result.json' + for name in ['artifact.tar', 'transport.json']: + yield root / 'preserved' / variant / name, Path('preserved') / variant / name + labels = {'clone': ['clone', 'fetch-cut', 'checkout'], 'toolchain': [], + 'install': ['frozen-install'], 'runtime': ['pnpm-build'], + 'boundary': ['ts-boundary'], 'plugins': ['select-plugins']} + for phase, commands in labels.items(): + yield root / 'prep-receipts' / phase / 'result.json', Path('prep-receipts') / phase / 'result.json' + yield work / (phase + '-deadline.json'), Path('host') / (phase + '-deadline.json') + for command in commands: + for name in ['receipt.json', 'stdout.txt', 'stderr.txt', 'time.txt']: + relative = Path(phase) / command / name + yield root / 'prep-receipts' / relative, Path('prep-receipts') / relative + for name in ['compiler-records.json', 'plugins/desktop.json', 'plugins/plugin-selection.json', + 'source-preparation.json', 'p0-reference.json', 'P0-artifacts.json']: + yield root / 'admission-inputs' / name, Path('admission-inputs') / name + + + +def follow_on_status(work, root, variant, phase, build_path): + receipt = facts(root / 'runtime-results' / (variant + '-' + phase) / 'result.json') + observed = receipt.get('status', 'invalid-receipt') + if observed != 'phase-passed': + return observed + deadline = facts(work / (variant + '-' + phase + '-deadline.json')) + if ((work / (variant + '-' + phase + '-skipped.json')).exists() + or deadline.get('exitCode') != 0 or deadline.get('timedOut') is not False + or deadline.get('interruptedBySignal') is not None + or deadline.get('finishedBeforeReserve') is not True): + return 'failed-or-missing-outer-receipt' + build = facts(build_path) + if build.get('status') != 'built-unsigned' or build.get('phase') != 'complete': + return 'invalid-build-binding' + artifact = build.get('artifact', {}) + with build_path.open('rb') as stream: + build_sha = hashlib.file_digest(stream, 'sha256').hexdigest() + expected = {'variant': variant, 'sourceCommit': '4fa442e332745f1f58ccedd27106abdafcf4e019', + 'binarySha256': artifact.get('executable', {}).get('sha256'), + 'manifestSha256': artifact.get('manifestSha256'), 'actualBuildReceiptSha256': build_sha} + if any(value is None or receipt.get(key) != value for key, value in expected.items()): + return 'invalid-build-binding' + return observed + + +def summary(work, root): + try: + execution = load(work / 'execution.json') + requested = requested_variants(execution) + selection = execution['variantSelection'] + selection_status = 'bound' + except (OSError, ValueError, KeyError, TypeError, AssertionError): + requested, selection, selection_status = [], None, 'missing-or-invalid' + result = {'sourceCommit': '4fa442e332745f1f58ccedd27106abdafcf4e019', + 'referenceRole': 'historical CB11 provenance only', 'variants': {}, + 'variantSelection': selection, 'requestedVariants': requested, + 'unselectedVariants': [variant for variant in VARIANTS if variant not in requested] if selection_status == 'bound' else [], + 'selectionStatus': selection_status, 'fullVariantMatrixComplete': False, + 'scheduledPhasesComplete': True, 'applicationQualified': False, 'shipReady': False, + 'unrunRequiredProof': ['same-machine Node/JIT npm baseline and balanced six-sweep ready/first-turn/RSS/CPU comparison', + 'full raw-trace strict zero-disk-JS and Worker boundary assessment', + 'live provider streamed-turn proof', + 'fetched CJS plugin load through the compiled SDK (PR183822); current plugin/Docker lanes do not establish this boundary']} + result['originatingAppExport'] = execution.get('originatingAppExport') if selection_status == 'bound' else None + result['functionalReplay'] = execution.get('kind') == 'untimed-functional-replay' if selection_status == 'bound' else False + result['nativeCompatibility'] = {'status': facts(root / 'prep-receipts/compatibility/result.json').get('status', 'not-run')} + result['scheduledPhasesComplete'] = selection_status == 'bound' and result['nativeCompatibility']['status'] == 'PASS' + for variant in VARIANTS: + if selection_status == 'bound' and variant not in requested: + result['variants'][variant] = {'requested': False, 'build': 'not-selected', 'runtime': {}, 'complete': False} + continue + build = root / 'build-receipts' / variant / 'result.json' + skipped = work / (variant + '-skipped.json') + row = {'requested': True if selection_status == 'bound' else None, + 'build': facts(build).get('status', 'invalid-receipt'), 'runtime': {}} + if skipped.is_file(): + row['skip'] = facts(skipped) + for phase in PHASES: + path = root / 'runtime-results' / (variant + '-' + phase) / 'result.json' + row['runtime'][phase] = facts(path).get('status', 'invalid-receipt') + row['complete'] = not skipped.is_file() and row['build'] == 'built-unsigned' and all(value == 'phase-passed' for value in row['runtime'].values()) + result['scheduledPhasesComplete'] = result['scheduledPhasesComplete'] and row['complete'] + row['followOnProof'] = {phase: follow_on_status(work, root, variant, phase, build) for phase in FOLLOW_ON_PHASES} + result['variants'][variant] = row + if requested and all(result['variants'][variant].get('followOnProof', {}).get('teams-fetched') == 'phase-passed' for variant in requested): + result['unrunRequiredProof'] = [item for item in result['unrunRequiredProof'] if not item.startswith('fetched CJS plugin load')] + result['guestSecurity'] = {variant: ('not-selected' if selection_status == 'bound' and variant not in requested else + facts(root / 'runtime-results' / (variant + '-guest-security') / 'result.json').get('status', 'invalid-receipt')) + for variant in ['js', 'c2-off']} + result['guestGaps'] = facts(work / 'guest-gaps.json') + if any(value != 'phase-passed' for value in result['guestSecurity'].values()): + result['unrunRequiredProof'].append('actual application PR_SET_MDWE on Linux >=6.7 guest for JS and C2') + cleanup = work / 'paging-cleanup.json' + result['pagingCleanup'] = facts(cleanup) + clean = result['pagingCleanup'] + cleanup_ok = clean.get('status') == 'not-activated' or ( + clean.get('operationExitCode') == 0 and clean.get('metadata', {}).get('phase') == 'cleaned') + result['scheduledPhasesComplete'] = result['scheduledPhasesComplete'] and cleanup_ok + result['fullVariantMatrixComplete'] = requested == list(VARIANTS) and result['scheduledPhasesComplete'] + return result + + +def main(): + os.umask(0o022) + work = Path(os.environ['P6_WORK']) + if sys.argv[1:] == ['--require-complete']: + result = load(work / 'export/summary.json') + print(json.dumps(result, indent=2)) + return 0 if result['scheduledPhasesComplete'] else 1 + assert not sys.argv[1:] + out = work / 'export' + out.mkdir(exist_ok=False) + index = [] + for source, relative in selections(work, ROOT): + if not source.exists(): + continue + assert stat.S_ISREG(source.lstat().st_mode), f'Only regular selected files: {source}' + resolved = source.resolve(strict=True) + boundary = ROOT if source.is_relative_to(ROOT) else work + assert resolved.is_relative_to(boundary.resolve(strict=True)), 'Selected export escapes its task boundary' + assert not any(part in ['ephemeral-swap64', 'paging-tools'] for part in resolved.parts) + target = out / relative + target.parent.mkdir(parents=True, exist_ok=True) + shutil.copyfile(source, target) + with target.open('rb') as stream: + digest = hashlib.file_digest(stream, 'sha256').hexdigest() + index.append({'path': str(relative), 'sha256': digest, 'bytes': target.stat().st_size}) + (out / 'index.json').write_text(json.dumps(index, indent=2) + '\n') + (out / 'summary.json').write_text(json.dumps(summary(work, ROOT), indent=2) + '\n') + return 0 + + +if __name__ == '__main__': + raise SystemExit(main()) diff --git a/scripts/openclaw-p6/app/guest.py b/scripts/openclaw-p6/app/guest.py new file mode 100644 index 000000000000..320af0380b49 --- /dev/null +++ b/scripts/openclaw-p6/app/guest.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python3 +"""Schedule the accepted actual-app KVM/MDWE owners if native capacity remains.""" +import hashlib +import json +import os +from pathlib import Path +import stat +import subprocess +import sys +import time +from selection import requested_variants + +ROOT = Path('/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1') + + +def read(path): + return json.loads(path.read_text()) + + +def sha(path): + with path.open('rb') as stream: + return hashlib.file_digest(stream, 'sha256').hexdigest() + + +def main(): + work = Path(os.environ['P6_WORK']) + requested = requested_variants(read(work / 'execution.json')) + variants = [variant for variant in ['js', 'c2-off'] if variant in requested] + if not variants: + return 0 + deadline = float(os.environ['P6_DEADLINE_EPOCH']) + gaps = [] + def gap(variant, reason): + gaps.append({'variant': variant, 'status': 'not-run', 'reason': reason}) + (work / 'guest-gaps.json').write_text(json.dumps(gaps, indent=2) + '\n') + device = Path('/dev/kvm') + if not device.exists() or not stat.S_ISCHR(device.stat().st_mode): + gap('all', 'Native /dev/kvm unavailable; no emulation fallback') + return 0 + ready = [] + for variant in variants: + build = ROOT / 'build-receipts' / variant / 'result.json' + core = ROOT / 'qualification-results' / (variant + '-core') / 'run/result.json' + if not build.is_file() or read(build).get('status') != 'built-unsigned' or not core.is_file(): + gap(variant, 'Actual successful build and host core/version receipt required') + else: + ready.append(variant) + if not ready: + return 0 + def phase(variant, name): + admission = ROOT / 'admissions' / (variant + '.json') + command = [sys.executable, '/p6-recipe/deadline_process.py', '--deadline-epoch', str(deadline), + '--reserve-seconds', '1200', '--cleanup-grace-seconds', '30', '--receipt', + str(work / (variant + '-' + name + '-deadline.json')), '--', 'env', '-i', + 'HOME=/home/runner', 'PATH=/usr/bin:/bin:/usr/sbin:/sbin', 'PYTHONDONTWRITEBYTECODE=1', + 'TMPDIR=' + str(ROOT / 'tmp'), sys.executable, '-B', str(ROOT / 'runtime-controller.py'), + '--variant', variant, '--phase', name, '--admission-sha256', sha(admission)] + code = subprocess.run(command).returncode + return 128 - code if code < 0 else code + if deadline - time.time() - 1200 < 1900: + gap('all', 'Less than 1900s remain for bounded prerequisite + actual guest owners') + return 0 + code = phase(ready[0], 'guest-prerequisites') + if code == 124 or code >= 128: + return code + if code: + gap('all', 'Guest prerequisites failed; preserve actual owner receipt') + return 0 + for variant in ready: + if deadline - time.time() - 1200 < 950: + gap(variant, 'Less than 950s remain for actual guest owner') + continue + code = phase(variant, 'guest-security') + if code == 124 or code >= 128: + return code + if code: + gap(variant, 'Actual guest owner failed; preserve result and raw evidence') + return 0 + + +if __name__ == '__main__': + raise SystemExit(main()) diff --git a/scripts/openclaw-p6/app/guest.sh b/scripts/openclaw-p6/app/guest.sh new file mode 100644 index 000000000000..28cd51e3f616 --- /dev/null +++ b/scripts/openclaw-p6/app/guest.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -euo pipefail +cd "$P6_WORK" +python3 -B /p6-recipe/app/guest.py diff --git a/scripts/openclaw-p6/app/host.sh b/scripts/openclaw-p6/app/host.sh new file mode 100644 index 000000000000..1ea9a6b968f4 --- /dev/null +++ b/scripts/openclaw-p6/app/host.sh @@ -0,0 +1,191 @@ +#!/usr/bin/env bash +set -euo pipefail +phase=${1:?bootstrap, prepare, variant or cleanup} +: "${P6_WORK:?Missing task directory}" +: "${P6_CONTAINER:?Missing owned container}" +recipe=$(cd "$(dirname "$0")/.." && pwd -P) +mode=${P6_EXECUTION_MODE:-app} +case "$mode" in app|benchmark|teams) ;; *) exit 2;; esac +initializer="$recipe/app/initialize.py" +if [[ "$mode" == benchmark ]]; then initializer="$recipe/app/benchmark/initialize.py"; fi +if [[ "$mode" == teams ]]; then initializer="$recipe/app/teams-mode/initialize.py"; fi +execution_file="$P6_WORK/execution.json" +if [[ "$mode" == teams ]]; then execution_file="$P6_WORK/teams-execution.json"; fi +base=/home/runner/.cache/oc-ty-ext/P6 +root=$base/app-x64-final-r4-v1 +label="openclaw.p6.actions=$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT" +paging() { + sudo -n env -i PATH=/usr/sbin:/usr/bin:/sbin:/bin P6_WORK="$P6_WORK" \ + GITHUB_REPOSITORY="$GITHUB_REPOSITORY" GITHUB_RUN_ID="$GITHUB_RUN_ID" \ + GITHUB_RUN_ATTEMPT="$GITHUB_RUN_ATTEMPT" GITHUB_JOB="$GITHUB_JOB" GITHUB_SHA="$GITHUB_SHA" \ + python3 -B "$recipe/app/paging-host.py" "$@" +} +remove_children() { + local ids + ids=$(timeout --kill-after=5s 30s docker ps -aq --filter "label=$label") + if [[ -n "$ids" ]]; then + while IFS= read -r id; do timeout --kill-after=5s 30s docker rm -f "$id"; done <<< "$ids" + fi + ids=$(timeout --kill-after=5s 30s docker network ls -q --filter "label=$label") + if [[ -n "$ids" ]]; then + while IFS= read -r id; do timeout --kill-after=5s 30s docker network rm "$id"; done <<< "$ids" + fi + [[ -z "$(timeout --kill-after=5s 30s docker ps -aq --filter "label=$label")" ]] + [[ -z "$(timeout --kill-after=5s 30s docker network ls -q --filter "label=$label")" ]] +} +ensure_running() { + [[ $(timeout --kill-after=5s 30s docker inspect --format '{{index .Config.Labels "openclaw.p6.owner"}}' "$P6_CONTAINER") == "$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT" ]] + if [[ $(timeout --kill-after=5s 30s docker inspect --format '{{.State.Running}}' "$P6_CONTAINER") != true ]]; then + remove_children + timeout --kill-after=10s 50s docker start "$P6_CONTAINER" >/dev/null + fi +} +if [[ "$phase" == reconcile-children ]]; then + [[ "$mode" == benchmark ]] + [[ $(timeout --kill-after=5s 30s docker inspect --format '{{index .Config.Labels "openclaw.p6.owner"}}' "$P6_CONTAINER") == "$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT" ]] + python3 -B - "$P6_WORK/requalification-child-cleanup.json" "$label" <<'PYTHON' +import hashlib,json,os,subprocess,sys +from pathlib import Path +path=Path(sys.argv[1]);label=sys.argv[2] +ids=subprocess.check_output(['docker','ps','-aq','--filter','label='+label],text=True,timeout=30).split() +format='{"id":{{json .Id}},"running":{{json .State.Running}},"paused":{{json .State.Paused}},"restarting":{{json .State.Restarting}}}' +rows=[json.loads(line) for line in subprocess.check_output(['docker','inspect','--format',format,*ids],text=True,timeout=30).splitlines()] if ids else [] +execution=Path(os.environ['P6_WORK'])/'execution.json' +execution_data=execution.read_bytes() +record={'status':'before-removal','identity':json.loads(execution_data)['identity'], + 'executionSha256':hashlib.sha256(execution_data).hexdigest(), 'label':label, + 'childrenBeforeRemoval':rows,'forcedRecovery':any(row['running'] or row['paused'] or row['restarting'] for row in rows)} +with path.open('x') as stream:json.dump(record,stream,indent=2);stream.write('\n') +PYTHON + remove_children + python3 -B - "$P6_WORK/requalification-child-cleanup.json" <<'PYTHON' +import json,sys +from pathlib import Path +path=Path(sys.argv[1]);record=json.loads(path.read_text());record['status']='children-removed' +path.write_text(json.dumps(record,indent=2)+'\n') +PYTHON + exit +fi +if [[ "$phase" == cleanup ]]; then + timeout --kill-after=5s 30s docker stop --time 15 "$P6_CONTAINER" >/dev/null 2>&1 || true + timeout --kill-after=5s 30s docker rm -f "$P6_CONTAINER" >/dev/null 2>&1 || true + [[ -z "$(timeout --kill-after=5s 30s docker ps -aq --filter "name=^${P6_CONTAINER}$")" ]] + remove_children + if [[ "$mode" == app ]]; then + paging cleanup + else + python3 -B "$initializer" cleanup + fi + exit +fi +: "${P6_DEADLINE_EPOCH:?Missing absolute work deadline}" +remember_terminal() { + if (( $1 == 124 || $1 >= 128 )); then + python3 -B "$initializer" terminal "$1" || true + fi +} +stop_on_failure() { + code=$? + if (( code != 0 )); then + remember_terminal "$code" + timeout --kill-after=5s 30s docker stop --time 15 "$P6_CONTAINER" >/dev/null 2>&1 || true + remove_children || true + fi + return "$code" +} +trap stop_on_failure EXIT +if [[ "$phase" == bootstrap ]]; then + [[ $(uname -s) == Linux && $(uname -m) == x86_64 ]] + [[ ! -e "$root" ]] + mkdir -p "$P6_WORK" "$base" + python3 -B "$initializer" + if [[ "$mode" == app ]]; then + timeout --kill-after=15s 300s sudo -n apt-get update + timeout --kill-after=15s 300s sudo -n apt-get install -y --no-install-recommends cryptsetup + fi + image=ubuntu:24.04@sha256:a2d43bffc46670d7108bb3c0468c67c5557c4c92e83e1e34cbff1322ad1b94dc + timeout --kill-after=15s 300s docker pull "$image" + devices=() + if [[ -c /dev/kvm ]]; then devices=(--device /dev/kvm:/dev/kvm); fi + inputs=() + if [[ "$mode" == benchmark ]]; then + [[ -d "$P6_WORK/benchmark-download" ]] + inputs=(--mount "type=bind,src=$P6_WORK/benchmark-download,dst=$P6_WORK/benchmark-download,readonly") + fi + if [[ "$mode" == teams ]]; then + [[ -d "${P6_WORK}-download" && -d "$GITHUB_WORKSPACE/.git" ]] + inputs=(--mount "type=bind,src=${P6_WORK}-download,dst=${P6_WORK}-download,readonly" + --mount "type=bind,src=$GITHUB_WORKSPACE,dst=/p6-helper,readonly") + fi + buildx=$(timeout --kill-after=5s 30s docker info --format '{{range .ClientInfo.Plugins}}{{if eq .Name "buildx"}}{{.Path}}{{end}}{{end}}') + [[ -n "$buildx" && -f "$buildx" && -x "$buildx" ]] + timeout --kill-after=10s 50s docker run --detach --name "$P6_CONTAINER" --init \ + --platform linux/amd64 --ulimit core=0:0 --label "openclaw.p6.owner=$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT" \ + "${devices[@]}" \ + --mount "type=bind,src=$recipe,dst=/p6-recipe,readonly" \ + --mount "type=bind,src=$base,dst=$base" \ + --mount "type=bind,src=$P6_WORK,dst=$P6_WORK" \ + "${inputs[@]}" \ + --mount "type=bind,src=$execution_file,dst=/p6-execution.json,readonly" \ + --mount "type=bind,src=$(command -v docker),dst=/p6-host-docker,readonly" \ + --mount "type=bind,src=$buildx,dst=/p6-host-buildx,readonly" \ + --mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock \ + "$image" sleep infinity >/dev/null + timeout --kill-after=5s 30s docker exec "$P6_CONTAINER" ln -s /p6-recipe/app/docker-client.py /usr/bin/docker + timeout --kill-after=5s 30s docker exec "$P6_CONTAINER" mkdir -p /usr/libexec/docker/cli-plugins + timeout --kill-after=5s 30s docker exec "$P6_CONTAINER" ln -s /p6-host-buildx /usr/libexec/docker/cli-plugins/docker-buildx + exit +fi +[[ "$mode" == app ]] || { echo 'Non-app phases use their dedicated host owner' >&2; exit 2; } +if [[ "$phase" == paging ]]; then + remaining=$((P6_DEADLINE_EPOCH - $(date +%s) - 1200)) + (( remaining > 120 )) || exit 124 + sudo -n python3 -B - "$root/prep-receipts/plugins/result.json" <<'PY' +import json,sys +from pathlib import Path +assert json.loads(Path(sys.argv[1]).read_text())['status']=='PASS', 'Actual completed native preparation required' +PY + timeout --signal=TERM --kill-after=30s "${remaining}s" docker exec \ + -e HOME=/home/runner -e P6_WORK="$P6_WORK" -e PYTHONDONTWRITEBYTECODE=1 \ + "$P6_CONTAINER" python3 -B /p6-recipe/app/preflight.py verify + paging activate + exit +fi +remaining=$((P6_DEADLINE_EPOCH - $(date +%s) - 1200)) +if (( remaining <= 120 )); then + python3 -B "$recipe/app/initialize.py" skip "${2:-$phase}" deadline + [[ "$phase" != prepare ]] || exit 124 + exit 0 +fi +if [[ ( "$phase" == variant || "$phase" == guest ) && -f "$P6_WORK/terminal.json" ]]; then + python3 -B "$recipe/app/initialize.py" skip "${2:-$phase}" previous-terminal-exit + exit 0 +fi +if [[ "$phase" == variant ]]; then + ensure_running + timeout --signal=TERM --kill-after=30s "${remaining}s" docker exec \ + -e HOME=/home/runner -e P6_WORK="$P6_WORK" -e P6_DEADLINE_EPOCH="$P6_DEADLINE_EPOCH" \ + -e PYTHONDONTWRITEBYTECODE=1 "$P6_CONTAINER" bash /p6-recipe/app/variant.sh "$2" prepare + paging verify "$2" + script=variant.sh +elif [[ "$phase" == prepare ]]; then + script=prepare.sh +elif [[ "$phase" == guest ]]; then + ensure_running + script=guest.sh +else + echo "Unknown app phase: $phase" >&2 + exit 2 +fi +remaining=$((P6_DEADLINE_EPOCH - $(date +%s) - 1200)) +(( remaining > 0 )) || exit 124 +code=0 +timeout --signal=TERM --kill-after=30s "${remaining}s" docker exec \ + -e HOME=/home/runner -e P6_WORK="$P6_WORK" -e P6_DEADLINE_EPOCH="$P6_DEADLINE_EPOCH" \ + -e PYTHONDONTWRITEBYTECODE=1 "$P6_CONTAINER" bash "/p6-recipe/app/$script" "${2:-}" run || code=$? +remember_terminal "$code" +if (( code != 0 )); then + timeout --kill-after=5s 30s docker stop --time 15 "$P6_CONTAINER" >/dev/null 2>&1 || true +fi +remove_children +exit "$code" diff --git a/scripts/openclaw-p6/app/initialize.py b/scripts/openclaw-p6/app/initialize.py new file mode 100644 index 000000000000..69e98f36e053 --- /dev/null +++ b/scripts/openclaw-p6/app/initialize.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 +"""Record the actual Actions identity and bounded skip results.""" +import json +import os +from pathlib import Path +import platform +import re +import resource +import shutil +import sys +import time +from selection import select_variants + +work = Path(os.environ['P6_WORK']) +resource.setrlimit(resource.RLIMIT_CORE, (0, 0)) +if len(sys.argv) > 1: + if sys.argv[1] == 'terminal': + code = int(sys.argv[2]) + assert code == 124 or code >= 128 + (work / 'terminal.json').write_text(json.dumps({'status': 'terminal', 'exitCode': code}) + '\n') + else: + assert sys.argv[1] == 'skip' and sys.argv[2] in ['prepare', 'js', 'c2-off', 'ts', 'guest'] + (work / (sys.argv[2] + '-skipped.json')).write_text(json.dumps({ + 'status': 'not-run', 'reason': sys.argv[3], 'applicationQualified': False}) + '\n') +else: + assert platform.system() == 'Linux' and platform.machine() == 'x86_64' + identity = {'repository': os.environ['GITHUB_REPOSITORY'], 'runId': os.environ['GITHUB_RUN_ID'], + 'runAttempt': os.environ['GITHUB_RUN_ATTEMPT'], 'job': os.environ['GITHUB_JOB']} + assert identity['repository'] == 'openclaw/bun' and identity['job'] == 'linux-x64-app' + assert all(re.fullmatch('[1-9][0-9]*', identity[key]) for key in ['runId', 'runAttempt']) + record = {'schemaVersion': 1, 'identity': identity, 'workflowHead': os.environ['GITHUB_SHA'], + 'sourceCommit': '4fa442e332745f1f58ccedd27106abdafcf4e019', 'startedEpoch': time.time(), + **select_variants(os.environ.get('P6_APP_VARIANTS', 'all'))} + with (work / 'execution.json').open('x') as stream: + json.dump(record, stream, indent=2) + stream.write('\n') + memory = int(next(row.split()[1] for row in Path('/proc/meminfo').read_text().splitlines() + if row.startswith('MemTotal:'))) * 1024 + facts = {'memTotalBytes': memory, 'cpus': len(os.sched_getaffinity(0)), + 'diskFreeBytes': shutil.disk_usage('/home/runner/.cache/oc-ty-ext/P6').free, + 'kernel': platform.release(), 'applicationFitQualified': False} + (work / 'resources.json').write_text(json.dumps(facts, indent=2) + '\n') + assert memory >= 30_000_000_000 and facts['cpus'] >= 2 + assert facts['diskFreeBytes'] >= 121 * 1024**3, '64GiB paging + 25GiB floor + 32GiB headroom required' diff --git a/scripts/openclaw-p6/app/packet/commands.json b/scripts/openclaw-p6/app/packet/commands.json new file mode 100644 index 000000000000..fa86c4bdc2c1 --- /dev/null +++ b/scripts/openclaw-p6/app/packet/commands.json @@ -0,0 +1,55 @@ +{ + "adopt-compilers": "set -euo pipefail\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/adopt-compilers.py\"\n", + "clone": "set -euo pipefail\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/native-prep.py\" --root \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1\" --phase clone\n", + "toolchain": "set -euo pipefail\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/native-prep.py\" --root \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1\" --phase toolchain\n", + "install": "set -euo pipefail\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/native-prep.py\" --root \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1\" --phase install\n", + "runtime": "set -euo pipefail\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/native-prep.py\" --root \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1\" --phase runtime\n", + "boundary": "set -euo pipefail\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/native-prep.py\" --root \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1\" --phase boundary\n", + "plugins": "set -euo pipefail\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/native-prep.py\" --root \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1\" --phase plugins\n", + "js-preflight": "set -euo pipefail\n: \"${P6_ADMISSION_SHA256:?Set the SHA256 of this exact actual root admission}\"\npython3 -B - '/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/js.json' \"$P6_ADMISSION_SHA256\" <<'P6_BIND'\nfrom pathlib import Path\nimport hashlib,sys\nassert hashlib.sha256(Path(sys.argv[1]).read_bytes()).hexdigest()==sys.argv[2]\nP6_BIND\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/build-prep/build-linux.py\" --root \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1\" --admission \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/js.json\" --measure-command \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/measure-command.py\"\n", + "js-build": "set -euo pipefail\n: \"${P6_ADMISSION_SHA256:?Set the SHA256 of this exact actual root admission}\"\npython3 -B - '/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/js.json' \"$P6_ADMISSION_SHA256\" <<'P6_BIND'\nfrom pathlib import Path\nimport hashlib,sys\nassert hashlib.sha256(Path(sys.argv[1]).read_bytes()).hexdigest()==sys.argv[2]\nP6_BIND\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/build-prep/build-linux.py\" --root \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1\" --admission \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/js.json\" --measure-command \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/measure-command.py\" --run\n", + "js-preserve": "set -euo pipefail\n: \"${P6_ADMISSION_SHA256:?Set the SHA256 of this exact actual root admission}\"\npython3 -B - '/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/js.json' \"$P6_ADMISSION_SHA256\" <<'P6_BIND'\nfrom pathlib import Path\nimport hashlib,sys\nassert hashlib.sha256(Path(sys.argv[1]).read_bytes()).hexdigest()==sys.argv[2]\nP6_BIND\nenv -i HOME=/home/runner PATH=/usr/bin:/bin python3 -B - \"$P6_ADMISSION_SHA256\" <<'P6_PRESERVE'\nfrom pathlib import Path\nimport hashlib,json,subprocess,sys\nroot=Path('/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1');receipt=Path('/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/build-receipts/js');admission=Path('/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/js.json')\nassert hashlib.sha256(admission.read_bytes()).hexdigest()==sys.argv[1]\nplan=receipt/'plan.json';result=receipt/'result.json';p=json.loads(plan.read_text())\nassert p['admissionSha256']==sys.argv[1]\ncommand=[sys.executable,'-B',str(root/'preserve.py'),'pack','--plan',str(plan),'--plan-sha256',hashlib.sha256(plan.read_bytes()).hexdigest(),'--result',str(result),'--result-sha256',hashlib.sha256(result.read_bytes()).hexdigest(),'--checker',str(root/'build-prep/artifact-contract.mjs'),'--out',str(root/'preserved'/'js')]\nsubprocess.run(command,check=True)\nP6_PRESERVE\n", + "js-core": "set -euo pipefail\n: \"${P6_ADMISSION_SHA256:?Set the SHA256 of this exact actual root admission}\"\npython3 -B - '/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/js.json' \"$P6_ADMISSION_SHA256\" <<'P6_BIND'\nfrom pathlib import Path\nimport hashlib,sys\nassert hashlib.sha256(Path(sys.argv[1]).read_bytes()).hexdigest()==sys.argv[2]\nP6_BIND\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/runtime-controller.py\" --variant js --phase core --admission-sha256 \"$P6_ADMISSION_SHA256\"\n", + "js-elf-floor": "set -euo pipefail\n: \"${P6_ADMISSION_SHA256:?Set the SHA256 of this exact actual root admission}\"\npython3 -B - '/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/js.json' \"$P6_ADMISSION_SHA256\" <<'P6_BIND'\nfrom pathlib import Path\nimport hashlib,sys\nassert hashlib.sha256(Path(sys.argv[1]).read_bytes()).hexdigest()==sys.argv[2]\nP6_BIND\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/runtime-controller.py\" --variant js --phase elf-floor --admission-sha256 \"$P6_ADMISSION_SHA256\"\n", + "js-zero-js": "set -euo pipefail\n: \"${P6_ADMISSION_SHA256:?Set the SHA256 of this exact actual root admission}\"\npython3 -B - '/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/js.json' \"$P6_ADMISSION_SHA256\" <<'P6_BIND'\nfrom pathlib import Path\nimport hashlib,sys\nassert hashlib.sha256(Path(sys.argv[1]).read_bytes()).hexdigest()==sys.argv[2]\nP6_BIND\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/runtime-controller.py\" --variant js --phase zero-js --admission-sha256 \"$P6_ADMISSION_SHA256\"\n", + "js-node-vm": "set -euo pipefail\n: \"${P6_ADMISSION_SHA256:?Set the SHA256 of this exact actual root admission}\"\npython3 -B - '/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/js.json' \"$P6_ADMISSION_SHA256\" <<'P6_BIND'\nfrom pathlib import Path\nimport hashlib,sys\nassert hashlib.sha256(Path(sys.argv[1]).read_bytes()).hexdigest()==sys.argv[2]\nP6_BIND\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/runtime-controller.py\" --variant js --phase node-vm --admission-sha256 \"$P6_ADMISSION_SHA256\"\n", + "js-node-vm-native-workers": "set -euo pipefail\n: \"${P6_ADMISSION_SHA256:?Set the SHA256 of this exact actual root admission}\"\npython3 -B - '/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/js.json' \"$P6_ADMISSION_SHA256\" <<'P6_BIND'\nfrom pathlib import Path\nimport hashlib,sys\nassert hashlib.sha256(Path(sys.argv[1]).read_bytes()).hexdigest()==sys.argv[2]\nP6_BIND\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/runtime-controller.py\" --variant js --phase node-vm-native-workers --admission-sha256 \"$P6_ADMISSION_SHA256\"\n", + "js-pty": "set -euo pipefail\n: \"${P6_ADMISSION_SHA256:?Set the SHA256 of this exact actual root admission}\"\npython3 -B - '/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/js.json' \"$P6_ADMISSION_SHA256\" <<'P6_BIND'\nfrom pathlib import Path\nimport hashlib,sys\nassert hashlib.sha256(Path(sys.argv[1]).read_bytes()).hexdigest()==sys.argv[2]\nP6_BIND\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/runtime-controller.py\" --variant js --phase pty --admission-sha256 \"$P6_ADMISSION_SHA256\"\n", + "js-plugin": "set -euo pipefail\n: \"${P6_ADMISSION_SHA256:?Set the SHA256 of this exact actual root admission}\"\npython3 -B - '/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/js.json' \"$P6_ADMISSION_SHA256\" <<'P6_BIND'\nfrom pathlib import Path\nimport hashlib,sys\nassert hashlib.sha256(Path(sys.argv[1]).read_bytes()).hexdigest()==sys.argv[2]\nP6_BIND\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/runtime-controller.py\" --variant js --phase plugin --admission-sha256 \"$P6_ADMISSION_SHA256\"\n", + "js-docker-image": "set -euo pipefail\n: \"${P6_ADMISSION_SHA256:?Set the SHA256 of this exact actual root admission}\"\npython3 -B - '/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/js.json' \"$P6_ADMISSION_SHA256\" <<'P6_BIND'\nfrom pathlib import Path\nimport hashlib,sys\nassert hashlib.sha256(Path(sys.argv[1]).read_bytes()).hexdigest()==sys.argv[2]\nP6_BIND\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/runtime-controller.py\" --variant js --phase docker-image --admission-sha256 \"$P6_ADMISSION_SHA256\"\n", + "js-docker-gateway-network": "set -euo pipefail\n: \"${P6_ADMISSION_SHA256:?Set the SHA256 of this exact actual root admission}\"\npython3 -B - '/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/js.json' \"$P6_ADMISSION_SHA256\" <<'P6_BIND'\nfrom pathlib import Path\nimport hashlib,sys\nassert hashlib.sha256(Path(sys.argv[1]).read_bytes()).hexdigest()==sys.argv[2]\nP6_BIND\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/runtime-controller.py\" --variant js --phase docker-gateway-network --admission-sha256 \"$P6_ADMISSION_SHA256\"\n", + "js-docker-kitchen-sink": "set -euo pipefail\n: \"${P6_ADMISSION_SHA256:?Set the SHA256 of this exact actual root admission}\"\npython3 -B - '/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/js.json' \"$P6_ADMISSION_SHA256\" <<'P6_BIND'\nfrom pathlib import Path\nimport hashlib,sys\nassert hashlib.sha256(Path(sys.argv[1]).read_bytes()).hexdigest()==sys.argv[2]\nP6_BIND\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/runtime-controller.py\" --variant js --phase docker-kitchen-sink --admission-sha256 \"$P6_ADMISSION_SHA256\"\n", + "js-docker-cron": "set -euo pipefail\n: \"${P6_ADMISSION_SHA256:?Set the SHA256 of this exact actual root admission}\"\npython3 -B - '/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/js.json' \"$P6_ADMISSION_SHA256\" <<'P6_BIND'\nfrom pathlib import Path\nimport hashlib,sys\nassert hashlib.sha256(Path(sys.argv[1]).read_bytes()).hexdigest()==sys.argv[2]\nP6_BIND\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/runtime-controller.py\" --variant js --phase docker-cron --admission-sha256 \"$P6_ADMISSION_SHA256\"\n", + "js-guest-security": "set -euo pipefail\n: \"${P6_ADMISSION_SHA256:?Set the SHA256 of this exact actual root admission}\"\npython3 -B - '/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/js.json' \"$P6_ADMISSION_SHA256\" <<'P6_BIND'\nfrom pathlib import Path\nimport hashlib,sys\nassert hashlib.sha256(Path(sys.argv[1]).read_bytes()).hexdigest()==sys.argv[2]\nP6_BIND\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/runtime-controller.py\" --variant js --phase guest-security --admission-sha256 \"$P6_ADMISSION_SHA256\"\n", + "c2-off-preflight": "set -euo pipefail\n: \"${P6_ADMISSION_SHA256:?Set the SHA256 of this exact actual root admission}\"\npython3 -B - '/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/c2-off.json' \"$P6_ADMISSION_SHA256\" <<'P6_BIND'\nfrom pathlib import Path\nimport hashlib,sys\nassert hashlib.sha256(Path(sys.argv[1]).read_bytes()).hexdigest()==sys.argv[2]\nP6_BIND\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/build-prep/build-linux.py\" --root \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1\" --admission \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/c2-off.json\" --measure-command \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/measure-command.py\"\n", + "c2-off-build": "set -euo pipefail\n: \"${P6_ADMISSION_SHA256:?Set the SHA256 of this exact actual root admission}\"\npython3 -B - '/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/c2-off.json' \"$P6_ADMISSION_SHA256\" <<'P6_BIND'\nfrom pathlib import Path\nimport hashlib,sys\nassert hashlib.sha256(Path(sys.argv[1]).read_bytes()).hexdigest()==sys.argv[2]\nP6_BIND\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/build-prep/build-linux.py\" --root \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1\" --admission \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/c2-off.json\" --measure-command \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/measure-command.py\" --run\n", + "c2-off-preserve": "set -euo pipefail\n: \"${P6_ADMISSION_SHA256:?Set the SHA256 of this exact actual root admission}\"\npython3 -B - '/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/c2-off.json' \"$P6_ADMISSION_SHA256\" <<'P6_BIND'\nfrom pathlib import Path\nimport hashlib,sys\nassert hashlib.sha256(Path(sys.argv[1]).read_bytes()).hexdigest()==sys.argv[2]\nP6_BIND\nenv -i HOME=/home/runner PATH=/usr/bin:/bin python3 -B - \"$P6_ADMISSION_SHA256\" <<'P6_PRESERVE'\nfrom pathlib import Path\nimport hashlib,json,subprocess,sys\nroot=Path('/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1');receipt=Path('/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/build-receipts/c2-off');admission=Path('/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/c2-off.json')\nassert hashlib.sha256(admission.read_bytes()).hexdigest()==sys.argv[1]\nplan=receipt/'plan.json';result=receipt/'result.json';p=json.loads(plan.read_text())\nassert p['admissionSha256']==sys.argv[1]\ncommand=[sys.executable,'-B',str(root/'preserve.py'),'pack','--plan',str(plan),'--plan-sha256',hashlib.sha256(plan.read_bytes()).hexdigest(),'--result',str(result),'--result-sha256',hashlib.sha256(result.read_bytes()).hexdigest(),'--checker',str(root/'build-prep/artifact-contract.mjs'),'--out',str(root/'preserved'/'c2-off')]\nsubprocess.run(command,check=True)\nP6_PRESERVE\n", + "c2-off-core": "set -euo pipefail\n: \"${P6_ADMISSION_SHA256:?Set the SHA256 of this exact actual root admission}\"\npython3 -B - '/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/c2-off.json' \"$P6_ADMISSION_SHA256\" <<'P6_BIND'\nfrom pathlib import Path\nimport hashlib,sys\nassert hashlib.sha256(Path(sys.argv[1]).read_bytes()).hexdigest()==sys.argv[2]\nP6_BIND\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/runtime-controller.py\" --variant c2-off --phase core --admission-sha256 \"$P6_ADMISSION_SHA256\"\n", + "c2-off-elf-floor": "set -euo pipefail\n: \"${P6_ADMISSION_SHA256:?Set the SHA256 of this exact actual root admission}\"\npython3 -B - '/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/c2-off.json' \"$P6_ADMISSION_SHA256\" <<'P6_BIND'\nfrom pathlib import Path\nimport hashlib,sys\nassert hashlib.sha256(Path(sys.argv[1]).read_bytes()).hexdigest()==sys.argv[2]\nP6_BIND\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/runtime-controller.py\" --variant c2-off --phase elf-floor --admission-sha256 \"$P6_ADMISSION_SHA256\"\n", + "c2-off-zero-js": "set -euo pipefail\n: \"${P6_ADMISSION_SHA256:?Set the SHA256 of this exact actual root admission}\"\npython3 -B - '/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/c2-off.json' \"$P6_ADMISSION_SHA256\" <<'P6_BIND'\nfrom pathlib import Path\nimport hashlib,sys\nassert hashlib.sha256(Path(sys.argv[1]).read_bytes()).hexdigest()==sys.argv[2]\nP6_BIND\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/runtime-controller.py\" --variant c2-off --phase zero-js --admission-sha256 \"$P6_ADMISSION_SHA256\"\n", + "c2-off-node-vm": "set -euo pipefail\n: \"${P6_ADMISSION_SHA256:?Set the SHA256 of this exact actual root admission}\"\npython3 -B - '/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/c2-off.json' \"$P6_ADMISSION_SHA256\" <<'P6_BIND'\nfrom pathlib import Path\nimport hashlib,sys\nassert hashlib.sha256(Path(sys.argv[1]).read_bytes()).hexdigest()==sys.argv[2]\nP6_BIND\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/runtime-controller.py\" --variant c2-off --phase node-vm --admission-sha256 \"$P6_ADMISSION_SHA256\"\n", + "c2-off-node-vm-native-workers": "set -euo pipefail\n: \"${P6_ADMISSION_SHA256:?Set the SHA256 of this exact actual root admission}\"\npython3 -B - '/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/c2-off.json' \"$P6_ADMISSION_SHA256\" <<'P6_BIND'\nfrom pathlib import Path\nimport hashlib,sys\nassert hashlib.sha256(Path(sys.argv[1]).read_bytes()).hexdigest()==sys.argv[2]\nP6_BIND\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/runtime-controller.py\" --variant c2-off --phase node-vm-native-workers --admission-sha256 \"$P6_ADMISSION_SHA256\"\n", + "c2-off-pty": "set -euo pipefail\n: \"${P6_ADMISSION_SHA256:?Set the SHA256 of this exact actual root admission}\"\npython3 -B - '/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/c2-off.json' \"$P6_ADMISSION_SHA256\" <<'P6_BIND'\nfrom pathlib import Path\nimport hashlib,sys\nassert hashlib.sha256(Path(sys.argv[1]).read_bytes()).hexdigest()==sys.argv[2]\nP6_BIND\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/runtime-controller.py\" --variant c2-off --phase pty --admission-sha256 \"$P6_ADMISSION_SHA256\"\n", + "c2-off-plugin": "set -euo pipefail\n: \"${P6_ADMISSION_SHA256:?Set the SHA256 of this exact actual root admission}\"\npython3 -B - '/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/c2-off.json' \"$P6_ADMISSION_SHA256\" <<'P6_BIND'\nfrom pathlib import Path\nimport hashlib,sys\nassert hashlib.sha256(Path(sys.argv[1]).read_bytes()).hexdigest()==sys.argv[2]\nP6_BIND\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/runtime-controller.py\" --variant c2-off --phase plugin --admission-sha256 \"$P6_ADMISSION_SHA256\"\n", + "c2-off-docker-image": "set -euo pipefail\n: \"${P6_ADMISSION_SHA256:?Set the SHA256 of this exact actual root admission}\"\npython3 -B - '/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/c2-off.json' \"$P6_ADMISSION_SHA256\" <<'P6_BIND'\nfrom pathlib import Path\nimport hashlib,sys\nassert hashlib.sha256(Path(sys.argv[1]).read_bytes()).hexdigest()==sys.argv[2]\nP6_BIND\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/runtime-controller.py\" --variant c2-off --phase docker-image --admission-sha256 \"$P6_ADMISSION_SHA256\"\n", + "c2-off-docker-gateway-network": "set -euo pipefail\n: \"${P6_ADMISSION_SHA256:?Set the SHA256 of this exact actual root admission}\"\npython3 -B - '/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/c2-off.json' \"$P6_ADMISSION_SHA256\" <<'P6_BIND'\nfrom pathlib import Path\nimport hashlib,sys\nassert hashlib.sha256(Path(sys.argv[1]).read_bytes()).hexdigest()==sys.argv[2]\nP6_BIND\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/runtime-controller.py\" --variant c2-off --phase docker-gateway-network --admission-sha256 \"$P6_ADMISSION_SHA256\"\n", + "c2-off-docker-kitchen-sink": "set -euo pipefail\n: \"${P6_ADMISSION_SHA256:?Set the SHA256 of this exact actual root admission}\"\npython3 -B - '/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/c2-off.json' \"$P6_ADMISSION_SHA256\" <<'P6_BIND'\nfrom pathlib import Path\nimport hashlib,sys\nassert hashlib.sha256(Path(sys.argv[1]).read_bytes()).hexdigest()==sys.argv[2]\nP6_BIND\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/runtime-controller.py\" --variant c2-off --phase docker-kitchen-sink --admission-sha256 \"$P6_ADMISSION_SHA256\"\n", + "c2-off-docker-cron": "set -euo pipefail\n: \"${P6_ADMISSION_SHA256:?Set the SHA256 of this exact actual root admission}\"\npython3 -B - '/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/c2-off.json' \"$P6_ADMISSION_SHA256\" <<'P6_BIND'\nfrom pathlib import Path\nimport hashlib,sys\nassert hashlib.sha256(Path(sys.argv[1]).read_bytes()).hexdigest()==sys.argv[2]\nP6_BIND\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/runtime-controller.py\" --variant c2-off --phase docker-cron --admission-sha256 \"$P6_ADMISSION_SHA256\"\n", + "c2-off-guest-security": "set -euo pipefail\n: \"${P6_ADMISSION_SHA256:?Set the SHA256 of this exact actual root admission}\"\npython3 -B - '/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/c2-off.json' \"$P6_ADMISSION_SHA256\" <<'P6_BIND'\nfrom pathlib import Path\nimport hashlib,sys\nassert hashlib.sha256(Path(sys.argv[1]).read_bytes()).hexdigest()==sys.argv[2]\nP6_BIND\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/runtime-controller.py\" --variant c2-off --phase guest-security --admission-sha256 \"$P6_ADMISSION_SHA256\"\n", + "ts-preflight": "set -euo pipefail\n: \"${P6_ADMISSION_SHA256:?Set the SHA256 of this exact actual root admission}\"\npython3 -B - '/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/ts.json' \"$P6_ADMISSION_SHA256\" <<'P6_BIND'\nfrom pathlib import Path\nimport hashlib,sys\nassert hashlib.sha256(Path(sys.argv[1]).read_bytes()).hexdigest()==sys.argv[2]\nP6_BIND\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/build-prep/build-linux.py\" --root \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1\" --admission \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/ts.json\" --measure-command \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/measure-command.py\"\n", + "ts-build": "set -euo pipefail\n: \"${P6_ADMISSION_SHA256:?Set the SHA256 of this exact actual root admission}\"\npython3 -B - '/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/ts.json' \"$P6_ADMISSION_SHA256\" <<'P6_BIND'\nfrom pathlib import Path\nimport hashlib,sys\nassert hashlib.sha256(Path(sys.argv[1]).read_bytes()).hexdigest()==sys.argv[2]\nP6_BIND\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/build-prep/build-linux.py\" --root \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1\" --admission \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/ts.json\" --measure-command \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/measure-command.py\" --run\n", + "ts-preserve": "set -euo pipefail\n: \"${P6_ADMISSION_SHA256:?Set the SHA256 of this exact actual root admission}\"\npython3 -B - '/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/ts.json' \"$P6_ADMISSION_SHA256\" <<'P6_BIND'\nfrom pathlib import Path\nimport hashlib,sys\nassert hashlib.sha256(Path(sys.argv[1]).read_bytes()).hexdigest()==sys.argv[2]\nP6_BIND\nenv -i HOME=/home/runner PATH=/usr/bin:/bin python3 -B - \"$P6_ADMISSION_SHA256\" <<'P6_PRESERVE'\nfrom pathlib import Path\nimport hashlib,json,subprocess,sys\nroot=Path('/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1');receipt=Path('/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/build-receipts/ts');admission=Path('/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/ts.json')\nassert hashlib.sha256(admission.read_bytes()).hexdigest()==sys.argv[1]\nplan=receipt/'plan.json';result=receipt/'result.json';p=json.loads(plan.read_text())\nassert p['admissionSha256']==sys.argv[1]\ncommand=[sys.executable,'-B',str(root/'preserve.py'),'pack','--plan',str(plan),'--plan-sha256',hashlib.sha256(plan.read_bytes()).hexdigest(),'--result',str(result),'--result-sha256',hashlib.sha256(result.read_bytes()).hexdigest(),'--checker',str(root/'build-prep/artifact-contract.mjs'),'--out',str(root/'preserved'/'ts')]\nsubprocess.run(command,check=True)\nP6_PRESERVE\n", + "ts-core": "set -euo pipefail\n: \"${P6_ADMISSION_SHA256:?Set the SHA256 of this exact actual root admission}\"\npython3 -B - '/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/ts.json' \"$P6_ADMISSION_SHA256\" <<'P6_BIND'\nfrom pathlib import Path\nimport hashlib,sys\nassert hashlib.sha256(Path(sys.argv[1]).read_bytes()).hexdigest()==sys.argv[2]\nP6_BIND\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/runtime-controller.py\" --variant ts --phase core --admission-sha256 \"$P6_ADMISSION_SHA256\"\n", + "ts-elf-floor": "set -euo pipefail\n: \"${P6_ADMISSION_SHA256:?Set the SHA256 of this exact actual root admission}\"\npython3 -B - '/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/ts.json' \"$P6_ADMISSION_SHA256\" <<'P6_BIND'\nfrom pathlib import Path\nimport hashlib,sys\nassert hashlib.sha256(Path(sys.argv[1]).read_bytes()).hexdigest()==sys.argv[2]\nP6_BIND\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/runtime-controller.py\" --variant ts --phase elf-floor --admission-sha256 \"$P6_ADMISSION_SHA256\"\n", + "ts-zero-js": "set -euo pipefail\n: \"${P6_ADMISSION_SHA256:?Set the SHA256 of this exact actual root admission}\"\npython3 -B - '/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/ts.json' \"$P6_ADMISSION_SHA256\" <<'P6_BIND'\nfrom pathlib import Path\nimport hashlib,sys\nassert hashlib.sha256(Path(sys.argv[1]).read_bytes()).hexdigest()==sys.argv[2]\nP6_BIND\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/runtime-controller.py\" --variant ts --phase zero-js --admission-sha256 \"$P6_ADMISSION_SHA256\"\n", + "ts-node-vm": "set -euo pipefail\n: \"${P6_ADMISSION_SHA256:?Set the SHA256 of this exact actual root admission}\"\npython3 -B - '/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/ts.json' \"$P6_ADMISSION_SHA256\" <<'P6_BIND'\nfrom pathlib import Path\nimport hashlib,sys\nassert hashlib.sha256(Path(sys.argv[1]).read_bytes()).hexdigest()==sys.argv[2]\nP6_BIND\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/runtime-controller.py\" --variant ts --phase node-vm --admission-sha256 \"$P6_ADMISSION_SHA256\"\n", + "ts-node-vm-native-workers": "set -euo pipefail\n: \"${P6_ADMISSION_SHA256:?Set the SHA256 of this exact actual root admission}\"\npython3 -B - '/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/ts.json' \"$P6_ADMISSION_SHA256\" <<'P6_BIND'\nfrom pathlib import Path\nimport hashlib,sys\nassert hashlib.sha256(Path(sys.argv[1]).read_bytes()).hexdigest()==sys.argv[2]\nP6_BIND\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/runtime-controller.py\" --variant ts --phase node-vm-native-workers --admission-sha256 \"$P6_ADMISSION_SHA256\"\n", + "ts-pty": "set -euo pipefail\n: \"${P6_ADMISSION_SHA256:?Set the SHA256 of this exact actual root admission}\"\npython3 -B - '/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/ts.json' \"$P6_ADMISSION_SHA256\" <<'P6_BIND'\nfrom pathlib import Path\nimport hashlib,sys\nassert hashlib.sha256(Path(sys.argv[1]).read_bytes()).hexdigest()==sys.argv[2]\nP6_BIND\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/runtime-controller.py\" --variant ts --phase pty --admission-sha256 \"$P6_ADMISSION_SHA256\"\n", + "ts-plugin": "set -euo pipefail\n: \"${P6_ADMISSION_SHA256:?Set the SHA256 of this exact actual root admission}\"\npython3 -B - '/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/ts.json' \"$P6_ADMISSION_SHA256\" <<'P6_BIND'\nfrom pathlib import Path\nimport hashlib,sys\nassert hashlib.sha256(Path(sys.argv[1]).read_bytes()).hexdigest()==sys.argv[2]\nP6_BIND\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/runtime-controller.py\" --variant ts --phase plugin --admission-sha256 \"$P6_ADMISSION_SHA256\"\n", + "ts-docker-image": "set -euo pipefail\n: \"${P6_ADMISSION_SHA256:?Set the SHA256 of this exact actual root admission}\"\npython3 -B - '/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/ts.json' \"$P6_ADMISSION_SHA256\" <<'P6_BIND'\nfrom pathlib import Path\nimport hashlib,sys\nassert hashlib.sha256(Path(sys.argv[1]).read_bytes()).hexdigest()==sys.argv[2]\nP6_BIND\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/runtime-controller.py\" --variant ts --phase docker-image --admission-sha256 \"$P6_ADMISSION_SHA256\"\n", + "ts-docker-gateway-network": "set -euo pipefail\n: \"${P6_ADMISSION_SHA256:?Set the SHA256 of this exact actual root admission}\"\npython3 -B - '/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/ts.json' \"$P6_ADMISSION_SHA256\" <<'P6_BIND'\nfrom pathlib import Path\nimport hashlib,sys\nassert hashlib.sha256(Path(sys.argv[1]).read_bytes()).hexdigest()==sys.argv[2]\nP6_BIND\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/runtime-controller.py\" --variant ts --phase docker-gateway-network --admission-sha256 \"$P6_ADMISSION_SHA256\"\n", + "ts-docker-kitchen-sink": "set -euo pipefail\n: \"${P6_ADMISSION_SHA256:?Set the SHA256 of this exact actual root admission}\"\npython3 -B - '/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/ts.json' \"$P6_ADMISSION_SHA256\" <<'P6_BIND'\nfrom pathlib import Path\nimport hashlib,sys\nassert hashlib.sha256(Path(sys.argv[1]).read_bytes()).hexdigest()==sys.argv[2]\nP6_BIND\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/runtime-controller.py\" --variant ts --phase docker-kitchen-sink --admission-sha256 \"$P6_ADMISSION_SHA256\"\n", + "ts-docker-cron": "set -euo pipefail\n: \"${P6_ADMISSION_SHA256:?Set the SHA256 of this exact actual root admission}\"\npython3 -B - '/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/ts.json' \"$P6_ADMISSION_SHA256\" <<'P6_BIND'\nfrom pathlib import Path\nimport hashlib,sys\nassert hashlib.sha256(Path(sys.argv[1]).read_bytes()).hexdigest()==sys.argv[2]\nP6_BIND\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/runtime-controller.py\" --variant ts --phase docker-cron --admission-sha256 \"$P6_ADMISSION_SHA256\"\n", + "ts-guest-security": "set -euo pipefail\n: \"${P6_ADMISSION_SHA256:?Set the SHA256 of this exact actual root admission}\"\npython3 -B - '/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/ts.json' \"$P6_ADMISSION_SHA256\" <<'P6_BIND'\nfrom pathlib import Path\nimport hashlib,sys\nassert hashlib.sha256(Path(sys.argv[1]).read_bytes()).hexdigest()==sys.argv[2]\nP6_BIND\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/runtime-controller.py\" --variant ts --phase guest-security --admission-sha256 \"$P6_ADMISSION_SHA256\"\n", + "guest-prerequisites": "set -euo pipefail\n: \"${P6_ADMISSION_SHA256:?Set the SHA256 of this exact actual root admission}\"\npython3 -B - '/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admissions/js.json' \"$P6_ADMISSION_SHA256\" <<'P6_BIND'\nfrom pathlib import Path\nimport hashlib,sys\nassert hashlib.sha256(Path(sys.argv[1]).read_bytes()).hexdigest()==sys.argv[2]\nP6_BIND\nenv -i HOME=/home/runner PATH=/usr/bin:/bin TMPDIR=\"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/tmp\" PYTHONDONTWRITEBYTECODE=1 python3 -B \"/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/runtime-controller.py\" --variant js --phase guest-prerequisites --admission-sha256 \"$P6_ADMISSION_SHA256\"\n" +} diff --git a/scripts/openclaw-p6/app/packet/input-projection.json b/scripts/openclaw-p6/app/packet/input-projection.json new file mode 100644 index 000000000000..72562fda0877 --- /dev/null +++ b/scripts/openclaw-p6/app/packet/input-projection.json @@ -0,0 +1,183 @@ +{ + "schemaVersion": 1, + "originalCapsuleSha256": "879c8909d02159882757675affbba14587c45b783bb480fd2fd73925c63372ec", + "projectionReason": "P6 public CB11 provenance projection with exact R4 source/tree/proof/path binding. Original capsule provenance and the reviewed Gateway shutdown repair are preserved.", + "changedFiles": { + "admission-inputs/P0-artifacts.json": { + "originalSha256": "6ceb952c8c527152d3fb534e203985b493c7c94e3729f27b65d36a925c755ab2", + "projectedSha256": "f60309fc44e418cfaf02df998ada40cfab89c10f773df0c09eb512775d0d8e83" + }, + "admission-inputs/p0-reference.json": { + "originalSha256": "09b61d429272bd580e4ed064260d431e7a864743e4afefebbf18bd6d0eceab99", + "projectedSha256": "1603c0262605fcb488ecbbd07a163b9afb5487456aca01b6574aaa6bac9296c9" + }, + "admission-inputs/source-preparation.json": { + "originalSha256": "60fcbaa4d97242d8ed3f0b970f7a14e9be46356d1d1ee588e75bc73bbe01d0de", + "projectedSha256": "dd8492221cf6bce907a90b392a24289a3c8e6f1e655e47dba174d51ccd0710e9" + }, + "admission-templates/c2-off.json": { + "originalSha256": "1f02cb47781a9e689fb7a3074945fca3a36bf05c064e5bac0047ebc2d49a57d2", + "projectedSha256": "8c3ad5cf6d473092c3ee0145afcae576b52288e822cb3e6485e429293b0bf7a3" + }, + "admission-templates/js.json": { + "originalSha256": "dcc439c33249b208d1f522f026fa21ecc8fa7aed7142c0f7991e3a9682c604f8", + "projectedSha256": "8ffbfe9f0bab1a910a8e40e0eb71037db32ed242bd00f12932020e6ef1d4d120" + }, + "admission-templates/ts.json": { + "originalSha256": "e73da6e668f071517b392cd56bf22cb32c0fbc2b2da61bfb9525357330752e93", + "projectedSha256": "f6fcd850b680c5f9b81ac77763afbba5dc67c6ff092b610a3623197faa2c25db" + }, + "adopt-compilers.py": { + "originalSha256": "e12f117f417d1bb108b5d4719f5e471ad75b2adba78a425e0dd9a2a0c697d2cf", + "projectedSha256": "97585382c7ee80321fd26595220120b2d42f855575059d283b4c58cb93362a27" + }, + "cron-fixture/inputs.json": { + "originalSha256": "0971140eb17775d974eb509693c864a9e954d5e7a5fc0946bff7852e43785ff6", + "projectedSha256": "fd559a9b5f566b19e155427ec267e512a5d7ed5cfd7b0ef89b460711b9017b36" + }, + "cron-fixture/run-native.sh": { + "originalSha256": "b07d4dac039fc0099a1697814b31cbf2ec32e56a2e2183aaef87be0a3b02ac46", + "projectedSha256": "e7201d5ec00c6759fa937eeb557ca7c20ae4e309a2b05d4d4dd105a9fcc28308" + }, + "guest/manifest.json": { + "originalSha256": "4280c2f62a9168b812176bab9fb762432a5425fe29821a1720471d2ece242d12", + "projectedSha256": "7c731171b9247059a043c2360224d6e92642f041372c3f706fac55cb7d9319ee" + }, + "guest/prepare-guest.py": { + "originalSha256": "936bf471c1c6e06ac2bb1ec1efec0e8e0c4583853e8fcb0ff1a53fb42cfacd52", + "projectedSha256": "1737d66cda6ef635973bd5ddcffdd43c19357f5c4687d9d6bf90a4ffe248babf" + }, + "native-prep.py": { + "originalSha256": "8bfd331144ad876405e73f317e839b35cfc7647288f9fb2c34f95dab86f66e91", + "projectedSha256": "5c6932de85c113f7b7d5b2a25780dc0cf103bd92352be084fb64561075bebf06" + }, + "preserve.py": { + "originalSha256": "5851e29c0832b017f7e7a98b0f64e51b4951f451574f49a6d9632f0a57b08d34", + "projectedSha256": "c6d78862f9921af842c0eec4eb3e9a2850426847859bf503ff08112c95b95456" + }, + "qualification/README.md": { + "originalSha256": "cbf5adaed9ff418fa5d0092994cf05166efe215cf56a153c8dcff17d3f1e9fbb", + "projectedSha256": "8e2eefd1160e26d374cb3cf6c0328cd73d92953fab1ae7d119d3c920cdb2ec33" + }, + "qualification/manifest.json": { + "originalSha256": "6a38454878806509950a1ea7fb9a15ffb2bb79b53f4ef586bee131474a3e9221", + "projectedSha256": "d6df4521dfc2cabda9cbda41fce4dc4882606fc0ed8be8438828af16beedeea4" + }, + "qualification/qualify.py": { + "originalSha256": "c32886e391f27eb8c66d333d07b15b4af4c8081c329bad2fe8dca28b2dd9c2d7", + "projectedSha256": "f20cbd54444d1cbf673bec08722fd04f982db6db0797522ced529cc9e9bf4ff5" + }, + "qualification/source-contract.json": { + "originalSha256": "e2056668fd189ba8505c75fbef695c535930600e08d6e8d7bb0df55f9cf13d2b", + "projectedSha256": "c1cffbee88de6e49601c68e753a0456e938a1ed2fc503640d43c7f942fea838b" + }, + "runtime-controller.py": { + "originalSha256": "d0974f26f8432bc3fe5c59afb640105ce53dc0d268d8f85fe0598d363ff5d7d9", + "projectedSha256": "659dac44a521dffa8111001b4684d02374b996b5e29330f01c00d3cae92ee0d7" + }, + "stage.py": { + "originalSha256": "d40bdf22aeae208f1165a0d74ee0b87eb7e93e9144a5092212211633b59124d3", + "projectedSha256": "29ad1ad089f28720ff1ac2c3036c5153b873856698ecb18122411a0c0d0db277" + } + }, + "manifestSha256": "9f80a1edc2678c7a9f2fd1c2ff1ff8462d45717203a1d5909153c9c5a8b081cf", + "runtimeControllerRepair": { + "terminalClassification": "Actual SIGTERM fixture child exit -15 formerly normalized to 1; retain timeout, cancellation and signal classification after cleanup", + "guestQmpPath": "Generated C2 guest label shortened consistently for preparation and raw collection, reducing Linux QMP pathname from108 to98bytes" + }, + "sourceRebind": { + "fromSource": "59baf4a051665750eb7055d0cec991d9876526df", + "sourceCommit": "4fa442e332745f1f58ccedd27106abdafcf4e019", + "sourceTree": "5409457bc1b8a901b00193469a3c2b7a74dc2f30", + "frozenAt": "2026-10-25T22:30:39.990290+00:00", + "rootProofSha256": "69a1a26a7c138ccb26fc03671949edf27b89c126036ce53f0fabc69bb16cfee5", + "requiredAncestors": 29, + "nativeRoot": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1", + "compilerPairChanged": false, + "materialChanges": [ + "typed resolver expression unwrapping PR183822 merged792b7d58", + "latest main runtime changes including perf(state)183890; all native preparation and runtime proof fresh", + "P0 CB11 signed/qualified C2 reference remains distinct from Linux150c/aaa" + ], + "currentC2QmpPathBytes": 96 + }, + "pnpmLauncherRepair": { + "cause": "Official pnpm archive exposes a shebang-less native placeholder until its installation script replaces it; Python exec does not provide shell fallback.", + "repair": "Install a task-local executable command shim that execs the pinned Node and official pnpm.mjs with forwarded arguments.", + "unchanged": "Official archive SHA512 pin, signed native downloader, native Linux x64 ELF check, source and compiler pins." + }, + "gatewayShutdownRepair": { + "baseHead": "f9634d8a2da46bd990913c7b07b51d40ed11db12", + "helperOwner": "shared/process-stop.mjs", + "helperSha256": "68c2e651f829a424a7fc2c2b7d44a05caa23bc2c4f6a047296ca5529f3afdaec", + "sourceBudgetOwner": "gateway-shutdown-budget.mjs", + "sourceBudgetSha256": "02757141fd71a0e03ee885d952edbcd664395a420b26c6b7ba596529336baa3a", + "scope": "Gateway source budget, explicit forced-stop failure and runtime-only outer cleanup grace; operation/default budgets retained" + }, + "fetchedTeamsFollowOn": { + "baseHead": "a61fc72a57672fafe87fc1bda9a8e231a5f98bc7", + "sourceCommit": "4fa442e332745f1f58ccedd27106abdafcf4e019", + "acceptedArmManifestSha256": "245a99b44189822443da485006ffa65f599c9edcc93c73f4f2120319b628455f", + "acceptedArmAcceptanceSha256": "8c3d796d709e7da0b74900e2117ec912240cc2b4f9709d581b2fb5ed1b897f11", + "rootSourceProofSha256": "69a1a26a7c138ccb26fc03671949edf27b89c126036ce53f0fabc69bb16cfee5", + "unchangedFixtureFiles": { + "assert-teams.py": "47b32e68002abdf7649a098c4783603f30eb53f43118fb425485e5e6c5976ed4", + "config.template.json": "6eb88933badf9e833be2c47bebb0a0667f441efdb6ae3862819be5dffca0cc6e" + }, + "runtimeFactsBound": false, + "executionAuthorized": false, + "defaultScheduleChanged": false, + "performanceEligible": false, + "pinProjection": { + "originalSha256": "f7225212c61579fe184ec455d733474ceee0734d17cf4e2c4516225c49fb182f", + "projectedSha256": "4c9c165d8367dc62df059d84cceef38d40c933c8207793a5d5d41791166eeb59", + "omittedFields": [ + "historicalP0Lock.path" + ], + "reason": "Public artifact omits the historical operator path; package/version/tarball/integrity/dependency fields are unchanged." + } + }, + "untimedRequalification": { + "baseHead": "a61d838fd9404a211d7a179eabae2509f962c01d", + "sourceCommit": "4fa442e332745f1f58ccedd27106abdafcf4e019", + "buildsApplication": false, + "buildsCompiler": false, + "phases": [ + "node-vm-native-workers", + "docker-image", + "docker-gateway-network", + "docker-kitchen-sink" + ], + "variants": [ + "js", + "c2-off" + ], + "ordinaryFailure": "retained; comparator allowed only after owned-child cleanup, existing reconciliation, quiet and fresh core gates; live-child forced recovery prevents requalification and scheduled completion", + "terminalFailure": "stops work", + "gitPrerequisite": { + "version": "2.56.0", + "url": "https://www.kernel.org/pub/software/scm/git/git-2.56.0.tar.xz", + "sha256": "26c56c296b38c0695b26fa95f475f1d01704d2d38e73465ca30b0b2f5dc789d3" + }, + "assertionOverlay": { + "source": "scripts/e2e/lib/clawhub-artifact-assertions.mjs", + "sourceSha256": "53bcdc520648dd5951e63ae7a88d553eba9a7c18454d88757520b10b3986c728", + "overlay": "qualification/harness/clawhub-artifact-assertions.mjs", + "overlaySha256": "ebbafe3f5d0c09c5b21a7669d5dc64b02ece869af257faab775effb06d058197", + "environment": "OPENCLAW_E2E_HOST_ROOT", + "expectedHostRoot": "/opt/p6-artifact/runtime" + }, + "nativeWorkerRepair": { + "sourcePatchSha256": "aeb38a730a20c166e1febd004af1dd4b010ef98b420f057c8ab1ab715cf5ef5e", + "environmentOwner": "qualification/harness/legacy/native_trace.py", + "ordinaryLaunchChanged": false + } + }, + "guestInvocationSelectionRepair": { + "baseHead": "a61d838fd9404a211d7a179eabae2509f962c01d", + "scope": "Select exact admitted --version or p6-mdwe argv while retaining same-binary SQLite child/version evidence and all existing policy checks.", + "newRuntimeExecuted": false, + "sourcePatchSha256": "99637a9ca74f83911738049d91bd82fd12f2f7474ca257cbf20317f8f33a9e20", + "handoffSha256": "a614c23fe089aeb00d7521549672ecd6377acad7b77ae7798df4e37a49de9780" + } +} diff --git a/scripts/openclaw-p6/app/packet/payload/admission-inputs/P0-artifacts.json b/scripts/openclaw-p6/app/packet/payload/admission-inputs/P0-artifacts.json new file mode 100644 index 000000000000..53fc1bd6dcd8 --- /dev/null +++ b/scripts/openclaw-p6/app/packet/payload/admission-inputs/P0-artifacts.json @@ -0,0 +1,26 @@ +{ + "schemaVersion": 1, + "lane": "P0", + "referenceRole": "historical-provenance-only", + "artifacts": [ + { + "variant": "desktop-c2", + "mainSha": "d465bda8766e9031f14bd266458e4bb09ac37ff2", + "sourceCommit": "58c12b7787c3852c32667329f506750a8ed63994", + "sourceStatus": "main-plus-open-pr", + "pr": "https://github.com/openclaw/openclaw/pull/183771", + "platform": "darwin", + "arch": "arm64", + "sha256": "877d86b206343b485d615e488e7b88802181a3c7f56bc1bd4dcdc91cb210638b", + "signed": true, + "qualified": true, + "compilerPins": { + "bun": "b838e73072227c2652a41c689299284f1965cdc6", + "webkit": "aaa690bfbf34c9d50775716ac2fc3c7d0573e0b8", + "shadowRealm": "retained", + "historicalC2Equivalent": false + } + } + ], + "projection": "P6-derived public projection of the selected CB11 record; not a byte-identical P0 index clone" +} diff --git a/scripts/openclaw-p6/app/packet/payload/admission-inputs/p0-reference.json b/scripts/openclaw-p6/app/packet/payload/admission-inputs/p0-reference.json new file mode 100644 index 000000000000..642dcde59533 --- /dev/null +++ b/scripts/openclaw-p6/app/packet/payload/admission-inputs/p0-reference.json @@ -0,0 +1,9 @@ +{ + "referenceRole": "historical-provenance-only", + "sourceManifestSha256": "7b909d75df066586f83ebbc9bfe78d9fcd17905b54688db1b1ed76dfa5cfc740", + "projectedManifestSha256": "f60309fc44e418cfaf02df998ada40cfab89c10f773df0c09eb512775d0d8e83", + "executableSha256": "877d86b206343b485d615e488e7b88802181a3c7f56bc1bd4dcdc91cb210638b", + "sourceCommit": "58c12b7787c3852c32667329f506750a8ed63994", + "originalModified": false, + "executed": false +} diff --git a/scripts/openclaw-p6/app/packet/payload/admission-inputs/source-preparation.json b/scripts/openclaw-p6/app/packet/payload/admission-inputs/source-preparation.json new file mode 100644 index 000000000000..5aab876f0c87 --- /dev/null +++ b/scripts/openclaw-p6/app/packet/payload/admission-inputs/source-preparation.json @@ -0,0 +1,77 @@ +{ + "sourceCommit": "4fa442e332745f1f58ccedd27106abdafcf4e019", + "sourceTree": "5409457bc1b8a901b00193469a3c2b7a74dc2f30", + "linuxCut": { + "status": "landed-main", + "commit": "4fa442e332745f1f58ccedd27106abdafcf4e019", + "requiredAncestors": [ + "c36710ec04ba17c98a6d3ba59d68fcb124df8e49", + "a171cfb74891e3abce0fb8312e976323998b3654", + "4dfd92bbda37dd05db97d93d773b342245c632be", + "fe0be1ae7477634479885e788d1e0b058f84905f", + "2f3ab195038294f9b3ffb96f4f381752e580cdb4", + "d11b06c8e815cfb5dbb62e7663a89086c4b567c0", + "a355200eef8abe8504f1e83dadc5de4717d59d9c", + "2678ee8e0e04d4721a4fe74ffb0c3ad0c70e2c2d", + "25a70e7d1f0cdf4af26ea3fd54d4ba82801957f9", + "44dd89b76ce56ef532bb6868b5d39c0dbbed7714", + "1bb18fd0aa5163d348df3398a8c8acaf5efc9019", + "c887adba97b6ee6a9c7817564c69cad31f976ca1", + "2f95e977c77d74ba463cdfee9436da1004778fcc", + "bc22cdba591eac1698f7577db0c8966d950417e4", + "f7397050bdf9959d834e92eb3a8f6c243f9b61f9", + "60c3a7c35283dd6377baff1e6ab137d1e0e96c0d", + "3e579ec1ea51bce7b98cec4ea910a84f08e06c29", + "3963fb319b08ba71d26baf6f16f37d17c283b855", + "90d689c000053b46dd9ca4e24009a0e8a16fbb24", + "83fb19513e8d3013a27db742a0610230070bc8df", + "aff4d23ad1e471155921c75732417bd63984a753", + "e6a0dc9b0d20a4649807c920cb58d27fcc559743", + "ed818c4b396c1e8dd363b65d74c5f8f844b5310a", + "ded76f196cc2a64111ecf8fd24dcd306d9c445e5", + "247b73c9bdc34dd723533f50d56fc345ef624d9a", + "d465bda8766e9031f14bd266458e4bb09ac37ff2", + "a4cfee8af58ac2fc43ea5497db4bf02b98cc46dc", + "59baf4a051665750eb7055d0cec991d9876526df", + "792b7d58c384eaa16c6caf28770fbc3064cf642b" + ], + "typedResolverMergeCommit": "792b7d58c384eaa16c6caf28770fbc3064cf642b", + "mainRef": "refs/remotes/origin/main", + "mainRefSha": "4fa442e332745f1f58ccedd27106abdafcf4e019", + "frozenAt": "2026-10-25T22:30:39.990290+00:00", + "p0DifferenceRationale": "Latest fetched landed main4fa includes merged typed resolver fix183822 and all prior29 repairs. Linux keeps native150c/aaa compiler profiles; P0 CB11 C2 is distinct58c/b838 signed reference. Fresh preparation and runtime required for1270changed paths sinceR3." + }, + "files": { + "extensions/acpx/package.json": "5e1e7275d8b79dd5e02d2eaaa1176e00abbb79b03f681d944056f0124e10b0ec", + "extensions/knowledge/package.json": "55e6d3f1a68f4596bf38cfd42409bdeecb5da38e2037f67c40ff76182065b767", + "extensions/knowledge/src/ingestion-contract.ts": "fc7ca97a164cf12cf7228fce71216b81e20a5216a90b2e6ec931810105e81646", + "extensions/knowledge/src/memory-index.ts": "e4f8747ff4abe79f2a985d176364ebae8e719001c454798f9ef464fd72c2d303", + "extensions/knowledge/src/plugin-files.ts": "419b45911df50cadd734a9033843aa32f1f9db436e23f277dae29526d50e6000", + "extensions/knowledge/src/registry-client.ts": "fc6bac80b6e4546b896ae070eba1e3186da76cc8b7c7e23667e3683bab5404e1", + "extensions/knowledge/src/registry-worker.ts": "f6385d8614965f02f28bbed21a2712dd626ad4d832cc1758714af67ac1d4d4be", + "extensions/knowledge/src/search-detail.ts": "bc871acfdb1aefff0f166cbe0433d7e11b7a0ce6508ea9ad990c3f47bd8aad5e", + "extensions/knowledge/src/storage-client.ts": "940ebeea8a662c63a268f5e503841acbe56a10afb55a47629d6bcb6fd47b44e8", + "extensions/knowledge/src/storage-worker.ts": "b72ff1dd8cafc24b78e228edb895d1abbf3f3002450c84afbcdcb8e48cbe2fdf", + "extensions/knowledge/src/worker-sdk-resolver.ts": "f5de90ba11e4ce29ee25343f8762175c3151370790e4d939f875474bc22f061b", + "package.json": "afe1412c6470a96cb9ae33d4b79a4584f69c19de3afc9556958fb9cbf1fc2ad8", + "pnpm-lock.yaml": "6711dcbef4e6504260a6cd0ba5dfe09f91d49b1414bd64f48e2dab55759c2aba", + "pnpm-workspace.yaml": "331a1990bfba6a4bf33c982fbf3e47477a1f3a3d2bc8d3c83e919b9c9d1717f9", + "runtime-process-scripts.generated.mjs": "c860dee676744f09b94c24615a5a5de4abafd5ac9fcd3588ff490f20c0e04264", + "scripts/build-all.mts": "797dd94f6c44263cb0106b583871b2680c27a5de81d586134e225e152ccb63d3", + "scripts/build-bun-standalone.mjs": "a32d46f7dd6e978834540ba1ca5d173afdd12d5df02acda7779c50b53119e0f0", + "scripts/lib/bun-standalone-bundle.mjs": "27d468a91b78819e68b2be08d1a4ec2b0c6ce985a45ac3e08d6f722d7af4afdc", + "scripts/lib/bun-standalone-contract.mjs": "7fadadc2f96e948cc2e18865e5df2bb6e5a334348ea913165485e9eaaf263b7c", + "scripts/lib/bun-standalone-native.mjs": "f9a1f75d68afe4173ac134f770677fa3ade21f33f2cba7dcf30748a358d3db00", + "scripts/lib/bun-standalone-plugins.mjs": "dc7a90471099b9ee73f5fdba02cd4c09ff92c8f5866120d6e3c526a18d9cc717", + "scripts/lib/bun-standalone-source-parser.mjs": "ff6e6d31b0e6f32dcbd1bf0dbdcc3ca1ea8b032a88f0f210c373967560dfeb4e", + "scripts/prepare-extension-package-boundary-artifacts.mts": "aa86566a4b5446bff6a3cf61dde414c7499cab87db535acd0d53c8fac976c04f", + "scripts/tsx.mjs": "e726c78d5a5a274215d9fe292ac91e4acf601c4554d68fbd57ff3b932573f9e6", + "src/cli/security-cli.ts": "18a37df7b3eb2ccdb7bfb55b63aecd9f1cef739f8b5fac16b0f266bd12fe23e1", + "src/commands/backup-record.ts": "6b7b088fc997cd31fa0178c2bb1b67622ea9e5e9169190a65637b93ae5265810", + "src/config/sessions/session-transcript-worker-readers.ts": "c8baed3ee4957099240bfd7014beb6c57de724d9270e43e6ba3c2653dbe1430a", + "src/plugins/plugin-state-operation-source.ts": "61f39fc6b9c289d7cf96a03d87c1b20230f81ea65b0bf4e9287d72faff29319f", + "scripts/lib/bun-standalone-imports.mjs": "8033969ca474dce851df256dce73845315b17ca99e887930e5459f2149117782", + "test/scripts/bun-standalone-imports.test.ts": "8b5f6b48dc8acb4a25e79564ad233eb0c66865006db1996e0115792d0b2991a7", + "docs/install/standalone.md": "6d9ddff15e12622d299c789e23025d9aeccbdf025e895b5885276d65e5f9c2c7" + } +} diff --git a/scripts/openclaw-p6/app/packet/payload/admission-templates/c2-off.json b/scripts/openclaw-p6/app/packet/payload/admission-templates/c2-off.json new file mode 100644 index 000000000000..ef1d896061e4 --- /dev/null +++ b/scripts/openclaw-p6/app/packet/payload/admission-templates/c2-off.json @@ -0,0 +1,80 @@ +{ + "schemaVersion": 1, + "lane": "P6", + "decision": "prepared-not-admitted", + "variant": "c2", + "source": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/source", + "output": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/artifacts/c2-off", + "receiptDirectory": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/build-receipts/c2-off", + "linuxCut": { + "status": "landed-main", + "commit": "4fa442e332745f1f58ccedd27106abdafcf4e019", + "requiredAncestors": [ + "c36710ec04ba17c98a6d3ba59d68fcb124df8e49", + "a171cfb74891e3abce0fb8312e976323998b3654", + "4dfd92bbda37dd05db97d93d773b342245c632be", + "fe0be1ae7477634479885e788d1e0b058f84905f", + "2f3ab195038294f9b3ffb96f4f381752e580cdb4", + "d11b06c8e815cfb5dbb62e7663a89086c4b567c0", + "a355200eef8abe8504f1e83dadc5de4717d59d9c", + "2678ee8e0e04d4721a4fe74ffb0c3ad0c70e2c2d", + "25a70e7d1f0cdf4af26ea3fd54d4ba82801957f9", + "44dd89b76ce56ef532bb6868b5d39c0dbbed7714", + "1bb18fd0aa5163d348df3398a8c8acaf5efc9019", + "c887adba97b6ee6a9c7817564c69cad31f976ca1", + "2f95e977c77d74ba463cdfee9436da1004778fcc", + "bc22cdba591eac1698f7577db0c8966d950417e4", + "f7397050bdf9959d834e92eb3a8f6c243f9b61f9", + "60c3a7c35283dd6377baff1e6ab137d1e0e96c0d", + "3e579ec1ea51bce7b98cec4ea910a84f08e06c29", + "3963fb319b08ba71d26baf6f16f37d17c283b855", + "90d689c000053b46dd9ca4e24009a0e8a16fbb24", + "83fb19513e8d3013a27db742a0610230070bc8df", + "aff4d23ad1e471155921c75732417bd63984a753", + "e6a0dc9b0d20a4649807c920cb58d27fcc559743", + "ed818c4b396c1e8dd363b65d74c5f8f844b5310a", + "ded76f196cc2a64111ecf8fd24dcd306d9c445e5", + "247b73c9bdc34dd723533f50d56fc345ef624d9a", + "d465bda8766e9031f14bd266458e4bb09ac37ff2", + "a4cfee8af58ac2fc43ea5497db4bf02b98cc46dc", + "59baf4a051665750eb7055d0cec991d9876526df", + "792b7d58c384eaa16c6caf28770fbc3064cf642b" + ], + "typedResolverMergeCommit": "792b7d58c384eaa16c6caf28770fbc3064cf642b", + "mainRef": "refs/remotes/origin/main", + "mainRefSha": "PENDING_ACTUAL_NATIVE_CLONE_MAIN_SHA", + "frozenAt": "2026-10-25T22:30:39.990290+00:00", + "p0DifferenceRationale": "Latest fetched landed main4fa includes merged typed resolver fix183822 and all prior29 repairs. Linux keeps native150c/aaa compiler profiles; P0 CB11 C2 is distinct58c/b838 signed reference. Fresh preparation and runtime required for1270changed paths sinceR3." + }, + "distBuildInfoSha256": "PENDING_ACTUAL_NATIVE_DIST_SHA256", + "p0Reference": { + "cohort": "cb-b838", + "manifest": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admission-inputs/P0-artifacts.json", + "manifestSha256": "f60309fc44e418cfaf02df998ada40cfab89c10f773df0c09eb512775d0d8e83", + "variant": "desktop-c2", + "sourceCommit": "58c12b7787c3852c32667329f506750a8ed63994", + "executableSha256": "877d86b206343b485d615e488e7b88802181a3c7f56bc1bd4dcdc91cb210638b" + }, + "compiler": { + "cohort": "rd-p6-150c", + "profile": "cb-compat", + "path": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/compilers/sr-off/bun", + "sha256": "PENDING_ACTUAL_PRESERVED_NATIVE_COMPILER_SHA256", + "bunCommit": "150c9620c53710060186b8b0cd50985e035408b0", + "webkitCommit": "aaa690bfbf34c9d50775716ac2fc3c7d0573e0b8", + "engineFeatures": { + "shadowRealm": false, + "hardened": false + } + }, + "buildNode": { + "path": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/opt/node/bin/node", + "sha256": "PENDING_ACTUAL_NATIVE_NODE_SHA256" + }, + "pluginsFile": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admission-inputs/plugins/desktop.json", + "pluginsSha256": "PENDING_ACTUAL_NATIVE_PLUGIN_SELECTION_SHA256", + "compileTrimAllow": [ + "run" + ], + "timeoutSeconds": "PENDING_ROOT_BOUNDED_TIMEOUT_SECONDS" +} diff --git a/scripts/openclaw-p6/app/packet/payload/admission-templates/js.json b/scripts/openclaw-p6/app/packet/payload/admission-templates/js.json new file mode 100644 index 000000000000..496fed8a4050 --- /dev/null +++ b/scripts/openclaw-p6/app/packet/payload/admission-templates/js.json @@ -0,0 +1,80 @@ +{ + "schemaVersion": 1, + "lane": "P6", + "decision": "prepared-not-admitted", + "variant": "js", + "source": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/source", + "output": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/artifacts/js", + "receiptDirectory": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/build-receipts/js", + "linuxCut": { + "status": "landed-main", + "commit": "4fa442e332745f1f58ccedd27106abdafcf4e019", + "requiredAncestors": [ + "c36710ec04ba17c98a6d3ba59d68fcb124df8e49", + "a171cfb74891e3abce0fb8312e976323998b3654", + "4dfd92bbda37dd05db97d93d773b342245c632be", + "fe0be1ae7477634479885e788d1e0b058f84905f", + "2f3ab195038294f9b3ffb96f4f381752e580cdb4", + "d11b06c8e815cfb5dbb62e7663a89086c4b567c0", + "a355200eef8abe8504f1e83dadc5de4717d59d9c", + "2678ee8e0e04d4721a4fe74ffb0c3ad0c70e2c2d", + "25a70e7d1f0cdf4af26ea3fd54d4ba82801957f9", + "44dd89b76ce56ef532bb6868b5d39c0dbbed7714", + "1bb18fd0aa5163d348df3398a8c8acaf5efc9019", + "c887adba97b6ee6a9c7817564c69cad31f976ca1", + "2f95e977c77d74ba463cdfee9436da1004778fcc", + "bc22cdba591eac1698f7577db0c8966d950417e4", + "f7397050bdf9959d834e92eb3a8f6c243f9b61f9", + "60c3a7c35283dd6377baff1e6ab137d1e0e96c0d", + "3e579ec1ea51bce7b98cec4ea910a84f08e06c29", + "3963fb319b08ba71d26baf6f16f37d17c283b855", + "90d689c000053b46dd9ca4e24009a0e8a16fbb24", + "83fb19513e8d3013a27db742a0610230070bc8df", + "aff4d23ad1e471155921c75732417bd63984a753", + "e6a0dc9b0d20a4649807c920cb58d27fcc559743", + "ed818c4b396c1e8dd363b65d74c5f8f844b5310a", + "ded76f196cc2a64111ecf8fd24dcd306d9c445e5", + "247b73c9bdc34dd723533f50d56fc345ef624d9a", + "d465bda8766e9031f14bd266458e4bb09ac37ff2", + "a4cfee8af58ac2fc43ea5497db4bf02b98cc46dc", + "59baf4a051665750eb7055d0cec991d9876526df", + "792b7d58c384eaa16c6caf28770fbc3064cf642b" + ], + "typedResolverMergeCommit": "792b7d58c384eaa16c6caf28770fbc3064cf642b", + "mainRef": "refs/remotes/origin/main", + "mainRefSha": "PENDING_ACTUAL_NATIVE_CLONE_MAIN_SHA", + "frozenAt": "2026-10-25T22:30:39.990290+00:00", + "p0DifferenceRationale": "Latest fetched landed main4fa includes merged typed resolver fix183822 and all prior29 repairs. Linux keeps native150c/aaa compiler profiles; P0 CB11 C2 is distinct58c/b838 signed reference. Fresh preparation and runtime required for1270changed paths sinceR3." + }, + "distBuildInfoSha256": "PENDING_ACTUAL_NATIVE_DIST_SHA256", + "p0Reference": { + "cohort": "cb-b838", + "manifest": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admission-inputs/P0-artifacts.json", + "manifestSha256": "f60309fc44e418cfaf02df998ada40cfab89c10f773df0c09eb512775d0d8e83", + "variant": "desktop-c2", + "sourceCommit": "58c12b7787c3852c32667329f506750a8ed63994", + "executableSha256": "877d86b206343b485d615e488e7b88802181a3c7f56bc1bd4dcdc91cb210638b" + }, + "compiler": { + "cohort": "rd-p6-150c", + "profile": "cb-standard", + "path": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/compilers/standard/bun", + "sha256": "PENDING_ACTUAL_PRESERVED_NATIVE_COMPILER_SHA256", + "bunCommit": "150c9620c53710060186b8b0cd50985e035408b0", + "webkitCommit": "aaa690bfbf34c9d50775716ac2fc3c7d0573e0b8", + "engineFeatures": { + "shadowRealm": true, + "hardened": false + } + }, + "buildNode": { + "path": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/opt/node/bin/node", + "sha256": "PENDING_ACTUAL_NATIVE_NODE_SHA256" + }, + "pluginsFile": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admission-inputs/plugins/desktop.json", + "pluginsSha256": "PENDING_ACTUAL_NATIVE_PLUGIN_SELECTION_SHA256", + "compileTrimAllow": [ + "run" + ], + "timeoutSeconds": "PENDING_ROOT_BOUNDED_TIMEOUT_SECONDS" +} diff --git a/scripts/openclaw-p6/app/packet/payload/admission-templates/ts.json b/scripts/openclaw-p6/app/packet/payload/admission-templates/ts.json new file mode 100644 index 000000000000..65b4ec06a6f2 --- /dev/null +++ b/scripts/openclaw-p6/app/packet/payload/admission-templates/ts.json @@ -0,0 +1,80 @@ +{ + "schemaVersion": 1, + "lane": "P6", + "decision": "prepared-not-admitted", + "variant": "ts", + "source": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/source", + "output": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/artifacts/ts", + "receiptDirectory": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/build-receipts/ts", + "linuxCut": { + "status": "landed-main", + "commit": "4fa442e332745f1f58ccedd27106abdafcf4e019", + "requiredAncestors": [ + "c36710ec04ba17c98a6d3ba59d68fcb124df8e49", + "a171cfb74891e3abce0fb8312e976323998b3654", + "4dfd92bbda37dd05db97d93d773b342245c632be", + "fe0be1ae7477634479885e788d1e0b058f84905f", + "2f3ab195038294f9b3ffb96f4f381752e580cdb4", + "d11b06c8e815cfb5dbb62e7663a89086c4b567c0", + "a355200eef8abe8504f1e83dadc5de4717d59d9c", + "2678ee8e0e04d4721a4fe74ffb0c3ad0c70e2c2d", + "25a70e7d1f0cdf4af26ea3fd54d4ba82801957f9", + "44dd89b76ce56ef532bb6868b5d39c0dbbed7714", + "1bb18fd0aa5163d348df3398a8c8acaf5efc9019", + "c887adba97b6ee6a9c7817564c69cad31f976ca1", + "2f95e977c77d74ba463cdfee9436da1004778fcc", + "bc22cdba591eac1698f7577db0c8966d950417e4", + "f7397050bdf9959d834e92eb3a8f6c243f9b61f9", + "60c3a7c35283dd6377baff1e6ab137d1e0e96c0d", + "3e579ec1ea51bce7b98cec4ea910a84f08e06c29", + "3963fb319b08ba71d26baf6f16f37d17c283b855", + "90d689c000053b46dd9ca4e24009a0e8a16fbb24", + "83fb19513e8d3013a27db742a0610230070bc8df", + "aff4d23ad1e471155921c75732417bd63984a753", + "e6a0dc9b0d20a4649807c920cb58d27fcc559743", + "ed818c4b396c1e8dd363b65d74c5f8f844b5310a", + "ded76f196cc2a64111ecf8fd24dcd306d9c445e5", + "247b73c9bdc34dd723533f50d56fc345ef624d9a", + "d465bda8766e9031f14bd266458e4bb09ac37ff2", + "a4cfee8af58ac2fc43ea5497db4bf02b98cc46dc", + "59baf4a051665750eb7055d0cec991d9876526df", + "792b7d58c384eaa16c6caf28770fbc3064cf642b" + ], + "typedResolverMergeCommit": "792b7d58c384eaa16c6caf28770fbc3064cf642b", + "mainRef": "refs/remotes/origin/main", + "mainRefSha": "PENDING_ACTUAL_NATIVE_CLONE_MAIN_SHA", + "frozenAt": "2026-10-25T22:30:39.990290+00:00", + "p0DifferenceRationale": "Latest fetched landed main4fa includes merged typed resolver fix183822 and all prior29 repairs. Linux keeps native150c/aaa compiler profiles; P0 CB11 C2 is distinct58c/b838 signed reference. Fresh preparation and runtime required for1270changed paths sinceR3." + }, + "distBuildInfoSha256": "PENDING_ACTUAL_NATIVE_DIST_SHA256", + "p0Reference": { + "cohort": "cb-b838", + "manifest": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admission-inputs/P0-artifacts.json", + "manifestSha256": "f60309fc44e418cfaf02df998ada40cfab89c10f773df0c09eb512775d0d8e83", + "variant": "desktop-c2", + "sourceCommit": "58c12b7787c3852c32667329f506750a8ed63994", + "executableSha256": "877d86b206343b485d615e488e7b88802181a3c7f56bc1bd4dcdc91cb210638b" + }, + "compiler": { + "cohort": "rd-p6-150c", + "profile": "cb-standard", + "path": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/compilers/standard/bun", + "sha256": "PENDING_ACTUAL_PRESERVED_NATIVE_COMPILER_SHA256", + "bunCommit": "150c9620c53710060186b8b0cd50985e035408b0", + "webkitCommit": "aaa690bfbf34c9d50775716ac2fc3c7d0573e0b8", + "engineFeatures": { + "shadowRealm": true, + "hardened": false + } + }, + "buildNode": { + "path": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/opt/node/bin/node", + "sha256": "PENDING_ACTUAL_NATIVE_NODE_SHA256" + }, + "pluginsFile": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/admission-inputs/plugins/desktop.json", + "pluginsSha256": "PENDING_ACTUAL_NATIVE_PLUGIN_SELECTION_SHA256", + "compileTrimAllow": [ + "run" + ], + "timeoutSeconds": "PENDING_ROOT_BOUNDED_TIMEOUT_SECONDS" +} diff --git a/scripts/openclaw-p6/app/packet/payload/adopt-compilers.py b/scripts/openclaw-p6/app/packet/payload/adopt-compilers.py new file mode 100644 index 000000000000..3ed385b44cf9 --- /dev/null +++ b/scripts/openclaw-p6/app/packet/payload/adopt-compilers.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 +"""Copy actual preserved150c native compilers into this fresh app root; no build.""" +import hashlib,json,os,platform,shutil +from pathlib import Path +ROOT=Path('/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1') +COMPILER_ROOT=Path('/home/runner/.cache/oc-ty-ext/P6/rd150c-x64-v1') +def sha(p): + with p.open('rb') as f:return hashlib.file_digest(f,'sha256').hexdigest() +def main(): + assert platform.system()=='Linux' and platform.machine()=='x86_64';os.umask(0o077) + record={'status':'native-compilers-adopted-not-app-admitted'};items=[] + for profile,directory,label,shadow in [('cb-standard','build-standard','standard',True),('cb-compat','build-c2','sr-off',False)]: + compiler=COMPILER_ROOT/directory/'bun';config=COMPILER_ROOT/directory/'configure.json';receipt=COMPILER_ROOT/'receipts'/f'{profile}-build.json';transport=COMPILER_ROOT/f'preserved-{profile}'/'transport.json' + built=json.loads(receipt.read_text());settings=json.loads(config.read_text());preserved=json.loads(transport.read_text()) + assert built['status']=='build-command-finished-not-qualified' and built['exitCode']==0 and built['profile']==profile + assert built['source']['bun']=='150c9620c53710060186b8b0cd50985e035408b0' and built['source']['webkit']=='aaa690bfbf34c9d50775716ac2fc3c7d0573e0b8' + assert preserved['status']=='native-preserved-not-downloaded' and preserved['profile']==profile + assert sha(compiler)==built['compilerSha256']==preserved['compilerSha256'] and sha(receipt)==preserved['buildReceiptSha256'] and sha(config)==preserved['configureSha256'] + assert settings['profile']=='release-local' and settings['overrides']['shadowRealm'] is shadow and settings['overrides'].get('hardened',False) is False + target=ROOT/'compilers'/label;assert not target.exists();items.append((profile,compiler,config,receipt,transport,target,shadow)) + assert not (ROOT/'admission-inputs/compiler-records.json').exists() + for profile,compiler,config,receipt,transport,target,shadow in items: + target.mkdir(parents=True) + for path,name in [(compiler,'bun'),(config,'configure.json'),(receipt,'build.json'),(transport,'transport.json')]:shutil.copy2(path,target/name) + assert sha(target/'bun')==sha(compiler) + record[profile]={'path':str(target/'bun'),'sha256':sha(target/'bun'),'cohort':'rd-p6-150c','bunCommit':'150c9620c53710060186b8b0cd50985e035408b0','webkitCommit':'aaa690bfbf34c9d50775716ac2fc3c7d0573e0b8','engineFeatures':{'shadowRealm':shadow,'hardened':False},'buildReceiptSha256':sha(receipt),'preservationReceiptSha256':sha(transport)} + with (ROOT/'admission-inputs/compiler-records.json').open('x') as f:json.dump(record,f,indent=2);f.write('\n') + print(json.dumps(record,indent=2)) +if __name__=='__main__':main() diff --git a/scripts/openclaw-p6/app/packet/payload/build-prep/artifact-contract.mjs b/scripts/openclaw-p6/app/packet/payload/build-prep/artifact-contract.mjs new file mode 100644 index 000000000000..98b90d54c903 --- /dev/null +++ b/scripts/openclaw-p6/app/packet/payload/build-prep/artifact-contract.mjs @@ -0,0 +1,52 @@ +// Linux packaging verification only; the runtime tree hash stays with its source owner. +import assert from 'node:assert/strict'; +import { createHash } from 'node:crypto'; +import fs from 'node:fs'; +import path from 'node:path'; +import { pathToFileURL } from 'node:url'; + +const [planFile] = process.argv.slice(2); +assert(planFile, 'Usage: bun artifact-contract.mjs plan.json'); +const plan = JSON.parse(fs.readFileSync(planFile, 'utf8')); +const manifestPath = path.join(plan.output, 'manifest.json'); +const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8')); +const owner = path.join(plan.source, 'scripts/lib/bun-standalone-contract.mjs'); +const { describeStandaloneRuntime, sha256File } = await import(pathToFileURL(owner).href); +assert.equal(manifest.schemaVersion, 1); +assert.deepEqual(manifest.target, { platform: 'linux', arch: plan.arch }); +assert.equal(manifest.openclaw.commit, plan.sourceProof.commit); +assert.equal(manifest.openclaw.version, plan.sourceProof.version); +assert.equal(manifest.mode, plan.variant === 'jit' ? 'jit' : 'aot'); +assert.equal('sourceBuild' in manifest, plan.variant === 'ts'); +assert.equal(manifest.bun.executableSha256, plan.compiler.sha256); +assert.equal(manifest.bun.commit, plan.compiler.bunCommit); +assert.deepEqual(manifest.plugins.embedded, plan.plugins); +assert.equal(manifest.build.flavor, 'standard'); +for (const name of ['id', 'moduleGraphSha256', 'pluginSetSha256']) { + assert.match(manifest.build[name], /^[a-f0-9]{64}$/); +} +assert.equal(manifest.build.pluginSetSha256, + createHash('sha256').update(JSON.stringify(plan.plugins)).digest('hex')); +assert.equal(manifest.executable.path, 'openclaw'); +assert.equal(manifest.runtime.path, 'runtime'); +const executable = path.join(plan.output, 'openclaw'); +assert.equal(fs.statSync(executable).size, manifest.executable.sizeBytes); +assert.equal(await sha256File(executable), manifest.executable.sha256); +const runtime = await describeStandaloneRuntime(path.join(plan.output, 'runtime')); +for (const name of ['sha256', 'sizeBytes', 'fileCount', 'symlinkCount']) { + assert.equal(runtime[name], manifest.runtime[name], `Runtime ${name} differs`); +} +assert.equal(Object.values(manifest.runtime.categories).reduce((sum, item) => sum + item.bytes, 0), runtime.sizeBytes); +assert.equal(manifest.runtime.sqlite.source, 'bun'); +assert.equal(manifest.runtime.sqlite.extensionLoadingSupported, true); +assert.equal('macos' in manifest, false); +console.log(JSON.stringify({ applicationQualified: false, platform: 'linux', arch: plan.arch, + sourceCommit: manifest.openclaw.commit, version: manifest.openclaw.version, + mode: manifest.mode, build: manifest.build, compilerSha256: manifest.bun.executableSha256, + compilerCohort: plan.compiler.cohort, engineProfile: plan.compiler.profile, + admittedEngineFeatures: plan.compiler.engineFeatures, policyLabel: plan.policyLabel, + compileTrimAllow: plan.compileTrimAllow, p0ReferenceCohort: plan.p0ReferenceCohort, + c2ApplicationHardening: plan.c2ApplicationHardening, + historicalC2Equivalent: plan.historicalC2Equivalent, + executable: manifest.executable, runtime, sqlite: manifest.runtime.sqlite, + manifestSha256: await sha256File(manifestPath), contractOwnerSha256: await sha256File(owner) })); diff --git a/scripts/openclaw-p6/app/packet/payload/build-prep/build-linux.py b/scripts/openclaw-p6/app/packet/payload/build-prep/build-linux.py new file mode 100644 index 000000000000..dc7372057bf0 --- /dev/null +++ b/scripts/openclaw-p6/app/packet/payload/build-prep/build-linux.py @@ -0,0 +1,477 @@ +#!/usr/bin/env python3 +"""Admitted native P6 standalone build. Default is read-only preflight/dry-run.""" +import argparse +import datetime +import hashlib +import json +import os +from pathlib import Path +import platform +import re +import runpy +import shutil +import signal +import subprocess +import sys +import traceback + +BUN_PIN = 'fd40ba44187c721ee023062fa153a6a27560e6b1' +WEBKIT_PIN = 'aaa690bfbf34c9d50775716ac2fc3c7d0573e0b8' +CB_BUN_PIN = 'b838e73072227c2652a41c689299284f1965cdc6' +RD_BUN_PIN = '150c9620c53710060186b8b0cd50985e035408b0' +COHORTS = { + 'baseline-fd40': {'bun': BUN_PIN, 'webkit': WEBKIT_PIN, 'profiles': { + 'standard': {'shadowRealm': True, 'hardened': False}, + 'c2': {'shadowRealm': False, 'hardened': False}, + 'c2-linux-hardened': {'shadowRealm': False, 'hardened': True}, + }}, + 'cb-b838': {'bun': CB_BUN_PIN, 'webkit': WEBKIT_PIN, 'profiles': { + 'cb-standard': {'shadowRealm': True, 'hardened': False}, + 'cb-compat': {'shadowRealm': False, 'hardened': False}, + 'cb-linux-hardened': {'shadowRealm': False, 'hardened': True}, + }}, + 'rd-p6-150c': {'bun': RD_BUN_PIN, 'webkit': WEBKIT_PIN, 'profiles': { + 'cb-standard': {'shadowRealm': True, 'hardened': False}, + 'cb-compat': {'shadowRealm': False, 'hardened': False}, + 'cb-linux-hardened': {'shadowRealm': False, 'hardened': True}, + }}, +} +MEASURE_SHA = '2fa495f4727a351f6cee078b403ac064610ce90ed339311f55c40a567463e4b7' +FLAGS = { + 'js': ['--compile-aot', '--explain=statistics'], + 'c2': ['--compile-aot', '--no-compile-function-source', + '--disallow-code-generation-from-strings', '--explain=statistics'], + 'ts': ['--aot-source', '--explain=statistics'], + 'strong': ['--compile-aot', '--no-compile-function-source', + '--disallow-code-generation-from-strings', '--explain=statistics'], + 'jit': [], +} +PROFILES = {'js': 'standard', 'ts': 'standard', 'jit': 'standard', + 'c2': 'c2', 'strong': 'c2-linux-hardened'} + + +def now(): + return datetime.datetime.now(datetime.timezone.utc).isoformat() + + +def require(condition, message): + if not condition: + raise ValueError(message) + + +def sha(filename): + digest = hashlib.sha256() + with Path(filename).open('rb') as stream: + for data in iter(lambda: stream.read(8 << 20), b''): + digest.update(data) + return digest.hexdigest() + + +def load(filename): + return json.loads(Path(filename).read_text()) + + +def write(filename, value): + with Path(filename).open('x') as stream: + json.dump(value, stream, indent=2) + stream.write('\n') + + +def beneath(root, value): + path = Path(value) + require(path.is_absolute(), f'Absolute path required: {value}') + path = path.resolve() + require(path != root and root in path.parents, f'Path must be inside P6 root {root}: {path}') + return path + + +def git(source, *args): + result = subprocess.run(['git', '-c', f'safe.directory={source}', '-C', str(source), *args], + env={'PATH': '/usr/local/bin:/usr/bin:/bin', 'HOME': str(source.parent), + 'GIT_CONFIG_NOSYSTEM': '1'}, capture_output=True, text=True) + require(result.returncode == 0, f'git {args[0]} failed: {result.stderr.strip()}') + return result.stdout.strip() + + +def native_elf(executable, arch): + require(os.access(executable, os.X_OK), f'Not executable: {executable}') + with executable.open('rb') as stream: + header = stream.read(20) + machine = 183 if arch == 'arm64' else 62 + require(header[:6] == b'\x7fELF\x02\x01' and int.from_bytes(header[18:20], 'little') == machine, + f'ELF architecture differs from native Linux target: {executable}') + + +class BuildInterrupted(Exception): + pass + + +def interrupted(signum, _frame): + # subprocess/select treats InterruptedError as a syscall retry, not cancellation. + raise BuildInterrupted(f'Build driver interrupted by signal {signum}') + + +def run_probe(command, *, env, cwd, timeout): + child = subprocess.Popen(command, env=env, cwd=cwd, stdin=subprocess.DEVNULL, + stdout=subprocess.PIPE, stderr=subprocess.PIPE, + text=True, start_new_session=True) + try: + stdout, stderr = child.communicate(timeout=timeout) + return subprocess.CompletedProcess(command, child.returncode, stdout, stderr) + finally: + if child.poll() is None: + try: + os.killpg(child.pid, signal.SIGKILL) + except ProcessLookupError: + pass + child.communicate() + + +def admitted(admission): + require(admission.get('schemaVersion') == 1 and admission.get('lane') == 'P6' and + admission.get('decision') == 'build-linux', 'Explicit root P6 build admission required') + + +def cohort(name): + require(name in COHORTS, 'Explicit supported compiler/reference cohort required') + return COHORTS[name] + + +def retained_capabilities(root, admission, compiler_cohort, variant): + allow = admission.get('compileTrimAllow') + if compiler_cohort == 'baseline-fd40' or variant == 'jit': + require(allow is None, 'Baseline and untrimmed JIT use no retained-capability option') + return None, None + require(allow in [['run'], ['run', 'jit']], 'CB AOT requires explicit compileTrimAllow:[run] or [run,jit]') + reason = None + if 'jit' in allow: + proof = admission.get('jitRetentionProof', {}) + require(isinstance(proof.get('reason'), str) and proof['reason'].strip(), + 'JIT retention requires a named observed runtime failure') + filename = beneath(root, proof['failureReceipt']) + require(sha(filename) == proof['sha256'], 'JIT-retention failure receipt changed') + reason = {**proof, 'failureReceipt': str(filename)} + return allow, reason + + +def source_retention_contract(node, source, root, output, flags, plugins, allow): + if allow is None: + return None + script = ('const owner=await import(process.argv[1]); ' + 'console.log(JSON.stringify(owner.parseStandaloneArguments(process.argv.slice(2))));') + checked = run_probe([str(node), '--no-warnings', '--input-type=module', '--eval', script, + (source / 'scripts/lib/bun-standalone-contract.mjs').as_uri(), str(output), + *flags, '--trim-allow', ','.join(allow), '--plugins', ','.join(plugins)], + cwd=root, env={'PATH': f'{node.parent}:/usr/bin:/bin', 'HOME': str(root), + 'TMPDIR': str(root), 'LANG': 'C.UTF-8'}, timeout=30) + require(checked.returncode == 0, + 'Retained-capability build blocked: admitted landed source must implement --trim-allow. ' + + checked.stderr.strip()) + parsed = json.loads(checked.stdout) + trim = parsed.get('aotCompileOptions', {}).get('trim') + require(parsed.get('mode') == 'aot' and isinstance(trim, dict) and trim.get('allow') == allow and + bool(parsed.get('source')) == ('--aot-source' in flags), + 'Retained-capability build blocked: source parser did not preserve the requested allow list') + return parsed + + +def execution_paths(root, admission, reserved_receipt=None): + source = beneath(root, admission['source']) + output = beneath(root, admission['output']) + receipt = beneath(root, admission['receiptDirectory']) + for path in [output, receipt]: + if path != reserved_receipt: + require(not path.exists(), f'Fresh path required: {path}') + require(source not in path.parents and source != path, 'Output/receipt must be outside source') + require(output != receipt and output not in receipt.parents and receipt not in output.parents, + 'Artifact and receipt directories must be separate') + return source, output, receipt + + +def source_proof(source, cut): + commit = cut['commit'] + require(re.fullmatch('[0-9a-f]{40}', commit), 'Full Linux source commit required') + require(cut['status'] == 'landed-main', 'Linux cut must explicitly be landed-main') + require(cut['mainRef'] in ['refs/remotes/origin/main', 'refs/heads/main'], 'Explicit main ref required') + require(re.fullmatch('[0-9a-f]{40}', cut['mainRefSha']), 'Full observed-main SHA required') + require(isinstance(cut['frozenAt'], str) and cut['frozenAt'], 'Root campaign freeze timestamp required') + datetime.datetime.fromisoformat(cut['frozenAt'].replace('Z', '+00:00')) + require(git(source, 'rev-parse', 'HEAD') == commit, 'Source HEAD differs from admitted Linux cut') + require(git(source, 'rev-parse', cut['mainRef']) == cut['mainRefSha'], 'Local main ref differs from admission') + git(source, 'merge-base', '--is-ancestor', commit, cut['mainRefSha']) + require(not git(source, 'status', '--porcelain', '--untracked-files=no'), 'Tracked source is dirty') + ancestors = cut['requiredAncestors'] + require(isinstance(ancestors, list), 'requiredAncestors must be explicit') + for ancestor in ancestors: + require(re.fullmatch('[0-9a-f]{40}', ancestor), 'Full required-ancestor SHA required') + git(source, 'merge-base', '--is-ancestor', ancestor, commit) + info = load(source / 'dist/build-info.json') + package = load(source / 'package.json') + require(info.get('commit') == commit, 'dist/build-info.json belongs to another source commit') + require(info.get('version') == package['version'], 'dist/build-info.json version is stale') + require((source / 'dist/cli-startup-metadata.json').is_file(), 'Complete pnpm build first') + return {'commit': commit, 'mainRef': cut['mainRef'], 'mainRefSha': cut['mainRefSha'], + 'frozenAt': cut['frozenAt'], 'requiredAncestors': ancestors, + 'version': package['version'], 'distBuildInfo': info, + 'hashes': {name: sha(source / name) for name in ['dist/build-info.json', + 'package.json', 'pnpm-lock.yaml', 'scripts/build-bun-standalone.mjs', + 'scripts/lib/bun-standalone-contract.mjs', + 'scripts/lib/bun-standalone-source-parser.mjs']}} + + +def prepare(root, admission_file, measurement, reserved_receipt=None): + require(platform.system() == 'Linux', 'Driver requires native Linux') + arch = {'aarch64': 'arm64', 'x86_64': 'x64'}.get(platform.machine()) + require(arch, 'Only Linux arm64/x64 supported') + admission = load(admission_file) + admitted(admission) + variant = admission['variant'] + require(variant in FLAGS, 'Unknown variant') + source, output, receipt = execution_paths(root, admission, reserved_receipt) + proof = source_proof(source, admission['linuxCut']) + require(proof['hashes']['dist/build-info.json'] == admission['distBuildInfoSha256'], + 'Admitted dist/build-info.json bytes differ') + reference = admission['p0Reference'] + reference_cohort = cohort(reference.get('cohort')) + index = beneath(root, reference['manifest']) + require(index.name == 'P0-artifacts.json' and index.is_file(), 'P0 manifest clone is required') + require(sha(index) == reference['manifestSha256'], 'P0 manifest clone differs from admission') + state = load(index) + require(state.get('schemaVersion') == 1 and state.get('lane') == 'P0', 'Invalid P0 manifest') + entries = [row for row in state['artifacts'] if row['variant'] == reference['variant'] and + row['sourceCommit'] == reference['sourceCommit'] and + row['sha256'] == reference['executableSha256']] + require(len(entries) == 1, 'P0 reference does not identify one immutable artifact') + p0 = entries[0] + require(p0.get('signed') is True, 'P0 reference must be an indexed signed artifact') + require(p0['compilerPins']['bun'] == reference_cohort['bun'] and + p0['compilerPins']['webkit'] == reference_cohort['webkit'], + 'P0 reference uses different compiler pins') + if reference['cohort'] == 'cb-b838': + require(p0['compilerPins']['shadowRealm'] == 'retained' and + p0['compilerPins']['historicalC2Equivalent'] is False, + 'CB P0 reference must preserve its retained-ShadowRealm distinction') + require(p0['sourceStatus'] in ['main', 'main-plus-open-pr'], 'Unknown P0 source status') + if p0['sourceStatus'] == 'main': + require(p0['mainSha'] == p0['sourceCommit'], 'P0 main artifact has inconsistent identity') + if p0['sourceCommit'] != proof['commit']: + require(admission['linuxCut']['requiredAncestors'] and + admission['linuxCut'].get('p0DifferenceRationale', '').strip(), + 'Different P0/Linux cuts require explicit root rationale and landed-repair ancestry') + compiler = admission['compiler'] + selected_cohort = cohort(compiler.get('cohort')) + executable = beneath(root, compiler['path']) + allowed_profiles = [PROFILES[variant]] if compiler['cohort'] == 'baseline-fd40' else ( + ['cb-linux-hardened'] if variant == 'strong' else + ['cb-standard', 'cb-compat'] if variant == 'c2' else ['cb-standard']) + require(compiler['profile'] in allowed_profiles, 'Compiler engine profile differs from cohort/variant') + expected_features = selected_cohort['profiles'][compiler['profile']] + require(compiler.get('engineFeatures') == expected_features and + all(type(value) is bool for value in compiler['engineFeatures'].values()), + 'Compiler engine features differ from the explicit cohort/profile') + require(compiler['bunCommit'] == selected_cohort['bun'] and + compiler['webkitCommit'] == selected_cohort['webkit'], + 'Compiler provenance uses different pins') + require(sha(executable) == compiler['sha256'], 'Compiler bytes differ from admission') + native_elf(executable, arch) + node = admission['buildNode'] + node_path = beneath(root, node['path']) + require(node_path.name == 'node', 'Build Node must be named node for the source parser fallback') + require(sha(node_path) == node['sha256'], 'Build Node bytes differ from admission') + native_elf(node_path, arch) + strip_probe = '''import {stripTypeScriptTypes} from 'node:module'; +const input='const f = true ? async (x: number): Promise => x : null;'; +const output=stripTypeScriptTypes(input,{mode:'strip'}); +console.log(JSON.stringify({platform:process.platform,arch:process.arch,version:process.version, + offsetsPreserved:output.length===input.length,typesRemoved:!output.includes('number')}));''' + probed = run_probe([str(node_path), '--no-warnings', '--input-type=module', '--eval', strip_probe], + cwd=root, env={'PATH': f'{node_path.parent}:/usr/bin:/bin', 'HOME': str(root), + 'TMPDIR': str(root), 'LANG': 'C.UTF-8'}, timeout=30) + require(probed.returncode == 0, f'Build Node type-stripper preflight failed: {probed.stderr}') + node_probe = json.loads(probed.stdout) + require(node_probe['platform'] == 'linux' and node_probe['arch'] == arch and + node_probe['offsetsPreserved'] and node_probe['typesRemoved'], + f'Build Node type-stripper contract failed: {node_probe}') + plugins_file = beneath(root, admission['pluginsFile']) + require(sha(plugins_file) == admission['pluginsSha256'], 'Plugin selection differs from admission') + plugins = load(plugins_file) + require(isinstance(plugins, list) and plugins and plugins == sorted(set(plugins)) and + all(isinstance(item, str) and re.fullmatch('[a-z0-9][a-z0-9._-]*', item) for item in plugins), + 'Plugin IDs must be a nonempty sorted unique JSON array') + allow, retention_proof = retained_capabilities(root, admission, compiler['cohort'], variant) + source_contract = source_retention_contract(node_path, source, root, output, FLAGS[variant], plugins, allow) + retention_flags = ['--trim-allow', ','.join(allow)] if allow is not None else [] + measurement = beneath(root, str(measurement)) + require(sha(measurement) == MEASURE_SHA, 'Reviewed measurement utility bytes changed') + command = ['/usr/bin/nice', '-n', '10', str(executable), '--no-env-file', '--no-install', + str(source / 'scripts/build-bun-standalone.mjs'), str(output), + *FLAGS[variant], *retention_flags, '--plugins', ','.join(plugins)] + timeout = admission.get('timeoutSeconds', 12 * 3600) + require(type(timeout) is int and 1 <= timeout <= 24 * 3600, 'Invalid build timeout') + return {'operation': 'build-linux', 'variant': variant, 'platform': 'linux', 'arch': arch, + 'kernel': platform.release(), 'source': str(source), 'sourceProof': proof, + 'linuxCut': admission['linuxCut'], 'p0Reference': p0, + 'p0ReferenceCohort': reference['cohort'], + 'p0ManifestClone': str(index), 'p0ManifestSha256': reference['manifestSha256'], + 'compiler': compiler, 'buildNode': node, 'buildNodeProbe': node_probe, + 'compileTrimAllow': allow, 'jitRetentionProof': retention_proof, + 'sourceRetentionContract': source_contract, + 'policyLabel': '/'.join([compiler['cohort'], compiler['profile'], variant, + '+'.join(allow) if allow is not None else 'default']), + 'c2ApplicationHardening': variant in ['c2', 'strong'], + 'historicalC2Equivalent': variant == 'c2' and compiler['cohort'] == 'baseline-fd40', + 'plugins': plugins, 'pluginsFile': str(plugins_file), + 'pluginsSha256': admission['pluginsSha256'], 'output': str(output), + 'receiptDirectory': str(receipt), 'command': command, + 'measurementUtility': str(measurement), 'measurementUtilitySha256': MEASURE_SHA, + 'admissionFile': str(admission_file), 'admissionSha256': sha(admission_file), + 'driverSha256': sha(__file__), + 'artifactCheckerSha256': sha(Path(__file__).with_name('artifact-contract.mjs')), + 'buildEnvironmentOverrides': {'UV_THREADPOOL_SIZE': '2'}, + 'timeoutSeconds': timeout} + + +def reject_competing_builds(): + active = [] + for item in Path('/proc').iterdir(): + if not item.name.isdigit() or int(item.name) == os.getpid(): + continue + try: + argv = (item / 'cmdline').read_bytes().decode(errors='replace').rstrip('\0').split('\0') + except (FileNotFoundError, ProcessLookupError, PermissionError): + continue + builder = any(Path(arg).name == 'build-bun-standalone.mjs' for arg in argv) + bun_compile = (len(argv) > 1 and Path(argv[0]).name == 'bun' and argv[1] == 'build' and + any(arg.startswith(('--compile', '--aot')) for arg in argv[2:])) + if builder or bun_compile: + active.append({'pid': int(item.name), 'argv': argv}) + require(not active, f'Competing actual standalone compiler process: {active}') + + +def environment(receipt, compiler, node): + state = receipt / 'state' + for name in ['home', 'tmp', 'cache', 'workspace']: + (state / name).mkdir(parents=True) + return {'PATH': f'{Path(node).parent}:{Path(compiler).parent}:/usr/local/bin:/usr/bin:/bin', + 'HOME': str(state / 'home'), 'TMPDIR': str(state / 'tmp'), + 'TMP': str(state / 'tmp'), 'TEMP': str(state / 'tmp'), + 'XDG_CACHE_HOME': str(state / 'cache'), 'LANG': 'C.UTF-8', 'LC_ALL': 'C.UTF-8', + 'SHELL': '/bin/bash', 'USER': 'p6-synthetic', 'NO_COLOR': '1', 'TERM': 'dumb', + 'CI': '1', 'UV_THREADPOOL_SIZE': '2', 'NODE_DISABLE_COMPILE_CACHE': '1', + 'OPENCLAW_STATE_DIR': str(state), 'OPENCLAW_CONFIG_PATH': str(state / 'openclaw.json'), + 'OPENCLAW_NO_RESPAWN': '1', 'OPENCLAW_SUPERVISOR_MODE': 'external', + 'OPENCLAW_SERVICE_REPAIR_POLICY': 'external'} + + +def measure(plan, env, receipt): + # Execute the reviewed owner in this process so SIGINT/TERM raises through + # its existing finally block and kills/reaps its isolated compiler group. + old_argv, old_env, old_cwd = sys.argv, dict(os.environ), Path.cwd() + old_signals = {sig: signal.signal(sig, interrupted) for sig in [signal.SIGINT, signal.SIGTERM]} + try: + sys.argv = [plan['measurementUtility'], '--label', plan['variant'], '--out', + str(receipt / 'measurement'), '--timeout', str(plan['timeoutSeconds']), + '--', *plan['command']] + os.environ.clear() + os.environ.update(env) + os.chdir(plan['source']) + try: + runpy.run_path(plan['measurementUtility'], run_name='__main__') + except SystemExit as exit_result: + code = exit_result.code + if isinstance(code, int) and (code == 124 or code < 0 or code >= 128): + raise + require(code in [None, 0], f'Build command exited {code}') + finally: + os.chdir(old_cwd) + os.environ.clear() + os.environ.update(old_env) + sys.argv = old_argv + for sig, handler in old_signals.items(): + signal.signal(sig, handler) + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--root', required=True, help='P6 external-volume root as mounted on Linux') + parser.add_argument('--admission', required=True) + parser.add_argument('--measure-command', required=True) + parser.add_argument('--run', action='store_true') + args = parser.parse_args() + root = Path(args.root).resolve(strict=True) + admission_file = beneath(root, args.admission) + if not args.run: + old_signals = {sig: signal.signal(sig, interrupted) for sig in [signal.SIGINT, signal.SIGTERM]} + try: + plan = prepare(root, admission_file, Path(args.measure_command)) + print(json.dumps({'status': 'dry-run', **plan}, indent=2)) + finally: + for sig, handler in old_signals.items(): + signal.signal(sig, handler) + return + admission = load(admission_file) + admitted(admission) + _, _, receipt = execution_paths(root, admission) + receipt.mkdir(parents=True) + result = {'status': 'failed', 'startedAt': now(), 'phase': 'preflight', + 'admissionFile': str(admission_file), 'admissionSha256': sha(admission_file), + 'applicationQualified': False} + old_signals = {sig: signal.signal(sig, interrupted) for sig in [signal.SIGINT, signal.SIGTERM]} + try: + plan = prepare(root, admission_file, Path(args.measure_command), reserved_receipt=receipt) + result['plan'] = plan + require(shutil.disk_usage(root).free >= 25 * 1024**3, 'Linux volume below 25 GiB floor') + reject_competing_builds() + env = environment(receipt, plan['compiler']['path'], plan['buildNode']['path']) + result['phase'] = 'compiler-identity' + identity = run_probe([plan['compiler']['path'], '--no-env-file', '--no-install', '-p', + 'JSON.stringify({platform:process.platform,arch:process.arch,bun:Bun.revision,webkit:process.versions.webkit})'], + env=env, cwd=receipt / 'state/home', timeout=30) + result['compilerIdentityProbe'] = {'exitCode': identity.returncode, + 'stdout': identity.stdout, 'stderr': identity.stderr} + require(identity.returncode == 0, f'Compiler identity probe failed: {identity.stderr}') + identity = json.loads(identity.stdout) + require(identity == {'platform': 'linux', 'arch': plan['arch'], + 'bun': plan['compiler']['bunCommit'], 'webkit': plan['compiler']['webkitCommit']}, + f'Compiler runtime provenance mismatch: {identity}') + result['compilerRuntimeIdentity'] = identity + write(receipt / 'plan.json', plan) + reject_competing_builds() + result['phase'] = 'build' + measure(plan, env, receipt) + result['measurement'] = load(receipt / 'measurement/receipt.json') + result['phase'] = 'post-build-source-check' + require(source_proof(Path(plan['source']), plan['linuxCut']) == plan['sourceProof'], + 'Source or package build identity changed during compilation') + require(sha(admission_file) == plan['admissionSha256'] and + sha(plan['pluginsFile']) == plan['pluginsSha256'] and + sha(plan['buildNode']['path']) == plan['buildNode']['sha256'] and + sha(plan['compiler']['path']) == plan['compiler']['sha256'], + 'Admitted inputs changed during build') + result['phase'] = 'artifact-contract' + inspector = Path(__file__).with_name('artifact-contract.mjs') + check = run_probe(['/usr/bin/nice', '-n', '10', plan['compiler']['path'], + '--no-env-file', '--no-install', str(inspector), + str(receipt / 'plan.json')], env=env, + cwd=receipt / 'state/home', timeout=1800) + (receipt / 'artifact-contract.stdout').write_text(check.stdout) + (receipt / 'artifact-contract.stderr').write_text(check.stderr) + require(check.returncode == 0, f'Artifact contract failed: {check.stderr}') + result['artifact'] = json.loads(check.stdout) + result['status'] = 'built-unsigned' + result['phase'] = 'complete' + except BaseException: + result['error'] = traceback.format_exc() + if (receipt / 'measurement/receipt.json').exists(): + result['measurement'] = load(receipt / 'measurement/receipt.json') + raise + finally: + result['finishedAt'] = now() + write(receipt / 'result.json', result) + print(json.dumps({'status': result['status'], 'phase': result['phase'], 'receipt': str(receipt)})) + for sig, handler in old_signals.items(): + signal.signal(sig, handler) + + +if __name__ == '__main__': + main() diff --git a/scripts/openclaw-p6/app/packet/payload/build-prep/select-plugins.mjs b/scripts/openclaw-p6/app/packet/payload/build-prep/select-plugins.mjs new file mode 100644 index 000000000000..c7113a57930b --- /dev/null +++ b/scripts/openclaw-p6/app/packet/payload/build-prep/select-plugins.mjs @@ -0,0 +1,40 @@ +// Run with the qualified Bun from the completed source checkout. +import assert from 'node:assert/strict'; +import { execFileSync } from 'node:child_process'; +import { createHash } from 'node:crypto'; +import fs from 'node:fs'; +import path from 'node:path'; +import { pathToFileURL } from 'node:url'; + +const [sourceInput, outputInput] = process.argv.slice(2); +assert(sourceInput && outputInput, 'Usage: bun select-plugins.mjs SOURCE FRESH_OUTPUT'); +const source = fs.realpathSync(sourceInput), output = path.resolve(outputInput); +assert(!fs.existsSync(output), 'Fresh selector output required'); +const sourceCommit = execFileSync('git', ['-C', source, 'rev-parse', 'HEAD'], { encoding: 'utf8' }).trim(); +const runtimeBuildInfo = JSON.parse(fs.readFileSync(path.join(source, 'dist/build-info.json'), 'utf8')); +assert.equal(runtimeBuildInfo.commit?.trim().toLowerCase(), sourceCommit, 'Runtime build is from a different source commit; rerun pnpm build'); +assert.equal(runtimeBuildInfo.version, JSON.parse(fs.readFileSync(path.join(source, 'package.json'), 'utf8')).version, 'Runtime package version is stale'); +const owner = path.join(source, 'scripts/lib/bun-standalone-plugins.mjs'); +const { classifyStandalonePlugins, planStandalonePlugins } = await import(pathToFileURL(owner).href); +const inventory = classifyStandalonePlugins(source); +const byId = new Map(inventory.map(row => [row.id, row])); +assert(byId.has('codex'), 'Desktop Codex plugin missing from completed build'); +const selected = new Set([...inventory.filter(row => !row.hasInstallRoute && !row.devOnly).map(row => row.id), 'codex']); +let size; +do { + size = selected.size; + for (const id of selected) for (const dependency of byId.get(id).requiresPlugins) { + assert(byId.has(dependency), `Missing required plugin ${dependency} for ${id}`); + selected.add(dependency); + } +} while (size !== selected.size); +const desktop = planStandalonePlugins(source, [...selected].toSorted()); +const all = planStandalonePlugins(source); +const hash = file => createHash('sha256').update(fs.readFileSync(file)).digest('hex'); +const receipt = { sourceRoot: source, sourceCommit, owner, ownerSha256: hash(owner), + rule: 'classifyStandalonePlugins: !hasInstallRoute && !devOnly, plus codex, with requiresPlugins closure; validated by planStandalonePlugins', + inventory, desktop, all, runtimeBuildInfo, buildInfoSha256: hash(path.join(source, 'dist/build-info.json')) }; +fs.mkdirSync(output, { recursive: true }); +for (const [file, value] of [['plugin-selection.json', receipt], ['desktop.json', desktop.embedded], ['all.json', all.embedded]]) + fs.writeFileSync(path.join(output, file), JSON.stringify(value, null, 2) + '\n', { flag: 'wx' }); +console.log(JSON.stringify({ sourceCommit, desktop: desktop.embedded.length, all: all.embedded.length, output })); diff --git a/scripts/openclaw-p6/app/packet/payload/cron-fixture/cron-cli-fixture.sh b/scripts/openclaw-p6/app/packet/payload/cron-fixture/cron-cli-fixture.sh new file mode 100644 index 000000000000..93c01f919dbc --- /dev/null +++ b/scripts/openclaw-p6/app/packet/payload/cron-fixture/cron-cli-fixture.sh @@ -0,0 +1,540 @@ +#!/usr/bin/env bash +# Bash 5.3+ can deadlock writing heredoc pipes on macOS before the reader starts. +if [[ ${OSTYPE:-} == darwin* && $BASH != /bin/bash ]] && ((BASH_VERSINFO[0] > 5 || (BASH_VERSINFO[0] == 5 && BASH_VERSINFO[1] >= 3))); then + exec /bin/bash "$0" "$@" +fi +set -euo pipefail + +ROOT_DIR="$(cd "${OPENCLAW_DOCKER_E2E_REPO_ROOT:?missing fixed source root}" && pwd -P)" +source "$ROOT_DIR/scripts/lib/docker-e2e-image.sh" + +IMAGE_NAME="$(docker_e2e_resolve_image "openclaw-cron-cli-e2e" OPENCLAW_IMAGE)" +TOKEN="cron-cli-e2e-$(date +%s)-$$" +CONTAINER_NAME="openclaw-cron-cli-e2e-$$" +CLIENT_LOG="$(mktemp -t openclaw-cron-cli-log.XXXXXX)" + +trap 'docker_e2e_cleanup_container_run "$CONTAINER_NAME" "$CLIENT_LOG"' EXIT + +docker_e2e_build_or_reuse "$IMAGE_NAME" cron-cli +OPENCLAW_TEST_STATE_SCRIPT_B64="$(docker_e2e_test_state_shell_b64 cron-cli empty)" + +echo "Running in-container Gateway + cron CLI smoke..." +set +e +docker_e2e_run_with_harness \ + --name "$CONTAINER_NAME" \ + -e "OPENCLAW_GATEWAY_TOKEN=$TOKEN" \ + -e "OPENCLAW_SKIP_CHANNELS=1" \ + -e "OPENCLAW_SKIP_GMAIL_WATCHER=1" \ + -e "OPENCLAW_SKIP_CANVAS_HOST=1" \ + -e "OPENCLAW_SKIP_ACPX_RUNTIME=1" \ + -e "OPENCLAW_SKIP_ACPX_RUNTIME_PROBE=1" \ + -e "OPENCLAW_TEST_STATE_SCRIPT_B64=$OPENCLAW_TEST_STATE_SCRIPT_B64" \ + -e "GW_TOKEN=$TOKEN" \ + -e "OPENCLAW_ALLOW_INSECURE_PRIVATE_WS=1" \ + -i \ + "$IMAGE_NAME" \ + bash -s >"$CLIENT_LOG" 2>&1 <<'INNER' +set -euo pipefail + +source scripts/lib/openclaw-e2e-instance.sh +openclaw_e2e_eval_test_state_from_b64 "${OPENCLAW_TEST_STATE_SCRIPT_B64:?missing OPENCLAW_TEST_STATE_SCRIPT_B64}" + +entry="$(openclaw_e2e_resolve_entrypoint)" +gateway_pid= +mock_pid= + +cleanup_inner() { + openclaw_e2e_stop_process "${gateway_pid:-}" + openclaw_e2e_stop_process "${mock_pid:-}" +} + +dump_logs_on_error() { + status=$? + if [ "$status" -ne 0 ]; then + openclaw_e2e_dump_logs \ + /tmp/cron-cli-gateway.log \ + /tmp/cron-cli-status.json \ + /tmp/cron-cli-add.json \ + /tmp/cron-cli-agent-add.json \ + /tmp/cron-cli-agent-default.json \ + /tmp/cron-cli-agent-restricted.json \ + /tmp/cron-cli-agent-cleared.json \ + /tmp/cron-authority-operator-matrix.json \ + /tmp/cron-cli-edit-exact.json \ + /tmp/cron-cli-edit-timeout.json \ + /tmp/cron-cli-get-after-edit.json \ + /tmp/cron-cli-script-add.json \ + /tmp/cron-cli-script-before.json \ + /tmp/cron-cli-script-generic-timeout.log \ + /tmp/cron-cli-script-after-generic.json \ + /tmp/cron-cli-script-edit-timeout.json \ + /tmp/cron-cli-script-after-specific.json \ + /tmp/cron-cli-event-add.json \ + /tmp/cron-cli-event-before.json \ + /tmp/cron-cli-event-generic-timeout.log \ + /tmp/cron-cli-event-after.json \ + /tmp/cron-cli-list.json \ + /tmp/cron-cli-show.json \ + /tmp/cron-cli-disable.json \ + /tmp/cron-cli-enable.json \ + /tmp/cron-cli-run.json \ + /tmp/cron-cli-runs.json \ + /tmp/cron-cli-remove.json + fi + cleanup_inner + exit "$status" +} + +trap cleanup_inner EXIT +trap dump_logs_on_error ERR + +cron_cli() { + node "$entry" cron "$@" --token "${GW_TOKEN:?missing GW_TOKEN}" +} + +run_operator_authority_matrix() { + local phase="$1" + node --input-type=module - "$entry" "${GW_TOKEN:?missing GW_TOKEN}" "$phase" <<'NODE' +import { readFile, writeFile } from "node:fs/promises"; +import { spawnSync } from "node:child_process"; + +const [entry, token, phase] = process.argv.slice(2); +const snapshotPath = "/tmp/cron-authority-operator-matrix.json"; + +function callGateway(method, params) { + const result = spawnSync( + process.execPath, + [entry, "gateway", "call", method, "--params", JSON.stringify(params), "--token", token, "--json"], + { encoding: "utf8", env: process.env }, + ); + if (result.status !== 0) { + throw new Error( + `${method} failed (${result.status}): ${String(result.stderr || result.stdout).trim()}`, + ); + } + return JSON.parse(result.stdout); +} + +function readAuthority(job) { + return { + toolsAllow: job.payload?.toolsAllow, + toolsAllowIsDefault: job.payload?.toolsAllowIsDefault, + }; +} + +function assertAuthority(label, job, expected) { + const actual = readAuthority(job); + if (JSON.stringify(actual) !== JSON.stringify(expected)) { + throw new Error( + `${label} authority mismatch: expected=${JSON.stringify(expected)} actual=${JSON.stringify(actual)}`, + ); + } +} + +if (phase === "create") { + const schedule = { kind: "every", everyMs: 3_600_000 }; + const cases = [ + { + label: "agent-default", + input: { + name: "operator agent default", + sessionTarget: "isolated", + payload: { kind: "agentTurn", message: "agent default" }, + }, + expected: { toolsAllow: ["*"] }, + }, + { + label: "agent-wildcard", + input: { + name: "operator agent wildcard", + sessionTarget: "isolated", + payload: { kind: "agentTurn", message: "agent wildcard", toolsAllow: ["*"] }, + }, + expected: { toolsAllow: ["*"] }, + }, + { + label: "agent-empty", + input: { + name: "operator agent empty", + sessionTarget: "isolated", + payload: { kind: "agentTurn", message: "agent empty", toolsAllow: [] }, + }, + expected: { toolsAllow: [] }, + }, + { + label: "script-default", + input: { + name: "operator script default", + sessionTarget: "isolated", + payload: { kind: "script", script: "return {}" }, + }, + expected: { toolsAllow: ["*"] }, + }, + { + label: "trigger-system-default", + input: { + name: "operator trigger system default", + sessionTarget: "main", + trigger: { script: "return { fire: false }" }, + payload: { kind: "systemEvent", text: "trigger system default" }, + }, + expected: { toolsAllow: ["*"] }, + }, + { + label: "trigger-command-default", + input: { + name: "operator trigger command default", + sessionTarget: "isolated", + trigger: { script: "return { fire: false }" }, + payload: { kind: "command", argv: ["printf", "trigger-command"] }, + }, + expected: { toolsAllow: ["*"] }, + }, + { + label: "transport-system-capless", + input: { + name: "operator transport system capless", + sessionTarget: "main", + payload: { kind: "systemEvent", text: "transport system capless" }, + }, + expected: {}, + }, + { + label: "transport-command-capless", + input: { + name: "operator transport command capless", + sessionTarget: "isolated", + payload: { kind: "command", argv: ["printf", "transport-command"] }, + }, + expected: {}, + }, + { + label: "transport-system-narrow-trigger", + input: { + name: "operator transport system narrow", + sessionTarget: "main", + payload: { kind: "systemEvent", text: "transport system narrow", toolsAllow: ["read"] }, + }, + expected: { toolsAllow: ["read"] }, + patch: { trigger: { script: "return { fire: false }" } }, + expectedAfterPatch: { toolsAllow: ["read"] }, + }, + { + label: "transport-system-capless-trigger", + input: { + name: "operator transport system adopts wildcard", + sessionTarget: "main", + payload: { kind: "systemEvent", text: "transport system adopts wildcard" }, + }, + expected: {}, + patch: { trigger: { script: "return { fire: false }" } }, + expectedAfterPatch: { toolsAllow: ["*"] }, + }, + ]; + + const snapshots = []; + for (const testCase of cases) { + let job = callGateway("cron.add", { + enabled: false, + schedule, + wakeMode: "now", + delivery: { mode: "none" }, + ...testCase.input, + }); + assertAuthority(`${testCase.label} create`, job, testCase.expected); + if (testCase.patch) { + callGateway("cron.update", { id: job.id, patch: testCase.patch }); + job = callGateway("cron.get", { id: job.id }); + assertAuthority(`${testCase.label} update`, job, testCase.expectedAfterPatch); + } + snapshots.push({ + id: job.id, + label: testCase.label, + authority: readAuthority(job), + }); + } + await writeFile(snapshotPath, `${JSON.stringify({ cases: snapshots }, null, 2)}\n`, "utf8"); + process.stdout.write(`operator authority matrix created ${snapshots.length} cases\n`); +} else if (phase === "verify") { + const snapshot = JSON.parse(await readFile(snapshotPath, "utf8")); + for (const testCase of snapshot.cases) { + const job = callGateway("cron.get", { id: testCase.id }); + assertAuthority(`${testCase.label} restart`, job, testCase.authority); + callGateway("cron.remove", { id: testCase.id }); + } + process.stdout.write(`operator authority matrix restart-verified ${snapshot.cases.length} cases\n`); +} else { + throw new Error(`unknown authority matrix phase: ${phase}`); +} +NODE +} + +read_json_field() { + local file="$1" + local field="$2" + node --input-type=module -e ' + const fs = await import("node:fs/promises"); + const [file, field] = process.argv.slice(1); + const value = JSON.parse(await fs.readFile(file, "utf8"))[field]; + if (typeof value !== "string" || value.length === 0) { + throw new Error(`missing string field ${field} in ${file}`); + } + process.stdout.write(value); + ' "$file" "$field" +} + +# Task-only fixture: disabled agent rows require a configured model route. +# Use the source-owned loopback mock; never real credentials or provider traffic. +MOCK_PORT=0 MOCK_REQUEST_LOG=/tmp/cron-cli-provider-requests.jsonl SUCCESS_MARKER=P6_CRON_SYNTHETIC \ + node scripts/e2e/mock-openai-server.mjs >/tmp/cron-cli-mock.log 2>&1 & +mock_pid="$!" +mock_port= +for attempt in {1..100}; do + mock_port="$(sed -n 's/^mock-openai listening on \([0-9][0-9]*\)$/\1/p' /tmp/cron-cli-mock.log | head -1)" + [ -z "$mock_port" ] || break + kill -0 "$mock_pid" 2>/dev/null || { cat /tmp/cron-cli-mock.log; exit 1; } + sleep 0.1 +done +[[ "$mock_port" =~ ^[1-9][0-9]*$ ]] || { cat /tmp/cron-cli-mock.log; exit 1; } +node --input-type=module - "$mock_port" <<'P6_CRON_PROVIDER' +import fs from 'node:fs'; +import {applyMockOpenAiModelConfig} from './scripts/e2e/lib/fixtures/mock-openai-config.mjs'; +const cfg={}; +applyMockOpenAiModelConfig(cfg,{mockPort:process.argv[2]}); +cfg.models.providers.openai.apiKey='p6-synthetic-cron-fixture-only'; +fs.writeFileSync(process.env.OPENCLAW_CONFIG_PATH,JSON.stringify(cfg,null,2)+'\n'); +console.log('P6_CRON_SYNTHETIC_PROVIDER '+JSON.stringify({baseUrl:cfg.models.providers.openai.baseUrl,credentialKind:'synthetic-fixture-only'})); +P6_CRON_PROVIDER + +node --input-type=module -e ' + const fs = await import("node:fs/promises"); + const configPath = process.env.OPENCLAW_CONFIG_PATH; + if (!configPath) { + throw new Error("OPENCLAW_CONFIG_PATH is required"); + } + const raw = await fs.readFile(configPath, "utf8").catch(() => "{}"); + const config = JSON.parse(raw || "{}"); + config.cron ??= {}; + config.cron.triggers = { ...(config.cron.triggers ?? {}), enabled: true }; + await fs.writeFile(configPath, `${JSON.stringify(config, null, 2)}\n`, "utf8"); +' + +gateway_pid="$(openclaw_e2e_start_gateway "$entry" 18789 /tmp/cron-cli-gateway.log)" +openclaw_e2e_wait_gateway_ready "$gateway_pid" /tmp/cron-cli-gateway.log 300 18789 + +run_operator_authority_matrix create +node --input-type=module - <<'P6_CRON_DISABLED' +import fs from 'node:fs'; +const file='/tmp/cron-cli-provider-requests.jsonl'; +const rows=fs.existsSync(file)?fs.readFileSync(file,'utf8').trim().split('\n').filter(Boolean).map(JSON.parse):[]; +const inference=rows.filter(row=>/\/v1\/(responses|chat\/completions)/.test(row.path??'')); +if(inference.length)throw Error('disabled authority rows unexpectedly requested inference'); +console.log('P6_CRON_DISABLED_INFERENCE '+JSON.stringify({requests:inference.length})); +P6_CRON_DISABLED +openclaw_e2e_stop_process "$gateway_pid" +gateway_pid= +gateway_pid="$(openclaw_e2e_start_gateway "$entry" 18789 /tmp/cron-cli-gateway.log)" +openclaw_e2e_wait_gateway_ready "$gateway_pid" /tmp/cron-cli-gateway.log 300 18789 +run_operator_authority_matrix verify + +cron_cli status --json > /tmp/cron-cli-status.json +cron_add_args=( + "cli cron smoke" + --cron "*/5 * * * *" + --command "printf openclaw-cli-cron-ok" + --no-deliver + --timeout-seconds 15 + --json +) +cron_cli add "${cron_add_args[@]}" > /tmp/cron-cli-add.json + +job_id="$(read_json_field /tmp/cron-cli-add.json id)" + +cron_cli add \ + "agent authority smoke" \ + --every 1h \ + --session isolated \ + --message "verify explicit cron tool authority" \ + --no-deliver \ + --json > /tmp/cron-cli-agent-add.json +agent_job_id="$(read_json_field /tmp/cron-cli-agent-add.json id)" + +cron_cli show "$agent_job_id" --json > /tmp/cron-cli-agent-default.json +cron_cli edit "$agent_job_id" --tools read +cron_cli show "$agent_job_id" --json > /tmp/cron-cli-agent-restricted.json +cron_cli edit "$agent_job_id" --clear-tools +cron_cli show "$agent_job_id" --json > /tmp/cron-cli-agent-cleared.json +node --input-type=module -e ' + const fs = await import("node:fs/promises"); + const readPayload = async (path) => JSON.parse(await fs.readFile(path, "utf8")).payload; + const defaultPayload = await readPayload("/tmp/cron-cli-agent-default.json"); + const restrictedPayload = await readPayload("/tmp/cron-cli-agent-restricted.json"); + const clearedPayload = await readPayload("/tmp/cron-cli-agent-cleared.json"); + if (JSON.stringify(defaultPayload?.toolsAllow) !== JSON.stringify(["*"])) { + throw new Error(`new agent job is not explicitly unrestricted: ${JSON.stringify(defaultPayload)}`); + } + if (JSON.stringify(restrictedPayload?.toolsAllow) !== JSON.stringify(["read"])) { + throw new Error(`cron edit --tools did not persist: ${JSON.stringify(restrictedPayload)}`); + } + if (JSON.stringify(clearedPayload?.toolsAllow) !== JSON.stringify(["*"])) { + throw new Error(`cron edit --clear-tools is not explicit: ${JSON.stringify(clearedPayload)}`); + } +' +cron_cli rm "$agent_job_id" --json >/dev/null + +cron_cli edit "$job_id" --exact > /tmp/cron-cli-edit-exact.json +cron_cli edit "$job_id" --timeout-seconds 30 > /tmp/cron-cli-edit-timeout.json +cron_cli get "$job_id" > /tmp/cron-cli-get-after-edit.json +node --input-type=module -e ' + const fs = await import("node:fs/promises"); + const value = JSON.parse(await fs.readFile("/tmp/cron-cli-get-after-edit.json", "utf8")); + if (value.schedule?.kind !== "cron" || value.schedule.staggerMs !== 0) { + throw new Error(`cron edit --exact did not persist: ${JSON.stringify(value.schedule)}`); + } + if (value.payload?.kind !== "command" || value.payload.timeoutSeconds !== 30) { + throw new Error(`cron timeout-only edit changed command payload kind: ${JSON.stringify(value.payload)}`); + } +' + +cat > /tmp/cron-cli-script.js <<'SCRIPT' +return { notify: "cron script timeout proof" }; +SCRIPT +cron_cli add \ + "script timeout smoke" \ + --every 1h \ + --session isolated \ + --script /tmp/cron-cli-script.js \ + --script-timeout-seconds 15 \ + --no-deliver \ + --json > /tmp/cron-cli-script-add.json +script_job_id="$(read_json_field /tmp/cron-cli-script-add.json id)" +cron_cli get "$script_job_id" > /tmp/cron-cli-script-before.json +if cron_cli edit "$script_job_id" --timeout-seconds 30 > /tmp/cron-cli-script-generic-timeout.log 2>&1; then + echo "generic timeout unexpectedly succeeded for script job" >&2 + exit 1 +fi +grep -q -- "Use --script-timeout-seconds for script jobs" /tmp/cron-cli-script-generic-timeout.log +cron_cli get "$script_job_id" > /tmp/cron-cli-script-after-generic.json +cron_cli edit "$script_job_id" --script-timeout-seconds 30 > /tmp/cron-cli-script-edit-timeout.json +cron_cli get "$script_job_id" > /tmp/cron-cli-script-after-specific.json +node --input-type=module -e ' + const fs = await import("node:fs/promises"); + const before = JSON.parse(await fs.readFile("/tmp/cron-cli-script-before.json", "utf8")); + const afterGeneric = JSON.parse( + await fs.readFile("/tmp/cron-cli-script-after-generic.json", "utf8"), + ); + const afterSpecific = JSON.parse( + await fs.readFile("/tmp/cron-cli-script-after-specific.json", "utf8"), + ); + if (before.payload?.kind !== "script" || before.payload.timeoutSeconds !== 15) { + throw new Error(`script setup mismatch: ${JSON.stringify(before.payload)}`); + } + if (JSON.stringify(afterGeneric.payload) !== JSON.stringify(before.payload)) { + throw new Error( + `rejected generic timeout changed script payload: ${JSON.stringify(afterGeneric.payload)}`, + ); + } + if (afterSpecific.payload?.kind !== "script" || afterSpecific.payload.timeoutSeconds !== 30) { + throw new Error( + `script-specific timeout did not persist: ${JSON.stringify(afterSpecific.payload)}`, + ); + } +' +cron_cli rm "$script_job_id" --json >/dev/null + +cron_cli add \ + "event timeout smoke" \ + --every 1h \ + --session main \ + --system-event "cron event timeout proof" \ + --json > /tmp/cron-cli-event-add.json +event_job_id="$(read_json_field /tmp/cron-cli-event-add.json id)" +cron_cli get "$event_job_id" > /tmp/cron-cli-event-before.json +if cron_cli edit "$event_job_id" --timeout-seconds 30 > /tmp/cron-cli-event-generic-timeout.log 2>&1; then + echo "generic timeout unexpectedly succeeded for systemEvent job" >&2 + exit 1 +fi +grep -q -- "--timeout-seconds is not supported for systemEvent jobs" \ + /tmp/cron-cli-event-generic-timeout.log +cron_cli get "$event_job_id" > /tmp/cron-cli-event-after.json +node --input-type=module -e ' + const fs = await import("node:fs/promises"); + const before = JSON.parse(await fs.readFile("/tmp/cron-cli-event-before.json", "utf8")); + const after = JSON.parse(await fs.readFile("/tmp/cron-cli-event-after.json", "utf8")); + if (before.payload?.kind !== "systemEvent") { + throw new Error(`event setup mismatch: ${JSON.stringify(before.payload)}`); + } + if (JSON.stringify(after.payload) !== JSON.stringify(before.payload)) { + throw new Error(`rejected generic timeout changed event payload: ${JSON.stringify(after.payload)}`); + } +' +cron_cli rm "$event_job_id" --json >/dev/null + +cron_cli list --all --json > /tmp/cron-cli-list.json +node --input-type=module -e ' + const fs = await import("node:fs/promises"); + const jobId = process.argv[1]; + const value = JSON.parse(await fs.readFile("/tmp/cron-cli-list.json", "utf8")); + if (!Array.isArray(value.jobs) || !value.jobs.some((job) => job.id === jobId && job.name === "cli cron smoke")) { + throw new Error("created job missing from cron list"); + } +' "$job_id" + +cron_cli show "$job_id" --json > /tmp/cron-cli-show.json +node --input-type=module -e ' + const fs = await import("node:fs/promises"); + const jobId = process.argv[1]; + const value = JSON.parse(await fs.readFile("/tmp/cron-cli-show.json", "utf8")); + if (value.id !== jobId || value.name !== "cli cron smoke") { + throw new Error("cron show returned the wrong job"); + } +' "$job_id" + +cron_cli disable "$job_id" > /tmp/cron-cli-disable.json +cron_cli enable "$job_id" > /tmp/cron-cli-enable.json + +cron_cli run "$job_id" --wait --wait-timeout 120s --poll-interval 500ms > /tmp/cron-cli-run.json +node --input-type=module -e ' + const fs = await import("node:fs/promises"); + const value = JSON.parse(await fs.readFile("/tmp/cron-cli-run.json", "utf8")); + if (value.completed !== true || value.status !== "ok") { + throw new Error(`cron run did not complete ok: ${JSON.stringify(value)}`); + } +' + +cron_cli runs --id "$job_id" --limit 5 > /tmp/cron-cli-runs.json +node --input-type=module -e ' + const fs = await import("node:fs/promises"); + const value = JSON.parse(await fs.readFile("/tmp/cron-cli-runs.json", "utf8")); + const matching = Array.isArray(value.entries) + ? value.entries.find((entry) => entry.status === "ok" && entry.summary === "openclaw-cli-cron-ok") + : undefined; + if (!matching) { + throw new Error("cron runs missing successful command summary"); + } +' + +cron_cli rm "$job_id" --json > /tmp/cron-cli-remove.json +node --input-type=module -e ' + const fs = await import("node:fs/promises"); + const value = JSON.parse(await fs.readFile("/tmp/cron-cli-remove.json", "utf8")); + if (value.ok !== true) { + throw new Error("cron remove failed"); + } +' + +node --input-type=module -e ' + process.stdout.write(JSON.stringify({ ok: true, jobId: process.argv[1] }) + "\n"); +' "$job_id" +INNER +status=${PIPESTATUS[0]} +set -e + +if [ "$status" -ne 0 ]; then + echo "Docker cron CLI smoke failed" + docker_e2e_print_log "$CLIENT_LOG" + exit "$status" +fi + +docker_e2e_print_log "$CLIENT_LOG" +echo "OK" diff --git a/scripts/openclaw-p6/app/packet/payload/cron-fixture/inputs.json b/scripts/openclaw-p6/app/packet/payload/cron-fixture/inputs.json new file mode 100644 index 000000000000..05a43bf646cb --- /dev/null +++ b/scripts/openclaw-p6/app/packet/payload/cron-fixture/inputs.json @@ -0,0 +1,22 @@ +{ + "status": "prepared-only-not-x64-proof", + "sourceCommit": "4fa442e332745f1f58ccedd27106abdafcf4e019", + "nativeRoot": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1", + "nativeSource": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/source", + "controllerNode": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/opt/node/bin/node", + "fixtureSha256": "958adbfa641e24736306fd23a5cb3a5e2bfda2c4502889ca593c33da368be4a2", + "helpersSha256": { + "scripts/e2e/cron-cli-docker.sh": "6abf5cf3e174992d313c1f69f863565ebad078a17dae89723fb817ec6ae33245", + "scripts/lib/docker-e2e-image.sh": "b1227189675dff51e3a0218edc2715fad01b771668f1a402a9effba28aec49b1", + "scripts/lib/docker-e2e-package.sh": "88a00beb30de0aee79e679d33d504c4058335b433166eb35a5c9d9bc14bab575", + "scripts/lib/docker-e2e-container.sh": "7ae9be2f95729d17913413189790973aa97e8bd6ba24ff0fbddf2ad450a40fe0", + "scripts/lib/openclaw-e2e-instance.sh": "bd6cf54ea310f96a891f12ec55ed282d29de8370b3505482ec1ab7626e6eb08e", + "scripts/lib/openclaw-test-state.mts": "610f6982125dc456f04ac241ad71ba7f01ac107c10f177ed6c947f2b0e25cc99", + "scripts/e2e/mock-openai-server.mjs": "e68f6ce4b4024aa0c04d0504dbe403f2e310be1fd2e2a51c907244e31dbf1820", + "scripts/e2e/lib/fixtures/mock-openai-config.mjs": "26986b7a44259220a98ba616e20297888502a6ec9f0cb89f9306159b544ebfb1" + }, + "runtimeExecuted": false, + "imageReceipt": "required approved qualification-prep-v3 docker-image.py result.json; PASS source/manifest/binary identity, actual immutable image ID", + "imageReceiptProducerSha256": "5cc18ed7bf5d02fc0eed0d2688dba355e470e62fe7910b4a679eab0751c9a87a", + "controllerNodeReceipt": "/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1/prep-receipts/toolchain/result.json" +} diff --git a/scripts/openclaw-p6/app/packet/payload/cron-fixture/run-native.sh b/scripts/openclaw-p6/app/packet/payload/cron-fixture/run-native.sh new file mode 100644 index 000000000000..6d612f26636e --- /dev/null +++ b/scripts/openclaw-p6/app/packet/payload/cron-fixture/run-native.sh @@ -0,0 +1,65 @@ +#!/usr/bin/env bash +set -euo pipefail +[[ $# -eq 3 ]] || { echo 'Usage: run-native.sh ACTUAL_ARTIFACT APPROVED_DOCKER_IMAGE_RESULT_JSON FRESH_P6_OUTPUT' >&2; exit 2; } +here="$(cd "$(dirname "$0")" && pwd -P)" +root=/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1 +source="$(cd "$root/source" && pwd -P)" +node="$root/opt/node/bin/node" +artifact=$1 +image_receipt=$2 +output=$3 +[[ $(uname -s) == Linux && $(uname -m) == x86_64 ]] || exit 1 +image="$("$node" --input-type=module - "$here" "$source" "$artifact" "$image_receipt" "$output" <<'NODE' +import assert from 'node:assert/strict'; +import fs from 'node:fs'; +import path from 'node:path'; +import {createHash} from 'node:crypto'; +import {execFileSync} from 'node:child_process'; +const [here,source,artifactArg,receiptArg,outArg]=process.argv.slice(2); +const read=p=>JSON.parse(fs.readFileSync(p,'utf8')); +const hash=p=>createHash('sha256').update(fs.readFileSync(p)).digest('hex'); +const input=read(path.join(here,'inputs.json')); +const toolchain=read(input.controllerNodeReceipt); +assert.equal(toolchain.status,'PASS'); +assert.equal(toolchain.buildNode.path,input.controllerNode); +assert.equal(hash(input.controllerNode),toolchain.buildNode.sha256); +assert.equal(hash(path.join(here,'cron-cli-fixture.sh')),input.fixtureSha256); +assert.equal(execFileSync('git',['-C',source,'rev-parse','HEAD'],{encoding:'utf8'}).trim(),input.sourceCommit); +assert.equal(execFileSync('git',['-C',source,'status','--porcelain','--untracked-files=no'],{encoding:'utf8'}).trim(),'','tracked helper source changed'); +for(const [name,digest] of Object.entries(input.helpersSha256))assert.equal(hash(path.join(source,name)),digest,name); +const artifact=fs.realpathSync(artifactArg),out=path.resolve(outArg),p6=path.dirname(input.nativeRoot); +const manifest=read(path.join(artifact,'manifest.json')); +assert.deepEqual(manifest.target,{platform:'linux',arch:'x64'}); +assert.equal(manifest.openclaw.commit,input.sourceCommit); +assert.equal(manifest.mode,'aot'); +const receiptBytes=fs.readFileSync(receiptArg),receipt=JSON.parse(receiptBytes); +assert.equal(receipt.status,'PASS','successful owner docker-image result.json required'); +assert.equal(receipt.sourceCommit,input.sourceCommit); +assert.equal(receipt.manifestSha256,hash(path.join(artifact,'manifest.json'))); +assert.equal(receipt.binarySha256,hash(path.join(artifact,'openclaw'))); +assert.equal(manifest.executable.sha256,receipt.binarySha256); +assert.match(receipt.imageId,/^sha256:[0-9a-f]{64}$/); +assert(out.startsWith(p6+path.sep)&&out!==artifact&&!out.startsWith(artifact+path.sep)&&out!==source&&!out.startsWith(source+path.sep)); +assert(!fs.existsSync(out),'fresh output required');fs.mkdirSync(out,{recursive:true}); +fs.writeFileSync(path.join(out,'image-receipt.json'),receiptBytes,{flag:'wx'}); +fs.writeFileSync(path.join(out,'image-binding.json'),JSON.stringify({imageId:receipt.imageId,sourceCommit:receipt.sourceCommit,manifestSha256:receipt.manifestSha256,binarySha256:receipt.binarySha256,receiptSha256:createHash('sha256').update(receiptBytes).digest('hex')},null,2)+'\n',{flag:'wx'}); +console.log(receipt.imageId); +NODE +)" +output="$(cd "$output" && pwd -P)" +mkdir "$output/tmp" +export TMPDIR="$output/tmp" PATH="$root/opt/node/bin:/usr/local/bin:/usr/bin:/bin" +finish() { code=$?;trap - EXIT;printf '{"exitCode":%s}\n' "$code" >"$output/exit.json";exit "$code"; } +trap finish EXIT +require_equal() { if [[ "$1" != "$2" ]]; then echo "Image identity mismatch: $3" >&2;exit 1;fi; } +require_equal "$(docker image inspect "$image" --format '{{.Id}}')" "$image" immutable-image-id +require_equal "$(docker image inspect "$image" --format '{{.Os}}')" linux operating-system +require_equal "$(docker image inspect "$image" --format '{{.Architecture}}')" amd64 architecture +docker image inspect "$image" >"$output/image.json" +sha256sum "$here/inputs.json" "$here/cron-cli-fixture.sh" "$artifact/manifest.json" "$artifact/openclaw" "$output/image-receipt.json" >"$output/input-sha256.txt" +export OPENCLAW_SKIP_DOCKER_BUILD=1 OPENCLAW_DOCKER_E2E_REQUIRE_LOCAL_IMAGE=1 +export OPENCLAW_IMAGE="$image" OPENCLAW_DOCKER_E2E_IMAGE="$image" +export OPENCLAW_DOCKER_E2E_REPO_ROOT="$source" DOCKER_E2E_HARNESS_ROOT_DIR="$source" +export OPENCLAW_SELECTED_SHA=4fa442e332745f1f58ccedd27106abdafcf4e019 +export OPENCLAW_DOCKER_E2E_SELECTED_SHA="$OPENCLAW_SELECTED_SHA" +/bin/bash "$here/cron-cli-fixture.sh" >"$output/lane.log" 2>&1 || exit "$?" diff --git a/scripts/openclaw-p6/app/packet/payload/guest/application/guest-cli.py b/scripts/openclaw-p6/app/packet/payload/guest/application/guest-cli.py new file mode 100755 index 000000000000..93f356062abc --- /dev/null +++ b/scripts/openclaw-p6/app/packet/payload/guest/application/guest-cli.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python3 +"""Actual app CLI and native memory probes in its main JS context; no policy injection.""" +from pathlib import Path +import hashlib,importlib.util,json,os,platform,re,shutil,signal,stat,subprocess,traceback + +def module(path,name): + spec=importlib.util.spec_from_file_location(name,path);m=importlib.util.module_from_spec(spec);spec.loader.exec_module(m);return m + +def main(): + os.umask(0o077) + payload=Path('/mnt/p6');manifest=json.loads((payload/'manifest.json').read_text());work=Path('/var/tmp/p6-application-security');work.mkdir(exist_ok=False);binary=payload/'artifact/openclaw' + report={**manifest,'kernel':platform.release(),'arch':platform.machine(),'pass':False,'applicationQualification':False,'qualificationKind':'application-main-memory-policy','performanceEligible':False,'scope':'Actual app main-thread anonymous RWX/RW-to-RX denial, allowed file-backed RX; no universal executable-memory claim','commands':[],'traces':{}} + try: + version=re.match(r'^(\d+)\.(\d+)',platform.release()) + if platform.machine()!='x86_64' or not version or tuple(map(int,version.groups()))<(6,7):raise RuntimeError('Requires Linux x64 kernel >=6.7') + if hashlib.file_digest(binary.open('rb'),'sha256').hexdigest()!=manifest['binarySha256']:raise RuntimeError('Application binary differs') + fixture_bytes={} + for name,expected in manifest['controlFiles'].items(): + raw=(payload/'security'/name).read_bytes() + if hashlib.sha256(raw).hexdigest()!=expected:raise RuntimeError('Control file differs: '+name) + if name.startswith('fixture/'):fixture_bytes[name]=raw + strace=shutil.which('strace') + if not strace:raise RuntimeError('Pinned guest strace absent') + report['straceVersion']=subprocess.run([strace,'--version'],capture_output=True,text=True,check=True).stdout.splitlines()[0] + for name in ['home','tmp','xdg','state','workspace']:(work/name).mkdir() + # mkfs -d preserves host ownership; the guest owns its verified fixture copy. + fixture=work/'fixture';fixture.mkdir(mode=0o700) + for name in ['package.json','openclaw.plugin.json','index.js']: + (fixture/name).write_bytes(fixture_bytes['fixture/'+name]) + def path_identity(path): + info=path.stat() + return {'path':str(path),'uid':info.st_uid,'gid':info.st_gid,'mode':oct(stat.S_IMODE(info.st_mode))} + report['fixtureAdmission']={'effectiveUid':os.geteuid(),'umask':'0077', + 'payload':[path_identity(payload/'security/fixture'),path_identity(payload/'security/fixture/index.js')], + 'owned':[path_identity(fixture),path_identity(fixture/'index.js')], + 'copiedFileSha256':{name:manifest['controlFiles']['fixture/'+name] for name in ['package.json','openclaw.plugin.json','index.js']}} + cfg={'gateway':{'mode':'local','bind':'loopback','port':33189,'auth':{'mode':'token','token':'p6-synthetic-mdwe'},'controlUi':{'enabled':False}},'agents':{'defaults':{'workspace':str(work/'workspace'),'skipBootstrap':True,'utilityModel':''},'entries':{'main':{}}},'browser':{'enabled':False},'update':{'checkOnStart':False},'plugins':{'enabled':True,'allow':['p6-mdwe-fixture'],'load':{'paths':[str(fixture)]},'entries':{'p6-mdwe-fixture':{'enabled':True}}}} + (work/'state/openclaw.json').write_text(json.dumps(cfg,indent=2)+'\n') + env={'PATH':'/usr/bin:/bin','HOME':str(work/'home'),'USERPROFILE':str(work/'home'),'OPENCLAW_HOME':str(work/'home'),'OPENCLAW_STATE_DIR':str(work/'state'),'OPENCLAW_CONFIG_PATH':str(work/'state/openclaw.json'),'OPENCLAW_TEST_WORKSPACE_DIR':str(work/'workspace'),'TMPDIR':str(work/'tmp'),'XDG_CONFIG_HOME':str(work/'xdg'),'OPENCLAW_NO_RESPAWN':'1','OPENCLAW_DISABLE_BONJOUR':'1','OPENCLAW_NO_AUTO_UPDATE':'1','LANG':'C.UTF-8','TZ':'UTC','NO_COLOR':'1','P6_EXPECT_MDWE':str(manifest['expectedMdwe'])} + def run(label,argv,prefix): + command=[strace,'-ff','-yy','-s','256','-e','trace=execve,prctl,mmap,mprotect,pkey_mprotect,memfd_create,ftruncate,write,munmap,exit_group','-o',str(work/prefix),str(binary),*argv] + row={'label':label,'command':command};report['commands'].append(row) + with (work/(label+'.stdout')).open('wb') as stdout,(work/(label+'.stderr')).open('wb') as stderr: + child=subprocess.Popen(command,cwd=work,env=env,stdout=stdout,stderr=stderr,start_new_session=True) + try:row['exitCode']=child.wait(timeout=180) + except subprocess.TimeoutExpired: + os.killpg(child.pid,signal.SIGTERM) + try:child.wait(timeout=5) + except subprocess.TimeoutExpired:os.killpg(child.pid,signal.SIGKILL);child.wait(timeout=5) + raise RuntimeError('Actual application command timed out: '+label) + row['stdout']=(work/(label+'.stdout')).read_text();row['stderr']=(work/(label+'.stderr')).read_text() + traces={f.name:f.read_text() for f in sorted(work.glob(prefix+'.*'))};report['traces'].update(traces) + if row['exitCode']!=0:raise RuntimeError('Actual application command failed: '+label) + return row,traces + analyzer=module(payload/'trace-policy.py','trace_policy') + row,traces=run('version',['--version'],'version.trace') + if row['stdout'].strip()!=manifest['expectedStdout'].strip():raise RuntimeError('Version differs from actual host result') + report['versionPolicy']=analyzer.analyze(traces,str(binary),manifest['expectedMdwe'],['--version']) + row,traces=run('memory',['p6-mdwe'],'app.trace') + report['policy']=analyzer.analyze(traces,str(binary),manifest['expectedMdwe'],['p6-mdwe']) + rows=[json.loads(line[len('P6_MDWE_RESULT '):]) for line in row['stdout'].splitlines() if line.startswith('P6_MDWE_RESULT ')] + if len(rows)!=1:raise RuntimeError('Expected exactly one actual main-context probe row') + trace=report['policy']['trace'] + if trace!='app.trace.'+str(rows[0]['pid']):raise RuntimeError('Probe PID differs from direct application trace') + report['memoryPolicy']=module(payload/'memory-policy.py','memory_policy').analyze(traces[trace],rows[0],report['policy'],str(binary)) + report['pass']=True + except Exception as error:report['error']=str(error);report['traceback']=traceback.format_exc() + finally: + report['traces']={f.name:f.read_text() for f in sorted(work.glob('*.trace.*'))} + (work/'result.json').write_text(json.dumps(report,indent=2)+'\n');print('P6_GUEST_RESULT '+json.dumps(report),flush=True) + return 0 if report['pass'] else 1 +if __name__=='__main__':raise SystemExit(main()) diff --git a/scripts/openclaw-p6/app/packet/payload/guest/application/memory-policy.py b/scripts/openclaw-p6/app/packet/payload/guest/application/memory-policy.py new file mode 100644 index 000000000000..2d1e17e2f9af --- /dev/null +++ b/scripts/openclaw-p6/app/packet/payload/guest/application/memory-policy.py @@ -0,0 +1,25 @@ +"""Require actual main-thread probe results and corresponding post-activation syscalls.""" +import re + +def analyze(text,row,policy,binary): + if row.get('kind')!='actual-application-plugin-main' or row.get('isMainThread') is not True or row.get('executable')!=binary or row.get('platform')!='linux' or row.get('arch')!='x64': + raise ValueError('Probe did not execute in the actual application main context') + if row.get('mdwe')!=policy['requestedBits'] or row.get('rwToRx')!=-13 or row.get('rwx')!=-13 or row.get('filePrivateRx')!=42: + raise ValueError('Unexpected actual probe result') + if not policy['getAfter'] or policy['getAfter'][-1]!=policy['requestedBits']: + raise ValueError('Actual plugin GET_MDWE readback missing') + lines=text.splitlines() + positions=[i for i,line in enumerate(lines) if re.match(r'^prctl\(PR_GET_MDWE,',line)] + if not positions:raise ValueError('No probe readback trace') + tail=lines[positions[-1]+1:] + rw=re.compile(r'^mmap\(NULL, 4096, PROT_READ\|PROT_WRITE, MAP_PRIVATE\|MAP_ANONYMOUS, -1, 0\)\s+=\s+(0x[0-9a-f]+)$') + allocations=[(i,m.group(1)) for i,line in enumerate(tail) if (m:=rw.match(line))] + pairs=[] + for i,address in allocations: + denied=re.compile(r'^mprotect\('+re.escape(address)+r', 4096, PROT_READ\|PROT_EXEC\)\s+=\s+-1 EACCES\b') + pairs.extend((tail[i],line) for line in tail[i+1:] if denied.match(line)) + rwx=[line for line in tail if re.match(r'^mmap\(NULL, 4096, PROT_READ\|PROT_WRITE\|PROT_EXEC, MAP_PRIVATE\|MAP_ANONYMOUS, -1, 0\)\s+=\s+-1 EACCES\b',line)] + memfd=[line for line in tail if line.startswith('memfd_create("p6-synthetic-code",') and re.search(r'= \d+\(deleted\)$',line)] + file_rx=[line for line in tail if re.match(r'^mmap\(NULL, 4096, PROT_READ\|PROT_EXEC, MAP_PRIVATE, \d+\(deleted\), 0\)\s+=\s+0x[0-9a-f]+$',line)] + if not pairs or not rwx or not memfd or not file_rx:raise ValueError('Missing corresponding memory denial/allowed file-RX syscall evidence') + return {'pass':True,'scope':'Actual app main-thread anonymous RWX and RW-to-RX denial; file-backed private RX remains allowed','rwToRx':pairs,'rwx':rwx,'memfd':memfd,'filePrivateRx':file_rx,'probe':row} diff --git a/scripts/openclaw-p6/app/packet/payload/guest/application/run-application-guest.py b/scripts/openclaw-p6/app/packet/payload/guest/application/run-application-guest.py new file mode 100755 index 000000000000..f1179bc6ab18 --- /dev/null +++ b/scripts/openclaw-p6/app/packet/payload/guest/application/run-application-guest.py @@ -0,0 +1,156 @@ +#!/usr/bin/env python3 +"""Future admitted-artifact CLI proof; never builds or modifies an application.""" +from pathlib import Path +import argparse +import hashlib +import importlib.util +import json +import os +import platform +import re +import secrets +import shutil +import subprocess +import sys + +IMAGE_SHA = '04e8f2461a16a44e78a370284471f29616cdd9baf1893df25807b71f985b6c94' +OWNER_SHA = 'bca0eac25f6bd828f67c895c675fea6c8202583b1e6027f6a83f22212860ab42' +TRANSPORT_SHA = '1e0d155a7827e3fa44e3c377d935001a3db6f6546cdc397fa909c86be4dcdd7b' + + +def digest(file): + with Path(file).open('rb') as stream: + return hashlib.file_digest(stream, 'sha256').hexdigest() + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--artifact', type=Path, required=True) + parser.add_argument('--admission-receipt', type=Path, required=True) + parser.add_argument('--binary-sha256', required=True) + parser.add_argument('--main-sha', required=True) + parser.add_argument('--variant', choices=['js-aot', 'c2', 'ts-aot', 'c2-linux-hardened'], required=True) + parser.add_argument('--expected-stdout', required=True) + parser.add_argument('--image', type=Path, required=True) + parser.add_argument('--work-dir', type=Path, required=True) + parser.add_argument('--vm-owner', type=Path, required=True) + parser.add_argument('--prerequisites', type=Path, required=True) + parser.add_argument('--prerequisites-sha256', required=True) + args = parser.parse_args() + if platform.system() != 'Linux' or platform.machine() != 'x86_64': + parser.error('requires the owned native Linux x64 host') + if not re.fullmatch('[0-9a-f]{40}', args.main_sha) or not re.fullmatch('[0-9a-f]{64}', args.binary_sha256): + parser.error('requires full admitted source and binary hashes') + artifact = args.artifact.resolve(strict=True) + work = args.work_dir.resolve() + if work.exists() or work == artifact or artifact in work.parents: + parser.error('work-dir must be fresh and outside the artifact') + if not (artifact / 'runtime').is_dir() or not (artifact / 'manifest.json').is_file(): + parser.error('requires a complete standalone artifact with runtime and manifest') + if digest(artifact / 'openclaw') != args.binary_sha256: + parser.error('application differs from admitted binary hash') + if digest(args.image) != IMAGE_SHA or digest(args.vm_owner) != OWNER_SHA: + parser.error('cloud image or reviewed VM lifecycle owner hash differs') + transport_file = args.vm_owner.with_name('guest_result_transport.py') + if digest(transport_file) != TRANSPORT_SHA: + parser.error('reviewed shared guest result transport hash differs') + admission_sha = digest(args.admission_receipt) + for entry in artifact.rglob('*'): + if entry.is_symlink(): + if os.path.isabs(os.readlink(entry)) or not entry.resolve(strict=True).is_relative_to(artifact): + parser.error('artifact link is not portable and contained: ' + str(entry)) + elif not entry.is_file() and not entry.is_dir(): + parser.error('artifact contains a non-regular payload entry: ' + str(entry)) + if digest(args.prerequisites) != args.prerequisites_sha256: + parser.error('Guest prerequisite receipt changed') + prerequisites = json.loads(args.prerequisites.read_text()) + if prerequisites['status'] != 'guest-prerequisites-present-not-kvm-qualified' or prerequisites['imageSha256'] != IMAGE_SHA: + parser.error('Guest prerequisites incomplete') + if set(prerequisites['tools']) != {'qemu-system-x86_64','qemu-img','cloud-localds','mkfs.ext4','timeout','sudo'}: + parser.error('Guest prerequisite tool hash map incomplete') + for tool, item in prerequisites['tools'].items(): + if shutil.which(tool) != item['path'] or digest(item['path']) != item['sha256']: + parser.error('Guest host tool changed: ' + tool) + for tool in ['qemu-system-x86_64', 'qemu-img', 'cloud-localds', 'mkfs.ext4', 'timeout', 'sudo']: + if not shutil.which(tool): + parser.error('host prerequisite absent: ' + tool) + spec = importlib.util.spec_from_file_location('p6_vm_owner', args.vm_owner) + owner = importlib.util.module_from_spec(spec) + spec.loader.exec_module(owner) + transport_spec = importlib.util.spec_from_file_location('p6_guest_result_transport', transport_file) + transport_owner = importlib.util.module_from_spec(transport_spec) + sys.modules[transport_spec.name] = transport_owner + transport_spec.loader.exec_module(transport_owner) + preflight = subprocess.run(['sudo', '-n', 'python3', str(args.vm_owner.parent / 'kvm-preflight.py')], + capture_output=True, text=True, timeout=30, check=True) + kvm = json.loads(preflight.stdout) + if kvm.get('pass') is not True: + parser.error('current host privileged KVM preflight did not pass') + work.mkdir(parents=True, exist_ok=False) + transport = transport_owner.prepare_result_transport(work) + payload = work / 'payload' + payload.mkdir() + shutil.copytree(artifact, payload / 'artifact', symlinks=True) + if digest(payload / 'artifact/openclaw') != args.binary_sha256: + raise RuntimeError('Copied application differs from admitted binary') + here = Path(__file__).resolve().parent + for name in ['guest-cli.py', 'trace-policy.py', 'memory-policy.py']: + shutil.copy2(here / name, payload / name) + shutil.copytree(here / 'security', payload / 'security') + controls = work / 'control-build' + controls.mkdir() + cc = shutil.which('cc', path='/usr/bin:/bin') + if not cc: + raise RuntimeError('Native fixture C compiler is absent; no application result') + control_commands = [] + for source, library in [('mdwe.c', 'libp6mdwe.so'), ('file-exec.c', 'libp6fileexec.so')]: + command = [cc, '-shared', '-fPIC', '-O2', '-DP6_LIBRARY', str(payload / 'security' / source), '-o', str(payload / 'security' / library)] + control_commands.append(command) + with (controls / (source + '.log')).open('wb') as output: + subprocess.run(command, stdout=output, stderr=subprocess.STDOUT, timeout=60, check=True, env={'PATH':'/usr/bin:/bin','TMPDIR':str(controls),'LANG':'C.UTF-8'}) + control_receipt = {'status':'native-x64-fixtures-built-not-app-proof','compiler':cc,'compilerSha256':digest(cc),'commands':control_commands,'sha256':{str(file.relative_to(payload / 'security')):digest(file) for file in (payload / 'security').rglob('*') if file.is_file()}} + (controls / 'result.json').write_text(json.dumps(control_receipt, indent=2)+'\n') + nonce = 'p6-app-' + args.variant + '-' + secrets.token_hex(8) + manifest = {'nonce': nonce, 'variant': args.variant, 'mainSha': args.main_sha, + 'binarySha256': args.binary_sha256, 'admissionReceiptSha256': admission_sha, + 'artifactManifestSha256': digest(artifact / 'manifest.json'), + 'expectedStdout': args.expected_stdout, 'controlFiles':control_receipt['sha256'], 'prerequisitesSha256':args.prerequisites_sha256, + 'expectedMdwe': 1 if args.variant == 'c2-linux-hardened' else 3} + (payload / 'manifest.json').write_text(json.dumps(manifest, indent=2) + '\n') + payload_image = work / 'payload.ext4' + size = sum(file.stat().st_size for file in payload.rglob('*') if file.is_file()) + with payload_image.open('wb') as stream: + stream.truncate(((size + 128 * 1024**2) // (64 * 1024**2) + 1) * 64 * 1024**2) + subprocess.run(['mkfs.ext4', '-q', '-F', '-L', 'P6APP', '-d', str(payload), str(payload_image)], check=True) + config = {'datasource_list': ['NoCloud'], 'ssh_pwauth': False, 'disable_root': True, 'users': [], + 'ssh_deletekeys': True, 'ssh_genkeytypes': [], 'ssh_publish_hostkeys': {'enabled': False}, + 'bootcmd': [['touch', '/etc/ssh/sshd_not_to_be_run']], 'network': {'config': 'disabled'}, + 'runcmd': [['bash', '-c', 'exec >/var/tmp/p6-launch.log 2>&1; set -eu; udevadm settle --timeout=30; mkdir -p /mnt/p6; mount -o ro,nodev,nosuid /dev/disk/by-label/P6APP /mnt/p6; ' + transport.guest_redirect + '; python3 /mnt/p6/guest-cli.py']], + 'power_state': {'mode': 'poweroff', 'delay': 'now', 'timeout': 30, 'condition': True}} + (work / 'user-data').write_text('#cloud-config\n' + json.dumps(config, indent=2) + '\n') + (work / 'meta-data').write_text(json.dumps({'instance-id': nonce, 'local-hostname': 'p6-app-synthetic'}) + '\n') + seed, overlay = work / 'seed.img', work / 'guest.qcow2' + subprocess.run(['cloud-localds', str(seed), str(work / 'user-data'), str(work / 'meta-data')], check=True) + subprocess.run(['qemu-img', 'create', '-f', 'qcow2', '-F', 'qcow2', '-b', str(args.image.resolve()), str(overlay)], check=True) + subprocess.run(['qemu-img', 'resize', str(overlay), '8G'], check=True) + command = ['sudo', '-n', 'env', '-i', 'PATH=/usr/sbin:/usr/bin:/sbin:/bin', 'timeout', '--signal=TERM', '--kill-after=5s', '600s', + 'qemu-system-x86_64', '-accel', 'kvm', '-cpu', 'host', '-smp', '2', '-m', '4096', '-display', 'none', '-monitor', 'none', + '-pidfile', str(work / 'qemu.pid'), *transport.qemu_args, + '-qmp', 'unix:' + str(work / 'qmp.sock') + ',server=on,wait=off', '-no-reboot', '-nic', 'none', + '-drive', 'file=' + str(overlay) + ',if=virtio,format=qcow2', + '-drive', 'file=' + str(seed) + ',if=virtio,format=raw,readonly=on', + '-drive', 'file=' + str(payload_image) + ',if=virtio,format=raw,readonly=on'] + report = {**manifest, 'command': command, 'cloudImageSha256': IMAGE_SHA, 'vmOwnerSha256': OWNER_SHA, + 'guestResultTransportSha256': TRANSPORT_SHA, 'resultTransport': transport.metadata, + 'hostKvmPreflight': kvm, 'pass': False, 'applicationQualification': False, + 'scope': 'Actual application CLI/main-thread MDWE memory controls; Gateway, workers and performance remain separate.'} + owner.run_guest_vm(command, work, overlay, report) + for source, name in transport.artifacts: + shutil.copy2(source, work / name) + (work / 'application-guest-result.json').write_text(json.dumps(report, indent=2) + '\n') + print(json.dumps({'pass': report['pass'], 'result': str(work / 'application-guest-result.json')})) + return 0 if report['pass'] else 1 + + +if __name__ == '__main__': + raise SystemExit(main()) diff --git a/scripts/openclaw-p6/app/packet/payload/guest/application/security/file-exec.c b/scripts/openclaw-p6/app/packet/payload/guest/application/security/file-exec.c new file mode 100644 index 000000000000..28d8c58db662 --- /dev/null +++ b/scripts/openclaw-p6/app/packet/payload/guest/application/security/file-exec.c @@ -0,0 +1,28 @@ +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#ifndef MFD_EXEC +#define MFD_EXEC 0x0010U +#endif +int p6_file_private_rx(void) { +#if defined(__aarch64__) + const uint32_t code[]={0x52800540,0xd65f03c0}; +#elif defined(__x86_64__) + const unsigned char code[]={0xb8,42,0,0,0,0xc3}; +#else +#error Unsupported architecture +#endif + int fd=memfd_create("p6-synthetic-code",MFD_CLOEXEC|MFD_EXEC); + if(fd<0) return -errno; + if(ftruncate(fd,4096)!=0 || write(fd,code,sizeof(code))!=(ssize_t)sizeof(code)) { + int e=errno; close(fd); return -e; + } + void *p=mmap(NULL,4096,PROT_READ|PROT_EXEC,MAP_PRIVATE,fd,0); + int e=errno; close(fd); + if(p==MAP_FAILED) return -e; + __builtin___clear_cache(p,(char*)p+sizeof(code)); + int result=((int(*)(void))p)(); munmap(p,4096); return result; +} diff --git a/scripts/openclaw-p6/app/packet/payload/guest/application/security/fixture/index.js b/scripts/openclaw-p6/app/packet/payload/guest/application/security/fixture/index.js new file mode 100644 index 000000000000..e0bbcd5c17d4 --- /dev/null +++ b/scripts/openclaw-p6/app/packet/payload/guest/application/security/fixture/index.js @@ -0,0 +1,19 @@ +const { dlopen, FFIType } = require('bun:ffi'); +function probe() { + const first = dlopen('/mnt/p6/security/libp6mdwe.so', { + p6_get_mdwe:{args:[],returns:FFIType.i64}, + p6_try_exec:{args:[],returns:FFIType.i32}, + p6_try_rwx:{args:[],returns:FFIType.i32}, + }); + let row; + try { row={kind:'actual-application-plugin-main',isMainThread:require('node:worker_threads').isMainThread,pid:process.pid,executable:process.execPath,arch:process.arch,platform:process.platform,mdwe:Number(first.symbols.p6_get_mdwe()),rwToRx:first.symbols.p6_try_exec(),rwx:first.symbols.p6_try_rwx()}; } + finally { first.close(); } + const second=dlopen('/mnt/p6/security/libp6fileexec.so',{p6_file_private_rx:{args:[],returns:FFIType.i32}}); + try { row.filePrivateRx=second.symbols.p6_file_private_rx(); } + finally { second.close(); } + console.log('P6_MDWE_RESULT '+JSON.stringify(row)); + if(row.mdwe!==Number(process.env.P6_EXPECT_MDWE)||row.isMainThread!==true||row.rwToRx!==-13||row.rwx!==-13||row.filePrivateRx!==42) process.exitCode=1; +} +module.exports={id:'p6-mdwe-fixture',name:'P6 MDWE fixture',register(api){ + api.registerCli(({program})=>{program.command('p6-mdwe').description('Synthetic MDWE qualification').action(probe);},{descriptors:[{name:'p6-mdwe',description:'Synthetic MDWE qualification',hasSubcommands:false}]}); +}}; diff --git a/scripts/openclaw-p6/app/packet/payload/guest/application/security/fixture/openclaw.plugin.json b/scripts/openclaw-p6/app/packet/payload/guest/application/security/fixture/openclaw.plugin.json new file mode 100644 index 000000000000..5a81ff58eb8a --- /dev/null +++ b/scripts/openclaw-p6/app/packet/payload/guest/application/security/fixture/openclaw.plugin.json @@ -0,0 +1,7 @@ +{ + "id": "p6-mdwe-fixture", + "configSchema": { + "type": "object", + "properties": {} + } +} diff --git a/scripts/openclaw-p6/app/packet/payload/guest/application/security/fixture/package.json b/scripts/openclaw-p6/app/packet/payload/guest/application/security/fixture/package.json new file mode 100644 index 000000000000..27dadd2759f6 --- /dev/null +++ b/scripts/openclaw-p6/app/packet/payload/guest/application/security/fixture/package.json @@ -0,0 +1,9 @@ +{ + "name": "@openclaw/p6-mdwe-fixture", + "version": "0.0.1", + "openclaw": { + "extensions": [ + "./index.js" + ] + } +} diff --git a/scripts/openclaw-p6/app/packet/payload/guest/application/security/mdwe.c b/scripts/openclaw-p6/app/packet/payload/guest/application/security/mdwe.c new file mode 100644 index 000000000000..681fedac3392 --- /dev/null +++ b/scripts/openclaw-p6/app/packet/payload/guest/application/security/mdwe.c @@ -0,0 +1,55 @@ +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifndef PR_SET_MDWE +#define PR_SET_MDWE 65 +#define PR_GET_MDWE 66 +#define PR_MDWE_REFUSE_EXEC_GAIN 1 +#define PR_MDWE_NO_INHERIT 2 +#endif +long p6_get_mdwe(void) { errno=0; return prctl(PR_GET_MDWE, 0, 0, 0, 0); } +int p6_try_exec(void) { + void *p=mmap(NULL,4096,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS,-1,0); + if(p==MAP_FAILED) return -errno; +#if defined(__aarch64__) + const uint32_t code[]={0x52800540,0xd65f03c0}; +#elif defined(__x86_64__) + const unsigned char code[]={0xb8,42,0,0,0,0xc3}; +#else +#error Unsupported architecture +#endif + memcpy(p,code,sizeof(code)); + if(mprotect(p,4096,PROT_READ|PROT_EXEC)!=0){ int e=errno; munmap(p,4096); return -e; } + __builtin___clear_cache(p,(char*)p+sizeof(code)); + int answer=((int(*)(void))p)(); munmap(p,4096); return answer; +} +int p6_try_rwx(void) { + void *p=mmap(NULL,4096,PROT_READ|PROT_WRITE|PROT_EXEC,MAP_PRIVATE|MAP_ANONYMOUS,-1,0); + if(p==MAP_FAILED) return -errno; + munmap(p,4096); return 0; +} +#ifndef P6_LIBRARY +int main(int argc,char **argv){ + if(argc>1 && strcmp(argv[1],"no-inherit")==0){if(prctl(PR_SET_MDWE,3,0,0,0)!=0){perror("PR_SET_MDWE");return 2;}} + if(argc>1 && strcmp(argv[1],"inherit")==0){if(prctl(PR_SET_MDWE,1,0,0,0)!=0){perror("PR_SET_MDWE");return 2;}} + printf("{\"mdwe\":%ld,\"rw_to_rx\":%d,\"rwx\":%d}\n",p6_get_mdwe(),p6_try_exec(),p6_try_rwx()); fflush(stdout); + if(argc>2 && strcmp(argv[2],"child")==0){ + pid_t pid=fork(); + if(pid<0){perror("fork");return 2;} + if(pid==0){execl(argv[0],argv[0],NULL);_exit(127);} + int w; + pid_t waited; + do { waited=waitpid(pid,&w,0); } while(waited<0 && errno==EINTR); + if(waited!=pid){perror("waitpid");return 2;} + return WIFEXITED(w)?WEXITSTATUS(w):128+WTERMSIG(w); + } + return 0; +} +#endif diff --git a/scripts/openclaw-p6/app/packet/payload/guest/application/trace-policy.py b/scripts/openclaw-p6/app/packet/payload/guest/application/trace-policy.py new file mode 100644 index 000000000000..cbd6b683b073 --- /dev/null +++ b/scripts/openclaw-p6/app/packet/payload/guest/application/trace-policy.py @@ -0,0 +1,62 @@ +"""Read only the actual application's strace file; no policy is injected.""" +import hashlib +import json +import re + +BITS = {'PR_MDWE_REFUSE_EXEC_GAIN': 1, 'PR_MDWE_NO_INHERIT': 2} + + +def value(text): + token = text.strip().split(' /*', 1)[0].split(' (', 1)[0].strip() + result = 0 + for part in token.split('|'): + part = part.strip() + try: + result |= BITS[part] if part in BITS else int(part, 0) + except ValueError: + raise ValueError('Unrecognized MDWE value: ' + token) from None + return result + + +def analyze(traces, binary, expected, argv): + application = re.compile(r'^execve\(' + re.escape(json.dumps(binary)) + r',.*\)\s+=\s+0$') + execution = re.compile(r'^execve\(' + re.escape(json.dumps(binary)) + r',\s*' + + re.escape(json.dumps([binary, *argv])) + r',.*\)\s+=\s+0$') + roots = [(name, text) for name, text in traces.items() + if any(execution.match(line) for line in text.splitlines())] + if len(roots) != 1: + raise ValueError('Expected one trace of the admitted application invocation') + name, text = roots[0] + other_executions = [other for other, body in traces.items() if other != name and + any(application.match(line) for line in body.splitlines())] + if not re.search(r'^\+\+\+ exited with 0 \+\+\+$', text, re.M): + raise ValueError('Application trace lacks a successful terminal exit') + observations = [] + for line in text.splitlines(): + match = re.match(r'^prctl\(PR_(GET|SET)_MDWE(?:,\s*(.*))?\)\s+=\s+(.+)$', line) + if not match: + continue + kind, arguments, returned = match.groups() + if returned.startswith('-1 '): + observations.append({'kind': kind, 'success': False, 'line': line}) + continue + row = {'kind': kind, 'success': True, 'returnValue': value(returned), 'line': line} + if kind == 'SET': + row['bits'] = value(arguments.split(',', 1)[0]) + observations.append(row) + sets = [index for index, row in enumerate(observations) + if row['kind'] == 'SET' and row['success'] and row['returnValue'] == 0 and row['bits'] == expected] + if len(sets) != 1: + raise ValueError('Expected one successful application PR_SET_MDWE for the admitted bits') + position = sets[0] + before = [row['returnValue'] for row in observations[:position] if row['kind'] == 'GET' and row['success']] + after = [row['returnValue'] for row in observations[position + 1:] if row['kind'] == 'GET' and row['success']] + if not before or before[-1] != 0: + raise ValueError('Application did not observe an unenforced MDWE baseline before its SET') + if any(bits != expected for bits in after): + raise ValueError('A post-SET application PR_GET_MDWE differs from the requested bits') + return {'trace': name, 'traceSha256': hashlib.sha256(text.encode()).hexdigest(), + 'argv': [binary, *argv], 'otherApplicationExecTraces': other_executions, + 'requestedBits': expected, 'successfulSet': True, 'getBefore': before, + 'getAfter': after, 'observations': observations, + 'scope': 'Direct application CLI requested MDWE and the kernel accepted it; no injected GET or memory-mapping probe.'} diff --git a/scripts/openclaw-p6/app/packet/payload/guest/collect-evidence.py b/scripts/openclaw-p6/app/packet/payload/guest/collect-evidence.py new file mode 100644 index 000000000000..5e1274fe0d39 --- /dev/null +++ b/scripts/openclaw-p6/app/packet/payload/guest/collect-evidence.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 +"""Preserve complete existing guest outputs; never rerun a guest or trim traces.""" +import argparse,hashlib,json,re,tarfile +from pathlib import Path + +def sha(p): + with p.open('rb') as f:return hashlib.file_digest(f,'sha256').hexdigest() + +def main(): + p=argparse.ArgumentParser(description=__doc__);p.add_argument('--work',type=Path,required=True);p.add_argument('--proof',type=Path,required=True);p.add_argument('--input-proof',type=Path,required=True);a=p.parse_args() + inputs=json.loads(a.input_proof.read_text());a.proof.mkdir(parents=True,exist_ok=False) + result={'status':'failed-no-native-result','applicationQualified':False,'scope':inputs['scope'],'sourceCommit':inputs['sourceCommit'],'binarySha256':inputs['binarySha256'],'rootBuildAdmissionSha256':inputs['rootBuildAdmissionSha256'],'inputProofSha256':sha(a.input_proof),'work':str(a.work),'traceCount':0} + files=[a.input_proof];report_path=a.work/'application-guest-result.json' + if report_path.is_file(): + report=json.loads(report_path.read_text());guest=report.get('guest',{}) + result.update(status='collected-main-memory-policy-pass' if report.get('pass') is True and guest.get('pass') is True else 'collected-main-memory-policy-failed',guestKernel=guest.get('kernel'),variant=report.get('variant'),nonce=report.get('nonce')) + traces=guest.get('traces',{}) + if traces: + directory=a.work/'raw-traces';directory.mkdir(exist_ok=False) + for name,content in traces.items(): + if not re.fullmatch(r'(?:app|version)\.trace\.\d+',name) or not isinstance(content,str):raise ValueError('Unexpected raw trace entry') + path=directory/name;path.write_bytes(content.encode());files.append(path) + result['traceCount']=len(traces) + policy=guest.get('policy',{});selected=directory/policy.get('trace','absent') + if result['status']=='collected-main-memory-policy-pass' and (not selected.is_file() or sha(selected)!=policy.get('traceSha256')):raise ValueError('Selected raw trace hash mismatch') + for extra in sorted((a.work/'control-build').glob('*')): + if extra.is_file():files.append(extra) + for name in ['application-guest-result.json','vm-result.json','guest-result-stream.log','guest-boot-console.log','serial.log','boot-console.log','qemu.log','qmp.stdout','qmp.stderr']: + file=a.work/name + if file.is_file():files.append(file) + if a.work.is_dir(): + archive=a.work/'evidence.tar' + if archive.exists():raise ValueError('Evidence archive already exists') + index=a.work/'evidence-index.json';index.write_text(json.dumps({str(file):sha(file) for file in files},indent=2)+'\n');files.append(index) + with tarfile.open(archive,'w') as tar: + for file in files:tar.add(file,arcname='input-proof.json' if file==a.input_proof else str(file.relative_to(a.work)),recursive=False) + result.update(archive=str(archive),archiveSha256=sha(archive),archiveBytes=archive.stat().st_size) + (a.proof/'receipt.json').write_text(json.dumps(result,indent=2)+'\n');print(json.dumps(result,indent=2)) + +if __name__=='__main__':main() diff --git a/scripts/openclaw-p6/app/packet/payload/guest/guest-prerequisites.py b/scripts/openclaw-p6/app/packet/payload/guest/guest-prerequisites.py new file mode 100644 index 000000000000..bf0304025795 --- /dev/null +++ b/scripts/openclaw-p6/app/packet/payload/guest/guest-prerequisites.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 +"""Guest tools/image only; no compiler, LLVM, app, VM or carrier action.""" +import argparse,hashlib,json,os,platform,shutil,subprocess,tempfile +from pathlib import Path +IMAGE_SHA='04e8f2461a16a44e78a370284471f29616cdd9baf1893df25807b71f985b6c94' +URL='https://cloud-images.ubuntu.com/releases/noble/release-20261017/ubuntu-24.04-server-cloudimg-amd64.img' +TOOLS=['qemu-system-x86_64','qemu-img','cloud-localds','mkfs.ext4','timeout','sudo'] +def sha(p): + with Path(p).open('rb') as f:return hashlib.file_digest(f,'sha256').hexdigest() +def main(): + p=argparse.ArgumentParser(description=__doc__);p.add_argument('--out',type=Path,required=True);p.add_argument('--install-and-download',action='store_true');a=p.parse_args() + if platform.system()!='Linux' or platform.machine()!='x86_64':p.error('Native Linux x64 required') + os.umask(0o077);root=Path.home()/'.cache/oc-ty-ext/P6';image=root/'cb-x64-final-toolchain-input/ubuntu-24.04-release-20261017-amd64.img' + if a.out.exists() or not a.out.resolve().is_relative_to(root.resolve()):p.error('Fresh task-owned prerequisite receipt directory required') + a.out.mkdir(parents=True) + result={'status':'inventory-only-not-ready','applicationQualified':False,'performanceEligible':False,'image':str(image),'imageUrl':URL,'expectedImageSha256':IMAGE_SHA,'packages':['qemu-system-x86','qemu-utils','cloud-image-utils','e2fsprogs'],'compilerSetupRequired':False} + try: + if a.install_and_download: + env={'PATH':'/usr/sbin:/usr/bin:/sbin:/bin','HOME':str(Path.home()),'TMPDIR':str(root/'guest-prerequisites-tmp'),'DEBIAN_FRONTEND':'noninteractive','LANG':'C.UTF-8'};Path(env['TMPDIR']).mkdir(parents=True,exist_ok=True) + with (a.out/'apt.log').open('wb') as log: + for command in [['sudo','-n','apt-get','update'],['sudo','-n','apt-get','install','-y','--no-install-recommends',*result['packages']]]:subprocess.run(command,env=env,stdout=log,stderr=subprocess.STDOUT,check=True) + image.parent.mkdir(parents=True,exist_ok=True) + if image.is_symlink():raise ValueError('Image symlink refused') + if not image.exists(): + with tempfile.TemporaryDirectory(prefix='guest-image-',dir=image.parent) as directory: + temporary=Path(directory)/'download.img' + with (a.out/'download.log').open('wb') as log:subprocess.run(['curl','-fL','--retry','2','--connect-timeout','30','--max-time','1800','-o',str(temporary),URL],stdout=log,stderr=subprocess.STDOUT,check=True) + if sha(temporary)!=IMAGE_SHA:raise ValueError('Pinned cloud image hash mismatch') + os.link(temporary,image) + result['tools']={} + for name in TOOLS: + path=shutil.which(name) + result['tools'][name]={'path':path,'sha256':sha(path) if path else None} + if image.is_file() and not image.is_symlink():result['imageSha256']=sha(image) + if not all(x['path'] for x in result['tools'].values()) or result.get('imageSha256')!=IMAGE_SHA:raise ValueError('QEMU/image prerequisites incomplete') + packages=subprocess.run(['dpkg-query','-W','-f=${Package}\t${Version}\n',*result['packages']],capture_output=True,text=True,check=True);(a.out/'packages.tsv').write_text(packages.stdout) + result['packageInventorySha256']=sha(a.out/'packages.tsv') + for name in ['qemu-system-x86_64','qemu-img']: + version=subprocess.run([result['tools'][name]['path'],'--version'],capture_output=True,text=True,check=True);(a.out/(name+'-version.txt')).write_text(version.stdout+version.stderr) + result['status']='guest-prerequisites-present-not-kvm-qualified' + except Exception as error:result['error']=str(error) + (a.out/'result.json').write_text(json.dumps(result,indent=2)+'\n');print(json.dumps(result,indent=2)) + return 0 if result['status']=='guest-prerequisites-present-not-kvm-qualified' else 1 +if __name__=='__main__':raise SystemExit(main()) diff --git a/scripts/openclaw-p6/app/packet/payload/guest/manifest.json b/scripts/openclaw-p6/app/packet/payload/guest/manifest.json new file mode 100644 index 000000000000..67574689ed9a --- /dev/null +++ b/scripts/openclaw-p6/app/packet/payload/guest/manifest.json @@ -0,0 +1,26 @@ +{ + "files": { + "application/guest-cli.py": "c7b11453c8bb0e80cbd20830a19028f8cac44bc15ab2f9a973bfb47af772bd71", + "application/memory-policy.py": "4ff6f0e9b1d84928115e4af7755359f74f501ef92b30999a6f3d2faada6ba1dc", + "application/run-application-guest.py": "faeb6a65aa52c8ac5943768c2148bf5d5115b93a090c1a4ec03cff9f63cf5a37", + "application/security/file-exec.c": "8d0707b88f72203b69e7b03e52887992eca12df2bd104dd27fca3ef3281aa2d5", + "application/security/fixture/index.js": "ea5c5fbceda9a536c64ef2c8a4509277b6aca2bf882307f865fa557beb6b171b", + "application/security/fixture/openclaw.plugin.json": "2d6cf08b7d9cd6c594ad2c8c1e8309748ca5ec5a864e5e2c667f40b87a18947f", + "application/security/fixture/package.json": "a00af8e500465b4ba10a1ccffd28f81b1ed049c4d9ce1a9030b011e0569ac5fb", + "application/security/mdwe.c": "02a21f72749fa26429ccbec58eb23bae65952d9db2dfedf389cab73c06b3de1b", + "application/trace-policy.py": "8372963b67a4343cccd416ce86afaa4efc9a7d34f383eae64c02034bd4badc8d", + "collect-evidence.py": "59a49d27f372b4f2bce4c7ad95b00bcc01708ea59fb17acf857d4c15c233a652", + "guest-prerequisites.py": "463a6cc56a7de19a49bc873cd630a7da28082337ab7f340809c43f4b2604050c", + "prepare-guest.py": "1737d66cda6ef635973bd5ddcffdd43c19357f5c4687d9d6bf90a4ffe248babf", + "shared/guest_result_transport.py": "1e0d155a7827e3fa44e3c377d935001a3db6f6546cdc397fa909c86be4dcdd7b", + "shared/kvm-preflight.py": "6ba9f17413342ddca66437bdb3c9b18d7c7357c1028470ebdebc689981e41ca5", + "shared/run-kvm-guest.py": "bca0eac25f6bd828f67c895c675fea6c8202583b1e6027f6a83f22212860ab42" + }, + "originalOwnersUnchanged": false, + "unchangedOwnerCount": 2, + "versionedApplicationAdapters": true, + "changedApplicationOwners": [ + "application/guest-cli.py", + "application/trace-policy.py" + ] +} diff --git a/scripts/openclaw-p6/app/packet/payload/guest/prepare-guest.py b/scripts/openclaw-p6/app/packet/payload/guest/prepare-guest.py new file mode 100644 index 000000000000..1532a3ed0df4 --- /dev/null +++ b/scripts/openclaw-p6/app/packet/payload/guest/prepare-guest.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python3 +"""Validate actual app inputs and render the immutable guest owner command only.""" +import argparse,base64,hashlib,json,platform,re,shlex,subprocess,sys +from pathlib import Path +HERE=Path(__file__).resolve().parent +CUT='4fa442e332745f1f58ccedd27106abdafcf4e019' +ROOT=Path('/home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1') +QUALIFIER_SHA='abac81c7af6762874c5954192a0f2eade85aaf902e668a9b3ce283faa8269fb2' + +def sha(p): + with Path(p).open('rb') as f:return hashlib.file_digest(f,'sha256').hexdigest() +def load(p):return json.loads(Path(p).read_text()) +def need(value,message): + if not value:raise ValueError(message) + +def main(): + p=argparse.ArgumentParser(description=__doc__) + for flag in ['artifact','build-receipt','root-admission','host-core-result']:p.add_argument('--'+flag,type=Path,required=True) + for flag in ['binary-sha256','manifest-sha256','build-receipt-sha256','root-admission-sha256','host-core-result-sha256']:p.add_argument('--'+flag,required=True) + p.add_argument('--prerequisites',type=Path,required=True);p.add_argument('--prerequisites-sha256',required=True) + p.add_argument('--label',required=True);a=p.parse_args() + need(sys.version_info >= (3,12),'Python3.12 or newer required') + need(platform.system()=='Linux' and platform.machine()=='x86_64','Native Linux x64 required') + need(re.fullmatch('[a-zA-Z0-9][a-zA-Z0-9._-]{0,63}',a.label),'Safe fresh label required') + for value in [a.binary_sha256,a.manifest_sha256,a.build_receipt_sha256,a.root_admission_sha256,a.host_core_result_sha256,a.prerequisites_sha256]:need(re.fullmatch('[0-9a-f]{64}',value),'Actual full SHA256 required') + for name,expected in load(HERE/'manifest.json')['files'].items():need(sha(HERE/name)==expected,'Staged harness changed: '+name) + need(sha(a.root_admission)==a.root_admission_sha256,'Root build admission changed') + admission=load(a.root_admission);built=load(a.build_receipt) + need(admission.get('schemaVersion')==1 and admission.get('lane')=='P6' and admission.get('decision')=='build-linux','Explicit root P6 build admission required') + need(admission['linuxCut']['commit']==CUT and admission['linuxCut']['status']=='landed-main' and admission['source']==str(ROOT/'source'),'Wrong root source admission') + need(sha(a.build_receipt)==a.build_receipt_sha256,'Actual build receipt changed') + need(built.get('status')=='built-unsigned' and built.get('phase')=='complete','Successful actual build required') + need(built['plan']['admissionSha256']==a.root_admission_sha256,'Build is not bound to root admission') + need(str(a.artifact.resolve())==admission['output']==built['plan']['output'],'Different actual admitted artifact') + variant={'js':'js-aot','c2':'c2','ts':'ts-aot','strong':'c2-linux-hardened'}[admission['variant']] + qualifier=ROOT/'qualification/qualify.py';need(sha(qualifier)==QUALIFIER_SHA,'Reviewed qualification v3 required') + work=ROOT/'application-guest-runs'/a.label;need(not work.exists(),'Fresh guest work required') + # Reuse the actual-artifact/source/runtime validator without running any workload. + command=[sys.executable,str(qualifier),'--artifact',str(a.artifact),'--binary-sha256',a.binary_sha256,'--manifest-sha256',a.manifest_sha256,'--build-receipt',str(a.build_receipt),'--build-receipt-sha256',a.build_receipt_sha256,'--lane','core','--out',str(ROOT/'qualification-results'/('guest-input-'+a.label))] + checked=subprocess.run(command,check=True,capture_output=True,text=True,env={'HOME':str(Path.home()),'PATH':'/usr/bin:/bin','LANG':'C.UTF-8'}) + proof=json.loads(checked.stdout);need(proof['mode']=='aot','Actual AOT app required') + need(sha(a.host_core_result)==a.host_core_result_sha256,'Host version result changed') + host=load(a.host_core_result) + need(host['binarySha256']==a.binary_sha256 and host['artifact']==str(a.artifact.resolve()) and host['source']==str(ROOT/'source') and host['platform']=='linux' and host['arch']=='x64','Host version identity differs') + rows=[r for r in host['commands'] if r['label']=='version'];need(len(rows)==1,'Exactly one actual host version command required');row=rows[0] + need(row['command']==[str(a.artifact.resolve()/'openclaw'),'--version'] and row['code']==0 and row.get('spawnError') is None,'Host version command did not succeed') + stdout=a.host_core_result.parent/'logs/version.stdout';need(Path(row['stdout'])==stdout,'Unexpected host version stdout path') + raw=stdout.read_text();need(0&2; exit 1; }; exit "$rc"; }\ntrap collect EXIT\n'+shlex.join(guest)+'\n' + out['guestShell']=body + print(json.dumps(out,indent=2)) + +if __name__=='__main__':main() diff --git a/scripts/openclaw-p6/app/packet/payload/guest/shared/guest_result_transport.py b/scripts/openclaw-p6/app/packet/payload/guest/shared/guest_result_transport.py new file mode 100644 index 000000000000..3ec81e806818 --- /dev/null +++ b/scripts/openclaw-p6/app/packet/payload/guest/shared/guest_result_transport.py @@ -0,0 +1,26 @@ +"""Non-TTY guest result transport; run_guest_vm keeps its serial.log contract.""" +from dataclasses import dataclass +from pathlib import Path + +@dataclass(frozen=True) +class GuestResultTransport: + qemu_args: list[str] + guest_redirect: str + metadata: dict[str, str] + artifacts: tuple[tuple[Path, str], ...] + +def prepare_result_transport(work: Path) -> GuestResultTransport: + port='org.openclaw.p6.result' + result=work/'serial.log' + console=work/'boot-console.log' + for path in [result,console]: path.touch(mode=0o600,exist_ok=False) + return GuestResultTransport( + qemu_args=['-serial','file:'+str(console),'-device','virtio-serial-pci', + '-chardev','file,id=p6-result,path='+str(result), + '-device','virtserialport,chardev=p6-result,name='+port], + guest_redirect='test -c /dev/virtio-ports/'+port+'; exec >/dev/virtio-ports/'+port+' 2>&1', + metadata={'kind':'virtio-serial/non-TTY','vmOwnerReceiveFile':'serial.log', + 'resultArtifact':'guest-result-stream.log','bootConsoleArtifact':'guest-boot-console.log', + 'guestPort':port}, + artifacts=((result,'guest-result-stream.log'),(console,'guest-boot-console.log')), + ) diff --git a/scripts/openclaw-p6/app/packet/payload/guest/shared/kvm-preflight.py b/scripts/openclaw-p6/app/packet/payload/guest/shared/kvm-preflight.py new file mode 100644 index 000000000000..e40558ff62ed --- /dev/null +++ b/scripts/openclaw-p6/app/packet/payload/guest/shared/kvm-preflight.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 +import fcntl,json,os,platform +result={'arch':platform.machine(),'kernel':platform.release(),'kvmDevice':'/dev/kvm','effectiveUid':os.geteuid(),'vmStarted':False} +fd=None +vm=None +try: + fd=os.open('/dev/kvm',os.O_RDWR|os.O_CLOEXEC) + result['apiVersion']=fcntl.ioctl(fd,0xAE00,0) + if result['apiVersion']!=12: raise RuntimeError('Unsupported KVM API version') + vm=fcntl.ioctl(fd,0xAE01,0) + result['emptyVmCreated']=vm>=0 + os.close(vm);vm=None + result['emptyVmClosed']=True + result['pass']=True +except (OSError,RuntimeError) as error: + result['pass']=False;result['error']=str(error) +finally: + if vm is not None: os.close(vm) + if fd is not None: os.close(fd) +print(json.dumps(result),flush=True) +raise SystemExit(0 if result['pass'] else 1) diff --git a/scripts/openclaw-p6/app/packet/payload/guest/shared/run-kvm-guest.py b/scripts/openclaw-p6/app/packet/payload/guest/shared/run-kvm-guest.py new file mode 100644 index 000000000000..728077e01ad2 --- /dev/null +++ b/scripts/openclaw-p6/app/packet/payload/guest/shared/run-kvm-guest.py @@ -0,0 +1,142 @@ +#!/usr/bin/env python3 +"""Run the synthetic x64 compiler suite in an offline, hardware-accelerated guest.""" +from pathlib import Path +import hashlib,json,os,platform,secrets,shutil,signal,subprocess,sys,time + +QMP_SCRIPT="import json,socket,sys\ns=socket.socket(socket.AF_UNIX,socket.SOCK_STREAM);s.settimeout(5);s.connect(sys.argv[1]);f=s.makefile('rwb',buffering=0)\ngreeting=json.loads(f.readline())\ndef command(name,number):\n f.write((json.dumps({'execute':name,'id':number})+'\\n').encode())\n while True:\n response=json.loads(f.readline())\n if response.get('id')==number:return response\ncommand('qmp_capabilities',1)\nresult=command('query-kvm',2)\nprint(json.dumps({'greeting':greeting,'queryKvm':result}))\ns.close()" + +class GuestInterrupted(Exception): + def __init__(self, signum): + self.signum=signum + super().__init__('Interrupted by '+signal.Signals(signum).name) + +def privileged_python(code, *args): + prefix=[sys.executable] if os.geteuid()==0 else ['sudo','-n','python3'] + return [*prefix,'-c',code,*map(str,args)] + +def run_guest_vm(command, work, overlay, report): + """Own the VM process through interruption, cleanup, and a durable result.""" + work=Path(work) + serial=work/'serial.log';qmp=work/'qmp.sock';pidfile=work/'qemu.pid' + state={'signal':None,'cleaning':False} + previous={} + child=None + def interrupted(signum, frame): + state['signal']=state['signal'] or signum + if not state['cleaning']: raise GuestInterrupted(signum) + qmp_script=QMP_SCRIPT + try: + for signum in [signal.SIGINT,signal.SIGTERM,signal.SIGHUP]: + previous[signum]=signal.signal(signum,interrupted) + with (work/'qemu.log').open('wb') as output: + child=subprocess.Popen(command,stdin=subprocess.DEVNULL,stdout=output,stderr=subprocess.STDOUT) + deadline=time.monotonic()+30 + while not qmp.exists() and child.poll() is None and time.monotonic()/dev/ttyS0 2>&1; set -eu; udevadm settle --timeout=30; mkdir -p /mnt/p6; mount -o ro,nodev,nosuid /dev/disk/by-label/P6PAYLOAD /mnt/p6; python3 /mnt/p6/guest-run.py']], + 'power_state':{'mode':'poweroff','delay':'now','timeout':30,'condition':True}} + user_data=work/'user-data';user_data.write_text('#cloud-config\n'+json.dumps(config,indent=2)+'\n') + meta_data=work/'meta-data';meta_data.write_text(json.dumps({'instance-id':nonce,'local-hostname':'p6-aot-synthetic'})+'\n') + seed=work/'seed.img' + subprocess.run(['cloud-localds',str(seed),str(user_data),str(meta_data)],check=True) + overlay=work/'guest.qcow2' + subprocess.run(['qemu-img','create','-f','qcow2','-F','qcow2','-b',str(image),str(overlay)],check=True) + subprocess.run(['qemu-img','resize',str(overlay),'8G'],check=True) + serial=work/'serial.log';serial.touch(mode=0o600,exist_ok=False) + qmp=work/'qmp.sock';pidfile=work/'qemu.pid' + command=['sudo','-n','env','-i','PATH=/usr/sbin:/usr/bin:/sbin:/bin','timeout','--signal=TERM','--kill-after=5s','600s','qemu-system-x86_64','-accel','kvm','-cpu','host','-smp','2','-m','4096','-display','none','-monitor','none','-pidfile',str(pidfile),'-serial','file:'+str(serial),'-qmp','unix:'+str(qmp)+',server=on,wait=off','-no-reboot','-nic','none','-drive','file='+str(overlay)+',if=virtio,format=qcow2','-drive','file='+str(seed)+',if=virtio,format=raw,readonly=on','-drive','file='+str(payload_image)+',if=virtio,format=raw,readonly=on'] + report={'nonce':nonce,'command':command,'cloudImage':{'url':url,'sha256':digest},'compilerSha256':compiler_sha,'hostKvmPreflight':preflight_result,'pass':False,'applicationQualification':False} + report=run_guest_vm(command,work,overlay,report) + for name in ['serial.log','qemu.log','qmp.stdout','qmp.stderr']: + if (work/name).exists(): shutil.copy2(work/name,proof/('guest-'+name)) + (proof/'guest-result.json').write_text(json.dumps(report,indent=2)+'\n') + print('P6_KVM_GUEST_RESULT '+json.dumps(report),flush=True) + return 0 if report['pass'] else 1 + +if __name__=='__main__': raise SystemExit(main()) diff --git a/scripts/openclaw-p6/app/packet/payload/manifest.json b/scripts/openclaw-p6/app/packet/payload/manifest.json new file mode 100644 index 000000000000..a3256deb5554 --- /dev/null +++ b/scripts/openclaw-p6/app/packet/payload/manifest.json @@ -0,0 +1,70 @@ +{ + "sourceCommit": "4fa442e332745f1f58ccedd27106abdafcf4e019", + "status": "prepared-not-admitted", + "nativeCompilerHashes": "pending", + "applicationBuilt": false, + "files": { + "admission-inputs/P0-artifacts.json": "f60309fc44e418cfaf02df998ada40cfab89c10f773df0c09eb512775d0d8e83", + "admission-inputs/p0-reference.json": "1603c0262605fcb488ecbbd07a163b9afb5487456aca01b6574aaa6bac9296c9", + "admission-inputs/source-preparation.json": "dd8492221cf6bce907a90b392a24289a3c8e6f1e655e47dba174d51ccd0710e9", + "admission-templates/c2-off.json": "8c3ad5cf6d473092c3ee0145afcae576b52288e822cb3e6485e429293b0bf7a3", + "admission-templates/js.json": "8ffbfe9f0bab1a910a8e40e0eb71037db32ed242bd00f12932020e6ef1d4d120", + "admission-templates/ts.json": "f6fcd850b680c5f9b81ac77763afbba5dc67c6ff092b610a3623197faa2c25db", + "adopt-compilers.py": "97585382c7ee80321fd26595220120b2d42f855575059d283b4c58cb93362a27", + "build-prep/artifact-contract.mjs": "bac5e4b00d4a457941c1d2082f280d4dca544b3c77e4fe9a6a47f9f399d669b7", + "build-prep/build-linux.py": "9cbb455e83922a84f929c51f161de115ba1988ccd3f796d4e071051fca45522a", + "build-prep/select-plugins.mjs": "14b4a6c3ca1415fcf31bd3f1d71f1e33dff4e4ba1290b09fa929652121199ee9", + "cron-fixture/cron-cli-fixture.sh": "958adbfa641e24736306fd23a5cb3a5e2bfda2c4502889ca593c33da368be4a2", + "cron-fixture/inputs.json": "fd559a9b5f566b19e155427ec267e512a5d7ed5cfd7b0ef89b460711b9017b36", + "cron-fixture/run-native.sh": "e7201d5ec00c6759fa937eeb557ca7c20ae4e309a2b05d4d4dd105a9fcc28308", + "guest/application/guest-cli.py": "c7b11453c8bb0e80cbd20830a19028f8cac44bc15ab2f9a973bfb47af772bd71", + "guest/application/memory-policy.py": "4ff6f0e9b1d84928115e4af7755359f74f501ef92b30999a6f3d2faada6ba1dc", + "guest/application/run-application-guest.py": "faeb6a65aa52c8ac5943768c2148bf5d5115b93a090c1a4ec03cff9f63cf5a37", + "guest/application/security/file-exec.c": "8d0707b88f72203b69e7b03e52887992eca12df2bd104dd27fca3ef3281aa2d5", + "guest/application/security/fixture/index.js": "ea5c5fbceda9a536c64ef2c8a4509277b6aca2bf882307f865fa557beb6b171b", + "guest/application/security/fixture/openclaw.plugin.json": "2d6cf08b7d9cd6c594ad2c8c1e8309748ca5ec5a864e5e2c667f40b87a18947f", + "guest/application/security/fixture/package.json": "a00af8e500465b4ba10a1ccffd28f81b1ed049c4d9ce1a9030b011e0569ac5fb", + "guest/application/security/mdwe.c": "02a21f72749fa26429ccbec58eb23bae65952d9db2dfedf389cab73c06b3de1b", + "guest/application/trace-policy.py": "8372963b67a4343cccd416ce86afaa4efc9a7d34f383eae64c02034bd4badc8d", + "guest/collect-evidence.py": "59a49d27f372b4f2bce4c7ad95b00bcc01708ea59fb17acf857d4c15c233a652", + "guest/guest-prerequisites.py": "463a6cc56a7de19a49bc873cd630a7da28082337ab7f340809c43f4b2604050c", + "guest/manifest.json": "7c731171b9247059a043c2360224d6e92642f041372c3f706fac55cb7d9319ee", + "guest/prepare-guest.py": "1737d66cda6ef635973bd5ddcffdd43c19357f5c4687d9d6bf90a4ffe248babf", + "guest/shared/guest_result_transport.py": "1e0d155a7827e3fa44e3c377d935001a3db6f6546cdc397fa909c86be4dcdd7b", + "guest/shared/kvm-preflight.py": "6ba9f17413342ddca66437bdb3c9b18d7c7357c1028470ebdebc689981e41ca5", + "guest/shared/run-kvm-guest.py": "bca0eac25f6bd828f67c895c675fea6c8202583b1e6027f6a83f22212860ab42", + "measure-command.py": "2fa495f4727a351f6cee078b403ac064610ce90ed339311f55c40a567463e4b7", + "native-prep.py": "5c6932de85c113f7b7d5b2a25780dc0cf103bd92352be084fb64561075bebf06", + "preserve.py": "c6d78862f9921af842c0eec4eb3e9a2850426847859bf503ff08112c95b95456", + "qualification/README.md": "8e2eefd1160e26d374cb3cf6c0328cd73d92953fab1ae7d119d3c920cdb2ec33", + "qualification/docker-image.py": "5560077a50bcfd0f5a5716d555519805c8f6b158c90b756be499b62ec4c5717b", + "qualification/harness/Dockerfile.aot": "dd745181bbcd98ea8301a532721f08ea8ca34e395283c0bee1d9bde0f2d1f231", + "qualification/harness/analyze-workers.py": "ba2e5187c3dda4614c35e51aa6e0e1079840b372ecfa50cf8f2009804b008086", + "qualification/harness/analyze-zero-js.py": "cd5ac0436fa1ffeebcbaa4b760c93f2cdc94e31dfa4c26d9ca6529ac0d43a621", + "qualification/harness/aot-entry.mjs": "ccb32c3d2a895ed5a7bbf9a5966f38a0ea1e70e4b41e65d838285ef93f61510b", + "qualification/harness/capability-runner.mjs": "177fe4fc33cd7cda89024a027d22f8749f9f14f7f38c359a6776796ff0ed155f", + "qualification/harness/config-roundtrip.mjs": "511d9140896da1cff71e116a428a985b7d1f695bd07b0423afebac6f1601d6b0", + "qualification/harness/core-runner.mjs": "56a4e32c40c2bf4e84a12f03f318acf62a9e98c38454ee055550f6cfda0876b0", + "qualification/harness/elf-floor.py": "ec0a288f782b6786105f7801d62f32f2d44d23659655286008004fb59cbf2932", + "qualification/harness/fixture-config.mjs": "3cd13d2aeb10982bbda7198fbd6a451c57d24b184de5f07b892d67b63c3f5120", + "qualification/harness/gateway-readiness.mjs": "a007aa71fd55a888d0b159ee4ab51cc63a35492586c87769086d95a50e3d0759", + "qualification/harness/kitchen-sink-pin.json": "6e94c782845e34fcd4ded796d26202b7eb1d53bec1ff0dff3f62fa416f936af4", + "qualification/harness/legacy/capability-provider.mjs": "3b28c3bc5a5b892e2b14164a8633671c444257448dbfcfffd8812fc47a5301b4", + "qualification/harness/legacy/native_trace.py": "c1fda60c8a74b76811555ee895e1df0a5083951a53df38f35a7a18de8df15607", + "qualification/harness/openclaw-launcher": "fc343d0173e513aa7e74bfc1943d385beaab4ced57447ad7ea2023bdad2aee09", + "qualification/manifest.json": "d6df4521dfc2cabda9cbda41fce4dc4882606fc0ed8be8438828af16beedeea4", + "qualification/qualify.py": "f20cbd54444d1cbf673bec08722fd04f982db6db0797522ced529cc9e9bf4ff5", + "qualification/source-contract.json": "c1cffbee88de6e49601c68e753a0456e938a1ed2fc503640d43c7f942fea838b", + "runtime-controller.py": "659dac44a521dffa8111001b4684d02374b996b5e29330f01c00d3cae92ee0d7", + "stage.py": "29ad1ad089f28720ff1ac2c3036c5153b873856698ecb18122411a0c0d0db277", + "qualification/harness/process-stop.mjs": "68c2e651f829a424a7fc2c2b7d44a05caa23bc2c4f6a047296ca5529f3afdaec", + "qualification/teams-fetched/assert-teams.py": "47b32e68002abdf7649a098c4783603f30eb53f43118fb425485e5e6c5976ed4", + "qualification/teams-fetched/boundary-reference.json": "4e6821dbf12444a7d1655dccf74579b25e3f56f52c2bfdb1c3043324ebbf97ad", + "qualification/teams-fetched/budget.json": "ad49da8949d9b95aa78c1369daef220016f01596abbee2dea7f62ce7b015da4a", + "qualification/teams-fetched/config.template.json": "6eb88933badf9e833be2c47bebb0a0667f441efdb6ae3862819be5dffca0cc6e", + "qualification/teams-fetched/pin.json": "4c9c165d8367dc62df059d84cceef38d40c933c8207793a5d5d41791166eeb59", + "qualification/teams-fetched/provenance.json": "ffde3e07d67d4ecd6199ee5bd90f5e595d805e82b05c05572a79b1cb9bc34942", + "qualification/teams-fetched.py": "e1939f691dfda4a5ed16694e9ca59e644b548954cb754596d2972cd557704886", + "qualification/harness/clawhub-artifact-assertions.mjs": "ebbafe3f5d0c09c5b21a7669d5dc64b02ece869af257faab775effb06d058197" + } +} diff --git a/scripts/openclaw-p6/app/packet/payload/measure-command.py b/scripts/openclaw-p6/app/packet/payload/measure-command.py new file mode 100644 index 000000000000..76c458785259 --- /dev/null +++ b/scripts/openclaw-p6/app/packet/payload/measure-command.py @@ -0,0 +1,106 @@ +#!/usr/bin/env python3 +"""Linux only; collect direct-executable wall/CPU/peak RSS without asserting application correctness.""" +import argparse, datetime, hashlib, json, math, os, pathlib, platform, signal, subprocess, time +p=argparse.ArgumentParser() +p.add_argument('--label',required=True) +p.add_argument('--out',required=True) +p.add_argument('--timeout',type=float,default=180) +p.add_argument('--cleanup-grace-seconds',type=float) +p.add_argument('command',nargs=argparse.REMAINDER) +a=p.parse_args() +cmd=a.command[1:] if a.command[:1]==['--'] else a.command +if platform.system()!='Linux' or not cmd: p.error('requires Linux and a command after --') +if a.cleanup_grace_seconds is not None and not (math.isfinite(a.cleanup_grace_seconds) and 0 < a.cleanup_grace_seconds <= 3600): + p.error('cleanup grace must be finite and between 0 and 3600 seconds') +out=pathlib.Path(a.out).resolve() +out.mkdir(parents=True,exist_ok=False) +timefile=out/'time.txt' +exe=pathlib.Path(cmd[0]) +receipt={'label':a.label,'at':datetime.datetime.now(datetime.timezone.utc).isoformat(), + 'arch':platform.machine(),'kernel':platform.release(),'command':cmd, + 'executableSha256':hashlib.file_digest(exe.open('rb'),'sha256').hexdigest() if exe.is_file() else None, + 'scope':'GNU time -v command plus reaped descendants; not exclusive gateway CPU'} +def signal_group(pgid, sig): + try: os.killpg(pgid,sig) + except ProcessLookupError: pass + +def live_group(pgid): + # An orphaned zombie can retain the group ID under a non-reaping container + # init; it has no work left to stop and must not trigger a false forced kill. + for process in pathlib.Path('/proc').iterdir(): + if not process.name.isdigit():continue + try: fields=(process/'stat').read_text().rsplit(') ',1)[1].split() + except (FileNotFoundError,ProcessLookupError):continue + if int(fields[2])==pgid and fields[0] not in ['Z','X']:return True + return False + +def stop_group(child, grace=5): + # GNU time may exit on TERM while its workload ignores it. Keep group custody + # for the full bounded grace, then send KILL independently of wrapper state. + signal_group(child.pid,signal.SIGTERM) + deadline=time.monotonic()+grace + while time.monotonic()=3.12 required') + if root!=Path.home()/'.cache/oc-ty-ext/P6/app-x64-final-r4-v1':p.error('Use the fresh owner root app-x64-final-r4-v1') + manifest=load(root/'manifest.json') + for name,expected in manifest['files'].items(): + if sha(root/name)!=expected:p.error('Staged input changed: '+name) + if shutil.disk_usage(root).free<25_000_000_000:p.error('Less than25GB free') + index=PHASES.index(a.phase) + if index and load(root/'prep-receipts'/PHASES[index-1]/'result.json')['status']!='PASS':p.error('Previous preparation phase must pass') + receipt=root/'prep-receipts'/a.phase;receipt.mkdir(parents=True,exist_ok=False) + source=root/'source';reference=load(root/'admission-inputs/source-preparation.json') + env={'HOME':str(root/'home'),'TMPDIR':str(root/'tmp'),'PATH':f'{root}/opt/node/bin:{root}/opt/bin:/usr/local/bin:/usr/bin:/bin','LANG':'C.UTF-8','LC_ALL':'C.UTF-8','CI':'1','NO_COLOR':'1','NODE_DISABLE_COMPILE_CACHE':'1','UV_THREADPOOL_SIZE':'2','XDG_CACHE_HOME':str(root/'cache'),'PNPM_HOME':str(root/'opt/bin'),'NPM_CONFIG_CACHE':str(root/'cache/npm'),'NPM_CONFIG_USERCONFIG':'/dev/null','NPM_CONFIG_GLOBALCONFIG':'/dev/null','GIT_CONFIG_GLOBAL':'/dev/null','GIT_CONFIG_SYSTEM':'/dev/null','GIT_TERMINAL_PROMPT':'0','GIT_ASKPASS':'/bin/false','SSH_ASKPASS':'/bin/false','OPENCLAW_STATE_DIR':str(root/'state'),'OPENCLAW_CONFIG_PATH':str(root/'state/openclaw.json'),'OPENCLAW_NO_RESPAWN':'1'} + for name in ['home','tmp','cache','state','downloads','opt']: (root/name).mkdir(exist_ok=True) + result={'phase':a.phase,'status':'FAIL','started':datetime.datetime.now(datetime.timezone.utc).isoformat(),'sourceCommit':CUT,'applicationBuildStarted':False,'aotAdmitted':False,'commands':[]} + node=root/'opt/node/bin/node';pnpm=root/'opt/pnpm/bin/pnpm.mjs' + def probe(args):return subprocess.check_output(list(map(str,args)),cwd=source,env=env,text=True,timeout=60).strip() + def source_ok(): + assert probe(['git','rev-parse','HEAD'])==CUT + assert not probe(['git','status','--porcelain','--untracked-files=no']) + for name,expected in reference['files'].items():assert sha(source/name)==expected,name + def run(label,command,cwd,timeout=3600): + result['commands'].append({'label':label,'command':list(map(str,command))}) + oldargv,oldenv,oldcwd=sys.argv,dict(os.environ),Path.cwd() + handlers={sig:signal.signal(sig,interrupted) for sig in [signal.SIGINT,signal.SIGTERM,signal.SIGHUP]} + try: + sys.argv=[str(root/'measure-command.py'),'--label',label,'--out',str(receipt/label),'--timeout',str(timeout),'--',*map(str,command)] + os.environ.clear();os.environ.update(env);os.chdir(cwd) + try:runpy.run_path(root/'measure-command.py',run_name='__main__') + except SystemExit as done: + if done.code not in [None,0]:raise RuntimeError(f'{label} failed with exit {done.code}') + finally: + os.chdir(oldcwd);os.environ.clear();os.environ.update(oldenv);sys.argv=oldargv + for sig,handler in handlers.items():signal.signal(sig,handler) + outer_handlers={sig:signal.signal(sig,interrupted) for sig in [signal.SIGINT,signal.SIGTERM,signal.SIGHUP]} + try: + if a.phase=='clone': + assert not source.exists() + run('clone',['/usr/bin/nice','-n','10','git','clone','--no-checkout','--depth=512','--single-branch','--branch','main','--no-tags','https://github.com/openclaw/openclaw.git',source],root,1800) + # Fetch the frozen cut explicitly as well, so main advancement cannot select a different checkout. + run('fetch-cut',['git','fetch','--depth=512','--no-tags','origin',CUT],source,1800) + run('checkout',['git','checkout','--detach',CUT],source,1800) + source_ok() + assert not (source/'.git/objects/info/alternates').exists() + assert not any((source/'.git/objects/pack').glob('*.promisor')) + assert len(reference['linuxCut']['requiredAncestors'])==29 + for ancestor in reference['linuxCut']['requiredAncestors']: + subprocess.run(['git','merge-base','--is-ancestor',ancestor,CUT],cwd=source,env=env,check=True,timeout=60) + main_sha=probe(['git','rev-parse','refs/remotes/origin/main']) + subprocess.run(['git','merge-base','--is-ancestor',CUT,main_sha],cwd=source,env=env,check=True,timeout=60) + result['nativeSource']={'commit':CUT,'mainRef':'refs/remotes/origin/main','mainRefSha':main_sha,'requiredAncestors':reference['linuxCut']['requiredAncestors'],'externalAlternates':False,'shallow':probe(['git','rev-parse','--is-shallow-repository'])} + else: + source_ok() + if a.phase=='toolchain': + assert not (root/'opt/node').exists() and not (root/'opt/pnpm').exists() + name='node-v26.12.1-linux-x64.tar.xz';base='https://nodejs.org/dist/v26.12.1/' + with urllib.request.urlopen(base+'SHASUMS256.txt',timeout=30) as f:lines=f.read().decode().splitlines() + expected=[line.split()[0] for line in lines if line.split()[-1]==name];assert len(expected)==1 + archive=root/'downloads'/name + with urllib.request.urlopen(base+name,timeout=30) as f,archive.open('xb') as target:shutil.copyfileobj(f,target) + assert sha(archive)==expected[0] + unpack=root/'downloads/node-unpack';unpack.mkdir() + with tarfile.open(archive) as t:t.extractall(unpack,filter='data') + (unpack/'node-v26.12.1-linux-x64').rename(root/'opt/node') + assert probe([node,'--version'])=='v26.12.1' + manager=load(source/'package.json')['packageManager'];prefix='pnpm@12.15.0+sha512.';assert manager.startswith(prefix) + archive=root/'downloads/pnpm-12.15.0.tgz' + with urllib.request.urlopen('https://registry.npmjs.org/pnpm/-/pnpm-12.15.0.tgz',timeout=30) as f,archive.open('xb') as target:shutil.copyfileobj(f,target) + assert sha(archive,'sha512')==manager[len(prefix):] + unpack=root/'downloads/pnpm-unpack';unpack.mkdir() + with tarfile.open(archive) as t:t.extractall(unpack,filter='data') + (unpack/'package').rename(root/'opt/pnpm');(root/'opt/bin').mkdir() + launcher=root/'opt/bin/pnpm' + launcher.write_text(f'#!/bin/sh\nexec {shlex.quote(str(node))} {shlex.quote(str(pnpm))} "$@"\n') + launcher.chmod(0o755) + assert probe([node,pnpm,'--version'])=='12.15.0' + assert probe(['pnpm','--version'])=='12.15.0' + native=root/'opt/pnpm/pnpm-native' + with native.open('rb') as stream:header=stream.read(20) + assert header[:6]==b'\x7fELF\x02\x01' and int.from_bytes(header[18:20],'little')==62 + result['buildNode']={'path':str(node),'sha256':sha(node),'version':'26.12.1'} + result['pnpm']={'path':str(pnpm),'sha256':sha(pnpm),'version':'12.15.0','archiveSha512':sha(archive,'sha512'),'nativeSha256':sha(native),'nativeResolution':'official pnpm.mjs + placeholder; signature/integrity checks unchanged'} + elif a.phase=='install':run('frozen-install',['/usr/bin/nice','-n','10',node,pnpm,'install','--frozen-lockfile'],source,3600) + elif a.phase=='runtime': + run('pnpm-build',['/usr/bin/nice','-n','10',node,pnpm,'build'],source,7200) + assert load(source/'dist/build-info.json')['commit']==CUT + result['distBuildInfoSha256']=sha(source/'dist/build-info.json') + elif a.phase=='boundary':run('ts-boundary',['/usr/bin/nice','-n','10',node,'--import','./scripts/tsx.mjs','scripts/prepare-extension-package-boundary-artifacts.mts'],source,3600) + elif a.phase=='plugins': + compiler=root/'compilers/standard/bun';records=load(root/'admission-inputs/compiler-records.json') + assert records['status']=='native-compilers-adopted-not-app-admitted' and sha(compiler)==records['cb-standard']['sha256'] + run('select-plugins',['/usr/bin/nice','-n','10',compiler,'--no-env-file','--no-install',root/'build-prep/select-plugins.mjs',source,root/'admission-inputs/plugins'],source,1800) + result['plugins']={name:sha(root/'admission-inputs/plugins'/name) for name in ['desktop.json','all.json','plugin-selection.json']} + result['buildNode']=load(root/'prep-receipts/toolchain/result.json')['buildNode'] + result['nativeSource']=load(root/'prep-receipts/clone/result.json')['nativeSource'] + result['distBuildInfoSha256']=sha(source/'dist/build-info.json') + + source_ok() + result['status']='PASS' + except Exception as error:result['error']=f'{type(error).__name__}: {error}' + finally: + result['finished']=datetime.datetime.now(datetime.timezone.utc).isoformat() + (receipt/'result.json').write_text(json.dumps(result,indent=2)+'\n') + for sig,handler in outer_handlers.items():signal.signal(sig,handler) + print('P6_FINAL_NATIVE_PREP '+json.dumps(result),flush=True) + return 0 if result['status']=='PASS' else 1 + +if __name__=='__main__':raise SystemExit(main()) diff --git a/scripts/openclaw-p6/app/packet/payload/preserve.py b/scripts/openclaw-p6/app/packet/payload/preserve.py new file mode 100644 index 000000000000..b1a6f747cd94 --- /dev/null +++ b/scripts/openclaw-p6/app/packet/payload/preserve.py @@ -0,0 +1,218 @@ +#!/usr/bin/env python3 +"""Preserve a successful P6 native artifact, then verify its relocated copy.""" +import argparse +import copy +import hashlib +import json +import os +from pathlib import Path, PurePosixPath +import stat +import subprocess +import tarfile + +SOURCE_COMMIT = '4fa442e332745f1f58ccedd27106abdafcf4e019' + + +def require(ok, message): + if not ok: + raise ValueError(message) + + +def sha(filename): + digest = hashlib.sha256() + with Path(filename).open('rb') as stream: + for chunk in iter(lambda: stream.read(1024 * 1024), b''): + digest.update(chunk) + return digest.hexdigest() + + +def read_pinned(filename, digest): + data = Path(filename).read_bytes() + require(hashlib.sha256(data).hexdigest() == digest, 'Input hash mismatch: ' + str(filename)) + return data + + +def write_json(filename, value): + Path(filename).write_text(json.dumps(value, indent=2) + '\n') + + +def contained(root, child): + try: + Path(child).relative_to(root) + return True + except ValueError: + return False + + +def inventory(root): + """Transport metadata only; content/tree hashes remain with the source owner.""" + rows = [{'path': '.', 'kind': 'directory', 'mode': stat.S_IMODE(root.stat().st_mode)}] + def visit(directory): + for item in sorted(directory.iterdir(), key=lambda p: p.name): + info = item.lstat() + row = {'path': item.relative_to(root).as_posix(), 'mode': stat.S_IMODE(info.st_mode)} + if stat.S_ISLNK(info.st_mode): + row.update(kind='symlink', target=os.readlink(item)) + require(not Path(row['target']).is_absolute() and contained(root, item.resolve(strict=True)), + 'Artifact link is not relocatable: ' + row['path']) + elif stat.S_ISDIR(info.st_mode): + row['kind'] = 'directory' + elif stat.S_ISREG(info.st_mode): + row.update(kind='file', size=info.st_size) + else: + raise ValueError('Unsupported artifact member: ' + row['path']) + rows.append(row) + if row['kind'] == 'directory': + visit(item) + visit(root) + return rows + + +def inputs(plan_file, plan_sha, result_file, result_sha): + plan_data = read_pinned(plan_file, plan_sha) + result_data = read_pinned(result_file, result_sha) + plan, result = json.loads(plan_data), json.loads(result_data) + require(result['status'] == 'built-unsigned' and result['phase'] == 'complete' and + result['measurement']['exitCode'] == 0, 'No successful completed native build') + require(result['plan'] == plan, 'Result does not contain the exact native plan') + require(plan['platform'] == 'linux' and plan['arch'] == 'x64' and + plan['sourceProof']['commit'] == SOURCE_COMMIT, 'Wrong native target or final source cut') + return plan_data, result_data, plan, result + + +def check_artifact(plan_file, plan, result, checker, node, logs): + checker, node = Path(checker).resolve(), Path(node).resolve() + require(sha(checker) == plan['artifactCheckerSha256'], 'Artifact checker changed') + owner = Path(plan['source']) / 'scripts/lib/bun-standalone-contract.mjs' + require(sha(owner) == result['artifact']['contractOwnerSha256'], 'Source contract owner changed') + env = {'PATH': str(node.parent) + ':/usr/bin:/bin', 'HOME': str(logs), + 'TMPDIR': str(logs), 'LANG': 'C.UTF-8', 'NODE_NO_WARNINGS': '1'} + process = subprocess.run([str(node), str(checker), str(plan_file)], env=env, + cwd=logs, capture_output=True, text=True, timeout=1800) + (logs / 'checker.stdout').write_text(process.stdout) + (logs / 'checker.stderr').write_text(process.stderr) + require(process.returncode == 0, 'Artifact owner check failed; see checker.stderr') + actual = json.loads(process.stdout) + require(actual == result['artifact'], 'Relocated owner facts differ from native result') + return actual + + +def fresh_output(output, protected): + output = Path(output).resolve() + require(not output.exists(), 'Output already exists') + require(all(not contained(Path(root).resolve(), output) for root in protected), + 'Preservation output must be outside source and artifact') + output.mkdir(parents=True) + return output + + +def pack(args): + plan_data, result_data, plan, result = inputs(args.plan, args.plan_sha256, + args.result, args.result_sha256) + artifact = Path(plan['output']).resolve(strict=True) + require(artifact.is_dir() and not Path(plan['output']).is_symlink(), 'Artifact root is not a directory') + require(sha(plan['buildNode']['path']) == plan['buildNode']['sha256'], 'Admitted native Node changed') + output = fresh_output(args.out, [artifact, plan['source']]) + for name, data in [('native-plan.json', plan_data), ('native-result.json', result_data)]: + (output / name).write_bytes(data) + facts = check_artifact(output / 'native-plan.json', plan, result, args.checker, + plan['buildNode']['path'], output) + metadata = inventory(artifact) + write_json(output / 'artifact-metadata.json', metadata) + archive = output / 'artifact.tar' + with tarfile.open(archive, 'w', dereference=False, format=tarfile.PAX_FORMAT) as bundle: + bundle.add(artifact, arcname='artifact', recursive=True) + for name in ['native-plan.json', 'native-result.json', 'artifact-metadata.json']: + bundle.add(output / name, arcname=name, recursive=False) + require(sha(args.plan) == args.plan_sha256 and sha(args.result) == args.result_sha256, + 'Native plan/result changed during preservation') + receipt = {'status': 'preserved-not-downloaded', 'sourceCommit': SOURCE_COMMIT, + 'archive': str(archive), 'archiveSha256': sha(archive), + 'archiveBytes': archive.stat().st_size, 'helperSha256': sha(__file__), + 'nativePlanSha256': args.plan_sha256, 'nativeResultSha256': args.result_sha256, + 'checkerSha256': plan['artifactCheckerSha256'], + 'contractOwnerSha256': facts['contractOwnerSha256'], + 'manifestSha256': facts['manifestSha256'], 'executable': facts['executable'], + 'runtime': facts['runtime'], 'artifactMetadataSha256': sha(output / 'artifact-metadata.json')} + write_json(output / 'transport.json', receipt) + return receipt + + +def validate_members(members): + names, links = set(), set() + allowed = {'native-plan.json', 'native-result.json', 'artifact-metadata.json'} + for member in members: + name = PurePosixPath(member.name) + require(not name.is_absolute() and '..' not in name.parts and member.name not in names, + 'Unsafe or duplicate archive path') + require(name.parts and (name.parts[0] == 'artifact' or str(name) in allowed), 'Unexpected archive root') + require(member.isdir() or member.isfile() or member.issym() or member.islnk(), 'Special archive member') + names.add(member.name) + if member.issym(): + target = PurePosixPath(member.linkname) + require(not target.is_absolute(), 'Absolute archive symlink') + normalized = os.path.normpath(str(name.parent / target)) + require(normalized == 'artifact' or normalized.startswith('artifact/'), 'Escaping archive symlink') + links.add(member.name) + if member.islnk(): + target = PurePosixPath(member.linkname) + require(not target.is_absolute() and '..' not in target.parts and target.parts[0] == 'artifact', + 'Escaping archive hardlink') + for name in names: + require(not any(str(parent) in links for parent in PurePosixPath(name).parents), + 'Archive member traverses a symlink') + + +def verify(args): + receipt = json.loads(read_pinned(args.transport, args.transport_sha256)) + require(receipt['status'] == 'preserved-not-downloaded' and + receipt['sourceCommit'] == SOURCE_COMMIT and receipt['helperSha256'] == sha(__file__), + 'Wrong transport receipt or helper') + require(args.archive_sha256 == receipt['archiveSha256'] and + sha(args.archive) == receipt['archiveSha256'] and + Path(args.archive).stat().st_size == receipt['archiveBytes'], 'Archive transfer differs') + source = Path(args.source).resolve(strict=True) + head = subprocess.check_output(['git', '-C', str(source), 'rev-parse', 'HEAD'], text=True).strip() + require(head == SOURCE_COMMIT, 'Local carrier is not the final source cut') + output = fresh_output(args.out, [source]) + with tarfile.open(args.archive, 'r:') as bundle: + validate_members(bundle.getmembers()) + # Validated paths and links above; retain exact modes across Python defaults. + if hasattr(tarfile, 'fully_trusted_filter'): + bundle.extractall(output, filter=tarfile.fully_trusted_filter) + else: + bundle.extractall(output) + plan_data, result_data, native_plan, result = inputs(output / 'native-plan.json', receipt['nativePlanSha256'], + output / 'native-result.json', receipt['nativeResultSha256']) + require(sha(output / 'artifact-metadata.json') == receipt['artifactMetadataSha256'], 'Metadata transfer differs') + require(inventory(output / 'artifact') == json.loads((output / 'artifact-metadata.json').read_text()), + 'Artifact paths, kinds, modes, sizes, or link targets changed') + derived = copy.deepcopy(native_plan) + derived['source'], derived['output'] = str(source), str(output / 'artifact') + write_json(output / 'local-check-plan.json', derived) + facts = check_artifact(output / 'local-check-plan.json', derived, result, args.checker, args.node, output) + report = {'status': 'downloaded-and-verified', 'applicationQualified': False, + 'sourceCommit': SOURCE_COMMIT, 'archiveSha256': receipt['archiveSha256'], + 'nativePlanSha256': receipt['nativePlanSha256'], 'nativeResultSha256': receipt['nativeResultSha256'], + 'localCheckPlanSha256': sha(output / 'local-check-plan.json'), + 'derivedPlanChangedKeys': ['source', 'output'], 'facts': facts, + 'artifact': str(output / 'artifact'), 'localNodeSha256': sha(args.node)} + write_json(output / 'verification.json', report) + return report + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + commands = parser.add_subparsers(dest='mode', required=True) + native = commands.add_parser('pack') + for name in ['plan', 'plan-sha256', 'result', 'result-sha256', 'checker', 'out']: + native.add_argument('--' + name, required=True) + local = commands.add_parser('verify') + for name in ['archive', 'archive-sha256', 'transport', 'transport-sha256', 'source', 'checker', 'node', 'out']: + local.add_argument('--' + name, required=True) + args = parser.parse_args() + print(json.dumps(pack(args) if args.mode == 'pack' else verify(args), indent=2)) + + +if __name__ == '__main__': + main() diff --git a/scripts/openclaw-p6/app/packet/payload/qualification/README.md b/scripts/openclaw-p6/app/packet/payload/qualification/README.md new file mode 100644 index 000000000000..c55a597a393a --- /dev/null +++ b/scripts/openclaw-p6/app/packet/payload/qualification/README.md @@ -0,0 +1,193 @@ +# Final native x64 qualification preparation + +Preparation only. No artifact is assumed to exist and no application, source +helper, Docker build, E2E lane, remote command or lease allocation has run here. +The native root is /home/runner/.cache/oc-ty-ext/P6/app-x64-final-r4-v1, source=root/source +at exact4fa442e332745f1f58ccedd27106abdafcf4e019, Node=root/opt/node/bin/node26.12.1. +The application guest/kernel lane is separate and is not provided by this bundle. + +## Immutable inputs and actual-artifact gate + +payload/harness contains12 unchanged existing P6 harness owner files and2 explicitly recorded adaptations and +needed direct dependencies. owner-inputs.json pins their original paths/bytes; +source-contract.json pins matching25a test imports and existing Docker lane +owners. Native staging uses a new root/qualification-harness-v2 directory; it +never changes root/manifest.json, original helpers, source or artifacts. + +qualify.py requires actual artifact path, executable and manifest SHA256 values, +and the actual successful build-driver receipt path+SHA256. It rejects missing +or wrong bytes, source/target mismatch, stale source/test owners, non-native x64, +wrong Node or reused outputs. The existing source-owned runtime descriptor must +match the complete current sidecar tree and accepted build receipt. Values are +supplied only after a real build/acceptance; no example invents artifact hashes. +Without --run it prints a plan, not a qualification pass. With --run it execs the +unchanged lane owner so process/signal cleanup remains with that owner. + +Each output must be a fresh root/qualification-results/