From a4e96df5d9edda047ca45c7d8f50894208552e61 Mon Sep 17 00:00:00 2001 From: Dylan Roy Date: Sun, 27 Sep 2026 17:09:39 -0500 Subject: [PATCH 1/3] Add read-only release source custody and pinned primary Lean replay OpenAI/ChatGPT implementation under Dylan Roy's delegated authority. Fourteen collector tests pass in normal and optimized Python, including a red-before-green authenticated redirect control. No scientific status, proof body, formal registry, or merge permission is changed. Hosted execution remains to be observed. --- .github/workflows/release-snapshot.yml | 96 +++++++ docs/RELEASE_OPERATIONS.md | 72 ++++++ .../plans/2026-09-27-release-snapshot.md | 13 + .../specs/2026-09-27-release-snapshot.md | 9 + tests/test_release_snapshot.py | 107 ++++++++ tools/release_snapshot.py | 240 ++++++++++++++++++ 6 files changed, 537 insertions(+) create mode 100644 .github/workflows/release-snapshot.yml create mode 100644 docs/RELEASE_OPERATIONS.md create mode 100644 docs/superpowers/plans/2026-09-27-release-snapshot.md create mode 100644 docs/superpowers/specs/2026-09-27-release-snapshot.md create mode 100644 tests/test_release_snapshot.py create mode 100644 tools/release_snapshot.py diff --git a/.github/workflows/release-snapshot.yml b/.github/workflows/release-snapshot.yml new file mode 100644 index 000000000..dfc52c25d --- /dev/null +++ b/.github/workflows/release-snapshot.yml @@ -0,0 +1,96 @@ +name: Release source custody and pinned toolchain replay +on: + pull_request: + paths: + - tools/release_snapshot.py + - tests/test_release_snapshot.py + - .github/workflows/release-snapshot.yml + - docs/RELEASE_OPERATIONS.md + workflow_dispatch: +permissions: + contents: read +concurrency: + group: release-snapshot-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: false +jobs: + source-custody: + runs-on: ubuntu-24.04 + timeout-minutes: 35 + steps: + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 + with: + persist-credentials: false + - name: Read-only collector controls in both Python modes + run: | + python3 -B -S -m unittest discover -s tests -p test_release_snapshot.py -v + python3 -B -O -S -m unittest discover -s tests -p test_release_snapshot.py -v + - name: Capture all allowlisted defaults and open PR source heads + env: + GITHUB_TOKEN: ${{ github.token }} + run: python3 -B -S tools/release_snapshot.py --output "$RUNNER_TEMP/release-snapshot" + - name: Preserve source and review snapshots, including partial failures + if: always() + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 + with: + name: release-source-custody-${{ github.run_id }} + path: ${{ runner.temp }}/release-snapshot/ + if-no-files-found: error + include-hidden-files: true + retention-days: 90 + primary-toolchain-replay: + runs-on: ubuntu-24.04 + timeout-minutes: 30 + env: + LEAN_NUM_THREADS: '2' + steps: + - name: Read the exact merged primary formal project + uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 + with: + repository: d6g8k5htny-coder/Math- + ref: 867d9e34b60186ff46ab5b3ecf8ad5ba6a5cc8b4 + persist-credentials: false + - name: Check source and regression controls before installing tools + run: | + python3 -B -S -m unittest discover -s formal/tests -v + python3 -B -O -S -m unittest discover -s formal/tests -v + python3 -B -S formal/gate.py + - uses: leanprover/lean-action@50fcf42d2e460296f1a34b402e990d1b24f8b596 + with: + lake-package-directory: formal + auto-config: 'false' + build: 'false' + test: 'false' + lint: 'false' + use-mathlib-cache: 'true' + use-github-cache: 'false' + - name: Rebuild, replay kernel, audit axioms and run false-proof controls + run: python3 -B -S formal/gate.py --execute + - name: Record installed runtime versions and executable hashes + if: always() + shell: bash + run: | + mkdir -p formal/.lake/formal-evidence + { + echo 'Execution location: disposable GitHub-hosted runner, not the owner laptop' + git rev-parse HEAD + python3 --version + git --version + elan --version + cd formal + lake env lean --version + lake --version + for name in lean lake leanchecker; do + resolved="$(lake env which "$name")" || continue + printf '%s: %s\n' "$name" "$resolved" + sha256sum "$resolved" + done + } > formal/.lake/formal-evidence/runner-tools.txt 2>&1 + - name: Preserve fresh primary evidence + if: always() + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 + with: + name: primary-toolchain-evidence-${{ github.run_id }} + path: formal/.lake/formal-evidence/ + include-hidden-files: true + if-no-files-found: error + retention-days: 90 diff --git a/docs/RELEASE_OPERATIONS.md b/docs/RELEASE_OPERATIONS.md new file mode 100644 index 000000000..6a39d9344 --- /dev/null +++ b/docs/RELEASE_OPERATIONS.md @@ -0,0 +1,72 @@ +# Release operations and source custody + +Owner authorization: Dylan Roy, 27 September 2026. Scientific effect: **NONE**. + +The existing [formal-verification guide](FORMAL_VERIFICATION.md), Math- formal +project, and [coordination issue #95](https://github.com/d6g8k5htny-coder/main/issues/95) +remain the integration entry points. This is not another scientific registry, +promotion engine, automatic merger, or scheduled agent loop. + +## Download and reproduce + +`tools/release_snapshot.py --output ` uses Python 3.11+ and Git. +It reads only the ten explicit public repositories in its allowlist, exhausts API +pagination, and records default commits and open same-repository PR heads. Sources +are archived directly from Git blobs, including export-ignored files; every blob's +Git identity and SHA-256 are checked. Symlinks are archived as link-target bytes, +not followed. Submodule gitlinks are listed, not recursively fetched. No complete +Git history, Git LFS hydration, personal Drive content, model weights, credentials, +or installation on the owner's laptop is implied. API/download failures produce +an explicit partial report and nonzero exit, never an empty successful queue. + +`SUMMARY.json`, per-commit manifests and `SHA256SUMS` bind the evidence. A snapshot +is an as-of observation, not a permanently current branch tip. Before extracting +an archive, validate paths and symlinks. Use isolated checkouts for executing code. + +The `Release source custody and pinned toolchain replay` Actions workflow runs +on relevant PRs or manual dispatch. It has read-only permissions, immutable action +pins, no persisted checkout credential and no privileged PR trigger. Evidence is +retained for 90 days by the requested artifact policy; download important receipts +for durable custody before expiration. Repository-policy limits can shorten retention. + +The separate primary replay job checks out Math- at +`867d9e34b60186ff46ab5b3ecf8ad5ba6a5cc8b4`, installs the existing locked Lean/mathlib +environment, and executes the unchanged source gate, kernel replay, axiom audit +and false-proof controls. Runtime versions and executable hashes are captured. +A workflow definition is not an installation receipt: only an observed successful +run licenses a statement that these tools were installed and executed there. + +## Review and merge + +Read the exact diff, full reviews and unresolved threads, current tests and source +bindings. A successful static check is not a fresh Lean execution. An absent check +is not a passing check. Re-fetch the PR immediately before a merge and use +`expected_head_sha`. A changed source or scope stales the corresponding review. +Do not bypass branch protection or simulate another account's approval. The owner +may delegate engineering integration, but delegation does not create independent +review or satisfy a mathematical premise. Record your actual provider/session and +scope; when agents share a GitHub account, a comment must not be represented as an +independent GitHub approval. + +Existing mathematical HOLD/AMENDs remain until their own evidence is reviewed. +Close genuinely superseded engineering PRs with successor links and preserved +history, not by merging obsolete code. Resolve parallel proposals by reusing their +useful components under explicit namespaces and source crosswalks rather than +landing competing registries. Do not race an active writer's branch. + +## All current and future agents + +Coordinate in main #95 and the relevant existing PR, not a parallel dispatch +system. Math- #92 and main #177 established the first merged formal foundation. +Math- #93, main #178, sandbox #3 and trial #160 were separately observed proposals. +Main #178 subsequently merged at `eaf12644bdcbf6176a9e216ffb4ab9304f17de12` +during this audit. Preserve that work and reconcile interfaces rather than +silently replacing it or claiming unobserved review. Trial's 4.19.0 experiment +must not be presented as the primary 4.34.1 toolchain. Keep component evidence, +semantic alignment, source custody, and scientific acceptance separate. + +An assignment or notification is OFFERED until a recipient posts a source-bound +pickup/result. Publishing this file does not prove every agent has read it. +Optional Blueprint publishing, external prover weights, additional proof-assistant +backends and an independent checker require their own explicit run receipts; they +are not prerequisites to call an isolated scalar Lean proof kernel-checked. diff --git a/docs/superpowers/plans/2026-09-27-release-snapshot.md b/docs/superpowers/plans/2026-09-27-release-snapshot.md new file mode 100644 index 000000000..6c59e4b2e --- /dev/null +++ b/docs/superpowers/plans/2026-09-27-release-snapshot.md @@ -0,0 +1,13 @@ +# Release snapshot implementation plan + +Goal: reproducible, read-only repository/PR custody and primary toolchain replay. +Architecture: one stdlib collector plus isolated GitHub Actions jobs; existing formal gates retain their scoped evidence roles. No new scientific-status database. +Tech stack: Python 3, Git, GitHub REST GET, existing pinned Lean action. +Spec: ../specs/2026-09-27-release-snapshot.md + +1. Write tests for immutable SHA/repo validation, complete pagination, unsafe paths, actual Git blob archive identity, tampering, gitlink exclusion, authenticated redirect refusal and nonempty output discipline. Observe RED, then implement tools/release_snapshot.py and run both Python modes. +2. Add .github/workflows/release-snapshot.yml: tests, snapshot, primary pinned replay, always-save evidence. Record exact runtime identities and failure limitations. +3. Create an isolated integration branch and PR; inspect hosted results. Download artifacts into the active container and verify archive/log digests. Use snapshots to inspect open PR diffs and current reviews, then merge only eligible changes using expected_head_sha. +4. Record every action/blocker in existing main #95 and per-PR conversations; publish permanent agent entry pointers without claiming acknowledgments not observed. + +Review focus: pagination truncation, fork/URL substitution, Git attribute exclusions, source drift, unmaterialized gitlinks, missing API access, premature merge eligibility. Each must fail closed or remain explicitly incomplete. Owner preapproval permits inline execution; no subagent independence is represented. diff --git a/docs/superpowers/specs/2026-09-27-release-snapshot.md b/docs/superpowers/specs/2026-09-27-release-snapshot.md new file mode 100644 index 000000000..7ec067d58 --- /dev/null +++ b/docs/superpowers/specs/2026-09-27-release-snapshot.md @@ -0,0 +1,9 @@ +# Release snapshot and integration design + +Owner: Dylan Roy, explicit autonomous implementation and merge-management request of 2026-09-27. Scientific effect: NONE. + +Use the existing main #95 and Math-/formal foundation. Add one read-only, manually reproducible evidence collector, not another formal registry, promotion engine, scheduler or agent loop. It records all ten currently accessible owner repositories, their default commit, every open same-repository PR head, current CI/review evidence, and exact downloadable source snapshots. A snapshot is as-of evidence, never a claim of current tip equality. Archive all tracked blobs at each pinned commit, verify Git blob identities, compute SHA-256 and record gitlinks without traversing them. No credentials enter source archives or reports. Restrict remote reads to the explicit public owner/repository allowlist. API pages must be exhausted or an error recorded; retrieval failure cannot become an empty queue. Snapshot errors produce a nonzero exit and a partial report. + +The hosted workflow uses read-only permissions, immutable action refs, no persisted checkout credential and no privileged PR trigger. A separate job installs the existing pinned primary Lean/mathlib environment and replays its unchanged gate at the observed merged Math- commit. Actual execution is the installation evidence. No assertion that Dylan's computer has been installed or that optional research/prover tools were run. + +Reconcile overlapping formal proposals by source-bound reviews in their own PRs. Do not modify peer branches, erase historical failures, self-approve or change mathematical verdicts. Merge decisions remain separate, exact-head operations after diff/review/check inspection; source changes stale prior reviews. diff --git a/tests/test_release_snapshot.py b/tests/test_release_snapshot.py new file mode 100644 index 000000000..5ee35097d --- /dev/null +++ b/tests/test_release_snapshot.py @@ -0,0 +1,107 @@ +import hashlib +import importlib.util +import json +import pathlib +import subprocess +import tempfile +import unittest +import zipfile + +ROOT = pathlib.Path(__file__).resolve().parents[1] +spec = importlib.util.spec_from_file_location('release_snapshot', ROOT / 'tools/release_snapshot.py') +m = importlib.util.module_from_spec(spec) if spec else None +if spec and spec.loader and (ROOT/'tools/release_snapshot.py').exists(): + spec.loader.exec_module(m) + +class SnapshotTests(unittest.TestCase): + def test_implementation_exists(self): + self.assertTrue(hasattr(m, 'snapshot_local'), 'read-only collector is not implemented') + + def test_redirects_are_refused(self): + self.assertTrue(hasattr(m, "NoRedirect"), "authenticated redirects must fail closed") + self.assertIsNone(m.NoRedirect().redirect_request(None, None, 302, "redirect", {}, "https://outside.invalid")) + + def test_sha(self): + self.assertEqual(m.checked_sha('a'*40), 'a'*40) + for value in ('main', 'abc', 'A'*40, 'a'*39+'g', '', None, 12): + with self.subTest(value=value), self.assertRaises(ValueError): m.checked_sha(value) + + def test_owner(self): + self.assertEqual(m.repo_url('Math-'), 'https://github.com/d6g8k5htny-coder/Math-.git') + for value in ('other/repo', '../main', 'main;id', '', 'https://evil.invalid'): + with self.subTest(value=value), self.assertRaises(ValueError): m.repo_url(value) + + def test_paths(self): + self.assertEqual(m.checked_path('formal/A.lean'), 'formal/A.lean') + for value in ('../a', '/a', 'a/../b', 'a//b', './a', 'a\\b', '', 'a\x00b'): + with self.subTest(value=value), self.assertRaises(ValueError): m.checked_path(value) + + def test_pagination(self): + calls=[] + def get(path): + calls.append(path) + return list(range(100)) if 'page=1&' in path else [100] + out=m.pages(get, 'repos/x/pulls') + self.assertEqual(len(out),101) + self.assertEqual(len(calls),2) + + def test_pagination_key(self): + self.assertEqual(m.pages(lambda p:{'check_runs':[{'id':1}]}, 'repos/x/check-runs', 'check_runs'),[{'id':1}]) + + def test_missing_key_not_empty(self): + with self.assertRaises(ValueError): m.pages(lambda p:{}, 'repos/x/check-runs', 'check_runs') + + def test_error_not_empty(self): + def bad(path): raise PermissionError('403') + with self.assertRaises(PermissionError): m.pages(bad,'repos/x/pulls') + + def test_wrong_page_type(self): + with self.assertRaises(ValueError): m.pages(lambda p:{'items':[]}, 'repos/x/pulls') + + def test_blob_hash(self): + b=b'proof\n'; oid=hashlib.sha1(b'blob 6\0'+b).hexdigest() + self.assertEqual(m.blob_digest(oid,b),hashlib.sha256(b).hexdigest()) + with self.assertRaises(ValueError): m.blob_digest(oid,b'wrong\n') + + def test_empty_output_only(self): + with tempfile.TemporaryDirectory() as d: + p=pathlib.Path(d)/'out'; m.fresh_output(p) + (p/'old').write_text('old') + with self.assertRaises(FileExistsError): m.fresh_output(p) + + def test_exact_archive_with_export_ignore_and_symlink(self): + with tempfile.TemporaryDirectory() as d: + root=pathlib.Path(d); repo=root/'repo'; repo.mkdir() + def git(*args): + return subprocess.check_output(['git','-C',str(repo),*args],stderr=subprocess.DEVNULL).decode().strip() + git('init','-q');git('config','user.email','test@example.invalid');git('config','user.name','test') + (repo/'proof.txt').write_bytes(b'exact proof\n') + (repo/'.gitattributes').write_text('proof.txt export-ignore\n') + (repo/'alias').symlink_to('proof.txt') + git('add','.');git('commit','-qm','fixture') + sha=git('rev-parse','HEAD'); dest=root/'out';dest.mkdir() + result=m.snapshot_local(repo,sha,dest/'source.zip') + with zipfile.ZipFile(dest/'source.zip') as z: + self.assertEqual(z.read('proof.txt'),b'exact proof\n') + self.assertEqual(z.read('alias'),b'proof.txt') + self.assertEqual(set(z.namelist()), {'.gitattributes','alias','proof.txt'}) + self.assertEqual(result['commit'],sha) + self.assertEqual(len(result['members']),3) + self.assertEqual(result['unmaterialized_gitlinks'],[]) + self.assertEqual(result['sha256'],hashlib.sha256((dest/'source.zip').read_bytes()).hexdigest()) + with self.assertRaises(FileExistsError): m.snapshot_local(repo,sha,dest/'source.zip') + + def test_gitlink_is_recorded_not_followed(self): + with tempfile.TemporaryDirectory() as d: + repo=pathlib.Path(d)/'repo';repo.mkdir() + def git(*args): + return subprocess.check_output(['git','-C',str(repo),*args],stderr=subprocess.DEVNULL).decode().strip() + git('init','-q');git('config','user.email','test@example.invalid');git('config','user.name','test') + (repo/'x').write_text('x');git('add','.');git('commit','-qm','one');parent=git('rev-parse','HEAD') + git('update-index','--add','--cacheinfo',f'160000,{parent},dependency');git('commit','-qm','gitlink') + sha=git('rev-parse','HEAD');out=pathlib.Path(d)/'out.zip' + result=m.snapshot_local(repo,sha,out) + self.assertEqual(result['unmaterialized_gitlinks'],[{'path':'dependency','commit':parent}]) + with zipfile.ZipFile(out) as z: self.assertNotIn('dependency',z.namelist()) + +if __name__ == '__main__': unittest.main() diff --git a/tools/release_snapshot.py b/tools/release_snapshot.py new file mode 100644 index 000000000..469fe2377 --- /dev/null +++ b/tools/release_snapshot.py @@ -0,0 +1,240 @@ +#!/usr/bin/env python3 +"""Read-only, as-of source/PR custody. No merge or scientific-status authority.""" +from __future__ import annotations +import argparse +import hashlib +import json +import os +from pathlib import Path, PurePosixPath +import re +import subprocess +import tempfile +from datetime import datetime, timezone +import urllib.parse +import urllib.request +import zipfile + +OWNER = 'd6g8k5htny-coder' +REPOS = ('main', 'Math-', 'trial', 'governance-', 'sandbox', 'query-', + 'meta-framework', 'google-drive', 'Universal-Law-Workspace', OWNER) + + +def checked_sha(value: str) -> str: + if not isinstance(value, str) or not re.fullmatch(r'[0-9a-f]{40}', value): + raise ValueError('expected immutable 40-character lowercase commit') + return value + + +def repo_url(name: str) -> str: + if name not in REPOS: + raise ValueError('repository is not in the owner allowlist') + return f'https://github.com/{OWNER}/{name}.git' + + +def checked_path(value: str) -> str: + if (not isinstance(value, str) or not value or '\\' in value or '\x00' in value + or value.startswith('/') or any(p in ('', '.', '..') for p in value.split('/'))): + raise ValueError('unsafe repository path') + if PurePosixPath(value).is_absolute(): + raise ValueError('absolute repository path') + return value + + +def fresh_output(path: Path) -> None: + if path.exists() and (not path.is_dir() or any(path.iterdir())): + raise FileExistsError('refusing to overwrite or mix prior snapshot evidence') + path.mkdir(parents=True, exist_ok=True) + + +def pages(get, path: str, key: str | None = None) -> list: + rows = [] + for page in range(1, 101): + sep = '&' if '?' in path else '?' + data = get(f'{path}{sep}page={page}&per_page=100') + if key is not None: + if not isinstance(data, dict) or key not in data: + raise ValueError('missing pagination collection: '+key) + data = data[key] + if not isinstance(data, list): + raise ValueError('expected a list page') + rows.extend(data) + if len(data) < 100: + return rows + raise ValueError('pagination safety cap reached; result is incomplete') + + +def blob_digest(oid: str, data: bytes) -> str: + checked_sha(oid) + actual = hashlib.sha1(b'blob '+str(len(data)).encode()+b'\0'+data).hexdigest() + if actual != oid: + raise ValueError('Git blob identity mismatch') + return hashlib.sha256(data).hexdigest() + + +def git(repo: Path, *args: str) -> bytes: + return subprocess.check_output(['git', '-C', str(repo), *args], + stderr=subprocess.PIPE, timeout=300) + + +def snapshot_local(repo: Path, sha: str, archive: Path) -> dict: + checked_sha(sha) + if archive.exists(): + raise FileExistsError(str(archive)) + if git(repo, 'rev-parse', sha+'^{commit}').decode().strip() != sha: + raise ValueError('resolved commit mismatch') + tree = git(repo, 'ls-tree', '-r', '-z', '--full-tree', sha) + members, gitlinks = [], [] + with zipfile.ZipFile(archive, 'x', compression=zipfile.ZIP_DEFLATED) as z: + for row in tree.split(b'\0'): + if not row: + continue + meta, raw_path = row.split(b'\t', 1) + mode, typ, oid = meta.decode().split() + path = checked_path(raw_path.decode('utf-8')) + if typ == 'commit' and mode == '160000': + gitlinks.append({'path': path, 'commit': checked_sha(oid)}) + continue + if typ != 'blob' or mode not in ('100644', '100755', '120000'): + raise ValueError('unsupported Git tree entry') + data = git(repo, 'cat-file', 'blob', oid) + digest = blob_digest(oid, data) + info = zipfile.ZipInfo(path, date_time=(1980, 1, 1, 0, 0, 0)) + info.create_system = 3 + info.external_attr = int(mode, 8) << 16 + info.compress_type = zipfile.ZIP_DEFLATED + z.writestr(info, data) + members.append({'path': path, 'git_mode': mode, 'git_blob': oid, + 'bytes': len(data), 'sha256': digest}) + with archive.open('rb') as f: + archive_digest = hashlib.file_digest(f, 'sha256').hexdigest() + return {'commit': sha, 'archive': archive.name, + 'sha256': archive_digest, + 'bytes': archive.stat().st_size, 'members': members, + 'unmaterialized_gitlinks': gitlinks, + 'scope': 'all tracked blobs at one commit; no history, LFS hydration or recursive submodules'} + + +class NoRedirect(urllib.request.HTTPRedirectHandler): + def redirect_request(self, req, fp, code, msg, headers, newurl): + # Refuse renamed-repository and external redirects rather than forward credentials. + return None + + +class Client: + def __init__(self): + self.token = os.environ.get('GITHUB_TOKEN', '') + self.opener = urllib.request.build_opener(NoRedirect()) + + def get(self, path: str): + parsed = urllib.parse.urlsplit(path) + if (parsed.scheme or parsed.netloc or not path.startswith(f'repos/{OWNER}/') + or path.split('/')[2] not in REPOS or '..' in path.split('/')): + raise ValueError('API path outside explicit repository allowlist') + headers = {'Accept': 'application/vnd.github+json', 'User-Agent': 'owner-release-snapshot', + 'X-GitHub-Api-Version': '2022-11-28'} + if self.token: + headers['Authorization'] = 'Bearer '+self.token + req = urllib.request.Request('https://api.github.com/'+path, headers=headers) + with self.opener.open(req, timeout=90) as response: + return json.load(response) + + +def write_json(path: Path, value) -> None: + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text(json.dumps(value, indent=2, ensure_ascii=True)+'\n') + + +def collect(out: Path, include_pr_sources: bool = True) -> dict: + fresh_output(out) + client = Client() + summary = {'schema_version': 1, 'observed_at': datetime.now(timezone.utc).isoformat(), + 'scientific_effect': 'NONE', 'merge_authority': False, + 'scope_repositories': list(REPOS), 'repositories': [], 'errors': []} + for name in REPOS: + row = {'repository': f'{OWNER}/{name}', 'pull_requests': [], 'snapshots': []} + summary['repositories'].append(row) + dest = out/name; dest.mkdir() + path = f'repos/{OWNER}/{name}' + def read(suffix, filename, key=None, paginated=False): + try: + value = pages(client.get, path+suffix, key) if paginated else client.get(path+suffix) + write_json(dest/filename, value) + return value + except Exception as exc: + summary['errors'].append({'repository': name, 'resource': suffix, + 'error': type(exc).__name__+': '+str(exc)}) + return None + meta = read('', 'repository.json') + if not meta or meta.get('private') is not False or meta.get('full_name') != f'{OWNER}/{name}': + summary['errors'].append({'repository': name, 'error': 'public identity not established'}) + continue + branch = meta['default_branch'] + commit = read('/commits/'+urllib.parse.quote(branch,safe=''), 'default-commit.json') + prs = read('/pulls?state=open', 'open-prs.json', paginated=True) + targets = {} + if commit: + sha = checked_sha(commit['sha']); row['default_commit'] = sha; targets[sha] = ['default'] + if prs is not None: + row['open_pr_count'] = len(prs) + for pr in prs: + n = pr['number']; prefix = f'pr-{n}/' + detail = read(f'/pulls/{n}', prefix+'detail.json') + if detail is None: + continue + sha = checked_sha(detail['head']['sha']) + item = {k:detail.get(k) for k in ('number','title','html_url','draft','mergeable','mergeable_state','state')} + item.update(head=sha, base=detail['base']['sha'], author=detail['user']['login']) + row['pull_requests'].append(item) + read(f'/pulls/{n}/files', prefix+'files.json', paginated=True) + read(f'/pulls/{n}/reviews', prefix+'reviews.json', paginated=True) + read(f'/issues/{n}/comments', prefix+'comments.json', paginated=True) + read(f'/pulls/{n}/comments', prefix+'inline-comments.json', paginated=True) + read(f'/commits/{sha}/check-runs', prefix+'checks.json', key='check_runs', paginated=True) + read(f'/commits/{sha}/status', prefix+'combined-status.json') + read(f'/actions/runs?head_sha={sha}', prefix+'runs.json', key='workflow_runs', paginated=True) + if include_pr_sources: + if detail['head']['repo'] and detail['head']['repo']['full_name'] == f'{OWNER}/{name}': + targets.setdefault(sha,[]).append(f'PR{n}') + else: + item['source_snapshot'] = 'not captured: fork outside same-repository scope' + read('/rulesets', 'rulesets.json', paginated=True) + with tempfile.TemporaryDirectory(prefix='release-git-') as tmp: + repo = Path(tmp) + subprocess.run(['git','init','--bare','-q',str(repo)],check=True,timeout=30) + git(repo,'remote','add','origin',repo_url(name)) + for sha, labels in targets.items(): + try: + git(repo, 'fetch','--quiet','--depth=1','origin',sha) + if git(repo,'rev-parse','FETCH_HEAD').decode().strip() != sha: + raise ValueError('fetch returned a different commit') + result=snapshot_local(repo,sha,dest/f'{sha}.zip') + result['labels']=labels + write_json(dest/f'{sha}.manifest.json', result) + row['snapshots'].append({k:v for k,v in result.items() if k!='members'}) + except Exception as exc: + summary['errors'].append({'repository':name,'commit':sha, + 'error':type(exc).__name__+': '+str(exc)}) + write_json(out/'SUMMARY.json',summary) + summary['completed_at']=datetime.now(timezone.utc).isoformat() + summary['complete']=not summary['errors'] + write_json(out/'SUMMARY.json',summary) + lines=[] + for p in sorted(out.rglob('*')): + if p.is_file(): + with p.open('rb') as f: digest=hashlib.file_digest(f,'sha256').hexdigest() + lines.append(f'{digest} {p.relative_to(out).as_posix()}') + (out/'SHA256SUMS').write_text('\n'.join(lines)+'\n') + return summary + + +def main() -> int: + p=argparse.ArgumentParser(description=__doc__) + p.add_argument('--output',type=Path,required=True) + p.add_argument('--defaults-only',action='store_true') + args=p.parse_args() + result=collect(args.output,not args.defaults_only) + print(json.dumps({'complete':result['complete'],'repositories':len(result['repositories']), + 'errors':result['errors']},indent=2)) + return 0 if result['complete'] else 1 + +if __name__=='__main__': raise SystemExit(main()) From 8603c636198235c75daed774cfcf4011399437e8 Mon Sep 17 00:00:00 2001 From: Dylan Roy Date: Sun, 27 Sep 2026 17:17:46 -0500 Subject: [PATCH 2/3] Bind formal source identity separately from the execution host Preserve the original primary receipt while adding an independently hash-bound context for cross-repository replay. Ten new tests observed red then green; all24 release tests pass in normal and optimized modes. First hosted run36354322676 remains preserved as history; this successor requires fresh execution and review. --- .github/workflows/release-snapshot.yml | 20 +++++++- docs/RELEASE_OPERATIONS.md | 9 ++++ tests/test_formal_execution_context.py | 49 ++++++++++++++++++ tools/formal_execution_context.py | 71 ++++++++++++++++++++++++++ 4 files changed, 147 insertions(+), 2 deletions(-) create mode 100644 tests/test_formal_execution_context.py create mode 100644 tools/formal_execution_context.py diff --git a/.github/workflows/release-snapshot.yml b/.github/workflows/release-snapshot.yml index dfc52c25d..2e3f77bc9 100644 --- a/.github/workflows/release-snapshot.yml +++ b/.github/workflows/release-snapshot.yml @@ -3,7 +3,9 @@ on: pull_request: paths: - tools/release_snapshot.py + - tools/formal_execution_context.py - tests/test_release_snapshot.py + - tests/test_formal_execution_context.py - .github/workflows/release-snapshot.yml - docs/RELEASE_OPERATIONS.md workflow_dispatch: @@ -24,6 +26,8 @@ jobs: run: | python3 -B -S -m unittest discover -s tests -p test_release_snapshot.py -v python3 -B -O -S -m unittest discover -s tests -p test_release_snapshot.py -v + python3 -B -S -m unittest discover -s tests -p test_formal_execution_context.py -v + python3 -B -O -S -m unittest discover -s tests -p test_formal_execution_context.py -v - name: Capture all allowlisted defaults and open PR source heads env: GITHUB_TOKEN: ${{ github.token }} @@ -40,13 +44,22 @@ jobs: primary-toolchain-replay: runs-on: ubuntu-24.04 timeout-minutes: 30 + defaults: + run: + working-directory: primary env: LEAN_NUM_THREADS: '2' steps: + - name: Read source-execution binding tools + uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 + with: + path: operations + persist-credentials: false - name: Read the exact merged primary formal project uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 with: repository: d6g8k5htny-coder/Math- + path: primary ref: 867d9e34b60186ff46ab5b3ecf8ad5ba6a5cc8b4 persist-credentials: false - name: Check source and regression controls before installing tools @@ -56,7 +69,7 @@ jobs: python3 -B -S formal/gate.py - uses: leanprover/lean-action@50fcf42d2e460296f1a34b402e990d1b24f8b596 with: - lake-package-directory: formal + lake-package-directory: primary/formal auto-config: 'false' build: 'false' test: 'false' @@ -65,6 +78,9 @@ jobs: use-github-cache: 'false' - name: Rebuild, replay kernel, audit axioms and run false-proof controls run: python3 -B -S formal/gate.py --execute + - name: Bind source and execution identities without rewriting the raw receipt + run: | + python3 -B -S ../operations/tools/formal_execution_context.py --source . --operations ../operations --expected-commit 867d9e34b60186ff46ab5b3ecf8ad5ba6a5cc8b4 --run-id "$GITHUB_RUN_ID" - name: Record installed runtime versions and executable hashes if: always() shell: bash @@ -90,7 +106,7 @@ jobs: uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 with: name: primary-toolchain-evidence-${{ github.run_id }} - path: formal/.lake/formal-evidence/ + path: primary/formal/.lake/formal-evidence/ include-hidden-files: true if-no-files-found: error retention-days: 90 diff --git a/docs/RELEASE_OPERATIONS.md b/docs/RELEASE_OPERATIONS.md index 6a39d9344..0849ad315 100644 --- a/docs/RELEASE_OPERATIONS.md +++ b/docs/RELEASE_OPERATIONS.md @@ -36,6 +36,15 @@ and false-proof controls. Runtime versions and executable hashes are captured. A workflow definition is not an installation receipt: only an observed successful run licenses a statement that these tools were installed and executed there. +**Cross-repository receipts:** the unchanged primary gate's `repository` field +records the Actions execution host (`main`), while `checked_commit` belongs to the +checked-out source (`Math-`). Do not pair those fields into a false source URL. +`execution-context.json` separately binds source repository/commit/remote, +execution repository/commit/run and the exact original receipt SHA-256. The binder +checks the live checkout identity and every recorded log hash. Original receipts +are preserved, not rewritten to conceal this distinction. Read the companion +context whenever replay is hosted in a different repository. + ## Review and merge Read the exact diff, full reviews and unresolved threads, current tests and source diff --git a/tests/test_formal_execution_context.py b/tests/test_formal_execution_context.py new file mode 100644 index 000000000..ddaa51c6b --- /dev/null +++ b/tests/test_formal_execution_context.py @@ -0,0 +1,49 @@ +import hashlib, importlib.util, json, pathlib, tempfile, unittest +ROOT=pathlib.Path(__file__).resolve().parents[1] +p=ROOT/'tools/formal_execution_context.py' +s=importlib.util.spec_from_file_location('ctx',p);m=importlib.util.module_from_spec(s) +if p.exists():s.loader.exec_module(m) +class ContextTests(unittest.TestCase): + def setUp(self): + self.tmp=tempfile.TemporaryDirectory();self.addCleanup(self.tmp.cleanup);self.root=pathlib.Path(self.tmp.name) + self.sha='a'*40; (self.root/'build.log').write_bytes(b'actual log\n') + self.receipt={'repository':'d6g8k5htny-coder/main','checked_commit':self.sha,'workflow_run_id':'123', 'formalization_status':'kernel-checked','scientific_effect':'NONE','logs':{'build.log':hashlib.sha256(b'actual log\n').hexdigest()}} + self.write() + self.kw={'source_repository':'d6g8k5htny-coder/Math-','expected_commit':self.sha,'observed_commit':self.sha,'observed_remote':'https://github.com/d6g8k5htny-coder/Math-','execution_repository':'d6g8k5htny-coder/main','execution_commit':'b'*40,'run_id':'123'} + def write(self): (self.root/'receipt.json').write_text(json.dumps(self.receipt)) + def bind(self):return m.bind(self.root/'receipt.json',**self.kw) + def test_distinct_source_and_execution_binding(self): + self.assertTrue(hasattr(m,'bind'),'cross-repository context binder is missing') + r=self.bind();self.assertEqual(r['source']['repository'],self.kw['source_repository']);self.assertEqual(r['execution']['repository'],self.kw['execution_repository']) + self.assertNotEqual(r['source']['repository'],r['execution']['repository']);self.assertEqual(r['receipt_repository_field_means'],'execution repository, not source repository') + self.assertEqual(r['receipt_sha256'],hashlib.sha256((self.root/'receipt.json').read_bytes()).hexdigest()) + def test_source_commit_mismatch(self): + self.kw['observed_commit']='c'*40 + with self.assertRaises(ValueError): self.bind() + def test_receipt_commit_mismatch(self): + self.receipt['checked_commit']='c'*40;self.write() + with self.assertRaises(ValueError): self.bind() + def test_source_remote_mismatch(self): + self.kw['observed_remote']='https://github.com/other/Math-' + with self.assertRaises(ValueError):self.bind() + def test_receipt_host_mismatch(self): + self.receipt['repository']='d6g8k5htny-coder/Math-';self.write() + with self.assertRaises(ValueError):self.bind() + def test_run_mismatch(self): + self.kw['run_id']='124' + with self.assertRaises(ValueError):self.bind() + def test_modified_log(self): + (self.root/'build.log').write_text('modified') + with self.assertRaises(ValueError):self.bind() + def test_log_path_escape(self): + self.receipt['logs']={'../build.log':'f'*64};self.write() + with self.assertRaises(ValueError):self.bind() + def test_kernel_status_is_required(self): + self.receipt['formalization_status']='specified';self.write() + with self.assertRaises(ValueError):self.bind() + def test_git_suffix(self): + self.kw['observed_remote']+=' .git' + with self.assertRaises(ValueError):self.bind() + self.kw['observed_remote']='https://github.com/d6g8k5htny-coder/Math-.git' + self.assertEqual(self.bind()['source']['commit'],self.sha) +if __name__=='__main__': unittest.main() diff --git a/tools/formal_execution_context.py b/tools/formal_execution_context.py new file mode 100644 index 000000000..4ec2561ad --- /dev/null +++ b/tools/formal_execution_context.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python3 +"""Bind an unchanged formal receipt to separate source and execution repositories.""" +from __future__ import annotations +import argparse +import hashlib +import json +from pathlib import Path +import re +import subprocess + + +def require(condition, message): + if not condition: + raise ValueError(message) + + +def exact_sha(value): + require(isinstance(value, str) and re.fullmatch(r'[0-9a-f]{40}', value), 'invalid exact commit') + return value + + +def bind(receipt_path: Path, *, source_repository: str, expected_commit: str, + observed_commit: str, observed_remote: str, execution_repository: str, + execution_commit: str, run_id: str) -> dict: + require(source_repository == 'd6g8k5htny-coder/Math-', 'unexpected primary source repository') + require(execution_repository == 'd6g8k5htny-coder/main', 'unexpected execution repository') + require(observed_remote in ('https://github.com/'+source_repository, + 'https://github.com/'+source_repository+'.git'), 'source remote mismatch') + require(exact_sha(expected_commit) == exact_sha(observed_commit), 'source commit mismatch') + exact_sha(execution_commit) + require(isinstance(run_id, str) and re.fullmatch(r'[0-9]+',run_id), 'invalid workflow run id') + raw=receipt_path.read_bytes(); receipt=json.loads(raw) + require(receipt.get('checked_commit') == observed_commit, 'receipt/source mismatch') + require(receipt.get('repository') == execution_repository, 'receipt execution host mismatch') + require(receipt.get('workflow_run_id') == run_id, 'receipt workflow mismatch') + require(receipt.get('scientific_effect') == 'NONE', 'unexpected scientific effect') + require(receipt.get('formalization_status') == 'kernel-checked', 'successful kernel receipt required') + logs=receipt.get('logs') + require(isinstance(logs,dict) and logs, 'missing log bindings') + for name,digest in logs.items(): + require(isinstance(name,str) and re.fullmatch(r'[A-Za-z0-9_-]+\.log',name), 'unsafe log path') + require(isinstance(digest,str) and re.fullmatch(r'[0-9a-f]{64}',digest), 'invalid log digest') + path=receipt_path.parent/name + require(not path.is_symlink(), 'symlinked log') + require(hashlib.sha256(path.read_bytes()).hexdigest()==digest, 'log digest mismatch') + return {'schema_version':1, 'scientific_effect':'NONE', + 'source':{'repository':source_repository,'commit':observed_commit,'remote':observed_remote}, + 'execution':{'repository':execution_repository,'commit':execution_commit,'workflow_run_id':run_id}, + 'receipt_sha256':hashlib.sha256(raw).hexdigest(), + 'receipt_repository_field_means':'execution repository, not source repository', + 'meaning':'Source/execution custody binding only; no independent alignment or scientific acceptance.'} + + +def main(): + p=argparse.ArgumentParser(description=__doc__) + p.add_argument('--source',type=Path,required=True) + p.add_argument('--operations',type=Path,required=True) + p.add_argument('--expected-commit',required=True) + p.add_argument('--run-id',required=True) + a=p.parse_args() + def git(root,*args): + return subprocess.check_output(['git','-C',str(root),*args],text=True,timeout=30).strip() + receipt=a.source/'formal/.lake/formal-evidence/receipt.json' + result=bind(receipt,source_repository='d6g8k5htny-coder/Math-',expected_commit=a.expected_commit, + observed_commit=git(a.source,'rev-parse','HEAD'),observed_remote=git(a.source,'remote','get-url','origin'), + execution_repository='d6g8k5htny-coder/main',execution_commit=git(a.operations,'rev-parse','HEAD'),run_id=a.run_id) + with (receipt.parent/'execution-context.json').open('x') as f: + json.dump(result,f,indent=2);f.write('\n') + print(json.dumps(result,indent=2)) + +if __name__=='__main__':main() From 86c34eeae8244621e10418df0b065962d4ba34d4 Mon Sep 17 00:00:00 2001 From: Dylan Roy Date: Sun, 27 Sep 2026 17:27:01 -0500 Subject: [PATCH 3/3] Close review findings on pagination, incomplete ZIPs and control paths Responds to Grok/Cursor engineering review of a4e96df. Total-count truncation/drift fails closed; snapshots publish only after all blobs validate; control-character paths are rejected. Six new regression cases observed RED before fixes, then all30 release tests passed in normal and optimized Python. Source/execution binding from8603 is retained. No scientific-status changes. --- tests/test_release_snapshot.py | 46 +++++++++++++++++++++++++++ tools/release_snapshot.py | 57 +++++++++++++++++++++------------- 2 files changed, 82 insertions(+), 21 deletions(-) diff --git a/tests/test_release_snapshot.py b/tests/test_release_snapshot.py index 5ee35097d..60e5207c5 100644 --- a/tests/test_release_snapshot.py +++ b/tests/test_release_snapshot.py @@ -6,6 +6,7 @@ import tempfile import unittest import zipfile +from unittest import mock ROOT = pathlib.Path(__file__).resolve().parents[1] spec = importlib.util.spec_from_file_location('release_snapshot', ROOT / 'tools/release_snapshot.py') @@ -104,4 +105,49 @@ def git(*args): self.assertEqual(result['unmaterialized_gitlinks'],[{'path':'dependency','commit':parent}]) with zipfile.ZipFile(out) as z: self.assertNotIn('dependency',z.namelist()) + def test_keyed_short_page_cannot_hide_total(self): + with self.assertRaisesRegex(ValueError, 'incomplete'): + m.pages(lambda _: {'total_count':250, 'check_runs':[{'id':1}]}, + 'repos/x/check-runs', 'check_runs') + + def test_keyed_total_count_success(self): + self.assertEqual(m.pages(lambda _: {'total_count':1, 'check_runs':[{'id':1}]}, + 'repos/x/check-runs', 'check_runs'), [{'id':1}]) + + def test_keyed_bad_total_count(self): + for count in (True, -1, '1', 0.5): + with self.subTest(count=count), self.assertRaises(ValueError): + m.pages(lambda _: {'total_count':count, 'check_runs':[]}, + 'repos/x/check-runs', 'check_runs') + + def test_keyed_total_drift_fails_closed(self): + def get(path): + return {'total_count':101, 'check_runs':list(range(100))} if 'page=1&' in path else {'total_count':102,'check_runs':[100,101]} + with self.assertRaisesRegex(ValueError, 'changed'): + m.pages(get, 'repos/x/check-runs', 'check_runs') + + def test_control_character_paths_rejected(self): + for value in ('line\nbreak', 'carriage\rreturn', 'tab\tfile', 'del\x7fete'): + with self.subTest(value=value), self.assertRaises(ValueError): m.checked_path(value) + + def test_no_published_zip_after_late_identity_failure(self): + with tempfile.TemporaryDirectory() as d: + root=pathlib.Path(d); repo=root/'repo';repo.mkdir() + def git(*args): + return subprocess.check_output(['git','-C',str(repo),*args],stderr=subprocess.DEVNULL).decode().strip() + git('init','-q');git('config','user.email','test@example.invalid');git('config','user.name','test') + (repo/'a.txt').write_text('a');(repo/'b.txt').write_text('b') + git('add','.');git('commit','-qm','two files');sha=git('rev-parse','HEAD') + out=root/'source.zip'; original=m.blob_digest; seen=[] + def corrupt_second(oid,data): + seen.append(oid) + if len(seen)==2: raise ValueError('injected identity mismatch') + return original(oid,data) + with mock.patch.object(m, 'blob_digest', side_effect=corrupt_second): + with self.assertRaisesRegex(ValueError, 'identity mismatch'): + m.snapshot_local(repo,sha,out) + self.assertEqual(len(seen),2) + self.assertFalse(out.exists(), 'failed snapshot must not publish a readable partial zip') + self.assertFalse(list(root.glob('.snapshot-*')), 'temporary snapshot was not cleaned') + if __name__ == '__main__': unittest.main() diff --git a/tools/release_snapshot.py b/tools/release_snapshot.py index 469fe2377..fc5701676 100644 --- a/tools/release_snapshot.py +++ b/tools/release_snapshot.py @@ -33,6 +33,7 @@ def repo_url(name: str) -> str: def checked_path(value: str) -> str: if (not isinstance(value, str) or not value or '\\' in value or '\x00' in value + or any(ord(c) < 32 or ord(c) == 127 for c in value) or value.startswith('/') or any(p in ('', '.', '..') for p in value.split('/'))): raise ValueError('unsafe repository path') if PurePosixPath(value).is_absolute(): @@ -48,17 +49,27 @@ def fresh_output(path: Path) -> None: def pages(get, path: str, key: str | None = None) -> list: rows = [] + expected_total = None for page in range(1, 101): sep = '&' if '?' in path else '?' data = get(f'{path}{sep}page={page}&per_page=100') if key is not None: if not isinstance(data, dict) or key not in data: raise ValueError('missing pagination collection: '+key) + if 'total_count' in data: + count = data['total_count'] + if type(count) is not int or count < 0: + raise ValueError('invalid pagination total_count') + if expected_total is not None and expected_total != count: + raise ValueError('pagination total_count changed; snapshot is incomplete') + expected_total = count data = data[key] if not isinstance(data, list): raise ValueError('expected a list page') rows.extend(data) if len(data) < 100: + if expected_total is not None and len(rows) != expected_total: + raise ValueError('incomplete pagination collection: total_count mismatch') return rows raise ValueError('pagination safety cap reached; result is incomplete') @@ -84,27 +95,31 @@ def snapshot_local(repo: Path, sha: str, archive: Path) -> dict: raise ValueError('resolved commit mismatch') tree = git(repo, 'ls-tree', '-r', '-z', '--full-tree', sha) members, gitlinks = [], [] - with zipfile.ZipFile(archive, 'x', compression=zipfile.ZIP_DEFLATED) as z: - for row in tree.split(b'\0'): - if not row: - continue - meta, raw_path = row.split(b'\t', 1) - mode, typ, oid = meta.decode().split() - path = checked_path(raw_path.decode('utf-8')) - if typ == 'commit' and mode == '160000': - gitlinks.append({'path': path, 'commit': checked_sha(oid)}) - continue - if typ != 'blob' or mode not in ('100644', '100755', '120000'): - raise ValueError('unsupported Git tree entry') - data = git(repo, 'cat-file', 'blob', oid) - digest = blob_digest(oid, data) - info = zipfile.ZipInfo(path, date_time=(1980, 1, 1, 0, 0, 0)) - info.create_system = 3 - info.external_attr = int(mode, 8) << 16 - info.compress_type = zipfile.ZIP_DEFLATED - z.writestr(info, data) - members.append({'path': path, 'git_mode': mode, 'git_blob': oid, - 'bytes': len(data), 'sha256': digest}) + with tempfile.TemporaryDirectory(prefix='.snapshot-', dir=archive.parent) as tmp: + temporary_archive = Path(tmp)/'source.zip' + with zipfile.ZipFile(temporary_archive, 'x', compression=zipfile.ZIP_DEFLATED) as z: + for row in tree.split(b'\0'): + if not row: + continue + meta, raw_path = row.split(b'\t', 1) + mode, typ, oid = meta.decode().split() + path = checked_path(raw_path.decode('utf-8')) + if typ == 'commit' and mode == '160000': + gitlinks.append({'path': path, 'commit': checked_sha(oid)}) + continue + if typ != 'blob' or mode not in ('100644', '100755', '120000'): + raise ValueError('unsupported Git tree entry') + data = git(repo, 'cat-file', 'blob', oid) + digest = blob_digest(oid, data) + info = zipfile.ZipInfo(path, date_time=(1980, 1, 1, 0, 0, 0)) + info.create_system = 3 + info.external_attr = int(mode, 8) << 16 + info.compress_type = zipfile.ZIP_DEFLATED + z.writestr(info, data) + members.append({'path': path, 'git_mode': mode, 'git_blob': oid, + 'bytes': len(data), 'sha256': digest}) + # Publish only after every member validates; link refuses to overwrite. + os.link(temporary_archive, archive) with archive.open('rb') as f: archive_digest = hashlib.file_digest(f, 'sha256').hexdigest() return {'commit': sha, 'archive': archive.name,