Skip to content

Start the append gate isolated so no base module can shadow its imports - #459

Draft
MaxGhenis wants to merge 8 commits into
codex/thesis-ledger-factsfrom
fix/gate-no-scripts-imports
Draft

MaxGhenis wants to merge 8 commits into
codex/thesis-ledger-factsfrom
fix/gate-no-scripts-imports

Conversation

@MaxGhenis

@MaxGhenis MaxGhenis commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Draft, stacked on #308. This branch contains #308's commits (head c29e1de4). It will be rebased onto codex/thesis-ledger-facts once #308 merges, and it does not merge before #308.

What this fixes

A data proposal could add a module off the gate surface that the append gate's judge would then import on every later pull request:

  • scripts/. The judge runs a script there, so scripts/ was sys.path[0], and both pull request jobs also put it on PYTHONPATH. Most of scripts/ is off the surface, because scripts/build_series_catalog.py ships with the ledger/series_catalog.json it generates (Series catalog: canonical registry for the thesis fact ledger #128). A scripts/tempfile.py, or a scripts/receipt/, scripts/receipt_pins/ or scripts/sitecustomize/ package, would stand in for a module the gate imports.
  • The root. uv installed the project editable, and its .pth file appended the base checkout's root to sys.path. A root sitecustomize/ package would run at the judge's startup. The editable build also read README.md, so deleting it would break every later trusted run.

#308 recorded these five shadows as a strict xfail.

Change

  • scripts/check_thesis_facts_append.py and scripts/verify_release_chain.py compile scripts/receipt_pins.py from its path. The scripts.receipt_pins fallback is gone. Compiling from source also means a __pycache__ entry cannot stand in for the pins.
  • Both pull request jobs in .github/workflows/thesis-facts-append.yml now set up and start the base gate this way:
    • They build its environment with uv sync --locked --no-dev --no-install-project --project "$base_gate", so no editable .pth exists and nothing is built from the checkout.
    • They start it with uv run --no-sync --project "$base_gate" python -I, with no PYTHONPATH. --no-sync stops uv run from installing the project again. -I keeps the script's directory off sys.path and ignores PYTHON* variables.
    • Every start does this: both --help questions and both arms of each case.
    • The dead PYTHONNOUSERSITE=1 goes.
  • The push path and the verify_release_chain.py --full step in ci.yml start the same way.
  • The comments in scripts/receipt_pins.py and the README say why the rest of scripts/ and the root can stay off the surface.

Ordering

pull_request_target runs main's copy of the workflow, so the trusted job needs a second pull request into main carrying this branch's workflow byte for byte, as in #242. That is #460. Neither order of landing breaks a run:

  • New workflow, old base gate.
    • Today's gate (ca7c6fcf) imports its pins as receipt_pins, then falls back to scripts.receipt_pins, which it finds only through the root. Started isolated, it fails with No module named 'scripts'; I checked this against a real --no-install-project environment.
    • So before it syncs, each job checks the base gate for a from scripts.receipt_pins import line. If the line is there, the job installs the project as before, and the start is still python -I.
    • The check reads the base checkout's copy of the gate, which the candidate cannot change. It defaults to the isolated environment, so a later refactor of the gate cannot fall back into the legacy branch by accident.
    • This PR's own pull_request job runs this pairing, because its base is today's gate.
  • Old workflow, new base gate. The new gate loads its pins by path whatever is on sys.path, so main's current invocation still runs it.

What the legacy branch still lets through

A base whose gate still imports its pins by name keeps that gate's limits. -I keeps scripts/ off sys.path, but the installed project puts the root on it, last. So a module that the old gate looks up and finds nowhere earlier reaches it: a root receipt_pins.py, a scripts/__init__.py or a scripts/receipt_pins/ package. A root sitecustomize/ package also runs, wherever the interpreter has no sitecustomize of its own. In exchange, the scripts/ shadows (scripts/tempfile.py, scripts/receipt/, scripts/sitecustomize/) close even for such a base. The workflow, scripts/receipt_pins.py and the README all say this.

Delete the legacy branch once no base reachable from codex/thesis-ledger-facts imports its pins by name. A gate older than the pins (before #116) imports its sibling scripts by name, cannot start under -I, and stops the step. No reachable base is that old.

Landing order

Land #460 first. Until main carries the new workflow, the trusted job starts every base gate the old way, with scripts/ on PYTHONPATH and the project installed. A base gate from this PR then loads its pins by path, but scripts/tempfile.py, scripts/receipt/ and scripts/sitecustomize/ still reach it, and so does a root sitecustomize/ package where the interpreter has none of its own. The trusted check closes only once #460 is on main.

CI's setup-uv@v5 may run a different uv than the 0.11.7 I tested. This PR's own pull_request job takes the legacy branch, because its base is today's gate; its trusted job runs main's current copy. The first isolated runs on ubuntu are this PR's push job on merge, then the next pull request's pull_request job, and its trusted job once #460 is on main.

Base checkout attributes

The #308 session's attribute check found one more way for the base to stop the judge, and routed it here because this PR owns the workflow change. Both pull request jobs checked the base out with its own .gitattributes, at every depth:

  • A boolean working-tree-encoding, or a required filter whose smudge fails, stops the checkout partway with exit 128. The job then fails on every later pull request, the one that removes the file included, until an admin steps in. Two pull requests that each pass alone can merge into such a base: one adds the attribute, the other the file it names.
  • An encoding on the gate's scripts stops Python. Receipt refuses a proposal that adds one, but that is a property of the receipt version.
  • eol=crlf on the trust anchors, which receipt does not refuse, makes the gate refuse every append ("anchor bytes are not code-pinned").

Both jobs now check the base out with --attr-source set to the empty tree, so the judge runs from its committed bytes. The runner's own git config still applies; GitHub's ubuntu runners set no core.autocrlf or core.attributesFile. Under today's root .gitattributes, a checkout of this repository with and without attributes is byte-identical (588 files). The trusted job's candidate keeps its attributes: if they stop its checkout, that refuses the candidate. An older git rejects --attr-source (2.41+) as an unknown option rather than ignoring it, as it would attr.tree. The runner images list git 2.56.1.

The attributes still apply on the push path, in a local run, and in the trusted job until #460 is on main, so the .gitattributes entries stay on the surface.

Tests

The strict xfail becomes test_a_module_that_shadows_a_gate_import_cannot_change_the_verdict. It runs the workflow's own step scripts, extracted from the YAML, for pull_request_target, pull_request and push:

  • A local bare remote serves the base and refs/pull/N/merge, and the runner sets a hostile PYTHONPATH.
  • A stand-in uv builds a real venv at <project>/.venv. Its locked dependencies are the test interpreter's site-packages, listed as plain paths, so the test repository's own editable .pth is never processed. A sync without --no-install-project, or a run without --no-sync, writes the editable .pth that puts the project root on sys.path, as hatchling's does. Before each isolated start it records the judge's sys.path.
  • The base holds one shadow, which writes a marker and forges a passing verdict.
  • On the two pull request paths, the candidate's own copy of the gate differs from the base's. Run, it would forge a pass and write a second marker. Read, its from scripts.receipt_pins import line would steer the workflow into the legacy branch. The tests check that every start runs the judging checkout's own gate.

Across 3 paths × 5 shadows, neither marker appears and the refusal stands. The judge's sys.path holds only the standard library, its venv and the locked dependencies; neither the root nor scripts/ appears in it. Further tests:

  • test_a_true_append_beside_shadowing_modules_is_accepted: with all five shadows in the base, the witnessed append still passes on all three paths.

  • test_a_base_gate_that_imports_its_pins_by_name_still_judges covers the ordering. A base gate rewritten to import its pins by name, with the three scripts/ shadows beside it, takes the legacy branch on both pull request jobs. It refuses the frozen-row rewrite and accepts the true append, and no shadow runs. In the refused case the candidate's gate loads its pins by path, so a workflow that chose the branch from the candidate's copy would take the isolated branch, where the old gate cannot start.

  • test_ci_verifies_the_release_chain_isolated_beside_shadowing_modules runs ci.yml's own "Verify witnessed release chain" step beside all five shadows: the chain verifies, no shadow runs, and the one start is isolated.

  • test_a_gitattributes_in_the_base_cannot_stop_or_rewrite_the_base_gate runs both pull request jobs against three bases: a boolean working-tree-encoding in docs/, off the surface; a UTF-16LE encoding on the gate's scripts; and eol=crlf on the anchors. The pull request that removes either of the first two is judged, the witnessed append beside the third is accepted, and the judge's scripts and anchors match their committed bytes. Its control, test_the_same_attributes_stop_a_base_gate_checked_out_with_them, takes the empty tree out of the trusted job's step: git refuses the checkout, Python the rewritten gate, or the gate the rewritten anchors. The step harness sets LC_ALL=C, so git's messages are untranslated.

  • Controls show that each shadow runs when its way in is open:

    • test_the_same_shadow_runs_when_scripts_is_on_the_path: scripts/tempfile.py, scripts/receipt/ and scripts/sitecustomize/, with the gate started the old way.
    • test_a_base_gate_that_imports_its_pins_by_name_keeps_its_limits: a root receipt_pins.py, a scripts/__init__.py, a scripts/receipt_pins/ package and a root sitecustomize/ package, through the legacy branch. The root sitecustomize/ case skips where the interpreter ships a sitecustomize of its own, as Debian's, Ubuntu's and Homebrew's do, since theirs comes first.
  • Mutation check. Each of these edits to the workflow makes the e2e tests fail:

    • keeping the project install;
    • uv run without --no-sync;
    • dropping -I;
    • always taking the legacy branch;
    • never taking it;
    • keeping the project install on the push path;
    • running the candidate's gate instead of the base's (10 failed);
    • choosing the branch from the candidate's gate (12 failed).
    • dropping the empty attribute tree from either job, or adding it to the candidate's checkout;
    • re-checking the anchors out with attributes after the empty-tree checkout (caught only by the anchors case).

    With the project installed, the root sitecustomize/ package runs and leaves its marker.

  • test_policyengine_ledger.py, test_release_chain.py and test_thesis_append_adversarial.py copied the gate into fixtures without its pins. They now copy receipt_pins.py too.

Real uv 0.11.7, macOS, Python 3.14.7, on a copy of an earlier head, 91f227d9, with a root sitecustomize/ package added (later heads change only comments in the workflows):

  • uv sync --no-cache --locked --no-dev --no-install-project succeeds with README.md deleted.
  • uv run --no-sync ... python -I answers --help, the marker stays absent, and the venv holds no editable .pth.
  • The same tree with the project installed runs the package.
  • verify_release_chain.py --full and the push-path gate, started as CI now starts them, both pass (35 releases).

Local runs on 05b49e27 (macOS, Python 3.14.7, git 2.55.0) of the CI "Ledger observation invariants" list, plus test_legacy_targets_retired.py and test_build_series_catalog.py: 620 passed and 5 xfailed. The 5 are the existing strict xfails in test_thesis_append_adversarial.py. On an earlier head, the shadow, legacy and ci.yml tests also passed under Homebrew's Python 3.14.7, whose standard library ships a sitecustomize: 29 passed, and the root sitecustomize/ control skipped as designed.

🤖 Generated with Claude Code

MaxGhenis and others added 3 commits September 29, 2026 18:34
Since the receipt shim refactor (4a23e31, #116), the trust pins live in
scripts/receipt_pins.py, but the gate surface still listed only the files
that held them before. receipt's append gate calls a proposal gate-changing
only when it touches gate_surface, so a resolver-shaped append that also
edited the pins, or bumped receipt in pyproject.toml and uv.lock, was judged
as plain data: accepted, and never named.

Reproduced with the base gate invoked as the trusted CI job invokes it:
3dd95a0's gate accepted the release-20 append plus a receipt_pins.py edit
as "+5 appended vs base, release 20", and #299's gate accepted #297's seven
rows plus a pins edit as "+7 appended vs base, release 21".

The surface now covers:
- scripts/**: the judge runs a script there, so scripts/ is sys.path[0],
  and both pull request jobs also put it on PYTHONPATH. A new module there
  shadows imports (the standard library's included), and a sitecustomize.py
  runs at startup. Both were observed.
- pyproject.toml and uv.lock, which pick the receipt version the judge runs,
  and uv.toml, .python-version and .venv/**, which uv also reads from the
  project it provisions the judge from. Each was observed to change what
  `uv sync --locked --no-dev --project <dir>` and `uv run` do.

The same candidates are now refused as mixed, naming the decider, while
both pure appends still pass and a pins-only change is reported as
gate-only. The resolver's proposals change only ledger/** and
releases/manifests/**, so they stay data proposals.

Tests: every decider is refused as mixed beside a witnessed append and
named when changed alone; a pure append beside unchanged deciders passes;
an audit-hook run shows every file the gate opens or imports from its own
checkout is on the surface; and the shim's surface is pinned as a
deliberate superset of the originals'.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…fix/gate-surface-trust-pins

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
All of scripts/ on the surface would refuse a catalog-builder change shipped
with the ledger/series_catalog.json it generates, as #128 did. The catalog
tests require the two to land together, so that shape could not be split.

The surface now lists the gate's own scripts and receipt_pins.py, plus the
files that set up its interpreter and environment: scripts/sitecustomize.py,
scripts/__pycache__/** (Python loads an unchecked-hash .pyc there in place of
its source; observed), pyproject.toml, uv.lock, uv.toml, .python-version and
.venv/**.

A new module under scripts/ that shadows one of the gate's imports is now off
the surface. A strict-xfail test records that limit; the fix is for the gate
to stop importing from scripts/.

Tests: a builder change beside an append stays a data proposal; the decider
list gains the unchecked-hash .pyc; fixtures force-add the changed decider so
an ignore file cannot drop it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A "dir/**" entry matches only paths below dir, so a symlink committed at
.venv or scripts/__pycache__ itself was unclassified and passed beside a
ledger append. List each such directory bare as well, with a test that a
symlink there is refused as mixed.

Add the other files that decide the judge's environment or the anchor
bytes it checks out: .python-versions, hatch.toml and hatch_build.py (uv
installs this project with hatchling), a root sitecustomize.py (the
editable install puts the root on sys.path), and .gitattributes and
releases/.gitattributes.

Record the limit that remains: a new module on the judge's import path,
under scripts/ or at the root, and the project's own build inputs such as
README.md. Running the judge isolated and without installing the project
closes it.

Pin the exact surface and the exact widening over the original gate in the
tests, and let the shadowing xfail pass only on an AssertionError.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MaxGhenis
MaxGhenis force-pushed the fix/gate-no-scripts-imports branch from 07a697d to 91f227d Compare December 1, 2026 17:04
@MaxGhenis MaxGhenis changed the title Start the append gate with python -I so scripts/ cannot shadow its imports Start the append gate isolated so no base module can shadow its imports Dec 1, 2026
MaxGhenis and others added 3 commits December 1, 2026 13:35
Git applies scripts/.gitattributes, .github/.gitattributes and
.github/workflows/.gitattributes when it checks out the judge. receipt
0.6.2 already refuses filter, ident and working-tree-encoding on every
surface path at any depth, and Python reads either line ending, so none
of the three can change a verdict today. Listing them keeps that from
depending on the receipt version. A structural test now checks that
every .gitattributes above a surface entry is on the surface.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The thesis-ledger append gate could import a module that a data proposal
added off the gate surface. scripts/ was sys.path[0] and on PYTHONPATH,
and uv's editable install of this project put the base checkout's root
on sys.path. A scripts/tempfile.py, a scripts/receipt/ or
scripts/receipt_pins/ package, or a root sitecustomize/ package would
then run inside the judge on every later pull request.

- The gate and verify_release_chain.py compile scripts/receipt_pins.py
  by path; the scripts.receipt_pins fallback is gone.
- Both pull request jobs build the base gate's environment with
  `uv sync --no-install-project` and start it with
  `uv run --no-sync ... python -I`, with no PYTHONPATH. A base gate that
  still imports its pins by name gets the project installed, as before,
  so the new workflow still judges with an older base gate.
- The push path and ci.yml's `verify_release_chain.py --full` start the
  same way.
- The strict xfail becomes end-to-end tests that run the workflow's own
  step scripts against all five shadows. A fake uv builds a real venv
  and models the editable install. Controls show each shadow runs when
  its way in is open.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An in-session adversarial check of the isolated-gate change found the
following:

- The root sitecustomize/ control assumed the interpreter ships no
  sitecustomize of its own. Ubuntu's /usr/bin/python3 does, and the push
  run's test venv is built on it, so that control would fail on every
  merge into the ledger branch. It now skips where the interpreter's own
  comes first. The legacy controls cover the spellings an old gate looks
  up at the root whatever the interpreter: a root receipt_pins.py, a
  scripts/__init__.py and a scripts/receipt_pins/ package.
- The step harness ran a candidate whose gate matched the base's, so a
  workflow that ran, or chose its branch from, the candidate's gate passed
  every test. On a pull request the candidate's gate now forges a pass if
  run and carries the by-name import if read. In the legacy tests it
  loads its pins by path. Every start's script must be the judging
  checkout's own.
- The legacy tests also keep the scripts/ shadows in the base, which -I
  keeps off sys.path in that branch too.
- A new test runs ci.yml's verify step as GitHub would, beside every
  shadow.
- The workflow, pins and README now name the legacy branch's limits:
  the root is on sys.path last, so a module the old gate looks up there
  still reaches it. They also say the trusted job needs main's copy, and
  word the legacy branch's deletion condition so it can be met.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MaxGhenis
MaxGhenis force-pushed the fix/gate-no-scripts-imports branch from d517251 to b2216cc Compare December 1, 2026 18:37
MaxGhenis added a commit that referenced this pull request Dec 1, 2026
Carries #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 (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. The candidate keeps its attributes. #459
holds the step tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Both pull request jobs check the base commit out to run its gate, and
git applied the base's .gitattributes to that checkout at every depth.
Some attributes stop the checkout partway, with exit 128: a boolean
working-tree-encoding, or a required filter whose smudge fails. The job
then fails on every later pull request, the one that removes the file
included, until an admin steps in. Two pull requests that each pass
alone can merge into such a base: one adds the attribute, the other the
file it names. Other attributes rewrite the bytes the judge runs from or
pins. An encoding on the gate's scripts stops Python; receipt refuses a
proposal that adds one, but that is a property of the receipt version.
eol=crlf on the trust anchors, which receipt does not refuse, makes the
gate refuse every append.

Both jobs now check the base out with --attr-source set to the empty
tree, so the judge runs from its committed bytes whatever the base's
attributes say. The runner's own git config still applies; GitHub's
ubuntu runners set no core.autocrlf or core.attributesFile. Under the
root .gitattributes today (text eol=lf, binary and -text) a checkout of
this repository writes the same bytes with and without attributes. The
trusted job's candidate keeps its attributes: if they stop its checkout,
that refuses the candidate. An older git rejects --attr-source as an
unknown option instead of ignoring it, as it would attr.tree.

The step tests run the workflow's own scripts against three bases: one
holding a boolean working-tree-encoding off the surface, one an encoding
on the gate's scripts, and one eol=crlf on the anchors. On both paths,
the pull request that removes either of the first two is judged, the
witnessed append beside the third is accepted, and the judge's scripts
and anchors match their committed bytes. The control takes the empty
tree out of the trusted job's step: git refuses the checkout, Python the
rewritten gate, or the gate the rewritten anchors. The step harness now
sets LC_ALL=C, so git's messages are untranslated. The README and the
comments say where the attributes still apply: the push path, a local
run, and the trusted job until the default branch carries this workflow.
Reported by the #308 session's attribute check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MaxGhenis added a commit that referenced this pull request Dec 1, 2026
Carries #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 <noreply@anthropic.com>
@MaxGhenis
MaxGhenis force-pushed the fix/gate-no-scripts-imports branch from a7180d6 to 05b49e2 Compare December 1, 2026 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant