Repository navigation
Description
Task
T-070b· Milestone M6 — Analysis + risk · Size S · Priority P0 · Epic #6Implements FR-ANA-001
Branch
feat/t-070b-failureclusterer-hdbscan-with-min-cluster— one task = one branch = one PR (doc 32 §6)
Summary
Implement analysis/clustering.py: HDBSCAN(min_cluster_size=max(floor, ⌈fraction·n_fail⌉), metric='euclidean', cluster_selection_method='eom'); noise points kept as 'unclustered'; n_fail < 6 ⇒ provisional modes grouped by failure class.
Context / motivation
Unknown number of modes with arbitrary shapes and explicit noise is exactly HDBSCAN's strength (ADR-0012).
Scope
In scope
ClusteringResult(labels, probabilities, outlier scores).HdbscanSettingsmodel incore/settings/analysis.pywith the two new keys documented in doc 27 §4.8 (generated reference via T-003c).
Implementation guidance
- Module
roboprobe/analysis/clustering.py; interface per doc 05 §7:class FailureClusterer: def __init__(self, settings: HdbscanSettings) -> None; def fit(self, F: FeatureMatrix) -> ClusteringResult. min_cluster_size = max(analysis.hdbscan.min_cluster_size_floor, ceil(analysis.hdbscan.min_cluster_fraction * n_fail));min_samplesdefaults tomin_cluster_size(settinganalysis.hdbscan.min_samples: int | None, new).- Use
sklearn.cluster.HDBSCAN(metric="euclidean", cluster_selection_method="eom", store_centers=None)(scikit-learn ≥ 1.3; no separatehdbscanpackage — keeps the dependency set lean, ADR-0012). ClusteringResult(frozen):labels: NDArray[int](−1 = noise),probabilities,outlier_scores(GLOSH, computed via1 - probabilitiesfallback if not exposed),method: Literal["hdbscan", "class_fallback"],min_cluster_size.- Small-n fallback: if
n_fail < analysis.hdbscan.min_failures_for_clustering(new, default 6) group byprimary_failureand mark modes provisional (ClusteringResult.provisional=True). - Determinism: HDBSCAN is deterministic for fixed input order — sort rows by
run_idbefore fitting and map labels back. - Log
analysis.clusteredwithn_fail,n_clusters,n_noise,method,duration_ms(doc 21 §5.1). - Standards: respect the layering contracts (doc 16 §2) and conventions in doc 34; no hard-coded tunables — thresholds/defaults come from typed settings (doc 27); no magic numbers (ruff
PLR2004); public APIs typed (mypy strict) and documented.
Configuration keys
From the configuration reference (doc 27). Keys marked (new) must be added to the typed settings models and appear in the generated reference (T-003c).
analysis.hdbscan.min_cluster_fractionanalysis.hdbscan.min_cluster_size_floor- analysis.hdbscan.min_samples (new)
- analysis.hdbscan.min_failures_for_clustering (new)
Acceptance criteria
- Synthetic Gaussian blobs: ARI ≥ 0.9 (doc 18 §4.6).
- Fallback path tested.
- n_fail = 0 ⇒ empty result, no exception.
- Fallback groups exactly by failure class and sets
provisional=True. - Label assignment invariant under input row permutation (test).
- Runs in < 1 s for 2 000 failures (benchmark marker).
- Tests listed below added and green in CI; coverage of new code meets the gate in doc 18 §3.
- Docs, config reference and CHANGELOG
Unreleasedupdated where behaviour, keys or interfaces changed. - Definition of Done (doc 32 §3) satisfied.
Tests required
tests/unit/analysis/test_clustering.py.- Property test: labels length = n rows; −1 allowed only for noise.
- Benchmark test
@pytest.mark.benchmarkfor 2 000 rows.
Dependencies
Blocked by: #126 (T-070a)
Blocks: #128 (T-103), #129 (T-071a), #130 (T-071b)
Parallelization notes
Files / paths owned by this task — avoid editing other paths; shared files (pyproject.toml entry points, cli/main.py, api/routers/__init__.py, router.tsx, docker/compose.yaml, ci.yml) are append-only:
backend/src/roboprobe/analysis/clustering.py
Small.
Definition of Done
Per doc 32 §3 and AGENTS.md §5: lint, format, mypy strict and import-linter green; tests added and passing; docs updated; PR template completed with Closes #<this issue>; Conventional Commit messages referencing T-070b (doc 16 §6); commits authored only by the repository owner identity (AGENTS.md §4); CI green; reviewer checklist (doc 32 §5.1) satisfied.
References
Design docs: doc 09 §3.2 · doc 18 §4.6 · ADR-0012 · doc 21 §5.1
Requirements: FR-ANA-001 (traceability: doc 28)
External:
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsBacklog
Activity