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(mobile): the phone's remote agent runs the desktop's loop guard (CA)
purple8d0036d6fce9
diff --git a/src/mobile/remote/__tests__/remote-agent-stops-a-loop.test.ts b/src/mobile/remote/__tests__/remote-agent-stops-a-loop.test.tsnew file mode 100644index 00000000..acc12fd1--- /dev/null+++ b/src/mobile/remote/__tests__/remote-agent-stops-a-loop.test.ts@@ -0,0 +1,50 @@+/**+ * CA (14.11.2026): the phone's remote agent drives the desktop's model, which+ * can be a paid cloud model. Until now only 50 steps and five failures in a+ * row stopped it. It now runs the same loop guard as the desktop.+ */+import { describe, it, expect } from 'vitest'+import { runRemoteAgentLoop } from '../remoteAgent'++function stubClient(sameCall: boolean) {+ let n = 0+ const sent: Array<Array<{ role: string; content: string }>> = []+ return {+ sent,+ client: {+ chatWithTools: async (req: { messages: Array<{ role: string; content: string }> }) => {+ sent.push(req.messages)+ n+++ return {+ content: '',+ thinking: '',+ toolCalls: [{ function: { name: 'file_read', arguments: { path: sameCall ? 'notes.txt' : `notes-${n}.txt` } } }],+ }+ },+ runAgentTool: async () => ({ ok: true, result: 'the same text every time' }),+ },+ }+}++describe('remote agent loop guard', () => {+ it('the same read over and over ends as looping, well before the 50-step limit', async () => {+ const s = stubClient(true)+ const res = await runRemoteAgentLoop({+ client: s.client as never, model: 'm', chatId: 'c', tools: ['file_read'],+ messages: [{ role: 'system', content: 'sys' }, { role: 'user', content: 'read notes' }] as never,+ })+ expect(res.end).toBe('looping')+ expect(res.steps.length).toBeLessThan(10)+ // The steer reached the model after the results, before the end.+ expect(s.sent.flat().some((m) => m.role === 'user' && /exactly the same|same arguments/i.test(m.content))).toBe(true)+ })++ it('honest progress is never stopped by the guard', async () => {+ const s = stubClient(false)+ const res = await runRemoteAgentLoop({+ client: s.client as never, model: 'm', chatId: 'c', tools: ['file_read'], maxIterations: 12,+ messages: [{ role: 'system', content: 'sys' }, { role: 'user', content: 'read all notes' }] as never,+ })+ expect(res.end).toBe('max-iterations')+ })+})diff --git a/src/mobile/remote/remoteAgent.ts b/src/mobile/remote/remoteAgent.tsindex 7f64f975..70689366 100644--- a/src/mobile/remote/remoteAgent.ts+++ b/src/mobile/remote/remoteAgent.ts@@ -31,6 +31,7 @@* Kein Store, keine Oberflaeche, kein Text fuer den Nutzer. Der Aufrufer* bekommt die Schritte und das Ende als Daten.*/+import { AgentLoopGuard } from '../../lib/agent-loop-guard'import {AGENT_TOOLS,buildToolDefs,@@ -330,6 +331,9 @@ export type RemoteAgentEnd =| 'aborted'| 'max-iterations'| 'tool-errors'+ /** Der Loop-Guard hat den Lauf beendet: dieselben Aufrufe immer wieder+ * (lib/agent-loop-guard.ts, derselbe Waechter wie am Desktop, CA 14.11.). */+ | 'looping'/** Das Modell kann keine Werkzeuge. */| 'no-tools'@@ -426,6 +430,11 @@ export async function runRemoteAgentLoop(run: RemoteAgentRun): Promise<RemoteAgelet echoRetries = ECHO_RETRIESlet nudges = STOP_NUDGESlet consecutiveErrors = 0+ // CA (14.11.2026): the same loop guard as the desktop's agent loops. The+ // remote loop had only its step limit and five failures in a row, and the+ // model it drives may be a paid cloud model on the desktop.+ const guard = new AgentLoopGuard()+ let pendingSteer: string | null = nullconst finish = (end: RemoteAgentEnd, content: string): RemoteAgentResult => ({ end, content, thinking, steps: steps.map((step) => ({ ...step })) })const aborted = () => run.signal?.aborted === true@@ -484,6 +493,14 @@ export async function runRemoteAgentLoop(run: RemoteAgentRun): Promise<RemoteAgelastContent = content || lastContentrun.onProgress?.({ content: lastContent, thinking })+ {+ const said = guard.recordNarration(content || '')+ const verdict = said.action === 'halt'+ ? said+ : guard.recordBatch(calls.map((c) => ({ name: c.function.name, args: JSON.stringify(c.function.arguments ?? {}) })))+ if (verdict.action === 'halt') return finish('looping', lastContent)+ pendingSteer = verdict.action === 'steer' ? verdict.message : said.action === 'steer' ? said.message : null+ }messages.push({role: 'assistant',content: content || '',@@ -523,6 +540,11 @@ export async function runRemoteAgentLoop(run: RemoteAgentRun): Promise<RemoteAgeconsecutiveErrors = failed ? consecutiveErrors + 1 : 0if (consecutiveErrors >= MAX_CONSECUTIVE_ERRORS) return finish('tool-errors', lastContent)}+ // The steer goes after the results it is about.+ if (pendingSteer) {+ messages.push({ role: 'user', content: pendingSteer })+ pendingSteer = null+ }}} catch (err) {// Ein Schritt, der gerade lief, ist nicht fertig geworden.diff --git a/src/mobile/remote/remoteClientStore.ts b/src/mobile/remote/remoteClientStore.tsindex f14419bf..da37ea50 100644--- a/src/mobile/remote/remoteClientStore.ts+++ b/src/mobile/remote/remoteClientStore.ts@@ -156,7 +156,7 @@ export interface RemoteMessage {/** Nur Antworten im Agentenmodus: die Werkzeugschritte auf dem Desktop. */steps?: RemoteAgentStep[]/** Nur Antworten im Agentenmodus: warum der Lauf endete, wenn nicht mit einer Antwort. */- agentEnd?: Extract<RemoteAgentEnd, 'max-iterations' | 'tool-errors'>+ agentEnd?: Extract<RemoteAgentEnd, 'max-iterations' | 'tool-errors' | 'looping'>}export interface RemoteChat {@@ -487,7 +487,7 @@ function sanitizeChats(raw: unknown, fallbackBaseUrl: string | null = null): Rem...(m.role === 'user' ? { mirrored: m.mirrored === true } : {}),...(m.role === 'user' && Array.isArray(m.images) && m.images.length > 0 ? { images: sanitizeImages(m.images) } : {}),...(m.role === 'assistant' && Array.isArray(m.steps) && m.steps.length > 0 ? { steps: sanitizeSteps(m.steps) } : {}),- ...(m.role === 'assistant' && (m.agentEnd === 'max-iterations' || m.agentEnd === 'tool-errors') ? { agentEnd: m.agentEnd } : {}),+ ...(m.role === 'assistant' && (m.agentEnd === 'max-iterations' || m.agentEnd === 'tool-errors' || m.agentEnd === 'looping') ? { agentEnd: m.agentEnd } : {}),})}out.push({diff --git a/src/mobile/screens/remote/RemoteChatPage.tsx b/src/mobile/screens/remote/RemoteChatPage.tsxindex 8d0f1f4a..37b9e176 100644--- a/src/mobile/screens/remote/RemoteChatPage.tsx+++ b/src/mobile/screens/remote/RemoteChatPage.tsx@@ -115,7 +115,7 @@ function Answer({ chat, message, isLast, status, waiting, foreign }: { chat: Rem) : null}{message.agentEnd ? (<div className="m-remote-msg-foot m-remote-msg-foot--warn" data-testid="m-remote-chat-agent-end">- <span className="m-grow">{message.agentEnd === 'max-iterations' ? S.chat.endMaxSteps : S.chat.endToolErrors}</span>+ <span className="m-grow">{message.agentEnd === 'max-iterations' ? S.chat.endMaxSteps : message.agentEnd === 'looping' ? S.chat.endLooping : S.chat.endToolErrors}</span></div>) : null}{footer ? (diff --git a/src/mobile/strings/remote.ts b/src/mobile/strings/remote.tsindex fb2eeb48..5ded388c 100644--- a/src/mobile/strings/remote.ts+++ b/src/mobile/strings/remote.ts@@ -176,6 +176,7 @@ export const REMOTE_STRINGS = {photoAlt: 'Attached photo',endMaxSteps: 'The model stopped after the highest number of steps.',endToolErrors: 'The model stopped because several steps in a row failed.',+ endLooping: 'Stopped because the model kept repeating the same steps.',missingTitle: 'This remote chat is not on this phone',missingText: 'It may have been deleted. Your other remote chats are in the list.',backToList: 'Back to remote chats',