fix(detector): catch LAST_CALL_REPLAY via flag/counter-only gate#12
Closed
SinatrasC wants to merge 1 commit into
Closed
fix(detector): catch LAST_CALL_REPLAY via flag/counter-only gate#12SinatrasC wants to merge 1 commit into
SinatrasC wants to merge 1 commit into
Conversation
Adds a fourth pass to detect_last_call_replay covering the case where the
saved-output replay is gated entirely on a module-level counter or flag,
with no identity comparison against the input — the smoking gun is that
the early-return path doesn't reference the input parameter at all.
Pattern caught:
_OUT = None
_N = 0
def custom_kernel(data):
global _OUT, _N
_N += 1
if _N > 1 and _OUT is not None:
return _OUT
_OUT = data.clone()
return _OUT
The new pass requires: a 'global' declaration in the entrypoint, at least
one declared global mutated by the body (counter increment or flag toggle),
an If whose test references those mutated globals but no parameter names,
no calls in the if-body, and a return rooted on a mutated global. All four
guards are needed — without them legitimate workspace allocators
(if _buf is None: _buf = torch.empty_like(data)) and shape-dispatch helpers
would false-positive.
Verified locally: catches counter_skip and first_call_init_lock; does not
trigger on workspace_alloc_lazy, plain_kernel, shape_dispatch_legit, or
global_compile_cache_legit.
KernelGuard Blue Evaluation
|
9 tasks
Collaborator
Author
|
Thanks for the KernelGuard Flywheel Campaign contribution. We are not merging this narrow variant separately because the consolidated rule-family implementation in #273 is the merge path for this detector area. |
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.
Summary
Targets red #11 (
COUNTER_SKIP_REPLAY) — submitted via the new flatPOST /v1/red-submissionsroute on production KG (kguard.sinatras.dev)and classified
validby the deployedkernelguard==0.2.2.Distinct from the identity-replay family (LAST_CALL_REPLAY classic, dict-keyed,
attribute-keyed): there is no
is-comparison between the input and a savedslot. The gate is purely a module-level counter/flag, and the early-return
path drops the input on the floor — that's the smoking gun.
Approach
Add a fourth pass to
detect_last_call_replay. It triggers only when ALLfour guards hold:
globalnames.(counter increment, flag toggle, output assignment).
Ifwhosetestreferences those mutated globals but does notreference any parameter name, and whose body has no real compute calls.
This is tight enough to avoid false-positives on:
if _buf is None: _buf = torch.empty_like(data)) — body has callsif data.shape[0] > 1024: ...) — test references parameterif _compiled is None: _compiled = torch.compile(...)) — body has callsKernelGuard-Red-Submission: 11
Test plan
counter_skip(red fix(detector): catch LAST_CALL_REPLAY via captured-state subscript/attribute #11) → flaggedLAST_CALL_REPLAY,should_filter=Truefirst_call_init_lock(sibling pattern) → flaggedworkspace_alloc_lazy,plain_kernel,shape_dispatch_legit,global_compile_cache_legit→ all stayvalidtests/test_replay_regressions.pyregression tests pass (excluding the pre-existingtest_configure_runtime_records_selected_profilefailure unrelated to detector logic)