From c66abbbeecf641b04a013334f418c7a53ffac02d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 23 Sep 2026 00:57:20 +0300 Subject: [PATCH] fix: store an abstain when a reasoning plan has no cited sentence A plan with no [N] became an empty string. The backend refuses to store an empty reply, so the study thread showed bad_reply instead of the missing-sources sentence. Local-Gate: 4e696f1d77810c2e0425ec57f5940f309d671aff (1407 passed, 35s) --- src/generate/prompt.py | 4 +++- tests/unit/test_query_sanitization.py | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/generate/prompt.py b/src/generate/prompt.py index 703b9c1..c4cd786 100644 --- a/src/generate/prompt.py +++ b/src/generate/prompt.py @@ -68,7 +68,9 @@ def drop_reasoning_plan(text: str) -> str: continue if _CITED.search(line): kept.append(line) - return "\n".join(kept) + # An empty string is not storable. A plan with no cited sentence is an + # abstain, not a blank bubble the backend rejects as bad_reply. + return "\n".join(kept) if kept else ABSTAIN_SENTENCE diff --git a/tests/unit/test_query_sanitization.py b/tests/unit/test_query_sanitization.py index 9a7b4b9..0d54cfc 100644 --- a/tests/unit/test_query_sanitization.py +++ b/tests/unit/test_query_sanitization.py @@ -125,6 +125,11 @@ class ReasoningPlanTests(unittest.TestCase): text = "C# bir programlama dilidir. [1]" self.assertEqual(drop_reasoning_plan(text), text) + def test_a_plan_with_no_citation_is_the_abstain_sentence(self): + raw = "We need to answer the student's question.\nSource 1: notes.\n" + self.assertEqual(drop_reasoning_plan(raw), "Kaynaklarda bu bilgi bulunamadı.") + + if __name__ == "__main__": unittest.main()