Skip to content

Fix unreachable true-zero carve-out for provably empty tiny files - #506

Merged
squid-protocol merged 1 commit into
mainfrom
fix-cog-load-unreachable-tiny-file-check
Jul 26, 2026
Merged

squid-protocol merged 1 commit into
mainfrom
fix-cog-load-unreachable-tiny-file-check

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Summary

Found via CodeQL's py/redundant-comparison + py/unreachable-statement alerts (#347, #349) while triaging the Security dashboard.

_calc_cog_load had:

if safe_loc < 15:
    ...
    return 5.0, total_density

...

if safe_loc <= 2 and total_density == 0:
    return 0.0, total_density

The second check can never execute -- by the time it's reached, safe_loc < 15 has already returned, so safe_loc is always >= 15, making safe_loc <= 2 impossible. 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 of 5.0 regardless of whether it had any actual signal.

The dead code documents its own original intent: a truly empty <=2 LOC 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 < 15 branch (right after that branch computes its own total_density, before its return 5.0), and removed the now-fully-dead duplicate below.

The carve-out only fires for tier1 languages (irc == 0) -- irc feeds into total_density too, so tier2/3 files always carry a nonzero floor from irc alone even with zero raw signals.

Verification against the real corpus

Ran test_golden_crucible.py -m golden_crucible against the language-crucible corpus 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 phantom 5.0% Cognitive Load Exposure to a correct 0.0%, rippling into its directory average and the global average. Regenerated both golden masters to reflect this.

Test plan

  • Added test_signal_processor_empty_tiny_file_scores_true_zero -- a provably empty <=2 LOC tier1 file scores 0.0, not 5.0.
  • Added test_signal_processor_small_file_floor_still_applies -- a small file with real signal still hits the unchanged 5.0 floor (regression guard for the untouched behavior).
  • Full suite: 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

…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]>
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol
squid-protocol merged commit 4effc88 into main Jul 26, 2026
27 checks passed
@squid-protocol
squid-protocol deleted the fix-cog-load-unreachable-tiny-file-check branch July 26, 2026 04:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant