Skip to content

feat: 透传并展示模型服务商上游与内部报错详情 - #1817

Merged
qqqqqf-q merged 2 commits into
mainfrom
feat/memoh-325-provider-upstream-details
Nov 19, 2026
Merged

qqqqqf-q merged 2 commits into
mainfrom
feat/memoh-325-provider-upstream-details

Conversation

@qqqqqf-q

@qqqqqf-q qqqqqf-q commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Author

  • Human
  • Agent

Type

  • bug
  • feat
  • test

Summary

在开源自托管版 Memoh 中,将模型服务商上游响应与运行时/传输层内部报错的原始诊断详情(args.upstream)原样透传至前端并持久化至对话历史,取消服务端正则脱敏和 HTTP 401 屏蔽:

  • 原始详情提取与限长(internal/models/upstream_error.go):
    • 外部 *sdk.APIError(含 401、400、403、429、5xx)原样按 HTTP <status> · <code>: <message> 与 Provider Request ID: <req_id> 格式化(Message 为空时回退至有效 UTF-8 响应体);无任何诊断字段的合成 *sdk.APIError 返回空串。
    • 传输层 *url.Error 与 Memoh 内部/运行时错误原样返回 err.Error()。
    • 不做正则脱敏或 URL 改写,仅按 UTF-8 边界截断至 2000 字节以防超大响应撑爆存储与界面。
  • 错误目录与后端贯通(internal/apperror/error.go、internal/agent/application/、internal/handlers/):
    • 为 agent.provider_*(含 agent.provider_auth_failed、agent.provider_unreachable)、agent.response_timeout、agent.response_interrupted、agent.tool_timeout、runtime_run_failed、runtime_prompt_failed 与 internal 开放 AllowedArgs: ["upstream"]。
    • 透传至 POST /providers/:id/test、POST /models/:id/test、POST /providers/:id/import-models 与聊天 SSE error 事件,并持久化写入历史消息 metadata.error_args,整页刷新后通过 GET /bots/:bot_id/messages 恢复;IM 渠道继续仅展示本地化文案;同步更新 spec/、@memohai/sdk 与 docs/errors.md。
  • Web 前端展示:
    • chat-error-block.vue:支持展开/收起 Details 查看等宽原始报错详情与关联 ID,并纳入 Copy 报告文本。
    • provider-form.vue:Test Connection 失败或 Unverified 的 HoverCard 展示原始诊断详情。
    • model-item.vue:单模型 Test 失败时行内展示原始诊断详情。

Related Issues

Validation

自动化检查(全部通过)

  • node scripts/check-ui-contract.mjs(0 error)
  • node scripts/check-settings-rows.mjs(328 组件通过)
  • pnpm lint(0 error)
  • mise exec -- golangci-lint run ./internal/apperror/... ./internal/models/... ./internal/providers/... ./internal/handlers/... ./internal/agent/...
  • go test ./internal/apperror/... ./internal/models/... ./internal/providers/... ./internal/agent/... ./internal/handlers/...
  • mise exec -- pnpm --filter @memohai/sdk --filter @memohai/web --filter @memohai/desktop typecheck
  • mise exec -- pnpm test run apps/web/src/pages/home/ apps/web/src/pages/providers/ apps/web/src/utils/api-error.test.ts apps/web/src/store/chat/(87 文件 / 844 用例通过)

本地运行时与浏览器验证

  • 环境:宿主机 cmd/agent serve(隔离测试库)+ 本地 Vite(http://127.0.0.1:18182)+ Mock 上游服务(18191)。
  • 验证路径:
    1. Provider Test Connection:401 鉴权失败在 HoverCard 原样展示 HTTP 401 · invalid_api_key 与 Provider Request ID;未监听端口(127.0.0.1:18199)在 HoverCard 展示完整传输层连接拒绝详情;429 限流原样展示上游限流信息(无正则脱敏)。
    2. Model Test:gpt-mock-400 与 gpt-mock-401 均在行内原样展示上游错误摘要与 Provider Request ID。
    3. 对话实时报错与刷新持久化:在真实 Bot 会话中触发 gpt-mock-400 报错,核验实时 SSE 与整页刷新后展开 Details 均完整恢复 HTTP 400 · context_length_exceeded 原文与 Provider Request ID: req_mock_chat_400。

Screenshots / Recordings

Provider Test Connection(401 原样透传 / 网络不可达内部详情 / 429 原样透传)

OSS Provider Test Connection 401 原样透传
OSS Provider Test Connection 网络不可达展示传输层详情
OSS Provider Test Connection 429 原样透传

Model Test(400 与 401 行内原样透传)

OSS Model Test 400 与 401 行内原样透传

对话错误卡片 Details(实时报错与整页刷新后持久化恢复)

OSS 对话 400 错误展开 Details 与刷新持久化

Human QA

  • Human QA passed

@github-actions github-actions Bot added change:server Changes backend code, configuration, or API contracts change:web Changes web frontend or shared frontend packages feat Adds or improves functionality size:M PR size uses the larger of added or deleted lines, excluding generated files labels Nov 19, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T05:34:19.266335Z a821f11 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a821f11c0b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +68 to +72
body := strings.TrimSpace(string(apiErr.Body))
if body == "" || body == "{}" || body == "[]" || body == "null" {
return ""
}
return body

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Decode structured response bodies before redacting URLs

When a non-authentication upstream error has an empty Message, this fallback forwards the entire response body without decoding it. Valid JSON can escape URL slashes: a body containing {"url":"https:\/\/user:password@gateway.example\/v1?api_key=plainsecret"} passes through all three sanitizers unchanged because errs.RedactURLs only recognizes literal ://, and neither credential matches the token patterns. The credentials consequently enter public args.upstream, chat history, and the Details UI. Decode structured bodies and extract diagnostic fields before sanitization, or omit the raw-body fallback when it cannot be safely interpreted.

Useful? React with 👍 / 👎.

@qqqqqf-q qqqqqf-q changed the title feat: 透传并展示脱敏后的模型服务商上游报错详情 feat: 透传并展示模型服务商上游与内部报错详情 Nov 19, 2026
@qqqqqf-q
qqqqqf-q merged commit 84548e2 into main Nov 19, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:server Changes backend code, configuration, or API contracts change:web Changes web frontend or shared frontend packages feat Adds or improves functionality size:M PR size uses the larger of added or deleted lines, excluding generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant