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(model-selector): 切换思考强度即时生效,远程连接下也不再置灰 (#5236)

Dash75f41f3f1bc0
diff --git a/apps/desktop/src/renderer/__tests__/chatInputModelSelectorRouting.test.ts b/apps/desktop/src/renderer/__tests__/chatInputModelSelectorRouting.test.ts
index cabee862be..12f70b6bb9 100644
--- a/apps/desktop/src/renderer/__tests__/chatInputModelSelectorRouting.test.ts
+++ b/apps/desktop/src/renderer/__tests__/chatInputModelSelectorRouting.test.ts
@@ -19,6 +19,20 @@ describe('ChatInput model source switching wiring', () => {
expect(normalizeSourceText(windowsCheckoutSource)).toBe(chatInputSource);
});
+ it('only the serialized unified panel skips the remote effort selector lock', () => {
+ const modelSelectorSource = normalizeSourceText(
+ readFileSync(resolve(__dirname, '..', 'components', 'new-chat', 'ModelSelector.tsx'), 'utf8'),
+ );
+ expect(modelSelectorSource).toContain('onEffortChange(effort, { serializedByPanel: true })');
+ const start = chatInputSource.indexOf('const handleEffortChange = useCallback(');
+ const body = chatInputSource.slice(start, chatInputSource.indexOf('\n );\n', start));
+ expect(body).toContain('const lockSelector = options?.serializedByPanel !== true;');
+ expect(body).toContain('if (lockSelector) setRemoteSwitchInFlight(true);');
+ expect(body).toContain(
+ 'if (lockSelector && isSessionScopeCurrent(sessionId, currentSessionIdRef.current))',
+ );
+ });
+
it('uses the unified 90% switch-rebuild line instead of a harness compaction setting', () => {
const start = chatInputSource.indexOf('const confirmModelSwitchContextGuard = useCallback(');
const end = chatInputSource.indexOf('// session-agent-switch', start);
diff --git a/apps/desktop/src/renderer/__tests__/unifiedModelPanelRendering.test.tsx b/apps/desktop/src/renderer/__tests__/unifiedModelPanelRendering.test.tsx
index d74451addd..674976799b 100644
--- a/apps/desktop/src/renderer/__tests__/unifiedModelPanelRendering.test.tsx
+++ b/apps/desktop/src/renderer/__tests__/unifiedModelPanelRendering.test.tsx
@@ -17,6 +17,9 @@ import { act, fireEvent, render, screen, waitFor, within } from '@testing-librar
import React from 'react';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+/** 统一面板发起的深度写入带上「面板已串行」标记(见 ModelSelector 的 onEffortChangeLive)。 */
+const FROM_PANEL = { serializedByPanel: true };
+
vi.mock('react-i18next', async (importOriginal) => ({
...(await importOriginal<typeof import('react-i18next')>()),
useTranslation: () => ({
@@ -1144,7 +1147,7 @@ describe('统一面板 · 会话内形态', () => {
key: 'ArrowRight',
});
});
- expect(onEffortChange).toHaveBeenCalledWith('high');
+ expect(onEffortChange).toHaveBeenCalledWith('high', FROM_PANEL);
});
});
@@ -1241,7 +1244,7 @@ describe('统一面板 · 恢复推荐应用到 live 配置', () => {
});
expect(onCrossEngineSelect).not.toHaveBeenCalled();
expect(getModelEngineOverride('xd', 'gpt-5.5')).toBeUndefined();
- expect(onEffortChange).toHaveBeenCalledWith('high');
+ expect(onEffortChange).toHaveBeenCalledWith('high', FROM_PANEL);
expect(onFastModeChange).toHaveBeenCalledWith(false);
});
@@ -1604,7 +1607,7 @@ describe('统一面板 · 删除选中的收藏回落到模型默认', () => {
});
// 默认引擎(codex)== 会话引擎 → 无损,不该弹跨引擎确认。
expect(onCrossEngineSelect).not.toHaveBeenCalled();
- expect(onEffortChange).toHaveBeenCalledWith('high');
+ expect(onEffortChange).toHaveBeenCalledWith('high', FROM_PANEL);
expect(onFastModeChange).toHaveBeenCalledWith(false);
expect(listModelFavorites()).toHaveLength(0);
});
@@ -1709,7 +1712,7 @@ describe('统一面板 · 同引擎实时写入成功才清存储', () => {
await act(async () => {
fireEvent.click(within(flyout).getByText('恢复推荐'));
});
- expect(onEffortChange).toHaveBeenCalledWith('high');
+ expect(onEffortChange).toHaveBeenCalledWith('high', FROM_PANEL);
// 深度没写成 → 整件事放弃:不该留下用户从没选过的「旧档 + 无 Fast」。
expect(onFastModeChange).not.toHaveBeenCalled();
expect(getModelEngineOverride('xd', 'gpt-5.5')).toBe('cc');
@@ -1783,7 +1786,7 @@ describe('统一面板 · 同引擎实时写入成功才清存储', () => {
await act(async () => {
fireEvent.click(favoriteStar());
});
- expect(onEffortChange).toHaveBeenCalledWith('high');
+ expect(onEffortChange).toHaveBeenCalledWith('high', FROM_PANEL);
// 收藏是用户手存的东西,不可逆:回落配置没落成就绝不能把记录删了。
expect(listModelFavorites()).toHaveLength(1);
expect(listModelFavorites()[0]?.uid).toBe(uid);
@@ -1826,7 +1829,7 @@ describe('统一面板 · 两笔实时写入要么都落要么回滚', () => {
fireEvent.click(within(flyout).getByText('恢复推荐'));
});
// 第一笔写推荐档 high,第二笔关 Fast 失败 → 第一笔按进入前的实时深度 low 回滚。
- expect(onEffortChange.mock.calls).toEqual([['high'], ['low']]);
+ expect(onEffortChange.mock.calls).toEqual([['high', FROM_PANEL], ['low', FROM_PANEL]]);
expect(onFastModeChange).toHaveBeenCalledWith(false);
expect(getModelEngineOverride('xd', 'gpt-5.5')).toBe('cc');
});
@@ -1853,7 +1856,7 @@ describe('统一面板 · 两笔实时写入要么都落要么回滚', () => {
await act(async () => {
fireEvent.click(within(flyout).getByText('恢复推荐'));
});
- expect(onEffortChange.mock.calls).toEqual([['high'], ['low']]);
+ expect(onEffortChange.mock.calls).toEqual([['high', FROM_PANEL], ['low', FROM_PANEL]]);
// 回滚失败不改变结论:这次「恢复推荐」没成功,override / 记忆一律原样留着。
expect(getModelEngineOverride('xd', 'gpt-5.5')).toBe('cc');
});
@@ -1878,7 +1881,7 @@ describe('统一面板 · 两笔实时写入要么都落要么回滚', () => {
await waitFor(() => {
expect(getModelEngineOverride('xd', 'gpt-5.5')).toBeUndefined();
});
- expect(onEffortChange.mock.calls).toEqual([['high']]);
+ expect(onEffortChange.mock.calls).toEqual([['high', FROM_PANEL]]);
});
});
@@ -1928,7 +1931,7 @@ describe('统一面板 · 改模型行的实时配置后收藏不再选中', ()
key: 'ArrowRight',
});
});
- expect(onEffortChange).toHaveBeenCalledWith('high');
+ expect(onEffortChange).toHaveBeenCalledWith('high', FROM_PANEL);
await waitFor(() => {
expect(onUnifiedSelect).toHaveBeenCalledWith({
providerId: 'xd',
@@ -2227,7 +2230,7 @@ describe('统一面板 · 编辑选中的收藏同步到 live', () => {
key: 'ArrowRight',
});
});
- expect(onEffortChange).toHaveBeenCalledWith('high');
+ expect(onEffortChange).toHaveBeenCalledWith('high', FROM_PANEL);
await waitFor(() => {
expect(listModelFavorites()[0]?.effort).toBe('high');
});
@@ -2375,7 +2378,7 @@ describe('统一面板 · 编辑选中的收藏同步到 live', () => {
key: 'ArrowRight',
});
});
- expect(onEffortChange).toHaveBeenCalledWith('high');
+ expect(onEffortChange).toHaveBeenCalledWith('high', FROM_PANEL);
expect(listModelFavorites()[0]?.effort).toBe('low');
});
@@ -3179,7 +3182,7 @@ describe('统一面板 · 实测回归', () => {
await act(async () => {
fireEvent.keyDown(slider, { key: 'ArrowRight' });
});
- expect(onEffortChange).toHaveBeenCalledWith('high');
+ expect(onEffortChange).toHaveBeenCalledWith('high', FROM_PANEL);
// 关键回归点:改完档,浮层与列表都不许消失。
expect(screen.queryByTestId('unified-model-config-flyout')).not.toBeNull();
expect(screen.getByRole('listbox')).toBeTruthy();
@@ -3729,18 +3732,18 @@ describe('统一选择器 · 旧偏好与配置变更回归', () => {
});
});
- it('编辑收藏的异步 Fast 写入期间,不能再改深度或删除收藏', async () => {
+ it('编辑收藏的异步 Fast 写入期间,改深度与删除收藏排队,落定后按顺序执行', async () => {
const uid = addModelFavorite({
providerId: 'xd',
modelId: 'gpt-5.5',
agent: 'codex',
effort: 'low',
});
- let finish!: (value: boolean) => void;
+ const fastWrites: Array<(value: boolean) => void> = [];
const onFastModeChange = vi.fn(
() =>
new Promise<boolean>((resolve) => {
- finish = resolve;
+ fastWrites.push(resolve);
}),
);
const onEffortChange = vi.fn();
@@ -3765,13 +3768,17 @@ describe('统一选择器 · 旧偏好与配置变更回归', () => {
});
fireEvent.click(within(favorite).getByRole('button', { name: '取消收藏' }));
});
+ // 同一时刻只提交一笔:Fast 写入在途时,深度与删除都还没发出。
expect(onFastModeChange).toHaveBeenCalledTimes(1);
expect(onEffortChange).not.toHaveBeenCalled();
expect(listModelFavorites()).toHaveLength(1);
await act(async () => {
- finish(true);
+ fastWrites[0]?.(true);
});
- expect(listModelFavorites()[0]?.fast).toBe(true);
+ // Fast 落定、收藏副本写入后,才按点击顺序提交排队的深度,最后执行删除;
+ // 全程没有第二笔并发写入。
+ await waitFor(() => expect(listModelFavorites()).toHaveLength(0));
+ expect(onFastModeChange).toHaveBeenCalledTimes(1);
});
});
@@ -3913,7 +3920,7 @@ describe('统一面板 · 推理滑杆一次拖动只写最终档', () => {
});
if (eventType === 'pointerup') {
expect(onEffortChange).toHaveBeenCalledTimes(1);
- expect(onEffortChange).toHaveBeenCalledWith('high');
+ expect(onEffortChange).toHaveBeenCalledWith('high', FROM_PANEL);
} else expect(onEffortChange).not.toHaveBeenCalled();
});
});
diff --git a/apps/desktop/src/renderer/__tests__/unifiedRowActionsOptimistic.test.ts b/apps/desktop/src/renderer/__tests__/unifiedRowActionsOptimistic.test.ts
new file mode 100644
index 0000000000..9908811812
--- /dev/null
+++ b/apps/desktop/src/renderer/__tests__/unifiedRowActionsOptimistic.test.ts
@@ -0,0 +1,353 @@
+// @vitest-environment jsdom
+
+/**
+ * 统一模型面板改深度 / Fast 的即时反馈:写入在途时行上先显示目标值(松手不回弹),
+ * 在途时仍可继续调(每一维只保留最新一笔,落定后提交);失败后回到真实值。
+ */
+
+import { act, renderHook } from '@testing-library/react';
+import { useState } from 'react';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+
+import type { UnifiedModelEntry } from '@cindy/model-providers';
+
+import type { UnifiedAnchor, UnifiedRowConfig } from '../components/new-chat/unifiedModelSelection';
+import {
+ PENDING_VISIBLE_DELAY_MS,
+ useUnifiedRowActions,
+ withOptimisticConfig,
+ type UnifiedRowActionsOptions,
+} from '../components/new-chat/useUnifiedRowActions';
+
+const anchor: UnifiedAnchor = { kind: 'model', providerId: 'openai', modelId: 'gpt' };
+const entry = { providerId: 'openai', modelId: 'gpt' } as unknown as UnifiedModelEntry;
+const config = {
+ engine: 'codex',
+ agent: 'codex',
+ efforts: ['low', 'medium', 'high', 'xhigh'],
+ effort: 'medium',
+ fast: false,
+ fastCapable: true,
+ customized: false,
+ capability: { defaultEffort: 'medium' },
+ wireModelId: 'gpt',
+} as unknown as UnifiedRowConfig;
+
+function deferred() {
+ let resolve!: (value: boolean) => void;
+ const promise = new Promise<boolean>((r) => {
+ resolve = r;
+ });
+ return { promise, resolve };
+}
+
+function renderActions(overrides: Partial<UnifiedRowActionsOptions>) {
+ return renderHook(() =>
+ useUnifiedRowActions({
+ interactionDisabled: false,
+ isLiveRow: () => true,
+ onSelect: vi.fn(),
+ onFavoriteFlash: vi.fn(),
+ onBeforeRemoveFavorite: vi.fn(),
+ ...overrides,
+ }),
+ );
+}
+
+describe('useUnifiedRowActions 深度 / Fast 即时反馈', () => {
+ beforeEach(() => {
+ vi.useFakeTimers();
+ });
+ afterEach(() => {
+ vi.useRealTimers();
+ });
+
+ it('深度写入在途时立即显示目标档,短写入不显示为不可操作', async () => {
+ const write = deferred();
+ const { result } = renderActions({ onEffortChangeLive: () => write.promise });
+
+ let settled: unknown;
+ act(() => {
+ settled = result.current.applyEffort(anchor, entry, config, 'high');
+ });
+ expect(result.current.optimistic).toEqual({ anchorKey: 'model::openai::gpt', effort: 'high' });
+ expect(withOptimisticConfig(anchor, config, result.current.optimistic).effort).toBe('high');
+ expect(result.current.pending).toBe(false);
+
+ await act(async () => {
+ write.resolve(true);
+ await settled;
+ });
+ expect(result.current.optimistic).toBeNull();
+ expect(result.current.pending).toBe(false);
+ });
+
+ it('深度写入在途时仍可继续调:只保留最新一笔,落定后再提交,全程不置灰', async () => {
+ const first = deferred();
+ const onEffortChangeLive = vi.fn((_effort: string) =>
+ onEffortChangeLive.mock.calls.length === 1 ? first.promise : Promise.resolve(true),
+ );
+ const { result } = renderActions({ onEffortChangeLive });
+
+ let settled: unknown;
+ act(() => {
+ settled = result.current.applyEffort(anchor, entry, config, 'high');
+ });
+ act(() => {
+ result.current.applyEffort(anchor, entry, config, 'xhigh');
+ result.current.applyEffort(anchor, entry, config, 'low');
+ });
+ expect(onEffortChangeLive).toHaveBeenCalledTimes(1);
+ expect(result.current.optimistic?.effort).toBe('low');
+
+ act(() => {
+ vi.advanceTimersByTime(PENDING_VISIBLE_DELAY_MS * 3);
+ });
+ expect(result.current.pending).toBe(false);
+
+ await act(async () => {
+ first.resolve(true);
+ await settled;
+ });
+ await act(async () => {});
+ expect(onEffortChangeLive.mock.calls.map(([effort]) => effort)).toEqual(['high', 'low']);
+ expect(result.current.optimistic).toBeNull();
+ });
+
+ it('深度在途时排队的 Fast 不会被随后的深度调整覆盖', async () => {
+ const first = deferred();
+ const writes: string[] = [];
+ const { result } = renderActions({
+ onEffortChangeLive: (effort) => {
+ writes.push(`effort:${effort}`);
+ return writes.length === 1 ? first.promise : Promise.resolve(true);
+ },
+ onFastModeChangeLive: (enabled) => {
+ writes.push(`fast:${enabled}`);
+ return Promise.resolve(true);
+ },
+ });
+ let settled: unknown;
+ act(() => {
+ settled = result.current.applyEffort(anchor, entry, config, 'high');
+ });
+ act(() => {
+ result.current.applyFast(anchor, entry, config, true);
+ result.current.applyEffort(anchor, entry, config, 'xhigh');
+ });
+ expect(withOptimisticConfig(anchor, config, result.current.optimistic)).toMatchObject({
+ effort: 'xhigh',
+ fast: true,
+ });
+ await act(async () => {
+ first.resolve(true);
+ await settled;
+ });
+ await act(async () => {});
+ await act(async () => {});
+ expect(writes).toEqual(['effort:high', 'fast:true', 'effort:xhigh']);
+ expect(result.current.optimistic).toBeNull();
+ });
+
+ it('在途写入失败时丢掉排队的调整', async () => {
+ const first = deferred();
+ const onEffortChangeLive = vi.fn(() => first.promise);
+ const { result } = renderActions({ onEffortChangeLive });
+ let settled: unknown;
+ act(() => {
+ settled = result.current.applyEffort(anchor, entry, config, 'high');
+ result.current.applyEffort(anchor, entry, config, 'xhigh');
+ });
+ await act(async () => {
+ first.resolve(false);
+ await settled;
+ });
+ expect(onEffortChangeLive).toHaveBeenCalledTimes(1);
+ expect(result.current.optimistic).toBeNull();
+ });
+
+ it('「先应用、后收尾」路径失败时同样回报失败,丢掉排队项', async () => {
+ const first = deferred();
+ const onEffortChangeLive = vi.fn(() => first.promise);
+ const { result } = renderActions({
+ onEffortChangeLive,
+ // 选中的是一条收藏、改的是同模型的普通行:成功后才清锚点的那条路径。
+ selectedFavoriteUid: 'fav-1',
+ onSelectedFavoriteAnchorClear: vi.fn(),
+ });
+ let settled: unknown;
+ act(() => {
+ settled = result.current.applyEffort(anchor, entry, config, 'high');
+ result.current.applyEffort(anchor, entry, config, 'xhigh');
+ });
+ await act(async () => {
+ first.resolve(false);
+ expect(await settled).toBe(false);
+ });
+ await act(async () => {});
+ expect(onEffortChangeLive).toHaveBeenCalledTimes(1);
+ expect(result.current.optimistic).toBeNull();
+ });
+
+ it('其它写入超过延迟阈值才显示为不可操作,期间的深度调整排队而不丢弃', async () => {
+ const external = deferred();
+ const onEffortChangeLive = vi.fn(() => Promise.resolve(true));
+ const { result } = renderActions({ onEffortChangeLive });
+ let settled: unknown;
+ act(() => {
+ settled = result.current.runExternal(() => external.promise);
+ });
+ act(() => {
+ expect(result.current.applyEffort(anchor, entry, config, 'high')).toBeUndefined();
+ });
+ expect(result.current.optimistic?.effort).toBe('high');
+ expect(result.current.pending).toBe(false);
+ act(() => {
+ vi.advanceTimersByTime(PENDING_VISIBLE_DELAY_MS);
+ });
+ expect(result.current.pending).toBe(true);
+ expect(onEffortChangeLive).not.toHaveBeenCalled();
+ await act(async () => {
+ external.resolve(true);
+ await settled;
+ });
+ await act(async () => {});
+ expect(result.current.pending).toBe(false);
+ expect(onEffortChangeLive).toHaveBeenCalledWith('high');
+ expect(result.current.optimistic).toBeNull();
+ });
+
+ it('深度在途时点其它行 / 收藏不会被静默丢弃,落定后按顺序执行', async () => {
+ const first = deferred();
+ const order: string[] = [];
+ const { result } = renderActions({
+ onEffortChangeLive: (effort) => {
+ order.push(`effort:${effort}`);
+ return first.promise;
+ },
+ });
+ let settled: unknown;
+ act(() => {
+ settled = result.current.applyEffort(anchor, entry, config, 'high');
+ });
+ act(() => {
+ result.current.runExternal(() => {
+ order.push('external');
+ });
+ });
+ expect(order).toEqual(['effort:high']);
+ await act(async () => {
+ first.resolve(true);
+ await settled;
+ });
+ await act(async () => {});
+ expect(order).toEqual(['effort:high', 'external']);
+ });
+
+ it('被替换的排队项移到队尾,提交顺序等于最后一次点击的先后', async () => {
+ const first = deferred();
+ const order: string[] = [];
+ const { result } = renderActions({
+ onEffortChangeLive: (effort) => {
+ order.push(`effort:${effort}`);
+ return order.length === 1 ? first.promise : Promise.resolve(true);
+ },
+ });
+ let settled: unknown;
+ act(() => {
+ settled = result.current.applyEffort(anchor, entry, config, 'high');
+ });
+ act(() => {
+ result.current.runExternal(() => {
+ order.push('external:1');
+ });
+ result.current.applyEffort(anchor, entry, config, 'xhigh');
+ result.current.runExternal(() => {
+ order.push('external:2');
+ });
+ });
+ await act(async () => {
+ first.resolve(true);
+ await settled;
+ });
+ await act(async () => {});
+ await act(async () => {});
+ expect(order).toEqual(['effort:high', 'effort:xhigh', 'external:2']);
+ });
+
+ it('排队项在上一笔落定并重新渲染后提交,用的是最新一次渲染的回调', async () => {
+ const staleFast = vi.fn(() => Promise.resolve(true));
+ const freshFast = vi.fn(() => Promise.resolve(true));
+ const { result } = renderHook(() => {
+ const [onFastModeChangeLive, setFastHandler] = useState(() => staleFast);
+ return useUnifiedRowActions({
+ interactionDisabled: false,
+ isLiveRow: () => true,
+ onSelect: vi.fn(),
+ onFavoriteFlash: vi.fn(),
+ onBeforeRemoveFavorite: vi.fn(),
+ // 与 ChatInput 一致:写入成功时先更新调用方状态(新闭包要到下一次渲染才生效),再返回。
+ onEffortChangeLive: () =>
+ Promise.resolve().then(() => {
+ setFastHandler(() => freshFast);
+ return true;
+ }),
+ onFastModeChangeLive,
+ });
+ });
+ let settled: unknown;
+ act(() => {
+ settled = result.current.applyEffort(anchor, entry, config, 'high');
+ result.current.applyFast(anchor, entry, config, true);
+ });
+ await act(async () => {
+ await settled;
+ });
+ await act(async () => {});
+ expect(staleFast).not.toHaveBeenCalled();
+ expect(freshFast).toHaveBeenCalledWith(true);
+ });
+
+ it('写入失败后撤掉目标值,回到真实配置', async () => {
+ const { result } = renderActions({
+ onEffortChangeLive: () => Promise.reject(new Error('persist failed')),
+ });
+ await act(async () => {
+ await result.current.applyEffort(anchor, entry, config, 'high');
+ });
+ expect(result.current.optimistic).toBeNull();
+ expect(withOptimisticConfig(anchor, config, result.current.optimistic)).toBe(config);
+ });
+
+ it('Fast 写入同样即时显示', async () => {
+ const write = deferred();
+ const { result } = renderActions({ onFastModeChangeLive: () => write.promise });
+ let settled: unknown;
+ act(() => {
+ settled = result.current.applyFast(anchor, entry, config, true);
+ });
+ const shown = withOptimisticConfig(anchor, config, result.current.optimistic);
+ expect(shown.fast).toBe(true);
+ expect(shown.customized).toBe(true);
+ await act(async () => {
+ write.resolve(true);
+ await settled;
+ });
+ expect(result.current.optimistic).toBeNull();
+ });
+});
+
+describe('withOptimisticConfig', () => {
+ it('只覆盖发起写入的那一行,且忽略该行不支持的档位', () => {
+ const other: UnifiedAnchor = { kind: 'model', providerId: 'openai', modelId: 'other' };
+ const optimistic = { anchorKey: 'model::openai::gpt', effort: 'high' as const };
+ expect(withOptimisticConfig(other, config, optimistic)).toBe(config);
+ expect(withOptimisticConfig(anchor, config, optimistic)).toMatchObject({
+ effort: 'high',
+ customized: true,
+ });
+ expect(
+ withOptimisticConfig(anchor, config, { anchorKey: 'model::openai::gpt', effort: 'max' }),
+ ).toBe(config);
+ });
+});
diff --git a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx
index 6cf0ffce5b..5576c8e402 100644
--- a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx
+++ b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx
@@ -120,6 +120,7 @@ import {
ModelSelector,
resolveRemoteModelListStatus,
resolveModelSelectorAgentIdentity,
+ type EffortChangeOptions,
type ModelMemoryAccessors,
} from './ModelSelector';
import {
@@ -7609,7 +7610,7 @@ export function ChatInput({
* handleFastModeChange)。统一面板的「先应用、后清存储」入口按它决定要不要收尾。
*/
const handleEffortChange = useCallback(
- async (newEffort: Effort): Promise<boolean> => {
+ async (newEffort: Effort, options?: EffortChangeOptions): Promise<boolean> => {
if (settingsLocked) return false;
// 切换意图期:effort 改动 = 更新意图(重登记),不走普通 setEffort 链路。
if (sessionId && makerChatStore.getAgentSwitchIntent(sessionId)) {
@@ -7633,19 +7634,24 @@ export function ChatInput({
// 控制端纯镜像:**await** 运行时隧道 setEffort,被控端持久化后广播回流更新分片。
// New-K:await 而非 fire-and-forget —— 失败时被控端没真改,不能照报成功、污染默认偏好;
// toast 提示并 return,不跑下方 onEffortDidChange 成功收尾。
- // 乐观显示目标 effort + 置灰 selector(model/provider 不变),等被控端 echo 回流;失败回滚。
- setPendingRemoteSwitch({
+ // 乐观显示目标 effort,等被控端 echo 回流;失败回滚。统一面板发起时不置灰 selector:
+ // 面板同一时刻只提交一笔,调档期间的后续点击由面板排队。平铺选择器 / 快捷键等其它
+ // 入口没有这层串行,仍在隧道 await 期间置灰,防止多笔远程写入交错。
+ const lockSelector = options?.serializedByPanel !== true;
+ const optimisticSwitch = {
model: activeModel,
effort: newEffort,
providerId: selectedProviderId,
fastMode: fastMode === true,
- });
- setRemoteSwitchInFlight(true);
+ };
+ setPendingRemoteSwitch(optimisticSwitch);
+ if (lockSelector) setRemoteSwitchInFlight(true);
try {
await makerApiForDevice(remoteDeviceId).setEffort(sessionId, newEffort);
} catch (err) {
if (isSessionScopeCurrent(sessionId, currentSessionIdRef.current)) {
- setPendingRemoteSwitch(null);
+ // 之后又调过档时,乐观显示已是那一笔的目标,不能被这笔的失败撤掉。
+ setPendingRemoteSwitch((current) => (current === optimisticSwitch ? null : current));
toast.error(
t(
mapIpcErrorToI18nKey(err, { fallback: 'newChat.chatInput.remoteSwitchFailed' }),
@@ -7654,7 +7660,7 @@ export function ChatInput({
}
return false;
} finally {
- if (isSessionScopeCurrent(sessionId, currentSessionIdRef.current))
+ if (lockSelector && isSessionScopeCurrent(sessionId, currentSessionIdRef.current))
setRemoteSwitchInFlight(false);
}
if (activeModel) {
diff --git a/apps/desktop/src/renderer/components/new-chat/ModelSelector.tsx b/apps/desktop/src/renderer/components/new-chat/ModelSelector.tsx
index 46db1d1c35..fda25d8ea6 100644
--- a/apps/desktop/src/renderer/components/new-chat/ModelSelector.tsx
+++ b/apps/desktop/src/renderer/components/new-chat/ModelSelector.tsx
@@ -150,6 +150,15 @@ export const UNIFIED_COMPACT_PANEL_WIDTH_CLASS =
*/
export type ModelTagDensity = 'full' | 'subscription' | 'hidden';
+/** 改深度的附加信息。 */
+export interface EffortChangeOptions {
+ /**
+ * 由统一面板发起:面板已保证同一时刻只提交一笔,调用方不必为防并发写入而锁住 selector。
+ * 其余入口(平铺选择器、快捷键)缺省为 false,仍按原样锁定。
+ */
+ serializedByPanel?: boolean;
+}
+
export function modelTagDensityForWidth(width: number | null): ModelTagDensity {
if (width === null || width > UNIFIED_COMPACT_PANEL_MAX_WIDTH_PX) return 'full';
if (width >= 370) return 'subscription';
@@ -630,7 +639,10 @@ interface ModelSelectorProps {
* 调用方视为落了)。统一面板的三个「先应用、后清存储」入口(恢复推荐 / 删选中收藏 /
* 编辑选中收藏)靠它决定要不要收尾;其余调用方照旧无视返回值。
*/
- onEffortChange: (effort: Effort) => void | boolean | Promise<void | boolean>;
+ onEffortChange: (
+ effort: Effort,
+ options?: EffortChangeOptions,
+ ) => void | boolean | Promise<void | boolean>;
/**
* per-session 来源选择(B · Provider-first)。
* - currentProviderId:本会话当前显式选定的供应商 id(null = 跟随默认路由)。
@@ -819,7 +831,10 @@ interface ModelSelectorContentProps {
* 调用方视为落了)。统一面板的三个「先应用、后清存储」入口(恢复推荐 / 删选中收藏 /
* 编辑选中收藏)靠它决定要不要收尾;其余调用方照旧无视返回值。
*/
- onEffortChange: (effort: Effort) => void | boolean | Promise<void | boolean>;
+ onEffortChange: (
+ effort: Effort,
+ options?: EffortChangeOptions,
+ ) => void | boolean | Promise<void | boolean>;
fastMode?: boolean;
/** 语义同 onEffortChange(含返回值口径)。 */
onFastModeChange?: (enabled: boolean) => void | boolean | Promise<void | boolean>;
@@ -3013,7 +3028,13 @@ function ModelSelectorContentView({
}
onSessionFavoriteAnchorChange?.(null);
}}
- {...(onEffortChange ? { onEffortChangeLive: onEffortChange } : {})}
+ {...(onEffortChange
+ ? {
+ // 统一面板自己保证同一时刻只提交一笔(在途点击排队),调用方无需再锁 selector。
+ onEffortChangeLive: (effort: Effort) =>
+ onEffortChange(effort, { serializedByPanel: true }),
+ }
+ : {})}
{...(onFastModeChange ? { onFastModeChangeLive: onFastModeChange } : {})}
panelElement={paneElement}
{...(overlayContentClassName !== undefined
diff --git a/apps/desktop/src/renderer/components/new-chat/UnifiedModelPanel.tsx b/apps/desktop/src/renderer/components/new-chat/UnifiedModelPanel.tsx
index bff76eca2a..15203b87a5 100644
--- a/apps/desktop/src/renderer/components/new-chat/UnifiedModelPanel.tsx
+++ b/apps/desktop/src/renderer/components/new-chat/UnifiedModelPanel.tsx
@@ -28,7 +28,7 @@ import { ModelConfigFlyout, type ModelConfigFlyoutState } from './ModelConfigFly
import type { ModelMemoryAccessors } from './ModelSelector';
import { UnifiedFlyoutHost } from './UnifiedFlyoutHost';
import { UnifiedModelRail } from './UnifiedModelRail';
-import { useUnifiedRowActions } from './useUnifiedRowActions';
+import { useUnifiedRowActions, withOptimisticConfig } from './useUnifiedRowActions';
import { UnifiedModelRow } from './UnifiedModelRow';
import { ModelSourceUsageProvider } from './ModelSourceDetails';
import type { ProviderUsageScope } from './useProviderWeeklyQuota';
@@ -767,6 +767,7 @@ export function UnifiedModelPanel({
removeFavorite,
selectRow,
pending: actionPending,
+ optimistic: optimisticConfig,
runExternal,
} = useUnifiedRowActions({
favoriteStore: deviceId ? remoteFavorites.store : undefined,
@@ -1073,7 +1074,11 @@ export function UnifiedModelPanel({
<span className="truncate">{sectionLabel(section)}</span>
</div>
{section.rows.map((row) => {
- const config = configOf(row.entry, row.favorite);
+ const config = withOptimisticConfig(
+ row.anchor,
+ configOf(row.entry, row.favorite),
+ optimisticConfig,
+ );
const key = anchorKey(row.anchor);
const priceDisplay = priceDisplayOf(row.entry, config);
return (
@@ -1195,7 +1200,12 @@ export function UnifiedModelPanel({
>
{(() => {
const target = flyTarget;
- const config = configOf(target.entry, target.favorite);
+ // 深度 / Fast 写入在途时显示目标值,松手即停在新档(见 withOptimisticConfig)。
+ const config = withOptimisticConfig(
+ target.anchor,
+ configOf(target.entry, target.favorite),
+ optimisticConfig,
+ );
const state: ModelConfigFlyoutState = target.favorite
? 'favorite'
: config.customized
diff --git a/apps/desktop/src/renderer/components/new-chat/useUnifiedRowActions.ts b/apps/desktop/src/renderer/components/new-chat/useUnifiedRowActions.ts
index 52bb9c1ddc..c8a542d2db 100644
--- a/apps/desktop/src/renderer/components/new-chat/useUnifiedRowActions.ts
+++ b/apps/desktop/src/renderer/components/new-chat/useUnifiedRowActions.ts
@@ -163,8 +163,46 @@ export interface UnifiedRowActionsOptions {
onBeforeRemoveFavorite: (anchor: UnifiedAnchor) => void;
}
+/** 在途写入的目标值:只覆盖发起那一行(按锚点)的深度或 Fast。 */
+export interface UnifiedOptimisticConfig {
+ anchorKey: string;
+ effort?: Effort;
+ fast?: boolean;
+}
+
+/**
+ * 把在途目标值叠到该行的解析配置上(只作用于发起写入的那一行)。
+ * 「已自定义」按与选中行 live 覆盖相同的口径补算,恢复推荐入口随之即时出现。
+ */
+export function withOptimisticConfig(
+ anchor: UnifiedAnchor,
+ config: UnifiedRowConfig,
+ optimistic: UnifiedOptimisticConfig | null,
+): UnifiedRowConfig {
+ if (!optimistic || optimistic.anchorKey !== anchorKey(anchor)) return config;
+ const effort =
+ optimistic.effort !== undefined && config.efforts.includes(optimistic.effort)
+ ? optimistic.effort
+ : config.effort;
+ const fast = optimistic.fast !== undefined && config.fastCapable ? optimistic.fast : config.fast;
+ if (effort === config.effort && fast === config.fast) return config;
+ const defaultEffort = config.capability?.defaultEffort;
+ return {
+ ...config,
+ effort,
+ fast,
+ customized:
+ config.customized ||
+ fast ||
+ (effort !== null && defaultEffort != null && effort !== defaultEffort),
+ };
+}
+
export interface UnifiedRowActions {
+ /** 异步写入已持续超过 PENDING_VISIBLE_DELAY_MS,控件应显示为不可操作。 */
pending: boolean;
+ /** 在途的深度 / Fast 目标值;渲染该锚点的行配置时覆盖上去。 */
+ optimistic: UnifiedOptimisticConfig | null;
runExternal: (action: () => ActionResult) => ActionResult;
applyEngine: (
anchor: UnifiedAnchor,
@@ -202,41 +240,129 @@ export interface UnifiedRowActions {
) => ActionResult;
}
+/**
+ * 非深度 / Fast 的异步写入超过这个时长才把控件显示为不可操作。本机写入通常几十毫秒就
+ * 落地,立即置灰只会造成一闪;这段时间里的点击不会被丢掉,而是排队(见 exclusive)。
+ */
+export const PENDING_VISIBLE_DELAY_MS = 400;
+
+type ActionName =
+ | 'runExternal'
+ | 'applyEngine'
+ | 'applyEffort'
+ | 'applyFast'
+ | 'resetToRecommended'
+ | 'addFavorite'
+ | 'removeFavorite'
+ | 'selectRow';
+
export function useUnifiedRowActions(options: UnifiedRowActionsOptions): UnifiedRowActions {
- // 同一个面板一次只提交一份配置。ref 同步挡住连点,pending 让控件显示不可操作;
- // 锁覆盖确认、写入、回滚和收藏收尾,避免后发请求先完成再被旧回执覆盖。
+ // 同一个面板一次只提交一份配置,避免后发请求先完成再被旧回执覆盖;锁覆盖确认、写入、
+ // 回滚和收藏收尾。在途时控件看上去可点就一定接得住:新的点击进队列,不静默丢弃 ——
+ // 深度 / Fast 按「行 + 维度」各留最新一笔,其余动作只留最新一个,按先后顺序依次提交。
const busy = useRef(false);
const mounted = useRef(true);
const [pending, setPending] = useState(false);
+ // 深度 / Fast 写入在途(含排队)时,目标值先画在那一行上:滑杆松手即停在新档,
+ // 不回弹到旧值再等回执。整条写入链空闲(或失败)即清除,之后以真实状态为准。
+ const [optimistic, setOptimistic] = useState<UnifiedOptimisticConfig | null>(null);
+ const queue = useRef(new Map<string, { name: ActionName; args: unknown[] }>());
+ // 排队的只是参数:上一笔落定后等一次渲染再提交,走最新一次渲染的动作,拿到上一笔
+ // 刚写入的实时值,而不是点击那一刻闭包里的旧值。
+ const latestRuns = useRef<Partial<Record<ActionName, (args: unknown[]) => ActionResult>>>({});
+ const [drainSignal, setDrainSignal] = useState(0);
useEffect(() => {
mounted.current = true;
return () => {
mounted.current = false;
};
}, []);
- const exclusive =
- <A extends unknown[]>(action: (...args: A) => ActionResult) =>
- (...args: A): ActionResult => {
- if (busy.current || options.interactionDisabled) return false;
+ const mergeOptimistic = (adjustment: UnifiedOptimisticConfig) =>
+ setOptimistic((current) =>
+ current?.anchorKey === adjustment.anchorKey ? { ...current, ...adjustment } : adjustment,
+ );
+ /** 写入链空闲:清掉排队残留的目标值显示,交回真实状态。 */
+ const settleIdle = () => {
+ busy.current = false;
+ setOptimistic(null);
+ };
+ /** 依次提交排队项,直到遇到一笔异步写入(它落定后会再次触发)或队列清空。 */
+ const drainQueue = () => {
+ for (;;) {
+ const [key] = queue.current.keys();
+ if (key === undefined) return settleIdle();
+ const next = queue.current.get(key)!;
+ queue.current.delete(key);
+ busy.current = false;
+ latestRuns.current[next.name]?.(next.args);
+ if (busy.current) return;
+ }
+ };
+ useEffect(() => {
+ if (drainSignal > 0) drainQueue();
+ // drainQueue 每次渲染都是新函数,但只在落定信号变化时执行一次。
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [drainSignal]);
+ const exclusive = <A extends unknown[]>(
+ name: ActionName,
+ action: (...args: A) => ActionResult,
+ adjustmentOf?: (...args: A) => UnifiedOptimisticConfig,
+ ) => {
+ const run = (...args: A): ActionResult => {
+ if (options.interactionDisabled) {
+ queue.current.clear();
+ return false;
+ }
busy.current = true;
+ const target = adjustmentOf?.(...args) ?? null;
try {
const result = action(...args);
- if (result && typeof result === 'object' && 'then' in result) {
- setPending(true);
- return Promise.resolve(result)
- .catch(() => false)
- .finally(() => {
- busy.current = false;
- if (mounted.current) setPending(false);
- });
+ if (!(result && typeof result === 'object' && 'then' in result)) {
+ busy.current = false;
+ return result;
}
- busy.current = false;
- return result;
+ if (target) mergeOptimistic(target);
+ const pendingTimer = target
+ ? null
+ : setTimeout(() => {
+ if (mounted.current) setPending(true);
+ }, PENDING_VISIBLE_DELAY_MS);
+ return Promise.resolve(result)
+ .catch(() => false as const)
+ .then((outcome) => {
+ if (pendingTimer !== null) clearTimeout(pendingTimer);
+ // 这笔没写成时丢掉排队项:调用方已提示失败,不在失败后悄悄接着改。
+ if (outcome === false || !mounted.current) queue.current.clear();
+ if (!mounted.current) {
+ busy.current = false;
+ return outcome;
+ }
+ setPending(false);
+ // 有排队项时锁不放开(新点击继续进队列,不插到前面),等下一次渲染后提交。
+ if (queue.current.size > 0) setDrainSignal((signal) => signal + 1);
+ else settleIdle();
+ return outcome;
+ });
} catch {
busy.current = false;
return false;
}
};
+ latestRuns.current[name] = (queued) => run(...(queued as A));
+ return (...args: A): ActionResult => {
+ if (options.interactionDisabled) return false;
+ if (!busy.current) return run(...args);
+ const target = adjustmentOf?.(...args);
+ const key = target
+ ? `${target.effort !== undefined ? 'effort' : 'fast'}:${target.anchorKey}`
+ : 'other';
+ // 先删再插:被替换的项移到队尾,排队顺序始终等于最后一次点击的先后。
+ queue.current.delete(key);
+ queue.current.set(key, { name, args });
+ if (target) mergeOptimistic(target);
+ return undefined;
+ };
+ };
const {
interactionDisabled,
isLiveRow,
@@ -402,7 +528,7 @@ export function useUnifiedRowActions(options: UnifiedRowActionsOptions): Unified
*/
favoriteUid: string | null;
onApplied: () => void | Promise<void>;
- }): Promise<void> => {
+ }): Promise<void | false> => {
if (!sessionEngineFilter) return Promise.resolve();
return runLive(() =>
(sessionEngineFilter.onCrossEngineConfigure ?? sessionEngineFilter.onCrossEngineSelect)({
@@ -417,11 +543,11 @@ export function useUnifiedRowActions(options: UnifiedRowActionsOptions): Unified
(applied) => {
// 只有明确的 false 表示「没切」(见 UnifiedModelPanelProps.onCrossEngineSelect);
// 返回 void 的调用方视为已切。
- if (applied === false) return;
+ if (applied === false) return false;
return args.onApplied();
},
// 事务抛错(切换失败)同样按「没应用」处理。
- () => {},
+ () => false as const,
);
};
@@ -497,9 +623,10 @@ export function useUnifiedRowActions(options: UnifiedRowActionsOptions): Unified
}
};
if (args.live && isLiveRow(args.entry, args.config)) {
- return args.live().then((applied) => {
+ return args.live().then(async (applied) => {
if (applied) return commitOrRestore(async () => { await args.rollback?.(); });
- if (args.rollback) return args.rollback();
+ await args.rollback?.();
+ return false;
});
}
const wireModelId = args.target.wireModelId ?? args.anchor.modelId;
@@ -532,8 +659,9 @@ export function useUnifiedRowActions(options: UnifiedRowActionsOptions): Unified
favoriteUid: args.uid,
rowModelId: args.anchor.modelId,
}),
- ).then((applied) => {
- if (applied) return commitOrRestore(() => (onConfigure ?? onSelect)(
+ ).then((applied): ActionResult => {
+ if (!applied) return false;
+ return commitOrRestore(() => (onConfigure ?? onSelect)(
args.anchor.providerId, args.config.wireModelId ?? args.anchor.modelId,
args.config.effort ?? '', {
engine: args.config.engine, fast: args.config.fast,
@@ -650,7 +778,8 @@ export function useUnifiedRowActions(options: UnifiedRowActionsOptions): Unified
rowModelId: anchor.modelId,
}),
).then((applied) => {
- if (applied) setModelEngineOverride(anchor.providerId, anchor.modelId, engine);
+ if (!applied) return false;
+ setModelEngineOverride(anchor.providerId, anchor.modelId, engine);
});
}
return;
@@ -688,7 +817,8 @@ export function useUnifiedRowActions(options: UnifiedRowActionsOptions): Unified
// (见 clearFavoriteAnchorForLiveRow 的头注)。顺序与本文件其它入口一致:先应用、后落状态。
if (selectedFavoriteUid && onSelectedFavoriteAnchorClear) {
return runLive(() => onEffortChangeLive(effort)).then((applied) => {
- if (applied) return clearFavoriteAnchorForLiveRow(anchor, { ...config, effort });
+ if (!applied) return false;
+ return clearFavoriteAnchorForLiveRow(anchor, { ...config, effort });
});
}
// 选中行的深度是会话实时状态,交给调用方持久化(与旧版 handleEditEffort 同语义)。
@@ -736,7 +866,8 @@ export function useUnifiedRowActions(options: UnifiedRowActionsOptions): Unified
// 同 applyEffort:改的是**普通模型行**的实时 Fast,而当前选中的是一条收藏 → 写成功后清锚点。
if (selectedFavoriteUid && onSelectedFavoriteAnchorClear) {
return runLive(() => onFastModeChangeLive(enabled)).then((applied) => {
- if (applied) return clearFavoriteAnchorForLiveRow(anchor, { ...config, fast: enabled });
+ if (!applied) return false;
+ return clearFavoriteAnchorForLiveRow(anchor, { ...config, fast: enabled });
});
}
// 选中行的 Fast 必须等调用方持久化成功后再由上层同步草稿;这里绝不预写 modelMemory
@@ -837,7 +968,8 @@ export function useUnifiedRowActions(options: UnifiedRowActionsOptions): Unified
effort: defaultEffort,
}),
).then((applied) => {
- if (applied) resetStoredConfig();
+ if (!applied) return false;
+ resetStoredConfig();
});
}
@@ -851,7 +983,7 @@ export function useUnifiedRowActions(options: UnifiedRowActionsOptions): Unified
// 反过来先清后写,一旦远程 setEffort / setFastMode 失败,override 与记忆已经没了、
// 任务还在旧配置上跑 —— 面板显示的推荐态与事实分家,且没有可回滚的原值。
return applyDefaultsLive(defaultEffort).then((applied) => {
- if (!applied) return;
+ if (!applied) return false;
resetStoredConfig();
return clearFavoriteAnchorForLiveRow(anchor, {
...config,
@@ -939,8 +1071,9 @@ export function useUnifiedRowActions(options: UnifiedRowActionsOptions): Unified
wireModelId,
effort: fallback.effort,
}),
- ).then((applied) => {
- if (applied) return commit();
+ ).then((applied): ActionResult => {
+ if (!applied) return false;
+ return commit();
});
}
// 会话内回落:默认引擎 ≠ 正在跑的引擎,或正挂着待发送意图,都走切换事务。
@@ -962,8 +1095,9 @@ export function useUnifiedRowActions(options: UnifiedRowActionsOptions): Unified
}
// 会话 + 默认引擎 == 正在跑的引擎,且没有待发送意图:无损,两个 live 回调把深度 / Fast 复位。
// 与跨引擎分支同一条顺序:**live 真写成了才**删记录。
- return applyDefaultsLive(fallback.effort).then((applied) => {
- if (applied) return commit();
+ return applyDefaultsLive(fallback.effort).then((applied): ActionResult => {
+ if (!applied) return false;
+ return commit();
});
};
@@ -1011,13 +1145,20 @@ export function useUnifiedRowActions(options: UnifiedRowActionsOptions): Unified
return {
pending,
- runExternal: exclusive((action: () => ActionResult) => action()),
- applyEngine: exclusive(applyEngine),
- applyEffort: exclusive(applyEffort),
- applyFast: exclusive(applyFast),
- resetToRecommended: exclusive(resetToRecommended),
- addFavorite: exclusive(addFavorite),
- removeFavorite: exclusive(removeFavorite),
- selectRow: exclusive(selectRow),
+ optimistic,
+ runExternal: exclusive('runExternal', (action: () => ActionResult) => action()),
+ applyEngine: exclusive('applyEngine', applyEngine),
+ applyEffort: exclusive('applyEffort', applyEffort, (anchor, _entry, _config, effort) => ({
+ anchorKey: anchorKey(anchor),
+ effort,
+ })),
+ applyFast: exclusive('applyFast', applyFast, (anchor, _entry, _config, enabled) => ({
+ anchorKey: anchorKey(anchor),
+ fast: enabled,
+ })),
+ resetToRecommended: exclusive('resetToRecommended', resetToRecommended),
+ addFavorite: exclusive('addFavorite', addFavorite),
+ removeFavorite: exclusive('removeFavorite', removeFavorite),
+ selectRow: exclusive('selectRow', selectRow),
};
}
diff --git a/docs/product-rules/model-selector-unified.md b/docs/product-rules/model-selector-unified.md
index 74de99df01..11c1f24eac 100644
--- a/docs/product-rules/model-selector-unified.md
+++ b/docs/product-rules/model-selector-unified.md
@@ -223,6 +223,17 @@
- `providerModelMemory` snapshot 原样进 `RemoteNewMakerDefaults` wire——**不改其 schema**;新 store 不进该 payload(老控制端看不到引擎 override 属可接受降级,新被控端按 override 生效,四格矩阵在 PR 写明)。
- 旧控制端 `maker:set-session-model-pref` 与新 `apply-new-maker-draft-pref` 双写桥保留。
- `pendingRemoteSwitch` 5s 兜底、`remoteSwitchInFlight` 绑 ack、镜像不写控制端本地记忆——原样保留。
+ 例外:**统一面板发起的**只改深度(模型 / 来源不变,`serializedByPanel`)不置 `remoteSwitchInFlight`,
+ 靠 `pendingRemoteSwitch` 乐观显示,调档期间 selector 保持可操作,顺序由面板的单笔提交保证;
+ 平铺选择器、快捷键等没有这层串行的入口仍在隧道 await 期间置灰。远程深度写入不进本机 effort
+ commit lane(该 lane 的已提交值不随远程回流更新)。
+- 面板里深度 / Fast 写入在途时行上先显示目标值(`withOptimisticConfig`),且可继续调。写入在途时
+ 看上去可点的控件一定接得住:点击进队列而非静默丢弃 —— 深度 / Fast 按「行 + 维度」各留最新一笔,
+ 其余动作只留最新一个,上一笔落定并重新渲染后按先后提交(用最新闭包),失败则丢弃排队项;
+ 非深度 / Fast 写入超过 400ms 才显示为不可操作。队列以「失败即回报 false」为判据:所有「先应用、
+ 后收尾」路径(跨引擎事务、恢复推荐、收藏编辑 / 删除、清锚点)没写成时都必须 resolve false。
+ 已知边界(刻意不处理):上一笔深度在途时再调档并立即发送,这一轮用的是在途那一档,排队的新档
+ 在落定后才提交、从下一轮起生效。
- SSH:`excludeSubscriptionDirect`/`excludeChatBridgedCodex` 只在 remoteHostId 非空时开;device-link 下 CreateWorkerPopover 外置 Fast 开关不能删。
- 老被控端 capabilities-only flat fallback(`resolveRemoteModelListStatus`)保留。