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。

merge: sync main and preserve scheduled harness switching

Yuewei-LLc920e734cbb0
diff --cc apps/desktop/src/main/maker-ipc/__tests__/scheduledModelSelection.test.ts
index a1812d5c06,e5b7ceb2c5..dfd0a4531a
--- a/apps/desktop/src/main/maker-ipc/__tests__/scheduledModelSelection.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/scheduledModelSelection.test.ts
@@@ -295,6 -247,37 +295,44 @@@ describe('bound target Harness capabili
expect(() => assertScheduledHarnessSupported(target, undefined)).not.toThrow();
},
);
+ // Regression: ordinary Orca switching supports all three Harnesses, but the
+ // scheduled guard blocked both the override and the next manual send's restore.
- // Unit tier: enter a persisted scope, switch, reload it and restore via the real
- // selection entry; the old guard fails before any model can be applied.
- it.each(['lead', 'worker'])('applies and restores a cross-Harness override for an Orca %s', async (orcaRole) => {
- let profile: ScheduledModelSelection = { ...selection, agentKind: 'codex', model: 'owner-model' };
++ // Merge regression, unit: also move the Agent with/without an engine change.
++ // Prior tests covered only Harness changes and could miss a location-only veto.
++ // The real scope/selection entries must restore both persisted axes after reload.
++ it.each([
++ { orcaRole: 'lead', agentKind: 'pi' as const },
++ { orcaRole: 'worker', agentKind: 'pi' as const },
++ { orcaRole: 'lead', agentKind: 'codex' as const },
++ { orcaRole: 'worker', agentKind: 'codex' as const },
++ ])('applies and restores a $agentKind override for an Orca $orcaRole across locations', async ({ orcaRole, agentKind }) => {
++ let profile: ScheduledModelSelection = { ...selection, agentKind: 'codex', agentDeviceId: null, model: 'owner-model' };
++ const override: ScheduledModelSelection = { ...selection, agentKind, agentDeviceId: 'shared:automation' };
+ const original = { ...profile };
+ let baseline: string | null = null;
+ const apply = async (_id: string, choice: ScheduledModelSelection) => {
+ await applyScheduledModelSelection(choice, {
- getTarget: async () => ({ agentKind: profile.agentKind, status: 'active', orcaRole }),
++ getTarget: async () => ({ agentKind: profile.agentKind, agentDeviceId: profile.agentDeviceId, status: 'active', orcaRole }),
+ isBusy: () => false,
+ resolveSelection: async (value) => value,
- switchHarness: async (value) => { profile = { ...profile, agentKind: value.agentKind }; return { engineReady: true }; },
++ switchHarness: async (value) => { profile = { ...profile, agentKind: value.agentKind, agentDeviceId: value.agentDeviceId }; return { engineReady: true }; },
+ applyModel: async (value) => { profile = { ...value }; },
+ });
+ };
+ const deps = {
+ createId: () => 'scope', isBusy: () => false,
+ read: async () => ({ profile, baseline }),
+ write: async (_id: string, value: unknown) => { baseline = value ? JSON.stringify(value) : null; },
+ apply,
+ };
+ expect(() => assertScheduledHarnessSupported({ agentKind: 'codex', status: 'active', orcaRole }, 'pi')).not.toThrow();
+ await createScheduledModelScope(deps).begin('task');
- await apply('task', selection);
- expect(profile).toEqual(selection);
++ await apply('task', override);
++ expect(profile).toEqual(override);
+ await createScheduledModelScope(deps).restore('task');
+ expect(profile).toMatchObject(original);
+ expect(baseline).toBeNull();
+ });
it('preserves ordinary local cross-Harness selection and archived-target recovery', () => {
expect(() => assertScheduledHarnessSupported({ agentKind: 'codex', status: 'active' }, 'pi')).not.toThrow();
expect(() => assertScheduledHarnessSupported({ agentKind: 'codex', status: 'archived', remoteHostId: 'ssh-host' }, 'pi')).not.toThrow();
diff --cc apps/desktop/src/main/maker-ipc/__tests__/sessionAgentSwitchHandler.test.ts
index 5e4e8f48e6,210437c165..feb734d66a
--- a/apps/desktop/src/main/maker-ipc/__tests__/sessionAgentSwitchHandler.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/sessionAgentSwitchHandler.test.ts
@@@ -17,6 -17,6 +17,7 @@@ import { MAKER_INVOKE } from '../channe
import { remoteAgentLinkError } from '../../remote-agent/controller/runClient';
import { IpcHarness } from './helpers/ipcHarness';
import { runDeviceLinkInvokeContext } from '../../device-link/invoke-context';
++import { applyScheduledModelSelection, type ScheduledModelSelection } from '../scheduledModelSelection';
function makeRow(overrides: Partial<AgentSwitchSessionRow> = {}): AgentSwitchSessionRow {
return {
@@@ -1530,6 -1530,6 +1531,39 @@@ describe('远程 Agent:选模型时换
expect(staged.calls).toEqual([]);
});
++ // PR #6830 merge regression, unit: the scheduled entry materialized inherited
++ // null and turned a same-computer Harness switch into a forbidden Worker move.
++ // Earlier tests entered the handoff directly. Exercise both production entries;
++ // an actual location change must still fail before runtime or database mutation.
++ it.each([undefined, null, 'office-pc'])('scheduled execution-device Worker keeps its location boundary: %j', async (agentDeviceId) => {
++ const h = relocationHarness({ agentDeviceId: null, orcaRole: null,
++ orcaRemoteLead: JSON.stringify({ leadDeviceId: 'lead-device', leadSessionId: 'lead-1', workerLabel: 'worker' }),
++ });
++ const choice: ScheduledModelSelection = { agentKind: 'codex', agentDeviceId,
++ model: 'gpt-5.5', providerId: 'openai', effort: null, fastMode: false };
++ const applyModel = vi.fn(async () => {});
++ const result = applyScheduledModelSelection(choice, {
++ getTarget: async () => ({ agentKind: 'claude-code', agentDeviceId: null, status: 'active' }),
++ isBusy: () => false,
++ resolveSelection: async (value) => value,
++ switchHarness: (value) => performSessionAgentSwitch({ ...h.deps, pendingSwitches: undefined }, {
++ sessionId: 's1', targetAgentKind: value.agentKind, model: value.model,
++ agentDeviceId: value.agentDeviceId, providerId: value.providerId,
++ effort: value.effort, fastMode: value.fastMode, applyNow: true, configStaged: true,
++ }),
++ applyModel,
++ });
++ if (agentDeviceId) {
++ await expect(result).rejects.toThrow(/UNSUPPORTED_CAPABILITY/);
++ expect(h.calls).toEqual([]);
++ expect(applyModel).not.toHaveBeenCalled();
++ } else {
++ await expect(result).resolves.toMatchObject({ agentKind: 'codex', agentDeviceId: null });
++ expect(h.deps.applyAgentSwitchToDb).toHaveBeenCalledWith('s1', expect.objectContaining({ agentKind: 'codex' }));
++ expect(applyModel).toHaveBeenCalledWith(expect.objectContaining({ agentKind: 'codex', agentDeviceId: null }));
++ }
++ });
++
it('协同 Lead 离开远程电脑:关闭旧远程会话遇链路错误仍提交新位置', async () => {
const linkError = Object.assign(
new Error('[REMOTE_AGENT_UNAVAILABLE] [DEVICE_LINK_DEVICE_OFFLINE] target offline'),
diff --cc apps/desktop/src/main/maker-ipc/scheduledModelSelection.ts
index 70ecf1b314,5652e90244..a11d702ee9
--- a/apps/desktop/src/main/maker-ipc/scheduledModelSelection.ts
+++ b/apps/desktop/src/main/maker-ipc/scheduledModelSelection.ts
@@@ -85,14 -75,12 +86,16 @@@ interface ScheduledModelTarget
export function assertScheduledHarnessSupported(
target: ScheduledModelTarget | null,
agentKind: AgentKind | undefined,
+ agentDeviceId?: string | null,
): void {
- if (target?.status !== 'active' || !agentKind || target.agentKind === agentKind) return;
- // Orca Lead/Worker use the ordinary handoff transaction, including restoration
- // before the next manual send. Only SSH still lacks cross-Harness handoff.
+ if (target?.status !== 'active') return;
+ const changesHarness = agentKind && target.agentKind !== agentKind;
+ const changesDevice = agentDeviceId !== undefined && agentDeviceId !== (target.agentDeviceId ?? null);
+ if (!changesHarness && !changesDevice) return;
- if (target.remoteHostId || target.orcaRole) {
- throw new Error('SSH and Orca automation targets must keep their current Harness');
++ // Ordinary Orca Lead/Worker use the existing handoff for both axes, including
++ // restoration before the next manual send. SSH still cannot change either.
+ if (target.remoteHostId) {
+ throwIpcError('SSH_HARNESS_SWITCH_UNSUPPORTED', 'SSH automation targets must keep their current Harness');
}
}
@@@ -136,14 -124,11 +139,18 @@@ export async function applyScheduledMod
return selection;
}
if (deps.isBusy()) throw new ScheduledModelSelectionBusyError('Scheduled model selection waits for the current turn');
- assertScheduledHarnessSupported(target, selection.agentKind);
- const resolved = await deps.resolveSelection(selection);
- if (target.agentKind !== resolved.agentKind) {
- const result = await deps.switchHarness(resolved);
+ assertScheduledHarnessSupported(target, selection.agentKind, selection.agentDeviceId);
+ const resolved = await deps.resolveSelection({ ...selection,
+ ...(selection.agentDeviceId === undefined && target.agentDeviceId !== undefined
+ ? { agentDeviceId: target.agentDeviceId } : {}),
+ });
- if (target.agentKind !== resolved.agentKind || (target.agentDeviceId ?? null) !== (resolved.agentDeviceId ?? null)) {
- const result = await deps.switchHarness(resolved);
- if (!result.engineReady || result.retryPending) throw new Error('Scheduled Harness switch did not become ready');
++ const changesDevice = (target.agentDeviceId ?? null) !== (resolved.agentDeviceId ?? null);
++ if (target.agentKind !== resolved.agentKind || changesDevice) {
++ // The handoff treats an explicit location as a relocation request. Preserve
++ // engine-only switching for execution-device Workers without relaxing that boundary.
++ const { agentDeviceId: _location, ...harnessSelection } = resolved;
++ const result = await deps.switchHarness(changesDevice ? resolved : harnessSelection);
+ if (!result.engineReady || result.retryPending) throwIpcError('HARNESS_SWITCH_NOT_READY', 'Scheduled Harness switch did not become ready');
}
await deps.applyModel(resolved);
return resolved;
diff --cc apps/desktop/src/renderer/features/scheduler/components/ScheduleFormDialog.tsx
index e6d41435b7,fd1a4dede2..bf74cf1c3e
--- a/apps/desktop/src/renderer/features/scheduler/components/ScheduleFormDialog.tsx
+++ b/apps/desktop/src/renderer/features/scheduler/components/ScheduleFormDialog.tsx
@@@ -158,9 -157,21 +159,21 @@@ export function ScheduleFormDialog(
const deviceProviders = useDeviceProviders(selectedAgentDeviceId ?? undefined);
const { providers, loading: providersLoading } = selectedAgentDeviceId ? deviceProviders : localProviders;
// Do not calibrate saved choices against a provisional local or loading snapshot.
- const modelCatalogReady = (!isBound || !!boundSessionReference) && !caps.loading && !providersLoading;
+ const modelCatalogReady = (!isBound || form.modelAgentDeviceId !== undefined || !!boundSessionReference) && !caps.loading && !providersLoading;
const hideWorkspaceFields = runMode === 'bound' || isBound;
const [submitting, setSubmitting] = useState(false);
+ const [submitError, setSubmitError] = useState<string | null>(null);
+ useEffect(() => { setSubmitError(null); }, [open, initial]);
+ const showSubmitError = (error: unknown) => {
+ const message = error instanceof Error ? error.message : String(error);
+ const code = parseAgentErrorCode(message)?.code;
+ if (code && i18n.exists(`chat.remoteError.${code}`)) {
+ setSubmitError(message);
+ // Save may be below the notice in a scrolled form. The shared alert toast
+ // stays visible above the dialog and announces the localized failure.
+ toast.error(t(`chat.remoteError.${code}`));
+ } else toast.error(message);
+ };
const [mode, setMode] = useState<'gallery' | 'form'>('form');
// 前置检查「测试运行」状态:结果只在弹窗内展示,不落任何记录。
const [hookTesting, setHookTesting] = useState(false);