Skip to content

armgit / Orkas

Public Imported from GitHub
0

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.

fix: classify Hermes retry exhaustion

wyt26b386b5afbc
diff --git a/src/main/features/local_agents/backends/_acp.ts b/src/main/features/local_agents/backends/_acp.ts
index df92f09d..804d0c50 100644
--- a/src/main/features/local_agents/backends/_acp.ts
+++ b/src/main/features/local_agents/backends/_acp.ts
@@ -16,6 +16,7 @@
import { createLogger } from '../../../logger.js';
import { logErrorSummary } from '../../../util/log-redact.js';
+import { isHermesApiRetryFailureText } from '../errors.js';
import {
type LocalBackend,
type BackendRunOptions,
@@ -265,6 +266,18 @@ export function makeAcpBackend(def: AcpBackendDef): LocalBackend {
if (opts.signal.aborted) return finish('cancelled', { output: resultText });
if (watchdog.fired()) return finish('timeout', { error: `cli ${watchdog.reason()}`, output: resultText, stderrTail: tail.toString() });
if (code === 0 && resultStatus === 'completed') {
+ // Hermes can exhaust its upstream API retries, stream the failure
+ // sentence as an agent_message_chunk, then still close with
+ // stopReason=end_turn and exit 0. The prefix is runtime-authored,
+ // not model prose. Treat that exact one-line terminal shape as a
+ // failed run and keep the provider detail out of public output.
+ if (isHermesApiRetryFailureText(resultText)) {
+ return finish('failed', {
+ error: 'upstream provider request failed after retries',
+ output: '',
+ stderrTail: tail.toString(),
+ });
+ }
// Demote silent failure: server claimed success via
// stopReason=end_turn but never streamed any text AND
// stderr contained an upstream-provider error. Hermes
diff --git a/src/main/features/local_agents/errors.ts b/src/main/features/local_agents/errors.ts
index ae0b72bc..873e6975 100644
--- a/src/main/features/local_agents/errors.ts
+++ b/src/main/features/local_agents/errors.ts
@@ -9,6 +9,17 @@ const UPGRADE_REQUIRED_PATTERNS = [
/Codex version is (?:too old|unsupported)/i,
];
+/** Hermes 0.9 can stream this runtime-authored sentence as its only agent
+ * message before returning a successful ACP end_turn. It is an upstream
+ * request failure, not a model answer. Keep the match deliberately narrow so
+ * ordinary explanations that merely discuss API errors remain untouched. */
+export function isHermesApiRetryFailureText(text: unknown): boolean {
+ const value = typeof text === 'string' ? text.trim() : '';
+ return value.length > 0
+ && value.length <= 1_000
+ && /^API call failed after \d+ retries?:\s*[^\r\n]+$/iu.test(value);
+}
+
export function classifyCliRuntimeFailure(error: unknown): CliRuntimeFailure {
const text = typeof error === 'string'
? error
diff --git a/src/main/features/local_agents/public-output.ts b/src/main/features/local_agents/public-output.ts
index 372f23f8..03ca6465 100644
--- a/src/main/features/local_agents/public-output.ts
+++ b/src/main/features/local_agents/public-output.ts
@@ -8,6 +8,7 @@
*/
import type { LocalCliType } from './registry.js';
+import { isHermesApiRetryFailureText } from './errors.js';
type KstarSectionId = 'K' | 'S' | 'T' | 'A' | 'EXPECTED' | 'R' | 'DELTA' | 'AAR';
@@ -121,6 +122,7 @@ export function sanitizeLocalAgentPublicOutput(args: {
}): string {
const text = String(args.text || '');
if (args.cli !== 'hermes' || !text.trim()) return text;
+ if (isHermesApiRetryFailureText(text)) return '';
if (hasExplicitKstarRequest(String(args.userTask || ''))) return text;
const extracted = extractHermesKstarResult(text);
return extracted.matched ? extracted.result : text;
diff --git a/test/main/features/local_agents/acp_backend.test.ts b/test/main/features/local_agents/acp_backend.test.ts
index e31f7879..827efebd 100644
--- a/test/main/features/local_agents/acp_backend.test.ts
+++ b/test/main/features/local_agents/acp_backend.test.ts
@@ -205,4 +205,64 @@ describe('local_agents/backends/_acp process lifecycle', () => {
output: 'silent setter recovered',
});
});
+
+ it('fails a terminal Hermes API retry message instead of publishing it as a successful answer', async () => {
+ const fakeAcpServer = String.raw`
+ let buffer = '';
+ const send = (message) => process.stdout.write(JSON.stringify(message) + '\n');
+ process.stdin.setEncoding('utf8');
+ process.stdin.on('data', (chunk) => {
+ buffer += chunk;
+ let newline;
+ while ((newline = buffer.indexOf('\n')) >= 0) {
+ const line = buffer.slice(0, newline);
+ buffer = buffer.slice(newline + 1);
+ if (!line.trim()) continue;
+ const message = JSON.parse(line);
+ if (message.method === 'initialize') {
+ send({ jsonrpc: '2.0', id: message.id, result: { protocolVersion: 1 } });
+ } else if (message.method === 'session/new') {
+ send({ jsonrpc: '2.0', id: message.id, result: { sessionId: 'acp-api-retry-failure' } });
+ } else if (message.method === 'session/prompt') {
+ send({ jsonrpc: '2.0', method: 'session/update', params: {
+ sessionId: 'acp-api-retry-failure',
+ update: {
+ sessionUpdate: 'agent_message_chunk',
+ content: {
+ text: 'API call failed after 3 retries: HTTP 404: 404 Not found. Check the docs for available routes.',
+ },
+ },
+ } });
+ send({ jsonrpc: '2.0', id: message.id, result: { stopReason: 'end_turn' } });
+ }
+ }
+ });
+ `;
+ const backend = makeAcpBackend({
+ logName: 'local-agents:test-acp',
+ argv: ['-e', fakeAcpServer],
+ clientName: 'orkas-test',
+ });
+ const events: any[] = [];
+
+ await backend.run({
+ binPath: TEST_NODE,
+ prompt: 'answer the user',
+ cwd: process.cwd(),
+ signal: new AbortController().signal,
+ timeoutMs: 2_000,
+ onEvent: event => events.push(event),
+ });
+
+ expect(events).toContainEqual(expect.objectContaining({
+ type: 'text-delta',
+ text: expect.stringContaining('API call failed after 3 retries'),
+ }));
+ expect(events.at(-1)).toMatchObject({
+ type: 'done',
+ status: 'failed',
+ error: 'upstream provider request failed after retries',
+ output: '',
+ });
+ });
});
diff --git a/test/main/features/local_agents/errors.test.ts b/test/main/features/local_agents/errors.test.ts
index b3850935..07035820 100644
--- a/test/main/features/local_agents/errors.test.ts
+++ b/test/main/features/local_agents/errors.test.ts
@@ -1,6 +1,9 @@
import { describe, expect, it } from 'vitest';
-import { classifyCliRuntimeFailure } from '../../../../src/main/features/local_agents/errors';
+import {
+ classifyCliRuntimeFailure,
+ isHermesApiRetryFailureText,
+} from '../../../../src/main/features/local_agents/errors';
describe('local_agents/errors', () => {
it('classifies Codex model/version rejections as upgrade requirements', () => {
@@ -20,3 +23,17 @@ describe('local_agents/errors', () => {
expect(classifyCliRuntimeFailure(null)).toBeNull();
});
});
+
+describe('local_agents/errors Hermes terminal text', () => {
+ it('matches only the bounded one-line retry-exhaustion result', () => {
+ expect(isHermesApiRetryFailureText(
+ 'API call failed after 3 retries: HTTP 404: 404 Not found. Check the docs for available routes.',
+ )).toBe(true);
+ expect(isHermesApiRetryFailureText(
+ 'The API call failed after 3 retries, so I checked another route and recovered.',
+ )).toBe(false);
+ expect(isHermesApiRetryFailureText(
+ 'API call failed after 3 retries: HTTP 404\nRecovery: use the local conversation.',
+ )).toBe(false);
+ });
+});
diff --git a/test/main/features/local_agents/public-output.test.ts b/test/main/features/local_agents/public-output.test.ts
index 641494ed..94ed0f33 100644
--- a/test/main/features/local_agents/public-output.test.ts
+++ b/test/main/features/local_agents/public-output.test.ts
@@ -207,4 +207,19 @@ describe('local_agents/public-output', () => {
userTask: 'Summarize',
})).toBe(raw);
});
+
+ it('does not publish a Hermes terminal API retry failure as agent prose', () => {
+ const raw = 'API call failed after 3 retries: HTTP 404: 404 Not found. Check the docs for available routes.';
+
+ expect(sanitizeLocalAgentPublicOutput({
+ cli: 'hermes',
+ text: raw,
+ userTask: 'Explain why the local conversation did not continue.',
+ })).toBe('');
+ expect(sanitizeLocalAgentPublicOutput({
+ cli: 'codex',
+ text: raw,
+ userTask: 'Repeat this diagnostic.',
+ })).toBe(raw);
+ });
});