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): a declined call tells the model its tools are still there

purplea9827e23a785
diff --git a/src/hooks/__tests__/a-declined-call-tells-the-model-it-still-has-tools.test.ts b/src/hooks/__tests__/a-declined-call-tells-the-model-it-still-has-tools.test.ts
new file mode 100644
index 00000000..bd95a258
--- /dev/null
+++ b/src/hooks/__tests__/a-declined-call-tells-the-model-it-still-has-tools.test.ts
@@ -0,0 +1,92 @@
+/**
+ * @vitest-environment jsdom
+ *
+ * Gegenprobe 01.10.2026: after "No" on an approval card the Code tab handed
+ * the model the bare "User rejected tool call", and Mistral answered that it
+ * had no tools at all. The next request now tells the model the call did not
+ * run, its tools are still there, and not to repeat the same call.
+ *
+ * Run: npx vitest run src/hooks/__tests__/a-declined-call-tells-the-model-it-still-has-tools.test.ts
+ */
+import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
+import { renderHook, act, waitFor } from '@testing-library/react'
+
+vi.mock('../../api/cloud/supabase', () => ({
+ getAccessToken: async () => 'session-token-abc',
+}))
+vi.mock('../../api/rag', () => ({
+ retrieveContext: async () => ({ context: { chunks: [], query: '', documentIds: [] }, scoredChunks: [] }),
+ generateEmbeddings: async () => [[0.1, 0.2]],
+}))
+vi.mock('../../lib/ttsBridge', () => ({ autoSpeak: () => {} }))
+vi.mock('../../api/vram-handoff', () => ({ requestGenerationCancel: () => {} }))
+vi.mock('../useMemory', () => ({
+ useMemory: () => ({ extractAndSave: async () => {} }),
+ extractMemoriesFromPair: async () => {},
+}))
+
+import { useCodex } from '../useCodex'
+import { useChatStore } from '../../stores/chatStore'
+import { useModelStore } from '../../stores/modelStore'
+import { useSettingsStore } from '../../stores/settingsStore'
+import { useProviderStore } from '../../stores/providerStore'
+import { useCodexStore } from '../../stores/codexStore'
+import { useCodexConfirmStore } from '../../stores/codexConfirmStore'
+import { useGenerationStore } from '../../stores/generationStore'
+import { DEFAULT_SETTINGS } from '../../lib/constants'
+import { __resetRunStopsForTests } from '../../lib/run-stop'
+import { REJECTED_CALL_FOR_MODEL } from '../../lib/rejected-call'
+import { toolRegistry, registerBuiltinTools } from '../../api/mcp'
+
+const MODEL = 'lu-cloud::zai-org/GLM-5.3'
+const sse = (...payloads: object[]) =>
+ payloads.map((p) => `data: ${JSON.stringify(p)}\n\n`).join('') + 'data: [DONE]\n\n'
+
+const bodies: Array<{ messages: Array<{ role: string; content: unknown; tool_call_id?: string }> }> = []
+
+beforeEach(() => {
+ registerBuiltinTools(toolRegistry)
+ __resetRunStopsForTests()
+ bodies.length = 0
+ useChatStore.setState({ conversations: [], activeConversationId: null })
+ useGenerationStore.setState({ generating: {}, aborters: {}, runs: {} })
+ useCodexStore.setState({ modeByConversation: {}, lastPickedMode: null, parkedModeByConversation: {} })
+ useSettingsStore.setState({ settings: { ...DEFAULT_SETTINGS, appMode: 'cloud', cavemanMode: 'off', codexConfirmShell: true } })
+ useProviderStore.setState((s) => ({
+ providers: { ...s.providers, 'lu-cloud': { ...s.providers['lu-cloud'], enabled: true } },
+ }))
+ useModelStore.setState({ models: [], activeModel: MODEL })
+ vi.spyOn(globalThis, 'fetch').mockImplementation(async (input: RequestInfo | URL, init?: RequestInit) => {
+ if (!String(input).includes('/chat/completions')) return new Response('{}', { status: 200 })
+ bodies.push(JSON.parse(String(init?.body)))
+ const first = bodies.length === 1
+ const text = first
+ ? sse(
+ { choices: [{ delta: { tool_calls: [{ index: 0, id: 'c1', function: { name: 'shell_execute', arguments: '{"command":"npm test"}' } }] } }] },
+ { choices: [{ delta: {}, finish_reason: 'tool_calls' }] },
+ )
+ : sse({ choices: [{ delta: { content: 'Understood, I will not run it.' }, finish_reason: 'stop' }] })
+ return new Response(text, { status: 200, headers: { 'content-type': 'text/event-stream' } })
+ })
+})
+afterEach(() => vi.restoreAllMocks())
+
+describe('after the user says No', () => {
+ it('the model reads that the call did not run and its tools are still there', async () => {
+ const { result } = renderHook(() => useCodex())
+ const convId = useChatStore.getState().createConversation(MODEL, '', 'codex')
+ useChatStore.getState().setActiveConversation(convId)
+ useCodexStore.getState().chooseCodexMode(convId, 'ask', false)
+
+ let run!: Promise<unknown>
+ act(() => { run = result.current.sendInstruction('run the tests') })
+ await waitFor(() => expect(useCodexConfirmStore.getState().pending).not.toBeNull())
+ act(() => useCodexConfirmStore.getState().answer(false))
+ await act(async () => { await run })
+
+ expect(bodies.length).toBeGreaterThanOrEqual(2)
+ const toolMsg = bodies[1].messages.find((m) => m.role === 'tool')
+ expect(String(toolMsg?.content)).toContain(REJECTED_CALL_FOR_MODEL)
+ expect(String(toolMsg?.content)).not.toContain('User rejected tool call')
+ })
+})
diff --git a/src/hooks/useAgentChat.ts b/src/hooks/useAgentChat.ts
index d6d4fb21..2928cc5d 100644
--- a/src/hooks/useAgentChat.ts
+++ b/src/hooks/useAgentChat.ts
@@ -79,6 +79,7 @@ import { useAgentGoalStore, renderGoalSection } from '../stores/agentGoalStore'
import { endLoopUnlessRearmed, useAgentLoopStore } from '../stores/agentLoopStore'
import { beginRun, isRunStopped, stopRun } from '../lib/run-stop'
import { noteStoppedIfEmpty } from '../lib/stopped-note'
+import { REJECTED_CALL_FOR_MODEL } from '../lib/rejected-call'
import { buildLoopRecheck, loopPassSaysDone } from '../lib/agent-commands'
import { applyStoredCompaction } from '../lib/compact-summary'
import { maybeAutoCompact } from '../lib/run-compact-command'
@@ -2600,7 +2601,7 @@ export function useAgentChat() {
const resultTextFor = (r: typeof results[number]): string => {
const text =
r.status === 'rejected'
- ? 'User rejected this action. Try a different approach.'
+ ? REJECTED_CALL_FOR_MODEL
: r.status === 'completed' || r.status === 'cached'
? (r.result ?? '')
: r.errorHint
diff --git a/src/hooks/useCodex.ts b/src/hooks/useCodex.ts
index fc95345c..b9c208b3 100644
--- a/src/hooks/useCodex.ts
+++ b/src/hooks/useCodex.ts
@@ -28,6 +28,7 @@ import { useAgentTaskStore } from '../stores/agentTaskStore'
import { useAgentGoalStore, renderGoalSection } from '../stores/agentGoalStore'
import { endLoopUnlessRearmed, useAgentLoopStore } from '../stores/agentLoopStore'
import { beginRun, isRunStopped, stopRun } from '../lib/run-stop'
+import { REJECTED_CALL_FOR_MODEL } from '../lib/rejected-call'
import { noteStoppedIfEmpty } from '../lib/stopped-note'
import { CODEX_CONFIRM_TOOLS, renderApprovalPreview } from './codexShellGate'
import { buildHermesToolPrompt, buildHermesToolResult, buildHermesToolCall, parseHermesToolCalls, stripToolCallTags, hasToolCallTags } from '../api/hermes-tool-calling'
@@ -2354,6 +2355,8 @@ export function useCodex() {
const text =
r.status === 'completed' || r.status === 'cached'
? (r.result ?? '')
+ : r.status === 'rejected'
+ ? REJECTED_CALL_FOR_MODEL
: r.errorHint
? `${r.error ?? 'Tool failed'}, ${r.errorHint}`
: (r.error ?? 'Tool failed')
diff --git a/src/lib/__tests__/tool-failure-note.test.ts b/src/lib/__tests__/tool-failure-note.test.ts
index a3d9c128..3aa9bbe0 100644
--- a/src/lib/__tests__/tool-failure-note.test.ts
+++ b/src/lib/__tests__/tool-failure-note.test.ts
@@ -26,7 +26,7 @@ describe('toolFailureNote', () => {
})
it('schweigt bei einer Ablehnung — die hat schon ihren eigenen Satz', () => {
- // 'User rejected this action. Try a different approach.' steht bereits in
+ // REJECTED_CALL_FOR_MODEL (lib/rejected-call.ts) steht bereits in
// der Historie; ein zweiter Satz davor waere nur Laerm.
expect(toolFailureNote('rejected')).toBe('')
})
diff --git a/src/lib/rejected-call.ts b/src/lib/rejected-call.ts
new file mode 100644
index 00000000..f75c14ef
--- /dev/null
+++ b/src/lib/rejected-call.ts
@@ -0,0 +1,12 @@
+/**
+ * What the model reads when the user said No to one of its tool calls.
+ *
+ * Gegenprobe 01.10.2026: after "No" the Code tab handed the model the bare
+ * executor text "User rejected tool call", and Mistral answered that it had no
+ * tools at all. The model has to know three things to carry on usefully: the
+ * call did not run, its tools are still there, and repeating the same call is
+ * the one thing that will not help. One sentence for Code and Agent.
+ */
+export const REJECTED_CALL_FOR_MODEL =
+ 'The user declined this tool call, so it did not run. All your tools are still available. ' +
+ 'Do not repeat the same call: continue another way, or ask the user what they want instead.'