Skip to content

metrics: add small-file smoothing to _calc_documentation density - #1100

Merged
squid-protocol merged 1 commit into
mainfrom
issue-1098-documentation-loc-smoothing
Aug 6, 2026
Merged

squid-protocol merged 1 commit into
mainfrom
issue-1098-documentation-loc-smoothing

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Summary

  • Fixes [BUG/METRICS] documentation_risk lacks LOC-smoothing, causing up to 8.4x tier1-vs-tier3 divergence at small files #1098: _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).
  • Added a loc_smoothing tuning constant (default 20.0, matching _calc_safety's laplace_smoothing) to the density denominator, mirroring the pattern already used by _calc_safety (laplace_smoothing) and _calc_concurrency/_calc_state_flux (loc_padding).
  • Added the secondary fix noted in the issue: an early if risk_hits == 0: return 0.0 guard, 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 with irc=0 and no other risk signal) carried a spurious ~11.92 score from the sigmoid's asymptotic floor at density=0, instead of a true zero.
  • Registered loc_smoothing: 20.0 in RISK_EQUATION_TUNING["documentation"] in analysis_lens.py alongside 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 true 0.0 now 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's irc=0 by 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.
  • Golden masters re-blessed via python tests/tools/update_golden_master.py --yes (both tests/golden_master_audit.json and tests/golden_master_zero_dep_audit.json): all 572 diffs in each are documentation-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.json line numbers shifted from added lines, regenerated as pure line-shifts.
  • Full pytest tests/ suite passes (6583 passed, 2 skipped, 11 xfailed, 3 xpassed).

Test plan

  • python tests/tools/audit_risk_equations.py --equation documentation shows reduced tier divergence, no direction violations
  • python tests/tools/crucible_check.py passes both modes
  • Golden masters re-blessed and committed
  • python tests/tools/audit_check.py clean
  • Full test suite passes

🤖 Generated with Claude Code

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

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol
squid-protocol merged commit ff6c8b2 into main Aug 6, 2026
28 checks passed
@squid-protocol
squid-protocol deleted the issue-1098-documentation-loc-smoothing branch August 6, 2026 15:06
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.

[BUG/METRICS] documentation_risk lacks LOC-smoothing, causing up to 8.4x tier1-vs-tier3 divergence at small files

1 participant