Repository navigation
Description
🛑 Problem Statement
function_data.func_archetype (and every function's in-RAM telemetry["archetype"]) is assigned
by a hand-rolled Euclidean nearest-centroid classifier in signal_processor.py:561-587,
independent of the shared _classify_archetype() helper the file-level classifier uses.
The live feature vector built for every function (signal_processor.py:562-568) has exactly
5 dimensions:
raw_vec = [
float(s.get("branch", 0)),
float(s.get("loc", 0)),
float(s.get("args", 0)),
float(s.get("keyword_density", 0.0)),
float(s.get("control_flow_ratio", s.get("cf_ratio", 0.0))),
]But the pre-trained model it's compared against -- GENERAL_FUNCTION_INFERENCE_MODEL in
analysis_lens.py:1253 (ARCHETYPES_K12, 12 clusters) -- has 62-dimensional
SCALER_MEDIANS, SCALER_IQRS, and centroid vectors. Confirmed by direct inspection:
func SCALER_MEDIANS len: 62
func arch key: ARCHETYPES_K12
func centroid count: 12
fxn_cluster_0 centroid len: 62
The distance loop at signal_processor.py:578:
dist = math.sqrt(sum((a - b) ** 2 for a, b in zip(scaled_vec, centroid)))uses zip(), which silently truncates to the shorter sequence -- so every function is classified
using only 5 of the 62 dimensions the model was actually trained on. ~92% of the trained
model's discriminating signal is discarded on every single classification. This isn't a crash
or an empty column (func_archetype is populated on every function) -- it's a confidently-wrong
label, which is worse: nothing signals the classification is untrustworthy.
🎯 Objective
Restore function-archetype classification to actually use the dimensions the model was trained
on (or retrain/ship a model matched to the 5 live features, if 5 was in fact always the intended
scope -- unclear which is true, needs an owner decision, see Acceptance Criteria).
🛠️ Proposed Implementation
- Decide the intended scope: either (a) the 5-feature live vector is a regression -- more
features used to be computed and fed in before some past refactor -- and needs to be restored,
or (b) the 62-dim model is legacy from a differently-scoped training run and needs to be
retrained against today's 5-feature (or intentionally-expanded) vector. Check git history
aroundGENERAL_FUNCTION_INFERENCE_MODEL's introduction and theraw_vecconstruction for
the answer. - Whichever direction is chosen, add a loud failure (not a silent
zip()truncation) when a
live feature vector's length doesn't match the model's trained dimensionality -- e.g.
raise/log an error and fall back to"Unclassified"rather than quietly comparing a truncated
vector. This is the same "silent schema drift" failure class as # [BUG/APPSEC] Fix Inert AI Guardrails (Schema Drift in Dev Agent Firewall) #101, AI/LLM detection sensor cluster (llm_api, llm_orchestrator, ai_tools, etc.) is entirely non-functional -- no rule ever produces these signals #313, tabs_vs_spaces conflates a lighthearted structural fact with a risk-exposure score -- move out of RISK_SCHEMA #1147, [Epic] Recurring pattern: keys read by a consumer that no producer ever writes #325 -- this
repo has hit it enough times that the guard is worth adding once, here, rather than
re-discovering the next drift by accident. - While fixing this, consider replacing the hand-inlined distance loop with the shared
_classify_archetype()helper (signal_processor.py:139-166) already used for file-level
classification, so there's one implementation of "K-Means nearest-centroid classify" instead of
two that can independently drift (echoes Two independent, disagreeing implementations of the same risk-scoring logic #249's "two disagreeing implementations" lesson).
✅ Acceptance Criteria
- Root cause of the 5-vs-62 mismatch identified and documented (regression vs. legacy model).
- Live feature vector and model dimensionality match, verified by a real test (e.g. assert
len(raw_vec) == len(GENERAL_FUNCTION_INFERENCE_MODEL["SCALER_MEDIANS"])). - A dimension mismatch between a live feature vector and its centroid model fails loudly
instead of silently truncating viazip().
Activity
squid-protocol commentedon Aug 9, 2026
Part of epic #1160 (K-Means archetype clustering drift, all 3 tiers).
Rosetta-governed 38-D function-archetype classifier (k=14) (#3016)
squid-protocol commentedon Sep 16, 2026
Following up now that the archetype tower work has landed: #3016 (merged 2026-09-14) went further than the guard added here in #1724 — it replaced
GENERAL_FUNCTION_INFERENCE_MODELoutright with a rosetta-governed 38-feature model (5 geometry + 33 pruned per-LOC densities) and rebuilt the live vector insignal_processor.pyto match it dimension-for-dimension, so function classification is no longer just guarded against the truncation bug — it's actually using the full feature space again (validated 20,000/20,000 against the offline labels per that PR's description).No action needed here; leaving closed. Noting it for the epic (#1160) record.
fix(archetypes): refuse an inconsistent FILE brain instead of classif…