Skip to content

fix: keep model selector visible when loading fails - #711

Merged
agegr merged 2 commits into
agegr:mainfrom
Jaspersol:main
Sep 5, 2026
Merged

agegr merged 2 commits into
agegr:mainfrom
Jaspersol:main

Conversation

@Jaspersol

Copy link
Copy Markdown
Contributor

摘要

/api/models 请求失败时,模型选择器现在会保留在界面中,并显示具体错误信息。对于开发服务器冷启动、服务重启或 cwd allow-list 尚未同步等瞬时故障,前端会按退避策略自动重试,避免模型选择器静默隐藏。

变更内容

  • 为模型列表请求增加重试退避间隔:2 秒、5 秒、10 秒。
  • 解析非成功响应中的 JSON error 字段,并将具体错误展示给用户。
  • 对非 JSON 错误响应回退到包含 HTTP 状态码的错误信息。
  • 请求被取消时立即停止重试,避免组件卸载后继续更新状态。
  • 模型加载成功后保持原有模型列表和模型错误状态更新逻辑。

影响范围

  • 文件:hooks/useAgentSession.ts
  • 用户可见行为:模型列表加载失败时,模型选择器不再被静默隐藏;临时失败会自动恢复。

验证

  • npm 测试 — 844 tests 通过
  • tsc --noEmit
  • npm run lint
  • git diff --check

English

Title

Fix the model selector being hidden when model loading fails

Summary

When /api/models fails, the model selector now remains visible and displays a useful error message. For transient failures caused by a dev-server cold start, server restart, or a cwd allow-list race, the client retries with backoff instead of leaving the selector hidden prematurely.

Changes

  • Added model-list retry backoff delays of 2 seconds, 5 seconds, and 10 seconds.
  • Extracted the error field from non-success JSON responses and surfaced it to the UI.
  • Falls back to an HTTP-status-based message for non-JSON error responses.
  • Stops retries immediately when the request is aborted, preventing updates after component unmount.
  • Preserved the existing model-list and model-error state updates after successful loading.

Scope

  • File: hooks/useAgentSession.ts
  • User-visible behavior: the model selector is no longer silently hidden when model loading fails; transient failures can recover automatically.

Verification

  • npm test — 844 tests passed
  • tsc --noEmit
  • npm run lint
  • git diff --check

@agegr
agegr merged commit 18923e6 into agegr:main Sep 5, 2026
sleepinginsummer pushed a commit to sleepinginsummer/pi-web that referenced this pull request Sep 9, 2026
* fix: keep model selector visible when loading fails

* fix: surface model loading failures and ignore cancelled requests

---------

Co-authored-by: Alex Yang <agegcn@gmail.com>
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.

2 participants