DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.
Python ai-agentsai-tutorclawbotcli-tooldeepresearchinteractive-learninglearningmulti-agent-systemsrag
fix(ask-user): drop an option whose visible text duplicates another (#1409) (#1418)
ZQR11016f72468d864e
diff --git a/deeptutor/tools/ask_user.py b/deeptutor/tools/ask_user.pyindex 18ab17752..27e1716b5 100644--- a/deeptutor/tools/ask_user.py+++ b/deeptutor/tools/ask_user.py@@ -261,6 +261,7 @@ def _build_question(raw: Any, idx: int, used_ids: set[str]) -> AskUserQuestion |return f"Question #{idx + 1}: `options` must be an array."cleaned: list[AskUserOption] = []seen_labels: set[str] = set()+ seen_bodies: set[str] = set()for opt in options_raw:normalised = _build_option(opt)if normalised is None:@@ -272,6 +273,17 @@ def _build_question(raw: Any, idx: int, used_ids: set[str]) -> AskUserQuestion |if normalised.label in seen_labels:continueseen_labels.add(normalised.label)+ # Two options whose visible text matches once whitespace and case+ # are folded leave the learner nothing to pick between — the same+ # duplicate-body rule the mastery quiz contract enforces at+ # registration (#1409). An option with no body *is* its label, so+ # label-only cards are governed by label uniqueness alone.+ body = (normalised.description or "").strip()+ if body:+ body_key = " ".join(body.split()).casefold()+ if body_key in seen_bodies:+ continue+ seen_bodies.add(body_key)cleaned.append(normalised)if len(cleaned) >= MAX_OPTIONS:breakdiff --git a/tests/tools/test_ask_user.py b/tests/tools/test_ask_user.pyindex 7edca5f30..4f3b83a03 100644--- a/tests/tools/test_ask_user.py+++ b/tests/tools/test_ask_user.py@@ -292,6 +292,69 @@ def test_v3_keeps_other_option_when_free_text_disabled() -> None:assert _labels(payload.questions[0]) == ("A", "Other")+def test_v3_drops_an_option_whose_body_duplicates_another() -> None:+ """Two options with the same visible text leave the learner nothing to+ pick between (#1409: a duplicated choice makes the question unanswerable).++ The mastery quiz contract already refuses duplicate bodies at+ registration; the clarification-card channel gets the same rule here.+ """+ payload, _ = build_ask_user_payload(+ questions=[+ {+ "prompt": "x",+ "options": [+ {"label": "B", "description": "8"},+ {"label": "C", "description": "8"},+ {"label": "D", "description": "-2"},+ ],+ }+ ]+ )+ assert payload is not None+ assert _labels(payload.questions[0]) == ("B", "D")+++def test_v3_duplicate_body_comparison_ignores_case_and_spacing() -> None:+ """Near-duplicates that differ only by case or spacing read as the same+ choice to a learner, so the same rule applies to them."""+ payload, _ = build_ask_user_payload(+ questions=[+ {+ "prompt": "x",+ "options": [+ {"label": "A", "description": "Rerank the query."},+ {"label": "B", "description": " rerank the query. "},+ {"label": "C", "description": "Rewrite the query."},+ ],+ }+ ]+ )+ assert payload is not None+ assert _labels(payload.questions[0]) == ("A", "C")+++def test_v3_label_only_options_are_never_body_deduped() -> None:+ """An option with no body is its label; distinct labels are distinct+ choices even though every description is empty."""+ payload, _ = build_ask_user_payload(questions=[{"prompt": "x", "options": ["A", "B", "C"]}])+ assert payload is not None+ assert _labels(payload.questions[0]) == ("A", "B", "C")+++def test_v3_duplicate_body_check_is_per_question() -> None:+ """Two different questions may offer the same answer text."""+ payload, _ = build_ask_user_payload(+ questions=[+ {"prompt": "x", "options": [{"label": "A", "description": "same"}]},+ {"prompt": "y", "options": [{"label": "A", "description": "same"}]},+ ]+ )+ assert payload is not None+ assert _labels(payload.questions[0]) == ("A",)+ assert _labels(payload.questions[1]) == ("A",)++# ------------------------- frontend contract shape ------------------------