Repository navigation
metrics: add small-file smoothing to _calc_documentation density - #1100
Merged
Merged
Conversation
_calc_documentation's density calc divided net_exposure by raw loc with no smoothing floor, unlike its siblings (_calc_safety's laplace_smoothing, _calc_concurrency/_calc_state_flux's loc_padding). Since irc contributes additively and flatly to risk_hits, this let irc dominate density at tiny files, producing up to 8.4x tier1-vs-tier3 divergence for identical documentation evidence at 10-20 LOC vs a modest 1.2-1.7x at 150-500 LOC. Add a loc_smoothing tuning constant (20.0, matching _calc_safety's laplace_smoothing default) and a risk_hits == 0 early-return guard so a genuinely risk-free file returns a true 0 instead of the ~11.92 sigmoid floor, matching the zero-return convention already used by _calc_safety/_calc_concurrency/_calc_graveyard/_calc_secrets_risk. Golden masters re-blessed: this shifts documentation_risk scores down for small tier2/tier3 files in the corpus, which is the point (previously inflated by the unsmoothed small-file denominator). ruff_audit_baseline.json line numbers shifted from the added lines; no new findings. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Contributor
12 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
_calc_documentation()was the only tier-aware equation among the audit group for epic Epic: Systematically audit tier-aware risk equations in signal_processor.py #1056 with no small-file smoothing term in its density calc, causing up to 8.4x tier1-vs-tier3 divergence for identical documentation evidence at 10-20 LOC files (vs 1.2-1.7x at typical 150-500 LOC sizes).loc_smoothingtuning constant (default 20.0, matching_calc_safety'slaplace_smoothing) to the density denominator, mirroring the pattern already used by_calc_safety(laplace_smoothing) and_calc_concurrency/_calc_state_flux(loc_padding).if risk_hits == 0: return 0.0guard, matching the zero-return convention already used by_calc_safety/_calc_concurrency/_calc_graveyard/_calc_secrets_risk. Previously a genuinely risk-free file (e.g. tier1 withirc=0and no other risk signal) carried a spurious ~11.92 score from the sigmoid's asymptotic floor atdensity=0, instead of a true zero.loc_smoothing: 20.0inRISK_EQUATION_TUNING["documentation"]inanalysis_lens.pyalongside the other tunable constants (previously only referenced via.get()default, which the dead-key auditor correctly flagged as a read with no producer).Verification
tests/tools/audit_risk_equations.py --equation documentation(added in tools: add direct-invocation tier-parity audit harness for epic #1056 #1097): tier2-vs-tier3 magnitude divergence at small LOC drops substantially (e.g. loc=10/hits=1: 8.38x → within the tier2/tier3 pair). Tier1 correctly floors at a true0.0now rather than the ~11.92 sigmoid artifact — the audit tool's "some tiers see signal, others see none" inf-ratio case is expected here since tier1'sirc=0by design (explicit-typed languages carry no baseline opacity risk). No direction violations, matching the required tier1 <= tier2 <= tier3 monotonicity.python tests/tools/crucible_check.py— both full-precision and zero-dependency modes pass.python tests/tools/update_golden_master.py --yes(bothtests/golden_master_audit.jsonandtests/golden_master_zero_dep_audit.json): all 572 diffs in each aredocumentation-exposure decreases for small files across the corpus, which is the intended effect of the fix.python tests/tools/audit_check.py(ruff/mypy/dead-key/format) — all clear;ruff_audit_baseline.jsonline numbers shifted from added lines, regenerated as pure line-shifts.pytest tests/suite passes (6583 passed, 2 skipped, 11 xfailed, 3 xpassed).Test plan
python tests/tools/audit_risk_equations.py --equation documentationshows reduced tier divergence, no direction violationspython tests/tools/crucible_check.pypasses both modespython tests/tools/audit_check.pyclean🤖 Generated with Claude Code