Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(scheduler): 将自动任务模型恢复延后至下次发送
Dashe97fd0416545
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/orcaModelSelectionIntent.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/orcaModelSelectionIntent.test.tsindex fb8c9f45b1..52f97974e3 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/orcaModelSelectionIntent.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/orcaModelSelectionIntent.test.ts@@ -7,6 +7,7 @@ import { acquireSendToSessionLock, withSendToSessionLock } from '../sendToSessioimport { effectiveSourceIdForModel, findCatalogModel, type ProviderView } from '@cindy/model-providers';import { resolveSessionRuntimeAxes } from '../sessionRuntimeControl';import { parseScheduledModelBaseline } from '../../../shared/scheduledModelBaseline';+import { createScheduledModelScope, type ScheduledModelSelection } from '../scheduledModelSelection';// Execute the actual picker admission branches (local and agent-device), with// everything after admission represented by applyLive. No Electron bootstrap.@@ -163,6 +164,46 @@ describe('pending target axis admission', () => {// Renderer persistence. Exercise the real queue/lease and recovery boundary;// Renderer-to-IPC persistence is covered in the existing cross-file guard suite.describe('complete selection commit boundaries', () => {+ // 2026-10-23: the real direct-send adapter restored the owner's smaller+ // 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 => {+ const owner: ScheduledModelSelection = {+ agentKind: 'codex', model: 'owner-model', providerId: 'provider', effort: 'high', fastMode: false,+ };+ const automatic = { ...owner, model: 'automatic-model' };+ let profile = owner;+ let baseline: string | null = null;+ const transitions: string[] = [];+ const apply = async (_id: string, next: ScheduledModelSelection) => {+ transitions.push(next.model);+ profile = next;+ return next;+ };+ const deps = {+ createId: () => 'saved-owner', read: async () => ({ profile, baseline }),+ write: async (_id: string, saved: unknown) => { baseline = saved ? JSON.stringify(saved) : null; },+ isBusy: () => false,+ apply: async (id: string, next: ScheduledModelSelection) => { await apply(id, next); },+ };+ await createScheduledModelScope(deps).begin('scheduled-task');+ profile = automatic;+ // A new scope instance also exercises a restart between turns.+ const directSend = 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);+ });+it('reads a picker intent staged while the direct send waits for the real route lock', async () => {const pending = createPendingAgentSwitchRegistry();let status = 'archived';diff --git a/apps/desktop/src/main/maker-ipc/register.ts b/apps/desktop/src/main/maker-ipc/register.tsindex 39ad974be7..f199f8d084 100644--- a/apps/desktop/src/main/maker-ipc/register.ts+++ b/apps/desktop/src/main/maker-ipc/register.ts@@ -4461,19 +4461,19 @@ let pendingAgentSwitchApplyHolder:signal?: AbortSignal,selection?: ScheduledModelSelection,beforeApply?: () => Promise<boolean | void>,- ) => Promise<{ release: () => void; selection?: ScheduledModelSelection; restore?: () => Promise<void> }>) | null = null;+ ) => Promise<{ release: () => void; selection?: ScheduledModelSelection }>) | null = null;let cancelPendingAgentSwitchHolder: ((sessionId: string) => void) | null = null;-let preserveScheduledModelPreferencesHolder: ((sessionId: string) => Promise<() => Promise<void>>) | null = null;+let prepareScheduledModelPreferencesHolder: ((sessionId: string, override: boolean) => Promise<void>) | null = null;let recordDispatchedModelHolder: ((sessionId: string, clientId: string) => void) | null = null;export function recordDispatchedModel(sessionId: string, clientId: string): void {recordDispatchedModelHolder?.(sessionId, clientId);}-/** Scheduler caller already owns the send lock; cleanup reacquires it after the run. */-export async function preserveScheduledModelPreferencesUnderLock(sessionId: string) {- if (!preserveScheduledModelPreferencesHolder) throw new Error('Scheduled model selection is not initialized');- return preserveScheduledModelPreferencesHolder(sessionId);+/** Send boundary: preserve an override's owner choice, or apply that choice for a following run. */+export async function prepareScheduledModelPreferencesUnderLock(sessionId: string, override: boolean) {+ if (!prepareScheduledModelPreferencesHolder) throw new Error('Scheduled model selection is not initialized');+ return prepareScheduledModelPreferencesHolder(sessionId, override);}/** 会话级完整路由选择(引擎 + 模型 + 来源 + 档位 + Fast)。 */@@ -4780,7 +4780,7 @@ export async function acquirePendingAgentSwitchForDirectSend(lease?.release();throw new Error('Scheduled model selection was not resolved');}- return { release: lease.release, selection: lease.selection, restore: lease.restore };+ return { release: lease.release, selection: lease.selection };}/** 直发路径在 createSession / 重读 live session 之前关掉不健康原生会话。 */@@ -11004,18 +11004,18 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)await updateScheduledPreference(sessionId, patch);return true;};- preserveScheduledModelPreferencesHolder = async (sessionId) => {- const scopeId = await scheduledModelScope.begin(sessionId);- return scopeId- ? () => withSendToSessionLock(sessionId, () => scheduledModelScope.restore(sessionId, scopeId))- : async () => {};+ prepareScheduledModelPreferencesHolder = async (sessionId, override) => {+ if (override) await scheduledModelScope.begin(sessionId);+ else await scheduledModelScope.restore(sessionId);};pendingAgentSwitchApplyHolder = async (sessionId, signal, selection, beforeApply) => {let stage = 'direct-send:acquire';let deferPendingApply = false;const release = await acquireSendToSessionLock(sessionId, undefined, () => stage);try {- await scheduledModelScope.restore(sessionId);+ // Another explicit automation 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);// 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);@@ -11041,20 +11041,16 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)});}let resolvedSelection: ScheduledModelSelection | undefined;- let scheduledScopeId: string | undefined;if (selection) {stage = 'direct-send:applyScheduledModelSelection';- scheduledScopeId = await scheduledModelScope.begin(sessionId);+ await scheduledModelScope.begin(sessionId);resolvedSelection = await applyScheduledProfile(sessionId, selection, signal);}stage = 'direct-send:prepareUnhealthySession';await contextOverflowRolloverHolder?.prepareUnhealthySession(sessionId);// The caller retains the lease through runtime refresh and Session.send.stage = 'direct-send:caller-dispatch';- return { release, selection: resolvedSelection,- ...(scheduledScopeId ? { restore: () => withSendToSessionLock(sessionId,- () => scheduledModelScope.restore(sessionId, scheduledScopeId)) } : {}),- };+ return { release, selection: resolvedSelection };} catch (err) {release();throw err;diff --git a/apps/desktop/src/main/maker-ipc/scheduledModelSelection.ts b/apps/desktop/src/main/maker-ipc/scheduledModelSelection.tsindex 4e7901f5f6..8e018673f0 100644--- a/apps/desktop/src/main/maker-ipc/scheduledModelSelection.ts+++ b/apps/desktop/src/main/maker-ipc/scheduledModelSelection.ts@@ -15,10 +15,9 @@ export interface ScheduledModelSelection {export interface ScheduledModelSelectionLease {release: () => void;selection: ScheduledModelSelection;- restore?: () => Promise<void>;}-/** All calls run under the existing session send lock. The saved preference survives restart. */+/** Send-boundary operations only. The saved preference survives idle time and restart. */export function createScheduledModelScope(deps: {read: (sessionId: string) => Promise<{profile: Omit<ScheduledModelSelection, 'effort'> & {diff --git a/apps/desktop/src/main/scheduler-host/__tests__/runnerModelSelection.test.ts b/apps/desktop/src/main/scheduler-host/__tests__/runnerModelSelection.test.tsindex 38980cc8cb..5f942bb75e 100644--- a/apps/desktop/src/main/scheduler-host/__tests__/runnerModelSelection.test.ts+++ b/apps/desktop/src/main/scheduler-host/__tests__/runnerModelSelection.test.ts@@ -90,7 +90,7 @@ vi.mock('../runners/_shared', () => ({}));import { MakerScheduleRunner } from '../runner';-import { applyScheduledModelSelection, resolveScheduledModelSelection } from '../../maker-ipc/scheduledModelSelection';+import { applyScheduledModelSelection, createScheduledModelScope, resolveScheduledModelSelection } from '../../maker-ipc/scheduledModelSelection';import type { ProviderView } from '@cindy/model-providers';import type { Scheduler } from '@cindy/maker-scheduler';@@ -249,7 +249,7 @@ function createRunnerHarness(opts: {sessionAlive?: boolean;acquirePendingAgentSwitch?: ConstructorParameters<typeof MakerScheduleRunner>[0]['acquirePendingAgentSwitch'];- preserveModelPreferences?: ConstructorParameters<typeof MakerScheduleRunner>[0]['preserveModelPreferences'];+ prepareModelPreferences?: ConstructorParameters<typeof MakerScheduleRunner>[0]['prepareModelPreferences'];onModelDispatched?: ConstructorParameters<typeof MakerScheduleRunner>[0]['onModelDispatched'];applyPiModelSelectionUnderLock?: ConstructorParameters<typeof MakerScheduleRunner>[0]['applyPiModelSelectionUnderLock'];resolveModelSelection?: ConstructorParameters<typeof MakerScheduleRunner>[0]['resolveModelSelection'];@@ -293,7 +293,7 @@ function createRunnerHarness(checkModelRoute: opts.checkModelRoute,...(opts.isAgentOnOtherDevice ? { isAgentOnOtherDevice: opts.isAgentOnOtherDevice } : {}),acquirePendingAgentSwitch: opts.acquirePendingAgentSwitch,- preserveModelPreferences: opts.preserveModelPreferences,+ prepareModelPreferences: opts.prepareModelPreferences,onModelDispatched: opts.onModelDispatched,applyPiModelSelectionUnderLock: opts.applyPiModelSelectionUnderLock ?? (async (_id, targetModel, providerId) => {await h.session.setModel(targetModel, { providerId });@@ -332,20 +332,31 @@ describe('MakerScheduleRunner model selection', () => {mocks.getSessionRowSnapshot.mockResolvedValue({ status: 'active' });});- // Integration: follow the production runner from model override through completion/failure.- // The previous route tests asserted the automation model only, never the next user's choice.+ // 2026-10-23 regression: completion restored the runtime and rebuilt a finished+ // task's context. Unit tier: real runner success/failure must leave the native+ // model untouched; the persisted owner preference is applied by the next send.it.each([['legacy', 'success'], ['explicit', 'success'],['legacy', 'failure'], ['explicit', 'failure'],- ] as const)('restores the owner model after %s dispatch %s', async (route, outcome) => {+ ] as const)('keeps the native context after %s dispatch %s', async (route, outcome) => {const h = createSessionHarness();const original = h.session.model;const release = vi.fn();- const restore = vi.fn(async () => {- expect(release).toHaveBeenCalledTimes(1);- await h.session.setModel(original);+ let baseline: string | null = null;+ const restore = vi.fn(async (_id, profile) => {+ await h.session.setModel(profile.model);+ });+ const scope = createScheduledModelScope({+ createId: () => 'owner-scope',+ read: async () => ({ baseline, profile: {+ agentKind: 'claude-code', model: h.session.model, providerId: null,+ effort: 'high', fastMode: false,+ } }),+ write: async (_id, saved) => { baseline = saved ? JSON.stringify(saved) : null; },+ isBusy: () => false,+ apply: restore,});- const preserve = vi.fn(async () => restore);+ const preserve = vi.fn(async () => { await scope.begin(h.session.id); });const onModelDispatched = vi.fn(() => {expect(h.session.model).toBe('claude-opus-4-8');});@@ -353,12 +364,13 @@ describe('MakerScheduleRunner model selection', () => {agentKind: 'claude-code', model: original, effort: 'high', workDir: '/work',}, {sessionAlive: true,- preserveModelPreferences: preserve,+ prepareModelPreferences: preserve,onModelDispatched,acquirePendingAgentSwitch: async (_id, _signal, selection) => {if (!selection) return release;+ await scope.begin(h.session.id);await h.session.setModel(selection.model);- return { release, selection, restore };+ return { release, selection };},});const schedule = baseSchedule({@@ -373,9 +385,15 @@ describe('MakerScheduleRunner model selection', () => {await fireToCompletion(harness, h, schedule);expect(onModelDispatched).toHaveBeenCalledWith(h.session.id, expect.any(String));}- expect(restore).toHaveBeenCalledTimes(1);- expect(h.session.model).toBe(original);+ expect(restore).not.toHaveBeenCalled();+ expect(h.session.model).toBe('claude-opus-4-8');expect(preserve).toHaveBeenCalledTimes(route === 'legacy' ? 1 : 0);+ expect(JSON.parse(baseline!).model).toBe(original);+ // Only the next ordinary send restores the user's route, including after+ // an automation failed before dispatch. Completion itself cannot do it.+ await scope.restore(h.session.id);+ expect(h.session.model).toBe(original);+ expect(baseline).toBeNull();});describe('resolved automation selection survives the full fire', () => {diff --git a/apps/desktop/src/main/scheduler-host/__tests__/runnerQueuedDispatch.test.ts b/apps/desktop/src/main/scheduler-host/__tests__/runnerQueuedDispatch.test.tsindex 2d313ef0dc..c0db45d3b1 100644--- a/apps/desktop/src/main/scheduler-host/__tests__/runnerQueuedDispatch.test.ts+++ b/apps/desktop/src/main/scheduler-host/__tests__/runnerQueuedDispatch.test.ts@@ -414,6 +414,7 @@ function createRunnerHarness(/** 停用轴裁决桩(缺省 = 不裁决,与生产未接线时一致)。 */checkModelRoute?: MakerScheduleRunnerDeps['checkModelRoute'];acquirePendingAgentSwitch?: MakerScheduleRunnerDeps['acquirePendingAgentSwitch'];+ prepareModelPreferences?: MakerScheduleRunnerDeps['prepareModelPreferences'];resolveModelSelection?: MakerScheduleRunnerDeps['resolveModelSelection'];applyPiModelSelectionUnderLock?: MakerScheduleRunnerDeps['applyPiModelSelectionUnderLock'];} = {},@@ -453,6 +454,7 @@ function createRunnerHarness(schedulerQueue,checkModelRoute: opts.checkModelRoute,acquirePendingAgentSwitch: opts.acquirePendingAgentSwitch,+ prepareModelPreferences: opts.prepareModelPreferences,applyPiModelSelectionUnderLock: opts.applyPiModelSelectionUnderLock ?? (async (_id, model, providerId) => {await liveSession.setModel(model, { providerId });mocks.getSessionProvider.mockReturnValue(providerId);@@ -495,6 +497,37 @@ beforeEach(() => {});describe('MakerScheduleRunner queued dispatch (busy bound session)', () => {+ // 2026-10-23 regression, unit tier: a follow-owner run queued behind an+ // override must refresh its route at dispatch, not keep the enqueue-time+ // automation model. Earlier queue cases had no deferred owner preference.+ it('uses the restored owner route when a queued run follows the task model', async () => {+ const h = createSessionHarness(async () => ({ accepted: true }));+ const queue = createQueueHarness({ busy: true });+ Object.assign(h.session, { model: 'automatic-model' });+ const checkModelRoute = vi.fn<NonNullable<MakerScheduleRunnerDeps['checkModelRoute']>>(+ async () => ({ kind: 'pass' }),+ );+ const opts = {+ metaModel: 'automatic-model', checkModelRoute,+ prepareModelPreferences: vi.fn(async (_id: string, override: boolean) => {+ expect(override).toBe(false);+ opts.metaModel = 'owner-model';+ Object.assign(h.session, { model: 'owner-model' });+ }),+ };+ const { runner } = createRunnerHarness(h.session, queue.deps, opts);+ const fire = runner.fire(heartbeatSchedule(), createFireContext());+ await vi.waitFor(() => expect(queue.enqueueCalls).toHaveLength(1));+ expect(opts.prepareModelPreferences).not.toHaveBeenCalled();+ await queue.accept();+ expect(checkModelRoute).toHaveBeenLastCalledWith('claude-code', 'owner-model', null);+ expect(h.session.setModel).not.toHaveBeenCalledWith('automatic-model', expect.anything());+ await vi.waitFor(() => expect(h.listenerCount()).toBe(1));+ h.emit({ type: 'done', data: {}, source: 'claude-code' });+ await expect(fire).resolves.toMatchObject({ sessionId: SESSION_ID });+ expect(opts.prepareModelPreferences).toHaveBeenCalledTimes(1);+ });+it('dispatches a fresh implicit provider route using the resolved fire-local schedule', async () => {const h = createSessionHarness(async () => ({ accepted: true }));Object.assign(h.session, { agentKind: 'pi', model: 'shared-model' });diff --git a/apps/desktop/src/main/scheduler-host/__tests__/schedulerQueueWiring.test.ts b/apps/desktop/src/main/scheduler-host/__tests__/schedulerQueueWiring.test.tsindex 42687eb087..079aecb4a2 100644--- a/apps/desktop/src/main/scheduler-host/__tests__/schedulerQueueWiring.test.ts+++ b/apps/desktop/src/main/scheduler-host/__tests__/schedulerQueueWiring.test.ts@@ -28,7 +28,7 @@ vi.mock('../../maker-ipc/register.js', () => ({ensureSchedulerQueueRestored: mocks.restore,findSchedulerUsageLimitWait: mocks.quotaWait,applyPiImModelSelectionUnderLock: vi.fn(), acquirePendingAgentSwitchForDirectSend: vi.fn(),- preserveScheduledModelPreferencesUnderLock: vi.fn(), recordDispatchedModel: vi.fn(),+ prepareScheduledModelPreferencesUnderLock: vi.fn(), recordDispatchedModel: vi.fn(),broadcastSessionCreated: vi.fn(), cancelSchedulerAutoResume: vi.fn(),enqueueSchedulerPrompt: vi.fn(), hasQueuedSchedulerPrompt: vi.fn(),isSchedulerAutoResumePending: vi.fn(), isSchedulerPromptTracked: vi.fn(),diff --git a/apps/desktop/src/main/scheduler-host/index.ts b/apps/desktop/src/main/scheduler-host/index.tsindex 1d0cfec1b5..57d7e4bbab 100644--- a/apps/desktop/src/main/scheduler-host/index.ts+++ b/apps/desktop/src/main/scheduler-host/index.ts@@ -39,7 +39,7 @@ import { getDesktopNotificationsEnabled } from '../notificationService.js';import {applyPiImModelSelectionUnderLock,acquirePendingAgentSwitchForDirectSend,- preserveScheduledModelPreferencesUnderLock,+ prepareScheduledModelPreferencesUnderLock,recordDispatchedModel,broadcastSessionCreated,cancelSchedulerAutoResume,@@ -131,7 +131,7 @@ async function startSchedulerInternal(deps: StartSchedulerDeps): Promise<SchedulonUndispatchedUserTurn: deps.onUndispatchedUserTurn,findUsageLimitWait: findSchedulerUsageLimitWait,acquirePendingAgentSwitch: acquirePendingAgentSwitchForDirectSend,- preserveModelPreferences: preserveScheduledModelPreferencesUnderLock,+ prepareModelPreferences: prepareScheduledModelPreferencesUnderLock,onModelDispatched: recordDispatchedModel,applyPiModelSelectionUnderLock: applyPiImModelSelectionUnderLock,resolveModelSelection: resolveScheduledModelSelectionLive,diff --git a/apps/desktop/src/main/scheduler-host/runner.ts b/apps/desktop/src/main/scheduler-host/runner.tsindex 4c683ada08..c7897fb46d 100644--- a/apps/desktop/src/main/scheduler-host/runner.ts+++ b/apps/desktop/src/main/scheduler-host/runner.ts@@ -286,7 +286,7 @@ export interface MakerScheduleRunnerDeps {signal?: AbortSignal,selection?: ScheduledModelSelection,) => Promise<(() => void) | ScheduledModelSelectionLease>;- preserveModelPreferences?: (sessionId: string) => Promise<() => Promise<void>>;+ prepareModelPreferences?: (sessionId: string, override: boolean) => Promise<void>;onModelDispatched?: (sessionId: string, clientId: string) => void;/** Resolve the same provider-specific snapshot for fresh explicit choices. */resolveModelSelection?: (selection: ScheduledModelSelection) => Promise<ScheduledModelSelection>;@@ -752,12 +752,8 @@ export class MakerScheduleRunner implements ScheduleRunner {closeQuietOutput?.();holder.releaseAgentSwitchLock?.();holder.releaseAgentSwitchLock = undefined;- try {- await holder.restoreModelPreferences?.();- } catch (error) {- // The durable baseline remains authoritative; the next input retries before sending.- this.deps.logger.warn?.('[runner] scheduled model restoration deferred', error);- }+ // Owner preferences already project from the durable baseline. Leave the+ // native context intact until an actual next send chooses its target model.await this.clearSchedulerRunContext(holder);holder.headlessGhostSetupTurn?.close();if (@@ -969,7 +965,6 @@ export class MakerScheduleRunner implements ScheduleRunner {? this.deps.acquirePendingAgentSwitch?.(sessionId, ctx.signal, selection): this.deps.acquirePendingAgentSwitch?.(sessionId, ctx.signal));holder.releaseAgentSwitchLock = typeof lease === 'function' ? lease : lease?.release;- if (typeof lease !== 'function') holder.restoreModelPreferences = lease?.restore;if (selection) {if (!lease || typeof lease === 'function')throw new Error('Scheduled model selection was not resolved');@@ -1094,8 +1089,8 @@ export class MakerScheduleRunner implements ScheduleRunner {providerId: row?.providerId ?? null,});}- if (!holder.restoreModelPreferences && hasScheduledModelOverride(schedule)) {- holder.restoreModelPreferences = await this.deps.preserveModelPreferences?.(sessionId);+ if (!resolvedSelection && hasScheduledModelOverride(schedule)) {+ await this.deps.prepareModelPreferences?.(sessionId, true);}resumeSessionId = meta?.sdkSessionId;heartbeatWorkingDir = meta?.workDir;@@ -2466,8 +2461,19 @@ export class MakerScheduleRunner implements ScheduleRunner {: schedule.prompt,origin,onPreparing: async () => {- if (schedule.targetSessionId && hasScheduledModelOverride(schedule) && this.deps.preserveModelPreferences) {- holder.restoreModelPreferences = await this.deps.preserveModelPreferences?.(sessionId);+ if (schedule.targetSessionId && this.deps.prepareModelPreferences) {+ const override = hasScheduledModelOverride(schedule);+ await this.deps.prepareModelPreferences(sessionId, override);+ if (!override) {+ // The previous automation can have left its native route in place+ // while this item waited. Use the restored owner route at dispatch.+ const meta = await this.deps.maker.getSessionMeta(sessionId);+ routingBaseline = {+ ...routingBaseline, model: meta?.model, agentKind: meta?.agentKind,+ effort: meta?.effort, fastMode: meta?.fastMode,+ providerId: getSessionProvider(sessionId) ?? null,+ };+ }}const preparingLive = this.deps.maker.getSession(sessionId);if ((preparingLive?.agentKind ?? routingBaseline.agentKind ?? schedule.agentKind) !== 'pi') return;@@ -3841,7 +3847,6 @@ interface EphemeralSessionHolder {keepAlive?: boolean;/** heartbeat direct-send route lock; released immediately after Session.send settles. */releaseAgentSwitchLock?: () => void;- restoreModelPreferences?: () => Promise<void>;/** unique ownership generation for the session-level scheduler run context. */schedulerRunContextOwner?: SchedulerRunContextOwner;}diff --git a/docs/dev-rules/configuration-and-overrides.md b/docs/dev-rules/configuration-and-overrides.mdindex c66198aeab..4bd08b1aae 100644--- a/docs/dev-rules/configuration-and-overrides.md+++ b/docs/dev-rules/configuration-and-overrides.md@@ -37,7 +37,9 @@ token)与 [`engineering-conventions.md`](engineering-conventions.md)(i18n)### 自动任务的单次模型选择绑定已有对话的自动任务,其模型、来源、推理档位与 Fast 仅用于该次运行。-选择器始终展示用户的选择,运行后及下一次用户输入前恢复原配置;权限与计划模式保持原有语义。+选择器始终展示用户的选择;运行结束不切换运行模型、不重建或整理上下文。+仅在下一次实际发送时落实最终选择的模型;新的自动任务指定模型时直接应用该模型,+不先恢复用户模型再切过去。权限与计划模式保持原有语义。跨引擎继续使用已有历史交接机制,不回滚原生会话检查点。保存的用户选择需能跨进程恢复;恢复失败保留它,下次发送前重试,不能悄悄沿用自动任务模型。用户在运行期间主动改选的模型优先;修改推理档位与 Fast 更新用户配置,不改正在运行的自动任务。