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(agent): native tool steps keep their call ids for a later cloud turn

purple207e190730ac
diff --git a/src/hooks/__tests__/a-native-step-keeps-its-call-ids.test.ts b/src/hooks/__tests__/a-native-step-keeps-its-call-ids.test.ts
new file mode 100644
index 00000000..cecd49e8
--- /dev/null
+++ b/src/hooks/__tests__/a-native-step-keeps-its-call-ids.test.ts
@@ -0,0 +1,42 @@
+/**
+ * Bug hunt 01.10.2026 (A7). On the native (Ollama) channel both loops wrote
+ * the assistant tool_calls without ids and the tool results without
+ * tool_call_id. That chain is kept as hidden history, so a switch to LU Cloud
+ * in the same conversation sent id-less calls next to results a strict
+ * upstream cannot tie to them: a 422, or at best a prefix that changed every
+ * step and missed the upstream cache. The ids now stay on every transport.
+ */
+import { describe, it, expect } from 'vitest'
+import { readFileSync } from 'node:fs'
+import { resolve } from 'node:path'
+
+const read = (f: string) => readFileSync(resolve(__dirname, '..', f), 'utf8')
+
+function nativeBranch(src: string): string {
+ const at = src.indexOf("} else if (strategy === 'native') {\n")
+ expect(at).toBeGreaterThan(0)
+ return src.slice(at, src.indexOf('} else {', at))
+}
+
+describe('a native step keeps its call ids', () => {
+ it('Agent tab', () => {
+ const branch = nativeBranch(read('useAgentChat.ts'))
+ expect(branch).toMatch(/tool_calls: toolCalls\.map\(\(tc\) => \(\{\s+id: tc\.id,/)
+ expect(branch).toContain('tool_call_id: tc.id')
+ })
+
+ it('Code tab', () => {
+ const branch = nativeBranch(read('useCodex.ts'))
+ expect(branch).toMatch(/tool_calls: batch\.map\(\(e\) => \(\{\s+id: e\.tc\.id,/)
+ expect(branch).toContain('tool_call_id: tc.id')
+ })
+
+ it('every call has an id before the batch is built, in both loops', () => {
+ for (const f of ['useAgentChat.ts', 'useCodex.ts']) {
+ const src = read(f)
+ const ids = src.indexOf('toolCalls = toolCalls.map((tc) => (tc.id ? tc : { ...tc, id: uuid() }))')
+ expect(ids, f).toBeGreaterThan(0)
+ expect(ids, f).toBeLessThan(src.indexOf("} else if (strategy === 'native') {\n"))
+ }
+ })
+})
diff --git a/src/hooks/useAgentChat.ts b/src/hooks/useAgentChat.ts
index d9ea0f30..e2b30e0a 100644
--- a/src/hooks/useAgentChat.ts
+++ b/src/hooks/useAgentChat.ts
@@ -2704,10 +2704,16 @@ export function useAgentChat() {
}, tc))
}
} else if (strategy === 'native') {
+ // Ids kept on the native channel too (bug hunt 01.10.2026, A7). Ollama
+ // ignores them, but this chain is saved as hidden history: a switch to
+ // LU Cloud in the same conversation sent id-less calls and results,
+ // which a strict upstream 422s, or at best a prompt prefix that changed
+ // every step and missed the upstream cache.
agentMessages.push({
role: 'assistant',
content: turnContent || '',
tool_calls: toolCalls.map((tc) => ({
+ id: tc.id,
function: { name: tc.function.name, arguments: tc.function.arguments },
})),
})
@@ -2716,6 +2722,7 @@ export function useAgentChat() {
agentMessages.push(rememberResult({
role: 'tool',
content: resultTextFor(result) + mediaNote(tc.function.name, result),
+ tool_call_id: tc.id,
}, tc))
}
} else {
diff --git a/src/hooks/useCodex.ts b/src/hooks/useCodex.ts
index 55aa1d22..644fc7ba 100644
--- a/src/hooks/useCodex.ts
+++ b/src/hooks/useCodex.ts
@@ -2385,16 +2385,19 @@ export function useCodex() {
messages.push(rememberResult({ role: 'tool', content: resultTextFor(result), tool_call_id: tc.id }, tc))
}
} else if (strategy === 'native') {
+ // Ids kept here too (bug hunt 01.10.2026, A7): Ollama ignores them,
+ // and a later switch to LU Cloud in the same conversation needs them.
messages.push({
role: 'assistant',
content: turnContent || '',
tool_calls: batch.map((e) => ({
+ id: e.tc.id,
function: { name: e.ac.toolName, arguments: e.injectedArgs },
})),
})
for (const { tc } of batch) {
const result = results.find((r) => r.id === batch.find((b) => b.tc === tc)?.ac.id)!
- messages.push(rememberResult({ role: 'tool', content: resultTextFor(result) }, tc))
+ messages.push(rememberResult({ role: 'tool', content: resultTextFor(result), tool_call_id: tc.id }, tc))
}
} else {
// Ollama on a non-native strategy that is not hermes_xml. Same