Repository navigation
Description
Found by the length-leak check added to keyword-rosetta's bias_report.py in gitgalaxy#2669 F.1. Design pass requested (T1), in the #2655 shape: no engine edit until the shape is approved.
What the check does
The rosetta corpus is one 12-probe program written in 46 languages, at 46 lengths (coding_loc from 4 to 19 lines per file; every shell is under the 50-line evidence-mass floor). For each derived metric, take the languages whose measured inputs for that metric are all inside the green band (content held equal) and that share the engine's scoring tier (_get_tier; the tier-3 languages are largely the short shells, so without this a tier effect reads as a length effect), and rank-correlate the metric against coding_loc. With content and tier held, length is the only thing left to vary, so a strong correlation means the formula is reading length where it should be reading content.
Threshold: |Spearman rho| ≥ 0.6 over ≥ 8 languages. Engine a334839, corpus main, 2026-09-04.
What it found
| metric | languages (tier3) | rho | inputs held in band | where length enters |
|---|---|---|---|---|
func_internal_density |
11 | −0.96 | branch, args, func_start | avg_func_complexity / avg_func_loc (record_keeper.py ~L487) — the denominator is length by construction |
avg_func_loc |
29 | +0.92 | func_start | loc / functions_found — length by definition |
control_flow_ratio |
21 | −0.67 | branch | branch / (branch + structural_boundaries) (detector.py ~L1288); structural_boundaries is a per-language token tally that grows with the file |
Weak (0.4 ≤ |rho| < 0.6), reported but not asserted: risk_cognitive_load −0.58 (n=8), risk_tech_debt −0.58 (n=16), cog_raw −0.55 (n=9), risk_verification +0.48 (n=25, no LOC term located), classes_found −0.41 (n=31, nothing held). Note that cog_raw read −0.63 before tier was held equal and dropped to weak after: most of what looked like a length leak there was #2653's irc / mass_loc term. Everything under _mass_loc (cog load, safety, state flux, tech debt) is floored at 50 by #2655, so no rosetta shell should carry a length term through those densities at all — the residual weak correlations are either an unheld input (concurrency, reflection_metaprogramming are not cached) or the per-file mean over four files, and are worth a look but are not the finding.
Why it matters
These three are the per-function morphology descriptors the bias report scores as "the engine describing one program differently depending on the language it is written in". For avg_func_loc that description is tautological: a per-function line count is length, and the corpus cannot plant it. For func_internal_density the same length sits in the denominator, so a language that writes the same 13 probes in fewer lines is reported as denser logic. For control_flow_ratio the branch count is planted at 3 while the denominator is a vocabulary tally that scales with the file — #2689 bucket B already established that planting structural_boundaries cannot equalise it.
On the real-world corpus the same thing holds one level up: two files with identical branch and argument structure score differently on all three purely by line count, which is the length-dependence #2655 removed from the risk densities but not from these recorder-side descriptors.
Options (for the design pass)
- Reclassify as length. Treat
avg_func_locas a size measure (it is), and the bias report demotes it to the context group besidecoding_loc. Cheapest, but does nothing for the other two. - Floor the per-function denominators the way UEF small-file normalization isn't achieving its intent — redesign scoring so identical intent scores identically regardless of file size (design pass for Fable) #2655 floored the per-file ones.
func_internal_density = avg_comp / max(avg_loc, F)with a per-function evidence floor;control_flow_ratioovermax(branch + boundaries, F'). Same doctrine as_mass_loc, moves golden masters for every function under the floor. - Redefine
control_flow_ratioagainst a planted-able denominator. Branch per function (avg_func_complexityalready exists) or branch per structural boundary kind rather than per boundary token. Changes the metric's meaning; needs the wiki 08-xx pages updated. - Leave the engine alone, ledger the three metrics corpus-side as length-derived. Honest for the rosetta gate, but leaves the real-world length dependence in place.
Recommendation to evaluate first: (2) for func_internal_density, (1) for avg_func_loc, and a decision between (3) and (4) for control_flow_ratio, since #2689 already showed its denominator cannot be planted.
Corpus side
keyword-rosetta PR (F.1/F.2) carries the check, the tiers map in docs/bias_data.json, and the table above regenerated on every corpus push. The three metrics' rosetta cells keep whatever verdict they have today; this issue does not change the gate.
Related: #2655 (evidence-mass floor — the per-file half of this), #2689 (bucket B: structural_boundaries is unplantable), #2653 (tier constants — the confound the check now holds equal), #2669 (Batch F).
Activity
squid-protocol commentedon Sep 4, 2026
Design pass done (2026-09-04). No engine edit yet — this is the shape for approval, in the #2655 pattern.
Recommendation: option 2 for
func_internal_density, option 4 forcontrol_flow_ratiowith the cause restated, option 1 already shipped foravg_func_loc. The two are not the same defect and should not get the same fix: one is a real per-function density with no floor, the other is not a length leak at all.Measurements below are against engine
a334839andtests/golden_master_audit.json(2817 files, 2291 with signals, 45422 functions — the real-world corpus, not rosetta).1.
avg_func_loc— closed, no engine changeOption 1 shipped as keyword-rosetta#49:
avg_func_locandcomment_linesjoinedCONTEXT_METRICS, andfunc_internal_densitynow declaresavg_func_locin itsDERIVED_INPUTS.avg_func_lochas dropped out of the leak table. Nothing owed here.2.
func_internal_density— floor the denominator (option 2),F = 12The floor value follows #2655's own derivation
#2655 set
EVIDENCE_MASS_FLOOR = 50because the golden-master mediancoding_locis 51 — the floor sits at the corpus median, so it neutralises the small-file regime and leaves the median-and-up regime byte-identical. The per-function analog on the same corpus:coding_locavg_func_locSame derivation, same calibration. Proposed:
FUNC_EVIDENCE_MASS_FLOOR: 12inanalysis_lens.ENGINE_CONSTANTSbesideEVIDENCE_MASS_FLOOR, andrecord_keeper.pyL487 becomes(the
avg_loc > 0guard folds into themax).What it does to the rosetta gate
Every rosetta shell's
avg_func_locis ≤ 5.69 (groovy, the longest), so every language is in the count regime andfunc_internal_densitybecomesavg_func_complexity / 12— an exact rescale of a planted-signal descriptor.coding_loc(n=11, tier3,branch/args/func_startheld)The floored column's out-of-band set is identical to
avg_func_complexity's, which is the point: the metric stops reporting length and reports the branch structure the SPEC actually plants.func_internal_densityis currently aderivedcell, so this changes no--gateverdict — the 91 unexplained stay 91.What it does to real code
Contained, and in the direction the doctrine predicts:
72.3% of files are untouched at F=12 (the floor is the identity for them). The movers are exactly the small-function inflation cases:
formula_installer.rb1.50 → 0.50, and fivefind*.sqlfiles at a flat 1.00 → 0.08 (functions averaging one line, one branch each). Median mover sits at 0.196 today and loses 0.060.Blast radius: smaller than it looks, because the metric is half-dead
func_internal_densityis not in either pre-trained ML vector — not the 5-dim per-function archetype vector (branch, loc, args, keyword_density, control_flow_ratio) and not the file-levelraw_vector. It reaches exactly two places: thefile_dataDB column, andsecurity_auditor.pyL385.And that second one never fires.
signal_processorbuildstelemetry_payloadwithfunc_complexity_gini(L849) but never writesfunc_internal_density— it is computed only insiderecord_keeperwhile writing the row. Sosecurity_auditor.py:385'stel.get("func_internal_density", 0.0)has always fallen through to0.0for every file: a permanently-zero column in the security training frame, the same shape as theprompt_injection/agentic_rceplaceholders documented atanalysis_lens.pyL1105. Worth filing separately — it is a pre-existing bug, not caused by anything here, and it means the floor's only live consumer is the DB column and the reports.So the bless is 574 file rows plus topology, no archetype drift.
3.
control_flow_ratio— option 3 is not safe, and length is not the causeOption 3 has the #1020 blast radius
cfris a pre-trained ML feature in two scoring paths:signal_processorL601 — the per-function archetype vector's 5th component, scaled againstGENERAL_FUNCTION_INFERENCE_MODEL'sSCALER_MEDIANS/SCALER_IQRSand matched to fixed centroids;signal_processorL665 — the file-levelraw_vector, which carries bothcfrandlog_logic_loc(logic_loc = coding_loc × cfr), againstself.SCALER_MEDIANSandGLOBAL_ARCHETYPES;control_flow_x1000inSAT_SCHEMA.Redefining the metric moves the feature's distribution wholesale against models trained on the old one. Measured on the golden master for the most natural redefinition (
branch / max(coding_loc, 50)— the #2655-consistent branch density):logic_locmedian 15 → 4, which moveslog_logic_loctoo;That is precisely the failure
analysis_lens.pyL1099-1112 records from #1020: "massivefile_cluster_N/Repository Archetype drift, not just the intended removal". The comment there guards against reordering the schema; the same models are just as sensitive to rescaling a feature in place. Rejecting option 3 on that evidence — and note the redefinition otherwise looks great on the gate (consistency 30% → 69%, rho −0.673 → +0.000), which is exactly the trap.The cause is vocabulary breadth, not length
structural_boundariesis not a boundary count. It is a per-language keyword tally, and the language definitions differ in breadth, not just in verbosity:soliditymatches every type token —uint\d*,int\d*,bytes\d*,address,bool,string,mapping, pluspragma|import|contract|…perlmatches everymy;javaeveryvar,new,return;pythoneverydef|class|return|import|from|as|pass|…schemematches three forms (let|let*|letrec|begin|do);yamlsix literal keys;makefileassignment lines onlyOn the identical 12-probe program, back-calculated mean
structural_boundariesruns 4.0 (makefile) to 65.2 (solidity) — 16×, whilecoding_locspans 4 to 18.75 — 4.7×. Length cannot account for the spread. On real code the same thing shows as a 9× spread in the growth rate: medianstructural_boundaries / coding_locis 0.047 in powershell, 0.112 in cobol, 0.264 in rust, 0.433 in lua.So
cfr = planted / (planted + vocabulary_tally)is a hybrid of a planted signal and a member of the F.1 verbosity family. It can never be cross-language consistent, and it is the weakest column in the report at 30% consistency (32/46 out of band) for that reason — not because of length.The −0.67 length correlation is the shadow:
structural_boundariesdoes track length within a language (rho 0.69–0.95 in every one of the 21 languages with ≥15 real files), and rosetta pinsbranchat 3, so the ratio has to fall as the shell gets longer.The real-world claim in the issue body holds, with a caveat
Marginally,
cfrrises with length on real code (rho +0.03 to +0.75 by language) becausebranchgrows faster thanstructural_boundaries. Run rosetta's own test instead — hold language and exact branch count and correlate againstcoding_loc:rho = −0.591 over 512 real files, 10 languages, 44 strata. Cobol −0.47, python −0.90, shell −0.50, assembly −0.64, groovy −0.75, lua −0.77. So the effect is real and about the size rosetta reports (−0.67); it just is not visible without holding branch.
Recommendation
Option 4, with the cause named correctly, plus nothing new in the engine. A length-and-vocabulary-invariant "how much of this program is control flow" descriptor already exists and is already gated:
avg_func_complexity— 67% consistent, leak rho +0.30 over the same 21 languages, reads the planted branch count directly. The gate should read branch shape through it;cfrstays what it actually is, a pre-trained ML feature with a language-specific denominator.Corpus side that would follow (keyword-rosetta, F.3 or its own PR):
control-flow-ratio-vocabulary-denominatoror similar —signal: branch|control_flow_ratio, covering the 32 out-of-band cfr cells, citing Design (D.1): shape-descriptor comparability — the 160 cells decompose into five mechanisms, only 15 of which are a real design question #2689 (the denominator is unplantable) and this issue for the 16× breadth measurement.bias_report.pychange solength_leaksreports this as a vocabulary leak rather than a length leak when the denominator is a registry token tally — otherwise the row reappears at every regen with the wrong cause on it.If you would rather keep the engine honest here anyway, the only safe form is an additive one: emit
branch / _mass_loc(coding_loc)as a new telemetry key and leavecontrol_flow_ratiountouched, so no trained vector moves. That is more surface for a descriptoravg_func_complexityalready covers, so I am not recommending it — but it is the option that gets the invariance without the #1020 risk.Decisions requested
func_internal_density: floor atFUNC_EVIDENCE_MASS_FLOOR = 12— yes/no, and is 12 the right value (the table above is the sensitivity)?control_flow_ratio: ledger it as a vocabulary-denominator deviation (recommended), or add the additive branch-density key, or redefine anyway and re-train?security_auditordead-feature find — file as its own bug, or fold into the same PR?Related: #2655, #2653, #2689, #1020 (the ML feature-layout precedent), #2669 Batch F, keyword-rosetta#49.
squid-protocol commentedon Sep 4, 2026
Decisions (epic owner, 2026-09-04):
func_internal_density: floor atFUNC_EVIDENCE_MASS_FLOOR = 12— approved. Same corpus-median derivation as UEF small-file normalization isn't achieving its intent — redesign scoring so identical intent scores identically regardless of file size (design pass for Fable) #2655; the out-of-band set becomes identical toavg_func_complexity's and 72% of real files do not move. Keep 12 rather than a lower value: a lower floor moves fewer rows but abandons the rule that made UEF small-file normalization isn't achieving its intent — redesign scoring so identical intent scores identically regardless of file size (design pass for Fable) #2655 defensible. The wiki page must say plainly that below the floor the column is a rescale ofavg_func_complexity.control_flow_ratio: option 4 — ledger, cause = vocabulary. Nothing new in the engine: no additive key (surface with no consumer,avg_func_complexityalready covers it), no redefinition (the 71.5% move against two pre-trained vectors is the Remove AST-dependent Security & Vulnerability metrics (Injection, RCE, Memory) #1020 failure; the good-looking gate numbers are the trap). Corpus side: the ledger entry already exists —control-flow-ratio-denominator-is-a-vocabulary-tally, validated, 21 languages; the other 11 out-of-band cells inherit frombranch. The one owed action is the leak-check label:length_leaksshould report a formula whose denominator is a registry token tally as a vocabulary leak, so the row stops reappearing with the wrong cause. Small keyword-rosetta tools change, rides with F.3.security_auditorfeature: filed on its own, not fixed here. Populating the telemetry key would change an input to the security training frame for every file — a different blast-radius question from flooring a DB column, and the two must not share a bless.Engine PR follows: one constant, one recorder line, one test in the
test_uef_length_invariance.pyshape, the wiki sentence; golden-master bless (~574 rows + topology) with explicit go-ahead at the time.squid-protocol commentedon Sep 4, 2026
Implemented as #2715 (one constant, one recorder line,
tests/tools_recorders/test_func_internal_density_floor.py, wiki 08-03 paragraph). Dead-feature find filed as #2714.One correction to the design pass: no golden-master bless is owed.
crucible_check.pypasses in both venvs because the audit fixtures (tests/golden_master_*.json) carryRaw Cognitive Densitybut not the recorder'sfunc_internal_densitycolumn — the 574-row figure was measured on the scanfile_dataDB, which never reaches the fixture. So the PR is exactly as small as it looks, andcrucible-auditstays green.fix(recorders): floor func_internal_density's denominator at 12 lines…
fix(core-engine): shell reflection counts dispatch, not command subst…
fix(core-engine): dependency_density is coupling per line, not per co…