Skip to content

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

Merged
squid-protocol merged 2 commits into
mainfrom
fix/4100-archetype-drift-harness
Oct 2, 2026
Merged

squid-protocol merged 2 commits into
mainfrom
fix/4100-archetype-drift-harness

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Closes #4100.

Why

The archetype brains are retrained offline (gitgalaxy-population-analyses) much less often than the engine changes, so labels are allowed to drift ahead of a retrain. Until now that drift was invisible. The golden master does diff archetype labels, but as an exact match that gets re-blessed wholesale: no tolerance, a baseline that moves on every bless, and archetype diffs buried among X/Y/Z noise behind a 50-line cap. Since the #3196 retrain, 85 re-blesses have accumulated 0.7% / 2.2% / 1.4% cumulative relabelling at the file, composition and function levels, and the crucible's repo archetype flipped. No PR ever showed that as a number.

The golden master had also blessed three structural breaks that the per-brain parity gate (#3125) cannot see, because it checks each brain in isolation:

  1. Function → composition label drift. The retrain renamed function labels (Annotated & Test Methods, Stateful Encapsulated Methods), but the composition brain still reads Annotated Framework Methods / Tests & Verification. Two input columns are always 0, and ~7% of crucible functions drop out of file composition.
  2. Composition → repo labels are disjoint. The repo brain's comp_archetypes are the k=18 file_cluster_N labels, while classify_repo counts composition labels. Every repo's composition sub-vector is all zeros.
  3. The k=18 file model ships unnamed file_cluster_N labels. This is recorded as a note, not a downgrade.

What this adds

Per-level trust state (archetype_parity.validation_status). Each level of the function → file → composition-file → composition-repo stack gets a state:

State Meaning Labels
VALIDATED ≥ 98% agreement with the trained state used
DRIFTING 95–98% used, drift reported
UNVALIDATED no measurement covers the loaded brain used, flagged
DEGRADED < 95%, or some inputs dead used, qualified; retrain issue
INVALID contract cannot be honoured withheld as Unvalidated

"Agreement" is the share of crucible code files the current engine labels the same way the engine the brains were trained against did. It measures stability, not accuracy: there is no ground-truth archetype.

  • Structural checks run live from the loaded brains, including new label-vocabulary parity between levels. Only these change scan output. Withholding never depends on the auto-refreshed record.
  • Record: archetype_brains/archetype_validation.json, shipped with the package. It holds the trained-at engine, commit and corpus, brain fingerprints, thresholds, per-level agreement and eroding archetypes, the open retrain issue, and a capped history.
  • Baseline: tests/archetype_trained_baseline.json, the crucible labels at the trained-against engine (44ffeb1e, v2.9.1, the feat(archetypes): retrain function/file/repo brains on the v2.9.0 corpus #3196 golden master). It moves only on rebaseline after a retrain.
  • Harness: tests/tools/archetype_drift.py (measure, issue-body, set-issue, rebaseline).
  • PR view (report-only): test_golden_crucible.py now shares one scan between the golden diff and a new test_archetype_drift_report, which writes "this PR vs recorded on main" to the job summary. It never fails on drift, only when the harness itself can't measure.
  • Main view: new archetype-validation.yml. After each push to main it re-measures, opens a PR refreshing the record only when a number moved (≥ 0.25 pp or a state change), and opens, updates or closes one archetype-retrain issue. The record PR is not auto-merged; it is left for review.
  • Reports: LLM brief section 0 rows per level; audit forensic trail "Archetype Validation" block (stripped in golden_diff.sanitize, like timestamps).

State today

Level State Agreement
function VALIDATED 98.6%
file VALIDATED (note: unnamed labels) 99.3%
composition_file DEGRADED (stale function labels) 97.8%
composition_repo INVALID → withheld n/a (inherits)

Golden master

Re-blessed against language-crucible v1.6.0. Each fixture has exactly 8 differences, all from the withheld repo composition archetype: Hub-Coupled Monorepo → Unvalidated and fit z 5.592 → 0.0, in Repository Composition Archetype, summary.repo_composition_*, repo_macro_species and Repository Ecosystem Baseline (Architecture). No file, function or composition label moved. The new forensic-trail "Archetype Validation" block is sanitized like a timestamp, so the fixtures don't store it and an automated record refresh can't make them stale.

Tests

  • tests/core_engine/test_archetype_validation.py: 26 tests covering states, propagation, withholding, record ↔ brain fingerprints, and the harness math.
  • test_archetype_parity.py: an uncomputable aux feature now yields the explicit Unvalidated label, with the same named warning.

Follow-up

The three structural breaks need a refreeze in gitgalaxy-population-analyses. Once this merges, the first archetype-validation.yml run on main opens the retrain issue that tracks them. The per-language SPECIFIC_FILE_INFERENCE_MODEL (per-file "File Archetype", N/A for 100% of files) is never applied and is out of this harness's scope; tracked separately.

🤖 Generated with Claude Code

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]>
@squid-protocol squid-protocol added data-integrity Issues relating to RAM state or SQLite database fidelity core-engine Modifications to the central physics and parsing engine labels Oct 2, 2026
@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

Comment thread tests/tools/archetype_drift.py Fixed
Comment thread tests/tools/archetype_drift.py Fixed
Comment thread tests/tools/archetype_drift.py Fixed
…atenation 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]>
@squid-protocol
squid-protocol merged commit 882a33b into main Oct 2, 2026
33 checks passed
@squid-protocol
squid-protocol deleted the fix/4100-archetype-drift-harness branch October 2, 2026 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core-engine Modifications to the central physics and parsing engine data-integrity Issues relating to RAM state or SQLite database fidelity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create a CI harness to auto-detect and mark archetype drift when changes break it

2 participants