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(proxy): classify Electron proxy connection failures

BlueSkyID666b3e779758f3a
diff --git a/src/main/util/proxy-dispatcher.ts b/src/main/util/proxy-dispatcher.ts
index 0e4312b7..bf0684e3 100644
--- a/src/main/util/proxy-dispatcher.ts
+++ b/src/main/util/proxy-dispatcher.ts
@@ -318,14 +318,29 @@ function validBridgeToken(actual: string | string[] | undefined, expected: strin
return a.length === b.length && timingSafeEqual(a, b);
}
+/** Chromium can reject a proxy connection with only a net error message.
+ * Add a transport code at the Electron boundary so provider retry accounting
+ * can use structured facts without interpreting arbitrary error prose. */
+export function normalizeElectronNetFetchError(error: unknown): unknown {
+ if (!(error instanceof Error) || error.name !== 'Error'
+ || error.message !== 'net::ERR_PROXY_CONNECTION_FAILED') return error;
+ const facts = error as Error & { code?: unknown; cause?: unknown };
+ if (facts.code != null || facts.cause != null) return error;
+ return Object.assign(new Error(error.message, { cause: error }), { code: 'ENETUNREACH' });
+}
+
async function electronSystemFetch(): Promise<FetchLike> {
const { net } = await import('electron');
- return ((input: Parameters<FetchLike>[0], init?: Parameters<FetchLike>[1]) => {
+ return (async (input: Parameters<FetchLike>[0], init?: Parameters<FetchLike>[1]) => {
const normalized = input instanceof URL ? input.href : input;
- return net.fetch(
- normalized as Parameters<typeof net.fetch>[0],
- init as Parameters<typeof net.fetch>[1],
- ) as Promise<Response>;
+ try {
+ return await net.fetch(
+ normalized as Parameters<typeof net.fetch>[0],
+ init as Parameters<typeof net.fetch>[1],
+ ) as Response;
+ } catch (error) {
+ throw normalizeElectronNetFetchError(error);
+ }
}) as FetchLike;
}
diff --git a/test/main/util/proxy-dispatcher.test.ts b/test/main/util/proxy-dispatcher.test.ts
index 58b780b1..0d33a328 100644
--- a/test/main/util/proxy-dispatcher.test.ts
+++ b/test/main/util/proxy-dispatcher.test.ts
@@ -14,10 +14,12 @@ import {
envProxyUrl,
installEnvProxyDispatcher,
installSystemProxyDispatcher,
+ normalizeElectronNetFetchError,
parseResolvedProxyRoute,
resolveProxyRouteForUrl,
startChildFetchBridge,
} from '../../../src/main/util/proxy-dispatcher';
+import { classifyTransientNetworkError } from '../../../src/core-agent/src/shared/errors';
const hostFetch = globalThis.fetch;
const proxyEnvKeys = [
@@ -52,6 +54,26 @@ afterEach(() => {
else process.env.ORKAS_NO_AUTO_PROXY = savedNoAutoProxy;
});
+describe('Electron system-proxy transport failures', () => {
+ it('keeps a message-only Chromium proxy failure in the network exhaustion category', () => {
+ const rejection = new Error('net::ERR_PROXY_CONNECTION_FAILED');
+ expect(classifyTransientNetworkError(rejection)).toBeNull();
+
+ const normalized = normalizeElectronNetFetchError(rejection);
+ expect(normalized).toMatchObject({ code: 'ENETUNREACH', cause: rejection });
+ expect(classifyTransientNetworkError(normalized)).toBe('network');
+ });
+
+ it('leaves structured failures, aborts, and similar prose untouched', () => {
+ const structured = Object.assign(new Error('net::ERR_PROXY_CONNECTION_FAILED'), { code: 'ETIMEDOUT' });
+ const aborted = Object.assign(new Error('net::ERR_PROXY_CONNECTION_FAILED'), { name: 'AbortError' });
+ const prose = new Error('request failed: net::ERR_PROXY_CONNECTION_FAILED');
+ expect(normalizeElectronNetFetchError(structured)).toBe(structured);
+ expect(normalizeElectronNetFetchError(aborted)).toBe(aborted);
+ expect(normalizeElectronNetFetchError(prose)).toBe(prose);
+ });
+});
+
describe('util/proxy-dispatcher environment configuration', () => {
it('returns no proxy when the environment is empty', () => {
expect(envProxyConfig({})).toMatchObject({ httpProxy: undefined, httpsProxy: undefined });