Enhance Stage Mismatch Handling and Roadmap Slot Purging
Deploy Development / deploy (push) Successful in 45s
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 33s
Test Suite / playwright-tests (push) Successful in 1m15s

- Introduced `_purge_stage_mismatch_roadmap_slots` to clear slots with persistent stage mismatches, improving the relevance of exercise suggestions.
- Updated `collect_gap_fill_specs` to handle stage mismatch issues more effectively, providing clearer rationale and title hints for off-topic exercises.
- Modified `_filter_learning_goal_candidate_ids` to enforce stricter filtering criteria, ensuring only relevant candidates are considered.
- Enhanced `rematch_roadmap_slots` to incorporate slot assignment history, preventing conflicts with previously assigned exercises.
- Bumped version to 0.8.230 to reflect the new features and improvements.
This commit is contained in:
Lars committed 2026-06-12 07:57:19 +02:00
1 parent 8a4be795f4
commit d448c3191f
6 files changed
+201 -35

No files matched your search

+110 -1
View File
@@ -269,7 +269,7 @@ def _filter_learning_goal_candidate_ids(
anti_patterns=stage_anti,
path_primary_topic=path_primary or None,
path_technique_excludes=path_tech_excludes,
relaxed=True,
relaxed=False,
):
out.append(eid)
return out
@@ -1322,6 +1322,78 @@ def _normalize_roadmap_steps_coverage(
return out
def _purge_stage_mismatch_roadmap_slots(
cur,
*,
steps: List[Dict[str, Any]],
roadmap_ctx: ProgressionRoadmapContext,
goal_query: str,
semantic_brief: PlanningSemanticBrief,
) -> Tuple[List[Dict[str, Any]], List[Tuple[int, StageSpecArtifact]]]:
"""Leert Slots mit persistentem stage_mismatch — KI-Gap statt schlechter Bibliotheks-Übung."""
issues = detect_off_topic_steps(
cur,
steps,
brief=semantic_brief,
goal_query=goal_query,
)
purge_majors: Set[int] = set()
for item in issues:
if str(item.get("issue") or "") != "stage_mismatch":
continue
midx = item.get("roadmap_major_step_index")
if midx is None:
continue
try:
purge_majors.add(int(midx))
except (TypeError, ValueError):
continue
if not purge_majors:
return steps, []
stage_specs = list(roadmap_ctx.stage_specs or [])
spec_by_major = {int(s.major_step_index): s for s in stage_specs}
major_by_index: Dict[int, MajorStep] = {}
if roadmap_ctx.roadmap:
major_by_index = {m.index: m for m in roadmap_ctx.roadmap.major_steps}
new_unfilled: List[Tuple[int, StageSpecArtifact]] = []
out: List[Dict[str, Any]] = []
for raw in steps:
step = dict(raw)
midx = step.get("roadmap_major_step_index")
if midx is None or int(midx) not in purge_majors:
out.append(step)
continue
major_idx = int(midx)
spec = spec_by_major.get(major_idx)
if spec is None:
out.append(step)
continue
step_index = next(
(i for i, sp in enumerate(stage_specs) if int(sp.major_step_index) == major_idx),
major_idx,
)
major = major_by_index.get(major_idx)
goal = (spec.learning_goal or step.get("roadmap_learning_goal") or "").strip()
out.append(
{
"exercise_id": None,
"variant_id": None,
"title": goal or f"Slot {major_idx + 1}",
"is_ai_proposal": False,
"roadmap_major_step_index": major_idx,
"roadmap_phase": major.phase if major else step.get("roadmap_phase"),
"roadmap_learning_goal": goal or None,
"roadmap_match_source": "unfilled",
"slot_status": "unfilled",
"reasons": ["Keine passende Bibliotheks-Übung für Stufen-Lernziel"],
}
)
new_unfilled.append((step_index, spec))
return out, new_unfilled
def _merge_rematch_unfilled(
roadmap_unfilled: List[Tuple[int, StageSpecArtifact]],
rematch_new_unfilled: List[Tuple[int, StageSpecArtifact]],
@@ -1401,6 +1473,16 @@ def _run_roadmap_rematch_loop(
_track_rejected(off_topic_before_strip)
_track_rejected(current_stripped)
slot_assignment_history: Dict[int, Set[int]] = {}
for raw in steps:
midx = raw.get("roadmap_major_step_index")
eid = raw.get("exercise_id")
if midx is None or eid is None:
continue
try:
slot_assignment_history.setdefault(int(midx), set()).add(int(eid))
except (TypeError, ValueError):
continue
for round_idx in range(max_rounds):
mini_qa = run_multistage_path_qa(
@@ -1462,6 +1544,7 @@ def _run_roadmap_rematch_loop(
rematch_reasons=rematch_reasons,
match_slot_fn=_match_roadmap_slot,
rejected_by_major=rejected_by_major,
slot_assignment_history=slot_assignment_history,
)
rematch_rounds += 1
for entry in round_log:
@@ -1475,6 +1558,16 @@ def _run_roadmap_rematch_loop(
rejected_by_major.setdefault(int(midx), set()).add(int(rid))
except (TypeError, ValueError):
pass
new_eid = entry.get("new_exercise_id")
if (
str(entry.get("action") or "") == "replaced"
and new_eid is not None
and midx is not None
):
try:
slot_assignment_history.setdefault(int(midx), set()).add(int(new_eid))
except (TypeError, ValueError):
pass
current_stripped = prune_stripped_after_rematch(current_stripped, round_log)
roadmap_unfilled = _merge_rematch_unfilled(roadmap_unfilled, rematch_new_unfilled)
@@ -1500,6 +1593,22 @@ def _run_roadmap_rematch_loop(
goal_query=goal_query,
)
steps, purged_unfilled = _purge_stage_mismatch_roadmap_slots(
cur,
steps=steps,
roadmap_ctx=roadmap_ctx,
goal_query=goal_query,
semantic_brief=semantic_brief,
)
if purged_unfilled:
roadmap_unfilled = _merge_rematch_unfilled(roadmap_unfilled, purged_unfilled)
off_topic_steps = detect_off_topic_steps(
cur,
steps,
brief=semantic_brief,
goal_query=goal_query,
)
return (
steps,
rematch_log,