diff --git a/research/selected-preflight-path-reuse/BENCHMARK-python312.json b/research/selected-preflight-path-reuse/BENCHMARK-python312.json new file mode 100644 index 0000000000..757619b2a4 --- /dev/null +++ b/research/selected-preflight-path-reuse/BENCHMARK-python312.json @@ -0,0 +1,153 @@ +{ + "scope": "Selected source-binding check only; complete inputs, warm filesystem, fresh Python process per sample; excludes startup/import/source-pin overhead.", + "base_commit": "7788b59946ebf3803dc38b6a19b47b4acb27f40b", + "python": "3.12.14 (main, Aug 12 2026, 13:57:54) [Clang 21.0.0 (clang-2100.1.1.101)]", + "platform": "macOS-26.3.1-arm64-arm-64bit", + "machine": "arm64", + "generated_at_utc": "2026-10-15T21:58:37Z", + "candidate_sha256": "a2397f5879a370b024b6b65dec316beca8f8716d1b06add4dbe06788f4b66ad6", + "baseline_sha256": "d7fd929726b326aeeaf0a3996475adec88eee9aac09ae0bebeeaa0bc1fc8f199", + "benchmark_sources": { + "certificates/selected-result.json": "10b9e340fd8e354a37a0c4813c90e5de1dd42044b5f6aca4a3fc5a42b685fa32", + "research/community-frontier1094-audit/SELECTED-SOURCE.json": "79b3de5db3dbcb9829789ba58e9e45758926031e2a7d80667a08429d369be53b" + }, + "samples": [ + { + "pair": 0, + "engine": "baseline", + "seconds": 0.29369462467730045, + "kappa": "836330098538459/500000000000000000", + "process_seconds": 0.3356675421819091 + }, + { + "pair": 0, + "engine": "candidate", + "seconds": 0.20178499957546592, + "kappa": "836330098538459/500000000000000000", + "process_seconds": 0.24236704176291823 + }, + { + "pair": 1, + "engine": "candidate", + "seconds": 0.20281712524592876, + "kappa": "836330098538459/500000000000000000", + "process_seconds": 0.24518337519839406 + }, + { + "pair": 1, + "engine": "baseline", + "seconds": 0.29281887505203485, + "kappa": "836330098538459/500000000000000000", + "process_seconds": 0.3327307081781328 + }, + { + "pair": 2, + "engine": "baseline", + "seconds": 0.2723348750732839, + "kappa": "836330098538459/500000000000000000", + "process_seconds": 0.3145917500369251 + }, + { + "pair": 2, + "engine": "candidate", + "seconds": 0.20877129072323442, + "kappa": "836330098538459/500000000000000000", + "process_seconds": 0.2517342087812722 + }, + { + "pair": 3, + "engine": "candidate", + "seconds": 0.2108765421435237, + "kappa": "836330098538459/500000000000000000", + "process_seconds": 0.2513171252794564 + }, + { + "pair": 3, + "engine": "baseline", + "seconds": 0.34591124998405576, + "kappa": "836330098538459/500000000000000000", + "process_seconds": 0.3924720832146704 + }, + { + "pair": 4, + "engine": "baseline", + "seconds": 0.3307564170099795, + "kappa": "836330098538459/500000000000000000", + "process_seconds": 0.40487383399158716 + }, + { + "pair": 4, + "engine": "candidate", + "seconds": 0.2307357075624168, + "kappa": "836330098538459/500000000000000000", + "process_seconds": 0.2745297090150416 + }, + { + "pair": 5, + "engine": "candidate", + "seconds": 0.20768620818853378, + "kappa": "836330098538459/500000000000000000", + "process_seconds": 0.2519654999487102 + }, + { + "pair": 5, + "engine": "baseline", + "seconds": 0.2887097499333322, + "kappa": "836330098538459/500000000000000000", + "process_seconds": 0.3299917089752853 + }, + { + "pair": 6, + "engine": "baseline", + "seconds": 0.2763425000011921, + "kappa": "836330098538459/500000000000000000", + "process_seconds": 0.31849349988624454 + }, + { + "pair": 6, + "engine": "candidate", + "seconds": 0.20603050012141466, + "kappa": "836330098538459/500000000000000000", + "process_seconds": 0.2464440413750708 + }, + { + "pair": 7, + "engine": "candidate", + "seconds": 0.2102356250397861, + "kappa": "836330098538459/500000000000000000", + "process_seconds": 0.25102295773103833 + }, + { + "pair": 7, + "engine": "baseline", + "seconds": 0.2895739581435919, + "kappa": "836330098538459/500000000000000000", + "process_seconds": 0.3292368329130113 + }, + { + "pair": 8, + "engine": "baseline", + "seconds": 0.2748460406437516, + "kappa": "836330098538459/500000000000000000", + "process_seconds": 0.3152926666662097 + }, + { + "pair": 8, + "engine": "candidate", + "seconds": 0.21229212498292327, + "kappa": "836330098538459/500000000000000000", + "process_seconds": 0.2538549997843802 + } + ], + "median_seconds": { + "baseline": 0.2895739581435919, + "candidate": 0.20877129072323442 + }, + "ratio": 1.3870391716238253, + "median_process_seconds": { + "baseline": 0.3299917089752853, + "candidate": 0.2513171252794564 + }, + "process_ratio": 1.313049035589379, + "timing_is_acceptance_gate": false +} diff --git a/research/selected-preflight-path-reuse/BENCHMARK.json b/research/selected-preflight-path-reuse/BENCHMARK.json new file mode 100644 index 0000000000..26243be31a --- /dev/null +++ b/research/selected-preflight-path-reuse/BENCHMARK.json @@ -0,0 +1,153 @@ +{ + "scope": "Selected source-binding check only; complete inputs, warm filesystem, fresh Python process per sample; excludes startup/import/source-pin overhead.", + "base_commit": "7788b59946ebf3803dc38b6a19b47b4acb27f40b", + "python": "3.14.7 (main, Aug 5 2026, 10:29:49) [Clang 21.0.0 (clang-2100.1.1.101)]", + "platform": "macOS-26.3.1-arm64-arm-64bit-Mach-O", + "machine": "arm64", + "generated_at_utc": "2026-10-15T21:58:20Z", + "candidate_sha256": "a2397f5879a370b024b6b65dec316beca8f8716d1b06add4dbe06788f4b66ad6", + "baseline_sha256": "d7fd929726b326aeeaf0a3996475adec88eee9aac09ae0bebeeaa0bc1fc8f199", + "benchmark_sources": { + "certificates/selected-result.json": "10b9e340fd8e354a37a0c4813c90e5de1dd42044b5f6aca4a3fc5a42b685fa32", + "research/community-frontier1094-audit/SELECTED-SOURCE.json": "79b3de5db3dbcb9829789ba58e9e45758926031e2a7d80667a08429d369be53b" + }, + "samples": [ + { + "pair": 0, + "engine": "baseline", + "seconds": 0.22039004135876894, + "kappa": "836330098538459/500000000000000000", + "process_seconds": 0.26792333275079727 + }, + { + "pair": 0, + "engine": "candidate", + "seconds": 0.16109600011259317, + "kappa": "836330098538459/500000000000000000", + "process_seconds": 0.20989416679367423 + }, + { + "pair": 1, + "engine": "candidate", + "seconds": 0.16718433424830437, + "kappa": "836330098538459/500000000000000000", + "process_seconds": 0.21458304207772017 + }, + { + "pair": 1, + "engine": "baseline", + "seconds": 0.30679741594940424, + "kappa": "836330098538459/500000000000000000", + "process_seconds": 0.4451370001770556 + }, + { + "pair": 2, + "engine": "baseline", + "seconds": 0.26966883335262537, + "kappa": "836330098538459/500000000000000000", + "process_seconds": 0.3222092501819134 + }, + { + "pair": 2, + "engine": "candidate", + "seconds": 0.1738962079398334, + "kappa": "836330098538459/500000000000000000", + "process_seconds": 0.22177812503650784 + }, + { + "pair": 3, + "engine": "candidate", + "seconds": 0.17723145801573992, + "kappa": "836330098538459/500000000000000000", + "process_seconds": 0.22707920894026756 + }, + { + "pair": 3, + "engine": "baseline", + "seconds": 0.225103666074574, + "kappa": "836330098538459/500000000000000000", + "process_seconds": 0.27277562487870455 + }, + { + "pair": 4, + "engine": "baseline", + "seconds": 0.22103654220700264, + "kappa": "836330098538459/500000000000000000", + "process_seconds": 0.26937608420848846 + }, + { + "pair": 4, + "engine": "candidate", + "seconds": 0.17445579217746854, + "kappa": "836330098538459/500000000000000000", + "process_seconds": 0.22185212466865778 + }, + { + "pair": 5, + "engine": "candidate", + "seconds": 0.17289512511342764, + "kappa": "836330098538459/500000000000000000", + "process_seconds": 0.22248570900410414 + }, + { + "pair": 5, + "engine": "baseline", + "seconds": 0.22229970898479223, + "kappa": "836330098538459/500000000000000000", + "process_seconds": 0.2705402080900967 + }, + { + "pair": 6, + "engine": "baseline", + "seconds": 0.2314319577999413, + "kappa": "836330098538459/500000000000000000", + "process_seconds": 0.27859029173851013 + }, + { + "pair": 6, + "engine": "candidate", + "seconds": 0.17357029160484672, + "kappa": "836330098538459/500000000000000000", + "process_seconds": 0.22327170800417662 + }, + { + "pair": 7, + "engine": "candidate", + "seconds": 0.1682809591293335, + "kappa": "836330098538459/500000000000000000", + "process_seconds": 0.22653195774182677 + }, + { + "pair": 7, + "engine": "baseline", + "seconds": 0.2552580004557967, + "kappa": "836330098538459/500000000000000000", + "process_seconds": 0.3099038330838084 + }, + { + "pair": 8, + "engine": "baseline", + "seconds": 0.24856925010681152, + "kappa": "836330098538459/500000000000000000", + "process_seconds": 0.30569579219445586 + }, + { + "pair": 8, + "engine": "candidate", + "seconds": 0.17378870816901326, + "kappa": "836330098538459/500000000000000000", + "process_seconds": 0.22739729192107916 + } + ], + "median_seconds": { + "baseline": 0.2314319577999413, + "candidate": 0.17357029160484672 + }, + "ratio": 1.333361577376522, + "median_process_seconds": { + "baseline": 0.27859029173851013, + "candidate": 0.22248570900410414 + }, + "process_ratio": 1.2521716248002746, + "timing_is_acceptance_gate": false +} diff --git a/research/selected-preflight-path-reuse/README.md b/research/selected-preflight-path-reuse/README.md new file mode 100644 index 0000000000..3abae32d3d --- /dev/null +++ b/research/selected-preflight-path-reuse/README.md @@ -0,0 +1,106 @@ +# Selected-record preflight: reuse checked canonical paths + +An **opt-in verifier prototype**, starting from canonical main +`7788b59946ebf3803dc38b6a19b47b4acb27f40b`, priority revision 5. +The complete selected source-binding check is **1.33–1.39 times faster** on +the measured host, saving about **58–81 ms per check**. This is a small +preflight improvement; no whole cold-replay or multiplication speedup is claimed. + +The production checker, frozen inputs, selected record and two byte-pinned +consumer audits remain unchanged. The investigation is +[Discussion 2787](https://github.com/CrocSwap/integer-mult-bounds/discussions/2787). +Scope, overlap, source hashes, exact Git blobs and remaining obligations are in +[TASK.json](TASK.json) and [SOURCES.json](SOURCES.json). + +## Delta and why it preserves coverage + +The retained `scripts/verify_selected_result.py` resolves each enumerated file +to check containment, then resolves all inventory paths again to build the set +of hash-covered primary-proof targets. The second pass is measurable on the +selected 1,579-file, 66,386,573-byte inventory, particularly its deep vendor paths. +An entry profile recorded 3,413 `Path.resolve` calls in one complete preflight. + +[candidate.py](candidate.py) yields `(inventory_path, resolved_path)` from +`package_files` and accumulates the latter while hashing the former. The legacy +manifest remains excluded from both the inventory and proof coverage. The +modern inventory still rejects overlapping roots. The candidate's only other +changes are its location-dependent `ROOT`, documentation and attribution. + +For a filesystem stable during one invocation, the reused canonical path is +exactly `(inventory_root / inventory_name).resolve()`, which the original +checker recomputes. Both manifest formats therefore give the same covered-path +set, including contained aliases. Complete inventory/hash equality still must +pass before that set can admit a primary proof. Certificate, arithmetic, +supplement, publication-pointer and optimized-CLI checks are retained. +Every invocation enumerates and hashes every source again; nothing is cached +between calls. Concurrent filesystem mutation remains outside the inherited +source-closure contract. + +## Reproduce + +From the repository root, using Python 3.12 or 3.14: + +```sh +python3.12 -B research/selected-preflight-path-reuse/verify.py +python3.12 -B research/selected-preflight-path-reuse/benchmark.py \ + --pairs 9 --out /tmp/new-selected-preflight-benchmark.json +``` + +Use a fresh output path. No third-party dependencies or network access are +needed. Expected verification output is `PASS_SELECTED_PREFLIGHT_PATH_REUSE`. +These are explicit manual commands; this package does not register a generic +CI replay or replace the selected cold-replay command. + +The verifier checks pinned source bytes, then runs the existing selected-result, +inventory-link and primary-proof suites against each engine: **25 inherited +groups plus four new groups per engine**, with no skipped groups permitted. +The extra groups exercise same-size source corruption with restored mtime, +same-content alias retargeting after success, an unhashed manifest selected as +primary proof, and overlapping nested roots. Both actual optimized CLIs must +also refuse execution. Both Python versions passed all 58 groups and both CLI +refusals. No independent human review is claimed. + +## Measurements and limits + +Nine alternating pairs per interpreter, one fresh child process per sample, +on a shared macOS 26.3.1 arm64 host with warm filesystem caches: + +| Interpreter | Original median | Candidate median | Ratio | +| --- | ---: | ---: | ---: | +| CPython 3.12.14 | 289.6 ms | 208.8 ms | 1.39× | +| CPython 3.14.7 | 231.4 ms | 173.6 ms | 1.33× | + +The timed region is the complete `check(record)` call. Import, interpreter +startup and benchmark source-pin overhead are excluded from this table. +The recorded full benchmark-worker process medians, including that overhead, +are 330.0 → 251.3 ms (3.12) and 278.6 → 222.5 ms (3.14). These worker processes +include the benchmark harness; they are not direct production-CLI timings. +Raw samples, interpreter/platform details and exact code/input bindings are in +[BENCHMARK-python312.json](BENCHMARK-python312.json) and +[BENCHMARK.json](BENCHMARK.json). Every sample checks the complete selected +inventory and returns the same exact kappa. Timings are measurements, never +acceptance thresholds or performance guarantees. + +No complete selected construction replay, mathematical supplier admission, +other operating system, hosted CI or new kappa is claimed. Source-binding +preflight success retains the original checker’s limited meaning. + +## Open next questions + +Does this small repeated-preflight saving justify default adoption? First measure +its cumulative cost in the intended review workflow. If worthwhile, port the +delta while explicitly providing successor provenance for +`selected-binding-coverage-seeda342` and `selected-dependency-heads-audit`, which +pin the original checker. Their existing pins and evidence are preserved here; +production compatibility migration and their replays remain separate work. +The structured question is in [TASK.json](TASK.json). + +## Credit + +Douglas Colkitt wrote and integrated the original checker. Mihir Srivastava’s +PR841 supplies primary-proof provenance guards; yssite’s PR959 supplies inventory +symlink closure. Aaron Wang’s PR1864 and the selected dependency-head audit +retain their source-binding evidence. The contribution reproduces their guarded +checker as a prototype and preserves their regression suites. + +Prepared by Arham Tahir with substantial OpenAI Codex assistance. Apache-2.0. diff --git a/research/selected-preflight-path-reuse/SOURCES.json b/research/selected-preflight-path-reuse/SOURCES.json new file mode 100644 index 0000000000..1bd6061cfa --- /dev/null +++ b/research/selected-preflight-path-reuse/SOURCES.json @@ -0,0 +1,22 @@ +{ + "base_commit": "7788b59946ebf3803dc38b6a19b47b4acb27f40b", + "live_sources": { + "scripts/verify_selected_result.py": "d7fd929726b326aeeaf0a3996475adec88eee9aac09ae0bebeeaa0bc1fc8f199", + "tests/test_selected_result.py": "b387bb442334da679bdf6262e51d57355f7ec07be420427826cde7b6555c31bc", + "tests/test_selected_inventory_links.py": "3f20ce025720eab12a65878696148acb9daeceadff6792085a3ea3bfa113836c", + "tests/test_selected_proof_binding.py": "1a470b0b00c6fe138200cb1e475bc5b0ee338f7f5b00bb578215851b218097a1" + }, + "benchmark_sources": { + "certificates/selected-result.json": "10b9e340fd8e354a37a0c4813c90e5de1dd42044b5f6aca4a3fc5a42b685fa32", + "research/community-frontier1094-audit/SELECTED-SOURCE.json": "79b3de5db3dbcb9829789ba58e9e45758926031e2a7d80667a08429d369be53b" + }, + "git_blobs": { + "scripts/verify_selected_result.py": "c755b76e0d44ba4917aa94440ebe54daefce5b2a", + "tests/test_selected_result.py": "1b52d9beae0c7a49ac587ebcc3a5409055d1d3f8", + "tests/test_selected_inventory_links.py": "2a7c8022e7948d205356a2d361da8f6f5b658930", + "tests/test_selected_proof_binding.py": "aebae9ce5bea1afb1a73dde32a032221f57d7634", + "certificates/selected-result.json": "ae6a99f28aa468649eb66a361e764d769363bf11", + "research/community-frontier1094-audit/SELECTED-SOURCE.json": "6a75493790b4eff9c4a98051ef8b01d6aad0d5a8" + }, + "scope": "Source-binding preflight only. Every benchmark source inventory and supplement is rehashed by both checkers. No production checker or frozen source changed. Filesystem must be stable during each call, as in the retained source-closure audit." +} diff --git a/research/selected-preflight-path-reuse/TASK.json b/research/selected-preflight-path-reuse/TASK.json new file mode 100644 index 0000000000..af9fcde6e5 --- /dev/null +++ b/research/selected-preflight-path-reuse/TASK.json @@ -0,0 +1,128 @@ +{ + "schema_version": 1, + "task_id": "replay-runtime", + "base_commit": "7788b59946ebf3803dc38b6a19b47b4acb27f40b", + "priority_revision": 5, + "chooser_seed": "1a2c3b83571a37bade43d14d29f91afb", + "scope_key": "b1dd41940c60d240b47a/selected-source-binding/canonical-path-reuse", + "original_card": { + "id": "replay-runtime", + "question": "Can one measured replay bottleneck be sped up without dropping coverage?", + "starting_points": [ + "scripts/run_isolated_tests.py", + "scripts/verify_replay_coverage.py", + "certificates/selected-result.json" + ], + "methods": [ + "Profile one isolated replay and optimize the measured bottleneck.", + "Design source-bound reuse with explicit dependency invalidation and negative controls." + ], + "acceptance_gate": "Report before/after wall time on the same fixture, retained checks and invalidation behavior.", + "first_step": { + "command": [ + "python3", + "-B", + "scripts/research_baseline.py" + ], + "expected": "PASS_RESEARCH_BASELINE_BINDINGS_ONLY", + "inspect": "Read the selected reproduction command and choose a single replay stage for profiling.", + "scope": "Positive control / source-bound orientation only; this is not a new construction or full cold replay." + }, + "first_experiment": "Measure one unchanged fixture, preserve check coverage, and test one optimization with invalidation controls.", + "bottleneck_link": "Faster trustworthy replays increase review throughput and let mechanism candidates be checked sooner.", + "allowed_variations": [ + "Profile one stage or design one source-bound cache boundary." + ], + "scope_change_triggers": [ + "Skipping coverage or comparing different fixtures to claim speedup." + ], + "overlap_terms": [ + "replay runtime", + "cache invalidation", + "isolated tests" + ] + }, + "scope_status": "refined", + "scope_change_reason": "Choose the selected source-binding preflight as the measured stage. Preserve live checker bytes because two registered audits pin them; provide an opt-in prototype, not production adoption.", + "actual_scope": "Reuse canonical inventory paths within one selected-record check, preserving all source hashes and proof-membership checks under the retained stable-filesystem scope. Cover both manifest formats, the full current selected inventory, inherited regressions and fresh-call mutation controls.", + "bottleneck_link": "Reduce repeated preflight verification work without caching successful checks or changing mathematical coverage. This saves only about 0.06-0.08 seconds per selected preflight on the measured host.", + "time_budget_minutes": 60, + "stop_rule": "One measured preflight optimization; abandon if equivalence fails or alternating same-fixture timings show no improvement. No wider verifier rewrite or supplier work.", + "outcome": "completed", + "evidence": "verify.py: 29 behavioral groups per engine and explicit optimized-CLI refusal; BENCHMARK.json and BENCHMARK-python312.json: nine fresh-process alternating pairs each, every call rehashes the full source inventory.", + "discussion": "https://github.com/CrocSwap/integer-mult-bounds/discussions/2787", + "entry_overlap": { + "open_prs": 719, + "discussion_records": 1425, + "local_records": 1977, + "pr_fetched_at": "2026-10-15T21:52:04.529196+00:00", + "discussions_fetched_at": "2026-10-15T21:54:41.165131+00:00", + "complete_pagination": true, + "warnings": [], + "limits": "Titles/bodies/replies and top-level local notes, not arbitrary diffs or code. No match is not proof of novelty.", + "nearby_work": [ + "PR2734 historical snapshot copy/hash", + "PR2676 direct-runner cancellation", + "PR1864 selected binding coverage audit", + "selected-dependency-heads-audit source-pinned consumer", + "PR959 inventory symlink closure", + "PR841 primary-proof binding" + ] + }, + "author": "Arham Tahir", + "ai_assistance": "Substantial OpenAI Codex assistance; no independent human or delegated-agent review.", + "predecessors": [ + "Douglas Colkitt: original selected-result checker and maintainer integration", + "Mihir Srivastava / PR841: primary-proof provenance guards", + "yssite / PR959: source-inventory symlink closure", + "Aaron Wang / PR1864: source-binding coverage audit; preserved byte-exactly" + ], + "remaining_obligations": [ + "Default adoption must deliberately supersede the two live byte-pinned audit dependencies, preserving their evidence and credit.", + "Stable filesystem during each check is inherited. Concurrent mutation, execution authentication and supplier/full multiplication proof are not covered.", + "Whole cold-replay runtime, other platforms and hosted CI were not measured." + ], + "open_questions": [ + { + "question": "Does this small repeated-preflight saving justify default adoption?", + "why_it_matters": "The prototype saves measured work, but source-pinned consumers make a production migration larger than this local delta.", + "first_step": "Measure repeated preflights in the intended review workflow; if worthwhile, port the delta with successor provenance and replay the two pinned audits.", + "blocked_by": "A separate explicit compatibility migration for selected-binding-coverage-seeda342 and selected-dependency-heads-audit; neither frozen package is modified here." + } + ], + "validation": { + "python3.12.14": "58 behavioral groups, zero skips, both optimized CLIs refused", + "python3.14.7": "58 behavioral groups, zero skips, both optimized CLIs refused", + "positive_cli_equivalence": [ + "certificates/selected-result.json", + "certificates/checkpoints/frontier1042.json" + ], + "preserved_consumer_metadata_and_pins": [ + "research/selected-binding-coverage-seeda342", + "research/selected-dependency-heads-audit" + ], + "whitespace": "git diff --cached --check" + }, + "compatibility_checkpoint": { + "canonical_main": "84f8e607779b81c05edc962d4981d1f9b4b9bc9f", + "checked_at_utc": "2026-10-15T22:02:05Z", + "relevant_changes": "No changes to AGENTS.md, autoresearch.md, task catalogue, priority/family status, selected record, checker or the three inherited test modules since the pinned scientific base." + }, + "final_overlap": { + "searched_at": "2026-10-15T22:02:51.787693+00:00", + "coverage": { + "open_prs": { + "fetched_at": "2026-10-15T22:00:09.085253+00:00", + "complete_pagination": true, + "records": 723 + }, + "discussions": { + "fetched_at": "2026-10-15T22:02:51.669836+00:00", + "complete_pagination": true, + "records": 1434 + } + }, + "warnings": [], + "finding": "Exact-scope results include this canonical claim and credited source-binding/proof predecessors; no competing path-reuse runtime claim found in reported coverage. No-match coverage is not proof of novelty." + } +} diff --git a/research/selected-preflight-path-reuse/benchmark.py b/research/selected-preflight-path-reuse/benchmark.py new file mode 100644 index 0000000000..6f893a84be --- /dev/null +++ b/research/selected-preflight-path-reuse/benchmark.py @@ -0,0 +1,85 @@ +#!/usr/bin/env python3 +"""Alternating fresh-process timings; no performance pass threshold or result cache. + +Arham Tahir with substantial OpenAI Codex assistance. Apache-2.0. +""" +import argparse +from hashlib import sha256 +import json +import os +from pathlib import Path +import platform +import statistics +import subprocess +import sys +import time + +from verify import HERE, ROOT, check_sources, load, require + + +def worker(engine): + sources = check_sources() + for name, expected in sources['benchmark_sources'].items(): + require(sha256((ROOT / name).read_bytes()).hexdigest() == expected, + 'Benchmark fixture changed: ' + name) + path = ROOT / 'scripts/verify_selected_result.py' if engine == 'baseline' else HERE / 'candidate.py' + checker = load('measured_preflight', path) + record = json.loads((ROOT / 'certificates/selected-result.json').read_text()) + start = time.perf_counter() + kappa = checker.check(record) + elapsed = time.perf_counter() - start + print(json.dumps(dict(engine=engine, seconds=elapsed, kappa=str(kappa)))) + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--pairs', type=int, default=7) + parser.add_argument('--out', type=Path) + parser.add_argument('--worker', choices=('baseline', 'candidate'), help=argparse.SUPPRESS) + args = parser.parse_args() + require(not sys.flags.optimize, 'Assertions must remain enabled') + if args.worker: + worker(args.worker) + return + require(3 <= args.pairs <= 30, 'Use 3..30 alternating pairs') + require(args.out is not None and not args.out.exists(), 'Use a fresh --out file') + sources = check_sources() + # Verify the full fixture once before measuring; no cold-disk timing claim. + env = os.environ.copy() + env.pop('PYTHONOPTIMIZE', None) + env['PYTHONDONTWRITEBYTECODE'] = '1' + def run(engine): + start = time.perf_counter() + result = subprocess.run([sys.executable, '-B', str(Path(__file__).resolve()), + '--worker', engine], cwd=ROOT, env=env, + capture_output=True, text=True, timeout=30, check=True) + return dict(json.loads(result.stdout), process_seconds=time.perf_counter() - start) + run('baseline') + rows = [] + for pair in range(args.pairs): + for engine in (('baseline', 'candidate') if pair % 2 == 0 else ('candidate', 'baseline')): + row = run(engine) + require(row['kappa'] == '836330098538459/500000000000000000', 'Result differs') + rows.append(dict(pair=pair, **row)) + medians = {engine: statistics.median(row['seconds'] for row in rows if row['engine'] == engine) + for engine in ('baseline', 'candidate')} + process_medians = {engine: statistics.median(row['process_seconds'] for row in rows if row['engine'] == engine) + for engine in ('baseline', 'candidate')} + receipt = dict(scope='Selected source-binding check only; complete inputs, warm filesystem, fresh Python process per sample; excludes startup/import/source-pin overhead.', + base_commit=sources['base_commit'], python=sys.version, + platform=platform.platform(), machine=platform.machine(), + generated_at_utc=time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime()), + candidate_sha256=sha256((HERE / 'candidate.py').read_bytes()).hexdigest(), + baseline_sha256=sources['live_sources']['scripts/verify_selected_result.py'], + benchmark_sources=sources['benchmark_sources'], samples=rows, + median_seconds=medians, ratio=medians['baseline'] / medians['candidate'], + median_process_seconds=process_medians, + process_ratio=process_medians['baseline'] / process_medians['candidate'], + timing_is_acceptance_gate=False) + with args.out.open('x', encoding='utf-8') as stream: + stream.write(json.dumps(receipt, indent=2) + '\n') + print(json.dumps(dict(median_seconds=medians, ratio=receipt['ratio']))) + + +if __name__ == '__main__': + main() diff --git a/research/selected-preflight-path-reuse/candidate.py b/research/selected-preflight-path-reuse/candidate.py new file mode 100644 index 0000000000..b2b1a25b76 --- /dev/null +++ b/research/selected-preflight-path-reuse/candidate.py @@ -0,0 +1,110 @@ +#!/usr/bin/env python3 +"""Opt-in prototype: reuse checked paths in selected-record source binding. + +This fast check does not replay the construction. Run the selected record's +reproduce command +for the complete selected finite replay. Douglas Colkitt, with OpenAI Codex +assistance. Path reuse by Arham Tahir with substantial OpenAI Codex +assistance; primary-proof guards retain Mihir Srivastava and the source-closure +lineage. The production verifier and its frozen consumers are unchanged. +Apache-2.0. +""" +from fractions import Fraction +from hashlib import sha256 +from pathlib import Path +import argparse +import json +import sys + +ROOT = Path(__file__).resolve().parents[2] +if hasattr(sys, 'set_int_max_str_digits'): + sys.set_int_max_str_digits(0) + + +def require(condition, message): + if not condition: + raise ValueError(message) + + +def path(root, relative): + p = (root / relative).resolve() + require(p.is_relative_to(root.resolve()) and p.is_file(), 'Invalid selected file: ' + relative) + return p + + +def package_files(package): + """Yield each inventory path and its checked canonical path, without caching.""" + for p in package.rglob('*'): + # rglob does not descend into directory symlinks. Reject them (and + # dangling links) before is_file can silently remove them from coverage. + require(not p.is_symlink() or p.is_file(), + 'Package symlink is not a regular file: ' + str(p)) + if p.is_file(): + resolved = p.resolve() + require(resolved.is_relative_to(package), 'Package symlink escapes root') + yield p, resolved + + +def check(record, root=ROOT): + root = root.resolve() + certificate_path = path(root, record['certificate']) + certificate = json.loads(certificate_path.read_text()) + kappa = Fraction(record['kappa']) + require(kappa > 0 and kappa == Fraction(certificate['kappa']), 'Selected kappa differs from finite certificate') + require(kappa == Fraction(record['decimal']), 'Selected decimal differs from exact kappa') + require(sha256(certificate_path.read_bytes()).hexdigest() == record['certificate_sha256'], + 'Selected certificate bytes changed') + manifest_path = path(root, record['source_manifest']) + manifest = json.loads(manifest_path.read_text()) + require(manifest.get('files'), 'Empty selected source inventory') + verified_paths = set() + if manifest.get('format') == 'repository-packages-sha256-v1': + roots = manifest.get('package_roots', []) + require(roots and len(roots) == len(set(roots)), 'Invalid package roots') + actual = {} + for relative in roots: + package = (root / relative).resolve() + require(package.is_relative_to(root.resolve()) and package != root.resolve() + and package.is_dir(), 'Invalid package root: ' + relative) + for p, resolved in package_files(package): + name = p.relative_to(root).as_posix() + require(name not in actual, 'Overlapping package roots') + actual[name] = sha256(p.read_bytes()).hexdigest() + verified_paths.add(resolved) + else: + package = manifest_path.parent + actual = {} + for p, resolved in package_files(package): + if p != manifest_path: + actual[p.relative_to(package).as_posix()] = sha256(p.read_bytes()).hexdigest() + verified_paths.add(resolved) + require(actual == manifest['files'], 'Selected package inventory or bytes changed') + # Canonical paths come from this invocation's containment checks, in both + # inventory formats. No source digest or filesystem result survives a call. + require(record['proof_supplements'], 'Missing construction proof supplement') + for relative, digest in record['proof_supplements'].items(): + require(sha256(path(root, relative).read_bytes()).hexdigest() == digest, + 'Selected proof supplement changed: ' + relative) + verified_paths.add(path(root, relative)) + require(path(root, record['proof']) in verified_paths, + 'Selected primary proof is not covered by a verified digest') + # Other publication pointers retain their existence check; any explicit + # digest above still applies. + for key in ('review', 'validation'): + path(root, record[key]) + return kappa + + +def main(): + require(not sys.flags.optimize, 'Assertions must remain enabled for the verification pipeline') + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--record', type=Path, default=ROOT / 'certificates/selected-result.json', + help='Selected or historical checkpoint record to verify') + args = parser.parse_args() + record = json.loads(args.record.read_text()) + kappa = check(record) + print('PASS selected record, exact kappa, original source inventory and proof supplement: ' + str(kappa)) + + +if __name__ == '__main__': + main() diff --git a/research/selected-preflight-path-reuse/verify.py b/research/selected-preflight-path-reuse/verify.py new file mode 100644 index 0000000000..ca9ded3d9b --- /dev/null +++ b/research/selected-preflight-path-reuse/verify.py @@ -0,0 +1,140 @@ +#!/usr/bin/env python3 +"""Behavioral equivalence and fresh-call invalidation for the preflight prototype. + +Arham Tahir with substantial OpenAI Codex assistance. Apache-2.0. +""" +from hashlib import sha256 +import importlib.util +import json +import os +from pathlib import Path +import subprocess +import sys +import tempfile +import unittest + +HERE = Path(__file__).resolve().parent +ROOT = HERE.parents[1] + + +def require(condition, message): + if not condition: + raise ValueError(message) + + +def load(name, path): + spec = importlib.util.spec_from_file_location(name, path) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + return module + + +def check_sources(): + sources = json.loads((HERE / 'SOURCES.json').read_text()) + for name, expected in sources['live_sources'].items(): + require(sha256((ROOT / name).read_bytes()).hexdigest() == expected, + 'Pinned source changed: ' + name) + return sources + + +class FreshCallControls(unittest.TestCase): + def each_layout(self, run): + for modern in (False, True): + with self.subTest(modern=modern), tempfile.TemporaryDirectory() as td: + root = Path(td).resolve() + record = self.fixtures.fixture(root, modern) + run(root, record, modern) + + def test_same_size_change_with_restored_mtime(self): + def run(root, record, modern): + source = root / record['proof'] + original = source.read_bytes() + stamp = source.stat() + self.checker.check(record, root) + source.write_bytes(bytes([original[0] ^ 1]) + original[1:]) + os.utime(source, ns=(stamp.st_atime_ns, stamp.st_mtime_ns)) + self.assertEqual(source.stat().st_size, len(original)) + self.assertEqual(source.stat().st_mtime_ns, stamp.st_mtime_ns) + with self.assertRaisesRegex(ValueError, 'inventory or bytes changed'): + self.checker.check(record, root) + source.write_bytes(original) + self.assertEqual(self.checker.check(record, root), self.fixtures.Fraction(1, 1000)) + self.each_layout(run) + + def test_alias_retargeted_after_success(self): + def run(root, record, modern): + source = root / record['proof'] + alias = root / 'supplier/alias.txt' + try: + alias.symlink_to('PROOF.md') + except (OSError, NotImplementedError) as exc: + self.skipTest(str(exc)) + manifest_path = root / record['source_manifest'] + manifest = json.loads(manifest_path.read_text()) + manifest['files']['supplier/alias.txt' if modern else 'alias.txt'] = sha256(source.read_bytes()).hexdigest() + manifest_path.write_text(json.dumps(manifest)) + self.checker.check(record, root) + outside = root / 'outside.txt' + outside.write_bytes(source.read_bytes()) + alias.unlink() + alias.symlink_to('../outside.txt') + with self.assertRaisesRegex(ValueError, 'Package symlink escapes root'): + self.checker.check(record, root) + self.each_layout(run) + + def test_unhashed_manifest_cannot_be_primary_proof(self): + def run(root, record, modern): + record['proof'] = record['source_manifest'] + with self.assertRaisesRegex(ValueError, 'primary proof is not covered'): + self.checker.check(record, root) + self.each_layout(run) + + def test_overlapping_nested_roots_still_rejected(self): + with tempfile.TemporaryDirectory() as td: + root = Path(td).resolve() + record = self.fixtures.fixture(root, True) + nested = root / 'supplier/nested' + nested.mkdir() + (nested / 'extra.txt').write_bytes(b'covered twice') + path = root / record['source_manifest'] + manifest = json.loads(path.read_text()) + manifest['package_roots'].append('supplier/nested') + manifest['files']['supplier/nested/extra.txt'] = sha256((nested / 'extra.txt').read_bytes()).hexdigest() + path.write_text(json.dumps(manifest)) + with self.assertRaisesRegex(ValueError, 'Overlapping package roots'): + self.checker.check(record, root) + + +def main(): + require(not sys.flags.optimize, 'Run equivalence tests with assertions enabled') + check_sources() + total = 0 + for engine, path in (('baseline', ROOT / 'scripts/verify_selected_result.py'), + ('candidate', HERE / 'candidate.py')): + checker = load('preflight_' + engine, path) + suite = unittest.TestSuite() + for name in ('test_selected_result', 'test_selected_inventory_links', + 'test_selected_proof_binding'): + tests = load(engine + '_' + name, ROOT / 'tests' / (name + '.py')) + tests.checker = checker + suite.addTests(unittest.defaultTestLoader.loadTestsFromModule(tests)) + fixtures = load(engine + '_fixtures', ROOT / 'tests/test_selected_proof_binding.py') + controls = type(engine + '_FreshCallControls', (FreshCallControls,), + {'checker': checker, 'fixtures': fixtures}) + suite.addTests(unittest.defaultTestLoader.loadTestsFromTestCase(controls)) + count = suite.countTestCases() + result = unittest.TextTestRunner(verbosity=1).run(suite) + require(result.wasSuccessful() and not result.skipped, + engine + ' equivalence/control suite failed or skipped') + total += count + print(engine, count, 'behavioral groups PASS', flush=True) + optimized = subprocess.run([sys.executable, '-I', '-B', '-O', str(path)], + capture_output=True, text=True, timeout=10) + require(optimized.returncode != 0 and 'Assertions must remain enabled' in optimized.stderr, + engine + ' optimized CLI did not fail closed') + check_sources() + print('PASS_SELECTED_PREFLIGHT_PATH_REUSE', total, 'behavioral groups; both optimized CLIs refused') + + +if __name__ == '__main__': + main()