Skip to content

The agent that grows with you

fix(aux): bracket-prefixed and fence-containing prose titles are kept

teknium1eff18764ff11
diff --git a/agent/title_generator.py b/agent/title_generator.py
index a8b728766c7..800231e7761 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 5bcb6e68743..82b81fad24c 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):