Repository navigation
Description
Task
T-070a· Milestone M6 — Analysis + risk · Size S · Priority P0 · Epic #6Implements FR-ANA-001
Branch
feat/t-070a-failurefeaturebuilder-weighted-parameter-class-one— one task = one branch = one PR (doc 32 §6)
Summary
Implement analysis/features.py building the per-failing-run feature matrix of doc 09 §3.1: normalised params (w_param), failure-class one-hot × w_class, trajectory features (s_fail/L, t_fail/T_max, min_clearance/d_norm, max_loc_error/e_max) × w_traj.
Context / motivation
'Same conditions + same kind of failure at the same place ⇒ same mode' — the feature design defines what a failure mode is.
Scope
In scope
FeatureMatrix(X, run_ids, column names) — internal analysis type (DataFrames allowed inside analysis, doc 34 §7).FeatureWeightstyped settings model (param,class_,traj) with validation> 0.FeatureDiagnostics(n_input, n_fail, n_excluded_invalid, missing_traj).
Implementation guidance
- Module
roboprobe/analysis/features.py(layer: domain — numpy/pandas only, no SQLAlchemy/FastAPI imports; import-linter enforces). - Interface (doc 05 §7):
class FailureFeatureBuilder: def __init__(self, weights: FeatureWeights) -> None; def build(self, runs: Sequence[RunRecord], space: ScenarioSpace) -> FeatureMatrix. FeatureMatrix(frozen dataclass inanalysis/types.py):X: npt.NDArray[np.float64]shape(n_fail, d + n_classes + 4),run_ids: tuple[UUID, ...],columns: tuple[str, ...],space_version: int.- Column blocks (doc 09 §3.1): (1)
space.normalize(values)for every enabled, unpinned parameter ×w_param; (2) one-hot ofprimary_failureoverFailureClassmembers in enum order ×w_class; (3) trajectory block ×w_traj:s_fail / L_nominal,t_fail / T_max,min_clearance / clear.d_norm,max_loc_error / loc.e_max— each clipped to [0, 1]. - Normalisers come from the run's resolved oracle thresholds snapshot (stored with the campaign) — never re-read global defaults, otherwise re-analysis after a config change silently changes modes.
- Only
verdict == FAILruns from phases other thanconfirmare included; INVALID runs are excluded and counted in the returned diagnostics. - Weights come from
AnalysisSettings.feature_weights(core/settings); missing trajectory metrics (e.g. analytic backend) ⇒ block filled with 0 anddiagnostics.missing_traj=True. - 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.feature_weights
Acceptance criteria
- Hand-computed feature rows for 3 synthetic runs.
- Weights honoured from config.
- Pinned parameters are excluded from the parameter block (test with a pinned space).
- Changing
analysis.feature_weightsvia env (ROBOPROBE_ANALYSIS__FEATURE_WEIGHTS__TRAJ=0) scales the block — verified by test. - Builder is pure: same inputs ⇒ byte-identical
X(hash test). - mypy strict + import-linter green (no infrastructure imports).
- 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_features.py.- Property test (Hypothesis): all features ∈ [0, max(weight)]; row count equals FAIL count.
- Factory-built
RunRecords (tests/factories.py) — no DB.
Dependencies
Blocked by: #61 (T-011a), #34 (T-021)
Blocks: #127 (T-070b)
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/features.py
Parallel with T-072/T-076.
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-070a (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.1 · doc 05 §7 · ADR-0012 · doc 16 §2 · doc 27 §4.8
Requirements: FR-ANA-001 (traceability: doc 28)
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsBacklog
Activity