Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 旧设备的迟到错误不再锁住新任务 + 远程不显示本机价格(#7011)
Zhang Yunjin721497aa8062
diff --git a/apps/desktop/src/renderer/components/status/ContextWindowBudgetChip.tsx b/apps/desktop/src/renderer/components/status/ContextWindowBudgetChip.tsxindex 9abeb15986..568474e381 100644--- a/apps/desktop/src/renderer/components/status/ContextWindowBudgetChip.tsx+++ b/apps/desktop/src/renderer/components/status/ContextWindowBudgetChip.tsx@@ -112,9 +112,14 @@ export function ContextWindowBudgetChip({const [committing, setCommitting] = useState(false);// 被控端不支持预算通道(老版本):卡转只读直到会话换设备。const [remoteUnsupported, setRemoteUnsupported] = useState(false);+ // 当前设备(供迟到的异步响应比对):组件在换设备时**不重挂**,所以 deviceId 变化+ // 后仍在飞的保存请求可能带回旧设备的 DEVICE_LINK_CHANNEL_NOT_ALLOWED —— 不比对就会+ // 把新任务(尤其是切换后的本地任务)误锁成只读(Greptile P1,2026-10-25)。+ const activeDeviceIdRef = useRef<string | undefined>(deviceId);useEffect(() => {// 换设备(远程→本地 / 换被控端)后重新探测支持状态。// 必须挂在组件的提前 return(约 :395)之前,否则 hooks 顺序随渲染路径漂移。+ activeDeviceIdRef.current = deviceId;setRemoteUnsupported(false);}, [deviceId]);// 卡片开合:**指针悬浮**展开(与货币 chip 的「用量明细」卡同一节奏:延迟 300ms 开、离开宽限@@ -400,8 +405,13 @@ export function ContextWindowBudgetChip({if (effectiveDefaultWindow === null || options.length === 0 || selectedTokens === null) return null;const agent = agentKind === 'cc' ? 'claude-code' : agentKind;- const quote = getModelPriceQuote(gatewayPricing, providerId, model, agent)- ?? getModelPriceQuote(referencePricing, providerId, model, agent);+ // 远程任务不显示价带:两份报价(gateway 服务端报价 + 本地参考价/用户覆盖)都来自+ // **本机**配置,被控端用的是它自己的 provider 连接与价格覆盖,同名模型的价可能不同+ // (Greptile P2,2026-10-25)。拿不到被控端报价时宁可不显示,也不给一个会误导的价。+ const quote = deviceId+ ? undefined+ : getModelPriceQuote(gatewayPricing, providerId, model, agent)+ ?? getModelPriceQuote(referencePricing, providerId, model, agent);// 当前档位占基准的百分比:与卡片行同一口径(默认档 = 100%)。const selectedPercent = contextWindowBudgetTierPercent(selectedTokens, tierBase);@@ -474,7 +484,8 @@ export function ContextWindowBudgetChip({const unsupported = extractIpcError(error)?.code === 'DEVICE_LINK_CHANNEL_NOT_ALLOWED';// 被控端不支持该通道时记住状态:整卡转只读并说明原因,档位不再可点 ——// 反复提交必然失败的修改只会制造更多错误 toast(Greptile P2,2026-10-24)。- if (unsupported) setRemoteUnsupported(true);+ // 只有仍是同一个设备时才记这条「不支持」:换设备后这条错误已经过期。+ if (unsupported && activeDeviceIdRef.current === deviceId) setRemoteUnsupported(true);toast.error(unsupported? t('ccAgent.contextWindowBudget.remoteUnsupported')diff --git a/apps/desktop/src/renderer/components/status/__tests__/contextWindowBudgetChip.test.tsx b/apps/desktop/src/renderer/components/status/__tests__/contextWindowBudgetChip.test.tsxindex ff83f05cb2..3103115c89 100644--- a/apps/desktop/src/renderer/components/status/__tests__/contextWindowBudgetChip.test.tsx+++ b/apps/desktop/src/renderer/components/status/__tests__/contextWindowBudgetChip.test.tsx@@ -1280,6 +1280,69 @@ describe('ContextWindowBudgetChip — Greptile 2026-10-24 三条 P2', () => {expect(getBounds.mock.calls.length).toBeGreaterThanOrEqual(2);});+ it('hides the price band on remote tasks instead of showing local prices', async () => {+ // 两份报价(gateway 服务端报价 + 本地参考价/用户覆盖)都来自本机配置,被控端用的是+ // 它自己的连接与价格覆盖 —— 远程任务给本机价会误导用户按错价比较档位+ // (Greptile P2,2026-10-25)。+ mockGatewayPricing.mockReturnValue(tieredPricingCatalog);+ renderChip({ deviceId: 'device-a' });+ const options = await openTierCard();+ expect(options.length).toBeGreaterThan(0);+ expect(options.every((el) => !/\$\d/.test(el.textContent ?? ''))).toBe(true);++ // 同一份目录在本地任务上照旧显示价带(确认隐藏只发生在远程)。+ cleanup();+ renderChip();+ const localOptions = await openTierCard();+ expect(localOptions.some((el) => /\$\d/.test(el.textContent ?? ''))).toBe(true);+ });++ it('does not lock a new task when the previous device reports the channel too late', async () => {+ // 组件换设备时不重挂:旧设备的保存请求在切换之后才返回 CHANNEL_NOT_ALLOWED,+ // 无条件置位会把新任务(这里切成本地任务)误锁成只读(Greptile P1,2026-10-25)。+ let rejectSave: ((error: unknown) => void) | null = null;+ const invoke = vi.fn((_deviceId: string, channel: string) => {+ if (channel === 'maker:get-context-window-bounds') {+ return Promise.resolve(boundsView({+ budget: 150_000, budgetCustomized: true,+ defaultEffectiveWindow: 200_000, maxEffectiveWindow: 200_000,+ }));+ }+ return new Promise((_resolve, reject) => {+ rejectSave = reject;+ });+ });+ (window as unknown as { electronAPI: { deviceLink: { invoke: typeof invoke } } }).electronAPI = {+ deviceLink: { invoke },+ };+ const view = renderChip({ deviceId: 'device-a' });+ const options = await openTierCard();+ fireEvent.click(options.find((el) => el.getAttribute('data-token') === '200000')!);+ await waitFor(() => {+ expect(rejectSave).not.toBeNull();+ });++ // 用户切到本地任务(同一组件实例,deviceId 消失)后才收到旧设备的拒绝。+ view.rerender(+ <ContextWindowBudgetChip+ sessionId={SESSION_ID}+ contextTokens={0}+ model="grok-4.6"+ providerId="xd"+ agentKind="cc"+ providers={routeCatalog}+ />,+ );+ await act(async () => {+ rejectSave!(Object.assign(new Error('channel not allowed'), {+ code: 'DEVICE_LINK_CHANNEL_NOT_ALLOWED',+ }));+ });++ expect(screen.queryByText('ccAgent.contextWindowBudget.remoteUnsupported')).toBeNull();+ expect(screen.queryAllByRole('radio').every((row) => !(row as HTMLButtonElement).disabled)).toBe(true);+ });+it('locks the card read-only after the device rejects the budget channel', async () => {// P2「不支持的设备仍可编辑」:CHANNEL_NOT_ALLOWED 之后只弹 toast 会让用户反复提交// 必然失败的修改。第二次失败前就必须整卡只读 + 卡内说明原因。