Repository navigation
feat(models): refresh the Future catalogue when a model picker opens - #1341
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
打开模型选择器时,后台刷新一次 Future 目录,让平台新上架的模型不必等重启或 24 小时维护才出现。
问题
平台新发布一个模型后,已跑着的 agent 看不到它:每个选择器读的都是 agent 内的 registry,而
list_models只轮询那份 registry,从不回头问平台。刷新只有三个触发点——agent 启动、桌面端的 24 小时维护、设置页手动按钮。所以「刚上线的模型」在界面上要等一小时到一天。而「打开模型选择器」恰好就是这个动作该发生的时刻:用户此刻正想看目录里有什么。
改动
Agent — 新增
request_future_models_refresh(sessionless),是sync_future_models的非阻塞版:Registry::new()同一套的抓取(同一单飞槽、同一 30 秒退避、同一后台任务登记),立刻返回{requested};provider_config_changed,所以已经打开的菜单会就地更新,不必重开;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)通过;models::152 项、rpc::commands::providers31 项、hostagent_bridge375 项、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分开,是为了让「自己持有闸门的测试」能走到抓取路径而不自锁;生产只有一个调用方,不加锁——单飞槽与退避时间戳才是并发控制。