From 50c50903be9dffb2c6722ddc3041abaf39ef6b10 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Tue, 1 Dec 2026 10:42:06 -0500 Subject: [PATCH 1/4] Start the trusted append gate with python -I pull_request_target loads this file from the default branch, so the trusted base gate on every pull request into codex/thesis-ledger-facts runs from main's copy. That copy starts the base gate with the base's scripts/ on PYTHONPATH and as sys.path[0]. scripts/ is mostly off the gate surface, so a data proposal can add a scripts/tempfile.py or a scripts/receipt/ package unnamed, and from then on it stands in for one the gate imports. This is the ledger branch's version of the file from PolicyEngine/chronicle#459, byte for byte. Every start of the base gate, both --help questions included, uses python -I and sets no PYTHONPATH. Today's base gate still starts this way: it finds its pins as scripts.receipt_pins through the base root that the editable project install appends to sys.path. #459's own Append gate job ran this pairing on ubuntu against base ca7c6fcf and accepted the proposal. A base gate from #459 on loads its pins by path. So this copy can land before or after #459, and neither order leaves a window in which a run breaks. The file also picks up the ledger branch's existing tests/test_production_tsa_pins.py line in the push-path test list, which no main run uses. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/thesis-facts-append.yml | 51 +++++++++++++---------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/.github/workflows/thesis-facts-append.yml b/.github/workflows/thesis-facts-append.yml index 5eccd2c0..4af18dcf 100644 --- a/.github/workflows/thesis-facts-append.yml +++ b/.github/workflows/thesis-facts-append.yml @@ -118,18 +118,29 @@ jobs: # cannot run at all stops the step instead of being read as an old # one. Delete the second branch below once no base reachable from # this branch predates --commit. + # + # Every start of the base gate, the --help question included, uses + # `python -I` and sets no PYTHONPATH. -I keeps the script's own + # directory off sys.path and ignores PYTHON* variables. Most of + # scripts/ is off the gate surface, so an earlier data proposal can + # add a module there (a tempfile.py, or a receipt/ package); started + # this way, the gate never imports it. A gate that loads its pins by + # path needs nothing else. A gate that still imports them by name + # finds them as scripts.receipt_pins, through the base root that the + # project's editable install appends to sys.path. Keep the project + # installed until no base reachable from this branch imports its + # pins by name. A gate older than the pins imports its sibling + # scripts by name, cannot start this way, and stops the step. base_gate_help="$( uv run --locked --no-dev --project "$base_gate" \ - python "$base_gate/scripts/check_thesis_facts_append.py" --help + python -I "$base_gate/scripts/check_thesis_facts_append.py" --help )" cd "$RUNNER_TEMP" case "$base_gate_help" in *--commit*) - PYTHONPATH="$base_gate/scripts" \ - PYTHONNOUSERSITE=1 \ - uv run --locked --no-dev --project "$base_gate" \ - python "$base_gate/scripts/check_thesis_facts_append.py" \ + uv run --locked --no-dev --project "$base_gate" \ + python -I "$base_gate/scripts/check_thesis_facts_append.py" \ --root "$candidate" \ --commit "$MERGE_SHA" \ --base-ref "$BASE_SHA" @@ -139,10 +150,8 @@ jobs: "judges the working tree at $candidate, without binding its" \ "verdict to $MERGE_SHA. This is the base's own guarantee and" \ "the only one available against that base." >&2 - PYTHONPATH="$base_gate/scripts" \ - PYTHONNOUSERSITE=1 \ - uv run --locked --no-dev --project "$base_gate" \ - python "$base_gate/scripts/check_thesis_facts_append.py" \ + uv run --locked --no-dev --project "$base_gate" \ + python -I "$base_gate/scripts/check_thesis_facts_append.py" \ --root "$candidate" \ --base-ref "$BASE_SHA" ;; @@ -185,19 +194,19 @@ jobs: [[ "$workspace_sha" =~ ^[0-9a-f]{40,64}$ ]] # As in the trusted job above: the commit is named, not inferred, - # and the base gate is asked what it accepts for the same reason. + # the base gate is asked what it accepts for the same reason, and + # every start of it uses `python -I` with no PYTHONPATH, so no + # module in the base's scripts/ can stand in for one it imports. base_gate_help="$( uv run --locked --no-dev --project "$base_gate" \ - python "$base_gate/scripts/check_thesis_facts_append.py" --help + python -I "$base_gate/scripts/check_thesis_facts_append.py" --help )" cd "$RUNNER_TEMP" case "$base_gate_help" in *--commit*) - PYTHONPATH="$base_gate/scripts" \ - PYTHONNOUSERSITE=1 \ - uv run --locked --no-dev --project "$base_gate" \ - python "$base_gate/scripts/check_thesis_facts_append.py" \ + uv run --locked --no-dev --project "$base_gate" \ + python -I "$base_gate/scripts/check_thesis_facts_append.py" \ --root "$GITHUB_WORKSPACE" \ --commit "$workspace_sha" \ --base-ref "$base_sha" @@ -206,10 +215,8 @@ jobs: echo "note: the base gate at $base_sha predates --commit, so" \ "it judges the workspace, without binding its verdict to" \ "$workspace_sha." >&2 - PYTHONPATH="$base_gate/scripts" \ - PYTHONNOUSERSITE=1 \ - uv run --locked --no-dev --project "$base_gate" \ - python "$base_gate/scripts/check_thesis_facts_append.py" \ + uv run --locked --no-dev --project "$base_gate" \ + python -I "$base_gate/scripts/check_thesis_facts_append.py" \ --root "$GITHUB_WORKSPACE" \ --base-ref "$base_sha" ;; @@ -217,10 +224,11 @@ jobs: else # The push path names the pushed commit explicitly too. The # argument is required, so there is no spelling of this run in - # which the commit is taken from the checkout instead. + # which the commit is taken from the checkout instead. It starts + # the gate with `python -I` for the same reason as the jobs above. uv sync --locked --no-dev uv run --locked --no-dev \ - python scripts/check_thesis_facts_append.py \ + python -I scripts/check_thesis_facts_append.py \ --commit "$GITHUB_SHA" fi @@ -246,4 +254,5 @@ jobs: tests/test_thesis_append_adversarial.py \ tests/test_thesis_append_shim_isolation.py \ tests/test_receipt_shim_transparency.py \ + tests/test_production_tsa_pins.py \ -q From 53cb60f7340fec7059cbfeb2e119a86f8c70350f Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Tue, 1 Dec 2026 12:02:30 -0500 Subject: [PATCH 2/4] Build the trusted append gate's environment without the project Carries the thesis-ledger branch's append workflow to main byte for byte, because pull_request_target reads main's copy. The base gate's environment no longer installs this project, so the base checkout's root is off its sys.path, and every start stays `python -I` with no PYTHONPATH. A base gate that still imports its pins by name gets the project installed, as before. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/thesis-facts-append.yml | 121 +++++++++++++--------- 1 file changed, 70 insertions(+), 51 deletions(-) diff --git a/.github/workflows/thesis-facts-append.yml b/.github/workflows/thesis-facts-append.yml index 4af18dcf..68b4de12 100644 --- a/.github/workflows/thesis-facts-append.yml +++ b/.github/workflows/thesis-facts-append.yml @@ -99,7 +99,36 @@ jobs: # the base gate with it: the gate scripts may import packaged # dependencies, and installing from the base's uv.lock # keeps the PR unable to influence what code judges it. - uv sync --locked --no-dev --project "$base_gate" + # + # Every start of the base gate, the --help question included, uses + # `python -I` and sets no PYTHONPATH, and the environment does not + # install this project. -I keeps the script's own directory off + # sys.path and ignores PYTHON* variables; without the project, no + # editable .pth puts the base checkout's root on sys.path, and the + # sync builds nothing from the checkout (no README.md, hatch.toml or + # hatch_build.py). Most of scripts/ and the root are off the gate + # surface, so an earlier data proposal can add a module there (a + # scripts/tempfile.py, a scripts/receipt/ package, a root + # sitecustomize/ package); started this way, the gate never imports + # it. `uv run --no-sync` keeps uv from installing the project again. + # + # A base gate that still imports its pins as scripts.receipt_pins + # finds them only through that root, so for such a base alone the + # project is installed as before, and the base keeps that older + # gate's limits. The check reads base-owned code, which the + # candidate cannot change. Delete the first branch below once no + # base reachable from this branch imports its pins by name. A gate + # older than the pins imports its sibling scripts by name, cannot + # start this way, and stops the step. + base_gate_script="$base_gate/scripts/check_thesis_facts_append.py" + if grep -qE '^[[:space:]]*from scripts\.receipt_pins import ' \ + "$base_gate_script"; then + uv sync --locked --no-dev --project "$base_gate" + base_gate_python=(uv run --locked --no-dev --project "$base_gate" python -I) + else + uv sync --locked --no-dev --no-install-project --project "$base_gate" + base_gate_python=(uv run --no-sync --project "$base_gate" python -I) + fi # Receipt 0.6 reads and rehashes the named commit's objects; the shim # prints the commit and tree from that verdict. --root only locates @@ -118,42 +147,24 @@ jobs: # cannot run at all stops the step instead of being read as an old # one. Delete the second branch below once no base reachable from # this branch predates --commit. - # - # Every start of the base gate, the --help question included, uses - # `python -I` and sets no PYTHONPATH. -I keeps the script's own - # directory off sys.path and ignores PYTHON* variables. Most of - # scripts/ is off the gate surface, so an earlier data proposal can - # add a module there (a tempfile.py, or a receipt/ package); started - # this way, the gate never imports it. A gate that loads its pins by - # path needs nothing else. A gate that still imports them by name - # finds them as scripts.receipt_pins, through the base root that the - # project's editable install appends to sys.path. Keep the project - # installed until no base reachable from this branch imports its - # pins by name. A gate older than the pins imports its sibling - # scripts by name, cannot start this way, and stops the step. - base_gate_help="$( - uv run --locked --no-dev --project "$base_gate" \ - python -I "$base_gate/scripts/check_thesis_facts_append.py" --help - )" + base_gate_help="$("${base_gate_python[@]}" "$base_gate_script" --help)" cd "$RUNNER_TEMP" case "$base_gate_help" in *--commit*) - uv run --locked --no-dev --project "$base_gate" \ - python -I "$base_gate/scripts/check_thesis_facts_append.py" \ - --root "$candidate" \ - --commit "$MERGE_SHA" \ - --base-ref "$BASE_SHA" + "${base_gate_python[@]}" "$base_gate_script" \ + --root "$candidate" \ + --commit "$MERGE_SHA" \ + --base-ref "$BASE_SHA" ;; *) echo "note: the base gate at $BASE_SHA predates --commit, so it" \ "judges the working tree at $candidate, without binding its" \ "verdict to $MERGE_SHA. This is the base's own guarantee and" \ "the only one available against that base." >&2 - uv run --locked --no-dev --project "$base_gate" \ - python -I "$base_gate/scripts/check_thesis_facts_append.py" \ - --root "$candidate" \ - --base-ref "$BASE_SHA" + "${base_gate_python[@]}" "$base_gate_script" \ + --root "$candidate" \ + --base-ref "$BASE_SHA" ;; esac @@ -187,49 +198,57 @@ jobs: test "$(git -C "$base_gate" rev-parse HEAD)" = "$base_sha" # Base gate runs from the BASE commit's own hash-locked env so - # gate dependencies resolve without the PR influencing them. - uv sync --locked --no-dev --project "$base_gate" + # gate dependencies resolve without the PR influencing them. As + # in the trusted job above, the env does not install this + # project and every start uses `python -I` with no PYTHONPATH, + # so no module in the base's scripts/ or at its root can stand in + # for one the gate imports, except for a base gate that still + # imports its pins by name. Delete the first branch below once + # no base reachable from this branch does. + base_gate_script="$base_gate/scripts/check_thesis_facts_append.py" + if grep -qE '^[[:space:]]*from scripts\.receipt_pins import ' \ + "$base_gate_script"; then + uv sync --locked --no-dev --project "$base_gate" + base_gate_python=(uv run --locked --no-dev --project "$base_gate" python -I) + else + uv sync --locked --no-dev --no-install-project --project "$base_gate" + base_gate_python=(uv run --no-sync --project "$base_gate" python -I) + fi workspace_sha="$(git -C "$GITHUB_WORKSPACE" rev-parse HEAD)" [[ "$workspace_sha" =~ ^[0-9a-f]{40,64}$ ]] # As in the trusted job above: the commit is named, not inferred, - # the base gate is asked what it accepts for the same reason, and - # every start of it uses `python -I` with no PYTHONPATH, so no - # module in the base's scripts/ can stand in for one it imports. - base_gate_help="$( - uv run --locked --no-dev --project "$base_gate" \ - python -I "$base_gate/scripts/check_thesis_facts_append.py" --help - )" + # and the base gate is asked what it accepts for the same reason. + base_gate_help="$("${base_gate_python[@]}" "$base_gate_script" --help)" cd "$RUNNER_TEMP" case "$base_gate_help" in *--commit*) - uv run --locked --no-dev --project "$base_gate" \ - python -I "$base_gate/scripts/check_thesis_facts_append.py" \ - --root "$GITHUB_WORKSPACE" \ - --commit "$workspace_sha" \ - --base-ref "$base_sha" + "${base_gate_python[@]}" "$base_gate_script" \ + --root "$GITHUB_WORKSPACE" \ + --commit "$workspace_sha" \ + --base-ref "$base_sha" ;; *) echo "note: the base gate at $base_sha predates --commit, so" \ "it judges the workspace, without binding its verdict to" \ "$workspace_sha." >&2 - uv run --locked --no-dev --project "$base_gate" \ - python -I "$base_gate/scripts/check_thesis_facts_append.py" \ - --root "$GITHUB_WORKSPACE" \ - --base-ref "$base_sha" + "${base_gate_python[@]}" "$base_gate_script" \ + --root "$GITHUB_WORKSPACE" \ + --base-ref "$base_sha" ;; esac else # The push path names the pushed commit explicitly too. The # argument is required, so there is no spelling of this run in - # which the commit is taken from the checkout instead. It starts - # the gate with `python -I` for the same reason as the jobs above. - uv sync --locked --no-dev - uv run --locked --no-dev \ - python -I scripts/check_thesis_facts_append.py \ - --commit "$GITHUB_SHA" + # which the commit is taken from the checkout instead. It runs + # the pushed commit's own gate, which loads its pins by path, so + # it starts it isolated, as the jobs above do, with no project + # install to undo. + uv sync --locked --no-dev --no-install-project + uv run --no-sync python -I scripts/check_thesis_facts_append.py \ + --commit "$GITHUB_SHA" fi - name: Install uv From 3173fd4a7c166d6cbc75446bcc64c4828b93076b Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Tue, 1 Dec 2026 13:28:44 -0500 Subject: [PATCH 3/4] Name the legacy branch's limits in the append workflow Carries the thesis-ledger branch's comment changes to main byte for byte: the legacy branch keeps scripts/ off sys.path but puts the root on it, last, so a module an old gate looks up there still reaches it, and its deletion condition is now one that can be met. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/thesis-facts-append.yml | 26 +++++++++++++---------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/.github/workflows/thesis-facts-append.yml b/.github/workflows/thesis-facts-append.yml index 68b4de12..195393cb 100644 --- a/.github/workflows/thesis-facts-append.yml +++ b/.github/workflows/thesis-facts-append.yml @@ -112,14 +112,18 @@ jobs: # sitecustomize/ package); started this way, the gate never imports # it. `uv run --no-sync` keeps uv from installing the project again. # - # A base gate that still imports its pins as scripts.receipt_pins - # finds them only through that root, so for such a base alone the - # project is installed as before, and the base keeps that older - # gate's limits. The check reads base-owned code, which the - # candidate cannot change. Delete the first branch below once no - # base reachable from this branch imports its pins by name. A gate - # older than the pins imports its sibling scripts by name, cannot - # start this way, and stops the step. + # A base gate that still imports its pins by name finds them only + # as scripts.receipt_pins, through that root, so for such a base + # alone the project is installed as before. -I still keeps scripts/ + # off sys.path, but the root is on it, last, so a module there that + # the old gate looks up and finds nowhere earlier (a root + # receipt_pins.py, a scripts/__init__.py or a scripts/receipt_pins/ + # package) still reaches it. The check reads the base checkout's + # copy of the gate, which the candidate cannot change. Delete the + # first branch below once no pull request into this branch can + # still have a base from before the gate loaded its pins by path. A + # gate older than the pins imports its sibling scripts by name, + # cannot start this way, and stops the step. base_gate_script="$base_gate/scripts/check_thesis_facts_append.py" if grep -qE '^[[:space:]]*from scripts\.receipt_pins import ' \ "$base_gate_script"; then @@ -202,9 +206,9 @@ jobs: # in the trusted job above, the env does not install this # project and every start uses `python -I` with no PYTHONPATH, # so no module in the base's scripts/ or at its root can stand in - # for one the gate imports, except for a base gate that still - # imports its pins by name. Delete the first branch below once - # no base reachable from this branch does. + # for one the gate imports, except in a base whose gate still + # imports its pins by name (see the trusted job above). Delete + # the first branch below when the trusted job's goes. base_gate_script="$base_gate/scripts/check_thesis_facts_append.py" if grep -qE '^[[:space:]]*from scripts\.receipt_pins import ' \ "$base_gate_script"; then From c8e4c06ebc6cd34697d963bf6a23085f62ee29aa Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Tue, 1 Dec 2026 13:49:44 -0500 Subject: [PATCH 4/4] Check the base gate out with an empty attribute tree Carries PolicyEngine/chronicle#459's workflow change into main, byte for byte, because pull_request_target runs main's copy. Both pull request jobs check the base commit out with --attr-source set to the empty tree, so the judge runs from its committed bytes. A .gitattributes anywhere in the base can no longer stop that checkout partway (a boolean working-tree-encoding, a required filter whose smudge fails), which would fail the trusted job on every later pull request, the one that removes the file included. Nor can it rewrite the gate's scripts or trust anchors. The candidate keeps its attributes. #459 holds the step tests. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/thesis-facts-append.yml | 24 +++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/.github/workflows/thesis-facts-append.yml b/.github/workflows/thesis-facts-append.yml index 195393cb..f18ee50f 100644 --- a/.github/workflows/thesis-facts-append.yml +++ b/.github/workflows/thesis-facts-append.yml @@ -92,7 +92,22 @@ jobs: git clone --no-checkout "$repository_url" "$base_gate" git -C "$base_gate" fetch --no-tags origin "$BASE_SHA" - git -C "$base_gate" checkout --detach "$BASE_SHA" + # Check the base gate out with an empty attribute tree, so the files + # it runs from, its trust anchors included, are the committed bytes. + # (The runner's own git config still applies; GitHub's ubuntu + # runners set no core.autocrlf or core.attributesFile.) + # A .gitattributes anywhere in the base, on the gate surface or off + # it, then can neither rewrite them (working-tree-encoding, ident, a + # filter, eol=crlf) nor stop the checkout (a boolean + # working-tree-encoding, a required filter whose smudge fails). A + # stopped checkout would fail this job on every later pull request, + # the one that removes the file included. Two pull requests that + # each pass alone can merge into such a base. The candidate above + # keeps its attributes: if they stop its checkout, that refuses the + # candidate. + empty_tree="$(git -C "$base_gate" hash-object -t tree /dev/null)" + git -C "$base_gate" --attr-source="$empty_tree" \ + checkout --detach "$BASE_SHA" test "$(git -C "$base_gate" rev-parse HEAD)" = "$BASE_SHA" # Provision the BASE commit's own hash-locked environment and run @@ -198,7 +213,12 @@ jobs: "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY.git" \ "$base_gate" git -C "$base_gate" fetch --no-tags --depth 1 origin "$base_sha" - git -C "$base_gate" checkout --detach "$base_sha" + # As in the trusted job: an empty attribute tree, so the base + # gate runs from the committed bytes and no .gitattributes can + # stop its checkout. + empty_tree="$(git -C "$base_gate" hash-object -t tree /dev/null)" + git -C "$base_gate" --attr-source="$empty_tree" \ + checkout --detach "$base_sha" test "$(git -C "$base_gate" rev-parse HEAD)" = "$base_sha" # Base gate runs from the BASE commit's own hash-locked env so