From eff18764ff11db0279a9f0894208989ed69d46b3 Mon Sep 17 00:00:00 2001 From: teknium1 <127238744+teknium1@users.noreply.github.com> Date: Thu, 17 Sep 2026 01:37:16 -0700 Subject: [PATCH] fix(aux): bracket-prefixed and fence-containing prose titles are kept MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `_is_truncated_structured_output` flagged any reply starting with `{`/`[` or containing an odd number of fences, so a provider that ignores response_format and answers `[WIP] Fix login flow` or `Fix ``` rendering in chat` lost its title (the derived title stayed). Truncated JSON is recognised by its JSON-shaped opener (`{"`, `["`, `[{`) and an unclosed fence only when the fence opens the reply — the fragments from #83903 are still dropped. Review follow-up on #113960; two legit-title cases added to the existing parametrized invariant (red on the previous head). --- agent/title_generator.py | 7 ++++--- tests/agent/test_title_generator.py | 4 ++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/agent/title_generator.py b/agent/title_generator.py index a8b728766c..800231e776 100644 --- a/agent/title_generator.py +++ b/agent/title_generator.py @@ -245,9 +245,10 @@ def _extract_json_title(raw: str) -> Optional[str]: def _is_truncated_structured_output(raw: str) -> bool: """Structured output the token cap cut before its closing quote/brace/fence (``{"title``, a bare fence opener). - Checked only after the JSON paths failed, and on structure alone (a leading brace/bracket, an - unclosed fence) so quoted or *emphasized* prose titles are untouched (#83903).""" - return raw.count("```") % 2 == 1 or raw.startswith(("{", "[")) + Checked only after the JSON paths failed, and on structure alone (a JSON-shaped opener, a fence + opener that is never closed) so quoted, *emphasized* or ``[WIP]``-prefixed prose titles are + untouched (#83903).""" + return raw.startswith(('{"', '["', "[{")) or (raw.startswith("```") and raw.count("```") % 2 == 1) def _extract_title_text(content: str) -> str: diff --git a/tests/agent/test_title_generator.py b/tests/agent/test_title_generator.py index 5bcb6e6874..82b81fad24 100644 --- a/tests/agent/test_title_generator.py +++ b/tests/agent/test_title_generator.py @@ -82,6 +82,10 @@ class TestGenerateTitle: ("修复登录按钮", "修复登录按钮"), ("42", "42"), ('```json\n{"title": "Fix login button"', "Fix login button"), + # Bracket/brace-prefixed prose and a literal fence inside a sentence are titles, not + # truncated JSON — a provider that ignores response_format still gets its title kept. + ("[WIP] Fix login flow", "[WIP] Fix login flow"), + ("Fix ``` rendering in chat", "Fix ``` rendering in chat"), ], ) def test_truncated_structured_output_never_becomes_the_title(self, content, expected):