Enhance Gap Fill and Rematch Logic in Progression Path
Deploy Development / deploy (push) Successful in 40s
Test Suite / pytest-backend (push) Successful in 47s
Test Suite / lint-backend (push) Successful in 1s
Test Suite / build-frontend (push) Successful in 14s
Test Suite / k6 /health Baseline (push) Successful in 39s
Test Suite / playwright-tests (push) Successful in 1m22s
Deploy Development / deploy (push) Successful in 40s
Test Suite / pytest-backend (push) Successful in 47s
Test Suite / lint-backend (push) Successful in 1s
Test Suite / build-frontend (push) Successful in 14s
Test Suite / k6 /health Baseline (push) Successful in 39s
Test Suite / playwright-tests (push) Successful in 1m22s
- Introduced `_step_neighbors_at_index` to safely retrieve neighboring steps without causing IndexErrors, improving robustness in gap fill specifications. - Updated `collect_gap_fill_specs` to utilize the new neighbor retrieval function, ensuring safe access to adjacent steps during gap fill processing. - Enhanced rematch logic in `_run_roadmap_rematch_loop` to incorporate `max_rematch_rounds`, allowing for controlled iterations during roadmap rematching. - Improved handling of unfilled roadmap slots in `collect_rematch_slot_indices`, ensuring accurate identification of gaps in the progression path. - Added tests to validate the new gap fill handling and rematch logic, ensuring reliability in path suggestion features.
This commit is contained in:
1 parent
de939481ba
commit
df93da9a03
6 files changed
+217
-53
No files matched your search
@@ -108,6 +108,7 @@ class ProgressionPathSuggestRequest(BaseModel):
|
||||
include_llm_intent: bool = True
|
||||
include_path_qa: bool = True
|
||||
auto_rematch_after_qa: bool = True
|
||||
max_rematch_rounds: int = Field(default=2, ge=0, le=3)
|
||||
include_llm_path_qa: bool = True
|
||||
include_path_reorder: bool = True
|
||||
include_ai_gap_fill: bool = True
|
||||
@@ -438,7 +439,17 @@ def _load_supplemental_exercise_rows(
|
||||
vis_params: Sequence[Any],
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""Supplemental-Übungen mit Graph-Sichtbarkeit, Fallback Library-vis_sql."""
|
||||
ids = list(dict.fromkeys(int(x) for x in (exercise_ids or []) if int(x) > 0))
|
||||
ids: List[int] = []
|
||||
for raw in exercise_ids or []:
|
||||
if raw is None:
|
||||
continue
|
||||
try:
|
||||
eid = int(raw)
|
||||
except (TypeError, ValueError):
|
||||
continue
|
||||
if eid > 0:
|
||||
ids.append(eid)
|
||||
ids = list(dict.fromkeys(ids))
|
||||
if not ids:
|
||||
return []
|
||||
if progression_graph_id and int(progression_graph_id) > 0:
|
||||
@@ -1222,7 +1233,19 @@ def _normalize_roadmap_steps_coverage(
|
||||
return out
|
||||
|
||||
|
||||
def _maybe_rematch_roadmap_after_strip(
|
||||
def _merge_rematch_unfilled(
|
||||
roadmap_unfilled: List[Tuple[int, StageSpecArtifact]],
|
||||
rematch_new_unfilled: List[Tuple[int, StageSpecArtifact]],
|
||||
) -> List[Tuple[int, StageSpecArtifact]]:
|
||||
if not rematch_new_unfilled:
|
||||
return roadmap_unfilled
|
||||
remapped = {sp.major_step_index for _, sp in rematch_new_unfilled}
|
||||
kept = [item for item in roadmap_unfilled if item[1].major_step_index not in remapped]
|
||||
kept.extend(rematch_new_unfilled)
|
||||
return kept
|
||||
|
||||
|
||||
def _run_roadmap_rematch_loop(
|
||||
cur,
|
||||
*,
|
||||
tenant: TenantContext,
|
||||
@@ -1237,6 +1260,7 @@ def _maybe_rematch_roadmap_after_strip(
|
||||
stripped_off_topic: List[Dict[str, Any]],
|
||||
off_topic_before_strip: List[Dict[str, Any]],
|
||||
roadmap_unfilled: List[Tuple[int, StageSpecArtifact]],
|
||||
gaps: List[Dict[str, Any]],
|
||||
) -> Tuple[
|
||||
List[Dict[str, Any]],
|
||||
List[Dict[str, Any]],
|
||||
@@ -1245,54 +1269,92 @@ def _maybe_rematch_roadmap_after_strip(
|
||||
int,
|
||||
List[Tuple[int, StageSpecArtifact]],
|
||||
]:
|
||||
"""Phase A/B: Rematch-Schleife aus Strip, unfilled Slots und optimization_hints."""
|
||||
rematch_log: List[Dict[str, Any]] = []
|
||||
rematch_rounds = 0
|
||||
if not body.auto_rematch_after_qa or not roadmap_ctx.stage_specs:
|
||||
return steps, rematch_log, stripped_off_topic, [], rematch_rounds, roadmap_unfilled
|
||||
max_rounds = int(body.max_rematch_rounds or 0)
|
||||
if not body.auto_rematch_after_qa or max_rounds <= 0 or not roadmap_ctx.stage_specs:
|
||||
off_topic_steps = detect_off_topic_steps(
|
||||
cur,
|
||||
steps,
|
||||
brief=semantic_brief,
|
||||
goal_query=goal_query,
|
||||
)
|
||||
return steps, rematch_log, stripped_off_topic, off_topic_steps, rematch_rounds, roadmap_unfilled
|
||||
|
||||
slot_indices, rematch_reasons = collect_rematch_slot_indices(
|
||||
stripped_off_topic=stripped_off_topic,
|
||||
off_topic_steps=off_topic_before_strip if not stripped_off_topic else [],
|
||||
optimization_hints=[],
|
||||
stage_specs=roadmap_ctx.stage_specs,
|
||||
)
|
||||
if not slot_indices:
|
||||
return steps, rematch_log, stripped_off_topic, [], rematch_rounds, roadmap_unfilled
|
||||
current_stripped = list(stripped_off_topic or [])
|
||||
use_initial_off_topic = not current_stripped
|
||||
off_topic_steps: List[Dict[str, Any]] = []
|
||||
|
||||
steps, rematch_log, rematch_new_unfilled = rematch_roadmap_slots(
|
||||
cur,
|
||||
tenant=tenant,
|
||||
body=body,
|
||||
goal_query=goal_query,
|
||||
max_steps=max_steps,
|
||||
semantic_brief=semantic_brief,
|
||||
path_target_profile=path_target_profile,
|
||||
path_intent=path_intent,
|
||||
roadmap_ctx=roadmap_ctx,
|
||||
steps=steps,
|
||||
slot_indices=slot_indices,
|
||||
rematch_reasons=rematch_reasons,
|
||||
match_slot_fn=_match_roadmap_slot,
|
||||
)
|
||||
rematch_rounds = 1
|
||||
stripped_off_topic = prune_stripped_after_rematch(stripped_off_topic, rematch_log)
|
||||
if rematch_new_unfilled:
|
||||
remapped = {sp.major_step_index for _, sp in rematch_new_unfilled}
|
||||
roadmap_unfilled = [
|
||||
item for item in roadmap_unfilled if item[1].major_step_index not in remapped
|
||||
]
|
||||
roadmap_unfilled.extend(rematch_new_unfilled)
|
||||
for round_idx in range(max_rounds):
|
||||
mini_qa = run_multistage_path_qa(
|
||||
off_topic_steps=off_topic_steps if round_idx > 0 else [],
|
||||
stripped_off_topic=current_stripped if round_idx == 0 else [],
|
||||
gaps=gaps if round_idx == 0 else [],
|
||||
llm_qa=None,
|
||||
llm_applied=False,
|
||||
roadmap_unfilled=roadmap_unfilled,
|
||||
)
|
||||
optimization_hints = list(mini_qa.get("optimization_hints") or [])
|
||||
|
||||
slot_indices, rematch_reasons = collect_rematch_slot_indices(
|
||||
stripped_off_topic=current_stripped if round_idx == 0 else [],
|
||||
off_topic_steps=off_topic_before_strip if round_idx == 0 and use_initial_off_topic else [],
|
||||
optimization_hints=optimization_hints,
|
||||
stage_specs=roadmap_ctx.stage_specs,
|
||||
roadmap_unfilled=roadmap_unfilled,
|
||||
)
|
||||
if not slot_indices:
|
||||
break
|
||||
|
||||
steps, round_log, rematch_new_unfilled = rematch_roadmap_slots(
|
||||
cur,
|
||||
tenant=tenant,
|
||||
body=body,
|
||||
goal_query=goal_query,
|
||||
max_steps=max_steps,
|
||||
semantic_brief=semantic_brief,
|
||||
path_target_profile=path_target_profile,
|
||||
path_intent=path_intent,
|
||||
roadmap_ctx=roadmap_ctx,
|
||||
steps=steps,
|
||||
slot_indices=slot_indices,
|
||||
rematch_reasons=rematch_reasons,
|
||||
match_slot_fn=_match_roadmap_slot,
|
||||
)
|
||||
rematch_rounds += 1
|
||||
for entry in round_log:
|
||||
tagged = dict(entry)
|
||||
tagged["round"] = rematch_rounds
|
||||
rematch_log.append(tagged)
|
||||
|
||||
current_stripped = prune_stripped_after_rematch(current_stripped, round_log)
|
||||
roadmap_unfilled = _merge_rematch_unfilled(roadmap_unfilled, rematch_new_unfilled)
|
||||
use_initial_off_topic = False
|
||||
|
||||
off_topic_steps = detect_off_topic_steps(
|
||||
cur,
|
||||
steps,
|
||||
brief=semantic_brief,
|
||||
goal_query=goal_query,
|
||||
)
|
||||
if round_idx + 1 >= max_rounds:
|
||||
break
|
||||
if not off_topic_steps and not roadmap_unfilled:
|
||||
break
|
||||
|
||||
if not off_topic_steps:
|
||||
off_topic_steps = detect_off_topic_steps(
|
||||
cur,
|
||||
steps,
|
||||
brief=semantic_brief,
|
||||
goal_query=goal_query,
|
||||
)
|
||||
|
||||
off_topic_steps = detect_off_topic_steps(
|
||||
cur,
|
||||
steps,
|
||||
brief=semantic_brief,
|
||||
goal_query=goal_query,
|
||||
)
|
||||
return (
|
||||
steps,
|
||||
rematch_log,
|
||||
stripped_off_topic,
|
||||
current_stripped,
|
||||
off_topic_steps,
|
||||
rematch_rounds,
|
||||
roadmap_unfilled,
|
||||
@@ -2000,7 +2062,7 @@ def suggest_progression_path(
|
||||
rematch_off_topic,
|
||||
rematch_rounds,
|
||||
roadmap_unfilled,
|
||||
) = _maybe_rematch_roadmap_after_strip(
|
||||
) = _run_roadmap_rematch_loop(
|
||||
cur,
|
||||
tenant=tenant,
|
||||
body=body,
|
||||
@@ -2014,6 +2076,7 @@ def suggest_progression_path(
|
||||
stripped_off_topic=stripped_off_topic,
|
||||
off_topic_before_strip=off_topic_before_strip,
|
||||
roadmap_unfilled=roadmap_unfilled,
|
||||
gaps=gaps,
|
||||
)
|
||||
if rematch_off_topic:
|
||||
off_topic_steps = rematch_off_topic
|
||||
|
||||
Reference in new issue
Block a user