Skip to content

feat(metrics): evidence-mass floor replaces the UEF's six small-file guards (#2655) - #2667

Merged
squid-protocol merged 2 commits into
mainfrom
design/2655-uef-small-file
Sep 2, 2026
Merged

squid-protocol merged 2 commits into
mainfrom
design/2655-uef-small-file

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Resolves #2655

Problem

Every per-file risk score is a density (hits / LOC) pushed through a sigmoid. On the keyword-rosetta control corpus (identical planted intent in 46 languages, files of 3–29 coding LOC) one planted hit is 3–33% density and lands on the sigmoid ceiling, so file length, not content, decided the score. Six independent small-file guards had accreted to soften this, each firing on a different LOC range with a different shape, and they fought each other:

guard where effect on a tiny file
if safe_loc < 15: return 5.0 _calc_cog_load flat 5.0 then a cliff to full density at 15 — the whole python −76% / powershell +91% cog swing
loc + 20 Laplace pad safety, documentation halves the 5→40 LOC swing, never removes it (2.4× residual)
bureaucracy_dampener = min(loc/15, 1) caller, on doc/test/spec a second, linear length dependence stacked on the first — the css/html doc and spec ambers
irc / safe_loc cog load; flat +irc in doc/debt the tier-3 opacity floor grows as the file shrinks
max(total_loc, 10) api volume weight 6 public functions score 70 in 13 lines, 36 in 200
safe_mass_floor = 50 graveyard the one guard that already did the right thing

The corpus was rescanned (46 languages, 184 files) and every equation re-invoked directly from the scan DB's raw signals; the harness reproduces every stored score to 0.000, so the attributions in #2655 could be checked exactly. Two of them are not what they looked like: the config/DSL tech-debt swing is orphan/duplicate synthesis in main/b files (every c file scored exactly 100 in all 45 languages), and fortran's state-flux "inversion" is two saturated files averaged (one mutation in a 10-line c.f90 scores 87). Both are length saturation on top of §2 effects, not a formula inversion.

Root cause

There was no single small-file mechanism; density was being estimated from files far too short to estimate a density from, and each patch addressed one symptom on one LOC range.

Fix: the evidence-mass floor

One shared denominator, _mass_loc(loc) = max(coding_loc, ENGINE_CONSTANTS["EVIDENCE_MASS_FLOOR"] = 50), in every per-file density equation. Below the floor a file is scored on its counts — a 2-hit file is a 2-hit file whether it is 5 or 49 lines long — so identical intent scores identically at any length. From 51 lines up the density regime is byte-identical to before (the +20 pads and paddings are kept on top of the floor for exactly that reason). max is continuous, so there is no cliff. This is the per-file analog of the mass-weighted averaging the directory scope already applies, and it generalises graveyard's existing safe_mass_floor.

Two consistency rules ride along, both approved in the design pass:

  • Zero measured evidence scores zero. Irc corrects measured risk; it never creates it. Documentation returns 0 when there is no API surface and no load-bearing undocumented block (safety, tech debt, concurrency and state flux already followed this convention); cognitive load returns 0 for a branchless file at any length (was: only above 50 LOC, with a flat 5.0 below 15 — a cliff at 15 and a discontinuity at 50/51 for the same file). Spec alignment returns 0 for a file with no functions or classes (was a flat 100 hidden by the dampener).
  • The bureaucracy_dampener is removed. The floor is now the only small-file mechanism.

Files below the floor carry mass_floored: true and their evidence_mass in telemetry (option 1's flag, without option 1's neutral tier).

Why 50: it is the engine's existing unit of mass (file_impact = loc/50, graveyard's floor, the loc > 50 cog rule), every corpus file sits under it with 21 lines of headroom, and it splits the golden-master corpus at its median (1,299 of 2,624 scored files are under 50 coding LOC).

Options 2 (shrinkage — what safety/doc already did, 2.4× residual) and 3 (Wilson lower bound — still scales with 1/n; 2 hits give 0.057 at n=10 vs 0.014 at n=40, a wider swing) were evaluated and rejected; option 4 (density-scale Irc) is subsumed by the floor bounding irc/loc and is otherwise #2653's remit.

