Repository navigation
Description
Split out of #3125 (this is its hole 4). Found on the expunge/3101-taint-tracking checkout; the file is not rexx-affected, but worth a confirm on main before scoping.
The defect
_classify_file_archetype (gitgalaxy/recorders/record_keeper.py:254) is the Phase 12.0 path that PR #3061 / v2.8.1 made the primary file-archetype classifier. It has two independent mismatch-masking behaviours.
1. Silent truncation in the distance loop (:296-300):
best_i, best_d = -1, None
for ci, cen in enumerate(fb["centroids"]):
d = 0.0
for j in range(min(len(vec), len(cen))): # <-- overlapping prefix only
diff = vec[j] - cen[j]
d += diff * diff
if best_d is None or d < best_d:
best_d, best_i = d, ciOn a vector/centroid length mismatch this computes squared distance over the overlapping prefix only, picks the nearest centroid, and returns a confident label.
2. Silent scaler padding (:291-293):
m = med[i] if i < len(med) else 0.0
q = iqr[i] if i < len(iqr) and iqr[i] > 0 else 1.0
w = wts[i] if i < len(wts) else 1.0
vec.append(((v - m) / q) * w)A short scaler array yields a full-length vector whose tail features pass through unscaled and unweighted rather than raising. This is arguably the more insidious half: the vector length then looks correct to anything downstream, so even a length-based check would pass.
The other live classification path does the exact opposite
gitgalaxy/metrics/signal_processor.py:210-227 warns once per (vector-length, centroid-length, archetype-name) tuple and returns ("Unclassified", 0.0, {}). Its own comment states the principle in as many words (:222):
skipping classification rather than silently truncating
signal_processor.py contains no min(len(...)) construct anywhere — verified, zero occurrences. So the two live paths disagree on a core safety property, and the permissive one is the primary path for file archetypes.
Why priority: high
Refuse-don't-truncate is the principle established by #1157/#1158 in response to the v2.8.0 three-way feature-space incident (engine 83-D / frozen model 115-D / trainer 186-D), which produced Unclassified for ~every code file. The replacement path reintroduced the behaviour that principle exists to prevent.
Worse, the original incident was loud — everything came back Unclassified, and it was caught by inspecting a scan. This failure is silent by construction: a short or long brain produces plausible-looking archetype labels that nobody has any reason to question. Every downstream consumer of composition_file_archetype inherits the wrong label with no diagnostic anywhere — the repo-level rollup in classify_repo, the LLM brief's archetype sections, and the drift z-scores.
Note on how this got in
This is not an oversight so much as a load-bearing assumption. #3061's own description says:
Building the vector in
FEATURE_NAMESorder makes a dimension mismatch structurally impossible.
That is true of the vector the engine builds — but it holds only if the brain's centroids and scaler arrays (SCALER_MEDIANS, SCALER_IQRS, FEATURE_WEIGHTS) are themselves consistent with that same FEATURE_NAMES, and nothing checks that. A brain frozen with a mismatched centroid width or a short scaler array satisfies the PR's reasoning and still lands in exactly these two branches. (Closing that hole from the other side is what #3125 is for; this issue is about not classifying confidently when it happens.)
Ask
Bring the Phase 12.0 path to signal_processor's posture: on any length mismatch between the built vector, the scaler arrays, or a centroid, refuse with a warn-once diagnostic naming both lengths and the offending artifact, rather than truncating or padding.
The issue also needs an explicit decision on the scaler fallbacks in (2): do they become hard errors too, or is there a legitimate case for a short scaler array that should be documented instead? Pick one deliberately — the current state is neither.
Related
- Algorithmic parity gate between the population-analyses trainers and the engine's archetype vectors #3125 — the algorithmic parity gate. This bug is its hole 4; fixing it removes one of the four holes that gate would otherwise have to cover.
- fix(archetypes): classify file archetype from a self-describing brain, post-assembly #3061 — the PR that introduced this path (merged; this was not raised in its thread).
- Function-level K-Means archetype classification only compares 5 of the trained model's 62 dimensions #1157 / File-level K-Means archetype classification silently truncates against its own trained models (115-dim global vs. 83-dim live vector) #1158 — the incident that established the refuse-don't-truncate principle. Repo-level ecosystem_baseline clustering's feature vocabulary is stale -- 3 of 4 static-file archetype slots never populated #1159 and epic Epic: K-Means archetype clustering (function/file/repo) has drifted out of sync with its own live feature pipeline #1160 are the rest of that family.
Activity
fix(archetypes): refuse an inconsistent FILE brain instead of classif…
Archetype-brain provenance + trainer/engine parity gate (#3124, #3125) (