Repository navigation
Description
The incident this exists to prevent
In v2.8.0 the engine's live archetype vector, the frozen model, and the offline trainer were in three different feature spaces:
| artifact | dims | trained/built on |
|---|---|---|
engine live vector (signal_processor.py) |
83 | v2.8.0 |
frozen GENERAL_FILE_INFERENCE_MODEL |
115 | v2.7.0 data |
cluster_files.py trainer |
186 | v2.8.0 data |
The engine logged Archetype dimension mismatch … skipping classification, so file_archetype and file_fingerprint came back Unclassified for effectively every code file — verified on a redox v2.8.0 scan at 80/104 Unclassified with empty fingerprints. It shipped that way.
The cause: the trainer's feature construction and the engine's vector construction were never pinned to one shared spec, and drifted across versions. Resolved for the FILE level in v2.8.1 (PR #3061) by porting the FUNCTION level's self-describing-brain pattern and moving classification into record_keeper (Phase 12.0), so the engine now builds its vector strictly in the model's FEATURE_NAMES order.
History: #1157 (function level, 5 of 62 dims compared), #1158 (file level, 115-dim model vs 83-dim live vector), #1159 (repo level), epic #1160.
The gap
That fix was structural — it makes one class of drift harder. The detection is still entirely manual: nothing algorithmically verifies that the artifacts baked from gitgalaxy-population-analyses still agree with the engine that consumes them. The parity contract exists only as a documented procedure in the train-archetypes skill — a human reading a checklist. Nothing fails a build.
This issue is about the check, not the port. (The deferred per-language port is #3085.)
What crosses the repo boundary — four artifacts, two families
All trained in gitgalaxy-population-analyses/kmeans_clustering, all consumed here.
Inference brains, inlined as Python dicts in gitgalaxy/standards/analysis_lens.py:
| model | line | state (verified) |
|---|---|---|
GENERAL_FUNCTION_INFERENCE_MODEL |
:1634 |
38-D, self-describing — FEATURE_NAMES, FEATURE_WEIGHTS, CAP_VALUES, DNA_SOURCES, SCALER_MEDIANS, SCALER_IQRS |
GENERAL_FILE_INFERENCE_MODEL |
:2412 |
83-D, self-describing since v2.8.1 (same full key set) |
SPECIFIC_FILE_INFERENCE_MODEL |
:4366 |
NOT on the pattern — confirmed, not assumed. Its top-level keys are five languages (python, javascript, typescript, c, cpp); each sub-dict carries only SCALER_MEDIANS, SCALER_IQRS, ARCHETYPES_K6. No FEATURE_NAMES anywhere, so there is no ordered contract to check against at all. Matches #3085's description of the deferred per-language model |
Composition brains, JSON in gitgalaxy/standards/archetype_brains/: file_archetype_brain.json and repo_archetype_brain.json, loaded at analysis_lens.py:33-34.
Why the existing guards are insufficient — four holes, all verified
1. The runtime dimension guard is a symptom detector, not a parity check. signal_processor.py:210-227 warns once per (vector-length, centroid-length, archetype-name) tuple and returns "Unclassified", 0.0, {} rather than truncating. That is correct behaviour — but it fires during a customer's scan, after shipping, and degrades quietly. Which is precisely how v2.8.0 got out the door.
2. Dimension parity is not semantic parity. If the engine still emits N features but one feature's computation changes — a different denominator, cap, or scaling — the dimensions match perfectly, no guard fires, and every classification silently shifts. control_flow_ratio is a live example of a feature whose denominator is an open question (the #2770 Phase 4 item). Nothing today would catch that.
3. A silent-zero fallback makes a renamed feature invisible. The self-describing file-vector builder _classify_file_archetype (gitgalaxy/recorders/record_keeper.py:254) iterates for i, fn in enumerate(fb["FEATURE_NAMES"]) (:271) through a chain of if fn == … / elif fn.startswith(…) branches ending in a bare else: v = 0.0 (:289-290). If the trainer renames or adds a feature the engine's builder does not recognise, that feature silently contributes a zero column. The vector length still matches the brain's, so a dimension guard would never fire, and the classification is quietly wrong instead of loudly absent. Same failure class as the v2.8.0 incident, in its most invisible form, live today.
4. (Found while verifying the above — not in the original report.) The v2.8.1 replacement path silently truncates, exactly as the pre-#1157/#1158 code did. In the same function, the nearest-centroid loop is:
# gitgalaxy/recorders/record_keeper.py:296-300
for ci, cen in enumerate(fb["centroids"]):
d = 0.0
for j in range(min(len(vec), len(cen))): # <-- silent truncation
diff = vec[j] - cen[j]
d += diff * diffsignal_processor.py contains no min(len(...)) comparison at all — it refuses to classify instead, which is what #1157/#1158 changed it to do. So the two live classification paths disagree on the core safety property: the old path refuses on a length mismatch, the new Phase 12.0 path silently compares the overlap and returns a confident label. The scaler lookups immediately above it hide the same mismatch (m = med[i] if i < len(med) else 0.0, and likewise for iqr/wts, :291-293).
This means hole 3 is understated as originally framed: in this path there is no dimension guard to evade, because there is no dimension guard.
Split out as its own bug: #3126. Fixing it removes this hole from the parity gate's scope — the gate still needs to cover holes 1-3.
The ask: an algorithmic, pre-release parity gate
Candidate mechanisms for the implementer to weigh — recorded, deliberately not pre-decided:
(a) Feature-contract hash. The trainer bakes a feature_contract_sha over the ordered FEATURE_NAMES plus weights, caps, DNA_SOURCES and scaler params; the engine recomputes it at load and fails/warns on mismatch. Catches renames, reorders and re-scalings cheaply. Does not catch a semantics change behind an unchanged name.
(b) Canary vectors — the strong option. The trainer bakes a handful of committed fixture files together with the exact feature vectors it computed for them at training time; CI re-runs the engine over those fixtures and asserts elementwise equality within epsilon. Catches semantic and scale drift automatically with no human discipline required, and is the only proposal here that would have caught holes 2, 3 or 4.
(c) Quantile-range runtime canary — nearly free. The composition brains already carry aux_quantiles per aux feature. If observed feature values at scan time fall systematically outside the ranges the brain was trained on, the feature's scale has drifted; emit a real diagnostic instead of classifying confidently. Uses data already present in the artifact.
(d) Remove the silent-zero fallback (and, per hole 4, the truncating comparison). Make an unrecognised FEATURE_NAME a hard error at brain-load or vector-build time — or at minimum a named warning identifying the offending feature — never a 0.0 column.
(e) Cross-repo CI. gitgalaxy-population-analyses records the engine commit it trained against; gitgalaxy CI validates every committed brain against the engine at HEAD, so a PR that changes a feature's computation fails loudly against the shipped artifacts rather than silently reinterpreting them.
Scope and sequencing
- Not self-contained in this repo. The freeze/emit step lives in
gitgalaxy-population-analyses, so (a), (b) and (e) all need a paired change there. Say so in the plan rather than discovering it mid-implementation. - Closely coupled to Archetype brains carry no training provenance #3124 (brain provenance). Provenance answers "what produced this artifact"; parity answers "does the current engine still agree with it". Both want an engine-commit field baked at freeze time — whoever picks up either should look at both.
- Nativeness conformance scoring: measure generated output against real-language archetype distributions #3123 raises the stakes. Once archetypes become a conformance authority over generated code, a silent feature drift stops being an internal metrics bug and becomes a wrong verdict delivered to a customer about their migration.
Related
#1157 / #1158 / #1159 / epic #1160 (the incident), #3085 (the deferred per-language port — this issue is the check, not that port), #3124 (provenance, shares the engine-commit field), #3123 (the conformance use that makes drift customer-visible), #2770 (control_flow_ratio's open denominator question).
Activity
fix(archetypes): refuse an inconsistent FILE brain instead of classif…
Archetype-brain provenance + trainer/engine parity gate (#3124, #3125) (