Enhance Stage Specification Refinement and Rematch Logic
Deploy Development / deploy (push) Successful in 46s
Test Suite / pytest-backend (push) Successful in 44s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 13s
Test Suite / k6 /health Baseline (push) Successful in 34s
Test Suite / playwright-tests (push) Successful in 1m22s

- Updated `max_rematch_rounds` in `ProgressionPathSuggestRequest` to allow for a maximum of 3 rounds, improving flexibility in rematch processes.
- Introduced `_track_rejected` function to track rejected exercises by major step index, enhancing the rematch logic to account for previously rejected exercises.
- Enhanced `_run_roadmap_rematch_loop` to utilize the new rejection tracking, ensuring better handling of off-topic steps during rematching.
- Improved `detect_off_topic_steps` to incorporate refined scoring and reasoning for stage fit, enhancing the accuracy of off-topic detection.
- Updated `refine_stage_spec_artifact` to merge stage exclusion phrases more effectively, improving the clarity of anti-pattern handling.
- Bumped version to 0.8.228 to reflect the new features and improvements.
This commit is contained in:
Lars committed 2026-06-11 22:11:31 +02:00
1 parent f36a747efa
commit a49987408b
9 files changed
+269 -74

No files matched your search

+41 -5
View File
@@ -21,12 +21,15 @@ from planning_exercise_semantics import (
_blob_from_fields,
_blob_matches_stage_excludes,
brief_to_summary_dict,
build_stage_match_brief,
exercise_passes_path_semantic_gate,
exercise_passes_stage_learning_goal_gate,
exercise_passes_technique_path_scope,
merge_stage_exclude_phrases,
resolve_path_anti_patterns,
resolve_path_primary_topic,
score_exercise_semantic_relevance,
score_exercise_stage_fit,
semantic_brief_for_stage,
step_phase_for_index,
technique_sibling_excludes,
@@ -442,8 +445,13 @@ def detect_off_topic_steps(
bundle["goal"],
bundle["variant_names"],
)
step_anti = list(step.get("roadmap_anti_patterns") or []) + path_anti
if step_anti and _blob_matches_stage_excludes(blob, step_anti):
step_anti_raw = list(step.get("roadmap_anti_patterns") or [])
stage_goal_pre = (step.get("roadmap_learning_goal") or "").strip()
exclude_phrases = merge_stage_exclude_phrases(
stage_goal_pre,
[*step_anti_raw, *path_anti],
)
if exclude_phrases and _blob_matches_stage_excludes(blob, exclude_phrases):
off_topic.append(
_with_roadmap_major_index(
step,
@@ -459,7 +467,6 @@ def detect_off_topic_steps(
)
)
continue
stage_goal_pre = (step.get("roadmap_learning_goal") or "").strip()
primary = (
resolve_path_primary_topic(
goal_query or "",
@@ -512,6 +519,26 @@ def detect_off_topic_steps(
step_phase=phase,
)
stage_anti = list(step.get("roadmap_anti_patterns") or [])
stage_match_brief = (
build_stage_match_brief(
learning_goal=stage_goal,
anti_patterns=stage_anti or None,
phase=phase or None,
)
if stage_goal
else None
)
stage_sem = 0.0
stage_reasons: List[str] = []
if stage_match_brief:
stage_sem, stage_reasons = score_exercise_stage_fit(
title=bundle["title"],
summary=bundle["summary"],
goal=bundle["goal"],
variant_names=bundle["variant_names"],
stage_brief=stage_match_brief,
step_phase=phase,
)
if stage_goal and not exercise_passes_stage_learning_goal_gate(
learning_goal=stage_goal,
title=bundle["title"],
@@ -520,6 +547,15 @@ def detect_off_topic_steps(
semantic_score=sem,
anti_patterns=stage_anti or None,
):
reasons = [
r
for r in stage_reasons
if r and r != "Kern-Thema der Anfrage im Übungstext"
]
if not reasons:
reasons = [
f"Stufen-Fit zu schwach ({stage_sem:.2f}) für „{stage_goal[:80]}“"
]
off_topic.append(
_with_roadmap_major_index(
step,
@@ -527,11 +563,11 @@ def detect_off_topic_steps(
"step_index": idx,
"exercise_id": int(step["exercise_id"]),
"title": step.get("title") or bundle["title"],
"semantic_score": round(sem, 4),
"semantic_score": round(stage_sem, 4),
"expected_phase": phase,
"issue": "stage_mismatch",
"roadmap_learning_goal": stage_goal,
"reasons": sem_reasons[:3],
"reasons": reasons[:3],
},
)
)