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(commands): the loop kept running after the model already said done
purple2a9a6e7e65a0
diff --git a/src/components/chat/CodexView.tsx b/src/components/chat/CodexView.tsxindex f747e0d4..763a4dce 100644--- a/src/components/chat/CodexView.tsx+++ b/src/components/chat/CodexView.tsx@@ -56,7 +56,9 @@ function stripChannelTags(text: string): string {t = t.replace(/^[ \t]*<?[|/]*t?ool_(?:call|calls|response|result)s?[|/]*>[ \t]*$/gim, '')// 1c) The /loop control markers. They are protocol between the driver and// the model, not something the user needs to read.- t = t.replace(/^[ \t]*LOOP_(?:DONE|CONTINUE)[ \t]*$/gm, '')+ // The template asks for a reason after the marker, so drop the whole line+ // rather than leaving a dangling "(verified by …)".+ t = t.replace(/^[ \t]*LOOP_(?:DONE|CONTINUE)\b.*$/gm, '')// 2) The autonomous-continue NUDGE, if a weak model parrots it back as its// own answer (qwen2.5-coder:7b did this verbatim). It is OUR fixed// instruction from useCodex — strip from its opening clause ("…continuediff --git a/src/hooks/useCodex.ts b/src/hooks/useCodex.tsindex 12cec8e3..658b4920 100644--- a/src/hooks/useCodex.ts+++ b/src/hooks/useCodex.ts@@ -21,7 +21,7 @@ import { useAgentModeStore } from '../stores/agentModeStore'import { loadLurules, renderRulesSection, type RulesReader } from '../lib/lurules'import {parseAgentCommand, parseLoopSpec, buildLoopRecheck, formatDuration,- MAX_LOOP_PASSES, MAX_LOOP_TOTAL_MS, LOOP_DONE_MARKER,+ MAX_LOOP_PASSES, MAX_LOOP_TOTAL_MS, loopPassSaysDone,} from '../lib/agent-commands'import { useGenerationStore } from '../stores/generationStore'import { backendCall, isOllamaLocal } from '../api/backend'@@ -1747,7 +1747,7 @@ export function useCodex() {// when the user hits stop (loopTimerRef is cleared there).if (loopState && convId && !userStoppedRef.current) {const answer = fullContent.trim()- const saidDone = new RegExp(`(^|\\s)${LOOP_DONE_MARKER}\\s*$`).test(answer)+ const saidDone = loopPassSaysDone(answer)const elapsed = Date.now() - loopState.startedAtconst nextPass = loopState.pass + 1diff --git a/src/lib/__tests__/agent-commands.test.ts b/src/lib/__tests__/agent-commands.test.tsindex c73251a2..19933297 100644--- a/src/lib/__tests__/agent-commands.test.ts+++ b/src/lib/__tests__/agent-commands.test.ts@@ -12,6 +12,7 @@ import {MAX_LOOP_PASSES,LOOP_DONE_MARKER,LOOP_CONTINUE_MARKER,+ loopPassSaysDone,} from '../agent-commands'import { MUTATING_TOOLS } from '../mutating-tools'@@ -290,3 +291,29 @@ describe('formatDuration', () => {expect(formatDuration(2 * 3_600_000)).toBe('2h')})})++describe('loopPassSaysDone', () => {+ // Caught live on the ship exe, 2026-07-25: Qwen3-32B ended with+ // "LOOP_DONE (verified by code_execute test)" and an end-anchored match+ // missed it, so the loop kept re-running an already-finished task. The+ // template ASKS for that reason, so the detector has to tolerate it.+ it('accepts the marker with the reason the template asks for', () => {+ expect(loopPassSaysDone('All good.\nLOOP_DONE (verified by code_execute test)')).toBe(true)+ expect(loopPassSaysDone('LOOP_DONE, tests pass')).toBe(true)+ expect(loopPassSaysDone('done.\nLOOP_DONE')).toBe(true)+ })++ it('does not finish on a continue', () => {+ expect(loopPassSaysDone('still work left\nLOOP_CONTINUE')).toBe(false)+ })++ it('treats a pass that says both as NOT done', () => {+ // Safer to spend one more pass than to ship on an ambiguous claim.+ expect(loopPassSaysDone('LOOP_DONE for the helper, LOOP_CONTINUE for the tests')).toBe(false)+ })++ it('does not finish on silence', () => {+ expect(loopPassSaysDone('I added the function.')).toBe(false)+ expect(loopPassSaysDone('')).toBe(false)+ })+})diff --git a/src/lib/__tests__/readonly-enforcement.test.ts b/src/lib/__tests__/readonly-enforcement.test.tsindex c8c1bdac..b22fd0b7 100644--- a/src/lib/__tests__/readonly-enforcement.test.ts+++ b/src/lib/__tests__/readonly-enforcement.test.ts@@ -105,7 +105,7 @@ describe('/loop actually loops', () => {it('stops on the done marker, the pass cap and the total ceiling', () => {const src = read('../../hooks/useCodex.ts')- expect(src).toContain('LOOP_DONE_MARKER')+ expect(src).toContain('loopPassSaysDone(answer)')expect(src).toContain('nextPass > MAX_LOOP_PASSES')expect(src).toContain('elapsed > MAX_LOOP_TOTAL_MS')})diff --git a/src/lib/agent-commands.ts b/src/lib/agent-commands.tsindex 5bf2db8c..8243e860 100644--- a/src/lib/agent-commands.ts+++ b/src/lib/agent-commands.ts@@ -65,6 +65,23 @@ export const MAX_LOOP_INTERVAL_MS = 30 * 60 * 1000export const LOOP_DONE_MARKER = 'LOOP_DONE'export const LOOP_CONTINUE_MARKER = 'LOOP_CONTINUE'+/**+ * Did the model declare this pass finished?+ *+ * Deliberately generous about what follows the marker, because the template+ * ASKS for a reason after it. Qwen3-32B wrote `LOOP_DONE (verified by+ * code_execute test)` and an end-anchored match missed it, so the loop kept+ * re-running an already-finished task (caught live on the ship exe,+ * 2026-07-25). A CONTINUE anywhere wins: if the model said both, it is not+ * done.+ */+export function loopPassSaysDone(answer: string): boolean {+ if (!answer) return false+ const hasContinue = new RegExp(`\\b${LOOP_CONTINUE_MARKER}\\b`).test(answer)+ if (hasContinue) return false+ return new RegExp(`\\b${LOOP_DONE_MARKER}\\b`).test(answer)+}+/*** Pull a leading interval off `/loop`'s arguments: `30s`, `20m`, `2h`,* `1h30m`, or a bare number read as minutes. Returns the interval in ms plus