The open source AI video agent: turns any coding agent into a video agent, with an editor to change anything it makes.
Desktop: the own agent waits 15 minutes for a quiet model and says it is waiting (#92)
riverisbuilding120193c63329
diff --git a/.changeset/own-agent-patience.md b/.changeset/own-agent-patience.mdnew file mode 100644index 0000000..8f2b2c8--- /dev/null+++ b/.changeset/own-agent-patience.md@@ -0,0 +1,5 @@+---+'@openfilm/desktop': patch+---++Desktop: the app's own agent waits up to 15 minutes for a model that thinks quietly before answering, says it is waiting after 2 minutes, and its failure says the real time.diff --git a/apps/desktop/chat/src/components/AgentActivityRow.tsx b/apps/desktop/chat/src/components/AgentActivityRow.tsxindex ea650a3..0e45f9b 100644--- a/apps/desktop/chat/src/components/AgentActivityRow.tsx+++ b/apps/desktop/chat/src/components/AgentActivityRow.tsx@@ -11,7 +11,7 @@ import { Markdown } from './Markdown';import { AttachmentPreview } from './AttachmentPreview';import { elapsedLabel, useTick } from './useTicker';import { useT } from '@/i18n';-import { actGroupParts, buildRuns, EPHEMERAL_ACT_LABELS, pendingWork } from '@/lib/agent-activity-runs';+import { actGroupParts, buildRuns, EPHEMERAL_ACT_LABELS, idleStatus, pendingWork } from '@/lib/agent-activity-runs';import { StickToBottomContext } from './useStickToBottom';import { WaitingContext } from '@/lib/developer';@@ -617,9 +617,9 @@ function togglePlayer(url: string, owner: string): void {* · neither: the caller's text (reconnecting and the like), else "Thinking".** The clock counts from the earliest start among the running acts. When the turn ends this row becomes- * the footer, at the same height (h-6).+ * the footer, at the same height (h-6). `ownAgent`: the turn runs on the app's own agent (see IdleStatus).*/-export function StatusLine({ items, fallback }: { items: AgentActivityItem[]; fallback?: string | null }) {+export function StatusLine({ items, fallback, ownAgent = false }: { items: AgentActivityItem[]; fallback?: string | null; ownAgent?: boolean }) {const t = useT();const running = React.useMemo(() => pendingWork(items), [items]);/* The last time anything happened: each new item (text, an act starting or finishing) gives the list a new identity */@@ -651,7 +651,7 @@ export function StatusLine({ items, fallback }: { items: AgentActivityItem[]; falet last: AgentActivityItem | undefined;for (let i = items.length - 1; i >= 0; i -= 1) if (items[i]!.kind !== 'notice') { last = items[i]; break; }if (last?.kind === 'text' && last.pending) return <StatusBlank />;- return <IdleStatus since={changedAt} quietFirst={last?.kind === 'text'} />;+ return <IdleStatus since={changedAt} quietFirst={last?.kind === 'text'} ownAgent={ownAgent} />;}/** The status row's empty slot: same height, says nothing. */@@ -669,27 +669,29 @@ const AFTER_TEXT_MS = 5_000;* written, which can be two minutes of silence. With only a stop button showing, that looks frozen. So* the row stays: "Working" plus the seconds since the last activity, "Still working" after half a minute* of quiet. A moving clock shows it is alive.+ *+ * The app's own agent says "Waiting for the model" after two minutes, with why as the row's faint words: some+ * models think for minutes before the first word. Those words go in the row, not on a line of their own, so it+ * stays one row high.*/-const QUIET_MS = 30_000;--function IdleStatus({ since, quietFirst = false }: { since: number; quietFirst?: boolean }) {+function IdleStatus({ since, quietFirst = false, ownAgent = false }: { since: number; quietFirst?: boolean; ownAgent?: boolean }) {const t = useT();const tick = useTick();const idle = (tick ?? Date.now()) - since;if (quietFirst && idle < AFTER_TEXT_MS) return <StatusBlank />;- const quiet = idle >= QUIET_MS;- return <StatusShell label={t(quiet ? 'act.stillWorking' : 'act.working')} since={since} />;+ const label = idleStatus(idle, ownAgent);+ return <StatusShell label={t(label)} extra={label === 'act.waitingForModel' ? t('act.waitingForModelHint') : undefined} plain since={since} />;}/* Status row: the act's icon while an act runs; thinking / working is text only, flush left. The shimmeralready says "in progress", so no spinner and no empty slot pushing the text right. */-function StatusShell({ Icon, label, extra, since, waiting = false }: { Icon?: LucideIcon | undefined; label: string; extra?: string | undefined; since: number; waiting?: boolean }) {+function StatusShell({ Icon, label, extra, plain = false, since, waiting = false }: { Icon?: LucideIcon | undefined; label: string; extra?: string | undefined; plain?: boolean; since: number; waiting?: boolean }) {return (<div role="status" className="flex h-6 min-w-0 items-center gap-2 text-[14px]">{Icon ? <Icon size={13} aria-hidden className="shrink-0 text-[var(--chat-hint)]" /> : null}<span className={`${waiting ? '' : 'text-sweep '}min-w-0 truncate ${extra ? 'max-w-[60%] shrink-0' : ''}`}>{label}</span>{extra ? (- <span className={`min-w-0 truncate text-[var(--chat-hint)] opacity-80 ${extra.startsWith('“') ? '' : 'font-mono text-[12.5px]'}`} title={extra}>+ <span className={`min-w-0 truncate text-[var(--chat-hint)] opacity-80 ${plain || extra.startsWith('“') ? '' : 'font-mono text-[12.5px]'}`} title={extra}>{extra}</span>) : null}diff --git a/apps/desktop/chat/src/components/ProjectConversation.tsx b/apps/desktop/chat/src/components/ProjectConversation.tsxindex 5629f75..a6bfbaf 100644--- a/apps/desktop/chat/src/components/ProjectConversation.tsx+++ b/apps/desktop/chat/src/components/ProjectConversation.tsx@@ -405,7 +405,7 @@ const ConversationTurn = React.memo(function ConversationTurn({footer under it on hover (its Log is the turn so far). Done, the footer alone. Always there, in one placein the tree: a log opened from it stays open as the turn finishes. An interruption doesn'tshow Failed here: the reason and Resume appear above the composer, as in Cursor. */}- {running ? <StatusLine items={rows ?? NO_ROWS} fallback={liveActivity} /> : null}+ {running ? <StatusLine items={rows ?? NO_ROWS} fallback={liveActivity} ownAgent={entry.agent === 'byok'} /> : null}<TurnFooter entry={entry} items={items} running={running} /></div></div>diff --git a/apps/desktop/chat/src/i18n/locales/en-US.ts b/apps/desktop/chat/src/i18n/locales/en-US.tsindex 450188d..0856eaf 100644--- a/apps/desktop/chat/src/i18n/locales/en-US.ts+++ b/apps/desktop/chat/src/i18n/locales/en-US.ts@@ -16,6 +16,9 @@ export const enUS = {},act: {waitingForYou: 'Waiting for you',+ /* the app's own agent, after two minutes with nothing from the model (some think for minutes first) */+ waitingForModel: 'Waiting for the model',+ waitingForModelHint: "Some models think for a long while before they start to answer. Stop if you don't want to wait.",asset: {genImage: 'Generating image',genVideo: 'Generating video',diff --git a/apps/desktop/chat/src/i18n/locales/es.ts b/apps/desktop/chat/src/i18n/locales/es.tsindex 0475e17..26fcda9 100644--- a/apps/desktop/chat/src/i18n/locales/es.ts+++ b/apps/desktop/chat/src/i18n/locales/es.ts@@ -17,6 +17,9 @@ export const es: Words = {},act: {waitingForYou: 'Esperando tu respuesta',+ /* the app's own agent, after two minutes with nothing from the model (some think for minutes first) */+ waitingForModel: 'Esperando al modelo',+ waitingForModelHint: 'Algunos modelos piensan un buen rato antes de empezar a responder. Si no quieres esperar, detenlo.',asset: {genImage: 'Generando una imagen',genVideo: 'Generando un video',diff --git a/apps/desktop/chat/src/i18n/locales/ja.ts b/apps/desktop/chat/src/i18n/locales/ja.tsindex 74562e1..83dd6ac 100644--- a/apps/desktop/chat/src/i18n/locales/ja.ts+++ b/apps/desktop/chat/src/i18n/locales/ja.ts@@ -17,6 +17,9 @@ export const ja: Words = {},act: {waitingForYou: 'あなたの返答を待っています',+ /* the app's own agent, after two minutes with nothing from the model (some think for minutes first) */+ waitingForModel: 'モデルの応答を待っています',+ waitingForModelHint: 'モデルによっては、答え始めるまで長く考えることがあります。待たない場合は停止してください。',asset: {genImage: '画像を作成中',genVideo: 'ビデオを作成中',diff --git a/apps/desktop/chat/src/i18n/locales/ko.ts b/apps/desktop/chat/src/i18n/locales/ko.tsindex b4dd73b..2615a9a 100644--- a/apps/desktop/chat/src/i18n/locales/ko.ts+++ b/apps/desktop/chat/src/i18n/locales/ko.ts@@ -17,6 +17,9 @@ export const ko: Words = {},act: {waitingForYou: '답변을 기다리는 중',+ /* the app's own agent, after two minutes with nothing from the model (some think for minutes first) */+ waitingForModel: '모델 응답을 기다리는 중',+ waitingForModelHint: '어떤 모델은 답하기 시작하기 전에 오래 생각합니다. 기다리지 않으려면 중지하세요.',asset: {genImage: '이미지 생성 중',genVideo: '비디오 생성 중',diff --git a/apps/desktop/chat/src/i18n/locales/zh-CN.ts b/apps/desktop/chat/src/i18n/locales/zh-CN.tsindex a7282aa..56c2eed 100644--- a/apps/desktop/chat/src/i18n/locales/zh-CN.ts+++ b/apps/desktop/chat/src/i18n/locales/zh-CN.ts@@ -17,6 +17,9 @@ export const zhCN: Words = {},act: {waitingForYou: '在等你',+ /* the app's own agent, after two minutes with nothing from the model (some think for minutes first) */+ waitingForModel: '等模型回应',+ waitingForModelHint: '有的模型会先想很久才开始输出;不想等可以停止。',asset: {genImage: '正在生成图片',genVideo: '正在生成视频',diff --git a/apps/desktop/chat/src/lib/agent-activity-runs.ts b/apps/desktop/chat/src/lib/agent-activity-runs.tsindex 9dd6361..bf1b63b 100644--- a/apps/desktop/chat/src/lib/agent-activity-runs.ts+++ b/apps/desktop/chat/src/lib/agent-activity-runs.ts@@ -82,6 +82,17 @@ export function pendingWork<T extends ActivityRunItem>(items: readonly T[]): T[]return items.filter((item) => (item.kind === 'act' || item.kind === 'thought') && item.pending && !isEphemeral(item));}+/** Quiet this long, "Working" reads "Still working". */+export const QUIET_MS = 30_000;+/** Quiet this long, the app's own agent says it waits for the model: some think for minutes before they answer. */+export const MODEL_WAIT_MS = 120_000;++/** What the status row says when nothing is reported, after `idleMs` of quiet; `ownAgent` for the app's own agent. */+export function idleStatus(idleMs: number, ownAgent: boolean): 'act.working' | 'act.stillWorking' | 'act.waitingForModel' {+ if (ownAgent && idleMs >= MODEL_WAIT_MS) return 'act.waitingForModel';+ return idleMs >= QUIET_MS ? 'act.stillWorking' : 'act.working';+}+/*** The folded row's summary: which kinds of things were done and how often, in order of first appearance, the samediff --git a/apps/desktop/package.json b/apps/desktop/package.jsonindex 3ef3f51..ac40b84 100644--- a/apps/desktop/package.json+++ b/apps/desktop/package.json@@ -22,7 +22,8 @@"@earendil-works/pi-coding-agent": "1.1.0","diff": "9.0.0","electron-updater": "6.8.9",- "openfilm": "workspace:*"+ "openfilm": "workspace:*",+ "undici": "8.10.2"},"devDependencies": {"@fontsource-variable/inter": "^5.3.0",diff --git a/apps/desktop/src/agent-activity-runs.test.mjs b/apps/desktop/src/agent-activity-runs.test.mjsnew file mode 100644index 0000000..2285cb6--- /dev/null+++ b/apps/desktop/src/agent-activity-runs.test.mjs@@ -0,0 +1,20 @@+import { test } from 'node:test';+import assert from 'node:assert/strict';+import { MODEL_WAIT_MS, QUIET_MS, idleStatus } from '../chat/src/lib/agent-activity-runs.ts';++test('quiet, any agent says "Working", then "Still working" after half a minute', () => {+ for (const ownAgent of [false, true]) {+ assert.equal(idleStatus(0, ownAgent), 'act.working');+ assert.equal(idleStatus(QUIET_MS - 1, ownAgent), 'act.working');+ assert.equal(idleStatus(QUIET_MS, ownAgent), 'act.stillWorking');+ assert.equal(idleStatus(MODEL_WAIT_MS - 1, ownAgent), 'act.stillWorking');+ }+});++test('after two minutes of quiet, the app\'s own agent says it waits for the model; other agents still say "Still working"', () => {+ assert.equal(MODEL_WAIT_MS, 2 * 60_000);+ assert.equal(idleStatus(MODEL_WAIT_MS, true), 'act.waitingForModel');+ assert.equal(idleStatus(10 * 60_000, true), 'act.waitingForModel');+ assert.equal(idleStatus(MODEL_WAIT_MS, false), 'act.stillWorking');+ assert.equal(idleStatus(10 * 60_000, false), 'act.stillWorking');+});diff --git a/apps/desktop/src/pi-agent.mjs b/apps/desktop/src/pi-agent.mjsindex 82f0481..d824923 100644--- a/apps/desktop/src/pi-agent.mjs+++ b/apps/desktop/src/pi-agent.mjs@@ -24,12 +24,19 @@ import { dirname, join, resolve } from 'node:path';import { Readable, Writable } from 'node:stream';import * as acp from '@agentclientprotocol/sdk';import { DefaultResourceLoader, ModelRuntime, SessionManager, SettingsManager, createAgentSession } from '@earendil-works/pi-coding-agent';+import { Agent, install, setGlobalDispatcher } from 'undici';import { agentSessionsDir, openLog } from './chat-store.mjs';-import { THINKING, contextUsed, effortOption, modelOption, modelsJson, providerOf, stopReason, toolCall, toolContent } from './pi-config.mjs';+import { THINKING, WAIT_MINUTES, contextUsed, effortOption, modelOption, modelsJson, providerOf, stopReason, toolCall, toolContent } from './pi-config.mjs';/* stdout is the protocol's: anything else Pi or a library prints goes to stderr */console.log = console.info = console.warn = console.debug = (...args) => process.stderr.write(`${args.map(String).join(' ')}\n`);+/* some services think quietly for minutes before they answer: wait that long for a byte (Node's fetch stops at 5+ minutes), with fetch and its connections from one undici, as Pi's own command line sets them */+const WAIT_MS = WAIT_MINUTES * 60_000;+setGlobalDispatcher(new Agent({ headersTimeout: WAIT_MS, bodyTimeout: WAIT_MS }));+install();+const config = JSON.parse(process.env.OPENFILM_PI ?? '{}');/** OpenFilm's skills for this session (agent-skills.mjs): Pi loads these and no others */const ownSkills = { paths: Array.isArray(config.skills?.paths) ? config.skills.paths : [], names: Array.isArray(config.skills?.names) ? config.skills.names : [] };@@ -106,7 +113,8 @@ async function open(client, cwd, resumeId) {const file = resumeId ? SessionManager.findById(cwd, resumeId, sessionDir) : null;if (resumeId && !file) throw new Error('That conversation is not here any more.');const sessionManager = file ? SessionManager.open(file, sessionDir) : SessionManager.create(cwd, sessionDir);- const settingsManager = SettingsManager.inMemory({ retry: { enabled: true, maxRetries: 2 } });+ /* the model clients' own timeout too (WAIT_MS above), then one more try */+ const settingsManager = SettingsManager.inMemory({ httpIdleTimeoutMs: WAIT_MS, retry: { enabled: true, maxRetries: 1 } });/* the request about to go: its whole context, for the turn's log */let pending = null;/* the session's id, once it has one: the questions `ask` puts are the session's */diff --git a/apps/desktop/src/pi-config.mjs b/apps/desktop/src/pi-config.mjsindex 77518f1..5665c1e 100644--- a/apps/desktop/src/pi-config.mjs+++ b/apps/desktop/src/pi-config.mjs@@ -149,7 +149,10 @@ export function stopReason(message) {}}-/* what the model service's client says when no answer came in time (Pi waits 5 minutes, then tries again twice) */+/** How long Pi waits for a model service to send anything (pi-agent.mjs), before it tries once more. */+export const WAIT_MINUTES = 15;++/* what the model service's client says when no answer came in time */const TIMED_OUT = /request timed out|headers timeout|body timeout/i;/* a conversation longer than the model takes: as Pi says it, then as services commonly do */const PI_OVERFLOW = /^context overflow recovery failed/i;@@ -159,7 +162,7 @@ const CONTEXT_HINT = "The model's context may be smaller than set in Settings: l/** Why a turn failed, in plain words where Pi's own are technical; anything else as Pi said it. */export function failureText(said) {const text = String(said ?? '').trim();- if (TIMED_OUT.test(text)) return "The model service didn't answer for 5 minutes, even after retries. Check that the service is running and reachable, then try again.";+ if (TIMED_OUT.test(text)) return `The model service didn't answer for ${WAIT_MINUTES} minutes, even after trying again. Check that the service is running and reachable, then try again.`;if (PI_OVERFLOW.test(text)) return `${text} ${CONTEXT_HINT}`;if (OVERFLOW.test(text)) return `The conversation is too long for the model. ${CONTEXT_HINT}`;return text;diff --git a/apps/desktop/src/pi-config.test.mjs b/apps/desktop/src/pi-config.test.mjsindex c0e5fd2..23574f9 100644--- a/apps/desktop/src/pi-config.test.mjs+++ b/apps/desktop/src/pi-config.test.mjs@@ -53,7 +53,7 @@ test('what Pi does reads in the chat as Codex\'s did: a command\'s kind and titlassert.equal(stopReason({ stopReason: 'aborted' }), 'cancelled');assert.throws(() => stopReason({ stopReason: 'error', errorMessage: '400 bad' }), /400 bad/);assert.throws(() => stopReason({ stopReason: 'error', errorMessage: 'Request timed out.' }),- (e) => e.message.startsWith("The model service didn't answer for 5 minutes") && e.details === 'Request timed out.');+ (e) => e.message.startsWith("The model service didn't answer for 15 minutes") && e.details === 'Request timed out.');assert.deepEqual(contextUsed({ usage: { input: 100, cacheRead: 900, cacheWrite: 0, output: 50 } }, { contextWindow: 10_000 }), { used: 1050, size: 10_000 });});@@ -97,7 +97,7 @@ test('the effort option: for a model offering more than one, its levels named',});test('why a turn failed, in plain words: a service that sent nothing in time, a conversation too long for the model; else as Pi said it', () => {- const timedOut = "The model service didn't answer for 5 minutes, even after retries. Check that the service is running and reachable, then try again.";+ const timedOut = "The model service didn't answer for 15 minutes, even after trying again. Check that the service is running and reachable, then try again.";assert.equal(failureText('Request timed out.'), timedOut, "the OpenAI and Anthropic clients' own timeout");assert.equal(failureText('Headers Timeout Error'), timedOut);assert.equal(failureText('Body Timeout Error'), timedOut);diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex bc49810..9a71efe 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -41,6 +41,9 @@ importers:openfilm:specifier: workspace:*version: link:../../packages/openfilm+ undici:+ specifier: 8.10.2+ version: 8.10.2devDependencies:'@fontsource-variable/inter':specifier: ^5.3.0