Repository navigation
Fix unreachable true-zero carve-out for provably empty tiny files - #506
Merged
Merged
Conversation
…alc_cog_load) Found via CodeQL's py/redundant-comparison + py/unreachable-statement alerts (#347, #349): `if safe_loc < 15: ... return 5.0, total_density` returns unconditionally for any 1-14 LOC file, so the later `if safe_loc <= 2 and total_density == 0: return 0.0, total_density` could never execute -- safe_loc is always >= 15 by the time execution reaches it. Every tiny file, including a provably empty stub (e.g. a near-blank __init__.py), was forced to a cognitive_load score of 5.0. The dead code itself documents the original intent: a truly empty <=2 LOC file shouldn't get even the small-file floor. Moved that exact check inside the reachable `< 15` branch rather than inventing new behavior, and removed the now-fully-dead duplicate below it. The carve-out only fires for tier1 languages (irc == 0) since irc feeds into total_density too -- tier2/3 files always carry a nonzero floor from irc alone. Verified against the language-crucible corpus in both zero-dependency and full-precision mode: exactly one file (rust/tokio/fuzz.rs, tier1) changed from a phantom 5.0% to a correct 0.0%, rippling into its directory/global averages. Regenerated both golden masters and added two unit tests (empty tiny file -> true 0.0, small file with real signal -> unchanged 5.0 floor). Full suite: 869 passed, 1 pre-existing xfail. Baseline regenerated for line-shift from removing the dead duplicate (no new findings). Co-Authored-By: Claude Sonnet 5 <[email protected]>
Contributor
2 tasks done
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
Found via CodeQL's
py/redundant-comparison+py/unreachable-statementalerts (#347, #349) while triaging the Security dashboard._calc_cog_loadhad:The second check can never execute -- by the time it's reached,
safe_loc < 15has already returned, sosafe_locis always>= 15, makingsafe_loc <= 2impossible. Every tiny file (1-14 LOC), including a provably empty stub (e.g. a near-blank__init__.py), was forced to a cognitive_load score of5.0regardless of whether it had any actual signal.The dead code documents its own original intent: a truly empty
<=2LOC file with zero measured signal shouldn't even get the small-file floor. Rather than inventing new behavior, I moved that exact check inside the reachable< 15branch (right after that branch computes its owntotal_density, before itsreturn 5.0), and removed the now-fully-dead duplicate below.The carve-out only fires for tier1 languages (
irc == 0) --ircfeeds intototal_densitytoo, so tier2/3 files always carry a nonzero floor fromircalone even with zero raw signals.Verification against the real corpus
Ran
test_golden_crucible.py -m golden_crucibleagainst thelanguage-cruciblecorpus in both zero-dependency and full-precision mode. Impact was exactly as narrow as expected: one file (rust/tokio/fuzz.rs, tier1) changed from a phantom5.0%Cognitive Load Exposure to a correct0.0%, rippling into its directory average and the global average. Regenerated both golden masters to reflect this.Test plan
test_signal_processor_empty_tiny_file_scores_true_zero-- a provably empty<=2LOC tier1 file scores0.0, not5.0.test_signal_processor_small_file_floor_still_applies-- a small file with real signal still hits the unchanged5.0floor (regression guard for the untouched behavior).pytest tests/-- 869 passed, 1 pre-existing xfail.pytest -m golden_crucible-- passes in both zero-dependency and full-precision mode against the regenerated golden masters.ruff check/ruff format --check: clean (baseline regenerated for line-shift from removing the dead duplicate; no new findings).🤖 Generated with Claude Code