fix(samples): de-overfit no_implicit_null_initial (inflector false positive) - #32
Closed
aspala wants to merge 1 commit into
Closed
Conversation
PR #30's action comment flagged inflector.ex detect_casing/1 (a pure cond-dispatch with no nil-initialization) as a CRITICAL no_implicit_null_initial block. Unlike the file-invariant phantoms fixed in #31, this was a genuine per-block outlier — caused by the same overfitting root cause: the behavior had ONE good/bad sample pair but a ~105-dimension scalar vector, so it matched dense cond/case blocks by chance. Added 3 good/bad Elixir sample pairs (pricing, session, router), each contrasting nil-init-then-branch (bad) against direct assignment via case/with/function results (good), and relearned the scalar vector via sample_report --apply-scalars (457 written, 148 deadzoned). Result: inflector.ex no_implicit_null_initial finding 0; the behavior still separates its samples cleanly (bad anti-aligns, good does not), so no real detections were lost. 884 tests, credo --strict clean.
aspala
added a commit
that referenced
this pull request
Jun 3, 2026
* fix(health-report): suppress false-positive per-block findings Combines the work from PRs #31 and #32 (their stacked base branch was squash-merged into main as #30, which orphaned them). Two false-positive classes from the action's own PR comment, both fixed: 1. File-invariant per-block phantoms: every block in health_report.ex got identical deltas (negated_boolean_name, single_responsibility, name_is_abbreviation) regardless of content. Root cause: leave-one-out cosine barely moves when a small block is removed from a large file, so each block inherited the file-level delta. Fix in TopBlocks: subtract the per-behavior file floor (min block delta, only when a file has >= 3 blocks) and dedupe exact-duplicate line ranges. 2. Overfit behaviors: negated_boolean_name, name_is_abbreviation, single_responsibility and no_implicit_null_initial each had 1-3 sample pairs but 70-105 scalar dimensions, matching unrelated code by chance. Added good/bad Elixir sample pairs and relearned the vectors via sample_report --apply-scalars. Separation ratios improved; behaviors still detect their own samples cleanly. Result on this codebase: health_report.ex critical blocks 10 -> 0, inflector.ex no_implicit_null_initial -> 0, all four phantom behaviors 0. Remaining block findings are real (line_length). 884 tests, dialyzer clean, credo --strict clean. * chore(combined-metrics): sync language coverage and scalar vectors [skip ci] --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
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.
Problem
PR #30's action comment flagged
lib/codeqa/metrics/file/inflector.ex:32-45— thedetect_casing/1function, a purecond-dispatch with regex guards — as a CRITICALno_implicit_null_initialblock. There is nonil-then-assign anywhere in it.Unlike the file-invariant phantoms fixed in #31 (every block of a file getting the same delta), this was a genuine per-block outlier — the relative-delta floor from #31 correctly let it through because it does stand out. The real cause is upstream.
Root cause
Same overfitting as #31: the
no_implicit_null_initialbehavior had one good/bad sample pair but a ~105-dimension scalar vector. Learned from a single data point, the vector encodes the quirks of that one file and matches densecond/caseblocks by chance.Fix
Added 3 good/bad Elixir sample pairs (
pricing,session,router), each contrasting:x = nilthenif … do x = … endacross branchescase/with/ function resultsRelearned the scalar vector via
sample_report --apply-scalars(457 written, 148 deadzoned). No engine code changed — consistent with the de-overfit approach.Result
inflector.exno_implicit_null_initialfinding: 0bad/loader.exsample anti-aligns,good/loader.exdoes not. No real detections lost (this codebase has no genuine nil-init-then-assign, which is idiomatic-Elixir-untypical).884 tests,
credo --strictclean.Stacked on #31 (base
fix/sample-overfitting-false-positives).