[Bug]: removeThinkTags step 2 wipes legitimate content after a stray </think>
Problem
removeThinkTags destroys valid response text when a stray </think> appears after a well-formed think block.
Steps
- Call
removeThinkTags('<think>reason</think>Here is answer</think>done')fromchrome-extension/src/background/agent/messages/utils.ts:31.
Expected
'Here is answer done' (or similar) — step 1 strips the well-formed pair; step 2 should only fire when there is no preceding <think>.
Actual
Returns 'done'. The lazy pattern at utils.ts:38 /[\s\S]*?<\/think>/g matches from string start to the first remaining </think>, wiping the 'Here is answer' that step 1 already produced as valid output.
Hits any reasoning model (DeepSeek-R1, Llama-3.3, gpt-5) that sometimes emits a trailing stray </think> — e.g. when discussing the tag itself in code or truncating mid-stream.
Suggested fix: only run step 2 when step 1 produced no replacement, or anchor step 2 to ^[\s\S]*?<\/think> and run once.
Environment
nanobrowser 0.1.13, TypeScript 5.5.4 (per root package.json). File: chrome-extension/src/background/agent/messages/utils.ts:31-42.
Thanks for maintaining nanobrowser/nanobrowser!
Source: nanobrowser/nanobrowser