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(desktop): reject disabled scheduled routes and reset inactive targets

ylliuuu66aeba47a87348
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/scheduledModelRemoteRoute.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/scheduledModelRemoteRoute.test.ts
index 7498ca744e..7dc3ac0baf 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/scheduledModelRemoteRoute.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/scheduledModelRemoteRoute.test.ts
@@ -32,7 +32,7 @@ function catalog(id: string): ProviderView[] {
id: 'test-model', efforts: ['low', 'high'], defaultEffort: 'low', supportsFastMode: false,
}] } }] as ProviderView[];
}
-function fixture(device: string | null = 'share:test') {
+function fixture(device: string | null = 'share:test', status = 'active') {
let current = { ...choice, agentDeviceId: device };
let baseline: string | null = JSON.stringify({ ...choice, scopeId: 'old-run' });
const local = catalog('openai');
@@ -52,7 +52,7 @@ function fixture(device: string | null = 'share:test') {
});
const apply = compile('scheduled', {
applyScheduledModelSelection, resolveScheduledModelSelection,
- agentSwitchDeps: { getSessionRow: async () => ({ ...current, status: 'active' }) },
+ agentSwitchDeps: { getSessionRow: async () => status === 'missing' ? null : ({ ...current, status }) },
dbToMakerAgentKind: (kind: string) => kind,
isSessionInTurn: () => false, maker: { getSession: () => undefined },
assertModelRouteUsable: guard, shouldApplyExclusiveProviderRerouteLive: () => false,
@@ -106,6 +106,38 @@ describe('automation restore uses the execution computer', () => {
expect(h.guard).not.toHaveBeenCalled();
expect(h.state().baseline).not.toBeNull();
});
+ it.each(['provider', 'model'] as const)('preserves the baseline when the remote %s is disabled after restart', async disabled => {
+ const h = fixture();
+ const before = h.state();
+ const views = catalog('openai-shared');
+ if (disabled === 'provider') views[0].suspended = true;
+ else views[0].models.codex![0].disabled = true;
+ h.remote.mockResolvedValueOnce(views);
+ await expect(h.scope.restore('task')).rejects.toThrow('unavailable');
+ expect(h.state()).toEqual(before);
+ expect(h.applyModel).not.toHaveBeenCalled();
+ expect(h.switchHarness).not.toHaveBeenCalled();
+ expect(h.guard).not.toHaveBeenCalled();
+ });
+ it.each(['archived', 'deleted', 'missing'])('resolves the replacement locally for a %s target', async status => {
+ const h = fixture('share:test', status);
+ const before = h.state();
+ h.remote.mockRejectedValue(new Error('REMOTE_AGENT_SHARE_PAUSED'));
+ const localChoice = { ...choice, providerId: 'openai' };
+ await expect(h.deps.apply('task', localChoice)).resolves.toEqual(localChoice);
+ expect(h.remote).not.toHaveBeenCalled();
+ expect(h.guard).toHaveBeenCalledWith('codex', 'test-model', 'openai');
+ expect(h.applyModel).not.toHaveBeenCalled();
+ expect(h.switchHarness).not.toHaveBeenCalled();
+ expect(h.state()).toEqual(before);
+ });
+ it.each(['archived', 'deleted'])('rejects a remote-only source for the local replacement of a %s target', async status => {
+ const h = fixture('share:test', status);
+ await expect(h.deps.apply('task', choice)).rejects.toThrow('provider unavailable');
+ expect(h.remote).not.toHaveBeenCalled();
+ expect(h.applyModel).not.toHaveBeenCalled();
+ expect(h.switchHarness).not.toHaveBeenCalled();
+ });
it('retains the scope and task when the sharing host rejects access', async () => {
const h = fixture();
h.remote.mockRejectedValueOnce(new Error('REMOTE_AGENT_SHARE_PAUSED'));
diff --git a/apps/desktop/src/main/maker-ipc/scheduledModelSelection.ts b/apps/desktop/src/main/maker-ipc/scheduledModelSelection.ts
index f18989297e..dce562d73a 100644
--- a/apps/desktop/src/main/maker-ipc/scheduledModelSelection.ts
+++ b/apps/desktop/src/main/maker-ipc/scheduledModelSelection.ts
@@ -92,7 +92,7 @@ export function resolveScheduledModelSelection(
effectiveSourceIdForModel(providers, null, selection.model, selection.agentKind);
const provider = providers.find((candidate) => candidate.id === providerId);
const model = findCatalogModel(provider, selection.model, selection.agentKind, { exact: true });
- if (!provider?.connected || !model) {
+ if (!provider?.connected || provider.suspended === true || !model || model.disabled === true) {
throw new Error(`Scheduled model "${selection.model}" is unavailable from provider "${providerId ?? 'default'}"`);
}
return {
@@ -115,9 +115,10 @@ export async function applyScheduledModelSelection(
},
): Promise<ScheduledModelSelection> {
const target = await deps.getTarget();
- // The runner owns missing/archived target recovery, including persistent-task rebinding.
+ // The runner replaces missing/archived targets with a new local task. Do not
+ // carry the retired task's execution computer into that replacement's route.
if (!target || target.status === 'archived' || target.status === 'deleted') {
- return deps.resolveSelection(selection, target);
+ return deps.resolveSelection(selection);
}
if (deps.isBusy()) throw new ScheduledModelSelectionBusyError('Scheduled model selection waits for the current turn');
assertScheduledHarnessSupported(target, selection.agentKind);