Skip to content

Put the files that decide a gate verdict on the gate surface - #308

Open
MaxGhenis wants to merge 5 commits into
codex/thesis-ledger-factsfrom
fix/gate-surface-trust-pins
Open

MaxGhenis wants to merge 5 commits into
codex/thesis-ledger-factsfrom
fix/gate-surface-trust-pins

Conversation

@MaxGhenis

@MaxGhenis MaxGhenis commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The append gate's gate_surface did not match the files that decide its verdicts. Since the receipt shim refactor (4a23e31, #116, 2026-07-25), the trust pins have lived in scripts/receipt_pins.py. The surface still listed only the scripts that held the pins before. It also never listed pyproject.toml or uv.lock, which pick the receipt version the judge runs.

receipt 0.6.2 treats a proposal as gate-changing only when it touches gate_surface (append_gate.py: _classify_surfaces, check_surface_separation). It refuses a proposal that mixes data and gate changes, and drops unclassified changes on the data path. So an append that also edited the pins passed as plain data, and the gate never named the change. The independent review of #299 found this by reading the code; this PR reproduces it by running the gate.

Invariant (trust boundary). Every file in the judging (base) checkout that decides the gate's verdict is on gate_surface. That covers:

  • the gate's code and pins, and the anchors;
  • the files that build its interpreter and environment;
  • every .gitattributes git applies to those files when it checks out the judge.

The exceptions are the open limits recorded below.

Reproduction (before the fix)

These runs used the base gate exactly as the "Trusted base append gate" job runs it: PYTHONPATH=$J/scripts PYTHONNOUSERSITE=1 uv run --locked --no-dev --project $J python $J/scripts/check_thesis_facts_append.py --root <clone> --commit <c> --base-ref <b>, from another cwd.

