Repository navigation
Description
Task
T-071b· Milestone M6 — Analysis + risk · Size S · Priority P1 · Epic #6Implements FR-ANA-002 · FR-ANA-006
Branch
feat/t-071b-stable-mode-identity-across-re— one task = one branch = one PR (doc 32 §6)
Summary
Implement analysis/mode_matching.py: match new clusters to previous modes by Hungarian assignment on Jaccard similarity of member runs (≥ mode_match_jaccard ⇒ same mode_id/code, user labels kept), new codes FM-NN otherwise.
Context / motivation
Incremental analysis every 25 runs must not rename cases under the user's eyes (doc 05 §7).
Scope
In scope
match_modes(prev, new, threshold) -> mapping.stalestatus handling documented in doc 11 if not already present (doc PR in same task).
Implementation guidance
- Module
roboprobe/analysis/mode_matching.py:def match_modes(previous: Sequence[StoredMode], new: Sequence[FailureModeSummary], threshold: float) -> ModeMatchwhereModeMatch.assignments: dict[int, UUID](new index → existing mode id),ModeMatch.new_codes: dict[int, str]. - Jaccard on member run-id sets; cost matrix
1 − J;scipy.optimize.linear_sum_assignment; accept pairs withJ ≥ analysis.mode_match_jaccard(doc 05 §7: 0.5). - Codes:
FM-NNmonotonically increasing per campaign (max(existing)+1), never reused even if a mode disappears (disappeared modes get statusstale, not deleted, so links in old reports stay valid). - User-owned fields (
labelwhenlabel_is_user,status) are preserved on matched modes; auto-labels are refreshed. - Pure function; persistence happens in the pipeline (T-075a).
- 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.mode_match_jaccard
Acceptance criteria
- Id stability test across perturbed re-clusterings.
- User-edited labels preserved.
- Matching is order-independent (permute inputs → same mapping).
- Codes never reused (test across three successive analyses).
- Threshold read from settings (env override test).
- 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_mode_matching.py.- Property test: every new mode either matched once or gets a fresh code; no existing id assigned twice.
Dependencies
Blocked by: #127 (T-070b)
Blocks: #137 (T-075a)
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/mode_matching.py
Parallel with T-071a.
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-071b (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 05 §7 · doc 09 §3.3 · doc 11 §3
Requirements: FR-ANA-002 · FR-ANA-006 (traceability: doc 28)
External:
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsBacklog
Activity
report.jsonand analysis artefacts #137