Skip to content

[T-071b] Stable mode identity across re-analysis (Hungarian matching on Jaccard) #130

Closed

Description

@CodewithJha

Task T-071b · Milestone M6 — Analysis + risk · Size S · Priority P1 · Epic #6

Implements 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.
  • stale status 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) -> ModeMatch where ModeMatch.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 with J ≥ analysis.mode_match_jaccard (doc 05 §7: 0.5).
  • Codes: FM-NN monotonically increasing per campaign (max(existing)+1), never reused even if a mode disappears (disappeared modes get status stale, not deleted, so links in old reports stay valid).
  • User-owned fields (label when label_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 Unreleased updated 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

No one assigned

    Labels

    area:analysisFailure clustering, SHAP, rules, interactionsmilestone:M6M6 — Analysis + riskpriority:P1Required for milestone exitsize:S<= 1 daytaskChild task of a milestone epictype:featureNew functionality

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions