Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

fix(chat): clear an UNCLOSED tool-call tag out of the visible answer

purple178ec7b7ac0b
diff --git a/src/lib/__tests__/loose-tool-parse.test.ts b/src/lib/__tests__/loose-tool-parse.test.ts
index d9369b42..982e978a 100644
--- a/src/lib/__tests__/loose-tool-parse.test.ts
+++ b/src/lib/__tests__/loose-tool-parse.test.ts
@@ -278,3 +278,28 @@ describe('parseLooseToolCalls — nested function object + string args (OpenAI/P
expect(r.calls[0]).toEqual({ name: 'image_generate', arguments: { prompt: 'y' } })
})
})
+
+describe('stripToolCallText — leftover Hermes tags', () => {
+ const KN = ['file_list', 'file_read', 'web_search']
+
+ // Live Agent run, ship exe 2026-07-25. stripToolCallTags only removes matched
+ // PAIRS, so an unclosed `<tool_call>` survived every stripper and reached the
+ // bubble, where the renderer ate the `<t` and the user saw `ool_call>`.
+ it('removes an UNCLOSED opening tag', () => {
+ expect(stripToolCallText('Let me look.\n<tool_call>', KN)).toBe('Let me look.')
+ })
+
+ it('removes a stray closing tag', () => {
+ expect(stripToolCallText('</tool_call>\nDone.', KN)).toBe('Done.')
+ })
+
+ it('still removes the piped and bracketed spellings', () => {
+ expect(stripToolCallText('<|tool_call|>x', KN)).toBe('x')
+ expect(stripToolCallText('[TOOL_CALLS]x', KN)).toBe('x')
+ })
+
+ it('leaves ordinary prose about tool calls alone', () => {
+ const prose = 'the tool call failed, try again'
+ expect(stripToolCallText(prose, KN)).toBe(prose)
+ })
+})
diff --git a/src/lib/loose-tool-parse.ts b/src/lib/loose-tool-parse.ts
index 431a9fb8..a192748d 100644
--- a/src/lib/loose-tool-parse.ts
+++ b/src/lib/loose-tool-parse.ts
@@ -303,6 +303,12 @@ export function stripToolCallText(text: string, known: string[]): string {
// (Phi-4: <|tool_call|>/<|tool|>; Mistral: [TOOL_CALLS]) so they don't show
// in the bubble. Detection/parsing above already handled the JSON inside.
.replace(/<\|\/?tool(?:_call)?(?:_start|_end)?\|>/gi, '')
+ // The plain Hermes spelling with no pipes. stripToolCallTags only removes
+ // MATCHED pairs, so an unclosed `<tool_call>` (a stream that ended mid-tag,
+ // a model that opened one and then answered in prose) walked all the way to
+ // the bubble — where the markdown renderer swallowed the `<t` and left the
+ // user staring at a bare `ool_call>` (live Agent run, ship exe 2026-07-25).
+ .replace(/<[|/\s]*tool_calls?[|/\s]*>/gi, '')
.replace(/\[\/?TOOL_CALLS?\]/gi, '')
.replace(/```(?:json|tool_code)?\s*```/gi, '')
.replace(/\n{3,}/g, '\n\n')