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.

Release client configuration refreshes after setup failures

BlueSkyID666dd451565f419
diff --git a/src/main/features/client_config.ts b/src/main/features/client_config.ts
index d65c154f..0aa3cf1e 100644
--- a/src/main/features/client_config.ts
+++ b/src/main/features/client_config.ts
@@ -501,11 +501,16 @@ export async function refresh(
const error = (err as Error)?.message || String(err);
log.warn('client config refresh failed', { reason, error });
return { updated: false, error };
- } finally {
- inFlight = null;
}
})();
- return inFlight;
+ // Publish the promise before cleanup can run, including synchronous setup
+ // failures before the request's first await.
+ const pending = inFlight;
+ try {
+ return await pending;
+ } finally {
+ if (inFlight === pending) inFlight = null;
+ }
}
function onReturnToApp(): void {
diff --git a/test/main/features/client_config.test.ts b/test/main/features/client_config.test.ts
index a1825c25..f570cf8a 100644
--- a/test/main/features/client_config.test.ts
+++ b/test/main/features/client_config.test.ts
@@ -502,6 +502,36 @@ describe('client_config', () => {
describe('client config response ownership and deadline', () => {
+ it('allows a fresh refresh after the attempt timestamp could not be persisted', async () => {
+ const users = await import('../../../src/main/features/users');
+ const paths = await import('../../../src/main/paths');
+ const storage = await import('../../../src/main/storage');
+ const uid = 'clientconfigattemptrecovery';
+ users.activateUser(uid);
+ const manager = new ClientConfigManager();
+ manager.applyServerPayload({ immediate: { 'feature.recovery': 'cached' }, restart: {} }, 'cached-etag');
+ const failure = Object.assign(new Error('synthetic config write unavailable'), { code: 'EACCES' });
+ const write = vi.spyOn(storage, 'writeJsonSync').mockImplementationOnce(() => { throw failure; });
+ const fetchMock = vi.fn(async () => new Response(JSON.stringify({
+ code: 0, immediate: { 'feature.recovery': 'fresh' }, restart: {}, config_hash: 'recovered-hash',
+ }), { headers: { etag: 'recovered-etag' } }));
+ vi.stubGlobal('fetch', fetchMock);
+ try {
+ await expect(refresh('manual', { force: true })).rejects.toBe(failure);
+ expect(fetchMock).not.toHaveBeenCalled();
+ expect(manager.get('feature.recovery')).toBe('cached');
+ write.mockRestore();
+ await expect(refresh('manual', { force: true })).resolves.toEqual({ updated: true });
+ expect(fetchMock).toHaveBeenCalledOnce();
+ expect(manager.get('feature.recovery')).toBe('fresh');
+ expect(manager.readCache().etag).toBe('recovered-etag');
+ } finally {
+ write.mockRestore();
+ fs.rmSync(path.dirname(paths.userRemoteConfigFile(uid)), { recursive: true, force: true });
+ }
+ });
+
+
afterEach(() => {
stop();
vi.unstubAllGlobals();