From c42c5b4d30b1bb32e0a3761b7cda324dcb9e3637 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Tue, 22 Sep 2026 22:19:26 +0500 Subject: [PATCH] =?UTF-8?q?fix:=20resolve=20#7693=20=E2=80=94=20Cross-scri?= =?UTF-8?q?pt=20title=20guard=20rejects=20valid=20CJK+English=20titles?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the user writes in CJK, the title language mismatch guard now allows Latin characters in the title as long as the title also contains CJK characters (cjk >= 2). This permits CJK titles with borrowed English product/technical terms (e.g. 'WeChat Pay 回调失败排查', 'Python 代码修复') while still rejecting pure-Latin titles for CJK conversations and unrelated scripts (Cyrillic, Arabic, etc.). Added regression tests: test_cjk_start_mixed_cjk_latin_title_is_allowed and test_cjk_start_pure_latin_title_still_rejected. --- api/streaming.py | 15 +++++++++- tests/test_issue3293_title_language_drift.py | 29 ++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/api/streaming.py b/api/streaming.py index 4431d4db..296beb85 100644 --- a/api/streaming.py +++ b/api/streaming.py @@ -4040,13 +4040,26 @@ def _title_language_mismatch(user_text: str, title: str) -> bool: return False # (1) Cross-script mismatch — language-agnostic. + # CJK text routinely borrows Latin product/technical terms (e.g. "WeChat + # Pay", "Python", "ProRes RAW"), so when the user writes in CJK, Latin + # characters in the title are acceptable as long as the title also + # contains CJK — i.e. the title is genuinely mixed, not pure drift. + # A pure-Latin title for a CJK conversation is still rejected. + # Unrelated scripts (Cyrillic, Arabic, Greek …) are always flagged. user_script = _dominant_script(user_text) if user_script: title_counts = _script_counts(candidate) title_total = sum(title_counts.values()) if title_total >= 2: for script, n in title_counts.items(): - if script != user_script and n >= 2 and (n / title_total) >= 0.35: + if script == user_script: + continue + # When user writes in CJK, Latin in the title is a borrowed + # term as long as the title also contains CJK characters. + if user_script == 'cjk' and script == 'latin': + if title_counts.get('cjk', 0) >= 2: + continue + if n >= 2 and (n / title_total) >= 0.35: return True # (2) Legacy same-script German→English heuristic. diff --git a/tests/test_issue3293_title_language_drift.py b/tests/test_issue3293_title_language_drift.py index 4143362f..fd2f84bb 100644 --- a/tests/test_issue3293_title_language_drift.py +++ b/tests/test_issue3293_title_language_drift.py @@ -71,6 +71,35 @@ def test_cjk_start_english_title_is_rejected(): assert _title_language_mismatch("如何修复这个错误问题", "Fixing the Bug") is True +def test_cjk_start_mixed_cjk_latin_title_is_allowed(): + """CJK conversations frequently embed English product/technical terms in + titles (e.g. 'WeChat Pay 回调失败排查'). As long as the title also + contains CJK characters, Latin borrowed terms should not trigger rejection. + Regression test for #7693.""" + from api.streaming import _title_language_mismatch + + # Pure CJK user, CJK title with English product name + assert _title_language_mismatch( + "微信支付回调一直失败怎么办", "WeChat Pay 回调失败排查" + ) is False + # CJK user, CJK title with English tech term + assert _title_language_mismatch( + "如何修复这个错误问题", "Python 代码修复" + ) is False + # Mixed CJK+Latin user, mixed title + assert _title_language_mismatch( + "prores raw是否能选择压缩?", "ProRes RAW 压缩选项与 BRAW 对比" + ) is False + + +def test_cjk_start_pure_latin_title_still_rejected(): + """A purely Latin title for a CJK conversation is still a genuine drift.""" + from api.streaming import _title_language_mismatch + + assert _title_language_mismatch("如何修复这个错误问题", "Fixing the Bug") is True + assert _title_language_mismatch("如何修复这个错误问题", "Python Error Guide") is True + + # ── regression guards: legitimate same-script titles must NOT be rejected ─── def test_english_start_english_title_allowed():