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(scheduler): 避免旧格式自动任务先恢复用户模型

Dash2f0fd1f3202c
diff --git a/apps/desktop/src/main/__tests__/makerSendToSessionOrdering.test.ts b/apps/desktop/src/main/__tests__/makerSendToSessionOrdering.test.ts
index 383f8985e3..11a1b1b9db 100644
--- a/apps/desktop/src/main/__tests__/makerSendToSessionOrdering.test.ts
+++ b/apps/desktop/src/main/__tests__/makerSendToSessionOrdering.test.ts
@@ -653,7 +653,7 @@ describe('sendToSession ordering', () => {
}
expectOrder(directSendSwitchBlock, 'prepareUnhealthySession', "stage = 'direct-send:caller-dispatch'");
expectOrder(directSendSwitchBlock, 'applyPendingAgentSwitchIfIdle(', 'prepareUnhealthySession');
- expectOrder(directSendSwitchBlock, 'prepareUnhealthySession', 'return { release, selection: resolvedSelection,');
+ expectOrder(directSendSwitchBlock, 'prepareUnhealthySession', 'return { release, selection: resolvedSelection');
});
it('仅 Device Link 归一化 SET_MODEL 的 JSON null 可选占位,本地仍走严格校验', () => {
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/orcaModelSelectionIntent.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/orcaModelSelectionIntent.test.ts
index 52f97974e3..1b3cf21a3e 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/orcaModelSelectionIntent.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/orcaModelSelectionIntent.test.ts
@@ -18,11 +18,15 @@ const confirmationChecks: string[] = [];
let applySelectionAdapter = '';
let piWindowOverride = '';
let directSendAdapter = '';
+let directSendEntry = '';
let archivedAdmission = '';
let terminalGuard = '';
let stageAxisAdapter = '';
let scheduledAxisAdapter = '';
function visit(node: ts.Node) {
+ if (ts.isFunctionDeclaration(node) && node.name?.text === 'acquirePendingAgentSwitchForDirectSend' && node.body) {
+ directSendEntry = node.getText(source).replace(/^export /, '');
+ }
if (ts.isVariableDeclaration(node) && node.name.getText(source) === 'updateSavedScheduledAxis') {
scheduledAxisAdapter = node.initializer!.getText(source);
}
@@ -168,7 +172,9 @@ describe('complete selection commit boundaries', () => {
// window before applying the next automation. Existing tests covered picker
// intents only. Unit tier: preserve native history across repeated automation
// sends and restore the durable owner preference only for an ordinary send.
- it.each([true, false])('applies only the next send route (automation=%s)', async automated => {
+ // PR #6831: legacy schedules have no complete selection, but still must
+ // preserve the native context before the runner applies their model override.
+ it.each(['explicit', 'legacy', 'ordinary'])('applies only the next send route (%s)', async route => {
const owner: ScheduledModelSelection = {
agentKind: 'codex', model: 'owner-model', providerId: 'provider', effort: 'high', fastMode: false,
};
@@ -190,18 +196,23 @@ describe('complete selection commit boundaries', () => {
await createScheduledModelScope(deps).begin('scheduled-task');
profile = automatic;
// A new scope instance also exercises a restart between turns.
- const directSend = compile(directSendAdapter, {
+ const adapter = compile(directSendAdapter, {
scheduledModelScope: createScheduledModelScope(deps),
acquireSendToSessionLock, agentSwitchPending: new Map(),
isUserPendingAgentSwitchIntent, reconcileBotModelRoute: vi.fn(),
applyPendingAgentSwitchIfIdle: vi.fn(), agentSwitchDeps: {},
applyScheduledProfile: apply, contextOverflowRolloverHolder: null,
});
- const lease = await directSend('scheduled-task', undefined, automated ? automatic : undefined);
- lease.release();
- expect(transitions).toEqual([automated ? automatic.model : owner.model]);
- expect(profile.model).toBe(automated ? automatic.model : owner.model);
- expect(baseline === null).toBe(!automated);
+ const directSend = compile(directSendEntry, { pendingAgentSwitchApplyHolder: adapter });
+ const lease = await directSend('scheduled-task', undefined,
+ route === 'explicit' ? automatic : undefined, route === 'legacy');
+ // The legacy runner applies its model later under this same lease.
+ if (route === 'legacy') await apply('scheduled-task', automatic);
+ if (typeof lease === 'function') lease();
+ else lease.release();
+ expect(transitions).toEqual([route === 'ordinary' ? owner.model : automatic.model]);
+ expect(profile.model).toBe(route === 'ordinary' ? owner.model : automatic.model);
+ expect(baseline === null).toBe(route === 'ordinary');
});
it('reads a picker intent staged while the direct send waits for the real route lock', async () => {
diff --git a/apps/desktop/src/main/maker-ipc/register.ts b/apps/desktop/src/main/maker-ipc/register.ts
index f199f8d084..932269b85f 100644
--- a/apps/desktop/src/main/maker-ipc/register.ts
+++ b/apps/desktop/src/main/maker-ipc/register.ts
@@ -4461,6 +4461,7 @@ let pendingAgentSwitchApplyHolder:
signal?: AbortSignal,
selection?: ScheduledModelSelection,
beforeApply?: () => Promise<boolean | void>,
+ scheduledModelOverride?: boolean,
) => Promise<{ release: () => void; selection?: ScheduledModelSelection }>) | null = null;
let cancelPendingAgentSwitchHolder: ((sessionId: string) => void) | null = null;
let prepareScheduledModelPreferencesHolder: ((sessionId: string, override: boolean) => Promise<void>) | null = null;
@@ -4763,18 +4764,22 @@ export function clearWorkingDirectoryRecoveryForOwnerBoundary(): void {
* intent,返回 no-op release 即可。
*/
export function acquirePendingAgentSwitchForDirectSend(
- sessionId: string, signal?: AbortSignal,
+ sessionId: string, signal?: AbortSignal, selection?: undefined, scheduledModelOverride?: boolean,
): Promise<() => void>;
export function acquirePendingAgentSwitchForDirectSend(
sessionId: string, signal: AbortSignal | undefined, selection: ScheduledModelSelection,
): Promise<ScheduledModelSelectionLease>;
+export function acquirePendingAgentSwitchForDirectSend(
+ sessionId: string, signal?: AbortSignal, selection?: ScheduledModelSelection, scheduledModelOverride?: boolean,
+): Promise<(() => void) | ScheduledModelSelectionLease>;
export async function acquirePendingAgentSwitchForDirectSend(
sessionId: string,
signal?: AbortSignal,
selection?: ScheduledModelSelection,
+ scheduledModelOverride?: boolean,
): Promise<(() => void) | ScheduledModelSelectionLease> {
if (selection && !pendingAgentSwitchApplyHolder) throw new Error('Scheduled model selection is not initialized');
- const lease = await pendingAgentSwitchApplyHolder?.(sessionId, signal, selection);
+ const lease = await pendingAgentSwitchApplyHolder?.(sessionId, signal, selection, undefined, scheduledModelOverride);
if (!selection) return lease?.release ?? (() => {});
if (!lease?.selection) {
lease?.release();
@@ -11008,14 +11013,14 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
if (override) await scheduledModelScope.begin(sessionId);
else await scheduledModelScope.restore(sessionId);
};
- pendingAgentSwitchApplyHolder = async (sessionId, signal, selection, beforeApply) => {
+ pendingAgentSwitchApplyHolder = async (sessionId, signal, selection, beforeApply, scheduledModelOverride) => {
let stage = 'direct-send:acquire';
let deferPendingApply = false;
const release = await acquireSendToSessionLock(sessionId, undefined, () => stage);
try {
- // Another explicit automation goes straight to its own route. Restoring
+ // An automation with a model override goes straight to its own route. Restoring
// the owner first could destructively shrink history that this send can use.
- if (!selection) await scheduledModelScope.restore(sessionId);
+ if (!selection && !scheduledModelOverride) await scheduledModelScope.restore(sessionId);
// Read after acquisition: a picker can have been queued ahead of this
// send. Restore under this same lease through dispatch, without re-taking it.
const pendingSelection = agentSwitchPending.get(sessionId);
diff --git a/apps/desktop/src/main/scheduler-host/__tests__/runnerModelSelection.test.ts b/apps/desktop/src/main/scheduler-host/__tests__/runnerModelSelection.test.ts
index 5f942bb75e..bd233effc0 100644
--- a/apps/desktop/src/main/scheduler-host/__tests__/runnerModelSelection.test.ts
+++ b/apps/desktop/src/main/scheduler-host/__tests__/runnerModelSelection.test.ts
@@ -366,8 +366,12 @@ describe('MakerScheduleRunner model selection', () => {
sessionAlive: true,
prepareModelPreferences: preserve,
onModelDispatched,
- acquirePendingAgentSwitch: async (_id, _signal, selection) => {
- if (!selection) return release;
+ acquirePendingAgentSwitch: async (_id, _signal, selection, scheduledModelOverride) => {
+ if (!selection) {
+ // Legacy model overrides must bypass owner restoration too.
+ expect(scheduledModelOverride).toBe(true);
+ return release;
+ }
await scope.begin(h.session.id);
await h.session.setModel(selection.model);
return { release, selection };
diff --git a/apps/desktop/src/main/scheduler-host/runner.ts b/apps/desktop/src/main/scheduler-host/runner.ts
index c7897fb46d..0285c0c764 100644
--- a/apps/desktop/src/main/scheduler-host/runner.ts
+++ b/apps/desktop/src/main/scheduler-host/runner.ts
@@ -285,6 +285,7 @@ export interface MakerScheduleRunnerDeps {
sessionId: string,
signal?: AbortSignal,
selection?: ScheduledModelSelection,
+ scheduledModelOverride?: boolean,
) => Promise<(() => void) | ScheduledModelSelectionLease>;
prepareModelPreferences?: (sessionId: string, override: boolean) => Promise<void>;
onModelDispatched?: (sessionId: string, clientId: string) => void;
@@ -963,6 +964,8 @@ export class MakerScheduleRunner implements ScheduleRunner {
try {
const lease = await (selection
? this.deps.acquirePendingAgentSwitch?.(sessionId, ctx.signal, selection)
+ : schedule.model?.trim()
+ ? this.deps.acquirePendingAgentSwitch?.(sessionId, ctx.signal, undefined, true)
: this.deps.acquirePendingAgentSwitch?.(sessionId, ctx.signal));
holder.releaseAgentSwitchLock = typeof lease === 'function' ? lease : lease?.release;
if (selection) {