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): bound the sub-agent limits on the desktop
purple240cc03c7e4e
diff --git a/src/api/agents/__tests__/sub-agent-limits-are-bounded.test.ts b/src/api/agents/__tests__/sub-agent-limits-are-bounded.test.tsnew file mode 100644index 00000000..fa0a3126--- /dev/null+++ b/src/api/agents/__tests__/sub-agent-limits-are-bounded.test.ts@@ -0,0 +1,29 @@+/**+ * Jaeger B, B9: the desktop sub-agent fields had no upper bound and+ * resolveSubAgentBudget took any value above 0, so a sub-agent that runs+ * unattended could be given 99999999 tool calls. Now the budget is clamped+ * to SUB_AGENT_LIMIT_MAX, the same bound set_setting from the chat uses,+ * and 0 still means "use the default".+ *+ * Run: npx vitest run src/api/agents/__tests__/sub-agent-limits-are-bounded.test.ts+ */+import { describe, it, expect } from 'vitest'+import { resolveSubAgentBudget, SUB_AGENT_BUDGET } from '../sub-agent'+import { SUB_AGENT_LIMIT_MAX } from '../../../lib/number-limits'+import { findEntry } from '../../../lib/settings-catalog'++describe('B9: sub-agent limits have an upper bound', () => {+ it('a huge value is clamped, 0 is the default, a normal value passes', () => {+ expect(resolveSubAgentBudget({ subAgentMaxToolCalls: 99_999_999, subAgentMaxIterations: 99_999_999 }))+ .toEqual({ maxToolCalls: SUB_AGENT_LIMIT_MAX, maxIterations: SUB_AGENT_LIMIT_MAX })+ expect(resolveSubAgentBudget({ subAgentMaxToolCalls: 0, subAgentMaxIterations: 0 }))+ .toEqual({ maxToolCalls: SUB_AGENT_BUDGET.maxToolCalls, maxIterations: SUB_AGENT_BUDGET.maxIterations })+ expect(resolveSubAgentBudget({ subAgentMaxToolCalls: 25, subAgentMaxIterations: 7 }))+ .toEqual({ maxToolCalls: 25, maxIterations: 7 })+ })++ it('the chat command uses the same bound', () => {+ expect(findEntry('subAgentMaxToolCalls')?.parse(SUB_AGENT_LIMIT_MAX + 1).ok).toBe(false)+ expect(findEntry('subAgentMaxIterations')?.parse(SUB_AGENT_LIMIT_MAX).ok).toBe(true)+ })+})diff --git a/src/api/agents/sub-agent.ts b/src/api/agents/sub-agent.tsindex 1e20ddd0..45a1338d 100644--- a/src/api/agents/sub-agent.ts+++ b/src/api/agents/sub-agent.ts@@ -51,6 +51,7 @@ import { MAX_EXPLICIT_FANOUT } from '../../lib/agent-fanout'import { resolveApprovalLevel } from '../../lib/agent-approval-policy'import { allowedInReadOnlyTurn } from '../../lib/mutating-tools'import { isSettingsToolName } from '../../lib/settings-tool-names'+import { clampSubAgentLimit } from '../../lib/number-limits'// NOTE: the toolRegistry import is done LAZILY inside defaultSubAgentRunner// to avoid a circular dependency with src/api/mcp/builtin-tools.ts, which@@ -142,8 +143,9 @@ export function resolveSubAgentBudget(s?: {subAgentMaxToolCalls?: numbersubAgentMaxIterations?: number}): { maxToolCalls: number; maxIterations: number } {- const zahl = (v: unknown, vorgabe: number) =>- typeof v === 'number' && Number.isFinite(v) && v > 0 ? Math.floor(v) : vorgabe+ // 0 or nothing = the default; above SUB_AGENT_LIMIT_MAX is clamped (B9),+ // a sub-agent runs unattended and must not get a practically endless budget.+ const zahl = (v: unknown, vorgabe: number) => clampSubAgentLimit(v) || vorgabereturn {maxToolCalls: zahl(s?.subAgentMaxToolCalls, SUB_AGENT_BUDGET.maxToolCalls),maxIterations: zahl(s?.subAgentMaxIterations, SUB_AGENT_BUDGET.maxIterations),diff --git a/src/components/settings/SettingsPage.tsx b/src/components/settings/SettingsPage.tsxindex 8f1ccd38..c321fba5 100644--- a/src/components/settings/SettingsPage.tsx+++ b/src/components/settings/SettingsPage.tsx@@ -90,7 +90,7 @@ import { isLmStudioProvider } from '../../lib/hf-to-provider'import { TEMPERATURE_MAX, TEMPERATURE_HELP, TEMPERATURE_HELP_LABEL } from '../../lib/sampling'import { HighTemperatureWarning } from '../chat/HighTemperatureWarning'import { BoundedNumberInput } from './BoundedNumberInput'-import { CONTEXT_WINDOW_MAX, MAX_TOKENS_MAX } from '../../lib/number-limits'+import { CONTEXT_WINDOW_MAX, MAX_TOKENS_MAX, SUB_AGENT_LIMIT_MAX } from '../../lib/number-limits'// ── User profile picture (Appearance) ───────────────────────────// Self-contained like HfDownloadPathSetting. Stores the picture as a@@ -2421,14 +2421,12 @@ export function SettingsPage() {>Sub-agent tool calls</span>- <input- aria-label="Sub-agent tool calls"- type="number"+ <BoundedNumberInput+ ariaLabel="Sub-agent tool calls"value={settings.subAgentMaxToolCalls ?? 0}- onChange={(e) => updateSettings({ subAgentMaxToolCalls: Math.max(0, parseInt(e.target.value) || 0) })}- min={0}+ max={SUB_AGENT_LIMIT_MAX}placeholder="10"- className="w-20 px-1.5 py-0.5 rounded bg-transparent border border-white/8 t-mono text-right text-gray-300 focus:outline-none focus:border-white/20"+ onCommit={(v) => updateSettings({ subAgentMaxToolCalls: v })}/></div><div className="flex items-center justify-between">@@ -2438,18 +2436,16 @@ export function SettingsPage() {>Sub-agent steps</span>- <input- aria-label="Sub-agent steps"- type="number"+ <BoundedNumberInput+ ariaLabel="Sub-agent steps"value={settings.subAgentMaxIterations ?? 0}- onChange={(e) => updateSettings({ subAgentMaxIterations: Math.max(0, parseInt(e.target.value) || 0) })}- min={0}+ max={SUB_AGENT_LIMIT_MAX}placeholder="5"- className="w-20 px-1.5 py-0.5 rounded bg-transparent border border-white/8 t-mono text-right text-gray-300 focus:outline-none focus:border-white/20"+ onCommit={(v) => updateSettings({ subAgentMaxIterations: v })}/></div><div className="t-micro text-gray-500 dark:text-gray-500 leading-relaxed pt-0.5">- 0 = use the defaults (10 calls, 5 steps). A sub-agent runs unattended, so these stay deliberately tight, raise them only for a task you know is long.+ 0 = use the defaults (10 calls, 5 steps), at most 1,000 each. A sub-agent runs unattended, so these stay deliberately tight, raise them only for a task you know is long.</div></Section>)}diff --git a/src/lib/settings-catalog.ts b/src/lib/settings-catalog.tsindex de57751b..2ac76f0e 100644--- a/src/lib/settings-catalog.ts+++ b/src/lib/settings-catalog.ts@@ -20,7 +20,7 @@ import { EFFORT_STEPS } from './effort'import { normalizeThinkBudget } from './think-budget'import { normalizeChatFirstReplySeconds } from './chat-reply-timeout'import { TEMPERATURE_MAX } from './sampling'-import { CONTEXT_WINDOW_MAX, MAX_TOKENS_MAX } from './number-limits'+import { CONTEXT_WINDOW_MAX, MAX_TOKENS_MAX, SUB_AGENT_LIMIT_MAX } from './number-limits'type Parsed = { ok: true; value: unknown } | { ok: false; error: string }@@ -207,8 +207,8 @@ export const CATALOG: readonly CatalogEntry[] = [// Agent limits: read at the start of a run, so a run cannot raise its own.e('agentMaxToolCalls', 'Agent tool call limit', 'agent', 'Most tool calls per message. Applies from the next message.', int(0, 10_000, '', 'unlimited')),e('agentMaxIterations', 'Agent step limit', 'agent', 'Most steps per message. Applies from the next message.', int(0, 10_000, '', 'unlimited')),- e('subAgentMaxToolCalls', 'Sub-agent tool call limit', 'agent', 'Most tool calls of one sub-agent.', int(0, 1_000, '', 'default')),- e('subAgentMaxIterations', 'Sub-agent step limit', 'agent', 'Most steps of one sub-agent.', int(0, 1_000, '', 'default')),+ e('subAgentMaxToolCalls', 'Sub-agent tool call limit', 'agent', 'Most tool calls of one sub-agent.', int(0, SUB_AGENT_LIMIT_MAX, '', 'default')),+ e('subAgentMaxIterations', 'Sub-agent step limit', 'agent', 'Most steps of one sub-agent.', int(0, SUB_AGENT_LIMIT_MAX, '', 'default')),e('loopMaxPasses', '/loop passes', 'agent', 'How many passes a /loop may run.', int(0, 10_000, '', 'unlimited')),// Look and feele('theme', 'Theme', 'general', 'Light or dark app theme.', oneOf(['light', 'dark'])),