Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 思考档位投影跟随进程实测值,目录误判不再渲染成假「低」 (#5780)
Yunjin Zhang935c8555455d
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/runtimeSelectionAxes.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/runtimeSelectionAxes.test.tsindex cd385520eb..5de5db9abb 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/runtimeSelectionAxes.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/runtimeSelectionAxes.test.ts@@ -17,7 +17,10 @@ describe('isSupportedRuntimeEffort', () => {});describe('resolveRetainedRuntimeEffort', () => {- it('clears stale live effort for a fixed-effort target', () => {+ it('keeps the observed live effort even when the target is judged fixed-effort', () => {+ // The retained process still runs at its live level, so the projection+ // must describe that state; a catalog-derived fixed-effort guess must not+ // overwrite it with a sticky null.expect(resolveRetainedRuntimeEffort({targetModelHasFixedEffort: true,@@ -25,7 +28,10 @@ describe('resolveRetainedRuntimeEffort', () => {liveEffort: 'ultra',previousEffort: 'high',}),- ).toBeNull();+ ).toBe('ultra');+ });++ it('clears effort for an explicit fixed-effort carrier and for a fixed target without live effort', () => {expect(resolveRetainedRuntimeEffort({targetModelHasFixedEffort: true,@@ -34,6 +40,14 @@ describe('resolveRetainedRuntimeEffort', () => {previousEffort: 'high',}),).toBeNull();+ expect(+ resolveRetainedRuntimeEffort({+ targetModelHasFixedEffort: true,+ requestedEffort: undefined,+ liveEffort: null,+ previousEffort: 'high',+ }),+ ).toBeNull();});it('uses the retained live effort before the previous store for variable-effort models', () => {diff --git a/apps/desktop/src/main/maker-ipc/runtimeSelectionAxes.ts b/apps/desktop/src/main/maker-ipc/runtimeSelectionAxes.tsindex 4115b33bec..de5198509b 100644--- a/apps/desktop/src/main/maker-ipc/runtimeSelectionAxes.ts+++ b/apps/desktop/src/main/maker-ipc/runtimeSelectionAxes.ts@@ -12,12 +12,19 @@ export function resolveRetainedRuntimeEffort(input: {liveEffort: Effort | null;previousEffort: Effort | null | undefined;}): Effort | null {- // Catalog capability is the request contract. A close failure leaves the old- // handle in Session status=error, and the next send rebuilds it instead of- // reusing its stale mutable effort, so never project that stale value onto a- // fixed-effort model.- if (input.targetModelHasFixedEffort || input.requestedEffort === null) return null;+ // An explicit null carrier means a fixed-effort target was selected on+ // purpose; nothing is representable.+ if (input.requestedEffort === null) return null;+ // The retained process is still running with its own effort, so the+ // projection must describe that observed state. A capability lookup can+ // transiently misreport a variable-effort model as fixed-effort (e.g. right+ // after a remote catalog reload), and letting that guess override the live+ // effort writes a sticky null that renders as a fake level while the process+ // keeps running at its real one.if (input.liveEffort !== null) return input.liveEffort;+ // No observable live effort: a fixed-effort target has no representable+ // value, so clear instead of carrying the previous model's level over.+ if (input.targetModelHasFixedEffort) return null;return input.previousEffort ?? null;}diff --git a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsxindex 21ddf6d7ff..2b73b882cb 100644--- a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx+++ b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx@@ -1769,7 +1769,9 @@ export function ChatInput({optimistic: pendingRemoteSwitch,});const activeModel = composerSelection.display.model;- const activeEffort = composerSelection.display.effort ?? 'low';+ // null = 投影未知/不可调档:回落到会话已持久化的档位(与运行实况一致),不能兜底成+ // 字面量 'low'——该值会随下一条发送作为用户选择下发,把假档位写成真档位。+ const activeEffort = composerSelection.display.effort ?? initialEffort ?? 'low';const activePermissionMode: PermissionMode =initialPermissionMode ?? localVendorDefaults.permissionMode;diff --git a/apps/desktop/src/renderer/components/new-chat/__tests__/chatInputModelLoading.test.tsx b/apps/desktop/src/renderer/components/new-chat/__tests__/chatInputModelLoading.test.tsxindex ae383401f6..b44b713778 100644--- a/apps/desktop/src/renderer/components/new-chat/__tests__/chatInputModelLoading.test.tsx+++ b/apps/desktop/src/renderer/components/new-chat/__tests__/chatInputModelLoading.test.tsx@@ -11,7 +11,7 @@ import * as providerMemory from '@/state/providerModelMemory';import * as draftMemory from '@/state/newMakerDraft';const h = vi.hoisted(() => ({ t: (key: string) => key, confirm: vi.fn(), editor: null as Editor | null, listening: false, stop: vi.fn().mockResolvedValue(undefined),- setModel: vi.fn(), selectModel: undefined as undefined | ((id: string) => Promise<void | boolean>), remoteProviders: [] as ProviderView[],+ setModel: vi.fn(), selectModel: undefined as undefined | ((id: string) => Promise<void | boolean>), selectEffort: undefined as string | null | undefined, remoteProviders: [] as ProviderView[],remoteStatus: 'ready' as 'ready' | 'loading' | 'error',}));vi.mock('react-i18next', async (original) => ({ ...await original<typeof import('react-i18next')>(), useTranslation: () => ({ t: h.t }) }));@@ -38,8 +38,9 @@ vi.mock('@/components/sidebar/SortableList', () => ({</div>),}));-vi.mock('../ModelSelector', async (original) => ({ ...await original<typeof import('../ModelSelector')>(), ModelSelector: ({ modelId, onModelChange, disabled }: { modelId: string; onModelChange: typeof h.selectModel; disabled?: boolean }) => {+vi.mock('../ModelSelector', async (original) => ({ ...await original<typeof import('../ModelSelector')>(), ModelSelector: ({ modelId, onModelChange, disabled, effort }: { modelId: string; onModelChange: typeof h.selectModel; disabled?: boolean; effort?: string | null }) => {h.selectModel = onModelChange;+ h.selectEffort = effort;return <button data-testid="model-selector" disabled={disabled}>{modelId}</button>;} }));vi.mock('@/hooks/useSshCodexProviders', () => ({ useSshCodexProviders: () => ({ providers: h.remoteProviders, status: h.remoteStatus, refresh: () => {} }) }));@@ -88,7 +89,7 @@ const attachments: ComponentProps<typeof ChatInput>['attachmentState'] = {pendingFileMentionsVersion: 0, consumePendingFileMentions: () => [],removeFile: noOp, updateFile: noOp, discardFiles: noOp, clearFiles: noOp, restoreFiles: (files) => [...files],};-beforeEach(() => { h.listening = false; h.stop.mockClear(); window.electronAPI = api; vi.stubGlobal('ResizeObserver', class { observe() {} unobserve() {} disconnect() {} }); });+beforeEach(() => { h.listening = false; h.stop.mockClear(); h.selectEffort = undefined; window.electronAPI = api; vi.stubGlobal('ResizeObserver', class { observe() {} unobserve() {} disconnect() {} }); });afterEach(() => { cleanup(); h.remoteProviders = []; h.remoteStatus = 'ready'; h.setModel.mockReset(); h.confirm.mockReset(); vi.unstubAllGlobals(); vi.restoreAllMocks(); });const props = {@@ -197,6 +198,20 @@ it('sends a remote-only Codex model when the controller has no connected provideexpect(onSend.mock.calls[0][6]).toEqual(expect.objectContaining({ providerId: 'openai' }));});+// 回归:投影 effort 为 null(目录误判/不可调档)时选择器回落会话已持久化档位,+// 不能兜底成字面量 'low';投影有值时仍优先投影值。+it.each([+ ['null projection with the persisted session effort instead of a literal low', null, 'high', 'high'],+ ['the projected effort wins over the initial prop when present', 'medium', 'high', 'medium'],+] as const)('renders %s', async (_name, projectedEffort, initialEffort, expected) => {+ h.remoteProviders = [sshNativeCodexProvider([sshModel('remote-only')])];+ render(<ChatInput {...props} hideRuntimeControls={false} sessionId="ssh-effort-fallback" deviceLinkDeviceId={null} remoteHostId="builder"+ initialModel="remote-only" initialProviderId="openai" initialEffort={initialEffort}+ runtimeEffective={{ agentKind: 'codex', model: 'remote-only', providerId: 'openai', effort: projectedEffort, fastMode: false }}+ onSend={vi.fn()} />);+ await waitFor(() => expect(h.selectEffort).toBe(expected));+});+it.each([['button', 'openai'], ['Enter', 'openai'], ['button', null], ['Enter', null],] as const)('sends a hidden existing SSH model through %s with provider %s', async (entry, providerId) => {