Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(orca): preserve execution-device discovery failures

davidfb66bb88a7aa
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/orcaRemoteWorkers.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/orcaRemoteWorkers.test.ts
index bd33c1f99f..2d272f71b9 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/orcaRemoteWorkers.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/orcaRemoteWorkers.test.ts
@@ -6,6 +6,7 @@ import type { OrcaRemotePendingReport } from '../../../shared/orcaRemoteWorker.j
import { createOrcaTeamService, type OrcaTeamService, type OrcaTeamServiceDeps, type OrcaWorkerRecordSnapshot, type WorkerTerminalTurnCapture } from '../orcaTeamService.js';
import { withSendToSessionLock } from '../sendToSessionLock.js';
import { createOrcaRemoteWorkerHost, type OrcaRemoteWorkerExistingSession } from '../orcaRemoteWorkerHost.js';
+import { orcaModelDiscoveryFailure } from '../orcaServiceFailure.js';
const store = vi.hoisted(() => ({
archiveSingleWorkerSession: vi.fn(async () => undefined),
@@ -157,6 +158,21 @@ describe('invokeDeviceValue', () => {
});
describe('execution devices', () => {
+ // PR #6787, unit: the roster still says online, then the real model invoke
+ // disconnects. Verify readModels plus the host mapper's public failure result;
+ // existing offline-open coverage never exercised discovery after the roster.
+ it('reports an execution computer that disconnects during model discovery', async () => {
+ const { workers, remoteInvoke } = setup({ handle: (_device, channel) =>
+ channel === 'maker:orca:remote-worker:models' ? fail('DEVICE_OFFLINE', 'work computer disconnected') : undefined });
+ try {
+ const result = await workers.readModels('mac-mini', { agent: 'codex' })
+ .catch(error => orcaModelDiscoveryFailure(error, true));
+ expect(result).toEqual({ ok: false, errorCode: 'REMOTE_AGENT_DEVICE_UNREACHABLE',
+ message: '[DEVICE_OFFLINE] work computer disconnected' });
+ expect(remoteInvoke.mock.calls.map(([, channel]) => channel)).toEqual(['maker:orca:remote-worker:models']);
+ } finally { workers.stop(); }
+ });
+
it('only offers other online desktops that allow remote control', () => {
expect(isExecutionDeviceCandidate(device({}))).toBe(true);
expect(isExecutionDeviceCandidate(device({ online: false }))).toBe(false);
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/orcaServiceFailure.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/orcaServiceFailure.test.ts
index b8601bdbec..0480fa4d97 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/orcaServiceFailure.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/orcaServiceFailure.test.ts
@@ -1,6 +1,38 @@
import { describe, expect, it } from 'vitest';
-import { throwOrcaServiceFailure } from '../orcaServiceFailure';
+import { orcaModelDiscoveryFailure, throwOrcaServiceFailure } from '../orcaServiceFailure';
+
+describe('Orca model discovery failure mapping', () => {
+ // PR #6787, unit: the production host response mapper must keep discovery
+ // failures actionable for list_available_models. Existing tests covered only
+ // creation/IPC throwing; an online work computer disconnecting during its
+ // model read or a not-yet-ready host instead became INTERNAL.
+ it.each([
+ ['DEVICE_OFFLINE', 'REMOTE_AGENT_DEVICE_UNREACHABLE'],
+ ['INVOKE_TIMEOUT', 'REMOTE_AGENT_DEVICE_UNREACHABLE'],
+ ['DEVICE_UNRESPONSIVE', 'REMOTE_AGENT_DEVICE_UNREACHABLE'],
+ ['LINK_NOT_OPEN', 'REMOTE_AGENT_DEVICE_UNREACHABLE'],
+ ['NOT_CONNECTED', 'REMOTE_AGENT_DEVICE_UNREACHABLE'],
+ ['PEER_RESET', 'REMOTE_AGENT_DEVICE_UNREACHABLE'],
+ ['BACKPRESSURE', 'REMOTE_AGENT_DEVICE_UNREACHABLE'],
+ ['HOST_NOT_READY', 'HOST_NOT_READY'],
+ ['UNSUPPORTED_CAPABILITY', 'UNSUPPORTED_CAPABILITY'],
+ ['REMOTE_AGENT_SHARE_PAUSED', 'REMOTE_AGENT_SHARE_PAUSED'],
+ ['ACCESS_REVOKED', 'INTERNAL'],
+ ['INVALID_PARAMS', 'INTERNAL'],
+ ])('maps execution-device discovery %s to %s', (code, expected) => {
+ const message = `[${code}] model discovery failed`;
+ expect(orcaModelDiscoveryFailure(new Error(message), true))
+ .toEqual({ ok: false, errorCode: expected, message });
+ });
+
+ it('keeps local and unclassified discovery failures internal', () => {
+ expect(orcaModelDiscoveryFailure(new Error('[DEVICE_OFFLINE] local read failed'), false))
+ .toEqual({ ok: false, errorCode: 'INTERNAL', message: '[DEVICE_OFFLINE] local read failed' });
+ expect(orcaModelDiscoveryFailure('model read failed', true))
+ .toEqual({ ok: false, errorCode: 'INTERNAL', message: 'model read failed' });
+ });
+});
describe('orca service failure IPC mapping', () => {
it('maps Orca BUSY failures to SESSION_RUNNING instead of INTERNAL', () => {
diff --git a/apps/desktop/src/main/maker-ipc/orcaServiceFailure.ts b/apps/desktop/src/main/maker-ipc/orcaServiceFailure.ts
index 19fa2147e9..e1009962ce 100644
--- a/apps/desktop/src/main/maker-ipc/orcaServiceFailure.ts
+++ b/apps/desktop/src/main/maker-ipc/orcaServiceFailure.ts
@@ -1,5 +1,24 @@
import { throwIpcError } from '../utils/ipcValidate.js';
+const MODEL_DISCOVERY_CONNECTION_ERRORS = new Set([
+ 'DEVICE_OFFLINE', 'DEVICE_UNRESPONSIVE', 'INVOKE_TIMEOUT', 'LINK_NOT_OPEN',
+ 'NOT_CONNECTED', 'PEER_RESET', 'BACKPRESSURE',
+]);
+
+/** list_available_models 的宿主错误转换;位置发现失败仍需返回结构化原因。 */
+export function orcaModelDiscoveryFailure(err: unknown, executionDevice: boolean): {
+ ok: false; errorCode: string; message: string;
+} {
+ const message = err instanceof Error ? err.message : String(err);
+ const code = /^\[([A-Z_]+)\]/.exec(message)?.[1];
+ let errorCode = 'INTERNAL';
+ if (executionDevice && code) {
+ if (MODEL_DISCOVERY_CONNECTION_ERRORS.has(code)) errorCode = 'REMOTE_AGENT_DEVICE_UNREACHABLE';
+ else if (code === 'HOST_NOT_READY' || code === 'UNSUPPORTED_CAPABILITY' || code.startsWith('REMOTE_AGENT_')) errorCode = code;
+ }
+ return { ok: false, errorCode, message };
+}
+
/** Orca service result 到 IPC 错误协议的统一翻译,避免不同 handler 的错误码漂移。 */
export function throwOrcaServiceFailure(result: { ok: false; errorCode: string; message: string }): never {
switch (result.errorCode) {
diff --git a/apps/desktop/src/main/maker-ipc/register.ts b/apps/desktop/src/main/maker-ipc/register.ts
index b7e9d755d9..dad4f08f3a 100644
--- a/apps/desktop/src/main/maker-ipc/register.ts
+++ b/apps/desktop/src/main/maker-ipc/register.ts
@@ -965,7 +965,7 @@ import {
createOrcaUiAssignmentDispatchClaims,
createOrcaUiAssignmentHistoryGate,
} from './orcaUiAssignmentHistoryGate.js';
-import { throwOrcaServiceFailure } from './orcaServiceFailure.js';
+import { orcaModelDiscoveryFailure, throwOrcaServiceFailure } from './orcaServiceFailure.js';
import {
createOrcaTeamService,
findFocusTargetWorker,
@@ -17017,14 +17017,7 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
}
return { ok: true, agentDeviceId: null, ...(locations ? { locations } : {}), ...result };
} catch (err) {
- const message = err instanceof Error ? err.message : String(err);
- const code = /^\[([A-Z_]+)\]/.exec(message)?.[1];
- return {
- ok: false,
- errorCode: executionDeviceId && code && (code === 'UNSUPPORTED_CAPABILITY' || code.startsWith('REMOTE_AGENT_'))
- ? code : 'INTERNAL',
- message,
- };
+ return orcaModelDiscoveryFailure(err, Boolean(executionDeviceId));
}
},
};