`remove_think_blocks` regex deletes content that is not in a `<think>` block
backend/utils/str_utils.py:9:
return re.sub(r"(?:<think>)?.*?</think>", "", text, flags=re.DOTALL | re.IGNORECASE)
The intent (per the docstring) is to remove <think>…</think> blocks including their inner content. The actual behaviour is broader: because (?:<think>)? makes the opening tag optional while .*?</think> still requires a closing tag, the regex will happily eat anything that ends with a </think> even if there's no opening tag.
Repro
>>> from utils.str_utils import remove_think_blocks
>>> remove_think_blocks("The model said: hello </think> world")
' world'
>>> remove_think_blocks("regular content ending with </think> stray tag")
' stray tag'
>>> remove_think_blocks("<think>secret</think>visible<think>second</think>tail")
'visibletail' # OK - matches intent
This matters for the streaming path in _process_thinking_tokens (backend/utils/llm_utils.py:15) which handles half-tokens around <think>/</think>; a stray closing tag emitted by a misbehaving provider will cause everything before it on the same chunk to be silently dropped.
Suggested fix
return re.sub(r"<think>.*?</think>", "", text, flags=re.DOTALL | re.IGNORECASE)
If the optional-open intent really was deliberate (e.g., to recover from a provider that streams only the closing tag), keep that behaviour but make it explicit, anchor it, and add a comment + a test.
Severity: Low — the failure mode requires a malformed/partial provider stream, but when it happens the user-visible content is silently truncated.