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): repeats the Agent tab skipped are named to the model; a chatty near-copy loop counts (CA loops)
purple48ecc9a8922e
diff --git a/src/hooks/useAgentChat.ts b/src/hooks/useAgentChat.tsindex a199f985..62e6b8ac 100644--- a/src/hooks/useAgentChat.ts+++ b/src/hooks/useAgentChat.ts@@ -1,4 +1,5 @@import { stripSourcesMarker } from '../lib/web-evidence'+import { canonicalArgs, repeatLabel, skippedRepeatsNote } from '../lib/agent-core/repeat-note'import { replayableReasoning } from '../lib/agent-core/reasoning-replay'import { useRef, useState, useCallback, useEffect } from 'react'import { frameFlush } from '../lib/frame-flush'@@ -1689,8 +1690,12 @@ export function useAgentChat() {const executedCallKeys = new Set<string>()/** Size of the tool catalogue the step before sent. Zero before the first step. */let catalogTokens = 0+ // Canonical arguments (lib/agent-core/repeat-note.ts): a re-ordered or+ // re-spaced copy of a call is the same call.const callKey = (tc: { function: { name: string; arguments: unknown } }) =>- tc.function.name + '|' + JSON.stringify(tc.function.arguments ?? {})+ tc.function.name + '|' + canonicalArgs(tc.function.arguments)+ // The repeats dropped from the current step, named after its results.+ let skippedRepeats: string[] = []// Loop-detection (audit follow-up): agent-loop-guard's own header says it// covers "Codex + Chat agent", but only Codex ever wired it — the agent// loop relied on the exact-repeat set alone, which the epoch reset (B1)@@ -2562,6 +2567,7 @@ export function useAgentChat() {let droppedVideo = falselet createInTurn = 0const kept: ToolCall[] = []+ skippedRepeats = []for (const tc of toolCalls) {const name = tc.function.nameif (name === CREATE_ORDER_TOOL) {@@ -2573,6 +2579,7 @@ export function useAgentChat() {} else if (executedCallKeys.has(callKey(tc))) {blocked = trueblockedNonMedia = true+ skippedRepeats.push(repeatLabel(name, tc.function.arguments))} else {kept.push(tc)}@@ -2588,6 +2595,8 @@ export function useAgentChat() {// the model to a short final reply ONCE; if it STILL only emits blocked// calls, fall through to the empty-content summary and stop cleanly.if (toolCalls.length === 0 && blocked) {+ // The whole step was repeats: the steer below says so itself.+ skippedRepeats = []if (!mediaSteered) {mediaSteered = trueif (turnContent.trim()) {@@ -3550,6 +3559,13 @@ export function useAgentChat() {if (pendingSteer) {agentMessages.push({ role: 'user', content: pendingSteer })}+ // Part of the step was a repeat and was not run: say which, after the+ // results of the rest (CA, cloud loops).+ {+ const note = skippedRepeatsNote(skippedRepeats)+ skippedRepeats = []+ if (note) agentMessages.push({ role: 'user', content: note })+ }if (failVerdict.action === 'steer') {agentMessages.push({ role: 'user', content: failVerdict.message })}diff --git a/src/lib/__tests__/c83-a-chatty-loop-is-still-a-loop.test.ts b/src/lib/__tests__/c83-a-chatty-loop-is-still-a-loop.test.tsnew file mode 100644index 00000000..a97a3e6e--- /dev/null+++ b/src/lib/__tests__/c83-a-chatty-loop-is-still-a-loop.test.ts@@ -0,0 +1,45 @@+/**+ * CA, cloud loops (13.11.2026): detector 8 (C83) counted only SILENT+ * near-copies. A cloud reasoner like GLM writes one line before every call,+ * "Let me check the file again." with a word changed, and that line reset the+ * streak to one each step, so the same call ran until the budget ended it.+ * A line that is a near-copy of the last one is no news.+ */+import { describe, it, expect } from 'vitest'+import { AgentLoopGuard } from '../agent-loop-guard'++const call = (i: number) => [{+ name: 'code_execute',+ args: JSON.stringify({ language: 'python', code: `import json\nd = json.load(open("data/reports/report_${i % 3}.json"))\nprint(len([x for x in d["items"] if x["status"] == "open"])) # try ${i % 2}` }),+}]++describe('detector 8 with a line before every call', () => {+ it('a near-copied line does not reset the streak: steer, then halt', () => {+ const g = new AgentLoopGuard()+ const verdicts: string[] = []+ for (let i = 0; i < 10; i++) {+ g.recordNarration(`Let me check the report file again, attempt ${i + 1}.`)+ const v = g.recordBatch(call(i))+ verdicts.push(v.action)+ if (v.action === 'halt') break+ }+ expect(verdicts).toContain('steer')+ expect(verdicts[verdicts.length - 1]).toBe('halt')+ })++ it('a line with real news each step keeps it out', () => {+ const g = new AgentLoopGuard()+ const lines = [+ 'Counting open items in the first report.',+ 'The first report has 52 open, now the second one.',+ 'Second done with 52 as well; checking the third.',+ 'All three counted, adding them up and comparing.',+ 'Double checking the status spelling in the data.',+ 'Status field confirmed, writing the summary now.',+ ]+ for (let i = 0; i < lines.length; i++) {+ g.recordNarration(lines[i])+ expect(g.recordBatch(call(i)).action).toBe('ok')+ }+ })+})diff --git a/src/lib/__tests__/loop-guard-failing-rounds.test.ts b/src/lib/__tests__/loop-guard-failing-rounds.test.tsindex 7a6eee17..37d38d27 100644--- a/src/lib/__tests__/loop-guard-failing-rounds.test.ts+++ b/src/lib/__tests__/loop-guard-failing-rounds.test.ts@@ -48,12 +48,33 @@ describe('the icacls run from the R26 measurement', () => {'icacls "C:\\\\…\\\\lu-matrix-sandbox" /grant Everyone=R,X',]- it('NEGATIVE CONTROL: the call-shape detectors never fire on it', () => {- // The model wrote a new line before every attempt in the measurement, so- // detector 8 (silent near-copies, C83) stays out of it as well.+ it('NEGATIVE CONTROL: the call-shape detectors stay out of the first four rounds', () => {+ // The model wrote a line before every attempt in the measurement. Until+ // CA (13.11.2026) any new line counted as news and kept detector 8 (C83)+ // out of the whole run; a line that only changes its number is no news+ // any more, so the fifth near-copy steers. The failure detector (below)+ // still speaks first, at the third failing round.const g = new AgentLoopGuard()- REAL_ARGS.forEach((args, i) => {+ const verdicts = REAL_ARGS.map((args, i) => {g.recordNarration(`Trying permission variant number ${i + 1} on the sandbox folder.`)+ return g.recordBatch([{ name: 'shell_execute', args }]).action+ })+ expect(verdicts.slice(0, 4)).toEqual(['ok', 'ok', 'ok', 'ok'])+ expect(verdicts).not.toContain('halt')+ })++ it('a really new line each round still keeps detector 8 out', () => {+ const lines = [+ 'The grant failed, so I will try the read-execute form instead.',+ 'Quoting the path might matter on Windows, trying that.',+ 'Maybe the comma form is what icacls expects here.',+ 'Checking whether parentheses change how the right is parsed.',+ 'One more spelling of the same right, then I stop.',+ 'Last attempt with quotes and the comma form together.',+ ]+ const g = new AgentLoopGuard()+ REAL_ARGS.forEach((args, i) => {+ g.recordNarration(lines[i])expect(g.recordBatch([{ name: 'shell_execute', args }]).action).toBe('ok')})})diff --git a/src/lib/agent-core/__tests__/repeat-note.test.ts b/src/lib/agent-core/__tests__/repeat-note.test.tsnew file mode 100644index 00000000..ccaa2797--- /dev/null+++ b/src/lib/agent-core/__tests__/repeat-note.test.ts@@ -0,0 +1,46 @@+/**+ * CA, cloud loops: the Agent tab names the repeats it did not run again, and+ * a re-ordered copy of a call is the same call.+ */+import { describe, it, expect } from 'vitest'+import { readFileSync } from 'node:fs'+import { canonicalArgs, repeatLabel, skippedRepeatsNote } from '../repeat-note'++describe('canonicalArgs', () => {+ it('key order and outer spaces do not make a new call', () => {+ expect(canonicalArgs({ path: 'a.ts', limit: 5 })).toBe(canonicalArgs({ limit: 5, path: ' a.ts ' }))+ expect(canonicalArgs({ q: { b: 1, a: [{ y: 2, x: 1 }] } })).toBe(canonicalArgs({ q: { a: [{ x: 1, y: 2 }], b: 1 } }))+ })++ it('different values stay different', () => {+ expect(canonicalArgs({ path: 'a.ts' })).not.toBe(canonicalArgs({ path: 'b.ts' }))+ expect(canonicalArgs(undefined)).toBe('{}')+ })+})++describe('skippedRepeatsNote', () => {+ it('nothing skipped, nothing said', () => {+ expect(skippedRepeatsNote([])).toBeNull()+ })++ it('names every skipped call and says the result is above', () => {+ const note = skippedRepeatsNote([repeatLabel('file_read', { path: 'src/a.ts' })])!+ expect(note).toContain('file_read {"path":"src/a.ts"}')+ expect(note).toMatch(/result is above/)+ })++ it('keeps a long argument list short', () => {+ expect(repeatLabel('code_execute', { code: 'x'.repeat(500) }).length).toBeLessThan(140)+ })+})++describe('the Agent loop uses it', () => {+ const src = readFileSync(new URL('../../../hooks/useAgentChat.ts', import.meta.url), 'utf8')+ it('compares canonical arguments', () => {+ expect(src).toMatch(/tc\.function\.name \+ '\|' \+ canonicalArgs\(tc\.function\.arguments\)/)+ })+ it('names a partial repeat after the results', () => {+ expect(src).toMatch(/skippedRepeats\.push\(repeatLabel\(name, tc\.function\.arguments\)\)/)+ expect(src.indexOf('skippedRepeatsNote(skippedRepeats)')).toBeGreaterThan(src.indexOf('Now the steer sits AFTER the calls it refers to'))+ })+})diff --git a/src/lib/agent-core/repeat-note.ts b/src/lib/agent-core/repeat-note.tsnew file mode 100644index 00000000..179b3b6a--- /dev/null+++ b/src/lib/agent-core/repeat-note.ts@@ -0,0 +1,43 @@+/**+ * Calls the Agent tab did not run again, said to the model (CA, cloud loops,+ * 13.11.2026).+ *+ * The Agent loop drops a call that exactly repeats one already run this turn.+ * When EVERY call of a step was a repeat it said so, but when only some were,+ * the model got results for the others and nothing about the rest: it asked+ * for X and Y, saw Y, and asked for X again on the next step. Now the dropped+ * ones are named after the results.+ *+ * The comparison is on canonical arguments (keys sorted, strings trimmed), so+ * `{"path":"a","limit":5}` and `{"limit":5, "path":"a "}` are one call. A+ * byte-exact key let a cloud model's re-ordered arguments slip past.+ */++/** Arguments as one stable string: keys sorted at every depth, strings trimmed. */+export function canonicalArgs(value: unknown): string {+ return JSON.stringify(canon(value ?? {}))+}++function canon(v: unknown): unknown {+ if (typeof v === 'string') return v.trim()+ if (Array.isArray(v)) return v.map(canon)+ if (v && typeof v === 'object') {+ const out: Record<string, unknown> = {}+ for (const k of Object.keys(v as Record<string, unknown>).sort()) out[k] = canon((v as Record<string, unknown>)[k])+ return out+ }+ return v+}++/** One short label per skipped call, for the note. */+export function repeatLabel(name: string, args: unknown): string {+ const a = canonicalArgs(args)+ return `${name} ${a.length > 120 ? a.slice(0, 117) + '...' : a}`+}++/** The note after the results, or null when nothing was skipped. */+export function skippedRepeatsNote(labels: string[]): string | null {+ if (labels.length === 0) return null+ const list = labels.map((l) => `- ${l}`).join('\n')+ return `Not run again, because each already ran this turn with the same arguments and its result is above, unchanged:\n${list}\nUse those results. Call a tool again only with different arguments.`+}diff --git a/src/lib/agent-loop-guard.ts b/src/lib/agent-loop-guard.tsindex ba2fda17..adbee509 100644--- a/src/lib/agent-loop-guard.ts+++ b/src/lib/agent-loop-guard.ts@@ -152,6 +152,8 @@ const SEARCH_HALT_AT = 12const NEAR_SIMILARITY = 0.85const NEAR_STEER_AT = 5const NEAR_HALT_AT = 8+/** Detector 8: a step's text at least this alike to the step before is no news. */+const NARRATION_NEWS_BELOW = 0.8/** Lower-cased, whitespace folded: the form two near-copies are compared in. */function normArgs(args: string): string {@@ -272,6 +274,9 @@ export class AgentLoopGuard {*/private stepSilent: boolean | null = null+ /** The last real line of text, for detector 8's "is this news" test. */+ private nearNarration = ''+/** Reads whose capped result was already forgiven once (detector 3). */private trimForgiven = new Set<string>()@@ -607,7 +612,13 @@ export class AgentLoopGuard {if (!this.enabled) return { action: 'ok' }const norm = text.trim().replace(/\s+/g, ' ').toLowerCase()// Detector 8 (C83): text the step before did not already have is news.- this.stepSilent = norm.length < MIN_NARRATION_LEN || norm === this.lastNarration+ // A near-copy of the last line is not (CA, cloud loops, 13.11.2026):+ // GLM writes "Let me check the file again." before each identical call,+ // and a fresh word per step kept the streak at one for good.+ this.stepSilent = norm.length < MIN_NARRATION_LEN+ || norm === this.lastNarration+ || (this.nearNarration !== '' && argSimilarity(this.nearNarration, norm) >= NARRATION_NEWS_BELOW)+ this.nearNarration = norm.length < MIN_NARRATION_LEN ? this.nearNarration : normif (norm.length < MIN_NARRATION_LEN) {this.lastNarration = ''this.narrationSeen = 0