You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maka.apache.org by zh...@apache.org on 2026/09/01 15:07:32 UTC

(maka) 09/10: fix(desktop): fail closed on onboarding response errors

This is an automated email from the ASF dual-hosted git repository.

me2seeks pushed a commit to branch feat/desktop-api-key-host-onboarding
in repository https://gitbox.apache.org/repos/asf/maka.git

commit 019c8e036f1c2a2fd760878b8acad8f0b4657779
Author: me2seeks <me...@gmail.com>
AuthorDate: Tue Sep 1 15:42:25 2026 +0800

    fix(desktop): fail closed on onboarding response errors
---
 .../runtime-host-connections-ipc-main.test.ts      | 41 ++++++++++++++++++++++
 .../src/main/runtime-host-connections-ipc-main.ts  | 21 ++++++-----
 2 files changed, 54 insertions(+), 8 deletions(-)

diff --git a/apps/desktop/src/main/__tests__/runtime-host-connections-ipc-main.test.ts b/apps/desktop/src/main/__tests__/runtime-host-connections-ipc-main.test.ts
index afd6bdaf7b..8f62b36c3d 100644
--- a/apps/desktop/src/main/__tests__/runtime-host-connections-ipc-main.test.ts
+++ b/apps/desktop/src/main/__tests__/runtime-host-connections-ipc-main.test.ts
@@ -224,6 +224,47 @@ test('keeps Host commit_outcome_unknown distinct from a safe non-save', async ()
   });
 });
 
+test('fails closed when a dispatched onboarding response cannot be decoded', async () => {
+  const handlers = new Map<string, (...args: unknown[]) => unknown>();
+  let attempt = 0;
+  registerRuntimeHostConnectionsIpc({
+    ipcMain: {
+      handle: (channel, handler) => {
+        handlers.set(channel, handler as (...args: unknown[]) => unknown);
+      },
+    },
+    client: {
+      saveConnectionOnboarding: async () => {
+        attempt += 1;
+        if (attempt === 1) {
+          // RuntimeHostConnection surfaces a malformed command response as
+          // an ordinary protocol error after the frame was dispatched.
+          throw new Error('Invalid connection onboarding save result');
+        }
+        throw new RuntimeHostOperationError(
+          'connection.onboarding.save',
+          'invalid_request',
+          'The Host definitively rejected the save',
+        );
+      },
+    } as never,
+    emitConnectionListChanged() {},
+  });
+  const input = {
+    target: { kind: 'create', providerType: 'openai' },
+    apiKey: 'test-key',
+    baseUrl: null,
+    enabledModelIds: ['gpt-5'],
+  };
+
+  assert.deepEqual(await handlers.get('connections:onboardingSave')?.({}, input), {
+    kind: 'outcome_unknown',
+  });
+  assert.deepEqual(await handlers.get('connections:onboardingSave')?.({}, input), {
+    kind: 'not_saved',
+  });
+});
+
 test('retries connection delete after a stale revision instead of failing permanently', async () => {
   const handlers = new Map<string, (...args: unknown[]) => unknown>();
   let revision = 1;
diff --git a/apps/desktop/src/main/runtime-host-connections-ipc-main.ts b/apps/desktop/src/main/runtime-host-connections-ipc-main.ts
index f33228756c..deeb731da8 100644
--- a/apps/desktop/src/main/runtime-host-connections-ipc-main.ts
+++ b/apps/desktop/src/main/runtime-host-connections-ipc-main.ts
@@ -181,15 +181,20 @@ export function registerRuntimeHostConnectionsIpc(
       if (result.kind === 'saved') deps.emitConnectionListChanged();
       return { kind: 'result', result } satisfies DesktopConnectionOnboardingSaveOutcome;
     } catch (error) {
-      if (
-        (error instanceof RuntimeHostOperationError &&
-          error.code === 'commit_outcome_unknown') ||
-        (error instanceof RuntimeHostRequestInterruptedError &&
-          error.dispatch === 'dispatched')
-      ) {
-        return { kind: 'outcome_unknown' } satisfies DesktopConnectionOnboardingSaveOutcome;
+      if (error instanceof RuntimeHostOperationError) {
+        return {
+          kind: error.code === 'commit_outcome_unknown' ? 'outcome_unknown' : 'not_saved',
+        } satisfies DesktopConnectionOnboardingSaveOutcome;
       }
-      return { kind: 'not_saved' } satisfies DesktopConnectionOnboardingSaveOutcome;
+      if (error instanceof RuntimeHostRequestInterruptedError) {
+        return {
+          kind: error.dispatch === 'not_dispatched' ? 'not_saved' : 'outcome_unknown',
+        } satisfies DesktopConnectionOnboardingSaveOutcome;
+      }
+      // A protocol/decode failure can arrive only after the command response
+      // has started coming back. Without affirmative evidence that the Host
+      // did not commit, allowing another create risks duplicating the account.
+      return { kind: 'outcome_unknown' } satisfies DesktopConnectionOnboardingSaveOutcome;
     }
   });
   deps.ipcMain.handle('connections:create', async (_event, raw: unknown) => {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org