Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(remote-agent): 分叉新错误码按能力协商,组内电脑缺 Agent 时对受邀者中性化
david27dc03185636
diff --git a/apps/desktop/src/main/remote-agent/__tests__/groupRelay.test.ts b/apps/desktop/src/main/remote-agent/__tests__/groupRelay.test.tsindex 14ad23fc76..941173b501 100644--- a/apps/desktop/src/main/remote-agent/__tests__/groupRelay.test.ts+++ b/apps/desktop/src/main/remote-agent/__tests__/groupRelay.test.ts@@ -205,7 +205,8 @@ function setup(options: {miniCapable?: boolean;switchWorthy?: (failure: RelayRunFailure) => boolean;/** mini 这台的 Agent 表现。 */- mini?: { failStart?: boolean; endImmediately?: boolean };+ mini?: { failStart?: boolean; endImmediately?: boolean;+ isAgentAvailable?: Parameters<typeof createRemoteAgentHost>[0]['isAgentAvailable'] };memberBinder?: Parameters<typeof createRemoteAgentHost>[0]['bindGuestProviderRoute'];/** 组所在电脑本机的 Agent 表现(组选中本机这一台时)。 */owner?: { failStart?: boolean; prepareImageEvent?: Parameters<typeof createRemoteAgentHost>[0]['prepareImageEvent'];@@ -449,6 +450,18 @@ describe('provider group relay for shared users', () => {expect(env.relay.plan).toHaveBeenCalledTimes(1);await resumed.client.close('close', 'navigation');});+ // The guest cannot see or fix the member computer: a member whose agent went away+ // before the fork must surface as the neutral unavailable error, not "install it there".+ it('masks a member whose agent became unavailable before a guest fork', async () => {+ let available = true;+ const env = setup({ mini: { isAgentAvailable: () => available } });+ const first = await openAsGuest(env, GUEST_A, openPayload(SESSION));+ await first.client.close('close', 'navigation');+ available = false;+ await expect(env.owner.handle(GUEST_A, { op: 'fork', sourceSessionId: SESSION, newSessionId: 'child-task',+ agentKind: 'claude-code', sourceSdkSessionId: first.started.id, model: 'claude-opus', upToMessageId: 'old',+ acceptsForkFailed: true })).rejects.toThrow(/^\[REMOTE_AGENT_UNAVAILABLE\]/);+ });it('hands a shared user’s new task to the chosen computer, which runs it isolated as a shared user', async () => {const env = setup();const { client, started } = await openAsGuest(env, GUEST_A, openPayload(SESSION));diff --git a/apps/desktop/src/main/remote-agent/__tests__/groupRelayClaudeFork.e2e.test.ts b/apps/desktop/src/main/remote-agent/__tests__/groupRelayClaudeFork.e2e.test.tsindex 195cab9f0b..bf51f3cad7 100644--- a/apps/desktop/src/main/remote-agent/__tests__/groupRelayClaudeFork.e2e.test.ts+++ b/apps/desktop/src/main/remote-agent/__tests__/groupRelayClaudeFork.e2e.test.ts@@ -181,9 +181,10 @@ describe.skipIf(!available)('a shared user forks a real Claude Code task throughconst anchor = events.filter((event) => event.type === 'text').map((event) => event.agentMeta?.uuid).find((uuid): uuid is string => typeof uuid === 'string');expect(anchor).toBeDefined();- const fork = (upToMessageId: string, newSessionId: string) => owner.handle(GUEST, roundTrip({+ const fork = (upToMessageId: string, newSessionId: string, acceptsForkFailed = true) => owner.handle(GUEST, roundTrip({op: 'fork', sourceSessionId: 'guest-task', newSessionId, agentKind: 'claude-code',sourceSdkSessionId: started.id, model: MODEL, upToMessageId,+ ...(acceptsForkFailed ? { acceptsForkFailed: true } : {}),}));await expect(fork(anchor!, 'guest-child')).resolves.toMatchObject({ newSdkSessionId: expect.any(String) });@@ -200,6 +201,10 @@ describe.skipIf(!available)('a shared user forks a real Claude Code task throughmsg: 'remote agent: a computer in the provider group could not fork the shared task',data: expect.objectContaining({ error: expect.objectContaining({ code: 'REMOTE_AGENT_FORK_FAILED' }) }),})]);++ // 不认识新错误码的旧受邀者(分叉请求不带 acceptsForkFailed)照旧收到「暂时不可用」。+ const legacy = await fork(missing, 'guest-child-3', false).then(() => null, (error: unknown) => error as Error);+ expect(legacy?.message).toMatch(/^\[REMOTE_AGENT_UNAVAILABLE\]/);} finally {for (const host of [owner, member]) { await host.abortAll(); host.dispose(); }}diff --git a/apps/desktop/src/main/remote-agent/controller/fork.ts b/apps/desktop/src/main/remote-agent/controller/fork.tsindex 7fadb1bde9..81ff8c40e7 100644--- a/apps/desktop/src/main/remote-agent/controller/fork.ts+++ b/apps/desktop/src/main/remote-agent/controller/fork.ts@@ -12,6 +12,7 @@ export async function forkRemoteAgentSession(if (!caps.nativeFork) {throw new Error('[REMOTE_AGENT_PEER_TOO_OLD] Update Cindy on the computer running this task to fork it.');}- const result = parseRemoteAgentForkResult(await invoke([{ op: 'fork', ...request }]));+ // 本端有 REMOTE_AGENT_FORK_FAILED 的文案;不声明的旧控制端由被控端回原来的 UNAVAILABLE。+ const result = parseRemoteAgentForkResult(await invoke([{ op: 'fork', ...request, acceptsForkFailed: true }]));return { ...result, uuidMap: new Map(result.uuidMap) };}diff --git a/apps/desktop/src/main/remote-agent/host/runHost.ts b/apps/desktop/src/main/remote-agent/host/runHost.tsindex 5ad70809d5..6b0c867750 100644--- a/apps/desktop/src/main/remote-agent/host/runHost.ts+++ b/apps/desktop/src/main/remote-agent/host/runHost.ts@@ -2409,6 +2409,8 @@ export function createRemoteAgentHost(deps: RemoteAgentHostDeps) {fail('REMOTE_AGENT_PEER_TOO_OLD', 'update Cindy on the computer running this task to fork it');}if (!deps.isAgentAvailable(request.agentKind)) {+ // 经供应商组转来的受邀者看不到组内电脑,也装不了它的 Agent:回位置类错误,组所在电脑(含旧版)统一成「暂时不可用」。+ if (request.relay) fail('REMOTE_AGENT_UNAVAILABLE', 'the computer running this task is not available right now');fail('REMOTE_AGENT_UNSUPPORTED', 'this agent is not available on the computer running this task');}const workingDir = path.join(shadowSessionRoot(controller, hostSessionId), 'fs', 'workspace', ...Array.from({ length: MAX_ANCESTOR_LEVELS }, () => 'p'));@@ -2437,8 +2439,10 @@ export function createRemoteAgentHost(deps: RemoteAgentHostDeps) {error: remoteAgentErrorInfo(error),});// 包在 Agent 报错里的远程 Agent 码(如 CodexForkError 的 cause)保留下来,正文换成中性说明。+ // 新错误码只回给声明认识它的控制端(provider-groups.md §14),旧控制端照旧收到 UNAVAILABLE。const nested = error instanceof Error ? remoteAgentErrorCode(error.message) : null;- fail(nested ?? 'REMOTE_AGENT_FORK_FAILED', 'the conversation could not be forked on the computer running this task');+ fail(nested ?? (request.acceptsForkFailed ? 'REMOTE_AGENT_FORK_FAILED' : 'REMOTE_AGENT_UNAVAILABLE'),+ 'the conversation could not be forked on the computer running this task');}});result = {diff --git a/docs/dev-rules/protocol-compatibility.md b/docs/dev-rules/protocol-compatibility.mdindex 6293921538..e76c2baffb 100644--- a/docs/dev-rules/protocol-compatibility.md+++ b/docs/dev-rules/protocol-compatibility.md@@ -1290,6 +1290,13 @@ handler 无 sender 依赖;不加入共享任务访客白名单,不进入自重建只决定原生会话能否复用,不把子任务改送到当前设备。Desktop 与 Mobile 沿用 `maker:fork`;共享任务访客与 SSH 工作区的现有边界不变。+运行端上 Agent 原生分叉失败时回 `REMOTE_AGENT_FORK_FAILED`(原始原因只记运行端日志),但只回给+`op: fork` 带了可选 `acceptsForkFailed: true` 的控制端;组所在电脑转发时原样带上受邀者的声明,旧控制端+不带、旧运行端忽略,照旧得到 `REMOTE_AGENT_UNAVAILABLE`。经供应商组转来的请求在组内电脑缺 Agent 时回+`REMOTE_AGENT_UNAVAILABLE`(位置类,组所在电脑统一成「暂时不可用」),直接调用方仍得到 `REMOTE_AGENT_UNSUPPORTED`。+实现见 `apps/desktop/src/main/remote-agent/host/runHost.ts` 与 `controller/fork.ts`,回归见+`groupRelay.test.ts`、`groupRelayClaudeFork.e2e.test.ts`。+运行端按已认证调用方复核供应商权限;受邀者及转分享还必须拥有来源原生会话。存储目录由运行端派生,不接受调用方传入路径。Claude 返回消息 UUID 映射,Codex/Pi 在受邀者原有隔离目录分叉;新原生会话登记到既有归属索引,支持继续分叉和恢复。diff --git a/packages/device-link/src/__tests__/remoteAgent.test.ts b/packages/device-link/src/__tests__/remoteAgent.test.tsindex 57b9596764..3917526aec 100644--- a/packages/device-link/src/__tests__/remoteAgent.test.ts+++ b/packages/device-link/src/__tests__/remoteAgent.test.ts@@ -46,6 +46,9 @@ describe('remote agent channel', () => {const request = { op: 'fork', sourceSessionId: 'g123', newSessionId: otherId,agentKind: 'pi', sourceSdkSessionId: '/guest/pi-sessions/source.jsonl', model: 'model' };expect(parseRemoteAgentRequest({ ...request, hostedGuestHome: '/owner', workingDir: '/owner' })).toEqual(request);+ // The FORK_FAILED opt-in survives the group relay hop only as an explicit `true`.+ expect(parseRemoteAgentRequest({ ...request, acceptsForkFailed: true })).toEqual({ ...request, acceptsForkFailed: true });+ expect(parseRemoteAgentRequest({ ...request, acceptsForkFailed: 'yes' })).toEqual(request);expect(() => parseRemoteAgentRequest({ ...request, sourceSessionId: '../owner' })).toThrow();expect(() => parseRemoteAgentRequest({ ...request, tailTurnsToDrop: -1 })).toThrow();expect(isRemoteAgentReadInvoke(REMOTE_AGENT_CHANNEL, [request])).toBe(false);diff --git a/packages/device-link/src/remoteAgent.ts b/packages/device-link/src/remoteAgent.tsindex 0de88fa84f..00c092dbb6 100644--- a/packages/device-link/src/remoteAgent.ts+++ b/packages/device-link/src/remoteAgent.ts@@ -89,7 +89,8 @@ export const REMOTE_AGENT_ERROR_CODES = ['REMOTE_AGENT_PROVIDER_NOT_ALLOWED',// 供应商组转来的受邀者任务:这台电脑的主人没有同意这个受邀者经组使用(只回给打开时带了 reshareKey 的组所在电脑)。'REMOTE_AGENT_RESHARE_NOT_ALLOWED',- // 那台电脑上的 Agent 分叉原生历史失败(电脑本身在线)。旧版控制端不认识,按通用分叉失败提示。+ // 那台电脑上的 Agent 分叉原生历史失败(电脑本身在线)。只回给分叉请求带了 acceptsForkFailed 的控制端,+ // 旧控制端照旧收到 REMOTE_AGENT_UNAVAILABLE。'REMOTE_AGENT_FORK_FAILED',] as const;export type RemoteAgentErrorCode = (typeof REMOTE_AGENT_ERROR_CODES)[number];@@ -256,6 +257,8 @@ export interface RemoteAgentForkRequest {forkAtTimestampMs?: number;relay?: string;reshareKey?: string;+ /** 控制端认识 REMOTE_AGENT_FORK_FAILED。组所在电脑转发时原样带上受邀者的声明;旧被控端忽略。 */+ acceptsForkFailed?: true;}export interface RemoteAgentForkResult {@@ -485,6 +488,7 @@ export function parseRemoteAgentRequest(value: unknown): RemoteAgentRequest {}if (v.tailTurnsToDrop !== undefined) result.tailTurnsToDrop = count(v.tailTurnsToDrop, Number.MAX_SAFE_INTEGER);if (v.forkAtTimestampMs !== undefined) result.forkAtTimestampMs = count(v.forkAtTimestampMs, Number.MAX_SAFE_INTEGER);+ if (v.acceptsForkFailed === true) result.acceptsForkFailed = true;if (result.sourceSessionId === result.newSessionId) invalid();return { op: 'fork', ...result };}