Orkas is an open-source (MIT), local-first AI team for your desktop: a Commander turns your goal into to-dos and coordinates 16 built-in specialist agents plus Claude Code, Codex, OpenCode, OpenClaw and Hermes, with projects, scheduled automations and connectors. Free app for macOS & Windows; built-in models or your own keys.
JavaScript agent-collaborationagent-harnessagent-orchestrationagent-teamagent-workflowai-assistantai-automationai-employeeai-productivityai-teamai-workflowautonomous-agentsclaude-code-guiclaude-coworkdesktop-agentlocal-firstmulti-agentmulti-agent-systemself-evolving-agentstask-automation
fix(local-agents): retain bounded OpenCode exit diagnostics
CloudTianTianf86854138c83
diff --git a/src/main/features/local_agents/backends/base.ts b/src/main/features/local_agents/backends/base.tsindex 4264cecd..21309818 100644--- a/src/main/features/local_agents/backends/base.ts+++ b/src/main/features/local_agents/backends/base.ts@@ -95,6 +95,7 @@ export interface LocalEvent {* // silent spinner.* done: { status: 'completed'|'failed'|'cancelled'|'timeout'|* 'missing_cli', error?, durationMs?, sessionId?, usage?,+ * exitCode?, protocolRecordCount?, protocolErrorSeen?,* finalMessageText?: string (Claude's last native result),* timeoutPhase?: 'foreground'|'background',* failureKind?: 'cli_spawn'|'cli_protocol', retrySafe?: boolean }diff --git a/src/main/features/local_agents/backends/opencode.ts b/src/main/features/local_agents/backends/opencode.tsindex d0249882..9c3e8969 100644--- a/src/main/features/local_agents/backends/opencode.ts+++ b/src/main/features/local_agents/backends/opencode.ts@@ -52,6 +52,7 @@ const opencodeRunBackend: LocalBackend = {let textOut = '';let resultStatus: 'completed' | 'failed' | undefined;let resultError: string | undefined;+ let protocolRecordCount = 0;let observedSessionId: string | undefined;// Most-recent per-step usage snapshot; step_finish events fire// throughout the turn, each carrying the cumulative-so-far. We@@ -91,6 +92,7 @@ const opencodeRunBackend: LocalBackend = {opts.onEvent({ type: 'raw-line', line: trimmed });return;}+ protocolRecordCount = Math.min(1_000_000, protocolRecordCount + 1);const ev = mapOpencodeEvent(obj);if (ev?.captureSessionId) observedSessionId = ev.captureSessionId;const events = ev?.events || (ev?.event ? [ev.event] : []);@@ -144,14 +146,22 @@ const opencodeRunBackend: LocalBackend = {});});child.on('close', code => {+ const exitDiagnostic = {+ exitCode: Number.isSafeInteger(code) && code !== null && code >= 0 && code <= 65535 ? code : null,+ protocolRecordCount,+ protocolErrorSeen: !!resultError,+ };if (opts.signal.aborted) return finish('cancelled', { output: textOut });-if (watchdog.fired()) return finish('timeout', { timeoutKind: watchdog.fired(), error: `cli ${watchdog.reason()}`, output: textOut, stderrTail: tail.toString() });+ if (watchdog.fired()) return finish('timeout', {+ timeoutKind: watchdog.fired(), error: `cli ${watchdog.reason()}`,+ output: textOut, stderrTail: tail.toString(),+ });if (code === 0 && (resultStatus === 'completed' || resultStatus === undefined)) {- return finish('completed', { output: textOut });+ return finish('completed', { output: textOut, ...exitDiagnostic });}const err = resultError|| (code !== 0 ? `opencode exited with code ${code}` : 'opencode closed without final event');- finish('failed', { error: err, output: textOut, stderrTail: tail.toString() });+ finish('failed', { error: err, output: textOut, stderrTail: tail.toString(), ...exitDiagnostic });});});},diff --git a/src/main/features/local_agents/runner.ts b/src/main/features/local_agents/runner.tsindex 541b12e6..1b97545f 100644--- a/src/main/features/local_agents/runner.ts+++ b/src/main/features/local_agents/runner.ts@@ -737,6 +737,9 @@ export interface LocalAgentRunLogDiagnostics {doneEventMs?: number;terminalStatus?: string;terminalError: boolean;+ exitCode?: number | null;+ protocolRecordCount?: number;+ protocolErrorSeen?: boolean;usage?: Record<string, number>;toolTimeline: LocalToolTimelineLogEntry[];toolTimelineTruncated: number;@@ -978,6 +981,14 @@ export function recordLocalAgentEventForLog(stats: LocalAgentRunLogDiagnostics,noteElapsedOnce(stats, 'doneEventMs', nowMs);stats.terminalStatus = typeof e.status === 'string' ? e.status : stats.terminalStatus;stats.terminalError = !!e.error;+ if (e.exitCode === null) stats.exitCode = null;+ else if (typeof e.exitCode === 'number' && Number.isSafeInteger(e.exitCode)+ && e.exitCode >= 0 && e.exitCode <= 65535) stats.exitCode = e.exitCode;+ if (typeof e.protocolRecordCount === 'number' && Number.isSafeInteger(e.protocolRecordCount)+ && e.protocolRecordCount >= 0 && e.protocolRecordCount <= 1_000_000) {+ stats.protocolRecordCount = e.protocolRecordCount;+ }+ if (typeof e.protocolErrorSeen === 'boolean') stats.protocolErrorSeen = e.protocolErrorSeen;stats.usage = safeUsageForLog(e.usage) || stats.usage;noteLocalEventTimelineForLog(stats, 'done', nowMs, `status=${String(e.status || '')} error=${e.error ? 'true' : 'false'}`);break;@@ -1020,6 +1031,9 @@ export function summarizeLocalAgentRunForLog(stats: LocalAgentRunLogDiagnostics,doneEventMs: stats.doneEventMs,terminalStatus: stats.terminalStatus,terminalError: stats.terminalError,+ ...(stats.exitCode !== undefined ? { exitCode: stats.exitCode } : {}),+ ...(stats.protocolRecordCount !== undefined ? { protocolRecordCount: stats.protocolRecordCount } : {}),+ ...(stats.protocolErrorSeen !== undefined ? { protocolErrorSeen: stats.protocolErrorSeen } : {}),usage: stats.usage,};}diff --git a/test/main/features/local_agents/opencode_backend.test.ts b/test/main/features/local_agents/opencode_backend.test.tsindex 69466a8f..2b81f348 100644--- a/test/main/features/local_agents/opencode_backend.test.ts+++ b/test/main/features/local_agents/opencode_backend.test.ts@@ -23,6 +23,16 @@ function fixture() {process.stdin.on('end', () => {const input = Buffer.concat(chunks);const args = process.argv.slice(2);+ if (args.includes('--fixture-silent-fail')) {+ process.stderr.write('startup failed before JSON output\\n');+ process.exitCode = 1;+ return;+ }+ if (args.includes('--fixture-protocol-error')) {+ process.stdout.write(JSON.stringify({ type: 'error', error: { data: { message: 'configured model unavailable' } } }) + '\\n');+ process.exitCode = 1;+ return;+ }const text = JSON.stringify({ hash: createHash('sha256').update(input).digest('hex'), bytes: input.length, args });process.stdout.write(JSON.stringify({ type: 'text', part: { text } }) + '\\n');if (args.includes('--fixture-wait')) { setInterval(() => {}, 1000); return; }@@ -77,4 +87,35 @@ describe('OpenCode prompt pipe transport', () => {expect(terminals[0].status).toBe(mode === 'cancel' ? 'cancelled' : 'failed');if (mode === 'fail') expect(terminals[0].error).toBe('opencode exited with code 7');});++ it('retains content-free evidence for a CLI that exits before its first protocol record', async () => {+ const events: LocalEvent[] = [];+ await opencodeBackend.run({+ binPath: process.env.ORKAS_TEST_NODE || process.execPath,+ cwd: fixture(), prompt: 'list files', customArgs: ['--fixture-silent-fail'],+ signal: new AbortController().signal, timeoutMs: 10_000,+ onEvent: event => events.push(event),+ });+ const done = events.find(event => event.type === 'done');+ expect(done).toMatchObject({+ status: 'failed', exitCode: 1, protocolRecordCount: 0,+ protocolErrorSeen: false,+ });+ expect(events.some(event => event.type === 'stderr-line')).toBe(true);+ });++ it('distinguishes a structured CLI error from a silent startup failure', async () => {+ const events: LocalEvent[] = [];+ await opencodeBackend.run({+ binPath: process.env.ORKAS_TEST_NODE || process.execPath,+ cwd: fixture(), prompt: 'list files', customArgs: ['--fixture-protocol-error'],+ signal: new AbortController().signal, timeoutMs: 10_000,+ onEvent: event => events.push(event),+ });+ expect(events.find(event => event.type === 'done')).toMatchObject({+ status: 'failed', exitCode: 1, protocolRecordCount: 1,+ protocolErrorSeen: true, error: 'configured model unavailable',+ });+ expect(events.some(event => event.type === 'stderr-line')).toBe(false);+ });});diff --git a/test/main/features/local_agents/runner.test.ts b/test/main/features/local_agents/runner.test.tsindex b3b35edb..d7223b87 100644--- a/test/main/features/local_agents/runner.test.ts+++ b/test/main/features/local_agents/runner.test.ts@@ -285,7 +285,7 @@ describe('local_agents/runner', () => {paths: ['/Users/test/private.txt', '/Users/test/other.txt'],}, 1170);runner.recordLocalAgentEventForLog(stats, { type: 'status', status: 'usage', usage: { input: 5, output: 7, secretText: 'nope' } }, 1180);- runner.recordLocalAgentEventForLog(stats, { type: 'done', status: 'completed', output: 'private final', usage: { input: 5, output: 8 } }, 1200);+ runner.recordLocalAgentEventForLog(stats, { type: 'done', status: 'completed', output: 'private final', usage: { input: 5, output: 8 }, exitCode: 0, protocolRecordCount: 2, protocolErrorSeen: false }, 1200);const summary = runner.summarizeLocalAgentRunForLog(stats, 1300);expect(summary.eventCount).toBe(13);@@ -298,6 +298,7 @@ describe('local_agents/runner', () => {expect(summary.fileChangePathCount).toBe(2);expect(summary.permissionAutoDeny).toBe(1);expect(summary.usage).toMatchObject({ input: 5, output: 8 });+ expect(summary).toMatchObject({ exitCode: 0, protocolRecordCount: 2, protocolErrorSeen: false });expect(summary.toolTimeline).toEqual(['#1 +140ms bash use call=loca...3456',`#2 +150ms bash result call=loca...3456 error=true output_chars=${'private tool output'.length} spilled=true`,