diff --git a/research/fraction-native-score-dispatch-feasibility/.gitignore b/research/fraction-native-score-dispatch-feasibility/.gitignore new file mode 100644 index 0000000000..4446e4135a --- /dev/null +++ b/research/fraction-native-score-dispatch-feasibility/.gitignore @@ -0,0 +1,3 @@ +__pycache__/ +work/ +*.so diff --git a/research/fraction-native-score-dispatch-feasibility/FINITE-SOURCE.json b/research/fraction-native-score-dispatch-feasibility/FINITE-SOURCE.json new file mode 100644 index 0000000000..21e6de8403 --- /dev/null +++ b/research/fraction-native-score-dispatch-feasibility/FINITE-SOURCE.json @@ -0,0 +1,5 @@ +{ + "function_sha256": "b05f469b8a6fe9a725ac59ba0e6171e86a4906c8929883a54862cf9b2605c6e4", + "boundary": "after all ten probe correctness controls; before fixed timing arms", + "module_sha256": "ad34e00ad7d0a9f192f4e3e89b1b7cc3b45d27d10063fa2dc1937e101cf60c09" +} diff --git a/research/fraction-native-score-dispatch-feasibility/NOTICE b/research/fraction-native-score-dispatch-feasibility/NOTICE new file mode 100644 index 0000000000..14c41af625 --- /dev/null +++ b/research/fraction-native-score-dispatch-feasibility/NOTICE @@ -0,0 +1,11 @@ +Fraction arithmetic primitive profile and bounded contribution-table feasibility +============================================================================ +Original Fraction/error arithmetic: Ali Romman, retaining Adam Gall/ywz65/PR2878, PR5826/5819, Mason Hale/PR5811 and all P104/native/compiler/precision notices. Full PR5848, PR5831 and nested source archives are unchanged. Apache-2.0. + +New primitive profiling, exact local table, finite/key/capacity/failure checks and complete-cost screen: Chris R / Clear1nsight, substantial OpenAI Codex assistance; no subagents or independent human/kernel acceptance. Memoization is a standard technique. PR5848/5839 supply the qualifier/Linux baseline; PR5816/5818/5832/5761 retain tooling and test-repair credit with original authorship. The prior zero/unit negative artifact71f22c77b393e5cc14925c771894dc1a92c8443c supplies source-binding and finite-fixture lineage. No complete performance or kappa improvement is claimed. + +Source-bound entry type gate: Chris R / Clear1nsight with substantial OpenAI Codex assistance; no independent human or proof-kernel acceptance. Parent table/finite bytes retained exactly from df9dc4c89b31494f1390d16b9ca2a15e5946e853 (PR5852). Publication agents handled only earlier branches, not this scientific test. + +Native cache/context, source-bound slot/compact-key integration and complete cold-build qualifier: Chris R / Clear1nsight with substantial OpenAI Codex assistance and GPT-6-astra xhigh static review. The original Fraction miss arithmetic and independent exact integer engine are unchanged. C API/reference-counting/memoization are standard techniques. Preserve all inherited authors and Apache-2.0 notices. The C helper is new code; it does not port CPython arithmetic. Local measured timings are not a universal speedup or hosted performance validation. No kappa claim. + +Scoped native score-dispatch probe: Chris R / Clear1nsight with substantial OpenAI Codex assistance; Astra static nomination/stop review only. Original Python Fraction._add is called, not ported. No new complete or kappa gain. Parent native/source authorship retained. Apache-2.0. diff --git a/research/fraction-native-score-dispatch-feasibility/PARENT-SCORE-LOOP.txt b/research/fraction-native-score-dispatch-feasibility/PARENT-SCORE-LOOP.txt new file mode 100644 index 0000000000..e8b391931e --- /dev/null +++ b/research/fraction-native-score-dispatch-feasibility/PARENT-SCORE-LOOP.txt @@ -0,0 +1,9 @@ + for(int k=0;k<3;k++){ + PyObject *score=PyList_GetItem(scores,k); + if(!score)goto fail; + Py_INCREF(score); + PyObject *next=PyNumber_InPlaceAdd(score,PyTuple_GET_ITEM(result,k+1)); + Py_DECREF(score); + if(!next)goto fail; + if(PyList_SetItem(scores,k,next)<0)goto fail; + } diff --git a/research/fraction-native-score-dispatch-feasibility/PROBE-SOURCE.json b/research/fraction-native-score-dispatch-feasibility/PROBE-SOURCE.json new file mode 100644 index 0000000000..9af43a876f --- /dev/null +++ b/research/fraction-native-score-dispatch-feasibility/PROBE-SOURCE.json @@ -0,0 +1,6 @@ +{ + "sha256": "ac5d282405e74f1f8cc4cddb768485709057d249dae370a16c063ab45327c2ea", + "parent_native_sha256": "78ed2e240ee40ce4989a4718e77e8b3967b092d2bf8c900124a26942c98a14cb", + "parent_loop_sha256": "b3dfa3aadae31d008309bc91fae06fab3aef86dd899dcbc34156cdff835d91e0", + "source_seam": "Exact retained parent three-score loop; only direct arm changes PyNumber_InPlaceAdd selection, with exact type guards and separate counts." +} diff --git a/research/fraction-native-score-dispatch-feasibility/PROOF.md b/research/fraction-native-score-dispatch-feasibility/PROOF.md new file mode 100644 index 0000000000..8b87ad8bed --- /dev/null +++ b/research/fraction-native-score-dispatch-feasibility/PROOF.md @@ -0,0 +1,11 @@ +# Scope of the finite probe and stopping rule + +The prototype copies the literal three-score C loop from authenticated PR5864 source. The generic arm preserves each checked score retrieval, owned reference, PyNumber_InPlaceAdd, decref and stealing list store. The direct arm changes only call selection at these sites, requiring both operands to be exactly the supplied Fraction class before vectorcalling the existing bound Python kernel. Other operands retain generic augmented assignment. Direct errors propagate without retry, with already completed score stores preserved. Both loops retain owned score references and checked stores around callbacks; immutable tuple arguments own the increments throughout the call. + +The checked wrapper binds the original existing Fraction addition code/closure/globals, constructor helpers and relevant MRO entries, with trace-entry freshness. Stable qualified runtime/operands are semantic premises. Raw packet type checks alone do not certify an arbitrary supplied function. The 33 prefix cases compare every complete score/type with ordinary Python addition, and ten controls test the native branch and error/fallback boundaries. These are finite probe checks; no full Cache/Event caller or all-input native proof is asserted. + +The registered verifier authenticates the complete parent archive and literal source loop, binds the live measured probe function to its unchanged source, and truncates only at the unique boundary after all ten controls and before any timing. Thus fresh finite replay repeats every probe correctness assertion while the historical timing observations remain evidence, not a flaky test condition. The probe source, C source, binder, shapes and all original observations are retained. + +The declared decision rule asks whether conservative illustrative gross saving can cover a nonnegative incremental full validation/build bill plus observed complete-parent variability. Its retained smaller-pair illustration is 0.187220978 wall / 0.187227513 CPU seconds, below the parent complete ranges 0.460568479 / 0.45. Even setting the unbuilt additional bill to zero gives negative margins. This justifies a scoped engineering stop before further integration. Synthetic scaling is not a true-gain upper bound, so this is not an impossibility theorem or a claim that a different benchmark cannot perform better. + +All four timing samples, their source inventory, cold build bill, raw narrower PASS status, the 33-versus-32 prose correction and the direct arm's per-add counter cost remain. A source reviewer independently checked receipt arithmetic but ran no numerical experiment. No performance sample was rerolled or discarded, and no work was added to the frozen successful PR5864 implementation. diff --git a/research/fraction-native-score-dispatch-feasibility/README.md b/research/fraction-native-score-dispatch-feasibility/README.md new file mode 100644 index 0000000000..2789395746 --- /dev/null +++ b/research/fraction-native-score-dispatch-feasibility/README.md @@ -0,0 +1,44 @@ +# Scoped stop for a native Fraction score-dispatch probe + +A fixed native B,C,C,B micro passes 33 prefix comparisons and ten functional/source-binding controls, and both paired micro comparisons improve. Its smaller paired difference illustrates only **0.187221 wall / 0.187228 CPU seconds** when scaled to the frozen 7,739,250 score-addition sites. This is below PR5864's observed complete candidate ranges of **0.460568 wall / 0.45 CPU seconds**, before any new full validation cost. Stop before full-control integration, actual audit or complete construction. + +This is an engineering screen for this probe, not a bound on true native gain, a universal obstruction or a measured complete saving. [PR #5864](https://github.com/CrocSwap/integer-mult-bounds/pull/5864)'s validated 19.12% wall / 18.82% CPU improvement remains unchanged. Kappa research stays paused. + +## Question and source boundary + +Can calling the existing, authenticated Python Fraction._add directly from C pay its additional complete verification cost? The exact parent three-score loop is retained from PR5864 head `3f15c943e4ad6479f03e674c80fff1269a16ccfe`; the full official export is authenticated before finite replay. The direct arm adds exact operand-type guards, vectorcall to that same Python arithmetic routine and per-add dispatch counters. The generic arm retains PyNumber_InPlaceAdd and reports an aggregate count at exit. This counter asymmetry is paid in the measured probe and limits its interpretation. + +The actual native Cache/Event integration is not built. No new rational arithmetic, independent backend, fixture or accepted caller is introduced. The probe demonstrates only its declared native score-loop controls, not all original qualification obligations. The retained prior binder checks executable shapes, closure/global/MRO state and identity-only freshness; it refuses unknown runtime bindings without invoking foreign descriptors. + +## Fixed observations and stop + +Sixteen fixed increment triples cover zeros, signs, cancellation, common/coprime denominators and 128-bit numerators. Each arm runs 32,768 groups / 98,304 additions with fresh scores, in B,C,C,B order. Prefix comparisons and controls run before timing. All samples are retained: + +| Arm | Wall seconds | CPU seconds | +| --- | ---: | ---: | +| B1 | 0.083361725 | 0.082788980 | +| C1 | 0.067125316 | 0.067122706 | +| C2 | 0.067535516 | 0.067539532 | +| B2 | 0.069913598 | 0.069917697 | + +The smaller paired difference is 0.002378082 wall / 0.002378165 CPU seconds. Illustrative scaling gives the 0.187-second figures above. Assuming an optimistically zero additional validation bill, its margin against the recorded complete-parent range is **−0.273348 wall / −0.262772 CPU seconds**. The prescribed conservative screen fails. No extra timing permutation, dropped sample, actual replay or larger construction follows. The raw micro status remains `MICRO_PASS_REQUIRES_FULL_INCREMENTAL_COST_BILL`: its narrower functional/timing predicates passed; the later complete-cost screening rule stopped expansion. + +One scientific command cost 0.710 seconds wall, including cold C compilation, with no stderr and unchanged source bytes/modes. No automatic retry. The original 180-second command / 1 GiB sampled group RSS / 600-second initial / 1,500-second shared round limits remain. A first packaged finite replay rejected source authentication before native execution: compiling an isolated function changed its imported-module call opcodes. Complete-module source authentication and truncation preserve the compilation context; fresh normal/O finite replays pass, and the failed draft/receipt remain. No timing was repeated. The initial plan said 32 prefix comparisons; actual code includes the zero prefix and tests all 33 prefixes 0 through 32. This extra zero case and the counter asymmetry are documented without rerunning or inventing savings credit. + +## Reproduction and coverage + +```sh +python3 -B scripts/research_package.py --package research/fraction-native-score-dispatch-feasibility +``` + +Registered replay freshly compiles the probe and executes all 33 prefix comparisons and ten functional/binding controls, without repeating timings or asserting that a new host must reproduce the historical stop. It authenticates the complete parent archive, native source and literal score-loop boundary. Tested with Linux CPython 3.12.3 / GCC 13.3; existing `cc` and Python development headers are required. No install or silent native skip. + +The ten controls cover complete prefix values/types and branch counts, nonexact/custom and Fraction-subtype generic augmented assignment, nonexact increments, direct exceptions without retry and exact partial-update order, callback list mutation, invalid kernel packets, live kernel / present-None-iadd drift and complete runtime restoration. + +The original PR5864's 964 comparisons / 118 controls and complete qualification were not repeated in this rejected extension; their measured/published implementation is untouched. The planned 19 prior dispatch controls and new Cache/Event lifetime integration were not executed because the earlier screen did not justify that construction. Do not describe this probe as preserving a newly integrated complete caller. See [SCREEN.json](SCREEN.json), [PROOF.md](PROOF.md) and retained evidence. + +## Open next questions + +No further measured continuation is justified in this round. A separately proposed mechanism needs its own source/ownership/coverage/cost argument and a new fixed feasibility gate. Constructor-elision and descriptor-metadata ideas retain unpriced obligations; this stop does not exclude them or other future work. Keep the successfully measured PR5864 frozen while it is reviewed. + +Chris R / Clear1nsight with substantial OpenAI Codex assistance; GPT-6-astra xhigh performed static nomination/stop review only and no compiler or numerical work. Original arithmetic remains Python Fraction and all credited Ali Romman/P104/native/tooling predecessors. Standard dispatch/C API techniques. Apache-2.0; no kappa, merge or selected-frontier change. diff --git a/research/fraction-native-score-dispatch-feasibility/RESULT.json b/research/fraction-native-score-dispatch-feasibility/RESULT.json new file mode 100644 index 0000000000..03a8dc84a1 --- /dev/null +++ b/research/fraction-native-score-dispatch-feasibility/RESULT.json @@ -0,0 +1,17 @@ +{ + "prefix_cases": 33, + "controls": [ + "all-33-prefix-values-types-and-branches", + "nonexact-custom-score-generic-iadd", + "Fraction-subtype-generic-iadd", + "nonexact-increment-generic", + "direct-error-no-retry-partial-update-order", + "callback-score-list-mutation-safe", + "nonfunction-kernel-packet-rejected", + "kernel-binding-drift", + "present-none-iadd-drift", + "runtime-restored-before-timing" + ], + "control_count": 10, + "runtime_current": true +} diff --git a/research/fraction-native-score-dispatch-feasibility/RUNTIME-SHAPES.json b/research/fraction-native-score-dispatch-feasibility/RUNTIME-SHAPES.json new file mode 100644 index 0000000000..9d7406e48d --- /dev/null +++ b/research/fraction-native-score-dispatch-feasibility/RUNTIME-SHAPES.json @@ -0,0 +1,17 @@ +{ + "functions": { + "__add__": "896b59b7df8e862396d6d7a2702cb7d70b0272fcb925d6f2eb05185a7538ddb0", + "__radd__": "6c3aec85f1cd6d3625edbc271d34714cb5760d8f1bfa8f8946c238760ea394fd", + "_add": "cd655a8ed6164c9e64d6fbaff8c41407b55d583d0327c9a889f0d4bfb30d24b1", + "__mul__": "896b59b7df8e862396d6d7a2702cb7d70b0272fcb925d6f2eb05185a7538ddb0", + "_mul": "fddb7b00e5a1935b50177847fed06d5be9b0e98a88b7b03168e39b7058fcaef5", + "__abs__": "97fd3b7adf132814a9c1e7046ca724af66e814c365e0e6f0b315c577e3eb1ffe", + "__neg__": "7e3ea316de290d2c079d2b638791708174d983db9bdbbb673eda15e4f37477de", + "__new__": "d4c031bbaf8cab747dc194b04b157ba1d4c2235f9bbc0048d72801fffc4f4b85", + "_from_coprime_ints": "e8b9a62eb272ce89e2433eaa70feb9eb29193f4895a3e9d5eb11731f3c848baa", + "__sub__": "896b59b7df8e862396d6d7a2702cb7d70b0272fcb925d6f2eb05185a7538ddb0", + "_sub": "17df3425c308b7395d2f9b4d2941ba5c4fe7eb316e880c62a00903cc568bee34" + }, + "reference_module_sha256": "cf33568f7b767f66896995a7a81cc662e8be226f2e58efb61d2028f64eb5d231", + "policy": "Known executable shapes, live closures/globals and full MRO bind the direct path; unsupported runtime uses unchanged generic +=. Source file hash recorded, not sufficient alone." +} diff --git a/research/fraction-native-score-dispatch-feasibility/SCREEN.json b/research/fraction-native-score-dispatch-feasibility/SCREEN.json new file mode 100644 index 0000000000..7620ca625a --- /dev/null +++ b/research/fraction-native-score-dispatch-feasibility/SCREEN.json @@ -0,0 +1,138 @@ +{ + "decision": "STOP_NATIVE_DIRECT_ADD_BEFORE_ACTUAL_OR_COMPLETE_CONSTRUCTION", + "micro": { + "additions_per_arm": 98304, + "build": { + "SOABI": "cpython-312-x86_64-linux-gnu", + "binary_sha256": "2539108f782328dcf75f477e6fa085235fa42a327743c97c1c16a4397c67ec95", + "cold_build_load_wall_seconds": 0.1481919409998227, + "compiler": "/usr/bin/cc", + "compiler_cpu_accounting": "outer GNU time user+system includes compiler children", + "compiler_version": "cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0", + "extension_suffix": ".cpython-312-x86_64-linux-gnu.so", + "flags": [ + "-O2", + "-shared", + "-fPIC", + "-std=c11", + "-Wall", + "-Werror", + "-I/usr/include/python3.12" + ], + "python": "3.12.3 (main, Aug 31 2026, 10:18:26) [GCC 13.3.0]", + "source_sha256": "ac5d282405e74f1f8cc4cddb768485709057d249dae370a16c063ab45327c2ea" + }, + "control_count": 10, + "controls": [ + "all-33-prefix-values-types-and-branches", + "nonexact-custom-score-generic-iadd", + "Fraction-subtype-generic-iadd", + "nonexact-increment-generic", + "direct-error-no-retry-partial-update-order", + "callback-score-list-mutation-safe", + "nonfunction-kernel-packet-rejected", + "kernel-binding-drift", + "present-none-iadd-drift", + "runtime-restored-before-timing" + ], + "fixed_order": "BCCB", + "groups_per_arm": 32768, + "illustrative_gross_only": { + "cpu_seconds": 0.18722751338958643, + "wall_seconds": 0.18722097821499695 + }, + "no_actual_or_complete_construction": true, + "not_a_full_trace_projection_or_improvement": true, + "observations": [ + { + "counts": [ + 0, + 98304 + ], + "cpu_seconds": 0.08278898000000001, + "label": "B", + "terminal_scores": [ + "2/3", + "-5/7", + "11/13" + ], + "wall_seconds": 0.08336172500276007 + }, + { + "counts": [ + 98304, + 0 + ], + "cpu_seconds": 0.06712270600000003, + "label": "C", + "terminal_scores": [ + "2/3", + "-5/7", + "11/13" + ], + "wall_seconds": 0.06712531601078808 + }, + { + "counts": [ + 98304, + 0 + ], + "cpu_seconds": 0.06753953200000001, + "label": "C", + "terminal_scores": [ + "2/3", + "-5/7", + "11/13" + ], + "wall_seconds": 0.06753551599103957 + }, + { + "counts": [ + 0, + 98304 + ], + "cpu_seconds": 0.069917697, + "label": "B", + "terminal_scores": [ + "2/3", + "-5/7", + "11/13" + ], + "wall_seconds": 0.06991359798121266 + } + ], + "paired_differences": { + "cpu_seconds": [ + 0.01566627399999998, + 0.0023781649999999876 + ], + "wall_seconds": [ + 0.016236408991971985, + 0.0023780819901730865 + ] + }, + "runtime_current": true, + "status": "MICRO_PASS_REQUIRES_FULL_INCREMENTAL_COST_BILL" + }, + "comparison_model": { + "gross": "Conservative smaller paired micro difference, illustratively scaled to source score count; not a bound on true actual saving.", + "additional_cost_assumed_seconds": 0, + "additional_cost_scope": "Optimistically zero to reject further expansion without building/measuring the full additional control union.", + "parent_complete_C_spread": { + "wall_seconds": 0.4605684790003579, + "cpu_seconds": 0.45000000000000284 + }, + "modeled_margin_before_any_new_cost": { + "wall_seconds": -0.27334750078536096, + "cpu_seconds": -0.2627724866104164 + } + }, + "why": "Even zero-cost illustrative saving fails the prespecified observed full-parent spread in wall and CPU. Both micro pairs improve but evidence does not justify further expansion. No timing reroll or sample omission.", + "not_a_universal_obstruction": true, + "not_a_complete_measurement": true, + "no_new_kappa": true, + "actual_audits": 0, + "complete_candidates": 0, + "scientific_command_count": 1, + "guarded_wall_seconds": 0.709715356992092 +} diff --git a/research/fraction-native-score-dispatch-feasibility/SOURCES.json b/research/fraction-native-score-dispatch-feasibility/SOURCES.json new file mode 100644 index 0000000000..77d0bb6300 --- /dev/null +++ b/research/fraction-native-score-dispatch-feasibility/SOURCES.json @@ -0,0 +1,56 @@ +{ + "schema_version": 1, + "base_commit": "de5ec2e7a6074068452f45b1a191b5c72832df4a", + "files": [ + { + "path": "docs/research/agent-task-catalog.json", + "usage": "provenance", + "git_blob": "3404fbdd5e7529a0674eef26114b5071e4586cec", + "sha256": "ead6cdc9d0af6d58e8a49744d8ec8c7c15e13d2ba93c276c434bcf9b51b93a81" + }, + { + "path": "certificates/selected-result.json", + "usage": "provenance", + "git_blob": "581f8d87008354eb5b869f7ed9de1317ad837ce8", + "sha256": "2a0220e866417774606e0f991e41b9c1d26b1f43b97857238cf478dbc7d330b5" + }, + { + "path": "research/fraction-native-score-dispatch-feasibility/inputs/PR5864.tar", + "usage": "input", + "git_blob": "bb9fc302168df0bf66cf43d08bce70544eeffc4e", + "sha256": "7b142567acacac5182045bf8daa8780e916661c2cf343dbf81b13c88ead85d64", + "pin": "head:dec843d2aebd0e66f2767aaac26d3db3f32a7226:research/fraction-native-score-dispatch-feasibility/inputs/PR5864.tar" + }, + { + "path": "research/fraction-native-score-dispatch-feasibility/native_parent.c", + "usage": "input", + "git_blob": "ada7b0d0bf999536b2c3a665d8845266b37d198b", + "sha256": "78ed2e240ee40ce4989a4718e77e8b3967b092d2bf8c900124a26942c98a14cb", + "pin": "head:dec843d2aebd0e66f2767aaac26d3db3f32a7226:research/fraction-native-score-dispatch-feasibility/native_parent.c" + }, + { + "path": "research/fraction-native-score-dispatch-feasibility/table_parent.py", + "usage": "input", + "git_blob": "7f44b25859e90d981587a53e9467284961f60a8f", + "sha256": "d598b8a757251c1e38ed77af6cc2aebe1b8ae23ad29ce06bff3ca973eb56dbc4", + "pin": "head:dec843d2aebd0e66f2767aaac26d3db3f32a7226:research/fraction-native-score-dispatch-feasibility/table_parent.py" + }, + { + "path": "research/fraction-native-score-dispatch-feasibility/runtime_binding.py", + "usage": "input", + "git_blob": "4f7c0a31f3c5e178d9817edcb746d26adfdc1250", + "sha256": "f2e74fef881cb49101338e40e2d84600e2c9d0e717dafb46a20d7217609d4c71", + "pin": "head:dec843d2aebd0e66f2767aaac26d3db3f32a7226:research/fraction-native-score-dispatch-feasibility/runtime_binding.py" + }, + { + "path": "research/fraction-native-score-dispatch-feasibility/RUNTIME-SHAPES.json", + "usage": "input", + "git_blob": "9d7406e48d01bd3c015110b57ce12e258e344a7b", + "sha256": "5a7080757fa132a2a45ad56a5e9319c938a352b1324c074cdccd9799c1aecdce", + "pin": "head:dec843d2aebd0e66f2767aaac26d3db3f32a7226:research/fraction-native-score-dispatch-feasibility/RUNTIME-SHAPES.json" + } + ], + "parent_pr": 5864, + "parent_archive_sha256": "7b142567acacac5182045bf8daa8780e916661c2cf343dbf81b13c88ead85d64", + "predecessor_binding": "Own prior direct-add feasibility runtime binder/shapes; retained as exact own-ancestor inputs, not independently authored mathematics." +} diff --git a/research/fraction-native-score-dispatch-feasibility/TASK.json b/research/fraction-native-score-dispatch-feasibility/TASK.json new file mode 100644 index 0000000000..9296bb8380 --- /dev/null +++ b/research/fraction-native-score-dispatch-feasibility/TASK.json @@ -0,0 +1,60 @@ +{ + "schema_version": 1, + "task_id": "replay-runtime", + "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_selected_baseline.py" + ], + "expected": "PASS_RESEARCH_BASELINE_BINDINGS_ONLY", + "inspect": "Resolve the current selected review, separate complex/ordinary BIT/admitted BIT/outer budgets, and compare the card against live handoffs before starting. Historical ceilings require exact source/model equivalence.", + "scope": "Source-binding orientation only; not a scientific replay or all-size proof. Materialize selected inputs if this checkout is sparse." + }, + "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": "Continuous user goal allowed a bounded further improvement nomination after the15% minimum. One fixed native score-loop probe passes finite checks but fails its conservative complete-cost/spread screen; no integration follows.", + "actual_scope": "PR5864/native-score-dispatch-micro-only", + "bottleneck_link": "Faster trustworthy replays increase review throughput and let mechanism candidates be checked sooner.", + "stop_rule": "Stop before full-control union, actual audit or complete construction. No reroll; preserve every sample. Same180s/1GiB/600sinitial1500sshared/serial/no-auto-retry contract.", + "time_budget_minutes": 60, + "outcome": "negative-result", + "evidence": "SCREEN.json, raw BCCB probe and source inventories;33 prefix comparisons/10 controls; no actual or complete candidate.", + "author": "Chris R / Clear1nsight", + "ai_assistance": "Substantial OpenAI Codex implementation/execution assistance and GPT-6-astra xhigh static nomination/stop review. Single parent numerical runner; no independent human or proof-kernel acceptance.", + "open_questions": [ + { + "question": "Can a separately justified mechanism pay its complete additional verification bill?", + "why_it_matters": "This fixed conservative probe screen lacks margin despite positive micro pairs; prior PR5864 minimum remains achieved.", + "first_step": "New exact source/coverage/resource contract and fixed small feasibility test; keep PR5864 frozen.", + "blocked_by": "No further measured continuation is justified by this round; deferred ideas carry unpriced obligations." + } + ], + "base_commit": "de5ec2e7a6074068452f45b1a191b5c72832df4a" +} diff --git a/research/fraction-native-score-dispatch-feasibility/VALIDATION.json b/research/fraction-native-score-dispatch-feasibility/VALIDATION.json new file mode 100644 index 0000000000..42fa1e5804 --- /dev/null +++ b/research/fraction-native-score-dispatch-feasibility/VALIDATION.json @@ -0,0 +1,17 @@ +{ + "scope": "Finite probe only; full caller and coverage integration not built", + "science_commands": 1, + "probe_controls": 10, + "prefix_cases": 33, + "guarded_wall_seconds": 0.709715356992092, + "actual_audits": 0, + "complete_candidates": 0, + "automatic_retries": 0, + "screen": "STOP even with zero added bill", + "source_before_after": true, + "all_four_timing_samples_retained": true, + "CI_claim": false, + "packaged_finite_normal_and_optimized": "PASS", + "retained_publication_harness_failure": "Isolated-function recompilation changed import-context opcodes; repaired by binding the complete original module, no scientific source or timing change.", + "all_guarded_attempts_preserved": true +} diff --git a/research/fraction-native-score-dispatch-feasibility/VERIFY.json b/research/fraction-native-score-dispatch-feasibility/VERIFY.json new file mode 100644 index 0000000000..500a51468e --- /dev/null +++ b/research/fraction-native-score-dispatch-feasibility/VERIFY.json @@ -0,0 +1,24 @@ +{ + "schema_version": 1, + "status": "ready", + "python": "3.12", + "requirements": [], + "inputs": [ + "research/fraction-native-score-dispatch-feasibility/inputs/PR5864.tar", + "research/fraction-native-score-dispatch-feasibility/native_parent.c", + "research/fraction-native-score-dispatch-feasibility/table_parent.py", + "research/fraction-native-score-dispatch-feasibility/runtime_binding.py", + "research/fraction-native-score-dispatch-feasibility/RUNTIME-SHAPES.json" + ], + "commands": [ + { + "argv": [ + "{python}", + "-B", + "{package}/verify.py" + ], + "timeout_seconds": 30, + "checks": "Fresh C compile; exact parent source/loop authentication; all33 prefix values/types and10 native binding/fallback/error controls. Does not rerun timings, integrate the full118-control parent chain, execute an actual word or claim complete speedup/kappa." + } + ] +} diff --git a/research/fraction-native-score-dispatch-feasibility/evidence/INTAKE.json b/research/fraction-native-score-dispatch-feasibility/evidence/INTAKE.json new file mode 100644 index 0000000000..8f6579d14a --- /dev/null +++ b/research/fraction-native-score-dispatch-feasibility/evidence/INTAKE.json @@ -0,0 +1,10 @@ +{ + "parent_pr": 5864, + "parent_head": "3f15c943e4ad6479f03e674c80fff1269a16ccfe", + "parent_archive_sha256": "7b142567acacac5182045bf8daa8780e916661c2cf343dbf81b13c88ead85d64", + "canonical_main": "de5ec2e7a6074068452f45b1a191b5c72832df4a", + "overlap": "Targeted main/PR5864 comments/Fraction-native-score search refreshed; only own source and predecessors. Bounded, not exhaustive.", + "status": "STATIC_NOMINATION_PENDING_NO_CONSTRUCTION", + "scientific_runs": 0, + "kappa": "PAUSED" +} diff --git a/research/fraction-native-score-dispatch-feasibility/evidence/PLAN.json b/research/fraction-native-score-dispatch-feasibility/evidence/PLAN.json new file mode 100644 index 0000000000..5e3cd9f470 --- /dev/null +++ b/research/fraction-native-score-dispatch-feasibility/evidence/PLAN.json @@ -0,0 +1,27 @@ +{ + "status": "ONE_NATIVE_MICRO_BEFORE_CONSTRUCTION", + "mechanism": "Source-bound C vectorcall to existing Fraction._add; no arithmetic port", + "parent_pr": 5864, + "parent_head": "3f15c943e4ad6479f03e674c80fff1269a16ccfe", + "canonical_main": "de5ec2e7a6074068452f45b1a191b5c72832df4a", + "micro": { + "triples": 16, + "groups_per_arm": 32768, + "score_additions_per_arm": 98304, + "order": "BCCB", + "adaptive_repetition": false + }, + "before_timing": "All32 prefix value/type comparisons, generic custom score dispatch, exception/no-retry and source/runtime binding controls must pass; record compiler/source/ABI", + "stop": "Stop if either paired wall/CPU comparison loses, or conservative illustrative gross saving cannot pay measured full incremental validation/build/binding costs plus spread. No actual/full construction before that gate.", + "coverage_future": "One inherited native suite covers964 comparisons/118 controls; map prior19 dispatch controls and distinct native branch/lifetime controls without duplicate suite.", + "caps": { + "command_seconds": 180, + "rss_bytes": 1073741824, + "initial_seconds": 600, + "shared_seconds": 1500, + "serial": true, + "automatic_retries": 0 + }, + "kappa": "PAUSED", + "scientific_runs": 0 +} diff --git a/research/fraction-native-score-dispatch-feasibility/evidence/PUBLICATION-HARNESS-CORRECTION.json b/research/fraction-native-score-dispatch-feasibility/evidence/PUBLICATION-HARNESS-CORRECTION.json new file mode 100644 index 0000000000..520328a296 --- /dev/null +++ b/research/fraction-native-score-dispatch-feasibility/evidence/PUBLICATION-HARNESS-CORRECTION.json @@ -0,0 +1,9 @@ +{ + "attempt": "runtime/runs/packaged-score-finite", + "failure": "Isolated function recompilation changed compiler call opcodes for an imported-module attribute, so live-code shape authentication rejected before any native compilation or correctness controls.", + "diagnostic": "Only co_code differed; recompiling the complete original module preserves its import binding compilation context.", + "manual_fix": "Authenticate the entire measured module plus function source; compile that complete module for live shape equality and preserve its module context when truncating only after every correctness control.", + "science_unchanged": true, + "timing_reruns": 0, + "automatic_retries": 0 +} diff --git a/research/fraction-native-score-dispatch-feasibility/evidence/PUBLICATION-SETUP.json b/research/fraction-native-score-dispatch-feasibility/evidence/PUBLICATION-SETUP.json new file mode 100644 index 0000000000..c559f2f202 --- /dev/null +++ b/research/fraction-native-score-dispatch-feasibility/evidence/PUBLICATION-SETUP.json @@ -0,0 +1,8 @@ +{ + "failure": "git switch attempted unavailable promisor blob despite same frozen starting head, failed DNS, and removed163 working package files before failing; no branch or remote head change.", + "secondary_setup": "Dependent mkdir failed because research directory had been removed; no candidate code was changed.", + "repair": "Restore all163 exact public package bytes/modes from verified public export; reinitialize full index and skip-worktree flags; create/ref-select new branch without checkout. Restored parent is clean.", + "no_missing_object_fetch": true, + "no_force_push": true, + "old_public_branch_unchanged": true +} diff --git a/research/fraction-native-score-dispatch-feasibility/evidence/ROUND2-NOMINATION.json b/research/fraction-native-score-dispatch-feasibility/evidence/ROUND2-NOMINATION.json new file mode 100644 index 0000000000..8403143748 --- /dev/null +++ b/research/fraction-native-score-dispatch-feasibility/evidence/ROUND2-NOMINATION.json @@ -0,0 +1,93 @@ +{ + "status": "STATIC_ONLY_NOMINATE_ONE_BOUNDED_NATIVE_DIRECT_ADD_SCREEN", + "date": "2026-10-27", + "selected_option": "b", + "mechanism": "C vectorcall to the existing authenticated Python Fraction._add at three score sites; exact operand guards and generic fallback", + "arithmetic_port": false, + "performance_improvement_demonstrated": false, + "complete_construction_approved": false, + "parent_reported_publication": { + "pull_request": 5864, + "head": "3f15c943e4ad6479f03e674c80fff1269a16ccfe", + "green_ci_run": "40480683014", + "independently_fetched_by_reviewer": false + }, + "parent_reported_complete_medians": { + "original_pull_request": 5848, + "original_wall_seconds": 40.516155579, + "original_cpu_seconds": 40.33, + "native_wall_seconds": 32.77129668, + "native_cpu_seconds": 32.74, + "wall_saving_percent": 19.1155, + "cpu_saving_percent": 18.8197, + "new_round_comparator": "fresh PR5864 native complete process", + "additional_fifteen_percent_requirement": false + }, + "retained_census": { + "coefficient_updates": 2579750, + "score_additions": 7739250, + "cache_hits": 2252966, + "cache_misses": 326784, + "cache_evictions": 310400, + "weight_tokens": 3587, + "destination_hit_count": null + }, + "deferred": { + "a": "Destination-hit count unknown; skipping construction expands allocation, callback and exception semantics obligations.", + "c": "Descriptor metadata, owner, offset, audit and lifetime proof adds risk and controls without measured economic margin." + }, + "runtime_boundary": "Existing qualified PR5864 domain plus successful source-shape/live-binding authentication and trace-entry freshness; runtime metadata stable during a trace; no arbitrary raw-callback equivalence claim", + "fallback": "Unknown or stale addition binding selects existing PR5864 checked behavior; nonexact score operands use PyNumber_InPlaceAdd; direct-call errors propagate without retry", + "new_native_obligations": [ + "strong optional kernel ownership and GC traverse/clear", + "exact Fraction operand guards at every direct addition", + "generic custom-score augmented-assignment behavior", + "native branch selection and full value/type equality", + "unsupported and stale binding fallback", + "kernel exception propagation without generic retry", + "partial update and error ordering retained" + ], + "coverage_execution": { + "inherited_suite_executions": 1, + "inherited_comparisons": 964, + "predecessor_native_controls": 118, + "prior_dispatch_controls": 19, + "rule": "Map every named obligation; do not invoke the old direct-add inherited suite a second time merely to reuse its dispatch controls", + "table_statistics": "Preserve the complete old dictionary and counter values; optional direct/fallback counts are separate" + }, + "proposed_micro": { + "coefficient_groups_per_arm": 32768, + "additions_per_arm": 98304, + "fixed_increment_triples": 16, + "order": ["B", "C", "C", "B"], + "implementation": "actual three-score C loop, unchanged generic and guarded vectorcall entry points", + "adaptive_repetition": false, + "scientific_receipt": false + }, + "economic_stop": "Stop unless both paired micro comparisons improve in wall and CPU and conservative illustrative scaling covers measured incremental complete controls/binding/build costs plus observed spread in both metrics. Only then one actual equivalence audit; complete construction requires a further measured net-positive screen.", + "final_acceptance": "Positive complete incremental wall and total CPU saving beyond PR5864 repeat variability after the new check/build bill; preserve >=15 percent in both metrics against PR5848; all inherited and new obligations retained", + "reviewer_actions": { + "scientific_runs": 0, + "compiler_runs": 0, + "external_posts": 0, + "measured_candidate_edits": 0, + "new_files": ["ROUND2-NOMINATION.md", "ROUND2-NOMINATION.json"] + }, + "inspected_local_sources": [ + {"path": "outputs/fraction-native-cache-20261027/feasibility/native_cache.c", "sha256": "78ed2e240ee40ce4989a4718e77e8b3967b092d2bf8c900124a26942c98a14cb"}, + {"path": "outputs/fraction-native-cache-20261027/feasibility/fraction_table.py", "sha256": "d70f8095002ffedb06fd6851e5b6d127e2f24c3ad31404130216345416159cf4"}, + {"path": "outputs/fraction-native-cache-20261027/feasibility/native_backend.py", "sha256": "f1fe0d4484ef86c7baa3a30c5d537950cb227b1979d825c61ab09ceead5f533d"}, + {"path": "outputs/fraction-native-cache-20261027/feasibility/slot_binding.py", "sha256": "f2f3193461b9f705a2683107c2305c40d2f82d9f1087a2af25cf9e88f45fc593"}, + {"path": "outputs/fraction-direct-add-20261027/feasibility/runtime_binding.py", "sha256": "f2e74fef881cb49101338e40e2d84600e2c9d0e717dafb46a20d7217609d4c71"}, + {"path": "outputs/fraction-direct-add-20261027/feasibility/RUNTIME-SHAPES.json", "sha256": "5a7080757fa132a2a45ad56a5e9319c938a352b1324c074cdccd9799c1aecdce"}, + {"path": "outputs/fraction-direct-add-20261027/feasibility/finite.py", "sha256": "ab1b35af378b2347dec12dfebe2562fb9c45c19a0c2b86db9077feb046563158"}, + {"path": "outputs/fraction-direct-add-20261027/SCREEN.json", "sha256": "429059e44df33949dbcd907b7a8e9df49120115ad3550076fa38a6e1b9615834"} + ], + "prior_micro_evidence": "outputs/fraction-direct-add-20261027/runtime/runs/micro-direct-add/stdout.txt", + "api_references": [ + "https://docs.python.org/3.12/c-api/call.html#c.PyObject_Vectorcall", + "https://docs.python.org/3.12/c-api/structures.html#c.PyMember_GetOne", + "https://github.com/python/cpython/blob/3.12/Objects/descrobject.c" + ], + "api_reference_boundary": "Moving documentation and branch explain APIs only; not the installed interpreter source pin" +} diff --git a/research/fraction-native-score-dispatch-feasibility/evidence/ROUND2-NOMINATION.md b/research/fraction-native-score-dispatch-feasibility/evidence/ROUND2-NOMINATION.md new file mode 100644 index 0000000000..d4ae725fbd --- /dev/null +++ b/research/fraction-native-score-dispatch-feasibility/evidence/ROUND2-NOMINATION.md @@ -0,0 +1,38 @@ +# Round 2: one bounded native direct-add nomination + +**Nominate (b), a direct call from C to the existing, authenticated Python `Fraction._add`, for finite and micro screening only.** This is a plausible incremental saving, not a measured native improvement or approval for complete construction. No arithmetic is ported. The reviewer performed only source inspection and wrote these two nomination files; no scientific run, compiler invocation, publication or measured-candidate edit occurred. + +The parent reports published PR5864 at `3f15c943e4ad6479f03e674c80fff1269a16ccfe`, green CI40480683014, and local complete medians of 32.771296680 wall / 32.74 CPU seconds versus 40.516155579 / 40.33 for the original PR5848 baseline. Those reported 19.1155% / 18.8197% savings already clear the user's 15% requirement. This round asks whether a further change pays its own complete costs against PR5864; it does not impose another 15% reduction. Publication and CI status were supplied by the parent, not independently fetched here. + +| Option | Remaining work it might remove | Decision | +| --- | --- | --- | +| (b) Existing `_add` from C | Three numeric dispatches and Python operator wrappers per coefficient update: 7,739,250 sites in the retained census. The native loop still calls `PyNumber_InPlaceAdd` at each site. | One bounded nomination. Known sites, an existing audited binding and reusable negative controls make a small net gain plausible. | +| (a) Delay `F(0)` until a destination miss | Some of the 2,579,750 eager constructor calls. The destination-hit count is not known; contribution-cache hits do not measure it. | Defer. A constructor-purity argument must cover metaclass call, initialization, allocation, setters and destruction, and explicitly delimit changed allocation/exception effects. Do not credit every constructor call or reuse the cache-hit percentage. | +| (c) `PyMember_GetOne` | Descriptor owner/audit dispatch around four member reads per coefficient update. | Defer. The public accessor accepts address/metadata; safely obtaining and retaining authenticated descriptor metadata adds full-CPython layout and lifetime obligations. Direct access must preserve applicable audit behavior and rule out wrong-owner/offset reads. No measured margin presently pays that proof. | + +The prior direct-add `SCREEN.json` remains a negative result for its old objective: the fixed Python BCCB micro gave about 0.78 seconds of illustrative gross scaling before added costs, insufficient to close the then-unmet 15% gap. That number is not transferable to the C loop. It supports only trying the bounded native screen below. + +## Exact supported boundary and implementation shape + +1. Start from PR5864's frozen native source, Linux CPython 3.12 build envelope, exact source/ABI receipt, certified input domain, qualified pure miss callback, canonical owned Fraction slots and original cache limits. Accept direct dispatch only when the prior `runtime_binding.py` executable-shape checks succeed on the live runtime. Reuse its complete authenticated function/closure/global/MRO predicates and its pure, identity-based freshness token; never substitute a source-file hash alone. Pin any copied binder and expected shapes. Authenticate ordinary raw function/static/classmethod descriptors before accessing their payloads. Require the known defaults/keyword-defaults/closure state relevant to invoked functions, the captured `__add__` monomorphic operator to be this kernel, and absence of `__iadd__` throughout the MRO, including a present `None` value. +2. Check both the inherited slot token and the addition token at each trace entry. Qualification assumes runtime metadata remains unchanged during that trace, as in the existing bounded packet contract. It does not certify concurrent or callback-driven monkey-patching during execution. Unknown code shapes, drift after derivation, foreign descriptors or unsupported inputs select the existing PR5864 checked path; its own rejection/fallback policy still applies. Qualification itself must not invoke foreign descriptors. +3. Change only the three score additions in `Event.apply`, in their existing order. With an owned optional kernel and **both operands exactly the qualified Fraction class**, call `PyObject_Vectorcall(kernel, argv, 2, NULL)`. Otherwise call the existing `PyNumber_InPlaceAdd`. The integer rounded-injection site stays untouched. Keep the original Fraction arithmetic, returned objects, contribution callback, zero construction, key, FIFO, iteration, score stores and scientific oracle. The [CPython call API](https://docs.python.org/3.12/c-api/call.html#c.PyObject_Vectorcall) supports this two-object call without constructing an argument tuple. +4. The cache must own the optional kernel reference, visit/clear it during GC, and release it on every constructor/error path. Preserve the existing strong score/result references and list-store ownership. A direct-call exception propagates immediately; **never retry it through generic addition**. The raw API defaults to generic addition, type-checks any optional function packet, and remains memory-safe for malformed inputs. A caller-supplied function is not thereby semantically certified: scientific eligibility belongs to the checked wrapper. Generic score objects retain their existing `__iadd__` behavior rather than acquiring a new exact-Fraction rejection. + +## Coverage mapping + +Retain the entire PR5864 finite chain and its full qualification/registered-verification boundaries. Execute the inherited suite once: all 964 comparisons and all 118 predecessor/native controls. Add the prior 19 dispatch controls and the new native seam obligations through an explicit coverage mapping; importing or calling the old direct-add suite must not rerun its inherited 964 comparisons. Verify the frozen manifests when assembling the union rather than treating counts as a substitute for named coverage. Preserve the original integer/reference finite programs, six source controls, reverse/literal checks, 27 Observation controls, complete receipts and the four separately registered custody controls. + +Reuse the prior direct-add arithmetic grid, dependent accumulation, live code/closure/global drift, subtraction-kernel, foreign-descriptor, MRO `__iadd__`, stale-after-derive, generic fallback and unchanged integer-injection controls. Map shared entry/table tests to the existing execution once; retain every distinct obligation. The new seam needs native controls for exact-Fraction branch selection, generic custom-score dispatch, disabled/unsupported binding, stale-before-entry fallback, direct-call exception without retry, and owned-kernel lifetime/GC. Run equivalent cases through generic and direct C branches, comparing complete values and types. Keep wrong-result detection and partial score-update/error ordering. Retain all prior native cache/iterator/mutation/callback/source-custody tests. Preserve the entire existing table-statistics dictionary, including its shape and counters. Any direct/fallback dispatch counts belong in a separate report. This mapping does not authorize silently reducing old coverage. + +## Fixed screen and economic stop + +Build an isolated feasibility copy only after the parent accepts this nomination. The smallest proposed micro contains the actual three-score C loop in two entry points: the unchanged generic loop, and the proposed guarded vectorcall loop. Both retain identical operand acquisition, strong references, list stores and error checks. Freeze sixteen exact-Fraction increment triples before timing, covering zero, signs, cancellation, common/coprime denominators and 128-bit numerators; their cycle should keep score size bounded. Verify all terminal scores and types outside timing. + +Use **32,768 coefficient groups, 98,304 additions per arm, one B,C,C,B sequence**, with fresh scores each arm and no adaptive repetition or workload selection. Include both per-add type guards in C timing. This micro isolates dispatch; it supplies no actual-word receipt and no admitted full-trace projection. Record interpreter/compiler/source hashes, both CPU and wall times, build cost and every failed result. + +Before any actual/full construction, measure the complete added union of finite controls, binding/freshness, initialization and cold compile/link/load cost against a fresh PR5864 process. Compiler-child CPU belongs in the bill. Reuse of one loaded module within a process is allowed; fresh complete processes each pay their own build. If either micro metric does not improve in both paired comparisons, or its conservative illustrative scaling to 7,739,250 sites cannot cover that measured incremental bill plus observed timing spread in **both** metrics, stop this candidate. Synthetic scaling is only a screen, never a claimed lower bound on the real trace saving. + +If that screen passes, at most one guarded actual equivalence audit is the next step. It must retain 2,579,750 calls, 2,252,966 hits, 326,784 misses, 310,400 evictions, 3,587 weight tokens and complete output/type/witness equality. Use the resulting measured actual saving and complete overhead bill to decide whether complete construction is justified. Final acceptance requires fresh complete measurements, a positive incremental saving beyond PR5864 repeat variability in both wall and total CPU after the new check/build bill, and preservation of at least 15% against PR5848. Preserve negative evidence if any gate fails; do not compensate by adding options (a) or (c) in this round. + +Primary API references checked for this nomination: [vectorcall](https://docs.python.org/3.12/c-api/call.html#c.PyObject_Vectorcall), [member metadata/accessor and flags](https://docs.python.org/3.12/c-api/structures.html#c.PyMember_GetOne), and [CPython descriptor implementation](https://github.com/python/cpython/blob/3.12/Objects/descrobject.c). These explain API behavior; the moving documentation/3.12 branch is not the installed interpreter's source pin. Local inspected-file hashes and the exact prior evidence paths are recorded in `ROUND2-NOMINATION.json`. diff --git a/research/fraction-native-score-dispatch-feasibility/evidence/ROUND2-STOP-REVIEW.json b/research/fraction-native-score-dispatch-feasibility/evidence/ROUND2-STOP-REVIEW.json new file mode 100644 index 0000000000..81629b1da4 --- /dev/null +++ b/research/fraction-native-score-dispatch-feasibility/evidence/ROUND2-STOP-REVIEW.json @@ -0,0 +1,84 @@ +{ + "status": "STOP_ROUND2_INSUFFICIENT_CONSERVATIVE_MARGIN_BEFORE_COMPLETE_CONSTRUCTION", + "date": "2026-10-27", + "decision": "Accept scoped stop; no further implementation or measurement supported in this round", + "micro_result": { + "raw_status_preserved": "MICRO_PASS_REQUIRES_FULL_INCREMENTAL_COST_BILL", + "order": ["B", "C", "C", "B"], + "groups_per_arm": 32768, + "additions_per_arm": 98304, + "prefix_comparisons": 33, + "controls": 10, + "all_reported_pass": true, + "observations": [ + {"arm": "B1", "wall_seconds": 0.08336172500276007, "cpu_seconds": 0.08278898000000001}, + {"arm": "C1", "wall_seconds": 0.06712531601078808, "cpu_seconds": 0.06712270600000003}, + {"arm": "C2", "wall_seconds": 0.06753551599103957, "cpu_seconds": 0.06753953200000001}, + {"arm": "B2", "wall_seconds": 0.06991359798121266, "cpu_seconds": 0.069917697} + ], + "wall_paired_differences": [0.016236408991971985, 0.0023780819901730865], + "cpu_paired_differences": [0.01566627399999998, 0.0023781649999999876], + "all_samples_retained": true, + "counter_boundary": "Direct arm increments per-add dispatch counters; generic returns aggregate counts. No hypothetical counter-removal saving credited.", + "plan_prose_count_note": "All32 prefix phrase differs from implemented range(33), which verifies prefixes 0 through 32." + }, + "economic_screen": { + "target_additions": 7739250, + "illustrative_gross_wall_seconds": 0.18722097821499695, + "illustrative_gross_cpu_seconds": 0.18722751338958643, + "parent_complete_wall_seconds": [32.771296680002706, 33.03183611499844, 32.57126763599808], + "parent_complete_cpu_seconds": [32.74, 32.95, 32.5], + "parent_wall_range_seconds": 0.4605684790003579, + "parent_cpu_range_seconds": 0.45, + "wall_margin_before_incremental_cost_seconds": -0.27334750078536096, + "cpu_margin_before_incremental_cost_seconds": -0.2627724866104164, + "actual_incremental_complete_bill_measured": false, + "optimistic_bill_used_for_stop_seconds": 0, + "reason": "Even zero added cost fails the conservative illustration plus observed-spread gate in both metrics; no integration is needed to reject this screen.", + "range_is_confidence_interval": false, + "illustration_bounds_true_gain": false + }, + "verified_receipt": { + "exit": 0, + "stderr_bytes": 0, + "source_bytes_and_modes_unchanged": true, + "source_inventory_sha256": "dc576d82c24a9f00d0dc87a3cec52384716f046516ca300a5f73da7e9d37ebac", + "probe_cold_build_load_wall_seconds": 0.1481919409998227, + "whole_probe_wall_seconds": 0.709715356992092, + "cost_boundary": "These are probe costs, not the unmeasured incremental complete successor bill." + }, + "coverage_boundary": "33 prefixes and ten probe controls passed; no claim that the full inherited 964/118 suite, prior19 dispatch controls or future cache-owned-kernel integration obligations have passed here", + "continuation_supported": ["preserve exact evidence", "record scoped stop and handoff"], + "continuation_not_supported_this_round": [ + "repeat or adapt timing", + "drop or replace samples", + "change the primary statistic to reverse the decision", + "credit hypothetical counter removal", + "full-control integration", + "actual-word audit", + "complete construction", + "combine deferred mechanisms without a new nomination" + ], + "claim_boundary": "Engineering stop for insufficient evidence of complete incremental margin, not a bound on true native gain or a universal optimization obstruction; PR5864 remains the accepted measured result", + "reviewer_actions": { + "compiler_runs": 0, + "numerical_experiments": 0, + "measured_file_mutations": 0, + "external_posts": 0, + "receipt_arithmetic_recomputed": true, + "written_files": ["ROUND2-STOP-REVIEW.md", "ROUND2-STOP-REVIEW.json"] + }, + "inspected_evidence": [ + {"path": "outputs/fraction-native-score-add-20261027/feasibility/score_probe.c", "sha256": "ac5d282405e74f1f8cc4cddb768485709057d249dae370a16c063ab45327c2ea"}, + {"path": "outputs/fraction-native-score-add-20261027/feasibility/micro.py", "sha256": "ad34e00ad7d0a9f192f4e3e89b1b7cc3b45d27d10063fa2dc1937e101cf60c09"}, + {"path": "outputs/fraction-native-score-add-20261027/feasibility/probe_backend.py", "sha256": "393e1a4c0a04b31eaa0bc75e0ed90686b072a05cd6ad6193eac7e99cab812e16"}, + {"path": "outputs/fraction-native-score-add-20261027/feasibility/runtime_binding.py", "sha256": "f2e74fef881cb49101338e40e2d84600e2c9d0e717dafb46a20d7217609d4c71"}, + {"path": "outputs/fraction-native-score-add-20261027/runtime/runs/micro-native-direct-add/stdout.txt", "sha256": "52212bb5f8fd5bf877b6b2bebe65346c1ef201eaec1b2b0bfd560df4263fcac7"}, + {"path": "outputs/fraction-native-score-add-20261027/runtime/runs/micro-native-direct-add/receipt.json", "sha256": "48f2a7ffdea2e2ae74833cf6d10b43bb1e9973acae4a077bbe5f8afaf33bd3b2"}, + {"path": "outputs/fraction-native-cache-20261027/runtime/runs/C1/receipt.json", "sha256": "9763ceec4da7db54fc61cb7f8440ffbccc3b9f3b291d2bce485fe309319e68ba"}, + {"path": "outputs/fraction-native-cache-20261027/runtime/runs/C2/receipt.json", "sha256": "56f0f5891a6efc138028647593e4221c63d19f3eebe161850928e0cc498a3579"}, + {"path": "outputs/fraction-native-cache-20261027/runtime/runs/C3/receipt.json", "sha256": "410eac666993518da4194bc8d97898d27b2c419aca19dc17f4fe35afc9bd30c9"}, + {"path": "outputs/fraction-15-percent-strategy-20261027/ROUND2-NOMINATION.md", "sha256": "201747b0da2dd28e84e1b35a9405142406e576b683394ecd4c1be4052fe8b4f1"}, + {"path": "outputs/fraction-15-percent-strategy-20261027/ROUND2-NOMINATION.json", "sha256": "1fc1474532777f487c0fc2d58ddc2f35acbd9c565a83fa457b7fd858b8f23d2e"} + ] +} diff --git a/research/fraction-native-score-dispatch-feasibility/evidence/ROUND2-STOP-REVIEW.md b/research/fraction-native-score-dispatch-feasibility/evidence/ROUND2-STOP-REVIEW.md new file mode 100644 index 0000000000..6aaa8a941e --- /dev/null +++ b/research/fraction-native-score-dispatch-feasibility/evidence/ROUND2-STOP-REVIEW.md @@ -0,0 +1,45 @@ +# Round 2 stopping review + +**Accept the proposed scoped STOP before full-control integration, an actual-word audit or complete construction.** The one prescribed native BCCB screen produced positive paired differences, but its conservative illustration does not clear the existing complete-run variability allowance even with zero added cost. The current evidence supports no further implementation or measurement in this round. Preserve PR5864 and retain this probe as a successful narrow semantics check with insufficient economic evidence. + +This reviewer inspected the probe source, its build loader, retained stdout/receipt, the prior written nomination, and PR5864's C1/C2/C3 receipts. No compiler or numerical experiment was run; arithmetic below was recomputed from existing receipts. Only this review and its JSON companion were written. + +## What the fixed probe established + +`micro.py` executes one B,C,C,B sequence, each arm containing 32,768 groups and 98,304 additions. The sixteen increment triples include zero, signs, cancellation, shared/coprime denominators and large integers, with fresh scores for each arm. The generic inner loop matches the retained parent C fragment's score acquisition, strong reference, numeric addition, error handling and list store. The direct loop adds exact operand-type guards and calls the existing authenticated Python kernel. Its separate dispatch counters are also incremented per addition; generic counts are calculated in aggregate. Therefore the record measures this particular instrumented probe, not an uninstrumented dispatch primitive or an integrated successor. + +The saved output reports all 33 prefix comparisons, ten controls, exact branch counts and equal terminal Fraction values/types passing. Source inspection confirms prefixes 0 through 32 are tested; `PLAN.json`'s phrase “All32 prefix” is a prose count error, not a missing prefix. The controls cover generic custom/subtype/integer behavior, direct errors without retry, partial update order, score-list mutation, invalid kernel packets and live binding drift. These are useful bounded observations. They do not execute the inherited 964-comparison/118-control suite, all 19 prior dispatch controls or future cache-owned-kernel lifetime/GC integration. No complete scientific or performance admission follows. + +The receipt records exit 0, no stderr, unchanged source bytes/modes and the source hash used for the cold build. The copied `runtime_binding.py` hash matches the previously reviewed binder. All four samples remain in the decision: + +| Arm | Wall seconds | CPU seconds | +| --- | ---: | ---: | +| B1 | 0.083361725003 | 0.082788980000 | +| C1 | 0.067125316011 | 0.067122706000 | +| C2 | 0.067535515991 | 0.067539532000 | +| B2 | 0.069913597981 | 0.069917697000 | + +The matched differences are B1−C1 and B2−C2. Both are positive in both metrics, but their sizes differ substantially. The record does not establish why B1 and B2 differ. No sample is declared an outlier, dropped, replaced or assigned a causal explanation. + +## Why stopping follows the written gate + +The nomination requires conservative illustrative scaling to cover the incremental complete bill **plus observed spread** before any actual/full construction. Scaling the smaller paired difference by `7,739,250 / 98,304` gives the following screen; this is arithmetic on the retained data, not an actual-trace prediction: + +| Decision quantity | Wall seconds | CPU seconds | +| --- | ---: | ---: | +| Smaller micro paired difference | 0.002378081990 | 0.002378165000 | +| Illustrative gross saving at retained site count | 0.187220978215 | 0.187227513390 | +| Frozen PR5864 complete C range | 0.460568479000 | 0.450000000000 | +| Illustration minus range, before new costs | **−0.273347500785** | **−0.262772486610** | + +The complete comparison range is verified directly from PR5864 C1/C2/C3 receipts: wall 32.771296680003, 33.031836114998 and 32.571267635998 seconds; total user+system CPU 32.74, 32.95 and 32.50 seconds. These use the same recorded interpreter, platform and runner as the probe. Their max-minus-min range is an observed engineering allowance from three retained complete runs. It is neither a confidence interval nor a lower bound on future noise or on any optimization's true gain. + +The actual new validation/binding/build bill has not been measured. That missing bill does not require integrating a successor: assigning it the optimistic value zero already fails the chosen margin screen in both metrics. There is no established offsetting reduction in validation or build work to credit. Conversely, the probe's 0.148191941-second cold-build/load time must not be substituted for the unknown *incremental* complete build bill; its 0.709715357-second whole-command duration is research-screen cost, not a successor qualification time. + +`MICRO_PASS_REQUIRES_FULL_INCREMENTAL_COST_BILL` in stdout records the script's narrower test that both micro pairs improved. The proposed STOP is the subsequent review against the full nominated screen. Preserve the raw status and receipt; add the scoped decision without rewriting that evidence. + +## Remaining action and claim boundary + +No additional timing permutation, longer/adaptive micro, sample removal, change to the primary statistic, speculative counter-removal credit, full suite integration or actual/full run is justified by this record. The earlier rejected options (a) and (c) acquire no new cost evidence from this probe, and combining them would be a separate mechanism requiring a new nomination. Complete only the durable stop/checkpoint and handoff already within the parent's scope. + +This is **insufficient conservative margin under a fixed engineering screen**. It does not prove that direct native score dispatch is slower, that its true gain is below 0.187 seconds, that no other workload benefits, or that further optimization is impossible. The measured PR5864 implementation and its previously established cumulative 15% threshold remain the accepted result; this round adds no new complete improvement claim. diff --git a/research/fraction-native-score-dispatch-feasibility/evidence/VERIFY-ISOLATED-FUNCTION-DRAFT.py.txt b/research/fraction-native-score-dispatch-feasibility/evidence/VERIFY-ISOLATED-FUNCTION-DRAFT.py.txt new file mode 100644 index 0000000000..783228bd9f --- /dev/null +++ b/research/fraction-native-score-dispatch-feasibility/evidence/VERIFY-ISOLATED-FUNCTION-DRAFT.py.txt @@ -0,0 +1,39 @@ +"""Replay all probe correctness controls without repeating its timing trial.""" +from hashlib import sha256 +import inspect,json,tarfile +from pathlib import Path +import micro +from table_parent import code_shape + +HERE=Path(__file__).resolve().parent +ARCHIVE='7b142567acacac5182045bf8daa8780e916661c2cf343dbf81b13c88ead85d64' + +def need(ok,message): + if not ok:raise ValueError(message) + +def main(): + archive=HERE/'inputs/PR5864.tar' + need(sha256(archive.read_bytes()).hexdigest()==ARCHIVE,'exact complete PR5864 export') + with tarfile.open(archive,'r:') as stream: + receipt=json.loads(stream.extractfile('.research-export.json').read()) + need(receipt['commit']=='3f15c943e4ad6479f03e674c80fff1269a16ccfe' and len(receipt['files'])==163,'exact parent source head/census') + native=stream.extractfile('research/fraction-native-qualification/native_cache.c').read() + need(native==(HERE/'native_parent.c').read_bytes(),'exact parent native C bytes') + start=native.index(b' for(int k=0;k<3;k++){',native.index(b'static PyObject *event_apply')) + end=native.index(b' int truth=',start) + need(native[start:end]==(HERE/'PARENT-SCORE-LOOP.txt').read_bytes(),'exact retained parent score loop') + raw=inspect.getsource(micro.main) + need(sha256(raw.encode()).hexdigest()==json.loads((HERE/'FINITE-SOURCE.json').read_text())['function_sha256'],'exact measured probe source') + namespace=dict(micro.__dict__);exec(compile(raw,'','exec'),namespace) + need(code_shape(namespace['main'].__code__)==code_shape(micro.main.__code__),'live probe executable agrees') + seam=' observations=[];groups=32768\n' + need(raw.count(seam)==1,'unique boundary after all ten correctness controls') + finite=raw[:raw.index(seam)]+''' result=dict(prefix_cases=33,controls=controls,control_count=len(controls),runtime_current=binding.still_current(token)) + print(json.dumps(dict(status='PASS_NATIVE_SCORE_FINITE_ONLY',result=result,build=probe_backend.receipt()),sort_keys=True)) + return result +''' + exec(compile(finite,'','exec'),namespace) + need(namespace['main']()==json.loads((HERE/'RESULT.json').read_text()),'all retained finite probe controls') + print('PASS_NATIVE_SCORE_DISPATCH_FEASIBILITY_FINITE_ONLY') + +if __name__=='__main__':main() diff --git a/research/fraction-native-score-dispatch-feasibility/evidence/parent-complete/C1/receipt.json b/research/fraction-native-score-dispatch-feasibility/evidence/parent-complete/C1/receipt.json new file mode 100644 index 0000000000..d61dc4261f --- /dev/null +++ b/research/fraction-native-score-dispatch-feasibility/evidence/parent-complete/C1/receipt.json @@ -0,0 +1,26 @@ +{ + "exit": 0, + "label": "C1", + "optimized": false, + "platform": "Linux-7.0.0-38-generic-x86_64-with-glibc2.39", + "python": "3.12.3 (main, Aug 31 2026, 10:18:26) [GCC 13.3.0]", + "runner_sha256": "7540f8cc4ae4d12ed86c844ef0837a74184d3ada653979608c295c09f200a751", + "runtime_policy_sha256": "f2fb57d260620346ad1100e4afb6e15e754460e3a086a54802c976fab2fc1552", + "sampled_process_group_rss_bytes": 115896320, + "script": "full_C.py", + "source_bytes_and_modes_unchanged": true, + "source_inventory_sha256": "94948995f7ffb81a2215df2828296156bd0e579a5d15fe2e998f72ca1ab94674", + "status": "PASS", + "stderr_bytes": 0, + "stderr_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "stdout_bytes": 14103, + "stdout_sha256": "94b8b578bdc812bf9c3a12e80bf2f00978000c6cc47119a180d4d003a1d0c20f", + "termination": null, + "usage": { + "exit": 0, + "kernel_max_rss_kib": 111728, + "system_seconds": 0.2, + "user_seconds": 32.54 + }, + "wall_seconds": 32.771296680002706 +} diff --git a/research/fraction-native-score-dispatch-feasibility/evidence/parent-complete/C2/receipt.json b/research/fraction-native-score-dispatch-feasibility/evidence/parent-complete/C2/receipt.json new file mode 100644 index 0000000000..f8e6215401 --- /dev/null +++ b/research/fraction-native-score-dispatch-feasibility/evidence/parent-complete/C2/receipt.json @@ -0,0 +1,26 @@ +{ + "exit": 0, + "label": "C2", + "optimized": false, + "platform": "Linux-7.0.0-38-generic-x86_64-with-glibc2.39", + "python": "3.12.3 (main, Aug 31 2026, 10:18:26) [GCC 13.3.0]", + "runner_sha256": "7540f8cc4ae4d12ed86c844ef0837a74184d3ada653979608c295c09f200a751", + "runtime_policy_sha256": "f2fb57d260620346ad1100e4afb6e15e754460e3a086a54802c976fab2fc1552", + "sampled_process_group_rss_bytes": 116826112, + "script": "full_C.py", + "source_bytes_and_modes_unchanged": true, + "source_inventory_sha256": "94948995f7ffb81a2215df2828296156bd0e579a5d15fe2e998f72ca1ab94674", + "status": "PASS", + "stderr_bytes": 0, + "stderr_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "stdout_bytes": 14105, + "stdout_sha256": "e5fae97b197190e7942f4af65ae80fdb7d8e57617640bdd268bb2774b2518e7c", + "termination": null, + "usage": { + "exit": 0, + "kernel_max_rss_kib": 112636, + "system_seconds": 0.2, + "user_seconds": 32.75 + }, + "wall_seconds": 33.03183611499844 +} diff --git a/research/fraction-native-score-dispatch-feasibility/evidence/parent-complete/C3/receipt.json b/research/fraction-native-score-dispatch-feasibility/evidence/parent-complete/C3/receipt.json new file mode 100644 index 0000000000..8225ad0284 --- /dev/null +++ b/research/fraction-native-score-dispatch-feasibility/evidence/parent-complete/C3/receipt.json @@ -0,0 +1,26 @@ +{ + "exit": 0, + "label": "C3", + "optimized": false, + "platform": "Linux-7.0.0-38-generic-x86_64-with-glibc2.39", + "python": "3.12.3 (main, Aug 31 2026, 10:18:26) [GCC 13.3.0]", + "runner_sha256": "7540f8cc4ae4d12ed86c844ef0837a74184d3ada653979608c295c09f200a751", + "runtime_policy_sha256": "f2fb57d260620346ad1100e4afb6e15e754460e3a086a54802c976fab2fc1552", + "sampled_process_group_rss_bytes": 115761152, + "script": "full_C.py", + "source_bytes_and_modes_unchanged": true, + "source_inventory_sha256": "94948995f7ffb81a2215df2828296156bd0e579a5d15fe2e998f72ca1ab94674", + "status": "PASS", + "stderr_bytes": 0, + "stderr_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "stdout_bytes": 14101, + "stdout_sha256": "56dc7baee49bc0aceabc9589593de191e31874345f83579664757ba96e40a193", + "termination": null, + "usage": { + "exit": 0, + "kernel_max_rss_kib": 111596, + "system_seconds": 0.19, + "user_seconds": 32.31 + }, + "wall_seconds": 32.57126763599808 +} diff --git a/research/fraction-native-score-dispatch-feasibility/evidence/runtime/dispatch.py b/research/fraction-native-score-dispatch-feasibility/evidence/runtime/dispatch.py new file mode 100644 index 0000000000..8fe0e66a6a --- /dev/null +++ b/research/fraction-native-score-dispatch-feasibility/evidence/runtime/dispatch.py @@ -0,0 +1,8 @@ +import sys +import guard +guard.SOURCE=guard.HERE.parent/'feasibility' +guard.CLOSURE=tuple(sorted(str(p.relative_to(guard.SOURCE)) for p in guard.SOURCE.rglob('*') if p.is_file() and '__pycache__' not in p.parts))+('/usr/lib/python3.12/fractions.py',) +label=sys.argv[1] +with (guard.HERE/'execution.lock').open('a') as lock: + guard.fcntl.flock(lock,guard.fcntl.LOCK_EX|guard.fcntl.LOCK_NB) + guard.run(label,'micro.py',optimized=label.endswith('-O')) diff --git a/research/fraction-native-score-dispatch-feasibility/evidence/runtime/guard.py b/research/fraction-native-score-dispatch-feasibility/evidence/runtime/guard.py new file mode 100644 index 0000000000..bf4265b129 --- /dev/null +++ b/research/fraction-native-score-dispatch-feasibility/evidence/runtime/guard.py @@ -0,0 +1,120 @@ +"""Serial bounded Linux measurements; preserve the complete frozen precision contract.""" +import argparse +import fcntl +import hashlib +import json +import os +from pathlib import Path +import platform +import signal +import statistics +import subprocess +import sys +import tempfile +import time + +HERE = Path(__file__).resolve().parent +SOURCE = HERE +CLOSURE = ('frozen.py','primitive_profile.py','guard.py','dispatch.py','inputs/PR5848.tar','../feasibility/fraction_table.py','../feasibility/finite.py','/usr/lib/python3.12/fractions.py','../feasibility/actual_audit.py') +TIMEOUT = 180 +RSS_CAP = 1024**3 +OUTPUT_CAP = 2*1024**2 +AGGREGATE = 600 +PREVIOUS_WALL_SECONDS = 0 + +def sha(raw): + return hashlib.sha256(raw).hexdigest() + +def inventory(): + result = {} + for name in CLOSURE: + path = SOURCE / name + if path.is_symlink() or not path.is_file(): + raise ValueError('Regular complete runtime file: ' + name) + result[name] = [sha(path.read_bytes()), path.stat().st_mode & 0o777] + return result + +def group_rss(group): + total = 0 + count = 0 + for p in Path('/proc').iterdir(): + if not p.name.isdigit(): + continue + try: + raw = (p/'stat').read_text() + fields = raw[raw.rfind(')')+2:].split() + if int(fields[2]) == group: + total += int(fields[21])*os.sysconf('SC_PAGE_SIZE') + count += 1 + except (FileNotFoundError, ProcessLookupError, PermissionError): + pass + return total, count + +def run(label, script, optimized=False): + records = HERE/'runs' + records.mkdir(exist_ok=True) + prior = list(records.glob('*/receipt.json')) + spent = PREVIOUS_WALL_SECONDS + sum(json.loads(p.read_bytes())['wall_seconds'] for p in prior) + if spent >= AGGREGATE: + raise ValueError('Aggregate budget consumed') + folder = records/label + folder.mkdir() + before = inventory() + env = os.environ.copy() + for key in ('PYTHONPATH','PYTHONOPTIMIZE','PYTHONINSPECT','PYTHONSTARTUP','PYTHONPYCACHEPREFIX'): + env.pop(key,None) + env.update(PYTHONHASHSEED='0', LC_ALL='C.UTF-8', TZ='UTC') + usage = folder/'usage.json' + with tempfile.TemporaryDirectory(prefix='linux5757-bytecode-') as cache: + command = ['/usr/bin/python3.12', '-B', '-X', 'pycache_prefix='+cache] + if optimized: + command.append('-O') + command.append(str(SOURCE/script)) + timed = ['/usr/bin/time','-f','{"user_seconds":%U,"system_seconds":%S,"kernel_max_rss_kib":%M,"exit":%x}', '-o', str(usage),'--',*command] + start = time.monotonic() + peak = 0 + stop = None + with (folder/'stdout.txt').open('wb') as out, (folder/'stderr.txt').open('wb') as err: + p = subprocess.Popen(timed, cwd=SOURCE, env=env, stdout=out, stderr=err, start_new_session=True) + try: + while p.poll() is None: + rss, _ = group_rss(p.pid) + peak = max(peak,rss) + elapsed = time.monotonic()-start + if rss > RSS_CAP: + stop='sampled_group_rss_cap' + elif elapsed > min(TIMEOUT,AGGREGATE-spent): + stop='wall_or_aggregate_cap' + elif max((folder/'stdout.txt').stat().st_size,(folder/'stderr.txt').stat().st_size)>OUTPUT_CAP: + stop='output_cap' + if stop: + os.killpg(p.pid,signal.SIGKILL) + break + time.sleep(0.05) + code=p.wait() + finally: + try: os.killpg(p.pid,signal.SIGKILL) + except ProcessLookupError: pass + p.wait() + elapsed = time.monotonic()-start + stdout=(folder/'stdout.txt').read_bytes() + stderr=(folder/'stderr.txt').read_bytes() + after=inventory() + measurement=None + if usage.exists(): + try: measurement=json.loads(usage.read_bytes()) + except json.JSONDecodeError: measurement={'raw':usage.read_text()} + receipt={'label':label,'script':script,'optimized':optimized,'wall_seconds':elapsed, + 'exit':code,'termination':stop,'sampled_process_group_rss_bytes':peak, + 'usage':measurement,'stdout_sha256':sha(stdout),'stdout_bytes':len(stdout), + 'stderr_sha256':sha(stderr),'stderr_bytes':len(stderr), + 'source_inventory_sha256':sha(json.dumps(before,sort_keys=True,separators=(',',':')).encode()), + 'source_bytes_and_modes_unchanged':before==after, + 'python':sys.version,'platform':platform.platform(), + 'runner_sha256':sha(Path(__file__).read_bytes()),'runtime_policy_sha256':sha(json.dumps(CLOSURE).encode())} + receipt['status']='PASS' if code==0 and stop is None and not stderr and before==after else 'STOP' + (folder/'receipt.json').write_text(json.dumps(receipt,indent=2,sort_keys=True)+'\n') + print(json.dumps(receipt,sort_keys=True),flush=True) + if receipt['status']!='PASS': + raise SystemExit(1) + return receipt diff --git a/research/fraction-native-score-dispatch-feasibility/evidence/runtime/runs/micro-native-direct-add/receipt.json b/research/fraction-native-score-dispatch-feasibility/evidence/runtime/runs/micro-native-direct-add/receipt.json new file mode 100644 index 0000000000..208f0a3511 --- /dev/null +++ b/research/fraction-native-score-dispatch-feasibility/evidence/runtime/runs/micro-native-direct-add/receipt.json @@ -0,0 +1,26 @@ +{ + "exit": 0, + "label": "micro-native-direct-add", + "optimized": false, + "platform": "Linux-7.0.0-38-generic-x86_64-with-glibc2.39", + "python": "3.12.3 (main, Aug 31 2026, 10:18:26) [GCC 13.3.0]", + "runner_sha256": "7540f8cc4ae4d12ed86c844ef0837a74184d3ada653979608c295c09f200a751", + "runtime_policy_sha256": "8fff40be6fffa046e5c02013b2814d94f908dd50ea5cf9f508f4921220de04e2", + "sampled_process_group_rss_bytes": 67977216, + "script": "micro.py", + "source_bytes_and_modes_unchanged": true, + "source_inventory_sha256": "dc576d82c24a9f00d0dc87a3cec52384716f046516ca300a5f73da7e9d37ebac", + "status": "PASS", + "stderr_bytes": 0, + "stderr_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "stdout_bytes": 2876, + "stdout_sha256": "52212bb5f8fd5bf877b6b2bebe65346c1ef201eaec1b2b0bfd560df4263fcac7", + "termination": null, + "usage": { + "exit": 0, + "kernel_max_rss_kib": 39016, + "system_seconds": 0.03, + "user_seconds": 0.66 + }, + "wall_seconds": 0.709715356992092 +} diff --git a/research/fraction-native-score-dispatch-feasibility/evidence/runtime/runs/micro-native-direct-add/stderr.txt b/research/fraction-native-score-dispatch-feasibility/evidence/runtime/runs/micro-native-direct-add/stderr.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/research/fraction-native-score-dispatch-feasibility/evidence/runtime/runs/micro-native-direct-add/stdout.txt b/research/fraction-native-score-dispatch-feasibility/evidence/runtime/runs/micro-native-direct-add/stdout.txt new file mode 100644 index 0000000000..0420ce1a13 --- /dev/null +++ b/research/fraction-native-score-dispatch-feasibility/evidence/runtime/runs/micro-native-direct-add/stdout.txt @@ -0,0 +1,5 @@ +{"observation": {"counts": [0, 98304], "cpu_seconds": 0.08278898000000001, "label": "B", "terminal_scores": ["2/3", "-5/7", "11/13"], "wall_seconds": 0.08336172500276007}} +{"observation": {"counts": [98304, 0], "cpu_seconds": 0.06712270600000003, "label": "C", "terminal_scores": ["2/3", "-5/7", "11/13"], "wall_seconds": 0.06712531601078808}} +{"observation": {"counts": [98304, 0], "cpu_seconds": 0.06753953200000001, "label": "C", "terminal_scores": ["2/3", "-5/7", "11/13"], "wall_seconds": 0.06753551599103957}} +{"observation": {"counts": [0, 98304], "cpu_seconds": 0.069917697, "label": "B", "terminal_scores": ["2/3", "-5/7", "11/13"], "wall_seconds": 0.06991359798121266}} +{"additions_per_arm": 98304, "build": {"SOABI": "cpython-312-x86_64-linux-gnu", "binary_sha256": "2539108f782328dcf75f477e6fa085235fa42a327743c97c1c16a4397c67ec95", "cold_build_load_wall_seconds": 0.1481919409998227, "compiler": "/usr/bin/cc", "compiler_cpu_accounting": "outer GNU time user+system includes compiler children", "compiler_version": "cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0", "extension_suffix": ".cpython-312-x86_64-linux-gnu.so", "flags": ["-O2", "-shared", "-fPIC", "-std=c11", "-Wall", "-Werror", "-I/usr/include/python3.12"], "python": "3.12.3 (main, Aug 31 2026, 10:18:26) [GCC 13.3.0]", "source_sha256": "ac5d282405e74f1f8cc4cddb768485709057d249dae370a16c063ab45327c2ea"}, "control_count": 10, "controls": ["all-33-prefix-values-types-and-branches", "nonexact-custom-score-generic-iadd", "Fraction-subtype-generic-iadd", "nonexact-increment-generic", "direct-error-no-retry-partial-update-order", "callback-score-list-mutation-safe", "nonfunction-kernel-packet-rejected", "kernel-binding-drift", "present-none-iadd-drift", "runtime-restored-before-timing"], "fixed_order": "BCCB", "groups_per_arm": 32768, "illustrative_gross_only": {"cpu_seconds": 0.18722751338958643, "wall_seconds": 0.18722097821499695}, "no_actual_or_complete_construction": true, "not_a_full_trace_projection_or_improvement": true, "observations": [{"counts": [0, 98304], "cpu_seconds": 0.08278898000000001, "label": "B", "terminal_scores": ["2/3", "-5/7", "11/13"], "wall_seconds": 0.08336172500276007}, {"counts": [98304, 0], "cpu_seconds": 0.06712270600000003, "label": "C", "terminal_scores": ["2/3", "-5/7", "11/13"], "wall_seconds": 0.06712531601078808}, {"counts": [98304, 0], "cpu_seconds": 0.06753953200000001, "label": "C", "terminal_scores": ["2/3", "-5/7", "11/13"], "wall_seconds": 0.06753551599103957}, {"counts": [0, 98304], "cpu_seconds": 0.069917697, "label": "B", "terminal_scores": ["2/3", "-5/7", "11/13"], "wall_seconds": 0.06991359798121266}], "paired_differences": {"cpu_seconds": [0.01566627399999998, 0.0023781649999999876], "wall_seconds": [0.016236408991971985, 0.0023780819901730865]}, "runtime_current": true, "status": "MICRO_PASS_REQUIRES_FULL_INCREMENTAL_COST_BILL"} diff --git a/research/fraction-native-score-dispatch-feasibility/evidence/runtime/runs/micro-native-direct-add/usage.json b/research/fraction-native-score-dispatch-feasibility/evidence/runtime/runs/micro-native-direct-add/usage.json new file mode 100644 index 0000000000..a5dd5b0ea0 --- /dev/null +++ b/research/fraction-native-score-dispatch-feasibility/evidence/runtime/runs/micro-native-direct-add/usage.json @@ -0,0 +1 @@ +{"user_seconds":0.66,"system_seconds":0.03,"kernel_max_rss_kib":39016,"exit":0} diff --git a/research/fraction-native-score-dispatch-feasibility/evidence/runtime/runs/packaged-score-context-finite-O/receipt.json b/research/fraction-native-score-dispatch-feasibility/evidence/runtime/runs/packaged-score-context-finite-O/receipt.json new file mode 100644 index 0000000000..3c6f3c6c78 --- /dev/null +++ b/research/fraction-native-score-dispatch-feasibility/evidence/runtime/runs/packaged-score-context-finite-O/receipt.json @@ -0,0 +1,26 @@ +{ + "exit": 0, + "label": "packaged-score-context-finite-O", + "optimized": true, + "platform": "Linux-7.0.0-38-generic-x86_64-with-glibc2.39", + "python": "3.12.3 (main, Aug 31 2026, 10:18:26) [GCC 13.3.0]", + "runner_sha256": "7540f8cc4ae4d12ed86c844ef0837a74184d3ada653979608c295c09f200a751", + "runtime_policy_sha256": "0502dc3118fa0c2b07578a404103cb78b6d220742c90f12fbe16c1cb23d8bb08", + "sampled_process_group_rss_bytes": 61353984, + "script": "verify.py", + "source_bytes_and_modes_unchanged": true, + "source_inventory_sha256": "fff4792a2c0bc7fd25a10356952c632a706057d854697260a2139dd7e3db594c", + "status": "PASS", + "stderr_bytes": 0, + "stderr_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "stdout_bytes": 1207, + "stdout_sha256": "b5ed16eb98db0e719f138edd145ac4471f20b4233baeb0bbab33d9c32f6e1e02", + "termination": null, + "usage": { + "exit": 0, + "kernel_max_rss_kib": 39148, + "system_seconds": 0.03, + "user_seconds": 0.45 + }, + "wall_seconds": 0.5075639769784175 +} diff --git a/research/fraction-native-score-dispatch-feasibility/evidence/runtime/runs/packaged-score-context-finite-O/stderr.txt b/research/fraction-native-score-dispatch-feasibility/evidence/runtime/runs/packaged-score-context-finite-O/stderr.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/research/fraction-native-score-dispatch-feasibility/evidence/runtime/runs/packaged-score-context-finite-O/stdout.txt b/research/fraction-native-score-dispatch-feasibility/evidence/runtime/runs/packaged-score-context-finite-O/stdout.txt new file mode 100644 index 0000000000..4722ec7a33 --- /dev/null +++ b/research/fraction-native-score-dispatch-feasibility/evidence/runtime/runs/packaged-score-context-finite-O/stdout.txt @@ -0,0 +1,2 @@ +{"build": {"SOABI": "cpython-312-x86_64-linux-gnu", "binary_sha256": "beb396ef0a98bcf77ead29ef83f20c30e2a3feaafc11414a27e80edaa241b501", "cold_build_load_wall_seconds": 0.15812393999658525, "compiler": "/usr/bin/cc", "compiler_cpu_accounting": "outer GNU time user+system includes compiler children", "compiler_version": "cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0", "extension_suffix": ".cpython-312-x86_64-linux-gnu.so", "flags": ["-O2", "-shared", "-fPIC", "-std=c11", "-Wall", "-Werror", "-I/usr/include/python3.12"], "python": "3.12.3 (main, Aug 31 2026, 10:18:26) [GCC 13.3.0]", "source_sha256": "ac5d282405e74f1f8cc4cddb768485709057d249dae370a16c063ab45327c2ea"}, "result": {"control_count": 10, "controls": ["all-33-prefix-values-types-and-branches", "nonexact-custom-score-generic-iadd", "Fraction-subtype-generic-iadd", "nonexact-increment-generic", "direct-error-no-retry-partial-update-order", "callback-score-list-mutation-safe", "nonfunction-kernel-packet-rejected", "kernel-binding-drift", "present-none-iadd-drift", "runtime-restored-before-timing"], "prefix_cases": 33, "runtime_current": true}, "status": "PASS_NATIVE_SCORE_FINITE_ONLY"} +PASS_NATIVE_SCORE_DISPATCH_FEASIBILITY_FINITE_ONLY diff --git a/research/fraction-native-score-dispatch-feasibility/evidence/runtime/runs/packaged-score-context-finite-O/usage.json b/research/fraction-native-score-dispatch-feasibility/evidence/runtime/runs/packaged-score-context-finite-O/usage.json new file mode 100644 index 0000000000..917afd59df --- /dev/null +++ b/research/fraction-native-score-dispatch-feasibility/evidence/runtime/runs/packaged-score-context-finite-O/usage.json @@ -0,0 +1 @@ +{"user_seconds":0.45,"system_seconds":0.03,"kernel_max_rss_kib":39148,"exit":0} diff --git a/research/fraction-native-score-dispatch-feasibility/evidence/runtime/runs/packaged-score-context-finite/receipt.json b/research/fraction-native-score-dispatch-feasibility/evidence/runtime/runs/packaged-score-context-finite/receipt.json new file mode 100644 index 0000000000..0c7f622dd4 --- /dev/null +++ b/research/fraction-native-score-dispatch-feasibility/evidence/runtime/runs/packaged-score-context-finite/receipt.json @@ -0,0 +1,26 @@ +{ + "exit": 0, + "label": "packaged-score-context-finite", + "optimized": false, + "platform": "Linux-7.0.0-38-generic-x86_64-with-glibc2.39", + "python": "3.12.3 (main, Aug 31 2026, 10:18:26) [GCC 13.3.0]", + "runner_sha256": "7540f8cc4ae4d12ed86c844ef0837a74184d3ada653979608c295c09f200a751", + "runtime_policy_sha256": "0502dc3118fa0c2b07578a404103cb78b6d220742c90f12fbe16c1cb23d8bb08", + "sampled_process_group_rss_bytes": 66867200, + "script": "verify.py", + "source_bytes_and_modes_unchanged": true, + "source_inventory_sha256": "fff4792a2c0bc7fd25a10356952c632a706057d854697260a2139dd7e3db594c", + "status": "PASS", + "stderr_bytes": 0, + "stderr_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "stdout_bytes": 1207, + "stdout_sha256": "1c65c41e04290db8e081ae7ef7264a051321555eb0079a809b1e25c4488e57e8", + "termination": null, + "usage": { + "exit": 0, + "kernel_max_rss_kib": 38952, + "system_seconds": 0.03, + "user_seconds": 0.43 + }, + "wall_seconds": 0.506363077001879 +} diff --git a/research/fraction-native-score-dispatch-feasibility/evidence/runtime/runs/packaged-score-context-finite/stderr.txt b/research/fraction-native-score-dispatch-feasibility/evidence/runtime/runs/packaged-score-context-finite/stderr.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/research/fraction-native-score-dispatch-feasibility/evidence/runtime/runs/packaged-score-context-finite/stdout.txt b/research/fraction-native-score-dispatch-feasibility/evidence/runtime/runs/packaged-score-context-finite/stdout.txt new file mode 100644 index 0000000000..bc0eb3ac6a --- /dev/null +++ b/research/fraction-native-score-dispatch-feasibility/evidence/runtime/runs/packaged-score-context-finite/stdout.txt @@ -0,0 +1,2 @@ +{"build": {"SOABI": "cpython-312-x86_64-linux-gnu", "binary_sha256": "1e5eafdcdf9e62bcdd2b52164447b04eba8feac4e8df3ff5dfc27aaa5b36aa9f", "cold_build_load_wall_seconds": 0.14683370498823933, "compiler": "/usr/bin/cc", "compiler_cpu_accounting": "outer GNU time user+system includes compiler children", "compiler_version": "cc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0", "extension_suffix": ".cpython-312-x86_64-linux-gnu.so", "flags": ["-O2", "-shared", "-fPIC", "-std=c11", "-Wall", "-Werror", "-I/usr/include/python3.12"], "python": "3.12.3 (main, Aug 31 2026, 10:18:26) [GCC 13.3.0]", "source_sha256": "ac5d282405e74f1f8cc4cddb768485709057d249dae370a16c063ab45327c2ea"}, "result": {"control_count": 10, "controls": ["all-33-prefix-values-types-and-branches", "nonexact-custom-score-generic-iadd", "Fraction-subtype-generic-iadd", "nonexact-increment-generic", "direct-error-no-retry-partial-update-order", "callback-score-list-mutation-safe", "nonfunction-kernel-packet-rejected", "kernel-binding-drift", "present-none-iadd-drift", "runtime-restored-before-timing"], "prefix_cases": 33, "runtime_current": true}, "status": "PASS_NATIVE_SCORE_FINITE_ONLY"} +PASS_NATIVE_SCORE_DISPATCH_FEASIBILITY_FINITE_ONLY diff --git a/research/fraction-native-score-dispatch-feasibility/evidence/runtime/runs/packaged-score-context-finite/usage.json b/research/fraction-native-score-dispatch-feasibility/evidence/runtime/runs/packaged-score-context-finite/usage.json new file mode 100644 index 0000000000..40381f4311 --- /dev/null +++ b/research/fraction-native-score-dispatch-feasibility/evidence/runtime/runs/packaged-score-context-finite/usage.json @@ -0,0 +1 @@ +{"user_seconds":0.43,"system_seconds":0.03,"kernel_max_rss_kib":38952,"exit":0} diff --git a/research/fraction-native-score-dispatch-feasibility/evidence/runtime/runs/packaged-score-finite/receipt.json b/research/fraction-native-score-dispatch-feasibility/evidence/runtime/runs/packaged-score-finite/receipt.json new file mode 100644 index 0000000000..c00588eba2 --- /dev/null +++ b/research/fraction-native-score-dispatch-feasibility/evidence/runtime/runs/packaged-score-finite/receipt.json @@ -0,0 +1,23 @@ +{ + "exit": 1, + "label": "packaged-score-finite", + "optimized": false, + "platform": "Linux-7.0.0-38-generic-x86_64-with-glibc2.39", + "python": "3.12.3 (main, Aug 31 2026, 10:18:26) [GCC 13.3.0]", + "runner_sha256": "7540f8cc4ae4d12ed86c844ef0837a74184d3ada653979608c295c09f200a751", + "runtime_policy_sha256": "56a1e4ef0cd9759999e0eecc628508eeb15021e741d2b26bfd68783e7611e2a5", + "sampled_process_group_rss_bytes": 40845312, + "script": "verify.py", + "source_bytes_and_modes_unchanged": true, + "source_inventory_sha256": "f463b09fdc3d50ae5508abae49b21bf0bbcea8e926f9544c05b37d0b3b2ced00", + "status": "STOP", + "stderr_bytes": 973, + "stderr_sha256": "e539dc6be197126ec6d5fd9e33340a073435e861870346a2da8b93ff6c5ca632", + "stdout_bytes": 0, + "stdout_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "termination": null, + "usage": { + "raw": "Command exited with non-zero status 1\n{\"user_seconds\":0.62,\"system_seconds\":0.02,\"kernel_max_rss_kib\":38888,\"exit\":1}\n" + }, + "wall_seconds": 0.6589367970009334 +} diff --git a/research/fraction-native-score-dispatch-feasibility/evidence/runtime/runs/packaged-score-finite/stderr.txt b/research/fraction-native-score-dispatch-feasibility/evidence/runtime/runs/packaged-score-finite/stderr.txt new file mode 100644 index 0000000000..7f60802d03 --- /dev/null +++ b/research/fraction-native-score-dispatch-feasibility/evidence/runtime/runs/packaged-score-finite/stderr.txt @@ -0,0 +1,10 @@ +Traceback (most recent call last): + File "/home/d3lerium/.codex/.chatgpt-projects/g-p-6ad5817fd84881918865926b6fd51453/outputs/fraction-native-cache-20261027/repo/research/fraction-native-score-dispatch-feasibility/verify.py", line 39, in + if __name__=='__main__':main() + ^^^^^^ + File "/home/d3lerium/.codex/.chatgpt-projects/g-p-6ad5817fd84881918865926b6fd51453/outputs/fraction-native-cache-20261027/repo/research/fraction-native-score-dispatch-feasibility/verify.py", line 28, in main + need(code_shape(namespace['main'].__code__)==code_shape(micro.main.__code__),'live probe executable agrees') + File "/home/d3lerium/.codex/.chatgpt-projects/g-p-6ad5817fd84881918865926b6fd51453/outputs/fraction-native-cache-20261027/repo/research/fraction-native-score-dispatch-feasibility/verify.py", line 12, in need + if not ok:raise ValueError(message) + ^^^^^^^^^^^^^^^^^^^^^^^^^ +ValueError: live probe executable agrees diff --git a/research/fraction-native-score-dispatch-feasibility/evidence/runtime/runs/packaged-score-finite/stdout.txt b/research/fraction-native-score-dispatch-feasibility/evidence/runtime/runs/packaged-score-finite/stdout.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/research/fraction-native-score-dispatch-feasibility/evidence/runtime/runs/packaged-score-finite/usage.json b/research/fraction-native-score-dispatch-feasibility/evidence/runtime/runs/packaged-score-finite/usage.json new file mode 100644 index 0000000000..96f745fc5c --- /dev/null +++ b/research/fraction-native-score-dispatch-feasibility/evidence/runtime/runs/packaged-score-finite/usage.json @@ -0,0 +1,2 @@ +Command exited with non-zero status 1 +{"user_seconds":0.62,"system_seconds":0.02,"kernel_max_rss_kib":38888,"exit":1} diff --git a/research/fraction-native-score-dispatch-feasibility/inputs/PR5864.tar b/research/fraction-native-score-dispatch-feasibility/inputs/PR5864.tar new file mode 100644 index 0000000000..bb9fc30216 Binary files /dev/null and b/research/fraction-native-score-dispatch-feasibility/inputs/PR5864.tar differ diff --git a/research/fraction-native-score-dispatch-feasibility/micro.py b/research/fraction-native-score-dispatch-feasibility/micro.py new file mode 100644 index 0000000000..ce04cc6b56 --- /dev/null +++ b/research/fraction-native-score-dispatch-feasibility/micro.py @@ -0,0 +1,102 @@ +"""One fixed BCCB native score-dispatch screen, no actual-word claim.""" +from fractions import Fraction as F +import json,time +import probe_backend +import runtime_binding as binding + +def need(ok,message): + if not ok:raise ValueError(message) + +def main(): + kernel=binding.bind_kernel(strict=True);token=binding.state_token() + probe=probe_backend.load();controls=[] + positives=[(F(0),F(0),F(0)),(F(1,2),F(-1,2),F(3,8)), + (F(2,3),F(5,7),F(-11,13)),(F(3,8),F(5,8),F(-1,8)), + (F(2**127+1,2**61),F(-3,16),F(7,31)), + (F(-9,17),F(11,17),F(1,2**127)), + (F(1),F(-1),F(0)),(F(5,16),F(-7,32),F(13,64))] + increments=tuple((F(0),*triple) for positive in positives for triple in (positive,tuple(-x for x in positive))) + need(len(increments)==16,'sixteen frozen contribution-shaped triples') + seed=[F(2,3),F(-5,7),F(11,13)] + for count in range(33): + expected=list(seed) + for i in range(count): + for k in range(3):expected[k]+=increments[i%16][k+1] + a=list(seed);b=list(seed) + generic=probe.generic(a,increments,count,F) + direct=probe.direct(b,increments,count,F,kernel) + need(a==b==expected and all(type(x) is F for x in a+b),'every finite prefix value/type') + need(generic==(0,count*3) and direct==(count*3,0),'both actual native branches counted') + controls.append('all-33-prefix-values-types-and-branches') + calls=[] + class Score: + def __iadd__(self,other):calls.append(other);return self + def forbidden(a,b):raise ValueError('nonexact direct call') + objects=[Score(),Score(),Score()] + need(probe.direct(objects,increments,2,F,forbidden)==(0,6) and len(calls)==6,'custom generic iadd retained') + controls.append('nonexact-custom-score-generic-iadd') + class Sub(F): + def __iadd__(self,other):calls.append(other);return self + objects=[Sub(1),Sub(2),Sub(3)];calls.clear() + need(probe.direct(objects,increments,1,F,forbidden)==(0,3) and len(calls)==3,'Fraction subtype uses generic iadd') + controls.append('Fraction-subtype-generic-iadd') + integer_increments=tuple((F(0),1,2,3) for _ in range(16));scores=[F(0)]*3 + need(probe.direct(scores,integer_increments,1,F,forbidden)==(0,3) and scores==[F(1),F(2),F(3)],'nonexact increment uses generic') + controls.append('nonexact-increment-generic') + original_add=F.__dict__['__add__'];retry=[];invoked=[] + def poison(self,other):retry.append(True);raise RuntimeError('unexpected generic retry') + def failing(a,b): + invoked.append(True) + if len(invoked)==2:raise ArithmeticError('direct kernel failure') + return kernel(a,b) + scores=[F(0),F(1),F(2)];first=tuple((F(0),F(10),F(20),F(30)) for _ in range(16)) + F.__add__=poison + try: + try:probe.direct(scores,first,1,F,failing) + except ArithmeticError as error:need(str(error)=='direct kernel failure','original direct error') + else:raise ValueError('direct exception swallowed') + finally:F.__add__=original_add + need(len(invoked)==2 and not retry and scores==[F(10),F(1),F(2)],'no retry and exact partial update order') + controls.append('direct-error-no-retry-partial-update-order') + scores=[F(0)]*3 + def clears(a,b):scores.clear();return kernel(a,b) + try:probe.direct(scores,increments,1,F,clears) + except IndexError:pass + else:raise ValueError('mutated score list accepted') + controls.append('callback-score-list-mutation-safe') + try:probe.direct([F(0)]*3,increments,1,F,object()) + except TypeError:pass + else:raise ValueError('foreign kernel packet accepted') + controls.append('nonfunction-kernel-packet-rejected') + old=F.__dict__['_add'];F._add=lambda a,b:F(999) + try:need(binding.bind_kernel() is None and not binding.still_current(token),'live kernel drift invalidates') + finally:F._add=old + controls.append('kernel-binding-drift') + F.__iadd__=None + try:need(binding.bind_kernel() is None and not binding.still_current(token),'present None iadd rejected') + finally:del F.__iadd__ + controls.append('present-none-iadd-drift') + need(binding.bind_kernel(strict=True) is kernel and binding.still_current(token),'all runtime controls restored before timing') + controls.append('runtime-restored-before-timing') + observations=[];groups=32768 + for label in 'BCCB': + scores=list(seed) + cpu=time.process_time();wall=time.perf_counter() + counts=probe.generic(scores,increments,groups,F) if label=='B' else probe.direct(scores,increments,groups,F,kernel) + elapsed=time.perf_counter()-wall;used=time.process_time()-cpu + need(scores==seed and all(type(x) is F for x in scores),'all terminal scores/types preserved') + need(counts==((0,groups*3) if label=='B' else (groups*3,0)),'timed native branch executed') + row=dict(label=label,wall_seconds=elapsed,cpu_seconds=used,counts=counts,terminal_scores=list(map(str,scores))) + observations.append(row);print(json.dumps(dict(observation=row),sort_keys=True),flush=True) + differences={metric:[observations[0][metric]-observations[1][metric],observations[3][metric]-observations[2][metric]] for metric in ('wall_seconds','cpu_seconds')} + both=all(min(x)>0 for x in differences.values()) + result=dict(status='MICRO_PASS_REQUIRES_FULL_INCREMENTAL_COST_BILL' if both else 'STOP_NATIVE_DIRECT_ADD_MICRO', + no_actual_or_complete_construction=True,controls=controls,control_count=len(controls), + fixed_order='BCCB',groups_per_arm=groups,additions_per_arm=groups*3,observations=observations, + paired_differences=differences, + illustrative_gross_only={k:min(v)*7739250/(groups*3) for k,v in differences.items()}, + not_a_full_trace_projection_or_improvement=True,build=probe_backend.receipt(), + runtime_current=binding.still_current(token)) + print(json.dumps(result,sort_keys=True));return result + +if __name__=='__main__':main() diff --git a/research/fraction-native-score-dispatch-feasibility/native_parent.c b/research/fraction-native-score-dispatch-feasibility/native_parent.c new file mode 100644 index 0000000000..ada7b0d0bf --- /dev/null +++ b/research/fraction-native-score-dispatch-feasibility/native_parent.c @@ -0,0 +1,227 @@ +/* Exact bounded cache/control only. All Fraction arithmetic stays in Python. + * Chris R / Clear1nsight, substantial OpenAI Codex/Astra assistance. Apache-2.0. + */ +#define PY_SSIZE_T_CLEAN +#include +#include + +typedef struct { + PyObject_HEAD + PyObject *dict, *weights, *tokens, *compute, *num, *den, *fraction; + PyObject **ring; + Py_ssize_t capacity, used, head, calls, hits, misses, evictions; + int ready, busy; +} Cache; +typedef struct { + PyObject_HEAD + vectorcallfunc vectorcall; + Cache *cache; + PyObject *q, *qn, *qd; +} Event; +static PyTypeObject CacheType, EventType; + +static int cache_traverse(Cache *s, visitproc visit, void *arg) { + Py_VISIT(s->dict); Py_VISIT(s->weights); Py_VISIT(s->tokens); + Py_VISIT(s->compute); Py_VISIT(s->num); Py_VISIT(s->den); Py_VISIT(s->fraction); + if (s->ring) for (Py_ssize_t i=0;icapacity;i++) Py_VISIT(s->ring[i]); + return 0; +} +static int cache_clear(Cache *s) { + s->ready=0; s->busy=1; + if (s->ring) { + for (Py_ssize_t i=0;icapacity;i++) Py_CLEAR(s->ring[i]); + PyMem_Free(s->ring); s->ring=NULL; + } + Py_CLEAR(s->dict); Py_CLEAR(s->weights); Py_CLEAR(s->tokens); + Py_CLEAR(s->compute); Py_CLEAR(s->num); Py_CLEAR(s->den); Py_CLEAR(s->fraction); + return 0; +} +static void cache_dealloc(Cache *s) { + PyObject_GC_UnTrack(s); cache_clear(s); Py_TYPE(s)->tp_free((PyObject *)s); +} +static int event_traverse(Event *s, visitproc visit, void *arg) { + Py_VISIT(s->cache); Py_VISIT(s->q); Py_VISIT(s->qn); Py_VISIT(s->qd); return 0; +} +static int event_clear(Event *s) { + Py_CLEAR(s->cache); Py_CLEAR(s->q); Py_CLEAR(s->qn); Py_CLEAR(s->qd); return 0; +} +static void event_dealloc(Event *s) { + PyObject_GC_UnTrack(s); event_clear(s); Py_TYPE(s)->tp_free((PyObject *)s); +} +static PyObject *event_disabled(PyTypeObject *type, PyObject *args, PyObject *kw) { + (void)type; (void)args; (void)kw; + PyErr_SetString(PyExc_TypeError,"events are created only by Cache.event"); return NULL; +} +static int is_pair(PyObject *p) { + return (PyList_CheckExact(p)||PyTuple_CheckExact(p)) && PySequence_Size(p)>=2; +} +static PyObject *cache_new(PyTypeObject *type, PyObject *args, PyObject *kw) { + if (kw && PyDict_Size(kw)) { PyErr_SetString(PyExc_TypeError,"positional cache arguments only");return NULL; } + PyObject *cap,*weights,*tokens,*compute,*num,*den,*fraction; + if (!PyArg_UnpackTuple(args,"Cache",7,7,&cap,&weights,&tokens,&compute,&num,&den,&fraction)) return NULL; + if (!PyLong_CheckExact(cap)) { PyErr_SetString(PyExc_ValueError,"integer capacity");return NULL; } + Py_ssize_t ncap=PyLong_AsSsize_t(cap); + if (ncap<1 || ncap>16384 || PyErr_Occurred()) { if(!PyErr_Occurred()) PyErr_SetString(PyExc_ValueError,"capacity 1..16384");return NULL; } + if (!(PyList_CheckExact(weights)||PyTuple_CheckExact(weights)) || !PyList_CheckExact(tokens) || !PyFunction_Check(compute) || !PyType_Check(fraction) || Py_TYPE(num)!=&PyMemberDescr_Type || Py_TYPE(den)!=&PyMemberDescr_Type || !Py_TYPE(num)->tp_descr_get || !Py_TYPE(den)->tp_descr_get) { + PyErr_SetString(PyExc_TypeError,"exact native packet types");return NULL; + } + Py_ssize_t n=PySequence_Size(weights); + if (PyList_GET_SIZE(tokens)!=n) { PyErr_SetString(PyExc_ValueError,"weight/token size");return NULL; } + Cache *s=(Cache *)type->tp_alloc(type,0); + if (!s) return NULL; + s->capacity=ncap; + s->dict=PyDict_New();s->weights=PyTuple_New(n);s->tokens=PyTuple_New(n); + s->ring=PyMem_Calloc((size_t)ncap,sizeof(PyObject *)); + if (!s->dict || !s->weights || !s->tokens || !s->ring) { if(!PyErr_Occurred())PyErr_NoMemory();Py_DECREF(s);return NULL; } + s->compute=Py_NewRef(compute);s->num=Py_NewRef(num);s->den=Py_NewRef(den);s->fraction=Py_NewRef(fraction); + for (Py_ssize_t i=0;iweights,i,pair); + PyObject *token=PySequence_GetItem(tokens,i); + if (!token) { Py_DECREF(s);return NULL; } + if (!PyLong_CheckExact(token)) { Py_DECREF(token);Py_DECREF(s);PyErr_SetString(PyExc_TypeError,"integer token");return NULL; } + Py_ssize_t t=PyLong_AsSsize_t(token); + if (t<0 || t>=16384 || PyErr_Occurred()) { Py_DECREF(token);Py_DECREF(s);if(!PyErr_Occurred())PyErr_SetString(PyExc_ValueError,"bounded token");return NULL; } + PyTuple_SET_ITEM(s->tokens,i,token); + } + s->ready=1;return (PyObject *)s; +} +static PyObject *member(PyObject *descriptor, PyObject *object, PyObject *type) { + return Py_TYPE(descriptor)->tp_descr_get(descriptor,object,type); +} +static PyObject *contribution(Event *e, PyObject *old, PyObject *v, Py_ssize_t i) { + Cache *s=e->cache; + if (i<0 || i>=PyTuple_GET_SIZE(s->tokens)) { PyErr_SetString(PyExc_IndexError,"native site index");return NULL; } + if (!Py_IS_TYPE(old,(PyTypeObject *)s->fraction)||!Py_IS_TYPE(v,(PyTypeObject *)s->fraction)) { PyErr_SetString(PyExc_TypeError,"exact Fraction coefficients");return NULL; } + PyObject *parts[4]={NULL,NULL,NULL,NULL}; + for (int k=0;k<4;k++) { + parts[k]=member(k%2?s->den:s->num,k<2?old:v,s->fraction); + if (!parts[k] || !PyLong_CheckExact(parts[k])) { + for(int j=0;j<4;j++)Py_XDECREF(parts[j]); + if(!PyErr_Occurred())PyErr_SetString(PyExc_TypeError,"integer Fraction slots"); + return NULL; + } + } + PyObject *key=PyTuple_New(7); + if(!key){for(int j=0;j<4;j++)Py_DECREF(parts[j]);return NULL;} + PyTuple_SET_ITEM(key,0,parts[0]);PyTuple_SET_ITEM(key,1,parts[1]); + PyTuple_SET_ITEM(key,2,Py_NewRef(e->qn));PyTuple_SET_ITEM(key,3,Py_NewRef(e->qd)); + PyTuple_SET_ITEM(key,4,parts[2]);PyTuple_SET_ITEM(key,5,parts[3]);PyTuple_SET_ITEM(key,6,Py_NewRef(PyTuple_GET_ITEM(s->tokens,i))); + if(s->calls==PY_SSIZE_T_MAX){Py_DECREF(key);PyErr_SetString(PyExc_OverflowError,"native counter overflow");return NULL;} + s->calls++; + PyObject *result=PyDict_GetItemWithError(s->dict,key); + if(result){s->hits++;Py_INCREF(result);Py_DECREF(key);return result;} + if(PyErr_Occurred()){Py_DECREF(key);return NULL;} + s->misses++; + PyObject *pair=PyTuple_GET_ITEM(s->weights,i); + PyObject *argv[5]={old,e->q,v,PyTuple_GET_ITEM(pair,0),PyTuple_GET_ITEM(pair,1)}; + result=PyObject_Vectorcall(s->compute,argv,5,NULL); + if(!result){Py_DECREF(key);return NULL;} + if(!PyTuple_CheckExact(result)||PyTuple_GET_SIZE(result)!=4){Py_DECREF(result);Py_DECREF(key);PyErr_SetString(PyExc_TypeError,"four exact contributions");return NULL;} + for(int k=0;k<4;k++)if(!Py_IS_TYPE(PyTuple_GET_ITEM(result,k),(PyTypeObject *)s->fraction)){Py_DECREF(result);Py_DECREF(key);PyErr_SetString(PyExc_TypeError,"Fraction contributions");return NULL;} + if(s->used==s->capacity){ + PyObject *oldkey=s->ring[s->head]; + if(PyDict_DelItem(s->dict,oldkey)<0){Py_DECREF(result);Py_DECREF(key);return NULL;} + Py_CLEAR(s->ring[s->head]);s->used--;s->evictions++; + } + if(PyDict_SetItem(s->dict,key,result)<0){Py_DECREF(result);Py_DECREF(key);return NULL;} + s->ring[s->head]=key;s->head=(s->head+1)%s->capacity;s->used++; + return result; +} +static int begin_event(Event *e) { + if(!e->cache||!e->cache->ready){PyErr_SetString(PyExc_RuntimeError,"cleared native event");return -1;} + if(e->cache->busy){PyErr_SetString(PyExc_RuntimeError,"reentrant native event");return -1;} + e->cache->busy=1;return 0; +} +static PyObject *event_call(PyObject *obj, PyObject *const *args, size_t nargsf, PyObject *kw) { + Event *e=(Event *)obj; + if(PyVectorcall_NARGS(nargsf)!=3 || (kw&&PyTuple_GET_SIZE(kw))){PyErr_SetString(PyExc_TypeError,"event(old,v,index)");return NULL;} + if(!PyLong_CheckExact(args[2])){PyErr_SetString(PyExc_TypeError,"integer site index");return NULL;} + Py_ssize_t i=PyLong_AsSsize_t(args[2]);if(PyErr_Occurred())return NULL; + if(begin_event(e)<0)return NULL; + PyObject *result=contribution(e,args[0],args[1],i);e->cache->busy=0;return result; +} +static PyObject *cache_event(Cache *s, PyObject *q) { + if(!s->ready){PyErr_SetString(PyExc_RuntimeError,"cleared cache");return NULL;} + if(!Py_IS_TYPE(q,(PyTypeObject *)s->fraction)){PyErr_SetString(PyExc_TypeError,"exact Fraction scalar");return NULL;} + Event *e=(Event *)EventType.tp_alloc(&EventType,0);if(!e)return NULL; + e->vectorcall=event_call;e->cache=(Cache *)Py_NewRef((PyObject *)s);e->q=Py_NewRef(q); + e->qn=member(s->num,q,s->fraction); + if(!e->qn){Py_DECREF(e);return NULL;} + e->qd=member(s->den,q,s->fraction); + if(!e->qd){Py_DECREF(e);return NULL;} + if(!PyLong_CheckExact(e->qn)||!PyLong_CheckExact(e->qd)){Py_DECREF(e);PyErr_SetString(PyExc_TypeError,"integer scalar slots");return NULL;} + return (PyObject *)e; +} +static PyObject *cache_statistics(Cache *s, PyObject *unused) { + (void)unused; + if(!s->ready){PyErr_SetString(PyExc_RuntimeError,"cleared cache");return NULL;} + return Py_BuildValue("{s:n,s:n,s:n,s:n,s:n,s:n,s:n}","calls",s->calls,"hits",s->hits,"misses",s->misses,"evictions",s->evictions,"bypasses",(Py_ssize_t)0,"resident",PyDict_Size(s->dict),"capacity",s->capacity); +} +static PyObject *event_apply(Event *e, PyObject *args) { + PyObject *dst,*src,*scores; + if(!PyArg_UnpackTuple(args,"apply",3,3,&dst,&src,&scores))return NULL; + if(!PyDict_CheckExact(dst)||!PyDict_CheckExact(src)||dst==src||!PyList_CheckExact(scores)||PyList_GET_SIZE(scores)!=3){PyErr_SetString(PyExc_TypeError,"distinct exact rows and three scores");return NULL;} + if(begin_event(e)<0)return NULL; + Cache *s=e->cache; + PyObject *pair=NULL,*result=NULL; + PyObject *view=PyObject_CallMethod(src,"items",NULL); + PyObject *iterator=view?PyObject_GetIter(view):NULL; + Py_XDECREF(view); + if(!iterator)goto fail; + while((pair=PyIter_Next(iterator))){ + if(!PyTuple_CheckExact(pair)||PyTuple_GET_SIZE(pair)!=2){PyErr_SetString(PyExc_TypeError,"dict item pair");goto fail;} + PyObject *index=PyTuple_GET_ITEM(pair,0),*value=PyTuple_GET_ITEM(pair,1); + if(!PyLong_CheckExact(index)){PyErr_SetString(PyExc_TypeError,"integer source site");goto fail;} + Py_ssize_t i=PyLong_AsSsize_t(index);if(PyErr_Occurred())goto fail; + PyObject *zeroarg=PyLong_FromLong(0);if(!zeroarg)goto fail; + PyObject *zero=PyObject_CallOneArg(s->fraction,zeroarg);Py_DECREF(zeroarg);if(!zero)goto fail; + PyObject *old=PyDict_GetItemWithError(dst,index); + if(old){Py_INCREF(old);Py_DECREF(zero);}else if(PyErr_Occurred()){Py_DECREF(zero);goto fail;}else old=zero; + result=contribution(e,old,value,i);Py_DECREF(old);if(!result)goto fail; + for(int k=0;k<3;k++){ + PyObject *score=PyList_GetItem(scores,k); + if(!score)goto fail; + Py_INCREF(score); + PyObject *next=PyNumber_InPlaceAdd(score,PyTuple_GET_ITEM(result,k+1)); + Py_DECREF(score); + if(!next)goto fail; + if(PyList_SetItem(scores,k,next)<0)goto fail; + } + int truth=PyObject_IsTrue(PyTuple_GET_ITEM(result,0)); + if(truth<0)goto fail; + if(truth){if(PyDict_SetItem(dst,index,PyTuple_GET_ITEM(result,0))<0)goto fail;} + else{ + PyObject *present=PyDict_GetItemWithError(dst,index); + if(present){if(PyDict_DelItem(dst,index)<0)goto fail;} + else if(PyErr_Occurred())goto fail; + } + Py_CLEAR(result);Py_CLEAR(pair); + } + if(PyErr_Occurred())goto fail; + Py_DECREF(iterator);s->busy=0;Py_RETURN_NONE; +fail:Py_XDECREF(result);Py_XDECREF(pair);Py_XDECREF(iterator);s->busy=0;return NULL; +} +static PyMethodDef cache_methods[]={{"event",(PyCFunction)cache_event,METH_O,"Fresh scalar context."},{"statistics",(PyCFunction)cache_statistics,METH_NOARGS,"Full counters."},{NULL,NULL,0,NULL}}; +static PyMethodDef event_methods[]={{"apply",(PyCFunction)event_apply,METH_VARARGS,"Same coefficient loop and Python numeric operations."},{NULL,NULL,0,NULL}}; +static PyTypeObject CacheType={PyVarObject_HEAD_INIT(NULL,0) + .tp_name="_fraction_native.Cache",.tp_basicsize=sizeof(Cache),.tp_flags=Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC, + .tp_new=cache_new,.tp_dealloc=(destructor)cache_dealloc,.tp_traverse=(traverseproc)cache_traverse,.tp_clear=(inquiry)cache_clear,.tp_methods=cache_methods}; +static PyTypeObject EventType={PyVarObject_HEAD_INIT(NULL,0) + .tp_name="_fraction_native.Event",.tp_basicsize=sizeof(Event),.tp_flags=Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC|Py_TPFLAGS_HAVE_VECTORCALL, + .tp_new=event_disabled,.tp_dealloc=(destructor)event_dealloc,.tp_traverse=(traverseproc)event_traverse,.tp_clear=(inquiry)event_clear, + .tp_call=PyVectorcall_Call,.tp_vectorcall_offset=offsetof(Event,vectorcall),.tp_methods=event_methods}; +static struct PyModuleDef module={PyModuleDef_HEAD_INIT,"_fraction_native","Bounded cache; exact Python arithmetic.",-1,NULL}; +PyMODINIT_FUNC PyInit__fraction_native(void){ + if(PyType_Ready(&CacheType)<0||PyType_Ready(&EventType)<0)return NULL; + PyObject *m=PyModule_Create(&module);if(!m)return NULL; + if(PyModule_AddObjectRef(m,"Cache",(PyObject *)&CacheType)<0){Py_DECREF(m);return NULL;} + return m; +} diff --git a/research/fraction-native-score-dispatch-feasibility/probe_backend.py b/research/fraction-native-score-dispatch-feasibility/probe_backend.py new file mode 100644 index 0000000000..b20e427855 --- /dev/null +++ b/research/fraction-native-score-dispatch-feasibility/probe_backend.py @@ -0,0 +1,61 @@ +"""Cold-build the owned C source; reuse code only within this process.""" +from hashlib import sha256 +import atexit +import importlib.util +import json +from pathlib import Path +import platform +import shutil +import subprocess +import sys +import sysconfig +import tempfile +import time + +HERE=Path(__file__).resolve().parent +_loaded=None +_temporary=None +_receipt=None + +def source_hash(): + path=HERE/'score_probe.c' + digest=sha256(path.read_bytes()).hexdigest() + expected=json.loads((HERE/'PROBE-SOURCE.json').read_text())['sha256'] + if path.is_symlink() or digest!=expected:raise ValueError('exact owned C source') + return digest + +def load(): + global _loaded,_temporary,_receipt + digest=source_hash() + if _loaded is not None: + if _receipt['source_sha256']!=digest:raise ValueError('loaded native code has this exact source') + return _loaded + if platform.python_implementation()!='CPython' or sys.version_info[:2]!=(3,12) or sys.platform!='linux': + raise RuntimeError('native feasibility requires Linux CPython 3.12') + compiler=shutil.which('cc') + if not compiler:raise RuntimeError('native feasibility requires an existing C compiler') + start=time.perf_counter() + _temporary=tempfile.TemporaryDirectory(prefix='fraction-native-owned-') + atexit.register(_temporary.cleanup) + root=Path(_temporary.name) + raw=(HERE/'score_probe.c').read_bytes() + if sha256(raw).hexdigest()!=digest:raise ValueError('C source remained authenticated at snapshot') + snapshot=root/'score_probe.c';snapshot.write_bytes(raw);snapshot.chmod(0o444) + destination=root/('_score_probe'+sysconfig.get_config_var('EXT_SUFFIX')) + flags=['-O2','-shared','-fPIC','-std=c11','-Wall','-Werror','-I'+sysconfig.get_path('include')] + command=[compiler,*flags,str(snapshot),'-o',str(destination)] + build=subprocess.run(command,capture_output=True,text=True,check=False) + if build.returncode or build.stderr or build.stdout: + raise RuntimeError('native build rejected: '+json.dumps(dict(command=command,returncode=build.returncode,stdout=build.stdout,stderr=build.stderr))) + destination.chmod(0o444) + spec=importlib.util.spec_from_file_location('_score_probe',destination) + value=importlib.util.module_from_spec(spec);spec.loader.exec_module(value) + _receipt=dict(source_sha256=digest,compiler=compiler,flags=flags,SOABI=sysconfig.get_config_var('SOABI'), + extension_suffix=sysconfig.get_config_var('EXT_SUFFIX'),python=sys.version, + binary_sha256=sha256(destination.read_bytes()).hexdigest(),cold_build_load_wall_seconds=time.perf_counter()-start, + compiler_cpu_accounting='outer GNU time user+system includes compiler children', + compiler_version=subprocess.run([compiler,'--version'],capture_output=True,text=True,check=True).stdout.splitlines()[0]) + _loaded=value + return value + +def receipt():return None if _receipt is None else dict(_receipt) diff --git a/research/fraction-native-score-dispatch-feasibility/runtime_binding.py b/research/fraction-native-score-dispatch-feasibility/runtime_binding.py new file mode 100644 index 0000000000..4f7c0a31f3 --- /dev/null +++ b/research/fraction-native-score-dispatch-feasibility/runtime_binding.py @@ -0,0 +1,100 @@ +"""Authenticate the exact same Fraction addition branch, or retain generic +=. + +No standard-library mutation or alternative rational arithmetic. Source/runtime +inspection and controls by Chris R / Clear1nsight with substantial Codex/Astra +assistance; original arithmetic remains its credited Python/Fraction authors. +""" +import builtins +from fractions import Fraction as F +from hashlib import sha256 +import json +import math +import operator +from pathlib import Path +from types import FunctionType +from table_parent import code_shape + +EXPECTED=json.loads(Path(__file__).with_name('RUNTIME-SHAPES.json').read_text())['functions'] + + +def raw_function(name): + value=F.__dict__.get(name) + if type(value) is FunctionType: + return value + if name=='__new__' and type(value) is staticmethod: + function=value.__func__ + if type(function) is FunctionType:return function + if name=='_from_coprime_ints' and type(value) is classmethod: + function=value.__func__ + if type(function) is FunctionType:return function + raise ValueError('ordinary authenticated descriptor '+name) + + +def state_token(): + """Identity-only trace-entry freshness; never invoke foreign descriptors.""" + try: + values=[] + for name in EXPECTED: + fn=raw_function(name);g=fn.__globals__;b=fn.__builtins__ + if type(b) is not dict:return None + values.extend((F.__dict__[name],fn,fn.__code__,fn.__defaults__,fn.__kwdefaults__,g,b,g.get('Fraction'),g.get('math'))) + for key in ('isinstance','super','int','abs'): + values.append(g.get(key,b.get(key))) + for cell in fn.__closure__ or (): + values.append(cell.cell_contents) + for cls in F.__mro__: + values.extend((cls,'__iadd__' in cls.__dict__,cls.__dict__.get('__iadd__'),'__new__' in cls.__dict__,cls.__dict__.get('__new__'))) + values.append(math.gcd) + return tuple(values) + except (ValueError,AttributeError,TypeError,KeyError):return None + + +def still_current(token): + current=state_token() + return token is not None and current is not None and len(token)==len(current) and all(a is b for a,b in zip(token,current)) + + +def bind_kernel(strict=False): + try: + if any('__iadd__' in cls.__dict__ for cls in F.__mro__): + raise ValueError('no distinct Fraction augmented assignment') + functions={} + for name,expected in EXPECTED.items(): + value=raw_function(name) + if type(value) is not FunctionType or sha256(repr(code_shape(value.__code__)).encode()).hexdigest()!=expected: + raise ValueError('known live Fraction executable '+name) + functions[name]=value + forward=functions['__add__'];kernel=functions['_add'] + cells=dict(zip(forward.__code__.co_freevars,forward.__closure__ or ())) + if set(cells)!={'fallback_operator','monomorphic_operator'}: + raise ValueError('exact addition closure fields') + if cells['monomorphic_operator'].cell_contents is not kernel or cells['fallback_operator'].cell_contents is not operator.add: + raise ValueError('addition closure uses this exact kernel') + for fn in functions.values(): + g=fn.__globals__ + if g.get('Fraction') is not F or g.get('math') is not math: + raise ValueError('standard Fraction and math globals') + b=fn.__builtins__ + b=vars(b) if b is builtins else b + if type(b) is not dict: + raise ValueError('ordinary builtin mapping') + for name in ('isinstance','super','int','abs'): + if g.get(name,b.get(name)) is not getattr(builtins,name): + raise ValueError('standard builtin '+name) + if type(math.gcd) is not type(operator.add) or math.gcd.__module__!='math' or math.gcd.__name__!='gcd': + raise ValueError('standard builtin gcd') + constructor=F.__dict__['_from_coprime_ints'] + if type(constructor) is not classmethod or constructor.__func__ is not functions['_from_coprime_ints']: + raise ValueError('Fraction classmethod allocator') + allocator=next((cls.__dict__['__new__'] for cls in F.__mro__[1:] if '__new__' in cls.__dict__),None) + if allocator is not object.__dict__['__new__']: + raise ValueError('standard inherited allocator') + for wrapper,operation,builtin in [('__mul__','_mul',operator.mul),('__sub__','_sub',operator.sub)]: + method=functions[wrapper] + mc=dict(zip(method.__code__.co_freevars,method.__closure__ or ())) + if set(mc)!={'fallback_operator','monomorphic_operator'} or mc['monomorphic_operator'].cell_contents is not functions[operation] or mc['fallback_operator'].cell_contents is not builtin: + raise ValueError('type-preserving branch '+wrapper) + return kernel + except (ValueError,AttributeError,TypeError,KeyError) as error: + if strict:raise ValueError('unsupported Fraction direct-add binding: '+str(error)) from error + return None diff --git a/research/fraction-native-score-dispatch-feasibility/score_probe.c b/research/fraction-native-score-dispatch-feasibility/score_probe.c new file mode 100644 index 0000000000..cf8e3af148 --- /dev/null +++ b/research/fraction-native-score-dispatch-feasibility/score_probe.c @@ -0,0 +1,63 @@ +/* Bounded dispatch feasibility only. Original Fraction arithmetic retained. + * Chris R / Clear1nsight with substantial OpenAI Codex assistance. Apache-2.0. */ +#define PY_SSIZE_T_CLEAN +#include +static int packet(PyObject *scores,PyObject *triples,PyObject *groups,PyObject *fraction,Py_ssize_t *count){ + if(!PyList_CheckExact(scores)||PyList_GET_SIZE(scores)!=3||!PyTuple_CheckExact(triples)||PyTuple_GET_SIZE(triples)!=16||!PyLong_CheckExact(groups)||!PyType_Check(fraction)){ + PyErr_SetString(PyExc_TypeError,"three scores, sixteen triples, integer groups and class");return -1; + } + *count=PyLong_AsSsize_t(groups); + if(PyErr_Occurred())return -1; + if(*count<0||*count>32768){PyErr_SetString(PyExc_ValueError,"groups 0..32768");return -1;} + for(int i=0;i<16;i++){ + PyObject *row=PyTuple_GET_ITEM(triples,i); + if(!PyTuple_CheckExact(row)||PyTuple_GET_SIZE(row)!=4){PyErr_SetString(PyExc_TypeError,"contribution-shaped triple");return -1;} + } + return 0; +} +static PyObject *generic(PyObject *module,PyObject *args){ + (void)module;PyObject *scores,*triples,*groups,*fraction;Py_ssize_t count; + if(!PyArg_UnpackTuple(args,"generic",4,4,&scores,&triples,&groups,&fraction))return NULL; + if(packet(scores,triples,groups,fraction,&count)<0)return NULL; + for(Py_ssize_t group=0;group=self.capacity: + self.table.popitem(last=False) + self.evictions+=1 + self.table[key]=result + return result + + def statistics(self): + return dict(calls=self.calls,hits=self.hits,misses=self.misses, + evictions=self.evictions,bypasses=self.bypasses, + resident=len(self.table),capacity=self.capacity) + + +def code_shape(code): + constants=tuple(code_shape(c) if isinstance(c,CodeType) else c for c in code.co_consts) + return (code.co_code,constants,code.co_names,code.co_varnames,code.co_argcount, + code.co_posonlyargcount,code.co_kwonlyargcount,code.co_flags, + code.co_freevars,code.co_cellvars,code.co_name,code.co_stacksize, + code.co_nlocals,code.co_exceptiontable) + + +def transformed(raw): + need(sha256(raw.encode()).hexdigest()==FUNCTION_SHA256,'exact Fraction function source') + need(raw.count(BEFORE)==1,'one exact Fraction contribution block') + value=raw.replace(BEFORE,AFTER) + seam=" n = word['public'] + word['owned_fields']\n" + need(value.count(seam)==1,'one exact Fraction setup seam') + value=value.replace(seam,seam+' _contribution_report(None)\n contributions = _contribution_factory()\n') + seam=' return dict(rounded=sorted(rounded), sites=sites, peaks=peaks, pareto=pareto,\n' + need(value.count(seam)==1,'one exact Fraction return seam') + return value.replace(seam,' _contribution_report(contributions.statistics())\n'+seam) + + +def derive(reference,capacity=CAPACITY): + need(type(capacity) is int and 0<=capacity<=CAPACITY,'bounded integer table capacity') + need(reference.F is F,'exact standard Fraction type') + need(sha256(Path(reference.__file__).read_bytes()).hexdigest()==MODULE_SHA256,'exact Fraction module bytes') + original=reference.error_trace + raw=inspect.getsource(original) + text=transformed(raw) + namespace=dict(reference.__dict__) + exec(compile(raw,'','exec'),namespace) + need(code_shape(original.__code__)==code_shape(namespace['error_trace'].__code__),'live Fraction code agrees with source') + need(original.__defaults__ is None and original.__kwdefaults__ is None and original.__closure__ is None,'ordinary Fraction function') + last=[None] + def report(value):last[0]=None if value is None else dict(value) + namespace.update(_contribution_factory=lambda:Contributions(capacity),_contribution_report=report) + exec(compile(text,'','exec'),namespace) + result=namespace['error_trace'] + result.statistics=lambda:None if last[0] is None else dict(last[0]) + return result + + +@contextmanager +def installed(reference,capacity=CAPACITY): + original=reference.error_trace + derived=derive(reference,capacity) + reference.error_trace=derived + try: + yield derived + finally: + reference.error_trace=original diff --git a/research/fraction-native-score-dispatch-feasibility/verify.py b/research/fraction-native-score-dispatch-feasibility/verify.py new file mode 100644 index 0000000000..10a2ec7d8f --- /dev/null +++ b/research/fraction-native-score-dispatch-feasibility/verify.py @@ -0,0 +1,42 @@ +"""Replay all probe correctness controls without repeating its timing trial.""" +from hashlib import sha256 +import inspect,json,tarfile +from pathlib import Path +import micro +from table_parent import code_shape + +HERE=Path(__file__).resolve().parent +ARCHIVE='7b142567acacac5182045bf8daa8780e916661c2cf343dbf81b13c88ead85d64' + +def need(ok,message): + if not ok:raise ValueError(message) + +def main(): + archive=HERE/'inputs/PR5864.tar' + need(sha256(archive.read_bytes()).hexdigest()==ARCHIVE,'exact complete PR5864 export') + with tarfile.open(archive,'r:') as stream: + receipt=json.loads(stream.extractfile('.research-export.json').read()) + need(receipt['commit']=='3f15c943e4ad6479f03e674c80fff1269a16ccfe' and len(receipt['files'])==163,'exact parent source head/census') + native=stream.extractfile('research/fraction-native-qualification/native_cache.c').read() + need(native==(HERE/'native_parent.c').read_bytes(),'exact parent native C bytes') + start=native.index(b' for(int k=0;k<3;k++){',native.index(b'static PyObject *event_apply')) + end=native.index(b' int truth=',start) + need(native[start:end]==(HERE/'PARENT-SCORE-LOOP.txt').read_bytes(),'exact retained parent score loop') + raw=inspect.getsource(micro.main);module_raw=Path(micro.__file__).read_text() + need(sha256(module_raw.encode()).hexdigest()==json.loads((HERE/'FINITE-SOURCE.json').read_text())['module_sha256'],'exact measured probe module') + need(sha256(raw.encode()).hexdigest()==json.loads((HERE/'FINITE-SOURCE.json').read_text())['function_sha256'],'exact measured probe source') + namespace=dict(micro.__dict__);exec(compile(module_raw,'','exec'),namespace) + need(code_shape(namespace['main'].__code__)==code_shape(micro.main.__code__),'live probe executable agrees') + seam=' observations=[];groups=32768\n' + need(raw.count(seam)==1,'unique boundary after all ten correctness controls') + entry="\nif __name__=='__main__':main()\n" + need(module_raw.count(entry)==1,'unique unchanged module entry guard') + finite=module_raw[:module_raw.index(seam)]+''' result=dict(prefix_cases=33,controls=controls,control_count=len(controls),runtime_current=binding.still_current(token)) + print(json.dumps(dict(status='PASS_NATIVE_SCORE_FINITE_ONLY',result=result,build=probe_backend.receipt()),sort_keys=True)) + return result +'''+module_raw[module_raw.index(entry):] + exec(compile(finite,'','exec'),namespace) + need(namespace['main']()==json.loads((HERE/'RESULT.json').read_text()),'all retained finite probe controls') + print('PASS_NATIVE_SCORE_DISPATCH_FEASIBILITY_FINITE_ONLY') + +if __name__=='__main__':main() diff --git a/tests/fixtures/README.md b/tests/fixtures/README.md new file mode 100644 index 0000000000..472a6a502f --- /dev/null +++ b/tests/fixtures/README.md @@ -0,0 +1,41 @@ +# Frozen research routing fixture + +`research-routing-v7.json` retains two exact task cards from priority revision 7: +`portable-replay` and `centre-path-sharing`. They exercise the generic-baseline +and historical-ceiling routes in `choose_current_research_task.py`. The fixture +records the source commit, path and SHA256. The card objects are unchanged. + +The source is commit `553d26d796fde9871ff2661a49ac7732e945410f`, file +`docs/research/agent-task-catalog.json`. The test places these cards in a small +catalogue with one track of weight 100. This carrier is test data, not a change +to research priorities. Current cards are checked separately from the live +catalogue. Every live card must preserve its other fields; each distinct direct +command also passes through both real CLIs. + +The CLI fixture copies the two real scripts. It creates inert reference files +for path validation and copies the current selected record for receipt fields. +It does not execute those references or verify a mathematical claim. Missing +references, sparse omissions, deleted files and staged replacements have separate +negative tests. No Git history, network request or change to the live catalogue +is needed to run the fixture. + +```sh +python3 -B -m unittest discover -s tests -p test_research_current_assignment.py -v +python3 -B -m unittest discover -s tests -p test_research_assignment.py -v +``` + +This fixture repairs the CI handoff in +[Discussion 5722](https://github.com/CrocSwap/integer-mult-bounds/discussions/5722). +The [investigation](https://github.com/CrocSwap/integer-mult-bounds/discussions/5758) +records the failure, checks and publication status. The original scripts, task +catalogue and selected frontier are unchanged. + +On base `de5ec2e7a6074068452f45b1a191b5c72832df4a`, the old suite has eight +failures and two errors. After the repair, all 12 current-assignment tests pass +under Python 3.14.7 and Python 3.12.14, including an isolated optimized run. +All 16 related assignment tests pass under Python 3.12.14. This is test coverage, +not a mathematical replay. See the investigation for hosted-plan status. + +Retain the original catalogue, routing and test authors, including Douglas +Colkitt, Ali Romman and Mihir Srivastava. New fixture and test repair: Ali Romman +with substantial OpenAI Codex assistance. No subagents. Apache-2.0. diff --git a/tests/fixtures/research-routing-v7.json b/tests/fixtures/research-routing-v7.json new file mode 100644 index 0000000000..f5d52ac21d --- /dev/null +++ b/tests/fixtures/research-routing-v7.json @@ -0,0 +1,87 @@ +{ + "source_commit": "553d26d796fde9871ff2661a49ac7732e945410f", + "source_path": "docs/research/agent-task-catalog.json", + "source_sha256": "f7a48bfa2659b88378282a8eee7d9fe52cdf505594124c4d1686b58510fffd72", + "scope": "Two exact revision-7 cards. The test carrier is not a research allocation.", + "cards": [ + { + "id": "centre-path-sharing", + "question": "Can the 64-per-call centre path (eight rank-8 COPY/ERASE totals through the private temporary) be shared across calls or shrunk?", + "starting_points": [ + "docs/research/research-family-status.md", + "research/complex-local-word-ceiling/README.md", + "research/split-centres-global/proofs/PR386-BIT-GEOMETRY.txt", + "certificates/selected-result.json" + ], + "methods": [ + "Derive a fully charged favorable relaxation for sharing one centre path across k calls, including restoration, hosting and precision.", + "Prove a lower bound on copied information per call for the selected decoder contract." + ], + "acceptance_gate": "Show the changed centre charge and copy profile per call with every added restoration or hosting cost charged, and its ceiling via ceiling.ceiling(centre=...). A scoped local result may be retained without a complete supplier. Expanding it into further construction rounds requires the family-level budget and obligation gate in research-family-status.md; an optimistic passing relaxation alone is not acceptance.", + "first_step": { + "command": [ + "python3", + "-B", + "research/complex-local-word-ceiling/verify.py" + ], + "expected": "PASS_COMPLEX_LOCAL_WORD_CEILING", + "inspect": "Read the selected word's per-call local profile, its packing ceiling and the lever table; run levers.py for the ideal budget of the lever you target.", + "scope": "Positive control and planning budget only; this is not a new construction or full cold replay." + }, + "first_experiment": "Write the per-call centre charge and copy children for sharing across k = 2 calls, charge the sharing overhead, and screen it; stop this route if even the ideal sharing gains under 10%. Ideal budgets: free 2.80x, shared by two 1.90x (levers.py).", + "bottleneck_link": "The centre path consumes 64 of about 99.6 unpaid coordinates per call, i.e. about 64% of the raw deficit.", + "allowed_variations": [ + "One sharing pattern across a fixed number of calls.", + "One reduced copied-total contract for the existing decoder.", + "If the coverage law, template or guard changes, derive an applicable fully charged replacement bound instead of applying the incumbent ceiling outside its scope." + ], + "scope_change_triggers": [ + "Removing copies without a replacement contract for the decoder's copied totals.", + "Continuing a partial cost improvement while leaving the same unpriced consumer, restoration or central-readout obligation unresolved; refresh the family expansion decision first. Local product-retiming evidence has a narrow scope and is not a ban on changed graphs or contracts." + ], + "overlap_terms": [ + "centre path", + "copied totals", + "private temporary", + "shared centre", + "batching" + ] + }, + { + "id": "portable-replay", + "question": "Can one reproducible environment or artifact-comparison failure be repaired?", + "starting_points": [ + "research/gzip-container-reproducibility/README.md", + "docs/ci-verification.md" + ], + "methods": [ + "Reproduce one portability failure and add a minimal cross-environment fix.", + "Audit one canonical-payload comparison for omitted proof-relevant fields." + ], + "acceptance_gate": "Preserve immutable source hashes and proof-relevant content; a different compressed byte stream alone is not a mathematical mismatch.", + "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." + }, + "first_experiment": "Reproduce one specific mismatch or audit one canonical comparison for omitted proof-relevant fields.", + "bottleneck_link": "Portable exact checks prevent environment failures from blocking valid contributions.", + "allowed_variations": [ + "One interpreter/version mismatch or one payload field comparison." + ], + "scope_change_triggers": [ + "Removing immutable-source pins because generated compressed bytes differ." + ], + "overlap_terms": [ + "gzip container", + "reproducibility", + "canonical payload" + ] + } + ] +} diff --git a/tests/test_research_current_assignment.py b/tests/test_research_current_assignment.py index 860f6b9b9e..c524c0037f 100644 --- a/tests/test_research_current_assignment.py +++ b/tests/test_research_current_assignment.py @@ -1,9 +1,15 @@ -"""Current orientation must preserve frozen task-selection evidence.""" +"""Current orientation must preserve frozen task-selection evidence. + +Frozen fixtures and live-catalog coverage: Ali Romman with OpenAI Codex +assistance. Retain the original routing and test authors. Apache-2.0. +""" import copy +from contextlib import contextmanager import importlib.util import json from pathlib import Path import subprocess +import shutil import sys import tempfile import unittest @@ -15,16 +21,49 @@ LEGACY = current.LEGACY legacy = current.runpy.run_path(str(LEGACY)) CATALOG = json.loads((ROOT / legacy["CATALOG"]).read_text(encoding="utf-8")) +FROZEN = json.loads((ROOT / "tests/fixtures/research-routing-v7.json").read_text()) +FROZEN_CATALOG = { + "schema_version": 1, "priority_revision": 7, + "priority_log": "docs/research/routing-fixture.md", + "tracks": [{"id": "routing-fixtures", "weight": 100, "tasks": FROZEN["cards"]}], +} + + +@contextmanager +def frozen_cli_tree(): + """Run the real scripts with exact old cards and inert reference files.""" + with tempfile.TemporaryDirectory() as directory: + root = Path(directory) + required = {FROZEN_CATALOG["priority_log"], + "scripts/research_selected_baseline.py", "scripts/research_package.py", + "research/historical-complex-ceiling-replay/VERIFY.json", + "research/historical-complex-ceiling-replay/verify.py"} + for card in FROZEN["cards"]: + required.update(card["starting_points"]) + required.add(card["first_step"]["command"][-1]) + for name in required: + path = root / name + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text("Inert reference for CLI validation only.\n") + for name in ("choose_research_task.py", "choose_current_research_task.py"): + shutil.copyfile(ROOT / "scripts" / name, root / "scripts" / name) + path = root / legacy["CATALOG"] + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text(json.dumps(FROZEN_CATALOG)) + path = root / "certificates/selected-result.json" + path.parent.mkdir(parents=True, exist_ok=True) + shutil.copyfile(ROOT / "certificates/selected-result.json", path) + yield root class CurrentResearchAssignmentTests(unittest.TestCase): - def test_every_frozen_card_and_other_fields_stay_exact(self): - before = copy.deepcopy(CATALOG) + def check_card_round_trips(self, catalog): + before = copy.deepcopy(catalog) resolved = 0 historical = 0 - for track in CATALOG["tracks"]: + for track in catalog["tracks"]: for task in track["tasks"]: - result = legacy["select"](CATALOG, "a1" * 16, task_id=task["id"]) + result = legacy["select"](catalog, "a1" * 16, task_id=task["id"]) original = copy.deepcopy(result) current.resolve_current_first_steps(result, ROOT) card = result["suggestions"][0] @@ -55,19 +94,25 @@ def test_every_frozen_card_and_other_fields_stay_exact(self): self.assertTrue(card.pop("first_step_resolution")) card["first_step"] = card.pop("catalog_first_step") self.assertEqual(result, original) - self.assertEqual(resolved, 16) - self.assertEqual(historical, 4) - self.assertEqual(CATALOG, before) + self.assertEqual(catalog, before) + return resolved, historical + + def test_frozen_routes_and_other_fields_stay_exact(self): + self.assertEqual(self.check_card_round_trips(FROZEN_CATALOG), (1, 1)) + + def test_every_live_card_and_other_fields_stay_exact(self): + self.assertTrue(CATALOG["tracks"]) + self.check_card_round_trips(CATALOG) def test_only_exact_generic_command_is_resolved(self): - result = copy.deepcopy(legacy["select"](CATALOG, "0" * 32, task_id="portable-replay")) + result = copy.deepcopy(legacy["select"](FROZEN_CATALOG, "0" * 32, task_id="portable-replay")) result["suggestions"][0]["first_step"]["command"].append("--historical-fixture") original = copy.deepcopy(result) self.assertEqual(current.resolve_current_first_steps(result, ROOT), []) self.assertEqual(result, original) def test_missing_current_helper_does_not_change_receipt(self): - result = legacy["select"](CATALOG, "0" * 32, task_id="portable-replay") + result = legacy["select"](FROZEN_CATALOG, "0" * 32, task_id="portable-replay") original = copy.deepcopy(result) with tempfile.TemporaryDirectory() as directory: with self.assertRaisesRegex(ValueError, "missing current first-step script"): @@ -82,7 +127,7 @@ def test_nonexact_scientific_commands_are_not_reinterpreted(self): ): with self.subTest(command=command): result = copy.deepcopy(legacy["select"]( - CATALOG, "0" * 32, task_id="centre-path-sharing")) + FROZEN_CATALOG, "0" * 32, task_id="centre-path-sharing")) result["suggestions"][0]["first_step"]["command"] = command original = copy.deepcopy(result) self.assertEqual(current.resolve_current_first_steps(result, ROOT), []) @@ -102,34 +147,52 @@ def test_missing_historical_reference_leaves_all_cards_unchanged(self): path = root / name path.parent.mkdir(parents=True, exist_ok=True) path.write_text("fixture\n") - result = legacy["select"](CATALOG, "0" * 32, task_id="portable-replay") + result = legacy["select"](FROZEN_CATALOG, "0" * 32, task_id="portable-replay") result["suggestions"] += legacy["select"]( - CATALOG, "0" * 32, task_id="centre-path-sharing")["suggestions"] + FROZEN_CATALOG, "0" * 32, task_id="centre-path-sharing")["suggestions"] original = copy.deepcopy(result) with self.assertRaises(ValueError) as raised: current.resolve_current_first_steps(result, root) self.assertIn(absent, str(raised.exception)) self.assertEqual(result, original) - def cli(self, script, args): - return subprocess.run([sys.executable, "-B", str(script), *args], cwd=ROOT, + def cli(self, script, args, root=ROOT): + return subprocess.run([sys.executable, "-B", str(root / "scripts" / Path(script).name), *args], cwd=root, capture_output=True, text=True, encoding="utf-8") def test_cli_preserves_legacy_output_and_emits_both_commands(self): - args = ["--seed", "0" * 32, "--task", "portable-replay"] - original = self.cli(LEGACY, args) - output = self.cli(ROOT / "scripts/choose_current_research_task.py", args) - self.assertEqual(original.returncode, 0) - self.assertEqual(output.returncode, 0) - old, new = json.loads(original.stdout), json.loads(output.stdout) - card = new["suggestions"][0] - self.assertEqual(card["first_step"]["command"], - ["python3", "-B", "scripts/research_selected_baseline.py"]) - self.assertEqual(card.pop("catalog_first_step"), old["suggestions"][0]["first_step"]) - self.assertTrue(card.pop("first_step_resolution")) - card["first_step"] = old["suggestions"][0]["first_step"] - self.assertEqual(new, old) - self.assertEqual(self.cli(LEGACY, args).stdout, original.stdout) + with frozen_cli_tree() as root: + args = ["--seed", "0" * 32, "--task", "portable-replay"] + original = self.cli(LEGACY, args, root) + output = self.cli(ROOT / "scripts/choose_current_research_task.py", args, root) + self.assertEqual(original.returncode, 0) + self.assertEqual(output.returncode, 0) + old, new = json.loads(original.stdout), json.loads(output.stdout) + card = new["suggestions"][0] + self.assertEqual(card["first_step"]["command"], + ["python3", "-B", "scripts/research_selected_baseline.py"]) + self.assertEqual(card.pop("catalog_first_step"), old["suggestions"][0]["first_step"]) + self.assertTrue(card.pop("first_step_resolution")) + card["first_step"] = old["suggestions"][0]["first_step"] + self.assertEqual(new, old) + self.assertEqual(self.cli(LEGACY, args, root).stdout, original.stdout) + + def test_live_cli_preserves_each_unmapped_command(self): + checked = {tuple(card["first_step"]["command"]) for card in FROZEN["cards"]} + for track in CATALOG["tracks"]: + for task in track["tasks"]: + command = tuple(task["first_step"]["command"]) + if command in checked: + continue + checked.add(command) + with self.subTest(task=task["id"]): + args = ["--seed", "0" * 32, "--task", task["id"]] + original = self.cli(LEGACY, args) + output = self.cli(ROOT / "scripts/choose_current_research_task.py", args) + self.assertEqual(original.returncode, 0, original.stderr) + self.assertEqual(output.returncode, 0, output.stderr) + self.assertEqual(json.loads(output.stdout), json.loads(original.stdout)) + self.assertEqual(self.cli(LEGACY, args).stdout, original.stdout) def test_help_and_error_preserve_child_status_and_output(self): for args, code in ((["--help"], 0), (["--unknown-option"], 2), (["--seed", "bad"], 2)): @@ -139,23 +202,24 @@ def test_help_and_error_preserve_child_status_and_output(self): self.assertEqual((output.stdout, output.stderr), (original.stdout, original.stderr)) def test_cli_distinguishes_current_orientation_from_historical_control(self): - args = ["--seed", "0" * 32, "--task", "complex-new-helper-inventory"] - original = self.cli(LEGACY, args) - output = self.cli(ROOT / "scripts/choose_current_research_task.py", args) - self.assertEqual(original.returncode, 0, original.stderr) - self.assertEqual(output.returncode, 0, output.stderr) - old, new = json.loads(original.stdout), json.loads(output.stdout) - card = new["suggestions"][0] - self.assertEqual(card["first_step"]["command"][2], "scripts/research_selected_baseline.py") - self.assertEqual(card["first_step"]["expected"], "PASS_RESEARCH_BASELINE_BINDINGS_ONLY") - follow_up, = card.pop("follow_up_steps") - self.assertEqual(follow_up["command"][-1], "research/historical-complex-ceiling-replay") - self.assertIn("historical", follow_up["scope"].lower()) - self.assertIn("cost law", follow_up["inspect"]) - self.assertTrue(card.pop("first_step_resolution")) - card["first_step"] = card.pop("catalog_first_step") - self.assertEqual(new, old) - self.assertEqual(self.cli(LEGACY, args).stdout, original.stdout) + with frozen_cli_tree() as root: + args = ["--seed", "0" * 32, "--task", "centre-path-sharing"] + original = self.cli(LEGACY, args, root) + output = self.cli(ROOT / "scripts/choose_current_research_task.py", args, root) + self.assertEqual(original.returncode, 0, original.stderr) + self.assertEqual(output.returncode, 0, output.stderr) + old, new = json.loads(original.stdout), json.loads(output.stdout) + card = new["suggestions"][0] + self.assertEqual(card["first_step"]["command"][2], "scripts/research_selected_baseline.py") + self.assertEqual(card["first_step"]["expected"], "PASS_RESEARCH_BASELINE_BINDINGS_ONLY") + follow_up, = card.pop("follow_up_steps") + self.assertEqual(follow_up["command"][-1], "research/historical-complex-ceiling-replay") + self.assertIn("historical", follow_up["scope"].lower()) + self.assertIn("cost law", follow_up["inspect"]) + self.assertTrue(card.pop("first_step_resolution")) + card["first_step"] = card.pop("catalog_first_step") + self.assertEqual(new, old) + self.assertEqual(self.cli(LEGACY, args, root).stdout, original.stdout) def test_sparse_historical_references_require_unchanged_head_entries(self): with tempfile.TemporaryDirectory() as directory: @@ -178,12 +242,12 @@ def git(*args): git("update-index", "--skip-worktree", *omitted) for name in omitted: (root / name).unlink() - result = legacy["select"](CATALOG, "0" * 32, task_id="coverage-law-change") + result = legacy["select"](FROZEN_CATALOG, "0" * 32, task_id="centre-path-sharing") self.assertEqual(current.resolve_current_first_steps(result, root), sorted(omitted)) # Ordinary deletion must not acquire the deliberate-sparse exemption. changed = omitted[-1] git("update-index", "--no-skip-worktree", changed) - result = legacy["select"](CATALOG, "0" * 32, task_id="coverage-law-change") + result = legacy["select"](FROZEN_CATALOG, "0" * 32, task_id="centre-path-sharing") original = copy.deepcopy(result) with self.assertRaises(ValueError): current.resolve_current_first_steps(result, root) @@ -208,9 +272,9 @@ def git(*args): git("-c", "user.name=Fixture", "-c", "user.email=fixture@example.invalid", "-c", "core.hooksPath=/dev/null", "commit", "-qm", "helper") git("update-index", "--skip-worktree", name); path.unlink() - result = legacy["select"](CATALOG, "0" * 32, task_id="portable-replay") + result = legacy["select"](FROZEN_CATALOG, "0" * 32, task_id="portable-replay") self.assertEqual(current.resolve_current_first_steps(result, root), [name]) git("update-index", "--no-skip-worktree", name) - result = legacy["select"](CATALOG, "0" * 32, task_id="portable-replay") + result = legacy["select"](FROZEN_CATALOG, "0" * 32, task_id="portable-replay") with self.assertRaisesRegex(ValueError, "missing current first-step script"): current.resolve_current_first_steps(result, root)