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(model-hub): require a current OpenCode menu baseline
cyh01b320a89164
diff --git a/docs/plans/model-hub-ui-spec.md b/docs/plans/model-hub-ui-spec.mdindex d04b884b1..f910090a0 100644--- a/docs/plans/model-hub-ui-spec.md+++ b/docs/plans/model-hub-ui-spec.md@@ -1488,7 +1488,7 @@ unable to outlive its surface, which is the cheaper answer wherever it is availa| `gateway.menu.search` `[derived]` | 搜索模型或供应商 | Search models or sources || `gateway.menu.selected` `[derived]` | 已选 {{selected}} / {{total}} | {{selected}} of {{total}} selected || `gateway.menu.empty` `[derived]` | 没有可供 OpenCode 选择的模型 | No eligible source models are available |-| `gateway.menu.inventoryUnavailable` `[derived]` | 暂时无法读取模型清单,请先重试供应商列表,再编辑此选择。 | Model inventory is unavailable. Retry the source list before editing this selection. |+| `gateway.menu.baselineUnavailable` `[derived]` | 模型菜单数据暂未更新,请等待刷新完成,或重试读取失败的区域后再编辑。 | Model menu data is not current. Wait for refresh, or retry the failed section before editing. || `gateway.menu.noMatch` `[derived]` | 没有匹配的模型 | No models match this search || `gateway.menu.save` `[derived]` | 保存选择 | Save selection || `gateway.menu.saving` `[derived]` | 正在保存… | Saving… |@@ -1869,10 +1869,12 @@ OpenCode identifier. Saving performs `PUT /api/models/agents/opencode/menu`; a smodel with no Route then appears as an ordinary row whose current-text slot reads`gateway.group.status.unconfigured`, and that row opens frame 02. The dialog preservesthe saved menu view, blocks dismissal while its write is outstanding, and retains the-draft after a failed save. The Source inventory must be an authoritative ready read before-the dialog enables search, selection, or save. An unread or failed inventory preserves the-stored `menu.checked` values, shows `gateway.menu.inventoryUnavailable`, and cannot issue-the menu `PUT`; stale or absent inventory is never interpreted as an empty selection.+draft after a failed save. Both inputs to the whole-menu write must be authoritative ready+reads before the dialog enables search, selection, or save: `AgentSupply` owns `menu`,+`standard_vendors` and eligibility, while `Source[]` owns the candidate inventory. Either+input being loading, unread or degraded preserves the stored `menu.checked` values, shows+`gateway.menu.baselineUnavailable`, and cannot issue the menu `PUT`; stale or absent data+is never interpreted as an empty selection.**Extreme data**diff --git a/ui/src/components/settings/models/OpenCodeMenuDialog.test.tsx b/ui/src/components/settings/models/OpenCodeMenuDialog.test.tsxindex 6aba3677d..11fe2298a 100644--- a/ui/src/components/settings/models/OpenCodeMenuDialog.test.tsx+++ b/ui/src/components/settings/models/OpenCodeMenuDialog.test.tsx@@ -5,8 +5,10 @@ import { I18nextProvider } from 'react-i18next';import { afterEach, describe, expect, it, vi } from 'vitest';import i18n from '@/i18n';+import { openCodeMenuBaselineReady } from './menuBaseline';import { modelsApi } from './modelsApi';import { OpenCodeMenuDialog } from './OpenCodeMenuDialog';+import { failRegionRead, readyRegion } from './regionRead';import type { AgentSupply, Source } from './types';const source = (overrides: Partial<Source> & Pick<Source, 'id' | 'vendor' | 'display_name'>): Source => ({@@ -82,7 +84,7 @@ describe('OpenCodeMenuDialog', () => {openagent={agent}sources={sources}- inventoryReady+ baselineReadyonClose={onClose}onSaved={onSaved}menuWrite={{ pending: false, track: async (work) => work() }}@@ -114,7 +116,7 @@ describe('OpenCodeMenuDialog', () => {openagent={{ ...agent, menu: { view: 'full', checked: ['openai/gpt-5.6-sol'] } }}sources={sources}- inventoryReady+ baselineReadyonClose={vi.fn()}onSaved={vi.fn()}menuWrite={{ pending: false, track: async (work) => work() }}@@ -137,7 +139,7 @@ describe('OpenCodeMenuDialog', () => {openagent={{ ...agent, menu: { view: 'featured', checked: ['openai/missing-model'] } }}sources={sources}- inventoryReady+ baselineReadyonClose={vi.fn()}onSaved={vi.fn()}menuWrite={{ pending: false, track: async (work) => work() }}@@ -159,7 +161,7 @@ describe('OpenCodeMenuDialog', () => {openagent={{ ...agent, menu: { view: 'featured', checked: ['openai/gpt-5.6-luna'] } }}sources={[]}- inventoryReady={false}+ baselineReady={false}onClose={vi.fn()}onSaved={vi.fn()}menuWrite={{ pending: false, track: async (work) => work() }}@@ -168,10 +170,19 @@ describe('OpenCodeMenuDialog', () => {);expect(screen.getByText('1 selected')).toBeTruthy();- expect(screen.getByText('Model inventory is unavailable. Retry the source list before editing this selection.')).toBeTruthy();+ expect(screen.getByText('Model menu data is not current. Wait for refresh, or retry the failed section before editing.')).toBeTruthy();const save = screen.getByRole('button', { name: 'Save selection' });expect(save.hasAttribute('disabled')).toBe(true);await user.click(save);expect(putMenu).not.toHaveBeenCalled();});++ it('requires current AgentSupply and Source inventory for the menu baseline', () => {+ const supply = readyRegion([agent]);+ const inventory = readyRegion(sources);++ expect(openCodeMenuBaselineReady(supply, inventory)).toBe(true);+ expect(openCodeMenuBaselineReady(failRegionRead(supply), inventory)).toBe(false);+ expect(openCodeMenuBaselineReady(supply, failRegionRead(inventory))).toBe(false);+ });});diff --git a/ui/src/components/settings/models/OpenCodeMenuDialog.tsx b/ui/src/components/settings/models/OpenCodeMenuDialog.tsxindex 8095b36f2..626c19d75 100644--- a/ui/src/components/settings/models/OpenCodeMenuDialog.tsx+++ b/ui/src/components/settings/models/OpenCodeMenuDialog.tsx@@ -39,18 +39,18 @@ export const OpenCodeMenuDialog: React.FC<{open: boolean;agent: AgentSupply;sources: Source[];- inventoryReady: boolean;+ baselineReady: boolean;onClose: () => void;onSaved: (echoed: AgentSupply) => void | Promise<void>;menuWrite: PendingWrite;-}> = ({ open, agent, sources, inventoryReady, onClose, onSaved, menuWrite }) => {+}> = ({ open, agent, sources, baselineReady, onClose, onSaved, menuWrite }) => {const { t } = useTranslation();const models = React.useMemo(() => selectableModels(agent, sources), [agent, sources]);const availableIds = React.useMemo(() => new Set(models.map((model) => model.id)), [models]);const rawChecked = React.useMemo(() => agent.menu?.checked ?? [], [agent.menu?.checked]);const savedChecked = React.useMemo(- () => inventoryReady ? rawChecked.filter((id) => availableIds.has(id)) : rawChecked,- [availableIds, inventoryReady, rawChecked],+ () => baselineReady ? rawChecked.filter((id) => availableIds.has(id)) : rawChecked,+ [availableIds, baselineReady, rawChecked],);const [selected, setSelected] = React.useState<Set<string>>(() => new Set(savedChecked));const [query, setQuery] = React.useState('');@@ -58,19 +58,19 @@ export const OpenCodeMenuDialog: React.FC<{const seed = React.useRef(initialSeedState);const inventoryKey = React.useMemo(() => JSON.stringify(models.map((model) => model.id)), [models]);- const [lastReadyInventory, setLastReadyInventory] = React.useState<string | null>(() => inventoryReady ? inventoryKey : null);- const inventoryAuthority = inventoryReady ? inventoryKey : lastReadyInventory ?? 'unread';+ const [lastReadyInventory, setLastReadyInventory] = React.useState<string | null>(() => baselineReady ? inventoryKey : null);+ const inventoryAuthority = baselineReady ? inventoryKey : lastReadyInventory ?? 'unread';const authoritative = JSON.stringify([savedMenuKey(agent.menu), inventoryAuthority]);React.useEffect(() => {if (!open) return;- if (inventoryReady && lastReadyInventory !== inventoryKey) setLastReadyInventory(inventoryKey);+ if (baselineReady && lastReadyInventory !== inventoryKey) setLastReadyInventory(inventoryKey);const step = seedStep(seed.current, authoritative);seed.current = step.state;if (!step.reseed) return;setSelected(new Set(savedChecked));setQuery('');setSaveFailed(false);- }, [open, authoritative, inventoryKey, inventoryReady, lastReadyInventory, savedChecked]);+ }, [open, authoritative, baselineReady, inventoryKey, lastReadyInventory, savedChecked]);const normalizedQuery = query.trim().toLocaleLowerCase();const visibleModels = normalizedQuery@@ -80,7 +80,7 @@ export const OpenCodeMenuDialog: React.FC<{const dirty = selected.size !== savedSet.size || [...selected].some((id) => !savedSet.has(id));const toggle = (id: string) => {- if (!inventoryReady || menuWrite.pending) return;+ if (!baselineReady || menuWrite.pending) return;setSaveFailed(false);setSelected((previous) => {const next = new Set(previous);@@ -91,7 +91,7 @@ export const OpenCodeMenuDialog: React.FC<{};const save = () => {- if (!inventoryReady || !dirty || menuWrite.pending) return;+ if (!baselineReady || !dirty || menuWrite.pending) return;setSaveFailed(false);void menuWrite.track(async () => {let echoed: AgentSupply;@@ -135,19 +135,19 @@ export const OpenCodeMenuDialog: React.FC<{placeholder={t('settings.models.gateway.menu.search') as string}aria-label={t('settings.models.gateway.menu.search') as string}className="min-w-0 flex-1 text-[12.5px]"- disabled={!inventoryReady || menuWrite.pending}+ disabled={!baselineReady || menuWrite.pending}/></div><span className="shrink-0 text-[11px] font-semibold text-muted">- {inventoryReady+ {baselineReady? t('settings.models.gateway.menu.selected', { selected: selected.size, total: models.length }): t('settings.models.gateway.selectedModelCount', { count: selected.size })}</span></div><div className="min-h-0 flex-1 overflow-y-auto rounded-md border border-border bg-background p-1.5">- {!inventoryReady ? (- <p className="px-4 py-10 text-center text-[12.5px] text-muted">{t('settings.models.gateway.menu.inventoryUnavailable')}</p>+ {!baselineReady ? (+ <p className="px-4 py-10 text-center text-[12.5px] text-muted">{t('settings.models.gateway.menu.baselineUnavailable')}</p>) : models.length === 0 ? (<p className="px-4 py-10 text-center text-[12.5px] text-muted">{t('settings.models.gateway.menu.empty')}</p>) : visibleModels.length === 0 ? (@@ -162,7 +162,7 @@ export const OpenCodeMenuDialog: React.FC<{type="button"role="checkbox"aria-checked={checked}- disabled={!inventoryReady || menuWrite.pending}+ disabled={!baselineReady || menuWrite.pending}onClick={() => toggle(model.id)}className={cn('flex min-h-11 w-full min-w-0 items-center gap-3 rounded-md px-3 py-2 text-left transition-colors hover:bg-surface-2 disabled:opacity-50',@@ -185,7 +185,7 @@ export const OpenCodeMenuDialog: React.FC<{<div className="min-h-5 text-[11px] font-semibold text-destructive-ink" role="status">{saveFailed ? t('settings.models.gateway.menu.saveFailed') : null}</div><div className="flex w-full flex-col-reverse gap-2 sm:w-auto sm:flex-row"><Button type="button" variant="outline" onClick={onClose} disabled={menuWrite.pending}>{t('settings.models.gateway.menu.cancel')}</Button>- <Button type="button" onClick={save} disabled={!inventoryReady || !dirty || menuWrite.pending}>+ <Button type="button" onClick={save} disabled={!baselineReady || !dirty || menuWrite.pending}>{menuWrite.pending && <LoaderCircle className="animate-spin" aria-hidden="true" />}{t(menuWrite.pending ? 'settings.models.gateway.menu.saving' : 'settings.models.gateway.menu.save')}</Button>diff --git a/ui/src/components/settings/models/SettingsModelsPage.tsx b/ui/src/components/settings/models/SettingsModelsPage.tsxindex 82b67446a..c48890374 100644--- a/ui/src/components/settings/models/SettingsModelsPage.tsx+++ b/ui/src/components/settings/models/SettingsModelsPage.tsx@@ -25,6 +25,7 @@ import { SourceOrderDrawer } from './SourceOrderDrawer';import { SourcesCard } from './SourcesCard';import { modelsSurfaceKindFromReads } from './modelHubSurfaceState';import { focusModelHubProjection } from './modelHubFocus';+import { openCodeMenuBaselineReady } from './menuBaseline';import { buildSupplyRelations } from './supplyRelations';import {emptySuspendedRouteAttempts,@@ -928,6 +929,7 @@ export const SettingsModelsPage: React.FC = () => {const sourceDetailOpen = selectedSourceId !== null && subscriptionVendor === null;const orderAgent = agents.find((agent) => agent.backend === orderBackend && agent.mode === 'hub') ?? null;const menuAgent = agents.find((agent) => agent.backend === menuBackend && agent.backend === 'opencode' && agent.mode === 'hub') ?? null;+ const menuBaselineReady = openCodeMenuBaselineReady(supplyRead, sourcesRead);const currentRouteAgent = routeTarget? installedAgents.find((agent) => agent.backend === routeTarget.agent.backend) ?? null: null;@@ -1383,7 +1385,7 @@ export const SettingsModelsPage: React.FC = () => {/>)}{orderAgent && <SourceOrderDrawer open agent={orderAgent} sources={sources} sourceReads={sourceCollectionReads} onClose={() => setOrderBackend(null)} onSaved={agentSaved} orderWrite={{ pending: agentWrites.has(orderAgent.backend), track: (work) => agentWriteRegistry.track(orderAgent.backend, work) }} />}- {menuAgent && <OpenCodeMenuDialog open agent={menuAgent} sources={sources} inventoryReady={sourcesRead.kind === 'ready'} onClose={() => setMenuBackend(null)} onSaved={agentSaved} menuWrite={{ pending: agentWrites.has(menuAgent.backend), track: (work) => agentWriteRegistry.track(menuAgent.backend, work) }} />}+ {menuAgent && <OpenCodeMenuDialog open agent={menuAgent} sources={sources} baselineReady={menuBaselineReady} onClose={() => setMenuBackend(null)} onSaved={agentSaved} menuWrite={{ pending: agentWrites.has(menuAgent.backend), track: (work) => agentWriteRegistry.track(menuAgent.backend, work) }} />}<RouteChainDialogselection={routeSelection}sources={sources}diff --git a/ui/src/components/settings/models/menuBaseline.ts b/ui/src/components/settings/models/menuBaseline.tsnew file mode 100644index 000000000..9dd8cba81--- /dev/null+++ b/ui/src/components/settings/models/menuBaseline.ts@@ -0,0 +1,8 @@+import type { RegionRead } from './regionRead';+import type { AgentSupply, Source } from './types';++/** A whole-menu write is safe only when both server-owned halves of its baseline are current. */+export const openCodeMenuBaselineReady = (+ supply: RegionRead<AgentSupply[]>,+ sources: RegionRead<Source[]>,+): boolean => supply.kind === 'ready' && sources.kind === 'ready';diff --git a/ui/src/i18n/en.json b/ui/src/i18n/en.jsonindex 209caedf1..7edb653d3 100644--- a/ui/src/i18n/en.json+++ b/ui/src/i18n/en.json@@ -946,7 +946,7 @@"search": "Search models or sources","selected": "{{selected}} of {{total}} selected","empty": "No eligible source models are available",- "inventoryUnavailable": "Model inventory is unavailable. Retry the source list before editing this selection.",+ "baselineUnavailable": "Model menu data is not current. Wait for refresh, or retry the failed section before editing.","noMatch": "No models match this search","save": "Save selection","saving": "Saving…",diff --git a/ui/src/i18n/zh.json b/ui/src/i18n/zh.jsonindex 14bbde198..091239620 100644--- a/ui/src/i18n/zh.json+++ b/ui/src/i18n/zh.json@@ -946,7 +946,7 @@"search": "搜索模型或供应商","selected": "已选 {{selected}} / {{total}}","empty": "没有可供 OpenCode 选择的模型",- "inventoryUnavailable": "暂时无法读取模型清单,请先重试供应商列表,再编辑此选择。",+ "baselineUnavailable": "模型菜单数据暂未更新,请等待刷新完成,或重试读取失败的区域后再编辑。","noMatch": "没有匹配的模型","save": "保存选择","saving": "正在保存…",