Enhance Slot Difference Annotation and Rematch Suggestion Logic
Deploy Development / deploy (push) Successful in 43s
Test Suite / pytest-backend (push) Successful in 44s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 14s
Test Suite / k6 /health Baseline (push) Successful in 34s
Test Suite / playwright-tests (push) Successful in 1m13s

- Introduced `_annotate_slot_diffs` to mark trivial ID swaps in slot differences, improving clarity in comparison results.
- Added `_actionable_slot_diffs` to filter out non-actionable differences, streamlining the evaluation process.
- Implemented `_build_rematch_suggestion_diffs` to generate suggestions based on rematch logs, enhancing the path optimization workflow.
- Updated `_build_progression_compare_response` to incorporate actionable slot differences and rematch suggestions, improving the response structure.
- Enhanced frontend components to display rematch suggestions and handle trivial differences more effectively.
- Bumped version to reflect the new features and improvements.
This commit is contained in:
Lars committed 2026-06-13 07:55:47 +02:00
1 parent e828a5da32
commit dccb065181
11 files changed
+552 -84

No files matched your search

+133 -11
View File
@@ -2208,20 +2208,120 @@ def _normalize_slot_title(title: Optional[str]) -> str:
return (title or "").strip().casefold()
def _filter_trivial_slot_diffs(diffs: Sequence[Mapping[str, Any]]) -> List[Dict[str, Any]]:
"""Gleicher sichtbarer Titel = kein inhaltlicher Wechsel (nur ID-Doppel in der Bibliothek)."""
def _annotate_slot_diffs(
diffs: Sequence[Mapping[str, Any]],
) -> List[Dict[str, Any]]:
"""Kennzeichnet reine ID-Tausche (gleicher Titel) — bleiben sichtbar, zählen aber nicht als inhaltlich."""
out: List[Dict[str, Any]] = []
for raw in diffs or []:
if not isinstance(raw, dict):
continue
bt = _normalize_slot_title(raw.get("baseline_title"))
pt = _normalize_slot_title(raw.get("proposed_title"))
if bt and pt and bt == pt:
continue
out.append(dict(raw))
entry = dict(raw)
bt = _normalize_slot_title(entry.get("baseline_title"))
pt = _normalize_slot_title(entry.get("proposed_title"))
entry["trivial_id_swap"] = bool(bt and pt and bt == pt)
out.append(entry)
return out
def _actionable_slot_diffs(diffs: Sequence[Mapping[str, Any]]) -> List[Dict[str, Any]]:
return [d for d in diffs if not d.get("trivial_id_swap")]
def _last_rematch_replacements_by_slot(
rematch_log: Sequence[Mapping[str, Any]],
) -> Dict[int, Mapping[str, Any]]:
"""Letzter erfolgreicher Replace je Slot (Multi-Runden-Rematch)."""
out: Dict[int, Mapping[str, Any]] = {}
for entry in rematch_log or []:
if not isinstance(entry, dict):
continue
if str(entry.get("action") or "") != "replaced":
continue
if entry.get("new_exercise_id") is None:
continue
midx = entry.get("roadmap_major_step_index")
if midx is None:
continue
out[int(midx)] = entry
return out
def _build_rematch_suggestion_diffs(
baseline_steps: Sequence[Mapping[str, Any]],
rematch_log: Sequence[Mapping[str, Any]],
) -> List[Dict[str, Any]]:
"""Vorschläge aus Rematch-Protokoll, wenn End-Pfad vs. Baseline identisch wirkt."""
base_by = _steps_by_major_index(baseline_steps)
replacements = _last_rematch_replacements_by_slot(rematch_log)
diffs: List[Dict[str, Any]] = []
for midx, entry in sorted(replacements.items()):
base = base_by.get(midx, {})
base_id = base.get("exercise_id")
new_id = entry.get("new_exercise_id")
base_title = (base.get("title") or "").strip() or None
new_title = (entry.get("new_title") or "").strip() or None
same_id = False
if base_id is not None and new_id is not None:
try:
same_id = int(base_id) == int(new_id)
except (TypeError, ValueError):
same_id = False
if same_id:
bt = _normalize_slot_title(base_title)
pt = _normalize_slot_title(new_title)
if bt and pt and bt == pt:
continue
diffs.append(
{
"roadmap_major_step_index": midx,
"baseline_exercise_id": int(base_id) if base_id is not None else None,
"baseline_title": base_title,
"proposed_exercise_id": int(new_id) if new_id is not None else None,
"proposed_title": new_title,
"baseline_slot_status": base.get("slot_status"),
"proposed_slot_status": "matched",
"changed": True,
"from_rematch_log": True,
}
)
return diffs
def _overlay_rematch_suggestions_on_steps(
proposed_steps: Sequence[Mapping[str, Any]],
suggestion_diffs: Sequence[Mapping[str, Any]],
) -> List[Dict[str, Any]]:
"""Ergänzt proposed_steps um Rematch-Kandidaten (für selektive Übernahme)."""
if not suggestion_diffs:
return list(proposed_steps or [])
prop_by = _steps_by_major_index(proposed_steps)
for diff in suggestion_diffs:
if not isinstance(diff, dict) or not diff.get("from_rematch_log"):
continue
midx = diff.get("roadmap_major_step_index")
new_id = diff.get("proposed_exercise_id")
if midx is None or new_id is None:
continue
existing = dict(prop_by.get(int(midx), {}))
existing.update(
{
"exercise_id": int(new_id),
"title": diff.get("proposed_title") or existing.get("title"),
"variant_id": existing.get("variant_id"),
"roadmap_major_step_index": int(midx),
"is_ai_proposal": False,
"slot_status": "matched",
"roadmap_match_source": "rematch_suggestion",
}
)
prop_by[int(midx)] = existing
ordered: List[Dict[str, Any]] = []
for midx in sorted(prop_by.keys()):
ordered.append(prop_by[midx])
return ordered
def _build_progression_slot_diffs(
baseline_steps: Sequence[Mapping[str, Any]],
proposed_steps: Sequence[Mapping[str, Any]],
@@ -2269,24 +2369,46 @@ def _build_progression_compare_response(
if isinstance(proposed_eval, dict) and isinstance(proposed_eval.get("path_qa"), dict)
else pipeline_qa
)
slot_diffs = _filter_trivial_slot_diffs(
slot_diffs = _annotate_slot_diffs(
_build_progression_slot_diffs(baseline_steps, proposed_steps),
)
actionable_diffs = _actionable_slot_diffs(slot_diffs)
slot_diffs_source = "steps"
rematch_log = (
pipeline_qa.get("rematch_log")
if isinstance(pipeline_qa.get("rematch_log"), list)
else []
)
apply_steps = list(proposed_steps)
if not actionable_diffs and rematch_log:
rematch_raw = _build_rematch_suggestion_diffs(baseline_steps, rematch_log)
rematch_diffs = _annotate_slot_diffs(rematch_raw)
rematch_actionable = _actionable_slot_diffs(rematch_diffs)
if rematch_actionable:
actionable_diffs = rematch_actionable
slot_diffs = rematch_diffs
slot_diffs_source = "rematch_log"
apply_steps = _overlay_rematch_suggestions_on_steps(proposed_steps, rematch_actionable)
return {
**dict(proposed),
"comparison_mode": True,
"baseline_steps": baseline_steps,
"baseline_path_qa": baseline_qa,
"proposed_steps": proposed_steps,
"proposed_steps": apply_steps,
"proposed_steps_pipeline": proposed_steps,
"proposed_path_qa": fair_qa,
"proposed_path_qa_pipeline": pipeline_qa,
"slot_diffs": slot_diffs,
"slot_diff_count": len(slot_diffs),
"slot_diffs_actionable": actionable_diffs,
"slot_diff_count": len(actionable_diffs),
"slot_diff_count_including_trivial": len(slot_diffs),
"slot_diffs_source": slot_diffs_source,
"optimization_actionable": len(actionable_diffs) > 0,
"baseline_quality_score": _path_qa_quality_score(baseline_qa),
"proposed_quality_score": _path_qa_quality_score(fair_qa),
"proposed_pipeline_quality_score": _path_qa_quality_score(pipeline_qa),
"path_qa": fair_qa,
"steps": proposed_steps,
"steps": apply_steps,
}