From 6c892dd8af5186817716921f2dd91f1b165a94f5 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Mon, 16 Nov 2026 22:52:52 -0500 Subject: [PATCH] Refuse an empty digest for unreadable files in the Route A driver sha_of piped openssl through cut, so a file openssl could not open hashed as an empty string. In a launchd job on 2026-11-17, /usr/bin/openssl got "Operation not permitted" on the archive drive. sha_of now returns 1 unless openssl prints 64 hex digits; verify_inputs reports the input as unreadable, and the crosswalk and base digests fail the run (a stale empty base.sha256 too). The README says which tools read an external drive under launchd. Co-Authored-By: Claude Opus 5.5 --- .../route-a-sha-of-unreadable.fixed.md | 1 + .../engine_free/us/test_route_a_driver.py | 59 +++++++++++++++++++ tools/route_a/README.md | 8 ++- tools/route_a/route_a.sh | 22 +++++-- 4 files changed, 84 insertions(+), 6 deletions(-) create mode 100644 changelog.d/route-a-sha-of-unreadable.fixed.md diff --git a/changelog.d/route-a-sha-of-unreadable.fixed.md b/changelog.d/route-a-sha-of-unreadable.fixed.md new file mode 100644 index 0000000000..e35dda0ce6 --- /dev/null +++ b/changelog.d/route-a-sha-of-unreadable.fixed.md @@ -0,0 +1 @@ +The Route A driver no longer hashes a file openssl cannot read as an empty digest: such an input is reported as unreadable, and the crosswalk and base digests fail the run. diff --git a/packages/microcosm-build/tests/engine_free/us/test_route_a_driver.py b/packages/microcosm-build/tests/engine_free/us/test_route_a_driver.py index ecfd7a4d9c..5609d3bb53 100644 --- a/packages/microcosm-build/tests/engine_free/us/test_route_a_driver.py +++ b/packages/microcosm-build/tests/engine_free/us/test_route_a_driver.py @@ -209,6 +209,65 @@ def test_overridden_feed_pin_still_verifies_digest_and_size( ) +@pytest.mark.parametrize( + "openssl", + [ + # Nothing on stdout: openssl could not open the file. + "openssl() { return 1; }", + # An error on stdout instead of a digest. + "openssl() { echo 'Operation not permitted'; }", + # A digest-shaped line that is not 64 hex digits. + "openssl() { echo '0123 *x'; }", + ], +) +def test_an_input_openssl_cannot_read_is_unreadable_not_an_empty_digest( + tmp_path: Path, openssl: str +) -> None: + # On 2026-11-17 a launchd job's /usr/bin/openssl could not read the + # archive drive, and sha_of turned that into an empty digest. Now it + # prints nothing and fails, and the input is reported as unreadable. + feed = tmp_path / "new-feed.jsonl" + payload = b'{"fixture": "feed"}\n' + feed.write_bytes(payload) + result = _input_settings_result( + tmp_path, + { + "FEED": str(feed), + "FEED_SHA": hashlib.sha256(payload).hexdigest(), + "FEED_BYTES": str(len(payload)), + }, + f""" +registered_rows=$(input_rows) +input_rows() {{ printf '%s\\n' "$registered_rows" | awk -F '|' '$1 == "release_ledger_facts"'; }} +stat() {{ "$PYTHON" -c 'import os,sys; print(os.stat(sys.argv[1]).st_size)' "$3"; }} +{openssl} +if out=$(sha_of "{feed}"); then echo "sha_of ok [$out]"; else echo "sha_of failed [$out]"; fi +verify_inputs +printf '%s\\n' "${{INPUT_PROBLEMS[@]}}" +""", + ) + assert result.returncode == 0, result.stderr.decode() + lines = result.stdout.decode().splitlines() + assert lines[0] == "sha_of failed []" + assert lines[1:] == [f"release_ledger_facts could not be read to hash it: {feed}"] + report = json.loads((tmp_path / "run_root" / "inputs.resolved.json").read_text()) + assert report["inputs"][0]["status"] == "unreadable" + assert report["inputs"][0]["observed_sha256"] == "" + + +def test_the_crosswalk_and_base_digests_refuse_an_unreadable_file() -> None: + # These run after the fetch, where the settings harness stops, so the + # source is checked: neither compares nor records an empty digest. + source = (ROUTE_A_TOOLS / "route_a.sh").read_text(encoding="utf-8") + assert ( + 'CROSSWALK_ACTUAL=$(sha_of "$W/$CROSSWALK_REL") || fail "could not read' + in source + ) + assert 'BASE_SHA=$(sha_of "$BASE_H5") || fail "could not read $BASE_H5' in source + assert "[[ $BASE_SHA =~ ^[0-9a-f]{64}$ ]] || fail" in source + assert '"$(sha_of ' not in source + + def _tiny_main(tmp_path: Path, files: dict[str, str]) -> tuple[Path, str]: """A throwaway local repository standing in for ``$MAIN`` at one commit.""" diff --git a/tools/route_a/README.md b/tools/route_a/README.md index fdb5abcdf2..44ad26d1b8 100644 --- a/tools/route_a/README.md +++ b/tools/route_a/README.md @@ -115,7 +115,13 @@ and 18,991,218 bytes. Use a fresh `RUN_ROOT` for that attempt: an existing does not rebuild a previously accepted base. The driver uses macOS `stat -f` and requires bash, git, openssl, uv and the -configured paths. It creates clean detached worktrees at the chosen commits, +configured paths. A file openssl cannot read is an input problem or a failed +run, never an empty digest. Under launchd, macOS can refuse the system's own +tools access to an external drive: on 2026-11-17, in a launchd job, +`/usr/bin/openssl`, `/usr/bin/shasum` and `/usr/bin/python3` got "Operation +not permitted" there, while a Homebrew openssl and the worktree's Python +read the same files. Put Homebrew's `bin` before `/usr/bin` on such a job's +`PATH`, or copy the inputs to the internal disk. It creates clean detached worktrees at the chosen commits, runs `uv sync --all-packages --locked --extra us`, and checks that their Python can import psutil and policyengine-us. The supervised stages use that worktree's interpreter. diff --git a/tools/route_a/route_a.sh b/tools/route_a/route_a.sh index 99630b15ed..2fcb7139e5 100755 --- a/tools/route_a/route_a.sh +++ b/tools/route_a/route_a.sh @@ -121,7 +121,15 @@ fail() { echo "$(date '+%F %T') $*" > "$RUN_ROOT/ROUTE_A_FAILED" exit 1 } -sha_of() { openssl dgst -sha256 -r "$1" 2>/dev/null | cut -c1-64; } +# The file's sha256, or nothing and status 1 when openssl prints no digest: +# an unreadable file (in a launchd job on 2026-11-17, /usr/bin/openssl got +# "Operation not permitted" on an external drive) must not hash as empty. +sha_of() { + local out + out=$(openssl dgst -sha256 -r "$1" 2>/dev/null | cut -c1-64) + [[ $out =~ ^[0-9a-f]{64}$ ]] || return 1 + printf '%s\n' "$out" +} free_bytes() { df -k "$DISK_PATH" | awk 'NR==2 {print $4*1024}'; } INPUT_PROBLEMS=() @@ -139,8 +147,9 @@ verify_inputs() { # fills INPUT_PROBLEMS; writes $RUN_ROOT/inputs.resolved.json if [ "$size" != "-" ] && [ "$asize" != "$size" ]; then status=size_mismatch; INPUT_PROBLEMS+=("$role size $asize != $size: $path") fi - actual=$(sha_of "$path") - if [ "$actual" != "$sha" ]; then + if ! actual=$(sha_of "$path"); then + status=unreadable; INPUT_PROBLEMS+=("$role could not be read to hash it: $path") + elif [ "$actual" != "$sha" ]; then status=sha_mismatch; INPUT_PROBLEMS+=("$role sha256 $actual != $sha: $path") fi fi @@ -402,7 +411,8 @@ ensure_worktree() { # $1 = full sha; sets WT ensure_worktree "$C"; W=$WT ensure_worktree "$PC"; PW=$WT PY=$W/.venv/bin/python -[ "$(sha_of "$W/$CROSSWALK_REL")" = "$CROSSWALK_SHA" ] || fail "packaged crosswalk digest in $W" +CROSSWALK_ACTUAL=$(sha_of "$W/$CROSSWALK_REL") || fail "could not read $W/$CROSSWALK_REL to hash it" +[ "$CROSSWALK_ACTUAL" = "$CROSSWALK_SHA" ] || fail "packaged crosswalk digest in $W" PEUS=$("$PY" -c 'import importlib.metadata as m; print(m.version("policyengine-us"))') [ -x "$W/.venv/bin/microcosm-publish-release-build" ] || fail "no microcosm-publish-release-build in $W/.venv" log "build worktree $W (policyengine-us $PEUS); preflight worktree $PW" @@ -585,9 +595,11 @@ if ! stage_done base; then fi [ -f "$BASE_H5" ] || fail "base stage accepted but $BASE_H5 is missing" if [ ! -f "$RUN/base.sha256" ] || [ "$BASE_H5" -nt "$RUN/base.sha256" ]; then - echo "$(sha_of "$BASE_H5") $BASE_H5" > "$RUN/base.sha256" + BASE_SHA=$(sha_of "$BASE_H5") || fail "could not read $BASE_H5 to hash it" + echo "$BASE_SHA $BASE_H5" > "$RUN/base.sha256" fi BASE_SHA=$(cut -c1-64 "$RUN/base.sha256") +[[ $BASE_SHA =~ ^[0-9a-f]{64}$ ]] || fail "$RUN/base.sha256 holds no sha256; delete it and rerun" log "base H5 $BASE_H5 sha256 $BASE_SHA ($(stat -f %z "$BASE_H5") bytes)" if [ "$PRUNE_BASE_CHECKPOINTS" = 1 ] && ls "$BASE_CKPT"/*.frame.h5 >/dev/null 2>&1; then log "PRUNE_BASE_CHECKPOINTS=1: removing base frame checkpoints ($(du -sh "$BASE_CKPT" | cut -f1)) after the base H5 was hashed"