Skip to content

File archetype classification silently truncates the feature vector on length mismatch #3126

Closed

Description

@squid-protocol

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, ci

On 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_NAMES order 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

Activity

  1. added
    bug
    ml-ops
    core-engine
    priority: high
    on Sep 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcore-engineml-opspriority: high

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions