From 5793ceb2006cc5c4939fd2a80886b54ab119bc4f Mon Sep 17 00:00:00 2001 From: ywz65 <154373401+ywz65@users.noreply.github.com> Date: Thu, 15 Oct 2026 10:36:41 -0700 Subject: [PATCH] Compare strict replay payloads with a paired positive traversal --- .../strict-payload-paired-walk/BENCHMARK.json | 115 +++++++++++ .../strict-payload-paired-walk/OVERLAP.json | 88 +++++++++ research/strict-payload-paired-walk/README.md | 128 ++++++++++++ .../strict-payload-paired-walk/RESULT.json | 19 ++ .../strict-payload-paired-walk/SELECTION.json | 91 +++++++++ .../strict-payload-paired-walk/SOURCES.json | 85 ++++++++ research/strict-payload-paired-walk/TASK.json | 183 ++++++++++++++++++ .../VALIDATION.json | 28 +++ .../strict-payload-paired-walk/VERIFY.json | 43 ++++ .../strict-payload-paired-walk/benchmark.py | 50 +++++ .../strict-payload-paired-walk/compare.py | 120 ++++++++++++ .../test_compare.py | 77 ++++++++ research/strict-payload-paired-walk/verify.py | 162 ++++++++++++++++ 13 files changed, 1189 insertions(+) create mode 100644 research/strict-payload-paired-walk/BENCHMARK.json create mode 100644 research/strict-payload-paired-walk/OVERLAP.json create mode 100644 research/strict-payload-paired-walk/README.md create mode 100644 research/strict-payload-paired-walk/RESULT.json create mode 100644 research/strict-payload-paired-walk/SELECTION.json create mode 100644 research/strict-payload-paired-walk/SOURCES.json create mode 100644 research/strict-payload-paired-walk/TASK.json create mode 100644 research/strict-payload-paired-walk/VALIDATION.json create mode 100644 research/strict-payload-paired-walk/VERIFY.json create mode 100644 research/strict-payload-paired-walk/benchmark.py create mode 100644 research/strict-payload-paired-walk/compare.py create mode 100644 research/strict-payload-paired-walk/test_compare.py create mode 100644 research/strict-payload-paired-walk/verify.py diff --git a/research/strict-payload-paired-walk/BENCHMARK.json b/research/strict-payload-paired-walk/BENCHMARK.json new file mode 100644 index 0000000000..2d05f398c9 --- /dev/null +++ b/research/strict-payload-paired-walk/BENCHMARK.json @@ -0,0 +1,115 @@ +{ + "aggregate_median_ratio": 2.446938669690739, + "alternating_order_trials": 3, + "files": [ + { + "body_bytes": 14139930, + "file": "global/hosted/GLOBAL-TEMPLATE.json.gz", + "median_ratio": 2.5888696310711405, + "median_seconds": { + "original": 5.755338600000073, + "paired": 2.2231087000000116 + }, + "seconds": { + "original": [ + 5.182077499999991, + 5.805689799999982, + 5.755338600000073 + ], + "paired": [ + 2.164645500000006, + 2.2231087000000116, + 2.4667056999999204 + ] + } + }, + { + "body_bytes": 9769015, + "file": "global/hosted/ACTUAL-SIGMAS.json.gz", + "median_ratio": 1.622032323562568, + "median_seconds": { + "original": 0.9897019999999657, + "paired": 0.6101617000000488 + }, + "seconds": { + "original": [ + 0.9385374999999385, + 0.9897019999999657, + 0.9907008999999789 + ], + "paired": [ + 0.5790405000000192, + 0.6101617000000488, + 0.615403600000036 + ] + } + }, + { + "body_bytes": 5906328, + "file": "parent16/complex-global/base/split-centres/GLOBAL-TEMPLATE.json.gz", + "median_ratio": 2.3186512024457913, + "median_seconds": { + "original": 3.0083660000000236, + "paired": 1.2974638000000596 + }, + "seconds": { + "original": [ + 3.1456018000000086, + 3.0083660000000236, + 2.8887455000000273 + ], + "paired": [ + 1.2974638000000596, + 1.354051199999958, + 1.2128192999999783 + ] + } + }, + { + "body_bytes": 5906328, + "file": "lift/GLOBAL-TEMPLATE.json.gz", + "median_ratio": 2.4257843561088537, + "median_seconds": { + "original": 2.9161374999999907, + "paired": 1.20214210000006 + }, + "seconds": { + "original": [ + 2.95317579999994, + 2.9161374999999907, + 2.8281696999999895 + ], + "paired": [ + 1.2499482000000626, + 1.178186299999993, + 1.20214210000006 + ] + } + }, + { + "body_bytes": 5906328, + "file": "global/base/split-centres/GLOBAL-TEMPLATE.json.gz", + "median_ratio": 2.750362320201454, + "median_seconds": { + "original": 3.4415566999999783, + "paired": 1.2513103 + }, + "seconds": { + "original": [ + 2.724268299999949, + 3.4896039999999857, + 3.4415566999999783 + ], + "paired": [ + 1.1993016000000125, + 1.2513103, + 1.3865067000000408 + ] + } + } + ], + "limits": "Machine/load-dependent observation, no threshold gate. Mismatches are parsed again by the original fallback and may be slower. Equal-byte fast path unchanged.", + "platform": "Windows-11-10.0.26300-SP0", + "python": "3.12.14", + "scope": "five largest frozen compressed JSON files, whitespace-only reformat, complete classify including decompression and parsing; no setup or fixture-generation timing" +} diff --git a/research/strict-payload-paired-walk/OVERLAP.json b/research/strict-payload-paired-walk/OVERLAP.json new file mode 100644 index 0000000000..c30016b3e8 --- /dev/null +++ b/research/strict-payload-paired-walk/OVERLAP.json @@ -0,0 +1,88 @@ +{ + "coverage": { + "discussions": { + "complete_pagination": true, + "fetched_at": "2026-10-15T15:22:22.047084+00:00", + "records": 1239 + }, + "open_prs": { + "complete_pagination": true, + "fetched_at": "2026-10-15T17:34:02.879446+00:00", + "records": 786 + } + }, + "limits": "Remote PR scope is open PRs including drafts. Closed work is searched through local READMEs, TASK metadata and ledger only. No code diffs or arbitrary package files are searched. Recheck relevant heads before submission.", + "local_records": 1690, + "matches": [ + { + "excerpt": "## Reproduce\n\nPython 3.12 standard library, from the repository root:\n\n```sh\npython3 -I -B research/strict-replay-payload-comparison/verify.py\npython3 -I -O -B research/strict-replay-payload-comparison/test_compare.py\npython3 scripts/research_package.py --package research/strict-replay-payload-comparison --check-only\npython3 scripts/research_package.py --package research/strict-replay-payload-comparison\n```\n\nExpected audit marker:\n\n```text\nPASS_STRICT_REPLAY_PAYLOAD_COMPARISON files=105 false_eq", + "kind": "local-readme", + "matched_terms": [ + "strict-replay-payload-comparison" + ], + "path": "research/strict-replay-payload-comparison/README.md", + "score": 3, + "sha256": "65195fa3cf40e61a7287d4fb7c16151080d7ca5e5b99d2691acd080f3a11fbe3", + "title": "research/strict-replay-payload-comparison/README.md" + }, + { + "excerpt": "glas Colkitt; retained supplier lineage.\",\n \"artifact_and_reproduction\": \"python3 -I -B research/strict-replay-payload-comparison/verify.py\"\n },\n \"discussion_url\": \"https://github.com/CrocSwap/integer-mult-bounds/discussions/1472#discussioncomment-18930555\",\n \"overlap\": {\n \"mode\": \"offline shared snapshot; complete pagination, expected stale-cache warnings\",\n \"queries\": [\n \"--task portable-replay\",\n \"--path research/selected-final-stage-portability/compare_payloads.py\",\n ", + "kind": "local-task", + "matched_terms": [ + "strict-replay-payload-comparison" + ], + "path": "research/strict-replay-payload-comparison/TASK.json", + "score": 3, + "sha256": "33cfce0e80cda6db73511d1ada30715d92f7b37108419f0f783f78be62415e38", + "title": "research/strict-replay-payload-comparison/TASK.json" + }, + { + "excerpt": "# Paired traversal for strict replay payload comparison\n\nThis opt-in successor accelerates positive comparisons in\n[`strict-replay-payload-comparison`](../strict-replay-payload-comparison/README.md)\nwithout materializing two complete tagged JSON trees. Its parser, path rules,\ntiming validation, directory inventory, CLI and negative diagnostics come from\nthe SHA256-authenticated PR2040 comparator by **commdata2338**. The predecessor\nfiles and selected evidence remain unchanged.\n\n`RESULT.json` rec", + "kind": "local-readme", + "matched_terms": [ + "strict-replay-payload-comparison", + "paired traversal" + ], + "path": "research/strict-payload-paired-walk/README.md", + "score": 2, + "sha256": "e8682d7aa299e742211b680e50b2807132b06463240c315d746e811e5bcb0bf7", + "title": "research/strict-payload-paired-walk/README.md" + }, + { + "excerpt": "if it fits the budget. No cold supplier replay and no new mathematics.\nExpected artifact: `research/strict-replay-payload-comparison/` with a source-bound audit, a strict comparator, an exact receipt and positive and negative controls. Verifier tooling and a scoped audit finding only.\nClaim expires: 2026-10-14T19:36Z\n\nNearest overlap: PR #1824 supplies the cross-interpreter replay and comparator; this audits its untested equality and key-relocation boundaries. The `selected-generated-identity` a", + "kind": "discussion-comment", + "matched_terms": [ + "strict-replay-payload-comparison" + ], + "number": 1472, + "score": 1, + "title": "DONE: Linux/POSIX portability audit and descendant cleanup regression", + "updated_at": "2026-10-14T17:59:31Z", + "url": "https://github.com/CrocSwap/integer-mult-bounds/discussions/1472#discussioncomment-18930555" + }, + { + "excerpt": "declared time fields, and each individual deletion rejects.\n\n**Reproduce:** `python3 -I -B research/strict-replay-payload-comparison/verify.py`, expecting `PASS_STRICT_REPLAY_PAYLOAD_COMPARISON files=105 false_equivalences=39 type_cases=25 path_cases=12 timing_rejections=22 no_new_kappa`. The registered CPython 3.12.3 replay, nine semantic test groups, an optimized minimal-source export, real corrupted-receipt rejection and immutable archive-header rejection pass.\n\n**Also observed:** the unchang", + "kind": "discussion-reply", + "matched_terms": [ + "strict-replay-payload-comparison" + ], + "number": 1472, + "score": 1, + "title": "DONE: Linux/POSIX portability audit and descendant cleanup regression", + "updated_at": "2026-10-14T17:59:29Z", + "url": "https://github.com/CrocSwap/integer-mult-bounds/discussions/1472#discussioncomment-18930899" + } + ], + "matches_total": 5, + "searched_at": "2026-10-15T17:35:17.495407+00:00", + "status": "POSSIBLE_OVERLAP_NOT_A_NOVELTY_CERTIFICATE", + "terms": [ + "strict-replay-payload-comparison", + "paired traversal", + "paired walk" + ], + "warnings": [ + "open_prs: offline; cached data may miss current changes", + "discussions: offline; cached data may miss current changes" + ] +} diff --git a/research/strict-payload-paired-walk/README.md b/research/strict-payload-paired-walk/README.md new file mode 100644 index 0000000000..584596ab9e --- /dev/null +++ b/research/strict-payload-paired-walk/README.md @@ -0,0 +1,128 @@ +# Paired traversal for strict replay payload comparison + +This opt-in successor accelerates positive comparisons in +[`strict-replay-payload-comparison`](../strict-replay-payload-comparison/README.md) +without materializing two complete tagged JSON trees. Its parser, path rules, +timing validation, directory inventory, CLI and negative diagnostics come from +the SHA256-authenticated PR2040 comparator by **commdata2338**. The predecessor +files and selected evidence remain unchanged. + +`RESULT.json` records complete-result differential agreement on **1,012 calls**: +365 calls from the unchanged predecessor audit (105-file corpus, 39 adverse +witnesses and its other controls), 625 additional semantic cases, and 22 +compressed JSON bodies reformatted to exercise the new traversal. The original +complete audit receipt also agrees. This is comparison evidence, not a fresh +execution of the mathematical supplier. + +## What is preserved + +Both inputs are completely decompressed and parsed. Duplicate object keys and +nonfinite constants are rejected; Decimal values remain exact. Integers, +Decimals and Booleans retain different tags. Every declared timing path is +validated on both inputs, including byte-identical inputs. Root tokens and +canonical POSIX prefixes retain the original injective path tagging, longest +prefix rule and literal-string distinction. Unknown fields and array order +remain significant. No digest or previously cached equality replaces reading +the actual payloads. + +`paired` compares matching containers recursively. For objects with root maps, +it makes only a per-object map from normalized key to original key/value; with +empty root maps it compares the original key sets. Arrays compare their lengths +and all corresponding entries. Scalar comparison first checks the exact Python +type produced by the retained parser. Object-key order is irrelevant, as it is +in the original sorted tagged representation. Original keys are retained for +the two timing-path traversals: a normalized key is never mistaken for a path +component. + +An induction on these cases shows that a successful traversal gives exactly +the same tagged-tree equality as PR2040. For the timing quotient, the two nodes +are equal as timing tags only when **both** original paths are masked; otherwise +the usual recursion applies. All masks have already passed the original shape, +type, finiteness and nonnegativity checks. Equal payload bytes under equal root +interpretations retain the predecessor's existing shortcut. + +If a comparison fails, or the speculative traversal encounters an error, the +adapter invokes the original comparator on the original bytes and policies. +This preserves its entire result, including invalid-input precedence and the +first-difference diagnostic. A new traversal cannot accidentally replace an +invalid sibling by an early mismatch. Binary files always take this original +path. The adapter changes only a private, authenticated module instance; it +does not patch another importer or rewrite a frozen file. + +## Measurements and limits + +`BENCHMARK.json` contains three alternating-order trials on the five largest +compressed JSON bodies in the pinned corpus. The run changes only leading and +trailing JSON whitespace and measures complete `classify` calls, including +decompression and parsing. Both methods must return the full same result. +Fixture creation, source authentication and corpus extraction are outside the +timed interval. Reproduce the observation on the intended machine; the timing +is not an acceptance threshold and concurrent load can change it. + +On CPython 3.12.14 / Windows 11, the sum of the five per-file median times fell +from 16.111 seconds to 6.584 seconds (**2.447x**). Individual ratios were +1.622x–2.750x. These timings include the same full-input checks and do not use a +warm result cache. The separately recorded tree-only profiling was used to +choose the optimization, not as the end-to-end speedup claim. + +The saving comes from avoiding complete tagged-tree allocations on positive +cases. Parsing still constructs both JSON values, and wide objects still need +per-object key maps when relocation is enabled. Peak memory was not measured. +Different or invalid payloads can be slower because the original fallback +parses them again. Equal-byte and ordinary gzip-container cases already have a +shortcut in the predecessor. There is no claimed speedup for those cases. + +The unchanged contract is JSON plus canonical POSIX root maps. PR2344's Windows +drive-root adaptation is a separate caller and is not replaced here. This does +not add UNC handling, raw digest rebinding, a supplier admission, a new circuit +cost, or a new kappa. Inputs remain trusted local files subject to the existing +parser's recursion and resource limits; arbitrary attacker-sized JSON is not a +new supported service interface. + +## Reproduce + +Python 3.12 or later, standard library only: + +```sh +python3 -I -B research/strict-payload-paired-walk/verify.py +python3 -I -O -B research/strict-payload-paired-walk/test_compare.py +python3 scripts/research_package.py --package research/strict-payload-paired-walk +python3 -I -B research/strict-payload-paired-walk/benchmark.py --rounds 3 --out /tmp/paired-benchmark.json +``` + +The test file runs all nine retained predecessor test groups against the new +adapter, including its CLI, plus six adapter controls. These check source-change +invalidation before execution, original diagnostic equality, original-key +masking, rejection of invalid identical timing data, detection of a Python +equality mutant, and that positive traversals do not build tagged trees. +`SOURCES.json` authenticates all 12 inherited inputs by SHA256 and Git blob ID; +the replay works without a Git checkout or network. `RESULT.json` is compared +as canonical JSON bytes, so Boolean/integer substitutions cannot satisfy it. + +The CLI is the same as the predecessor, with this script path: + +```sh +python3 research/strict-payload-paired-walk/compare.py REF_DIR RUN_DIR \ + --ref-root W=/old/root --run-root W=/new/root --out comparison.json +``` + +Use an explicit timing policy only when that caller authorizes those exact +typed paths. This package introduces no default ignored fields. + +## Open next questions + +Can an actual replay wrapper obtain a useful end-to-end saving after its own +source authentication and unchanged-output shortcuts? First run its complete +output comparison through both implementations with identical policy and +retained negative fixtures; adoption is blocked on caller-specific review. + +Can the negative path reuse already parsed values while preserving the +predecessor's exact error ordering? First profile a representative changed +large payload. This is left open because positive-path allocation is the +measured bottleneck addressed here, and moving diagnostic logic would enlarge +the verification boundary. + +Prepared by **ywz65**, with substantial OpenAI Codex assistance in implementation, +proof review, testing and writing. Apache-2.0. Credit to commdata2338 for the +strict comparator and controls, Josie Elliston for the historical portability +comparator, Rohan Arun and the retained supplier authors for the frozen corpus. diff --git a/research/strict-payload-paired-walk/RESULT.json b/research/strict-payload-paired-walk/RESULT.json new file mode 100644 index 0000000000..aa31a3cbfe --- /dev/null +++ b/research/strict-payload-paired-walk/RESULT.json @@ -0,0 +1,19 @@ +{ + "classifications": { + "binary-diff": 1, + "bytes": 252, + "gzip-container": 23, + "invalid": 40, + "json-diff:declared-timing": 6, + "json-diff:proof-relevant-candidate": 582, + "json-format": 106, + "json-relocated": 2 + }, + "compressed_json_reformats": 22, + "corpus_files": 105, + "extra_differential_cases": 625, + "retained_adverse_witnesses": 39, + "retained_classify_calls": 365, + "scope": "exact comparison equivalence on stated corpus/controls; no supplier replay or new kappa", + "status": "PASS_STRICT_PAYLOAD_PAIRED_WALK" +} diff --git a/research/strict-payload-paired-walk/SELECTION.json b/research/strict-payload-paired-walk/SELECTION.json new file mode 100644 index 0000000000..dd65300d80 --- /dev/null +++ b/research/strict-payload-paired-walk/SELECTION.json @@ -0,0 +1,91 @@ +{ + "base_commit": "1884c509efc004524786e9b7cfcc4aca572316d5", + "catalog_assessed_on": "2026-10-15", + "catalog_sha256": "7d185cd8c2af35988d638d969748ad7b670f902606444dbfc748e4402c340df6", + "next_step": "Check live overlap, refine one question's object and domain, and record a bounded task card. A different seed or scope key is not evidence of novelty.", + "priority_log": "docs/research/research-priority-log.md", + "priority_revision": 5, + "seed": "7b211647cc73d979992dbe2661a5d40f", + "selected": { + "kappa": "836330098538459/500000000000000000", + "reproduce": "make frontier1094-verify", + "review": "docs/research/community-batch1099-review.md", + "source_manifest": "research/community-frontier1094-audit/SELECTED-SOURCE.json" + }, + "selected_record_sha256": "10b9e340fd8e354a37a0c4813c90e5de1dd42044b5f6aca4a3fc5a42b685fa32", + "status": "SUGGESTIONS_ONLY_NOT_RESERVED", + "suggestions": [ + { + "acceptance_gate": "Report before/after wall time on the same fixture, retained checks and invalidation behavior.", + "allowed_variations": [ + "Profile one stage or design one source-bound cache boundary." + ], + "bottleneck_link": "Faster trustworthy replays increase review throughput and let mechanism candidates be checked sooner.", + "first_experiment": "Measure one unchanged fixture, preserve check coverage, and test one optimization with invalidation controls.", + "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." + }, + "method": "Design source-bound reuse with explicit dependency invalidation and negative controls.", + "overlap_terms": [ + "replay runtime", + "cache invalidation", + "isolated tests" + ], + "question": "Can one measured replay bottleneck be sped up without dropping coverage?", + "scope_change_triggers": [ + "Skipping coverage or comparing different fixtures to claim speedup." + ], + "scope_key": "a76657a85478d269d19f", + "scope_rule": "If you change the card's premise, record scope_status=changed and explain why. A package metadata check cannot establish mathematical relevance.", + "starting_points": [ + "scripts/run_isolated_tests.py", + "scripts/verify_replay_coverage.py", + "certificates/selected-result.json" + ], + "task_id": "replay-runtime" + }, + { + "acceptance_gate": "Preserve immutable source hashes and proof-relevant content; a different compressed byte stream alone is not a mathematical mismatch.", + "allowed_variations": [ + "One interpreter/version mismatch or one payload field comparison." + ], + "bottleneck_link": "Portable exact checks prevent environment failures from blocking valid contributions.", + "first_experiment": "Reproduce one specific mismatch or audit one canonical comparison for omitted proof-relevant fields.", + "first_step": { + "command": [ + "python3", + "-B", + "scripts/research_baseline.py" + ], + "expected": "PASS_RESEARCH_BASELINE_BINDINGS_ONLY", + "inspect": "Read the gzip-container reproducibility examples and distinguish frozen source bytes from regenerated payloads.", + "scope": "Positive control / source-bound orientation only; this is not a new construction or full cold replay." + }, + "method": "Reproduce one portability failure and add a minimal cross-environment fix.", + "overlap_terms": [ + "gzip container", + "reproducibility", + "canonical payload" + ], + "question": "Can one reproducible environment or artifact-comparison failure be repaired?", + "scope_change_triggers": [ + "Removing immutable-source pins because generated compressed bytes differ." + ], + "scope_key": "831cc1a3c8f9ff01b197", + "scope_rule": "If you change the card's premise, record scope_status=changed and explain why. A package metadata check cannot establish mathematical relevance.", + "starting_points": [ + "research/gzip-container-reproducibility/README.md", + "docs/ci-verification.md" + ], + "task_id": "portable-replay" + } + ], + "track": "verifier-engineering" +} diff --git a/research/strict-payload-paired-walk/SOURCES.json b/research/strict-payload-paired-walk/SOURCES.json new file mode 100644 index 0000000000..3dfa3bbaa0 --- /dev/null +++ b/research/strict-payload-paired-walk/SOURCES.json @@ -0,0 +1,85 @@ +{ + "base_commit": "8513ab11936831dc45305170357ce6d33098e4e5", + "files": [ + { + "git_blob": "127f143bb8e46ca9be26210bcdd2d15c12a79798", + "path": "research/strict-replay-payload-comparison/compare.py", + "sha256": "7592c2475a851ac68a6db1a82af4ae9db466690c7e2c1daced654c5641b66492", + "usage": "input" + }, + { + "git_blob": "8e9f9d768249424ae29ef99bc9d494fc19b40d90", + "path": "research/strict-replay-payload-comparison/verify.py", + "sha256": "07e571472224c937f1c0655e251f88c7d6e381b893788dce12707fcc3a3494c4", + "usage": "input" + }, + { + "git_blob": "9c199b1b5c913c38fb9384d69655ca1746269fa0", + "path": "research/strict-replay-payload-comparison/RESULT.json", + "sha256": "f23fff4ff3f079675db860718ef12525c2412b790c455afbc763cce3f99b2cc2", + "usage": "input" + }, + { + "git_blob": "0c1e7c75b3758542f27006a6a62691fd191d0c66", + "path": "research/strict-replay-payload-comparison/SOURCES.json", + "sha256": "eb100e16f5577496dc1180c30d16e40b0d5d4aad4b0c173fca36d6085f78a255", + "usage": "input" + }, + { + "git_blob": "648ef4605e098d2be03838793bcf0908c2485566", + "path": "research/strict-replay-payload-comparison/TIMINGS.json", + "sha256": "401c8faa82f6ed370b7d39bbe099fa5a444dccdbd014b35f9363d3d7549e2be4", + "usage": "input" + }, + { + "git_blob": "16c1e943453029eace96b96325d6de870711b90c", + "path": "research/strict-replay-payload-comparison/test_compare.py", + "sha256": "f91ef0173461c3ff2402cb5ede957cd2011db75328205f5b8c03b20dad8e769a", + "usage": "input" + }, + { + "git_blob": "c24daf067f9c543421d89ca2eeaa4eb78a57fb6f", + "path": "research/community-frontier1094-audit/selected-replay.tar.gz", + "sha256": "f1da80610bf33c58527f18ad63b4350d0b864e1d4486141ee17ac9bed4d529d6", + "usage": "input" + }, + { + "git_blob": "131d9c96a54632ae385ced4138fd7f30ad448a3e", + "path": "research/community-frontier1094-audit/RESULT.json", + "sha256": "1e3e47e9ec24bcb6fb5f703b7fce0aab658d84ff72bfae5da3ae429d17b6e752", + "usage": "input" + }, + { + "git_blob": "2cfb7fffa7cd78f418be16c13224c3206b6d0183", + "path": "research/community-frontier1094-audit/REPLAY.json", + "sha256": "ce0678fa7abaab221de74baeace0c6696d5ea23a36719a58cff230215a06aae7", + "usage": "input" + }, + { + "git_blob": "5fd676df060f3b450782fdf5ff5f6beb63a5eeb0", + "path": "research/community-frontier1094-audit/ASSEMBLY.json", + "sha256": "1122cb3a575f8c788345fc1bf4c108ac7c3250fb81a5988671f5eb04b3ab3045", + "usage": "input" + }, + { + "git_blob": "a2a2aea73bda06c2358065388a30fd4cbc7d423f", + "path": "research/selected-final-stage-portability/compare_payloads.py", + "sha256": "3aa3459404265188e51a4a74a57f6c01d9ea7cad205edb962e5d51c5a45a50cb", + "usage": "input" + }, + { + "git_blob": "f14313df138b0a6d022e73f5395addd195067306", + "path": "research/selected-final-stage-portability/README.md", + "sha256": "13b6ada37c593b172fb73fac58fb615993d8f5c10c7508f9e895c6bb9006e127", + "usage": "input" + }, + { + "git_blob": "889b95d936746df124872133ae1e7cc339adcb92", + "path": "docs/research/agent-task-catalog.json", + "sha256": "7d185cd8c2af35988d638d969748ad7b670f902606444dbfc748e4402c340df6", + "usage": "provenance" + } + ], + "predecessor": "PR2040 by commdata2338; comparison semantics preserved", + "schema_version": 1 +} diff --git a/research/strict-payload-paired-walk/TASK.json b/research/strict-payload-paired-walk/TASK.json new file mode 100644 index 0000000000..9c6e604d51 --- /dev/null +++ b/research/strict-payload-paired-walk/TASK.json @@ -0,0 +1,183 @@ +{ + "actual_scope": "Opt-in source-authenticated PR2040 positive-path paired JSON traversal; preserve exact comparison classifications and full negative diagnostics.", + "ai_assistance": "Substantial OpenAI Codex assistance; separate agent review, no independent human review claimed.", + "author": "ywz65", + "base_commit": "8513ab11936831dc45305170357ce6d33098e4e5", + "bottleneck_link": "Preserve trustworthy full replay comparison while reducing repeated review cost.", + "chooser": { + "base_commit": "1884c509efc004524786e9b7cfcc4aca572316d5", + "catalog_assessed_on": "2026-10-15", + "catalog_sha256": "7d185cd8c2af35988d638d969748ad7b670f902606444dbfc748e4402c340df6", + "next_step": "Check live overlap, refine one question's object and domain, and record a bounded task card. A different seed or scope key is not evidence of novelty.", + "priority_log": "docs/research/research-priority-log.md", + "priority_revision": 5, + "seed": "7b211647cc73d979992dbe2661a5d40f", + "selected": { + "kappa": "836330098538459/500000000000000000", + "reproduce": "make frontier1094-verify", + "review": "docs/research/community-batch1099-review.md", + "source_manifest": "research/community-frontier1094-audit/SELECTED-SOURCE.json" + }, + "selected_record_sha256": "10b9e340fd8e354a37a0c4813c90e5de1dd42044b5f6aca4a3fc5a42b685fa32", + "status": "SUGGESTIONS_ONLY_NOT_RESERVED", + "suggestions": [ + { + "acceptance_gate": "Report before/after wall time on the same fixture, retained checks and invalidation behavior.", + "allowed_variations": [ + "Profile one stage or design one source-bound cache boundary." + ], + "bottleneck_link": "Faster trustworthy replays increase review throughput and let mechanism candidates be checked sooner.", + "first_experiment": "Measure one unchanged fixture, preserve check coverage, and test one optimization with invalidation controls.", + "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." + }, + "method": "Design source-bound reuse with explicit dependency invalidation and negative controls.", + "overlap_terms": [ + "replay runtime", + "cache invalidation", + "isolated tests" + ], + "question": "Can one measured replay bottleneck be sped up without dropping coverage?", + "scope_change_triggers": [ + "Skipping coverage or comparing different fixtures to claim speedup." + ], + "scope_key": "a76657a85478d269d19f", + "scope_rule": "If you change the card's premise, record scope_status=changed and explain why. A package metadata check cannot establish mathematical relevance.", + "starting_points": [ + "scripts/run_isolated_tests.py", + "scripts/verify_replay_coverage.py", + "certificates/selected-result.json" + ], + "task_id": "replay-runtime" + }, + { + "acceptance_gate": "Preserve immutable source hashes and proof-relevant content; a different compressed byte stream alone is not a mathematical mismatch.", + "allowed_variations": [ + "One interpreter/version mismatch or one payload field comparison." + ], + "bottleneck_link": "Portable exact checks prevent environment failures from blocking valid contributions.", + "first_experiment": "Reproduce one specific mismatch or audit one canonical comparison for omitted proof-relevant fields.", + "first_step": { + "command": [ + "python3", + "-B", + "scripts/research_baseline.py" + ], + "expected": "PASS_RESEARCH_BASELINE_BINDINGS_ONLY", + "inspect": "Read the gzip-container reproducibility examples and distinguish frozen source bytes from regenerated payloads.", + "scope": "Positive control / source-bound orientation only; this is not a new construction or full cold replay." + }, + "method": "Reproduce one portability failure and add a minimal cross-environment fix.", + "overlap_terms": [ + "gzip container", + "reproducibility", + "canonical payload" + ], + "question": "Can one reproducible environment or artifact-comparison failure be repaired?", + "scope_change_triggers": [ + "Removing immutable-source pins because generated compressed bytes differ." + ], + "scope_key": "831cc1a3c8f9ff01b197", + "scope_rule": "If you change the card's premise, record scope_status=changed and explain why. A package metadata check cannot establish mathematical relevance.", + "starting_points": [ + "research/gzip-container-reproducibility/README.md", + "docs/ci-verification.md" + ], + "task_id": "portable-replay" + } + ], + "track": "verifier-engineering" + }, + "claim_url": "https://github.com/CrocSwap/integer-mult-bounds/pull/2040#issuecomment-6198042519", + "evidence": "RESULT.json:1012 complete differential results, original105-file39adverse audit,625 additional cases,22 large reformats;15 test groups; BENCHMARK.json.", + "family_gate": { + "costs": "Measured runtime; no mathematical tariff change", + "decision": "narrow", + "frames_ownership_restoration": "not a mathematical operator; no change", + "inputs": "12 exact inherited files", + "next_consumer": "opt-in artifact comparison; caller adoption separately reviewed", + "outputs": "same comparator results", + "stop_reopen": "stop if equivalence fails; revisit negatives only with measured caller need" + }, + "open_questions": [ + { + "blocked_by": "Caller-specific compatibility review.", + "first_step": "Compare complete intended output with same policies.", + "question": "Does a caller gain end-to-end runtime?", + "why_it_matters": "Parsing and equal-byte shortcuts may dominate." + } + ], + "original_card": { + "acceptance_gate": "Report before/after wall time on the same fixture, retained checks and invalidation behavior.", + "allowed_variations": [ + "Profile one stage or design one source-bound cache boundary." + ], + "bottleneck_link": "Faster trustworthy replays increase review throughput and let mechanism candidates be checked sooner.", + "first_experiment": "Measure one unchanged fixture, preserve check coverage, and test one optimization with invalidation controls.", + "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." + }, + "id": "replay-runtime", + "methods": [ + "Profile one isolated replay and optimize the measured bottleneck.", + "Design source-bound reuse with explicit dependency invalidation and negative controls." + ], + "overlap_terms": [ + "replay runtime", + "cache invalidation", + "isolated tests" + ], + "question": "Can one measured replay bottleneck be sped up without dropping coverage?", + "scope_change_triggers": [ + "Skipping coverage or comparing different fixtures to claim speedup." + ], + "starting_points": [ + "scripts/run_isolated_tests.py", + "scripts/verify_replay_coverage.py", + "certificates/selected-result.json" + ] + }, + "outcome": "completed", + "overlap": { + "coverage": { + "discussions": { + "complete_pagination": true, + "fetched_at": "2026-10-15T15:22:22.047084+00:00", + "records": 1239 + }, + "open_prs": { + "complete_pagination": true, + "fetched_at": "2026-10-15T17:34:02.879446+00:00", + "records": 786 + } + }, + "finding": "Existing strict comparator and own package/claim; no matching optimization found. Discussion snapshot stale after GraphQL quota exhaustion; not a novelty certificate.", + "limits": "Remote PR scope is open PRs including drafts. Closed work is searched through local READMEs, TASK metadata and ledger only. No code diffs or arbitrary package files are searched. Recheck relevant heads before submission." + }, + "priority_revision": 5, + "schema_version": 1, + "scope_change_reason": "The runtime card permits one measured replay bottleneck. Initial tagged-tree profiling identified allocation on large reformat comparisons; this changes representation only.", + "scope_status": "refined", + "source_status": "PR2040 incorporated on main; retained exact bytes. PR2344 Windows adaptation is separate.", + "stop_rule": "Stop on semantic divergence or no useful same-fixture full-call saving; no new comparison quotient or supplier change.", + "task_id": "replay-runtime", + "upstream_checkpoint": { + "checked_utc": "2026-10-15T17:36:39.346582+00:00", + "commit": "b5ea56e0a5ac4552166253b1fa4be0753bb38c30", + "guidance": "Priority5,selectedrecord,guidanceand12liveinputsunchanged from originating8513 snapshot; reviewbatch1100now79merged." + } +} diff --git a/research/strict-payload-paired-walk/VALIDATION.json b/research/strict-payload-paired-walk/VALIDATION.json new file mode 100644 index 0000000000..4c5f095e27 --- /dev/null +++ b/research/strict-payload-paired-walk/VALIDATION.json @@ -0,0 +1,28 @@ +{ + "files": 23, + "git_free": true, + "limits": [ + "No hosted CI or mathematical supplier replay", + "Benchmarkmachine/loaddependent", + "Negative comparisons may be slower; peak memory not measured" + ], + "python": "3.14.5", + "read_only": true, + "registered": "PASS1012differentialcallsand15testgroups", + "registered_python": "3.12.14", + "results": [ + { + "returncode": 0, + "script": "verify.py" + }, + { + "returncode": 0, + "script": "test_compare.py" + }, + { + "control": "Boolean corpus_files receipt", + "returncode": 1 + } + ], + "separate_review": "AgentA read exact source and new traversal; no actionable finding. No independent test rerun claimed." +} diff --git a/research/strict-payload-paired-walk/VERIFY.json b/research/strict-payload-paired-walk/VERIFY.json new file mode 100644 index 0000000000..2bd37d4e14 --- /dev/null +++ b/research/strict-payload-paired-walk/VERIFY.json @@ -0,0 +1,43 @@ +{ + "commands": [ + { + "argv": [ + "{python}", + "-I", + "-B", + "{package}/verify.py" + ], + "checks": "Authenticate12inputs; full1012-call differential; retained complete original receipt and typed new receipt.", + "timeout_seconds": 600 + }, + { + "argv": [ + "{python}", + "-I", + "-O", + "-B", + "{package}/test_compare.py" + ], + "checks": "15testgroups:9retained semantic/CLI/source tests plus6adapter controls.", + "timeout_seconds": 120 + } + ], + "inputs": [ + "research/strict-replay-payload-comparison/compare.py", + "research/strict-replay-payload-comparison/verify.py", + "research/strict-replay-payload-comparison/RESULT.json", + "research/strict-replay-payload-comparison/SOURCES.json", + "research/strict-replay-payload-comparison/TIMINGS.json", + "research/strict-replay-payload-comparison/test_compare.py", + "research/community-frontier1094-audit/selected-replay.tar.gz", + "research/community-frontier1094-audit/RESULT.json", + "research/community-frontier1094-audit/REPLAY.json", + "research/community-frontier1094-audit/ASSEMBLY.json", + "research/selected-final-stage-portability/compare_payloads.py", + "research/selected-final-stage-portability/README.md" + ], + "python": "3.12", + "requirements": [], + "schema_version": 1, + "status": "ready" +} diff --git a/research/strict-payload-paired-walk/benchmark.py b/research/strict-payload-paired-walk/benchmark.py new file mode 100644 index 0000000000..3e0c1f1d91 --- /dev/null +++ b/research/strict-payload-paired-walk/benchmark.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python3 +"""Measured full classify calls on five large immutable payloads; not a gate. + +ywz65, with substantial OpenAI Codex assistance. Apache-2.0. +""" +import argparse +import gzip +import importlib.util +import json +from pathlib import Path +import platform +import statistics +import time + +HERE=Path(__file__).resolve().parent +spec=importlib.util.spec_from_file_location('paired_verifier',HERE/'verify.py') +v=importlib.util.module_from_spec(spec);spec.loader.exec_module(v) + + +def run(rounds): + fast,old=v.setup();data=old.corpus(old.bound_inputs()) + largest=sorted([(len(gzip.decompress(raw)),name,raw) for name,raw in data.items() + if name.endswith('.json.gz')],reverse=True)[:5] + rows=[] + for size,name,raw in largest: + changed=gzip.compress(b'\n'+gzip.decompress(raw)+b'\n',mtime=123) + times={'original':[],'paired':[]} + functions={'original':fast.original_classify,'paired':fast.classify} + for trial in range(rounds): + for key in (('original','paired') if trial%2==0 else ('paired','original')): + start=time.perf_counter();result=functions[key](name,raw,changed) + elapsed=time.perf_counter()-start + v.require(result=={'cls':'json-format'},'benchmark result differs') + times[key].append(elapsed) + medians={k:statistics.median(x) for k,x in times.items()} + row={'file':name,'body_bytes':size,'seconds':times,'median_seconds':medians, + 'median_ratio':medians['original']/medians['paired']} + rows.append(row);print(name,round(row['median_ratio'],3),flush=True) + return {'scope':'five largest frozen compressed JSON files, whitespace-only reformat, complete classify including decompression and parsing; no setup or fixture-generation timing', + 'python':platform.python_version(),'platform':platform.platform(), + 'alternating_order_trials':rounds,'files':rows, + 'aggregate_median_ratio':sum(x['median_seconds']['original'] for x in rows)/sum(x['median_seconds']['paired'] for x in rows), + 'limits':'Machine/load-dependent observation, no threshold gate. Mismatches are parsed again by the original fallback and may be slower. Equal-byte fast path unchanged.'} + + +if __name__=='__main__': + parser=argparse.ArgumentParser(description=__doc__);parser.add_argument('--rounds',type=int,default=3);parser.add_argument('--out',type=Path,required=True) + args=parser.parse_args();v.require(args.rounds>=1,'positive trial count required');result=run(args.rounds) + with args.out.open('x',encoding='utf-8',newline='\n') as out: + json.dump(result,out,indent=2,sort_keys=True);out.write('\n') diff --git a/research/strict-payload-paired-walk/compare.py b/research/strict-payload-paired-walk/compare.py new file mode 100644 index 0000000000..f18e6a6180 --- /dev/null +++ b/research/strict-payload-paired-walk/compare.py @@ -0,0 +1,120 @@ +#!/usr/bin/env python3 +"""Opt-in paired traversal preserving PR2040 strict comparison semantics. + +ywz65, with substantial OpenAI Codex assistance. Apache-2.0. +The source comparator by commdata2338 supplies all parsing, policies, inventory, +CLI and negative diagnostics. This private adapter never changes its source. +""" +import hashlib +import json +from pathlib import Path +import sys +import types + +HERE = Path(__file__).resolve().parent +ROOT = HERE.parents[1] +SOURCE = 'research/strict-replay-payload-comparison/compare.py' + + +def load_source(root=ROOT): + manifest = json.loads((HERE / 'SOURCES.json').read_text(encoding='utf-8')) + rows = [r for r in manifest['files'] if r['path'] == SOURCE and r['usage'] == 'input'] + if len(rows) != 1: + raise ValueError('source comparator inventory differs') + raw = (root / SOURCE).read_bytes() + if hashlib.sha256(raw).hexdigest() != rows[0]['sha256']: + raise ValueError('source comparator SHA256 differs') + module = types.ModuleType('source_strict_payload') + module.__file__ = str(root / SOURCE) + exec(compile(raw, module.__file__, 'exec'), module.__dict__) + return module + + +source = load_source() +original_classify = source.classify +EMPTY = source.EMPTY_ROOTS + + +def paired(a, b, ra=EMPTY, rb=EMPTY, ta=frozenset(), tb=frozenset(), pa=(), pb=()): + """True only for equal complete tagged trees; allocate no complete tree. + + Timing paths on the two sides retain their original object keys. A mismatch + need not search the remaining branches: classify delegates that case to the + original full-tree routine, including its error precedence and diagnostics. + """ + if pa in ta or pb in tb: + return pa in ta and pb in tb + if type(a) is not type(b): + return False + if type(a) is dict: + if not ra.pairs and not rb.pairs: + if a.keys() != b.keys(): + return False + return all(paired(v, b[k], ra, rb, ta, tb, + pa + (k,) if ta else (), pb + (k,) if tb else ()) + for k, v in a.items()) + left = {ra.string(k): (k, v) for k, v in a.items()} + right = {rb.string(k): (k, v) for k, v in b.items()} + source.require(len(left) == len(a) and len(right) == len(b), + 'relocation key collision') + if left.keys() != right.keys(): + return False + return all(paired(v, right[k][1], ra, rb, ta, tb, + pa + (original,) if ta else (), + pb + (right[k][0],) if tb else ()) + for k, (original, v) in left.items()) + if type(a) is list: + return len(a) == len(b) and all( + paired(x, y, ra, rb, ta, tb, + pa + (i,) if ta else (), pb + (i,) if tb else ()) + for i, (x, y) in enumerate(zip(a, b))) + if type(a) is str: + return ra.string(a) == rb.string(b) + if type(a) is source.Decimal: + source.require(a.is_finite() and b.is_finite(), 'nonfinite decimal') + elif type(a) not in (bool, int, type(None)): + raise source.InvalidPayload('unsupported JSON type: ' + type(a).__name__) + return a == b + + +def classify(name, reference, run, ref_roots=EMPTY, run_roots=EMPTY, timing_paths=()): + source.require(ref_roots.tokens == run_roots.tokens, 'root-token sets must agree') + compressed = name.endswith('.gz') + json_name = name[:-3] if compressed else name + if json_name.endswith('.json'): + try: + a = source.gzip.decompress(reference) if compressed else reference + b = source.gzip.decompress(run) if compressed else run + ja, jb = source.read_json(a), source.read_json(b) + ta = source.validate_timings(ja, timing_paths) + tb = source.validate_timings(jb, timing_paths) + if a == b and ref_roots.pairs == run_roots.pairs: + return {'cls': 'bytes' if reference == run else 'gzip-container'} + if paired(ja, jb, ref_roots, run_roots): + if reference == run: + return {'cls': 'bytes'} + if a == b: + return {'cls': 'gzip-container'} + if (not ref_roots.pairs and not run_roots.pairs) or paired(ja, jb): + return {'cls': 'json-format'} + return {'cls': 'json-relocated'} + if (ta or tb) and paired(ja, jb, ref_roots, run_roots, ta, tb): + return {'cls': 'json-diff', 'verdict': 'declared-timing'} + except (ValueError, UnicodeError, OSError, EOFError, + source.zlib.error, source.InvalidOperation): + # Preserve the original diagnostic and which invalid branch wins. + pass + return original_classify(name, reference, run, ref_roots, run_roots, timing_paths) + + +# Only this authenticated private module is adapted. Its API and CLI are reused. +source.classify = classify +Roots = source.Roots +read_json = source.read_json +accepted = source.accepted +compare = source.compare +InvalidPayload = source.InvalidPayload + + +if __name__ == '__main__': + sys.exit(source.main()) diff --git a/research/strict-payload-paired-walk/test_compare.py b/research/strict-payload-paired-walk/test_compare.py new file mode 100644 index 0000000000..8ac3aa4a2b --- /dev/null +++ b/research/strict-payload-paired-walk/test_compare.py @@ -0,0 +1,77 @@ +#!/usr/bin/env python3 +"""Retain predecessor controls and test the adapter boundary. Apache-2.0. + +ywz65, with substantial OpenAI Codex assistance. +""" +import importlib.util +from pathlib import Path +import shutil +import sys +import tempfile +import unittest + +HERE=Path(__file__).resolve().parent +spec=importlib.util.spec_from_file_location('paired_verifier',HERE/'verify.py') +verify=importlib.util.module_from_spec(spec);spec.loader.exec_module(verify) +fast,retained=verify.setup() +oldtests=verify.module(verify.ROOT/verify.OLD/'test_compare.py',{'compare':fast,'verify':retained}) +# Their CLI fixture now exercises this adapter, while source checks retain their +# original bound-input function and root. No predecessor source is rewritten. +oldtests.HERE=HERE +ComparisonControls=oldtests.ComparisonControls + + +class AdapterControls(unittest.TestCase): + def test_source_change_invalidates_before_execution(self): + with tempfile.TemporaryDirectory() as name: + root=Path(name);path=root/fast.SOURCE;path.parent.mkdir(parents=True) + shutil.copyfile(verify.ROOT/fast.SOURCE,path) + fast.load_source(root) + path.write_bytes(path.read_bytes()+b'\nraise RuntimeError("must not execute")\n') + with self.assertRaisesRegex(ValueError,'SHA256 differs'): + fast.load_source(root) + + def test_success_does_not_build_tagged_trees(self): + oldtree=fast.source.tree + def forbidden(*args,**kwargs): + raise AssertionError('positive traversal allocated tagged tree') + fast.source.tree=forbidden + try: + self.assertEqual(fast.classify('a.json',b'{"v":[1,true,1.00]}',b' {"v":[1,true,1e0]}'),{'cls':'json-format'}) + ra,rb=fast.Roots([('W','/a')]),fast.Roots([('W','/b')]) + self.assertEqual(fast.classify('a.json',b'{"/a/f":1}',b'{"/b/f":1}',ra,rb),{'cls':'json-relocated'}) + self.assertEqual(fast.classify('a.json',b'{"t":1}',b'{"t":2.0}',timing_paths=[('t',)]),{'cls':'json-diff','verdict':'declared-timing'}) + finally: + fast.source.tree=oldtree + + def test_negative_result_uses_original_diagnostics(self): + args=('a.json',b'{"unknown":{"values":[0,1]}}',b'{"unknown":{"values":[0,true]}}') + self.assertEqual(fast.classify(*args),fast.original_classify(*args)) + self.assertEqual(fast.classify(*args)['first_difference']['path'],[['string','unknown'],['string','values'],1]) + + def test_masks_use_both_original_key_paths(self): + ra,rb=fast.Roots([('W','/a')]),fast.Roots([('W','/b')]) + a=fast.read_json(b'{"/a":1,"/b":2}') + b=fast.read_json(b'{"/b":3,"/a":2}') + # The '/a' mask exists on both inputs but denotes different normalized + # keys. It cannot erase the different path-tagged value on only one side. + self.assertFalse(fast.paired(a,b,ra,rb,frozenset({('/a',)}),frozenset({('/a',)}))) + self.assertFalse(fast.accepted(fast.classify('a.json',b'{"/a":1,"/b":2}',b'{"/b":3,"/a":2}',ra,rb,[('/a',)]))) + + def test_full_result_differential_detects_python_equality_mutant(self): + previous=fast.paired + fast.paired=lambda a,b,*args: a==b + try: + args=('a.json',b'{"x":true}',b'{"x":1}') + self.assertNotEqual(fast.classify(*args),fast.original_classify(*args)) + finally: + fast.paired=previous + + def test_timing_validation_still_rejects_identical_invalid_data(self): + for value in (b'true',b'-1',b'"1"',b'null'): + raw=b'{"t":'+value+b'}' + self.assertEqual(fast.classify('a.json',raw,raw,timing_paths=[('t',)])['cls'],'invalid') + + +if __name__=='__main__': + unittest.main(verbosity=2) diff --git a/research/strict-payload-paired-walk/verify.py b/research/strict-payload-paired-walk/verify.py new file mode 100644 index 0000000000..a4e53a93ce --- /dev/null +++ b/research/strict-payload-paired-walk/verify.py @@ -0,0 +1,162 @@ +#!/usr/bin/env python3 +"""Full retained corpus differential replay and scoped traversal controls. + +ywz65, with substantial OpenAI Codex assistance. Apache-2.0. +""" +import argparse +import builtins +from collections import Counter +import gzip +import hashlib +import importlib.util +import itertools +import json +from pathlib import Path +import sys +import types + +HERE = Path(__file__).resolve().parent +ROOT = HERE.parents[1] +OLD = 'research/strict-replay-payload-comparison/' + + +def require(ok, message): + if not ok: + raise ValueError(message) + + +def encoded(value): + return json.dumps(value, sort_keys=True, separators=(',', ':'), allow_nan=False).encode() + + +def bind(root=ROOT): + manifest = json.loads((HERE / 'SOURCES.json').read_text(encoding='utf-8')) + expected = {OLD + x for x in ('compare.py', 'verify.py', 'RESULT.json', + 'SOURCES.json', 'TIMINGS.json', 'test_compare.py')} + expected |= {'research/community-frontier1094-audit/' + x for x in ( + 'selected-replay.tar.gz', 'RESULT.json', 'REPLAY.json', 'ASSEMBLY.json')} + expected |= {'research/selected-final-stage-portability/' + x for x in ('compare_payloads.py', 'README.md')} + rows = [r for r in manifest['files'] if r['usage'] == 'input'] + require(len(rows) == len(expected) and {r['path'] for r in rows} == expected, + 'input inventory differs') + for row in rows: + raw = (root / row['path']).read_bytes() + require(row['usage'] == 'input' and hashlib.sha256(raw).hexdigest() == row['sha256'], + 'input SHA256 differs: ' + row['path']) + require(hashlib.sha1(b'blob ' + str(len(raw)).encode() + b'\0' + raw).hexdigest() == row['git_blob'], + 'input blob differs: ' + row['path']) + return manifest + + +def module(path, aliases=None): + mod = types.ModuleType('private_' + path.stem) + mod.__file__ = str(path) + env = dict(vars(builtins)) + def importing(name, *args, **kwargs): + if aliases and name in aliases: + return aliases[name] + return builtins.__import__(name, *args, **kwargs) + env['__import__'] = importing + mod.__dict__['__builtins__'] = env + exec(compile(path.read_bytes(), str(path), 'exec'), mod.__dict__) + return mod + + +def setup(): + bind() + fast = module(HERE / 'compare.py') + retained = module(ROOT / OLD / 'verify.py', {'compare': fast.source}) + return fast, retained + + +def controls(fast, differential): + total = 0 + atoms = [b'null', b'true', b'false', b'0', b'1', b'-1', b'1.0', b'1.00', + b'0.00000000000000000000001', b'1e999', b'10e998', b'"x"', b'[]', b'{}'] + for a, b in itertools.product(atoms, repeat=2): + for prefix, suffix in ((b'', b''), (b'[', b']'), (b'{"x":', b'}')): + differential('p.json', prefix+a+suffix, prefix+b+suffix) + total += 1 + ra, rb = fast.Roots([('W', '/a'), ('N', '/a/n')]), fast.Roots([('W', '/b'), ('N', '/b/n')]) + # Timing paths use original keys, not normalized key tags. Both masks must + # designate the paired node; root-valued timing is also an allowed policy. + pairs = [ + (b'{"s":[{"seconds":1.0}],"proof":17}', b'{"s":[{"seconds":2}],"proof":17}', [('s',0,'seconds')]), + (b'{"s":[{"seconds":1.0}],"proof":17}', b'{"s":[{"seconds":2}],"proof":18}', [('s',0,'seconds')]), + (b'1.0', b'2', [()]), + (b'{"/a":1,"/b":2}', b'{"/a":2,"/b":1}', [('/a',)]), + (b'{"/a":1,"/b":2}', b'{"/a":1,"/b":2}', [('/a',)]), + (b'{"/a/n/file":1,"x":"/a/f"}', b'{"/b/n/file":1,"x":"/b/f"}', []), + (b'{"x":"/a/f"}', b'{"x":"/a/f"}', []), + (b'{"x":"/a/f"}', b'{"x":"W/f"}', []), + ] + for a,b,policy in pairs: + for x,y in ((fast.EMPTY,fast.EMPTY),(ra,rb)): + differential('p.json',a,b,x,y,policy); total += 1 + invalid = [b'{"a":1,"a":2}', b'NaN', b'Infinity', b'{', b'"\xff"'] + for a in invalid: + for b in (a,b'{}'): + differential('p.json',a,b); total += 1 + raw = b'{"x":1}' + for a,b in [(gzip.compress(raw,mtime=1),gzip.compress(raw,mtime=2)), + (gzip.compress(raw),gzip.compress(b'{"x":true}')), + (gzip.compress(raw),gzip.compress(raw)[:-5]),(b'bad',b'bad')]: + differential('p.json.gz',a,b); total += 1 + for policy in ([('s',0,'seconds')]*2,[('s',False,'seconds')],[('s',-1,'seconds')], + [('missing',)],None): + differential('p.json',pairs[0][0],pairs[0][1],timing_paths=policy); total += 1 + for a,b in ((b'a',b'a'),(b'a',b'b')): + differential('p.bin',a,b); total += 1 + return total + + +def run(): + fast, retained = setup() + counts = Counter() + def differential(*args, **kwargs): + expected = fast.original_classify(*args, **kwargs) + actual = fast.classify(*args, **kwargs) + require(encoded(actual) == encoded(expected), 'complete classification differs: '+str(args[0])) + counts[retained.label(actual)] += 1 + return actual + # Original exact-source corpus generator and 39 original adverse witnesses. + # Every classify invocation now checks the full original result, including + # errors/first-difference paths; the stored original receipt also must match. + proxy = types.SimpleNamespace(**vars(fast.source)) + proxy.classify = differential + retained.strict = proxy + inputs = retained.bound_inputs() + data = retained.corpus(inputs) + result = retained.audit(inputs,data) + require(encoded(result) == encoded(json.loads((ROOT / OLD / 'RESULT.json').read_bytes())), + 'retained complete receipt differs') + before = sum(counts.values()) + extra = controls(fast,differential) + # Reformat every compressed JSON body too: these large positive payloads + # exercise the optimized traversal rather than the equal-body shortcut. + reformats = 0 + for name,raw in sorted(data.items()): + if name.endswith('.json.gz'): + body = gzip.decompress(raw) + changed = b'\n'+body+b'\n' + actual = differential(name,raw,gzip.compress(changed,mtime=123)) + require(actual == {'cls':'json-format'}, 'large reformat not exercised') + reformats += 1 + return {'status':'PASS_STRICT_PAYLOAD_PAIRED_WALK', 'corpus_files':len(data), + 'retained_classify_calls':before, 'retained_adverse_witnesses':39, + 'extra_differential_cases':extra,'compressed_json_reformats':reformats, + 'classifications':dict(sorted(counts.items())), + 'scope':'exact comparison equivalence on stated corpus/controls; no supplier replay or new kappa'} + + +if __name__ == '__main__': + parser=argparse.ArgumentParser(description=__doc__) + parser.add_argument('--write',type=Path) + args=parser.parse_args() + result=run() + if args.write: + with args.write.open('x',encoding='utf-8',newline='\n') as stream: + json.dump(result,stream,indent=2,sort_keys=True);stream.write('\n') + else: + require(encoded(result)==encoded(json.loads((HERE/'RESULT.json').read_bytes())), 'typed complete receipt differs') + print(result['status'])