Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(scheduler): preserve runtime location during recovery and template creation
david5124a10767b2
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/scheduleIntervalJsonBoundary.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/scheduleIntervalJsonBoundary.test.tsindex 421ae0c33f..cc7d9cf10d 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/scheduleIntervalJsonBoundary.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/scheduleIntervalJsonBoundary.test.ts@@ -213,6 +213,22 @@ describe('scheduled model selection IPC compatibility', () => {}));});+ // PR #6832: template creation dropped the runtime location while retaining its+ // model/provider. Existing template cases bound a task and had no device field.+ // Unit tier: JSON -> real IPC handler -> creation input, with a remote-only route.+ it.each(['studio', null, undefined])('preserves template runtime location %s through the JSON handler', async (agentDeviceId) => {+ const create = vi.fn(async (input: CreateScheduleInput) => input);+ setSchedulerReady({ create } as never, {} as never);+ registerScheduleHandlers();+ const wire = JSON.parse(JSON.stringify({+ templateId: BUILTIN_TEMPLATES[0]!.id,+ overrides: { agentDeviceId, agentKind: 'codex', model: 'remote-only', providerId: 'remote-source' },+ }));+ const result = await handlers.get('maker:schedule:create-from-template')!(null, wire);+ expect(result).toMatchObject({ agentKind: 'codex', model: 'remote-only', providerId: 'remote-source' });+ expect((result as CreateScheduleInput).agentDeviceId).toBe(agentDeviceId);+ });+it.skipIf(process.platform === 'win32')('rejects a template override whose pre-run hook has a shell syntax error', async () => {const create = vi.fn(async (input: CreateScheduleInput) => input);setSchedulerReady({ create } as never, {} as never);diff --git a/apps/desktop/src/main/maker-ipc/__tests__/scheduledModelSelection.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/scheduledModelSelection.test.tsindex cc0da87806..e68182e145 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/scheduledModelSelection.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/scheduledModelSelection.test.ts@@ -143,12 +143,15 @@ describe('saved automation model selection at dispatch', () => {expect(deps.switchHarness).not.toHaveBeenCalled();expect(deps.applyModel).not.toHaveBeenCalled();});- it.each(['missing', 'archived', 'deleted'])('returns the resolved snapshot for %s target recovery without touching the target', async (status) => {+ // PR #6832: recovery must not depend on a dead target's catalog. The previous+ // fixture only resolved successfully, hiding offline/revoked-share failures.+ // Unit tier: unresolved saved preferences reach the runner without remote I/O.+ it.each(['missing', 'archived', 'deleted'])('preserves the saved choice for %s recovery without resolving the old catalog', async (status) => {const deps = fixture();- const expected = { ...selection, effort: 'medium' as const };deps.getTarget.mockResolvedValue(status === 'missing' ? null as never : { agentKind: 'codex', status });- deps.resolveSelection.mockResolvedValue(expected);- await expect(applyScheduledModelSelection(selection, deps)).resolves.toEqual(expected);+ deps.resolveSelection.mockRejectedValue(new Error('old target offline or share revoked'));+ await expect(applyScheduledModelSelection(selection, deps)).resolves.toEqual(selection);+ expect(deps.resolveSelection).not.toHaveBeenCalled();expect(deps.switchHarness).not.toHaveBeenCalled();expect(deps.applyModel).not.toHaveBeenCalled();});diff --git a/apps/desktop/src/main/maker-ipc/schedule.ts b/apps/desktop/src/main/maker-ipc/schedule.tsindex f3363e0634..807e621b40 100644--- a/apps/desktop/src/main/maker-ipc/schedule.ts+++ b/apps/desktop/src/main/maker-ipc/schedule.ts@@ -311,6 +311,7 @@ function buildCreateScheduleInput(manual: overrides.manual,intervalMs: overrides.intervalMs,agentKind: overrides.agentKind ?? template.agentKind ?? 'claude-code',+ agentDeviceId: overrides.agentDeviceId,modelAgentKind: overrides.modelAgentKind,model: overrides.model ?? template.model,providerId: overrides.providerId ?? template.providerId,diff --git a/apps/desktop/src/main/maker-ipc/scheduledModelSelection.ts b/apps/desktop/src/main/maker-ipc/scheduledModelSelection.tsindex 4e7901f5f6..470f41db8e 100644--- a/apps/desktop/src/main/maker-ipc/scheduledModelSelection.ts+++ b/apps/desktop/src/main/maker-ipc/scheduledModelSelection.ts@@ -115,8 +115,10 @@ export async function applyScheduledModelSelection(): Promise<ScheduledModelSelection> {const target = await deps.getTarget();// The runner owns missing/archived target recovery, including persistent-task rebinding.+ // Its replacement resolves at the schedule's saved location. Do not query the old+ // target's catalog: that device may be offline or its provider share revoked.if (!target || target.status === 'archived' || target.status === 'deleted') {- return deps.resolveSelection(selection);+ return selection;}if (deps.isBusy()) throw new ScheduledModelSelectionBusyError('Scheduled model selection waits for the current turn');assertScheduledHarnessSupported(target, selection.agentKind);diff --git a/apps/desktop/src/main/scheduler-host/__tests__/runnerModelSelection.test.ts b/apps/desktop/src/main/scheduler-host/__tests__/runnerModelSelection.test.tsindex 846de46ba6..82cdb1fd74 100644--- a/apps/desktop/src/main/scheduler-host/__tests__/runnerModelSelection.test.ts+++ b/apps/desktop/src/main/scheduler-host/__tests__/runnerModelSelection.test.ts@@ -410,6 +410,42 @@ describe('MakerScheduleRunner model selection', () => {expect(harness.createSession.mock.calls[0][0].agentDeviceId).toBe(agentDeviceId);});+ // PR #6832: the old rebinding fixture returned a successful catalog snapshot.+ // Exercise the real selection entry with an unavailable old catalog; fire must+ // still create at the saved location with its route (unit, in-memory host).+ it.each([undefined, 'studio'])('rebinds at %s when the archived target catalog is unavailable', async (agentDeviceId) => {+ const h = createSessionHarness();+ Object.assign(h.session, { agentKind: 'codex', model: 'gpt-5.5' });+ mocks.getSessionRowSnapshot.mockResolvedValue({ status: 'archived', agentDeviceId: 'relocated' });+ const oldCatalog = vi.fn(async () => { throw new Error('old target offline or share revoked'); });+ const resolveModelSelection = vi.fn(async (choice) => ({ ...choice, effort: 'high' as const }));+ const harness = createRunnerHarness(h, null, {+ acquirePendingAgentSwitch: async (_id, _signal, selection) => ({+ release: vi.fn(),+ selection: await applyScheduledModelSelection(selection!, {+ getTarget: async () => ({ agentKind: 'codex', status: 'archived' }),+ isBusy: () => false,+ resolveSelection: oldCatalog,+ switchHarness: async () => ({ engineReady: true }),+ applyModel: async () => {},+ }),+ }),+ resolveModelSelection,+ });+ harness.runner.attachScheduler({ update: vi.fn(), isRunSilenced: () => false } as unknown as Scheduler);+ const opts = await fireToCompletion(harness, h, baseSchedule({+ targetSessionId: h.session.id, persistentSession: true, agentDeviceId,+ agentKind: 'codex', modelAgentKind: 'codex', model: 'gpt-5.5', providerId: 'saved-provider',+ }));+ expect(opts).toMatchObject({ providerId: 'saved-provider', effort: 'high' });+ expect(harness.createSession.mock.calls[0][0].agentDeviceId).toBe(agentDeviceId);+ expect(oldCatalog).not.toHaveBeenCalled();+ expect(resolveModelSelection.mock.calls[0]).toEqual([+ expect.objectContaining({ providerId: 'saved-provider' }),+ ...(agentDeviceId ? [{ agentDeviceId }] : []),+ ]);+ });+// PR #6832: existing remote coverage only created new tasks. Cold resume and// model-triggered rebuild must dispatch at the bound row's current location,// even when the automation still saves its original location. Tier: unit.