Refactor Roadmap Step Annotation and Slot Assignment Logic
Deploy Development / deploy (push) Successful in 49s
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 1m12s

- Updated `_annotate_roadmap_step` to change the condition for setting `slot_status` based on `roadmap_match_source`, improving clarity in slot assignment handling.
- Removed the `_try_reconcile_slot_assignment` function to streamline the slot assignment process, as its logic is now integrated into the main flow.
- Enhanced `_match_roadmap_slot` to conditionally preserve slot assignments based on exercise ID, ensuring better handling of existing assignments.
- Improved the handling of semantic scores in `rank_visible_library_hits` to prioritize the best semantic fit, enhancing exercise retrieval accuracy.
- Added tests to validate the new logic for title equivalence and semantic scoring, ensuring robustness in exercise selection processes.
This commit is contained in:
Lars committed 2026-06-11 12:45:53 +02:00
1 parent ca2adbd55e
commit b2fbf6b4af
5 files changed
+91 -129

No files matched your search

+11 -113
View File
@@ -816,7 +816,7 @@ def _annotate_roadmap_step(
step["roadmap_match_source"] = "stage_spec"
if step.get("exercise_id") is not None:
step["slot_status"] = step.get("slot_status") or (
"preserved" if step.get("roadmap_match_source") == "slot_reconciled" else "matched"
"preserved" if step.get("roadmap_match_source") == "slot_best_match" else "matched"
)
else:
step["slot_status"] = step.get("slot_status") or "unfilled"
@@ -825,84 +825,6 @@ def _annotate_roadmap_step(
return step
def _try_reconcile_slot_assignment(
cur,
*,
assignment: EvaluateStepPayload,
stage_spec: StageSpecArtifact,
major_step: Optional[MajorStep],
tenant: TenantContext,
progression_graph_id: Optional[int],
stage_match_brief: Optional[PlanningSemanticBrief],
stage_goal: str,
stage_anti: Optional[List[str]],
path_primary: str,
path_tech_excludes: Optional[List[str]],
) -> Optional[Dict[str, Any]]:
"""
Bestehende Slot-Zuordnung behalten, wenn sie noch zum Stufen-Lernziel passt.
Validiert gegen dieselben Gates wie Match/QA (relaxed), inkl. Titel-Äquivalenz.
"""
from planning_exercise_semantics import (
exercise_passes_stage_fit,
exercise_title_equivalent_to_stage_goal,
)
step = _path_step_from_slot_assignment(
cur,
assignment=assignment,
stage_spec=stage_spec,
major_step=major_step,
tenant=tenant,
progression_graph_id=progression_graph_id,
)
if not step:
return None
title = str(step.get("title") or "").strip()
summary = str(step.get("summary") or "").strip()
goal = ""
cur.execute("SELECT goal FROM exercises WHERE id = %s", (int(step["exercise_id"]),))
grow = cur.fetchone()
if grow:
goal = str(grow.get("goal") or "").strip()
lg = (stage_goal or stage_spec.learning_goal or "").strip()
if exercise_title_equivalent_to_stage_goal(title, lg):
step["roadmap_match_source"] = "slot_reconciled"
step["slot_status"] = "preserved"
step["reasons"] = ["Bestehende Zuordnung (Titel = Lernziel)"] + list(step.get("reasons") or [])[:2]
return _annotate_roadmap_step(
step,
stage_spec=stage_spec,
major_step=major_step,
anti_patterns_override=stage_anti,
)
if exercise_passes_stage_fit(
learning_goal=lg,
title=title,
summary=summary,
goal=goal,
stage_brief=stage_match_brief,
anti_patterns=stage_anti,
path_primary_topic=path_primary or None,
path_technique_excludes=path_tech_excludes,
relaxed=True,
):
step["roadmap_match_source"] = "slot_reconciled"
step["slot_status"] = "preserved"
step["reasons"] = ["Bestehende Zuordnung (Stufen-Fit)"] + list(step.get("reasons") or [])[:2]
return _annotate_roadmap_step(
step,
stage_spec=stage_spec,
major_step=major_step,
anti_patterns_override=stage_anti,
)
return None
def _stage_validation_context_for_spec(
cur,
*,
@@ -1138,7 +1060,16 @@ def _match_roadmap_slot(
skill_expectations=skill_exp_api,
anti_patterns_override=stage_anti,
)
step["slot_status"] = "matched"
if (
slot_priority_exercise_id is not None
and int(step["exercise_id"]) == int(slot_priority_exercise_id)
):
step["slot_status"] = "preserved"
step["roadmap_match_source"] = "slot_best_match"
step["reasons"] = ["Bester Treffer (bestehende Zuordnung)"] + list(step.get("reasons") or [])[:2]
else:
step["slot_status"] = "matched"
step["roadmap_match_source"] = "stage_spec"
return step, None
@@ -1307,39 +1238,6 @@ def _build_steps_roadmap_first(
slot_priority_id: Optional[int] = None
if major_idx in assignments:
ctx = _stage_validation_context_for_spec(
cur,
body=body,
goal_query=goal_query,
semantic_brief=semantic_brief,
path_target_profile=path_target_profile,
roadmap_ctx=roadmap_ctx,
stage_spec=stage_spec,
step_index=step_index,
stage_count=stage_count,
major=major,
)
reconciled = _try_reconcile_slot_assignment(
cur,
assignment=assignments[major_idx],
stage_spec=stage_spec,
major_step=major,
tenant=tenant,
progression_graph_id=body.progression_graph_id,
stage_match_brief=ctx["stage_match_brief"],
stage_goal=ctx["stage_goal"],
stage_anti=ctx["stage_anti"],
path_primary=ctx["path_primary"],
path_tech_excludes=ctx["path_tech_excludes"],
)
if reconciled:
steps.append(reconciled)
eid = int(reconciled["exercise_id"])
used.add(eid)
planned_ids.append(eid)
anchor_id = eid
anchor_variant_id = reconciled.get("variant_id")
continue
try:
slot_priority_id = int(assignments[major_idx].exercise_id)
except (TypeError, ValueError):