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 step the run fixed itself is not shown as an error

purple60c35575e486
diff --git a/src/components/chat/ToolCallBand.tsx b/src/components/chat/ToolCallBand.tsx
index b2feafa5..3650cf42 100644
--- a/src/components/chat/ToolCallBand.tsx
+++ b/src/components/chat/ToolCallBand.tsx
@@ -13,6 +13,7 @@ import {
groupIsLive,
type BandNote,
} from '../../lib/tool-call-groups'
+import { hasUnrecoveredFailure } from '../../lib/recovered-failure'
import { MOTION_S } from '../ui/motion'
interface Props {
@@ -45,7 +46,9 @@ export function ToolCallBand({ calls, notes, renderNote, pendingApprovalId, onAp
const expanded = userToggled ?? false
const live = groupIsLive(calls)
const active = activeToolCall(calls)
- const anyFailed = calls.some((c) => c.status === 'failed' || c.status === 'rejected')
+ // A failure the run fixed by itself does not mark the header (Gegenprobe
+ // 01.10.2026); the step keeps its own mark in the expanded list.
+ const anyFailed = hasUnrecoveredFailure(calls)
const durationLabel = groupDurationLabel(calls)
const blockFor = (tc: AgentToolCall) => {
diff --git a/src/components/chat/__tests__/a-fixed-failure-keeps-the-header-calm.test.tsx b/src/components/chat/__tests__/a-fixed-failure-keeps-the-header-calm.test.tsx
new file mode 100644
index 00000000..74b0b337
--- /dev/null
+++ b/src/components/chat/__tests__/a-fixed-failure-keeps-the-header-calm.test.tsx
@@ -0,0 +1,40 @@
+/**
+ * @vitest-environment jsdom
+ *
+ * Gegenprobe 01.10.2026: "3 steps" carried a red mark although the run fixed
+ * its one failed step itself and ended well. The header now marks only a
+ * failure the run did not fix (lib/recovered-failure.ts).
+ */
+import { describe, it, expect, afterEach } from 'vitest'
+import { createElement } from 'react'
+import { render, cleanup } from '@testing-library/react'
+import { ToolCallBand } from '../ToolCallBand'
+import type { AgentToolCall } from '../../../types/agent-mode'
+
+afterEach(() => cleanup())
+
+let n = 0
+const call = (toolName: string, status: AgentToolCall['status'], path: string): AgentToolCall =>
+ ({ id: `t${++n}`, toolName, args: { path }, status, timestamp: n, duration: 12 }) as AgentToolCall
+
+const redMark = (el: HTMLElement) => el.querySelector('.text-red-400\\/60')
+
+describe('the steps header after a run', () => {
+ it('fixed by the run itself: no red mark', () => {
+ const { container } = render(createElement(ToolCallBand, { calls: [
+ call('file_write', 'failed', 'C:\\Users\\x\\Desktop\\poem.txt'),
+ call('file_write', 'completed', 'poem.txt'),
+ call('file_read', 'completed', 'poem.txt'),
+ ] }))
+ expect(container.textContent).toContain('3 steps')
+ expect(redMark(container)).toBeNull()
+ })
+
+ it('not fixed: the red mark stays', () => {
+ const { container } = render(createElement(ToolCallBand, { calls: [
+ call('file_read', 'failed', 'C:\\data\\sales.csv'),
+ call('file_list', 'completed', '.'),
+ ] }))
+ expect(redMark(container)).not.toBeNull()
+ })
+})
diff --git a/src/components/chat/__tests__/agent-workspace-sichtbar.test.tsx b/src/components/chat/__tests__/agent-workspace-sichtbar.test.tsx
index 1e605819..b306594a 100644
--- a/src/components/chat/__tests__/agent-workspace-sichtbar.test.tsx
+++ b/src/components/chat/__tests__/agent-workspace-sichtbar.test.tsx
@@ -61,14 +61,17 @@ describe('the pill shows where the agent really works', () => {
})
describe('the refusal reaches the user whatever the model says', () => {
- it('the agent chat raises the line from the applied call, file_edit included', async () => {
+ it('the agent chat raises the line at the end of the run, from the applied calls', async () => {
const { readFileSync } = await import('node:fs')
const { join } = await import('node:path')
const src = readFileSync(join(__dirname, '..', '..', '..', 'hooks', 'useAgentChat.ts'), 'utf8')
- expect(src).toContain("isOutsideWorkspaceRefusal(entry.ac.toolName, entry.ac.error)")
+ expect(src).toContain('hasUnrecoveredOutsideRefusal(steps)')
expect(src).toContain("show('agent-outside-workspace', OUTSIDE_WORKSPACE_NOTICE)")
- // After applyResultToToolCall, which is what turns file_edit's text into a failure.
- expect(src.indexOf("isOutsideWorkspaceRefusal(entry.ac.toolName"))
- .toBeGreaterThan(src.indexOf('applyResultToToolCall(entry.ac, result)'))
+ // In the finally, after every applyResultToToolCall, which is what turns
+ // file_edit's text into a failure.
+ expect(src.indexOf('hasUnrecoveredOutsideRefusal(steps)'))
+ .toBeGreaterThan(src.lastIndexOf('applyResultToToolCall(entry.ac, result)'))
+ expect(src.indexOf('hasUnrecoveredOutsideRefusal(steps)'))
+ .toBeGreaterThan(src.indexOf(' } finally {', src.indexOf('// ── Agent Loop ──')))
})
})
diff --git a/src/hooks/useAgentChat.ts b/src/hooks/useAgentChat.ts
index 2e1c48db..fe38850b 100644
--- a/src/hooks/useAgentChat.ts
+++ b/src/hooks/useAgentChat.ts
@@ -95,7 +95,7 @@ import { executeParallel, applyResultToToolCall, resultFailed, type ExecutionReq
import { useToolAuditStore } from '../stores/toolAuditStore'
import { makeInTurnCacheLookup } from '../api/agents/in-turn-cache'
import { explainError as explainToolError } from '../api/agents/error-hints'
-import { isOutsideWorkspaceRefusal, OUTSIDE_WORKSPACE_NOTICE } from '../lib/workspace-refusal'
+import { hasUnrecoveredOutsideRefusal, OUTSIDE_WORKSPACE_NOTICE } from '../lib/workspace-refusal'
import { useChatNoticeStore } from '../stores/chatNoticeStore'
import { settleThinking } from '../lib/thinking-stripper'
import { openPlanGap, planReconcileSteer, PLAN_RECONCILE_BUDGET } from '../lib/plan-reconcile'
@@ -2576,15 +2576,6 @@ export function useAgentChat() {
const result = results.find((r) => r.id === entry.ac.id)
if (!result) continue
applyResultToToolCall(entry.ac, result)
- // Discord 2026-09-28 (xambran): a file outside the chat's folder was
- // refused in a collapsed tool block, and the model alone was left to
- // explain it. The user gets the way out above the chat, whatever the
- // model makes of the refusal (lib/workspace-refusal.ts).
- // Read off the applied call: file_edit returns its refusal as text,
- // and only applyResultToToolCall turns that into a failure.
- if (entry.ac.status === 'failed' && isOutsideWorkspaceRefusal(entry.ac.toolName, entry.ac.error)) {
- useChatNoticeStore.getState().show('agent-outside-workspace', OUTSIDE_WORKSPACE_NOTICE)
- }
// Over-loop accounting (David 2026-06-04): remember every executed call
// (so an identical repeat is skipped) and count successful media gens
// against the per-turn cap that stops "13× the same cat".
@@ -3016,6 +3007,18 @@ export function useAgentChat() {
// unstoppable through generationStore (Stop button, sign-out, window
// close, app quit) even though activeAgentRuns still pointed at it.
// A Stop before anything was written leaves a line, not an empty bubble.
+ // Discord 2026-09-28 (xambran): a file outside the chat's folder was
+ // refused in a collapsed tool block, and the model alone was left to
+ // explain it. The user gets the way out above the chat, whatever the
+ // model makes of the refusal (lib/workspace-refusal.ts). Only when the
+ // run did not fix it itself: a model that retried inside its folder
+ // and succeeded left a "then ask again" over a finished task
+ // (Gegenprobe 01.10.2026). file_edit returns its refusal as text, and
+ // only applyResultToToolCall turned that into the failure read here.
+ const steps = runState.blocks.flatMap((b) => (b.phase === 'tool_call' && b.toolCall ? [b.toolCall] : []))
+ if (hasUnrecoveredOutsideRefusal(steps)) {
+ useChatNoticeStore.getState().show('agent-outside-workspace', OUTSIDE_WORKSPACE_NOTICE)
+ }
if (abort.signal.aborted || isRunStopped(convId)) {
if (placeholderId && runState.blocks.some((b) => b.id === placeholderId)) {
removeBlock(runState, convId, assistantMessage.id, placeholderId)
diff --git a/src/lib/__tests__/a-fixed-failure-is-not-news.test.ts b/src/lib/__tests__/a-fixed-failure-is-not-news.test.ts
new file mode 100644
index 00000000..e685ef68
--- /dev/null
+++ b/src/lib/__tests__/a-fixed-failure-is-not-news.test.ts
@@ -0,0 +1,54 @@
+/**
+ * Gegenprobe 01.10.2026: Mistral wrote poem.txt to the Desktop first, the
+ * folder guard refused it, the next step wrote poem.txt into the chat's own
+ * folder, and the run ended well. The steps header still showed red and a
+ * line said "then ask again". A failure the run fixed itself is not news.
+ *
+ * Run: npx vitest run src/lib/__tests__/a-fixed-failure-is-not-news.test.ts
+ */
+import { describe, it, expect } from 'vitest'
+import { isRecovered, hasUnrecoveredFailure } from '../recovered-failure'
+import { hasUnrecoveredOutsideRefusal } from '../workspace-refusal'
+
+const REFUSED = 'Path escapes the allowed workspace: C:\\Users\\x\\Desktop\\poem.txt'
+const step = (toolName: string, status: string, path?: string, error?: string) =>
+ ({ toolName, status, args: path ? { path } : {}, error })
+
+describe('a failure the run fixed itself', () => {
+ const poemRun = [
+ step('file_write', 'failed', 'C:\\Users\\x\\Desktop\\poem.txt', REFUSED),
+ step('file_write', 'completed', 'poem.txt'),
+ step('file_read', 'completed', 'poem.txt'),
+ ]
+
+ it('the box run: the header stays calm and no "ask again" line', () => {
+ expect(isRecovered(poemRun, 0)).toBe(true)
+ expect(hasUnrecoveredFailure(poemRun)).toBe(false)
+ expect(hasUnrecoveredOutsideRefusal(poemRun)).toBe(false)
+ })
+
+ it('a refused file the run never got: the line and the mark stay', () => {
+ const run = [step('file_read', 'failed', 'C:\\data\\sales.csv', REFUSED), step('file_list', 'completed', '.')]
+ expect(hasUnrecoveredFailure(run)).toBe(true)
+ expect(hasUnrecoveredOutsideRefusal(run)).toBe(true)
+ })
+
+ it('another file of the same tool is no fix', () => {
+ const run = [step('file_read', 'failed', 'C:\\data\\sales.csv', REFUSED), step('file_read', 'completed', 'notes.txt')]
+ expect(isRecovered(run, 0)).toBe(false)
+ })
+
+ it('a success BEFORE the failure is no fix', () => {
+ const run = [step('file_write', 'completed', 'a.txt'), step('file_write', 'failed', 'a.txt')]
+ expect(hasUnrecoveredFailure(run)).toBe(true)
+ })
+
+ it('tools without a path: a later success of the same tool fixes it', () => {
+ const run = [step('web_search', 'failed'), step('web_search', 'completed')]
+ expect(hasUnrecoveredFailure(run)).toBe(false)
+ })
+
+ it('a rejection by the user still marks the header, a tick would claim it ran', () => {
+ expect(hasUnrecoveredFailure([step('shell_execute', 'rejected')])).toBe(true)
+ })
+})
diff --git a/src/lib/recovered-failure.ts b/src/lib/recovered-failure.ts
new file mode 100644
index 00000000..23364c87
--- /dev/null
+++ b/src/lib/recovered-failure.ts
@@ -0,0 +1,49 @@
+/**
+ * Did a failed step get fixed later in the same run?
+ *
+ * Gegenprobe 01.10.2026: Mistral first wrote poem.txt to the user's Desktop,
+ * the folder guard refused it, and the next step wrote poem.txt into the
+ * chat's own folder. The run ended well, and still the steps header showed a
+ * red mark and a line above the chat said "then ask again". A failure the run
+ * fixed by itself is not news for the customer. The failed step keeps its own
+ * red mark inside the expanded list, where it is the truth about that step.
+ *
+ * Fixed means: a LATER call of the same tool succeeded, on the same file name
+ * when the calls carry a path. A read of data.csv that failed is not fixed by
+ * a read of notes.txt.
+ */
+
+type Step = {
+ toolName: string
+ status: string
+ args?: unknown
+}
+
+const OK = new Set(['completed', 'cached'])
+
+function baseName(args: unknown): string | null {
+ if (!args || typeof args !== 'object') return null
+ const path = (args as Record<string, unknown>).path
+ if (typeof path !== 'string' || !path.trim()) return null
+ const parts = path.trim().split(/[\\/]+/).filter(Boolean)
+ return parts.length ? parts[parts.length - 1].toLowerCase() : null
+}
+
+/** Does the step at `index` count as fixed by a later step in `steps`? */
+export function isRecovered(steps: readonly Step[], index: number): boolean {
+ const failed = steps[index]
+ if (!failed) return false
+ const name = baseName(failed.args)
+ for (let i = index + 1; i < steps.length; i++) {
+ const later = steps[i]
+ if (later.toolName !== failed.toolName || !OK.has(later.status)) continue
+ if (name === null || baseName(later.args) === name) return true
+ }
+ return false
+}
+
+/** A failed step the run did not fix, or a step the user rejected (a tick
+ * next to a rejection would claim it ran). */
+export function hasUnrecoveredFailure(steps: readonly Step[]): boolean {
+ return steps.some((s, i) => s.status === 'rejected' || (s.status === 'failed' && !isRecovered(steps, i)))
+}
diff --git a/src/lib/workspace-refusal.ts b/src/lib/workspace-refusal.ts
index 14bdf621..2404176a 100644
--- a/src/lib/workspace-refusal.ts
+++ b/src/lib/workspace-refusal.ts
@@ -12,6 +12,8 @@
// (`contain_within`, `check_workspace_root`), mirrored for the dev server in
// lib/dev-fs-jail.ts. Its wording is pinned there; this only recognises it.
+import { isRecovered } from './recovered-failure'
+
/** Both jail refusals: a path that leaves the working folder, and a working
* folder the jail does not accept at all. */
export const OUTSIDE_WORKSPACE = /escapes the allowed workspace|Not an allowed workspace folder/i
@@ -24,6 +26,15 @@ export function isOutsideWorkspaceRefusal(toolName: string, error: string | null
return FILE_TOOLS.has(toolName) && !!error && OUTSIDE_WORKSPACE.test(error)
}
+/** A refused file the run did not get by itself (a later call of the same
+ * tool on the same file name succeeded). Only then is the line worth
+ * showing; see lib/recovered-failure.ts. */
+export function hasUnrecoveredOutsideRefusal(
+ steps: readonly { toolName: string; status: string; error?: string | null; args?: unknown }[],
+): boolean {
+ return steps.some((c, i) => c.status === 'failed' && isOutsideWorkspaceRefusal(c.toolName, c.error) && !isRecovered(steps, i))
+}
+
/** The line above the chat, in the words of the buttons the user sees. */
export const OUTSIDE_WORKSPACE_NOTICE =
'The agent can only open files in this chat\'s folder. To let it use yours, click the Sandbox or folder button next to Agent, choose "Pick a folder…" and select the folder that holds them, then ask again.'