Evidence

Tests and audits

  • tests/core_engine/test_uef_length_invariance.py (new): invariance below the floor, continuity at it, parity at 51 LOC against values pinned from origin/main, tier ordering preserved in the count regime, zero-evidence rules, spec-needs-entities.
  • test_signal_processor_small_file_floor_still_applies (pinned the removed 5.0 floor) rewritten as ..._small_file_scores_on_counts plus ..._branchless_file_zero_cog_at_any_length.
  • tests/tools/audit_length_invariance.py (new): the length-axis twin of audit_risk_equations.py. Both audits pass; audit_check.py clean (ruff baseline regenerated for pure line shifts only).
  • Golden masters re-blessed via crucible_check.py --update --yes, both modes. A scoped diff over the per-file records (2,624 scored files, identical shape in both fixtures): 1,324 files under the floor moved (count regime, including 25 zero-coding-LOC files that were scored as 1 line); the only ≥50-LOC movements are the approved zero-evidence rules (documentation → 0 in 402 files with no API surface, spec → 0 in 146 files with no functions or classes) and the branchless cognitive-load rule at exactly 50 LOC (3 files); every other ≥50-LOC exposure is byte-identical (1,065 files untouched). 0 violations.

Docs

docs/wiki/08-03 gains the fifth UEF principle ("Evidence-Mass Floor"); 08-05, 08-08, 08-09, 08-16 formulas updated to the floored denominator; 08-14 rewritten to what _calc_api_exposure actually computes (the page described a 40/60 ratio-plus-volume blend the code never shipped; the api_exposure tuning keys are unread).

Cross-repo

🤖 Generated with Claude Code

squid-protocol and others added 2 commits September 2, 2026 12:15
…guards (#2655)

Every per-file density equation now divides by max(coding_loc, 50) instead of raw
LOC. Below the floor a file is scored on its counts, so identical planted intent
scores identically at any length; from 51 LOC up the density regime is
byte-identical to before (the +20 pads and paddings stay on top of the floor).
This one mechanism replaces the <15-LOC cognitive-load cliff, the loc/15
bureaucracy dampener, the unbounded irc/loc floor and api's max(total_loc, 10).

Consistency rules that ride along: zero measured evidence scores zero in every
tier (irc corrects risk, never creates it) for documentation and cognitive load;
a branchless file carries no cognitive load at any length (was: only >50 LOC,
with a 5.0 floor <15); spec alignment is 0 when there is nothing to specify.
Telemetry gains evidence_mass / mass_floored.

Evidence: on the keyword-rosetta corpus, groups of languages with identical
formula inputs now have 0.00 output range on all seven affected metrics (was up
to 77 points). New tests/core_engine/test_uef_length_invariance.py pins
invariance, continuity at the floor, parity at 51 LOC against origin/main, and
tier ordering; tests/tools/audit_length_invariance.py is the length-axis twin
of audit_risk_equations.py. Wiki 08-03/05/08/09/14/16 updated (08-14 now
documents the formula the code actually ships).

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…2655)

Both fixtures regenerated via crucible_check.py --update --yes. Scoped diff over
the per-file records: 1,324 files under the 50-LOC floor moved (count regime);
at >=50 LOC only the approved zero-evidence rules moved (documentation -> 0 in
402 files with no API surface, spec -> 0 in 146 files with no entities) plus the
branchless cognitive-load rule at exactly 50 LOC (3 files). 1,065 files are
byte-identical; 0 unexplained movements in either fixture.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@squid-protocol squid-protocol added enhancement New feature, sensor, or structural signature metrics Heuristics, risk exposures, and topological math updates core-engine Modifications to the central physics and parsing engine labels Sep 2, 2026
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol
squid-protocol merged commit 3ac9182 into main Sep 2, 2026
64 of 65 checks passed
@squid-protocol
squid-protocol deleted the design/2655-uef-small-file branch September 2, 2026 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core-engine Modifications to the central physics and parsing engine enhancement New feature, sensor, or structural signature metrics Heuristics, risk exposures, and topological math updates

Projects

None yet

1 participant