Skip to content

The open source AI video agent: turns any coding agent into a video agent, with an editor to change anything it makes.

Chat: an agent whose process ends without a word names the command and its exit code, not the network (#232)

Rick2811d4bef604
diff --git a/.changeset/agent-exit-command.md b/.changeset/agent-exit-command.md
new file mode 100644
index 0000000..6958293
--- /dev/null
+++ b/.changeset/agent-exit-command.md
@@ -0,0 +1,5 @@
+---
+"@openfilm/desktop": patch
+---
+
+An agent whose process ends before it answers, without a word, is no longer blamed on the network. The chat names the command that was run and the code its process ended with, as in "Its process ("…\dsh\lib\cli.js" --profile acp) ended with code 0.", so a wrong program is plain to see.
diff --git a/apps/desktop/src/agents.mjs b/apps/desktop/src/agents.mjs
index e6d0a09..5dc2f5d 100644
--- a/apps/desktop/src/agents.mjs
+++ b/apps/desktop/src/agents.mjs
@@ -900,22 +900,27 @@ export function stderrReason(stderr = '') {
return [...new Set((reasons.length ? reasons : lines).slice(-3))].join(' | ').slice(-600);
}
+/* one word of a command as the chat shows it: quoted when it has a space */
+const shownArg = (/** @type {string} */ a) => (a && !/[\s"]/.test(a) ? a : `"${a}"`);
+
/**
- * An agent's failure as it is: what it said when it said why; else the step it stopped at, how its process ended and
- * the last it wrote to stderr; with neither, that an agent which cannot reach its service stops like this.
- * @param {any} e @param {{ label: string, step?: string | null, stderr?: string, exited?: { code: number | null } | null }} at
+ * An agent's failure as it is: what it said when it said why; else the step it stopped at, how its process ended (the
+ * command it ran and its code) and the last it wrote to stderr; with neither, while its process still runs, that an
+ * agent which cannot reach its service stops like this. A process that ended is not the network.
+ * @param {any} e @param {{ label: string, step?: string | null, stderr?: string, exited?: { code: number | null } | null, command?: string[] | null }} at
*/
-export function explainFailure(e, { label, step = null, stderr = '', exited = null }) {
+export function explainFailure(e, { label, step = null, stderr = '', exited = null, command = null }) {
const said = (e instanceof Error ? e.message : String(e ?? '')).trim();
const bare = !said || SAYS_NOTHING.test(said);
if (!bare && !exited) return e;
const tail = stderrReason(stderr);
const where = step && STEP_WORDS[step] ? ` ${STEP_WORDS[step]}` : '';
- const ended = exited ? ` Its process ended${exited.code == null ? '' : ` with code ${exited.code}`}.` : '';
+ const ran = command?.length ? ` (${command.map(shownArg).join(' ')})` : '';
+ const ended = exited ? ` Its process${ran} ended${exited.code == null ? '' : ` with code ${exited.code}`}.` : '';
const message = [
bare ? `${label} stopped${where} without saying why.` : said,
ended.trim(),
- tail ? `It last wrote: ${tail}` : bare ? 'If it cannot reach its service, check the network or proxy, then try again.' : '',
+ tail ? `It last wrote: ${tail}` : bare && !exited ? 'If it cannot reach its service, check the network or proxy, then try again.' : '',
].filter(Boolean).join(' ');
return Object.assign(new Error(message, { cause: e }), { ...(e?.code !== undefined ? { code: e.code } : {}), ...(step ? { step } : {}) });
}
@@ -1040,7 +1045,7 @@ export class AgentSession {
if (this.child && !this.exited && this.child.exitCode === null && this.child.signalCode === null) {
await new Promise((done) => { this.child.once('exit', done); setTimeout(done, 1000).unref?.(); });
}
- return explainFailure(e, { label: this.spec.label, step: this.step, stderr: this.stderr, exited: this.exited ?? null });
+ return explainFailure(e, { label: this.spec.label, step: this.step, stderr: this.stderr, exited: this.exited ?? null, command: this.command ?? null });
}
/**
@@ -1089,6 +1094,8 @@ export class AgentSession {
? await logSwitches(this.opts.agent, { base: this.opts.logDir, shell, cwd: this.opts.cwd }).catch(() => null) : null;
/* an agent that speaks ACP itself: its own program, started as the registry starts it */
const native = cli && !this.spec.adapter ? starting(cli.path, [...this.spec.args, ...(this.logging?.args ?? []), ...(skills?.args ?? [])]) : null;
+ /* what a failure names: the agent's program and its own words, as the person would run it (not our logging or skills) */
+ this.command = native ? [cli.path, ...this.spec.args] : null;
const extra = { ...agentDefaults(this.opts.agent, shell), ...this.opts.env, ...(native ? native.env : node.env), ...(cli && this.spec.env ? this.spec.env(cli.path) : {}), ...own, ...skills?.env, ...this.logging?.env };
/* OpenCode's inline configuration carries both its skills and, in Developer mode, its logging */
if (skills?.env?.OPENCODE_CONFIG_CONTENT && this.logging?.env?.OPENCODE_CONFIG_CONTENT) {
diff --git a/apps/desktop/src/agents.test.mjs b/apps/desktop/src/agents.test.mjs
index 4dcccaa..01df0f5 100644
--- a/apps/desktop/src/agents.test.mjs
+++ b/apps/desktop/src/agents.test.mjs
@@ -444,6 +444,21 @@ test('a failure keeps what the agent said; one that says nothing says where it s
assert.equal(ended.message, 'Rate limit reached. Its process ended.');
});
+test('a process that ends without a word names the command it ran, not the network', () => {
+ const command = ['C:\\Programs\\DeepSeek Harness\\resources\\app.asar\\dsh\\lib\\cli.js', '--profile', 'acp'];
+ const silent = explainFailure(new Error('ACP connection closed'), { label: 'DeepSeek Harness', step: 'initialize', exited: { code: 0 }, command });
+ assert.equal(silent.message, 'DeepSeek Harness stopped as it started without saying why. '
+ + 'Its process ("C:\\Programs\\DeepSeek Harness\\resources\\app.asar\\dsh\\lib\\cli.js" --profile acp) ended with code 0.');
+ assert.doesNotMatch(silent.message, /network/);
+
+ const wrote = explainFailure(new Error('ACP connection closed'), { label: 'Kimi', step: 'initialize', exited: { code: 1 }, stderr: 'Error: bad config', command: ['/usr/local/bin/kimi', 'acp'] });
+ assert.equal(wrote.message, 'Kimi stopped as it started without saying why. Its process (/usr/local/bin/kimi acp) ended with code 1. It last wrote: Error: bad config');
+
+ const running = explainFailure(new Error('Internal error'), { label: 'Kimi', step: 'session/prompt', command: ['/usr/local/bin/kimi', 'acp'] });
+ assert.match(running.message, /check the network or proxy/, 'a process still running may be waiting on its service');
+ assert.doesNotMatch(running.message, /kimi acp/);
+});
+
test('"Internal error" with its reason in data: the reason is what the turn says, and the error as sent stays under it', () => {
const sent = Object.assign(new Error('Internal error'), { code: -32603, data: { details: 'Request timed out.' } });
const said = explainFailure(signInError('Codex', sent, { own: true }), { label: 'Codex', step: 'session/prompt' });