Judge Candidate Verdict
3dd95a0 55bbf3d (a real release-20 resolver append) + a receipt_pins.py edit, vs d77afe2 OK: 221 rows, immutable prefix 128, +5 appended vs base, release 20
75b74b1 (#299) #297's 7 rows + a pins edit, vs a simulated #299 merge OK: 228 rows, immutable prefix 128, +7 appended vs base, release 21
75b74b1 #297's rows alone (control) the same OK ... +7 appended vs base, release 21

The mixed proposal and the pure one got the same verdict line. With this PR's surface, both mixed candidates are refused: mixed data/gate proposal is forbidden: ... GATE_SURFACE changes=['scripts/receipt_pins.py']. Both pure appends still pass, and a pins-only edit is reported as gate-only proposal; ... GATE_SURFACE changes=['scripts/receipt_pins.py'].

The surface

Entry Why
scripts/check_thesis_facts_append.py, verify_release_chain.py, canonical_json.py, cut_release_manifest.py, .github/workflows/thesis-facts-append.yml, releases/anchors/** unchanged
scripts/receipt_pins.py the trust pins and the surfaces themselves
scripts/sitecustomize.py both PR jobs put scripts/ on PYTHONPATH; a new sitecustomize.py there ran at interpreter startup (observed)
sitecustomize.py (root) uv installs this project editable, and its .pth puts the root on sys.path, where site looks for sitecustomize
scripts/__pycache__, scripts/__pycache__/** a committed unchecked-hash .pyc was loaded in place of its source (observed: printed forged while the source said honest)
pyproject.toml, uv.lock pick the receipt version and every package in the judge's environment
uv.toml, .python-version, .python-versions uv sync --locked --no-dev --project <dir> failed on a project uv.toml with required-version = "==0.0.1", a .python-version of 3.12 switched uv run to 3.12.14, and a lone .python-versions of 3.12 switched uv 0.11.7's interpreter choice from 3.15 to 3.12 (all observed)
.venv, .venv/** a committed site-packages/*.pth survived uv sync --locked and ran on uv run (observed, same machine; on CI the committed venv's interpreter path would also have to exist)
hatch.toml, hatch_build.py the sync builds this project with hatchling, which merges hatch.toml over [tool.hatch] and runs a configured build hook
.gitattributes, releases/.gitattributes git applies them when it checks out the judge, so an eol change rewrites the anchor bytes the pins check, and every later proposal is refused, including the one that reverts it
scripts/.gitattributes, .github/.gitattributes, .github/workflows/.gitattributes git applies them to the gate's scripts and the workflow when it checks out the judge. They cannot change a verdict today (see below); they are listed so that this does not depend on the receipt version
releases/anchors listed bare, like every dir/** entry

Bare directory entries. receipt matches dir/** only for paths below dir. So a symlink committed at .venv or scripts/__pycache__ itself was unclassified, and it passed beside a ledger append. Each dir/** entry is now also listed bare, and a test commits such a symlink.

Why not all of scripts/. An earlier revision listed scripts/**. That would refuse a catalog-builder change shipped together with the ledger/series_catalog.json it generates, which is the shape of #128. The required check test_build_series_catalog.py::test_committed_catalog_is_current_and_valid asserts bsc.render(catalog) == committed_text, so that shape cannot be split. The gate never imports the builder, so editing it cannot change a verdict.

Nested attribute files. receipt 0.6.2 refuses filter, ident and working-tree-encoding on every surface path, and it reads .gitattributes at every depth. So a data PR whose scripts/.gitattributes sets *.py working-tree-encoding=UTF-16LE was refused (transforming attribute working-tree-encoding applies to protected path scripts/canonical_json.py), and so were ident, filter, a case variant and the .github/ files (all observed with the e0f6734 judge). Without that refusal the encoding would matter: a judge checked out under it cannot run its scripts, and in a test repository working-tree-encoding=UTF-7 rewrote print(3 + 2) as print(3 2) (git 2.55.0). text and eol pass, and a judge with CRLF scripts gave byte-identical output over 9 cases. The three files are on the surface, and a test checks that every .gitattributes above a surface entry is on it.

Open limits. These are about how the workflow runs the judge, so this list cannot close them:

  • A new module on the judge's import path that shadows one of its imports. Two places put modules on that path:
    • scripts/ is sys.path[0] and is on PYTHONPATH. Observed: a scripts/tempfile.py replaced the standard-library module. A scripts/receipt/ or scripts/receipt_pins/ package would also count.
    • The root, through the editable install. An example is a sitecustomize/ package.
  • The project's own build inputs, such as README.md. The editable build reads it.
  • A .gitattributes in any directory can abort the judge's whole checkout, for example with a boolean working-tree-encoding on a file that exists (observed in a test repository: git exits 128 and writes no files). The trusted job checks out the candidate the same way, so I expect such a PR to fail its own check; it would take a stale merge of two passing PRs or a direct push (inferred, not run). Checking the judge out with an empty attribute tree (git -c attr.tree=<empty tree>) prevents it (observed).

A strict-xfail test records the shadowing cases. The fix is to run the judge isolated (python -I) and without installing this project (uv sync --no-install-project, uv run --no-sync). That is a workflow change, in #459 (gate-only, stacked on this PR); the checkout abort has been reported for it too.

Effects on other PRs

Tests

tests/test_thesis_append_shim_isolation.py is in the CI "Ledger observation invariants" list and in Arch checks.

It covers 17 deciders:

  • scripts/receipt_pins.py;
  • pyproject.toml, uv.lock, uv.toml, .python-version and .python-versions;
  • hatch.toml and hatch_build.py;
  • scripts/sitecustomize.py and a root sitecustomize.py;
  • scripts/__pycache__/receipt_pins.cpython-314.pyc;
  • a .venv .pth;
  • .gitattributes, releases/.gitattributes, scripts/.gitattributes, .github/.gitattributes and .github/workflows/.gitattributes.

The cases:

  • A witnessed append plus a change to any one decider is refused as mixed, and the refusal names it.
  • Each decider changed alone is a named gate-only proposal.
  • A symlink committed at .venv or scripts/__pycache__, beside an append, is refused as mixed.
  • The fixtures force-add the changed path, so an ignore file cannot drop it from the commit.
  • A pure append beside unchanged deciders passes with the exact accepting output. This is the resolver's shape.
  • A scripts/build_series_catalog.py change beside an append stays a data proposal.
  • Measured. An audit-hook run of an accepting verdict records every file the gate opens or imports from its own checkout, and checks that all of them are on the surface.
  • Structural. These are pinned:
    • the workflow's PYTHONPATH and uv sync --project spellings;
    • the hatchling backend;
    • the exact surface;
    • every dir/** entry also listed bare;
    • every .gitattributes above a surface entry on the surface;
    • the builder off the surface.
  • Open limit. A strict xfail (raises=AssertionError) asserts that five shadowing modules are on the surface. It fails loudly once that becomes true.

tests/test_receipt_shim_transparency.py pins the exact widening over the original gate's surface, using an AST read of the hash-authenticated fixture. No differential case touches a decider, so byte-identity is unaffected.

Verification

  • At a7c013a (the scripts/** surface), run locally on 2026-09-29:

    • the CI "Ledger observation invariants" list: 174 passed, 5 xfailed;
    • a mutation check: with the old surface, 16 of the 17 new isolation tests failed;
    • the push-path gate and verify_release_chain.py --full: OK.
  • At 8438230, CI (pull-request runs):

    • invariants list: 190 passed, 7 xfailed;
    • catalog tests: 284 passed;
    • Arch surface: 240 passed, 1 skipped, 5 xfailed;
    • trusted base gate: OK.

    The push-triggered Arch checks run failed at "Identity anchor move continues the base pin". It compared against this branch's September tip, which predates the anchor fixture; the pull-request run compares against the base and passed.

  • At e0f6734: ruff check and ruff format --check (repo-pinned 0.14.10) are clean. CI passes on both the push and pull-request runs:

    • invariants list: 204 passed, 10 xfailed;
    • catalog tests: 284 passed;
    • Arch surface: 240 passed, 1 skipped, 5 xfailed;
    • trusted base gate: OK: 351 rows, immutable prefix 128, +0 appended vs base, release 34.

    This push also cleared the push-run anchor check.

  • At c29e1de (the nested .gitattributes entries): ruff check and ruff format --check are clean, and the two changed test files pass locally (94 passed, 5 xfailed). CI is running. A separate run of the full pytest tests, the classification replays (including Series catalog: canonical registry for the thesis fact ledger #128, Fold seven entity-drift lineages into their economy/aggregate siblings #344 and a scripts/.gitattributes case) and the mutation check is queued.

  • Independent review: queued, read-only. Its report will be linked here.

🤖 Generated with Claude Code

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>
@MaxGhenis

Copy link
Copy Markdown
Contributor Author

Arch checks is red for a reason that predates this PR: tests/test_build_series_catalog.py::test_committed_catalog_is_current_and_valid fails on its transcribed stripped-segments list (At index 32 diff: 'week_2026-08-29' != 'week_2026_06_13'). The base commit 598f394 fails the same way. #306 updates that list. Once #306 merges, this branch will be brought up to date (branch protection is strict), and the remaining Arch steps, including this PR's new tests, will run. An independent Opus review is queued.

@vahid-ahmadi vahid-ahmadi left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One gap in the invariant this PR states ("every file in the judging (base) checkout that can decide a verdict is on gate_surface"):

The repo root is on the judge's sys.path, so a root sitecustomize.py runs in the judge. .github/workflows/thesis-facts-append.yml:102 builds the judge's environment with uv sync --locked --no-dev --project "$base_gate", without --no-install-project. pyproject.toml builds with hatchling (packages = ["arch", "db", "micro", "calibration", "packages"]) and has no [tool.uv] package = false, so uv installs the base checkout editable (uv.lock:1643, source = { editable = "." }). Hatchling's editable .pth adds the repository root to sys.path, and site then imports sitecustomize from there at startup. A root sitecustomize.py is on neither gate_surface (scripts/receipt_pins.py:89-111) nor the data surface. Going by this PR's description of how receipt 0.6.2 treats unclassified files (dropped on the data path), a ledger append that also adds one would pass as data and go unnamed. That is the same class as the scripts/receipt_pins.py case this PR fixes.

Reproduced on a scratch project with the same build config, using the job's exact invocation from another cwd: PYTHONPATH=$P/scripts PYTHONNOUSERSITE=1 uv run --locked --no-dev --project $P python $P/scripts/judge.py. The venv gets _editable_impl_<name>.pth pointing at the project root, and a root sitecustomize.py executed during the judge script.

The gate scripts import only the stdlib and receipt, so the simplest fix is --no-install-project on the judge's uv sync/uv run (or [tool.uv] package = false), plus a regression case with a root sitecustomize.py in tests/test_thesis_append_shim_isolation.py. That also takes arch/, db/ and the rest off the judge's import path. Adding root sitecustomize.py to gate_surface is the narrower alternative. Until one of these lands, the new README sentence that the surface "lists every base-checkout file that can decide a verdict" overstates it.

Review drafted with AI assistance and checked against the code at a7c013a.

MaxGhenis and others added 2 commits November 29, 2026 07:24
…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>
@MaxGhenis MaxGhenis changed the title Put every file that decides a gate verdict on the gate surface Put the files that decide a gate verdict on the gate surface Nov 29, 2026
MaxGhenis and others added 2 commits December 1, 2026 11:43
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>
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>
MaxGhenis added a commit that referenced this pull request Dec 1, 2026
Both pull request jobs check the base commit out to run its gate. Git
applied the base's .gitattributes to that checkout, at every depth. A
boolean working-tree-encoding, or a required filter whose smudge fails,
then stops the checkout before it writes a file. The job 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 or anchors rewrites the bytes the judge
runs from or pins; receipt refuses a proposal that adds one, but that is
a property of the receipt version.

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. Under the root .gitattributes today (text eol=lf, binary
and -text) a Linux checkout writes the committed bytes either way. 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 a base holding a
boolean working-tree-encoding off the surface, and one holding an
encoding on the gate's scripts. The pull request that removes either is
judged on both paths, and the judge's scripts and anchors match their
committed bytes. The control takes the empty tree out of the trusted
job's step, and git refuses the checkout, or Python the rewritten gate.
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
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>
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.

2 participants