Skip to content

feat(models): refresh the Future catalogue when a model picker opens - #1341

Merged
huichen merged 3 commits into
mainfrom
dev-huichen
Oct 24, 2026
Merged

huichen merged 3 commits into
mainfrom
dev-huichen

Conversation

@huichen

@huichen huichen commented Oct 24, 2026

Copy link
Copy Markdown
Collaborator

打开模型选择器时,后台刷新一次 Future 目录,让平台新上架的模型不必等重启或 24 小时维护才出现。

问题

平台新发布一个模型后,已跑着的 agent 看不到它:每个选择器读的都是 agent 内的 registry,而 list_models 只轮询那份 registry,从不回头问平台。刷新只有三个触发点——agent 启动、桌面端的 24 小时维护、设置页手动按钮。所以「刚上线的模型」在界面上要等一小时到一天。

而「打开模型选择器」恰好就是这个动作该发生的时刻:用户此刻正想看目录里有什么。

改动

Agent — 新增 request_future_models_refresh(sessionless),是 sync_future_models 的非阻塞版:

  • 只读凭据,然后启动与 Registry::new() 同一套的抓取(同一单飞槽、同一 30 秒退避、同一后台任务登记),立刻返回 {requested};
  • 抓取落地后走原有的 sync 回调重建注册表并广播 provider_config_changed,所以已经打开的菜单会就地更新,不必重开;
  • 没有 Future 凭据、或退避/单飞闸门拒绝时返回 requested: false,这是 no-op 而不是错误。

Host / 桌面端 — request_future_models_refresh 的桥接与 Tauri 命令;agent 不可达时返回 requested: false 而非报错。

界面 — 新模块 modelCatalogRefresh.ts:fire-and-forget、10 分钟 TTL、失败静默。触发点:输入框的模型选择器(新建会话页共用同一控件)、设置 → 模型页。

选择器的请求不 await,菜单照常立即打开;刷新完成后经 provider_config_changed → providers-changed → 列表重新拉取。

未动 24 小时定时任务,也未动设置页那个会报数量的「更新模型列表」按钮(它仍同步、仍会报数)。

验证

  • cargo fmt --check、cargo clippy --all-targets -D warnings(agent/rpc/host/futureos 四个 crate)通过;
  • agent models:: 152 项、rpc::commands::providers 31 项、host agent_bridge 375 项、desktop 新命令解析测试通过;桌面 tsc --noEmit、相关 eslint、受影响 vitest(178 项)通过;
  • 新增测试覆盖:无凭据时不发请求且不打退避时间戳、有凭据时启动刷新、退避窗口内第二次请求被拒(避免重复打平台);
  • 顺带修掉一个测试锁顺序死锁:background_refresh_notifies_the_sync_callback_on_success_only 原先先取刷新闸门再建隔离 HOME,任何「持有 HOME 再走带闸门刷新」的测试都会死锁。现在统一为 HOME → 闸门。

全量 cargo test -p future-agent 仍有 3 个与环境相关的失败(gRPC 绑定、临时 HOME、一个竞态窗口),改动前后的基线上都复现,失败集合不同,非本次引入。

一点说明

start_future_models_refresh 与 spawn_future_models_refresh 分开,是为了让「自己持有闸门的测试」能走到抓取路径而不自锁;生产只有一个调用方,不加锁——单飞槽与退避时间戳才是并发控制。

A model published on the platform after the agent had already fetched the
catalogue stayed invisible until a restart or the desktop's 24h maintenance
pass: every picker reads the agent's registry, and `list_models` polls that
registry without ever asking the platform again.

Opening a model picker (the composer's picker, the new-conversation screen and
Settings -> Models) is exactly the moment to catch up, so it now asks for a
refresh. The new `request_future_models_refresh` command is the non-blocking
counterpart of `sync_future_models`: it starts the same single-flight,
backoff-guarded fetch `Registry::new()` uses and answers immediately. When the
fetch lands, the agent's sync callback rebuilds the registry and publishes
`provider_config_changed`, which the desktop already turns into
`providers-changed` -> a model-list reload, so an open picker updates in place
without anything waiting on the platform.

The GUI side is fire-and-forget and TTL-gated (10 minutes across all pickers),
so opening the menu repeatedly does not ask the platform each time, and a failed
request is swallowed rather than surfaced at the picker.

Also fixes a latent lock-order inversion in the future-models tests: the
sync-callback test took the refresh gate before its isolated HOME, which
deadlocks any test that holds a HOME and then goes through the gated refresh.
@huichen
huichen merged commit 5d70d2d into main Oct 24, 2026
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant