Skip to content

feat(archetypes): retrain function/file/repo brains on the v2.9.0 corpus - #3196

Merged
squid-protocol merged 2 commits into
mainfrom
feat/retrain-archetypes-v2.9.1
Sep 19, 2026
Merged

squid-protocol merged 2 commits into
mainfrom
feat/retrain-archetypes-v2.9.1

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Retrains all archetype models on the fresh 739-repo v2.9.0 fleet scan (8.27 M functions, 1.49 M files) and bakes the new brains into the engine.

What changed

Model Result
GENERAL_FUNCTION_INFERENCE_MODEL k=14, re-labeled. 12 archetypes kept 1:1 (nearest-centroid on the aligned contract); "Tests & Verification" merged into "Annotated & Test Methods"; new "Stateful Encapsulated Methods" for the Encapsulated-Accessors split. Contract dropped log_density_token_mass (Rosetta governance) → 37-dim.
GENERAL_FILE_INFERENCE_MODEL k=18, 83-dim (now carries the 14 function-stoichiometry features from func_cluster_ratios).
file_archetype_brain.json k=15, refrozen, 100% self-consistent.
repo_archetype_brain.json k=7, refrozen, 100% self-consistent. feature_contract_sha re-pinned (composition features follow the retrained file archetypes).

DNA_SOURCES (the schema-stable feature→hit_vector mapping the trainer doesn't emit) is carried over from the prior brains, verified to cover every new feature.

Validation

  • Parity scan (original_doom, baked engine): no dimension mismatch, no Unclassified flood — func 748/748, file 146/146, composition 146/146; new labels flow through ("Stateful Encapsulated Methods", "Compute Cores Files"). Values changed vs main (= new clustering).
  • Detection accuracy unchanged: 1.0 determinable, no confusion (archetypes don't touch language detection).
  • Golden masters reblessed (both legs): all 12,727 diffs are archetype-driven — categorized, zero structural/language drift.
  • Full engine suite: 9681 passed; archetype parity 14/14 (repo feature_contract_sha updated deliberately per the intentional-change gate).

Notes

  • The analysis_lens.py diff is large because the two model dicts are machine-generated and were reformatted on regeneration — the semantic change is just those two constants.
  • Corpus must be re-scanned with this engine for the new archetype values to appear in output DBs (old DBs don't self-update).
  • Reproducible trainer artifacts (.txt/.csv/.json) land in a companion gitgalaxy-population-analyses PR.

🤖 Generated with Claude Code

Retrained all archetype models on the fresh 739-repo v2.9.0 fleet scan
(8.27M functions, 1.49M files) via the population-analyses trainers:

- GENERAL_FUNCTION_INFERENCE_MODEL: k=14, re-labeled (12 archetypes kept 1:1
  by nearest-centroid on the aligned contract; 'Tests & Verification' merged
  into 'Annotated & Test Methods'; new 'Stateful Encapsulated Methods' for the
  Encapsulated-Accessors split). Feature contract dropped log_density_token_mass
  (Rosetta governance) -> 37-dim. DNA_SOURCES carried over from the prior brain
  (schema-stable engine->hit_vector mapping the trainer does not emit).
- GENERAL_FILE_INFERENCE_MODEL: k=18, 83-dim (now includes the 14 function
  stoichiometry features from func_cluster_ratios). DNA_SOURCES carried over.
- file_archetype_brain.json (k=15) + repo_archetype_brain.json (k=7): refrozen,
  both self-validate at 100%. repo feature_contract_sha re-pinned (composition
  features follow the retrained file archetypes) with engine review.

Parity: a real scan classifies func/file/composition/repo with no dimension
mismatch and no Unclassified flood (func 748/748, file 146/146, composition
146/146 on original_doom). Detection accuracy unchanged (1.0, no confusion).
Golden masters reblessed -- all 12,727 diffs are archetype-driven, no
structural/language drift. Full engine suite 9681 passed; archetype parity 14/14.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol

Copy link
Copy Markdown
Owner Author

Process notes — this retrain took far longer than it should have

Recording the friction so the next archetype retrain is a fraction of the effort. Ranked by payoff.

1. The corpus DB was on the HDD → the rollup was I/O-bound (biggest single cost)

master_db_updater.py --update function_clusters/rollup_function_clusters does millions of SQLite UPDATEs on the ~5.5 GB corpus DB. On the spinning disk this was a seek storm — identical 100k-row chunks took 4 s to 124 s (30× swing = disk, not CPU), and the function rollup alone took ~43 min. Moving the DB to NVMe cut the entire files→apply→rollup→freeze tail to ~3.5 min.

  • Fix: stage master_db_v<v>.db on NVMe (or any SSD) before the rollup, not after. Ideally the trainer/updater should PRAGMA-tune for bulk writes (one transaction, journal_mode=OFF/MEMORY during the batch update) and/or warn when the DB is on rotational storage.

2. There is no single "retrain" entry point — it's ~10 manual, order-sensitive steps

The real order is: merge → train functions → label functions → master_db_updater function_clusters → rollup_function_clusters → re-fit files → apply_file_clusters → rollup_file_clusters → freeze → (per-language) → bake. The skill documents a simplified version that diverges from this (e.g. it doesn't mention that func_cluster_ratios must exist before the file fit/freeze, which cost a wasted premature file fit).

  • Fix: commit a single retrain.sh / Makefile target that runs the whole tower with set -e and per-stage verification. I hand-rolled exactly this (retrain_master.sh) — it should live in the repo.

3. The trainer doesn't emit DNA_SOURCES, but the engine needs it → the bake is a manual merge

DNA_SOURCES maps each log_density_<x> feature to its runtime hit_vector key, and 31/33 (func) + 55/55 (file) of those are non-identity remaps (struct_branch → branch). The trainer reads DB columns by feature-name directly so it never needs the mapping — but pasting the emitted brain over the engine constant drops it, and the engine then reads zeros → garbage/Unclassified. I carried it over from the prior brain by hand.

  • Fix: make the trainer emit DNA_SOURCES (it's schema-stable; the mapping lives in the feature-governance config). Then the bake is a clean paste, matching the skill's "self-describing brain" ideal that functions/files are supposed to follow.

4. cluster_names re-mapping across a re-fit is manual and easy to get wrong

k-means cluster IDs aren't stable across fits, so the 14 curated function names have to be re-mapped to the new centroids. I did it with an optimal (Hungarian) assignment on the aligned FEATURE_NAMES contract — which also surfaced a real taxonomy shift (a split + a merge) that needed a human call.

  • Fix: a --relabel-from <old_brain> flag on the function trainer that does the nearest-centroid remap and prints the mapping + low-confidence/ collision warnings for review.

5. Smaller papercuts

  • Inconsistent flags: cluster_functions.py --clusters (plural) vs cluster_files.py --cluster (singular). Standardize.
  • The bake itself is a hand-edit of a 5000-line file. I wrote a bake.py (splice the two model dicts by brace-matching, merge DNA_SOURCES, copy the frozen JSONs, print the new feature_contract_sha to pin). Worth committing next to the skill.
  • pprint output isn't ruff format-clean — the regenerated model dicts failed ruff on first push. The bake script should ruff format the file as its last step.
  • The golden re-bless + feature_contract_sha bump are always required after a retrain (12,727 archetype-driven golden diffs here) — bundle them into the retrain flow rather than discovering them at PR CI time.

Net

The clustering itself was fast and clean (freeze self-validated at 100%). Nearly all the wall-clock went to (a) the HDD I/O and (b) reconstructing an end-to-end runbook the tooling doesn't encode. Items 1–3 would turn a multi-hour, error-prone session into roughly a one-command, ~15-minute run.

@squid-protocol
squid-protocol merged commit 44ffeb1 into main Sep 19, 2026
30 checks passed
@squid-protocol
squid-protocol deleted the feat/retrain-archetypes-v2.9.1 branch September 19, 2026 13:15
squid-protocol added a commit that referenced this pull request Oct 2, 2026
…#4105)

* feat(archetypes): graded per-level validation + drift harness (#4100)

The archetype brains are retrained offline far less often than the engine
changes, so labels are allowed to drift ahead of a retrain -- but no longer
unseen. Each level of the function -> file -> composition-file ->
composition-repo tower now carries a trust state (VALIDATED / DRIFTING /
UNVALIDATED / DEGRADED / INVALID):

- archetype_parity: live structural checks incl. cross-level label-vocabulary
  parity (which the per-brain gate could not see), brain fingerprints, and
  validation_status() combining them with the shipped record.
- archetype_brains/archetype_validation.json: trained-at engine/corpus,
  per-level agreement with the trained state, eroding archetypes, open
  retrain issue, history. Agreement is stability, not accuracy.
- INVALID levels are withheld ("Unvalidated"); withholding depends only on
  the brains, never on the auto-refreshed record.
- tests/tools/archetype_drift.py + tests/archetype_trained_baseline.json
  (crucible labels at the #3196 trained-against engine, 44ffeb1).
- Golden Crucible job: one shared scan feeds the golden diff and a
  report-only drift summary. archetype-validation.yml re-measures on main,
  opens a record PR for review when a number moves, and opens/updates/closes
  one archetype-retrain issue.
- LLM brief section 0 + audit forensic trail report the state (the audit
  block is sanitized from golden diffs like a timestamp).

Found and now flagged: the composition brain reads pre-#3196 function labels
(DEGRADED), and the repo brain's inputs share no label with the composition
brain (INVALID -> repo composition archetype withheld).

Golden masters re-blessed: 8 diffs per mode, all the withheld repo
composition archetype (Hub-Coupled Monorepo -> Unvalidated, z 5.592 -> 0.0).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* fix(#4100): make multi-line strings explicit for CodeQL implicit-concatenation alerts

Hoist render_issue's multi-line strings to named constants and build
structural problems via _problem(), so no list/tuple element relies on
implicit string concatenation.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

---------

Co-authored-by: Joe Esquibel <[email protected]>
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant