Skip to content

Measurement tiers (#2994): SURFACE_FAMILIES, snapshot percentiles, count relations — additive, legacy frozen - #2995

Merged
squid-protocol merged 8 commits into
mainfrom
feat/measurement-tiers
Sep 13, 2026
Merged

squid-protocol merged 8 commits into
mainfrom
feat/measurement-tiers

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Implements #2994 per the approved plan. Additive only — 1,348 insertions, zero deletions in legacy code paths; every risk_* value emitted byte-identically (golden-crucible triage: the single failing check reproduces identically on unmodified a1a2d717 — the known venv/networkx leg mismatch — with zero diffs touching risk/hit/telemetry).

Tier 1 — SURFACE_FAMILIES: 22 declarative families over 63/95 signals + SURFACE_FAMILY_EXEMPT (32, each with a reason), enforced by a partition contract test. Families sum raw counts — deliberately exempt from mitigation suppression (tested).
Tier 2 — _compute_snapshot_percentiles: Hazen average-rank, 35 series (22 fam + 13 vec), all-zero series → 0.0, N=1 → 50; runs immediately after _normalize_temporal_metrics (churn-ordering commented + tested).
Tier 3 — rel_guard_balance, rel_alloc_cleanup (count÷count, mechanism-documented).
DB: 59 new file_data columns (dynamic generation, _ensure_columns ALTER-heal for existing DBs, round-trip + heal tested). Brief: new §6b Surface Family Profile. Docs: the tier model in docs/vectors.md + wiki cross-ref; firewall 50.0-cutoff noted as future migration.

Verification: full suite 8,593 passed / 0 failed; ruff/mypy/dead-key audits clean (baseline regen = line-shifts only; 2 genuinely-new findings fixed in code); audit-recorder keyset-unchanged guard added. Live end-to-end: scanned db-tutorial with the branch — fam = Σ members exact over 1,884 checked cells, percentiles bounded with the all-zero rule confirmed in the wild (fam_crypto absent → pct 0.0), relations populated.

Zero tuned constants in any new measurement. Follow-ups on record: optional file-split of signal_processor (legacy vs tiers) as hygiene-only PR; gpu payload tier keys; firewall percentile migration.

Supersedes #2984/#2979 (closed). Evidence chain: #2991 → #2993 → #2994; epic #2982.

🤖 Generated with Claude Code

squid-protocol and others added 7 commits September 13, 2026 12:29
…alaxy#2994)

Tier 1 of the measurement-tier reform: a declarative {family: [signal, ...]}
map over SIGNAL_SCHEMA's 95 names, grouping 63 of them into 22 families
(memory, cleanup, guards, danger, concurrency, connectivity, io, crypto,
ipc, time, serialization, regex, events, tests, docs, debt, mutation,
dead_code, credential, threat, ml_ai, ui). The remaining 32 are declared
exempt in SURFACE_FAMILY_EXEMPT with a one-line reason each, in four
groups: structural-shape (11), style/naming (8), ownership (1), paradigm
(3), sec_* lens duplicates (7), always-zero placeholders (2).

Both are standalone top-level constants (not nested in RECORDING_SCHEMAS),
matching the existing ENGINE_CONSTANTS/APERTURE_CONFIG pattern.

tests/core_engine/test_surface_families_contract.py is the enforced
contract: every SIGNAL_SCHEMA name in exactly one family XOR exempt, every
member/exempt entry a real SIGNAL_SCHEMA name, no fam_*/pct_fam_*/pct_vec_*/
rel_* column collides with an existing file_data column, and the 22/63/32
reconciliation is pinned.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RS9yZk89DyCmECaARkBmdB
…entiles (gitgalaxy#2994)

Tier 1/3 (calculate_risk_vector, before the main return): sums raw_signals
(never the mitigation-suppressed exposure_vector -- families are "raw
truth by construction") into telemetry["surface_families"] per
SURFACE_FAMILIES, and derives telemetry["surface_relations"]:
  guard_balance_ratio = guards / (danger + 1)
  alloc_cleanup_pairing = cleanup / (memory + 1)
A suppressed legacy risk_safety_score can coexist with a nonzero `guards`
family total -- pinned by a dedicated suppression-interplay test.

Tier 2 (_compute_snapshot_percentiles, new method): ranks the 22 family
sums and 13 RISK_SCHEMA legacy-vector values into snapshot-relative Hazen
percentiles (pct = (avg_rank - 0.5) / N * 100, 2dp, ties -> mean rank).
All-zero series read 0.0 for every file (never a false-median 50); N=1
reads 50.0 for every series. Called from summarize_galaxy_metrics
IMMEDIATELY AFTER _normalize_temporal_metrics -- load-bearing ordering,
since Pass 2 rewrites risk_vector's churn slot in place and percentiles
must rank the post-normalization value. Writes
telemetry["surface_percentiles"] = {"fam": {...}, "vec": {...}}.

Both hooks are additive only: risk_vector/hit_vector/file_impact and the
summarize_galaxy_metrics return dict (the golden-mastered audit JSON) are
untouched.

The three early-return paths in calculate_risk_vector (critical-leak
override, minified override, literature override) do not compute
surface_families/surface_relations -- record_keeper.py's tel.get(...)
already defaults those to 0/0.0, so this is a deliberate scope decision
(single hook point, per the verified plan anchor) rather than an oversight.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RS9yZk89DyCmECaARkBmdB
… (gitgalaxy#2994)

Dynamic column generation, same pattern as risk_cols/hit_cols: 22
fam_<name> INTEGER, 22 pct_fam_<name> REAL, 13 pct_vec_<risk-slug> REAL,
and rel_guard_balance/rel_alloc_cleanup REAL -- 59 new file_data columns,
canonical order (families, then legacy-vector percentiles, then
relations) shared across the CREATE TABLE, the guarded-ALTER heal, and
the INSERT. folder_data is untouched.

New _ensure_columns(cursor, table, col_defs) helper generalizes the
existing guarded-ALTER precedent (is_zero_dependency_mode et al.) into a
loop, so a pre-#2994 database gets the new columns healed in via ALTER
TABLE ADD COLUMN instead of failing the INSERT.

The INSERT triple-edit (row_data, column list, CREATE) reads
tel.get("surface_families"/"surface_percentiles"/"surface_relations", {})
with 0/0.0 defaults, so files whose telemetry never computed tier values
(the early-return paths in calculate_risk_vector) still insert cleanly.

Tests: schema presence, data round-trip, missing-telemetry defaults, an
ALTER-heal round-trip test (drop one column from each of the four groups,
re-run, confirm both healing and correct values), and a direct unit test
of _ensure_columns's idempotency.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RS9yZk89DyCmECaARkBmdB
…2994)

Display-only section, directly below the legacy section 6 sigmoid table:
per-family repo total, files-with-signal count, P90 file value, and top
file, plus the two relations as repo medians. A percentile-semantics line
explains the snapshot-relative reading ("87" = 87th percentile of THIS
repo, not a calibrated risk threshold).

Nothing here is golden-mastered -- section 6 reads risk_vector (the
audit-recorder's hashed contract); this reads
telemetry["surface_families"/"surface_percentiles"/"surface_relations"],
which audit_recorder never touches (see the companion keyset-unchanged
guard test in test_audit_recorder.py).

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RS9yZk89DyCmECaARkBmdB
…metry (gitgalaxy#2994)

audit_recorder's output is hashed WHOLE by the golden-master corpus -- any
new key breaks every master. This test proves the enforced constraint:
adding telemetry["surface_families"/"surface_percentiles"/
"surface_relations"] to a file's raw pipeline state produces a
byte-identical audit_recorder JSON payload, because the recorder reads an
explicit whitelist of telemetry keys and never dumps the dict wholesale.
Belt-and-suspenders check that none of the new tier vocabulary
(fam_guards, rel_guard_balance, etc.) leaked into any key anywhere in the
payload.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RS9yZk89DyCmECaARkBmdB
…(gitgalaxy#2994)

Adds "The tier model" section to docs/vectors.md: the four-tier design
table, Tier 1 (SURFACE_FAMILIES, the raw-truth suppression semantics),
Tier 2 (snapshot percentiles, the Hazen formula, the all-zero-series-is-0
and N=1-is-50 rules, and a firewall 50.0-cutoff migration note --
supply_chain_firewall.py is unaffected by this reform, no code change),
Tier 3 (the two relations), where tiers surface, and the golden-master
constraint that keeps audit_recorder's output byte-identical. Cross-refs
gitgalaxy#2994 from the document's intro and References section.

docs/wiki/02-09-signal-processing.md (the file:line-verified home of
calculate_risk_vector/summarize_galaxy_metrics) gets a short pointer to
the new tier layer and a Related Components link to vectors.md.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RS9yZk89DyCmECaARkBmdB
…2994

signal_processor.py/record_keeper.py grew (new SURFACE_FAMILIES binding,
the tier-computation block, the _ensure_columns helper, the dynamic
column-gen/CREATE/INSERT additions), shifting every pre-existing baseline
finding below the insertion points. Regenerated per ruff_audit.py's
documented SCOPE & LIMITATIONS path (line numbers aren't stable baseline
keys); confirmed zero new rule violations beyond the shifts -- the two
genuinely new findings this branch introduced (an unused `# noqa: S608`
and a PERF203 on the new _ensure_columns loop) were fixed in code, not
baselined. Baseline count: 26 -> 22 (four pre-existing trailing-whitespace
findings were incidentally fixed by edits that touched their lines).

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RS9yZk89DyCmECaARkBmdB
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

CodeQL's unused-variable finding on the N=1 test exposed a real semantic
inversion: the count==1 branch preceded the all-zero check, so an absent
surface on a single-file snapshot read 50.0 -- exactly the "absent signal
must not read as mid-band" failure the all-zero rule exists to prevent.
Reordered: all-zero -> 0.0 at every N (including N=1); N=1 with a nonzero
value -> 50.0 unchanged. Docstring, docs/vectors.md rule text, and the N=1
test corrected (which also removes the unused idx_cog CodeQL flagged).

Co-Authored-By: Claude Fable 5 <[email protected]>
@squid-protocol

Copy link
Copy Markdown
Owner Author

CodeQL's unused-variable nit turned out to be load-bearing: the flagged test line sat next to a semantic inversion — the N==1 branch preceded the all-zero check, so an absent surface on a single-file snapshot read 50.0 (the exact mid-band lie the all-zero rule exists to prevent). Fixed with precedence swapped (all-zero → 0.0 at every N; N=1 nonzero → 50.0 unchanged), docstring + docs/vectors.md rule text aligned, test corrected (removing the unused variable). Targeted tests 106/106, ruff clean.

@squid-protocol
squid-protocol marked this pull request as ready for review September 13, 2026 16:42
@squid-protocol
squid-protocol merged commit 78a39c0 into main Sep 13, 2026
30 checks passed
@squid-protocol
squid-protocol deleted the feat/measurement-tiers branch September 13, 2026 16:42
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.

2 participants