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.

Use Electron fetch for main-process retries

wyt41aa2d8390ce
diff --git a/src/main/index.ts b/src/main/index.ts
index 855db553..8aee477d 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -30,7 +30,7 @@ import * as path from 'node:path';
import * as fs from 'node:fs';
import { spawn } from 'node:child_process';
import { Readable } from 'node:stream';
-import { app, BrowserWindow, Menu, ipcMain, nativeImage, protocol, session, shell } from 'electron';
+import { app, BrowserWindow, Menu, ipcMain, nativeImage, net, protocol, session, shell } from 'electron';
// Side-effect import: at module-load time this resolves the install
// container, runs the one-shot PC/data → <container>/data migration, and
// sets process.env.ORKAS_WORKSPACE_ROOT. Must be the FIRST project import
@@ -126,6 +126,9 @@ installSseHeaderTimeoutPatch();
import { installFetchDiag } from './model/core-agent/fetch-diag';
installFetchDiag();
+import { setFetchImplementation } from './util/retry';
+setFetchImplementation((input, init) => net.fetch(input as Parameters<typeof net.fetch>[0], init));
+
import { prompts } from './prompts/loader';
import * as ipc from './ipc';
import * as users from './features/users';
diff --git a/src/main/util/retry.ts b/src/main/util/retry.ts
index 3d87f7f2..15f2da6b 100644
--- a/src/main/util/retry.ts
+++ b/src/main/util/retry.ts
@@ -6,6 +6,14 @@ const log = createLogger('retry');
export const DEFAULT_NETWORK_RETRY_ATTEMPTS = 3;
export const DEFAULT_NETWORK_RETRY_DELAYS_MS = [500, 1_000, 2_000];
+type FetchImplementation = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
+
+let fetchImplementation: FetchImplementation | null = null;
+
+export function setFetchImplementation(impl: FetchImplementation | null): void {
+ fetchImplementation = impl;
+}
+
export class RetriableHttpStatusError extends Error {
status: number;
@@ -67,7 +75,7 @@ export async function fetchWithRetry(
} = {},
): Promise<Response> {
return retryAsync(label, async () => {
- const res = await fetch(input, init);
+ const res = await (fetchImplementation || fetch)(input, init);
if (isRetriableHttpStatus(res.status)) {
throw new RetriableHttpStatusError(res.status, label);
}