{"record":{"id":"b08175da70308860","repo":"Hmbown/CodeWhale","slug":"runtime-contract-measurement-failed-with-exit-code","errorCode":null,"errorMessage":"runtime-contract measurement failed with exit code {proc.returncode}","messagePattern":"runtime-contract measurement failed with exit code (.+?)","errorType":"exception","errorClass":"RuntimeContractError","httpStatus":null,"severity":"error","filePath":"scripts/check-runtime-contract-budget.py","lineNumber":405,"sourceCode":"        temporary_path.unlink(missing_ok=True)\n        raise\n\n\ndef run_measurement() -> dict[str, Any]:\n    env = os.environ.copy()\n    env[\"CARGO_NET_OFFLINE\"] = \"true\"\n    proc = subprocess.run(\n        [sys.executable, str(MEASURE_SCRIPT)],\n        cwd=REPO_ROOT,\n        env=env,\n        capture_output=True,\n        text=True,\n        check=False,\n    )\n    sys.stderr.write(proc.stderr)\n    if proc.returncode != 0:\n        sys.stdout.write(proc.stdout)\n        raise RuntimeContractError(\n            f\"runtime-contract measurement failed with exit code {proc.returncode}\"\n        )\n    try:\n        receipt = json.loads(proc.stdout)\n    except json.JSONDecodeError as error:\n        raise RuntimeContractError(f\"measurement emitted invalid JSON: {error}\") from error\n    if not isinstance(receipt, dict):\n        raise RuntimeContractError(\"measurement top level must be an object\")\n    validate_receipt(receipt)\n    return receipt\n\n\ndef update_command(receipt_path: Path | None, budget_path: Path) -> str:\n    parts = [\"python3\", \"scripts/check-runtime-contract-budget.py\"]\n    if receipt_path is not None:\n        parts.extend([\"--receipt\", str(receipt_path)])\n    if budget_path != BUDGET_PATH:\n        parts.extend([\"--budget\", str(budget_path)])","sourceCodeStart":387,"sourceCodeEnd":423,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/8880682c63083a91624de936797efa3ce9e498fd/scripts/check-runtime-contract-budget.py#L387-L423","documentation":"run_measurement() shells out to scripts/measure-runtime-contract.py (which itself runs `cargo test --locked -p codewhale-tui --lib core::engine::tests::<name> -- --ignored --exact --nocapture --test-threads=1`) with CARGO_NET_OFFLINE=true. A non-zero child exit code raises this error after echoing the child's stdout/stderr, so the underlying cargo failure is visible above the message. This is an environment/build failure, not a contract verdict.","triggerScenarios":"cargo missing or older than rust-toolchain.toml pins; offline builds where CARGO_NET_OFFLINE=true hits unfetched registry crates (no prior cargo fetch, stale Cargo.lock); compile errors anywhere in the codewhale-tui dependency graph; the ignored metric test no longer existing or panicking.","commonSituations":"First run on a fresh CI container or a clean Nix shell without a warmed cargo cache; after a Cargo.lock bump that pulled new crates never vendored/fetched; local runs on a machine without the pinned toolchain.","solutions":["Run the child directly to see the real failure: python3 scripts/measure-runtime-contract.py","Warm the offline cache: cargo fetch --locked (so CARGO_NET_OFFLINE=true can resolve), and install the toolchain from rust-toolchain.toml","Fix any workspace compile error the child reports - the gate compiles codewhale-tui --lib","In CI, run this gate after the normal build job so caches and toolchain are already in place"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"import shutil, subprocess, sys\nfrom pathlib import Path\n\n\ndef measurement_prerequisites_ok() -> bool:\n    if not Path(\"scripts/measure-runtime-contract.py\").is_file():\n        return False\n    if shutil.which(\"cargo\") is None:\n        return False\n    proc = subprocess.run(\n        [\"cargo\", \"metadata\", \"--locked\", \"--offline\", \"--format-version\", \"1\"],\n        capture_output=True,\n        text=True,\n    )\n    return proc.returncode == 0  # offline dependency set is resolvable","typeGuard":null,"tryCatchPattern":"import importlib.util\n\nspec = importlib.util.spec_from_file_location(\n    \"crcb\", \"scripts/check-runtime-contract-budget.py\"\n)\nmod = importlib.util.module_from_spec(spec)\nspec.loader.exec_module(mod)\n\ntry:\n    receipt = mod.run_measurement()\nexcept mod.RuntimeContractError:\n    # the child's stderr (and stdout on failure) were already echoed -\n    # read them; exit code 2 mirrors the CLI's ERROR path\n    raise SystemExit(2)","preventionTips":["Run cargo fetch --locked in CI before this gate so CARGO_NET_OFFLINE=true resolves","Install the toolchain pinned by rust-toolchain.toml (rustup will do it automatically)","Smoke-test with python3 scripts/measure-runtime-contract.py once before wiring the gate into a new pipeline"],"tags":["python","cargo","subprocess","offline-build","ci"],"backgroundTag":null,"analyzedSha":"8880682c63083a91624de936797efa3ce9e498fd","analyzedAt":"2026-08-16T11:31:27.956Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}