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): 修复手机 Worker 切换 Agent 后的记忆与旧宿主提交

fmfsaisai1c78f63aa242
diff --git a/apps/mobile/src/__tests__/useOrcaWorkerForm.test.tsx b/apps/mobile/src/__tests__/useOrcaWorkerForm.test.tsx
index 99a5348232..8c467c43ab 100644
--- a/apps/mobile/src/__tests__/useOrcaWorkerForm.test.tsx
+++ b/apps/mobile/src/__tests__/useOrcaWorkerForm.test.tsx
@@ -164,6 +164,52 @@ it.each(['agent-pc', 'share:s1', null])('remembers the submitted model route ind
}
});
+// PR #6453:完整路线恢复优先于 lastAgent;切 Agent 后成功提交不能再次恢复旧 Agent。
+// unit:已有用例未覆盖 select → remember → changeAgent → remember → reset 的连续操作;
+// 分别覆盖有效旧模型、收敛成默认模型,以及不能写进本机逐 Agent 槽的远程目录。
+it.each([
+ { location: null, remembered: 'pi-model', expected: 'pi-model' },
+ { location: null, remembered: 'retired', expected: null },
+ { location: 'agent-pc', remembered: 'pi-model', expected: null },
+])('replaces the saved Agent only after submitting an Agent switch ($location, $remembered)', async ({ location, remembered, expected }) => {
+ const maker = fakeMaker();
+ const defaults = defaultOrcaWorkerCreationPrefs();
+ const otherHostSelection = { agent: 'codex' as const, agentDeviceId: 'other-pc', model: { id: 'other-model', providerId: 'other-provider', effort: 'high', fast: false } };
+ saveOrcaWorkerCreationPrefs('user-1', {
+ ...defaults,
+ modelSelectionByHost: { 'host-b': otherHostSelection },
+ agents: { ...defaults.agents, pi: { model: remembered, effort: 'high', fast: false } },
+ });
+ await act(async () => { root.render(<LocationProbe maker={maker} lead={location} selectable />); await flush(); });
+ await act(async () => { latest!.reset(); await flush(); });
+ await act(async () => { await latest!.modelPicker.select(
+ { agent: 'codex', modelId: 'codex/gpt-5.5', providerId: 'chosen-provider', effort: 'high', fast: true },
+ { deviceId: location },
+ ); });
+ await act(async () => { latest!.remember(latest!.form); await flush(); });
+ const original = (await readOrcaWorkerCreationPrefs('user-1')).modelSelectionByHost?.['host-a'];
+
+ await act(async () => { latest!.changeAgent('pi'); await flush(); });
+ expect(latest!.form.model?.id ?? null).toBe(expected);
+ // 没有成功提交时,仅关闭重开不能删除旧完整路线。
+ await act(async () => { latest!.reset(); await flush(); });
+ expect(latest!.form).toMatchObject({ agent: 'codex', agentDeviceId: location });
+ expect((await readOrcaWorkerCreationPrefs('user-1')).modelSelectionByHost?.['host-a']).toEqual(original);
+
+ await act(async () => { latest!.changeAgent('pi'); await flush(); });
+ expect(latest!.form.model?.id ?? null).toBe(expected);
+ await act(async () => { latest!.remember(latest!.form); await flush(); });
+ await act(async () => root.render(null));
+ resetOrcaWorkerCreationPrefsMemory();
+ await act(async () => { root.render(<LocationProbe maker={maker} lead={location} selectable />); await flush(); });
+ await act(async () => { latest!.reset(); await flush(); });
+ expect(latest!.form.agent).toBe('pi');
+ expect(latest!.form.model?.id ?? null).toBe(expected);
+ const saved = await readOrcaWorkerCreationPrefs('user-1');
+ expect(saved.agents.pi.model).toBe(remembered);
+ expect(saved.modelSelectionByHost?.['host-b']).toEqual(otherHostSelection);
+});
+
it('does not save cancelled picks or let a late saved route replace a new pick', async () => {
const AsyncStorage = (await import('@react-native-async-storage/async-storage')).default;
const maker = fakeMaker();
@@ -198,11 +244,23 @@ it('leaves the Worker location unset when the controlled computer cannot honor i
expect(latest!.form.model).toBeNull();
await act(async () => {
await latest!.modelPicker.select(
- { agent: 'codex', modelId: 'codex/gpt-5.5', providerId: 'xd', effort: 'high', fast: false },
+ { agent: 'codex', modelId: 'remote-only-model', providerId: 'xd', effort: 'high', fast: false },
{ deviceId: 'agent-pc' },
);
});
expect(latest!.form.agentDeviceId).toBeUndefined();
+ // PR #6453:旧端未指定位置表示跟随 Lead,选行不能把合法提交误禁用。
+ expect(latest!.valid).toBe(true);
+ await act(async () => { latest!.remember(latest!.form); await flush(); });
+ // 跟随远程 Lead 的模型不能写入本机旧槽,完整记忆仍需记录实际位置。
+ const prefs = await readOrcaWorkerCreationPrefs('user-1');
+ expect(prefs.agents.codex.model).toBe(defaultOrcaWorkerCreationPrefs().agents.codex.model);
+ expect(prefs.modelSelectionByHost?.['host-a']).toMatchObject({ agentDeviceId: 'agent-pc', model: { id: 'remote-only-model' } });
+ // 同一个远程 Lead 下,显式 null 是要求放在任务电脑,旧端不能兑现。
+ act(() => latest!.restore({ ...latest!.form, agentDeviceId: null }));
+ expect(latest!.valid).toBe(false);
+ act(() => latest!.restore({ ...latest!.form, agentDeviceId: 'agent-pc' }));
+ expect(latest!.valid).toBe(true);
});
it('keeps local Worker creation available on older Leads without the device-list channel', async () => {
diff --git a/apps/mobile/src/session/orcaWorkerPrefs.ts b/apps/mobile/src/session/orcaWorkerPrefs.ts
index b2bfa06e68..44a80c83d4 100644
--- a/apps/mobile/src/session/orcaWorkerPrefs.ts
+++ b/apps/mobile/src/session/orcaWorkerPrefs.ts
@@ -139,9 +139,10 @@ export function saveOrcaWorkerCreationPrefs(scope: string, prefs: OrcaWorkerCrea
export interface OrcaWorkerSubmittedChoice {
agent: OrcaWorkerAgentKind;
permissionMode: OrcaWorkerPermissionMode;
- /** 只有完整手动选择带 host;旧版逐 Agent 偏好仍可单独更新。 */
+ /** 普通任务的提交可更新该 host 的完整路线;SSH / 运行设备不传。 */
taskHostDeviceId?: string;
- selection?: OrcaWorkerModelSelection;
+ /** null = 本次提交改用逐 Agent 默认,删除该 host 的旧完整路线;缺省 = 不改。 */
+ selection?: OrcaWorkerModelSelection | null;
model: { id: string; effort: string | null; fast: boolean } | null;
}
@@ -150,11 +151,15 @@ export function mergeOrcaWorkerChoice(
previous: OrcaWorkerCreationPrefs,
submitted: OrcaWorkerSubmittedChoice,
): OrcaWorkerCreationPrefs {
+ let modelSelectionByHost = previous.modelSelectionByHost;
+ if (submitted.taskHostDeviceId && submitted.selection !== undefined) {
+ modelSelectionByHost = { ...modelSelectionByHost };
+ if (submitted.selection) modelSelectionByHost[submitted.taskHostDeviceId] = submitted.selection;
+ else delete modelSelectionByHost[submitted.taskHostDeviceId];
+ }
return {
...previous,
- ...(submitted.taskHostDeviceId && submitted.selection ? {
- modelSelectionByHost: { ...previous.modelSelectionByHost, [submitted.taskHostDeviceId]: submitted.selection },
- } : {}),
+ ...(modelSelectionByHost ? { modelSelectionByHost } : {}),
lastAgent: submitted.agent,
workerPermissionMode: submitted.permissionMode,
agents: submitted.model
diff --git a/apps/mobile/src/session/useSessionOrcaCollab.ts b/apps/mobile/src/session/useSessionOrcaCollab.ts
index fa2c8d385e..7b75f6f9be 100644
--- a/apps/mobile/src/session/useSessionOrcaCollab.ts
+++ b/apps/mobile/src/session/useSessionOrcaCollab.ts
@@ -549,13 +549,18 @@ export function useOrcaWorkerForm(params: {
/** 提交成功后写回记忆(与桌面一样只在提交时记);读—合并—写由 rememberOrcaWorkerChoice 一处完成。 */
const remember = useCallback((choice: OrcaWorkerFormValue) => {
if (prefsScopeRef.current !== prefsScope || hostRef.current !== taskHostDeviceId) return;
+ // 未指定位置时按 Lead 的实际位置记忆,不能把旧端跟随远程 Lead 的模型写进本机旧槽。
+ const agentDeviceId = choice.agentDeviceId === undefined ? leadAgentDeviceIdRef.current : choice.agentDeviceId;
// 完整路线按任务电脑隔离,运行设备与 SSH 不进入这份记忆。
const submitted = {
...choice,
- model: orcaWorkerAgentElsewhere(choice) || choice.executionDeviceId ? null : choice.model,
- ...(!sshRemote && taskHostDeviceId && choice.modelSelectionExplicit && choice.model && !choice.executionDeviceId ? {
+ model: agentDeviceId !== null || choice.executionDeviceId ? null : choice.model,
+ ...(!sshRemote && taskHostDeviceId && !choice.executionDeviceId ? {
taskHostDeviceId,
- selection: { agent: choice.agent, agentDeviceId: choice.agentDeviceId === undefined ? leadAgentDeviceIdRef.current : choice.agentDeviceId, model: choice.model },
+ // 切 Agent 自动带出的模型仍按目录收敛;成功提交后不能再恢复上一条完整路线。
+ selection: choice.modelSelectionExplicit && choice.model
+ ? { agent: choice.agent, agentDeviceId, model: choice.model }
+ : null,
} : {}),
};
prefsRef.current = mergeOrcaWorkerChoice(prefsRef.current, submitted);
@@ -665,7 +670,7 @@ export function useOrcaWorkerForm(params: {
pickerAgents,
valid: canSubmitOrcaWorkerForm(form, customRoleMode)
&& (!form.modelSelectionExplicit || params.agentLocationSelectable === true
- || (form.agentDeviceId ?? null) === (params.leadAgentDeviceId ?? null))
+ || form.agentDeviceId === undefined || form.agentDeviceId === (params.leadAgentDeviceId ?? null))
&& (!form.executionDeviceId || executionDevices.some((device) => device.deviceId === form.executionDeviceId && device.supported)),
/** 模型选择器是否列出远程供应商(被控电脑支持给 Worker 选 Agent 位置,且没选运行设备)。 */
agentLocationSelectable: params.agentLocationSelectable === true && !form.executionDeviceId,