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.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
fix(agent): the in-turn cache does not serve a failure as a result
purple70ba5579dc38
diff --git a/src/api/agents/__tests__/a-failure-is-not-served-from-the-cache.test.ts b/src/api/agents/__tests__/a-failure-is-not-served-from-the-cache.test.tsnew file mode 100644index 00000000..16cdfc94--- /dev/null+++ b/src/api/agents/__tests__/a-failure-is-not-served-from-the-cache.test.ts@@ -0,0 +1,34 @@+import { describe, it, expect, beforeEach } from 'vitest'+import { makeInTurnCacheLookup } from '../in-turn-cache'+import { useToolAuditStore } from '../../../stores/toolAuditStore'+import { stableArgsHash } from '../block-helpers'++/**+ * Bug hunt 01.10.2026, A5: tools report most failures as text with status+ * 'completed'. The in-turn cache kept such a failure as a hit, so a retry in+ * the same turn got the old error back and the call never ran again.+ */++function prior(toolName: string, args: Record<string, unknown>, result: string): void {+ const s = useToolAuditStore.getState()+ const id = s.record({ convId: 'c1', toolCallId: `p-${toolName}`, toolName, args, startedAt: 1000 })+ s.complete(id, { status: 'completed', completedAt: 1100, resultPreview: result })+}++describe('the in-turn cache does not serve a failure', () => {+ beforeEach(() => useToolAuditStore.getState().clearAll())++ it('a failed web_fetch runs again on the retry', () => {+ const args = { url: 'https://example.com' }+ prior('web_fetch', args, 'Error: fetch timed out after 30s')+ const lookup = makeInTurnCacheLookup({ convId: 'c1', turnStartMs: 500 })+ expect(lookup({ id: 'n', toolName: 'web_fetch', args }, stableArgsHash(args))).toBeUndefined()+ })++ it('a successful web_fetch is still served from the cache', () => {+ const args = { url: 'https://example.com' }+ prior('web_fetch', args, '<h1>Example Domain</h1>')+ const lookup = makeInTurnCacheLookup({ convId: 'c1', turnStartMs: 500 })+ expect(lookup({ id: 'n', toolName: 'web_fetch', args }, stableArgsHash(args))).toBe('<h1>Example Domain</h1>')+ })+})diff --git a/src/api/agents/in-turn-cache.ts b/src/api/agents/in-turn-cache.tsindex 11c9f6b0..76190cf5 100644--- a/src/api/agents/in-turn-cache.ts+++ b/src/api/agents/in-turn-cache.ts@@ -18,6 +18,7 @@import { useToolAuditStore } from '../../stores/toolAuditStore'import type { ExecutionRequest } from './tool-executor'+import { toolResultIsFailure } from '../../lib/tool-result-failure'export interface InTurnCacheOptions {convId: string@@ -124,6 +125,12 @@ export function makeInTurnCacheLookup(opts: InTurnCacheOptions) {// as a miss so the model re-reads the whole file instead of a silently// truncated slice. Empty strings are a legitimate cached payload.if (typeof candidate.fullResult !== 'string') return undefined+ // A failure is not an answer to keep (bug hunt 01.10.2026, A5). Tools+ // report most failures as text with status 'completed', so the audit kept+ // a timed-out web_fetch or a file_read of a file not written yet as a hit,+ // and every retry in the same turn got the old error back without the+ // call running again.+ if (toolResultIsFailure(candidate.fullResult)) return undefinedreturn candidate.fullResult}}