Formal: Python/native classifier accuracy — both paths, vs CPython signal semantics - #1083
Merged
Merged
Conversation
…nal semantics Closes the classifier-accuracy gap (HANDOFF §7 step 5) and adds the per-thread comparison. Accuracy cannot be a bare theorem -- which branch is right depends on where the program truly was when the timer fired, observable only through CPython's signal-delivery semantics. So the module makes that an EXPLICIT hypothesis and proves exact correctness relative to it. SigDeliverySound (the hypothesis): CPython delivers a signal only at a bytecode boundary, so a timer firing inside a C call is deferred until return, leaving f_lasti at the CALL opcode. Hence atCall = true iff truly in a C call. A runtime + synchronous-stamping property, stated not proved -- the honest residual. Theorems: - worker_classifier_correct: the worker-thread bytecode classifier (_update_thread_stats:458) charges native EXACTLY the in-call samples, under the hypothesis. Exact, not approximate. - main_branchA_correct: the main-thread branch A (:256-275) is exact too. - main_worker_agree / main_worker_both_exact: THE COMPARISON -- in the shared regime (use_call_attribution true), both paths make byte-for-byte the same decision, so one correctness proof covers both call sites. - deferral_route_iff + deferral_formula_exact: the paths diverge exactly in virtual-time non-thread-sampled mode, where only the main thread has a virtual timer to measure deferral; that route is exact when native time shows up as timer-deferral (and the code's known blind spot otherwise). - misclassified_when_unsound / missed_when_unsound: if the hypothesis fails, the two-sided error is pinned down -- quantifying what SigDeliverySound buys. No sorry; standard axioms only. Full lake build green (8576 jobs). 17 modules / 142 theorems. STATUS.md, README (§17 + roundup), HANDOFF updated.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes the classifier-accuracy gap (HANDOFF §7 step 5) and adds the per-thread comparison.
sorry-free, standard axioms only; fulllake buildgreen (8576 jobs); 17 modules / 142 theorems.Accuracy can't be a bare theorem — which branch is right depends on where the program truly was when the timer fired, observable only through CPython's signal-delivery semantics. So this module makes that an explicit hypothesis and proves exact correctness relative to it.
The hypothesis —
SigDeliverySoundCPython delivers a signal only at a bytecode boundary, so a timer firing inside a C call is deferred until the call returns, leaving
f_lastiat the CALL opcode. HenceatCall = true ↔ truly in a C call. A CPython-runtime + synchronous-stamping property — stated, not proved. It is the honest residual.Theorems
worker_classifier_correct— the worker-thread bytecode classifier (_update_thread_stats,:458) charges native exactly the in-call samples under the hypothesis. Exact, not approximate.main_branchA_correct— the main-thread branch A (:256-275) is exact too.main_worker_agree/main_worker_both_exact— the comparison you asked for: in the shared regime (use_call_attributiontrue), the two paths make byte-for-byte the same Python/native decision, so one correctness proof covers both call sites.deferral_route_iff+deferral_formula_exact/deferral_formula_zero_when_no_excess— the paths diverge exactly in virtual-time, non-thread-sampled mode, where only the main thread has a virtual timer to measure deferral; that route is exact when native time shows up as timer-deferral (and the code's documented blind spot otherwise).misclassified_when_unsound/missed_when_unsound— if the hypothesis fails, the two-sided error is pinned down (false positive → native charged for Python; false negative → the reverse), quantifying whatSigDeliverySoundbuys.Docs
STATUS.md (classifier accuracy row⚠️ →✅-conditional; ⚠️ ), README §17 + roundup + boundary, HANDOFF module table + step 5 updated.
SigDeliverySoundas the residualFormal-only; no production code touched.