Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions services/clustering/backend/app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,15 @@ class Settings(BaseSettings):
# construction and a re-cluster reproduces the same DBSCAN-noise. Below the
# floor, drift is treated as STRUCTURAL (not staleness): recluster_recommended
# returns False and the scheduler stops the ~60s auto-refit loop (see
# model_unclusterable). Observed coverage: ~0.16 uniform/tight, ~0.43
# heavy-tail, ~0.88 a healthy dominant-mode fit, so 0.5 separates the
# pathological fits from the healthy one. Raising it only treats MORE fits as
# un-clusterable (fewer re-fits, more honest UI): recall-safe, since classify +
# anomaly scoring run every tick regardless.
min_cluster_coverage: float = Field(default=0.5, ge=0.0, le=1.0, alias="MIN_CLUSTER_COVERAGE")
# model_unclusterable). Calibrated on mainnet 2026-07-23: the degenerate
# stablecoin-validator fits cluster at 0.52 (Strike) and 0.58 (Djed at a 2000
# window), both with drift pinned at ~1.0 and a re-fit reproducing the same
# noise; a genuinely healthy fit (Djed at a ~1100 window) sits at 0.97. 0.6
# falls in the wide empty gap between those two regimes, so it gates the
# pathological fits while leaving healthy ones clusterable. Raising it only
# treats MORE fits as un-clusterable (fewer re-fits, more honest UI): recall-
# safe, since classify + anomaly scoring run every tick regardless.
min_cluster_coverage: float = Field(default=0.6, ge=0.0, le=1.0, alias="MIN_CLUSTER_COVERAGE")

# Number of transactions whose (tx, utxos) pairs are fetched concurrently
# within a page during ingest. Admission is still serialized by the token
Expand Down
29 changes: 28 additions & 1 deletion services/clustering/backend/tests/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@

from typing import Any

from app.config import get_settings
from app.config import Settings, get_settings
from app.service.scheduler import _decide

# Real mainnet fit coverages observed 2026-07-23 (see config.min_cluster_coverage):
# the two degenerate stablecoin-validator fits vs a genuinely healthy one.
_COV_STRIKE_DEGENERATE = 0.522
_COV_DJED_DEGENERATE = 0.578
_COV_DJED_HEALTHY = 0.97

_NOW = 1_000_000_000 # fixed clock; tests offset last_fit_at relative to it


Expand Down Expand Up @@ -99,3 +105,24 @@ def test_legacy_unknown_coverage_behaves_as_before() -> None:
deploy changes nothing until the first fit records a real coverage (self-heal)."""
c = _contract(drift_score=_high_drift(), fit_coverage=-1.0, last_fit_at=0)
assert _decide(c, get_settings(), now=_NOW) == ("onboard", 1)


def test_default_floor_gates_degenerate_fits_but_not_healthy_ones() -> None:
"""Calibration lock: the shipped default (0.6) must classify the observed
degenerate stablecoin fits (0.52, 0.58) as un-clusterable while leaving a
healthy fit (0.97) clusterable. Guards against silently drifting the floor back
below the degenerate regime (which would re-enable the futile re-fit loop) or
above the healthy regime (which would suppress legitimate re-clusters)."""
s = Settings()
assert s.model_unclusterable(_COV_STRIKE_DEGENERATE)
assert s.model_unclusterable(_COV_DJED_DEGENERATE)
assert not s.model_unclusterable(_COV_DJED_HEALTHY)


def test_default_floor_stops_strike_style_tight_loop() -> None:
"""End-to-end at the real Strike numbers: drift pinned at 1.0 with coverage 0.522
and a recent fit must fall through to classify, not the ~60s re-fit loop it did
before the floor was raised. (It still re-baselines once per slow interval, per
test_unclusterable_rebaselines_on_slow_cadence.)"""
c = _contract(drift_score=1.0, fit_coverage=_COV_STRIKE_DEGENERATE, last_fit_at=_recent())
assert _decide(c, Settings(), now=_NOW) == ("classify", 0)
Loading