Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
fix(models): hold hosted-tool writes on a stale report and name a lost save's outcome as unknown (#2822)
Call White1e2e7f5934d2
diff --git a/tests/scenarios/model_hub/catalog.yaml b/tests/scenarios/model_hub/catalog.yamlindex 78dab429d..1feaf95f5 100644--- a/tests/scenarios/model_hub/catalog.yaml+++ b/tests/scenarios/model_hub/catalog.yaml@@ -499,7 +499,7 @@ scenarios:- 'ui/src/components/settings/models/hostedTools.test.ts::MH-HOSTED-UI-006: gives a Source model one capability per feature, a call refusal hiding the success and the replay'- 'ui/src/components/settings/models/hostedTools.test.ts::MH-HOSTED-UI-006: gives a Source model one capability per tool with a record, in catalog order'- id: MH-HOSTED-UI-007- name: Hosted-tool writes and clears run one at a time and a read never overlaps one, so the screen holds the newest committed state+ name: Hosted-tool writes and clears run one at a time and a read never overlaps one, so the screen holds the newest committed state; no control builds on a report being re-read or kept after a failed read, and only a refusal the server named is announced as a failurestatus: coveredkind: concurrencylayer: unit@@ -515,6 +515,11 @@ scenarios:- 'ui/src/components/settings/models/useHostedTools.test.tsx::MH-HOSTED-UI-007: drops a write answer asked under another Source identity'- 'ui/src/components/settings/models/useHostedTools.test.tsx::MH-HOSTED-UI-007: keeps a tool pending until every write queued for it has settled'- 'ui/src/components/settings/models/useHostedTools.test.tsx::MH-HOSTED-UI-007: queues a clear behind a write like any write, so its answer lands last'+ - 'ui/src/components/settings/models/useHostedTools.test.tsx::MH-HOSTED-UI-007: holds every tool while the report is re-read, and after that read fails, until a read lands'+ - 'ui/src/components/settings/models/useHostedTools.test.tsx::MH-HOSTED-UI-007: names the outcome of a save that ended in a refusal the server named'+ - 'ui/src/components/settings/models/useHostedTools.test.tsx::MH-HOSTED-UI-007: names the outcome of a save that ended in a lost answer'+ - 'ui/src/components/settings/models/useHostedTools.test.tsx::MH-HOSTED-UI-007: names the outcome of a save that ended in an engine whose answer never reached the UI process'+ - 'ui/src/components/settings/models/useHostedTools.test.tsx::MH-HOSTED-UI-007: names the outcome of a save that ended in no answer at all'- id: MH-HOSTED-UI-018name: Every hosted tool is on by default under its capability group, and nothing locks its switchstatus: covereddiff --git a/ui/src/components/settings/models/useHostedTools.test.tsx b/ui/src/components/settings/models/useHostedTools.test.tsxindex da020df54..0b21ed7f6 100644--- a/ui/src/components/settings/models/useHostedTools.test.tsx+++ b/ui/src/components/settings/models/useHostedTools.test.tsx@@ -3,13 +3,13 @@// the whole status, so what is on screen must be the newest state the server// committed, whatever order the requests happen to return in.import * as React from 'react';-import { act, cleanup, renderHook, waitFor } from '@testing-library/react';+import { act, cleanup, renderHook, screen, waitFor } from '@testing-library/react';import { I18nextProvider } from 'react-i18next';import { afterEach, describe, expect, it, vi } from 'vitest';import { ToastProvider } from '@/context/ToastProvider';import i18n from '@/i18n';-import { modelsApi } from './modelsApi';+import { ApiCallError, modelsApi } from './modelsApi';import { foldRegionRead, type RegionRead } from './regionRead';import type { HostedToolsStatus } from './types';import { useHostedTools } from './useHostedTools';@@ -185,6 +185,43 @@ describe('useHostedTools ordering', () => {expect(result.current.pending.has('web_search')).toBe(false);});+ it('MH-HOSTED-UI-007: holds every tool while the report is re-read, and after that read fails, until a read lands', async () => {+ const reread = deferred<HostedToolsStatus>();+ vi.spyOn(modelsApi, 'getHostedTools')+ .mockResolvedValueOnce(status(false))+ .mockReturnValueOnce(reread.promise)+ .mockResolvedValueOnce(status(true));+ const { result } = renderHook(() => useHostedTools(true), { wrapper });+ await waitFor(() => expect(shown(result.current.read)).toBe(false));++ // An engine or Source change asks for a re-read: what is shown may no longer be what the server holds.+ let refreshing!: Promise<void>;+ act(() => { refreshing = result.current.refresh(); });+ expect(result.current.pending.has('web_search')).toBe(true);+ await act(async () => { reread.reject(new Error('offline')); await refreshing; });+ expect(result.current.read.kind).toBe('degraded');+ expect(result.current.pending.has('web_search')).toBe(true);++ await act(async () => { await result.current.refresh(); });+ expect(shown(result.current.read)).toBe(true);+ expect(result.current.pending.has('web_search')).toBe(false);+ });++ it.each([+ ['a refusal the server named', new ApiCallError('tool_unavailable', undefined, true), "Couldn't save the web search setting. Please retry."],+ ['a lost answer', new ApiCallError('http_502', undefined, false), "Couldn't confirm whether the web search setting was saved. It's being re-read from the server; check it before trying again."],+ ['an engine whose answer never reached the UI process', new ApiCallError('engine_down'), "Couldn't confirm whether the web search setting was saved. It's being re-read from the server; check it before trying again."],+ ['no answer at all', new TypeError('Failed to fetch'), "Couldn't confirm whether the web search setting was saved. It's being re-read from the server; check it before trying again."],+ ])('MH-HOSTED-UI-007: names the outcome of a save that ended in %s', async (_case, error, notice) => {+ vi.spyOn(modelsApi, 'getHostedTools').mockResolvedValue(status(false));+ vi.spyOn(modelsApi, 'putHostedTool').mockRejectedValue(error);+ const { result } = renderHook(() => useHostedTools(true), { wrapper });+ await waitFor(() => expect(shown(result.current.read)).toBe(false));++ await act(async () => { await result.current.save('web_search', { enabled: true }); });+ await screen.findByText(notice);+ });+it('MH-HOSTED-UI-007: drops a write answer asked under another Source identity', async () => {const put = deferred<HostedToolsStatus>();vi.spyOn(modelsApi, 'getHostedTools').mockResolvedValueOnce(status(false)).mockRejectedValue(new Error('offline'));diff --git a/ui/src/components/settings/models/useHostedTools.ts b/ui/src/components/settings/models/useHostedTools.tsindex a1a7e7228..ea56066c2 100644--- a/ui/src/components/settings/models/useHostedTools.ts+++ b/ui/src/components/settings/models/useHostedTools.ts@@ -2,8 +2,9 @@ import * as React from 'react';import { useTranslation } from 'react-i18next';import { useToast } from '@/context/ToastContext';-import { modelsApi } from './modelsApi';-import { beginRegionRead, loadingRegion, readRegion, readyRegion, settleRegionRead, type RegionRead } from './regionRead';+import { classifyModelHubFailure } from './asyncLifetime';+import { apiFailure, modelsApi } from './modelsApi';+import { beginRegionRead, foldRegionRead, loadingRegion, readRegion, readyRegion, settleRegionRead, type RegionRead } from './regionRead';import type { HostedToolClear, HostedToolName, HostedToolPut, HostedToolsStatus } from './types';/**@@ -22,13 +23,15 @@ import type { HostedToolClear, HostedToolName, HostedToolPut, HostedToolsStatus* already out when a write is queued is dropped, because it cannot tell* whether it saw that write.*- * `pending` comes from one per-tool ledger and nowhere else. A tool is pending- * while a write for it is queued or out, or while a write for it ended without- * an answer and no authoritative status has landed since: that write may have- * committed, so no control may build a body on what is shown. Only an- * authoritative status ends that wait: a write's answer or a read that landed.- * Each is the whole status and newer than every write before it, so it covers- * every tool. A read that failed or was dropped covers nothing.+ * `pending` comes from one per-tool ledger and the report's freshness. A tool+ * is pending while a write for it is queued or out, or while a write for it+ * ended without an answer and no authoritative status has landed since: that+ * write may have committed, so no control may build a body on what is shown.+ * Only an authoritative status ends that wait: a write's answer or a read that+ * landed. Each is the whole status and newer than every write before it, so it+ * covers every tool. A read that failed or was dropped covers nothing. A report+ * that is itself out of date (being re-read, or kept after its read failed)+ * holds every tool it shows the same way, for the same reason.*/export function useHostedTools(active: boolean, revision: string | null = null) {const { t } = useTranslation();@@ -92,7 +95,7 @@ export function useHostedTools(active: boolean, revision: string | null = null)const write = React.useCallback(async (tool: HostedToolName,send: () => Promise<HostedToolsStatus>,- failure: 'saveFailed' | 'clearFailed',+ failure: 'save' | 'clear',) => {const clock = order.current;clock.writes += 1;@@ -110,13 +113,17 @@ export function useHostedTools(active: boolean, revision: string | null = null)} else {clock.rereadAfterWrites = true;}- } catch {+ } catch (error) {// A refused write changed nothing, and a lost answer may have committed;- // either way the tab converges on what the server now holds.+ // either way the tab converges on what the server now holds. Only a+ // decided refusal is a failure: a lost answer is an unknown outcome.clock.rereadAfterWrites = true;entry(tool).awaiting = true;if (alive.current) {- showToast(t(`settings.models.tools.${failure}`, { toolInline: t(`settings.models.tools.tool.${tool}.inline`) }) as string, 'error');+ const toolInline = t(`settings.models.tools.tool.${tool}.inline`);+ // `engine_down` is inconclusive too: the UI process also says it when the engine's answer never reached it.+ if (classifyModelHubFailure(apiFailure(error)) === 'inconclusive') showToast(t(`settings.models.tools.${failure}Unconfirmed`, { toolInline }) as string, 'warning');+ else showToast(t(`settings.models.tools.${failure}Failed`, { toolInline }) as string, 'error');}}});@@ -133,14 +140,21 @@ export function useHostedTools(active: boolean, revision: string | null = null)/** Change the fields `body` names; an absent field stays as saved. */const save = React.useCallback(- (tool: HostedToolName, body: HostedToolPut) => write(tool, () => modelsApi.putHostedTool(tool, body), 'saveFailed'),+ (tool: HostedToolName, body: HostedToolPut) => write(tool, () => modelsApi.putHostedTool(tool, body), 'save'),[write],);/** Clear refusals: from the next request the tool is tried natively again there. */const clear = React.useCallback(- (tool: HostedToolName, body: HostedToolClear) => write(tool, () => modelsApi.clearHostedTool(tool, body), 'clearFailed'),+ (tool: HostedToolName, body: HostedToolClear) => write(tool, () => modelsApi.clearHostedTool(tool, body), 'clear'),[write],);- return { read, pending, refresh, save, clear };+ const held = React.useMemo<ReadonlySet<HostedToolName>>(() => foldRegionRead(read, {+ loading: () => pending,+ ready: () => pending,+ unread: () => pending,+ degraded: (stale) => new Set([...pending, ...stale.tools.map((tool) => tool.name)]),+ }), [read, pending]);++ return { read, pending: held, refresh, save, clear };}diff --git a/ui/src/i18n/en.json b/ui/src/i18n/en.jsonindex 5d511bcaa..99c6a6671 100644--- a/ui/src/i18n/en.json+++ b/ui/src/i18n/en.json@@ -2460,7 +2460,9 @@},"footnote": "Costs are estimated at the vendor's API price, and a relay may bill differently. Subscriptions add no charge. A Claude subscription can't run these tools.","saveFailed": "Couldn't save the {{toolInline}} setting. Please retry.",- "clearFailed": "Couldn't clear the {{toolInline}} refusal. Please retry."+ "saveUnconfirmed": "Couldn't confirm whether the {{toolInline}} setting was saved. It's being re-read from the server; check it before trying again.",+ "clearFailed": "Couldn't clear the {{toolInline}} refusal. Please retry.",+ "clearUnconfirmed": "Couldn't confirm whether the {{toolInline}} refusal was cleared. It's being re-read from the server; check it before trying again."},"capability": {"readFailed": "Couldn't read this Source's tool capabilities.",diff --git a/ui/src/i18n/zh.json b/ui/src/i18n/zh.jsonindex 8753814db..686f8886a 100644--- a/ui/src/i18n/zh.json+++ b/ui/src/i18n/zh.json@@ -2460,7 +2460,9 @@},"footnote": "费用按厂商 API 标价估算,中转的实际账单可能不同;订阅不另计费。Claude 订阅不能运行这些工具。","saveFailed": "{{toolInline}}设置未能保存,请重试。",- "clearFailed": "{{toolInline}}拒绝记录未能清除,请重试。"+ "saveUnconfirmed": "无法确认{{toolInline}}设置是否已保存,正在从服务器重新读取,请确认后再重试。",+ "clearFailed": "{{toolInline}}拒绝记录未能清除,请重试。",+ "clearUnconfirmed": "无法确认{{toolInline}}拒绝记录是否已清除,正在从服务器重新读取,请确认后再重试。"},"capability": {"readFailed": "未能读取此供应商的工具能力。",