Repository navigation
feat: 透传并展示模型服务商上游与内部报错详情 - #1817
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 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".
| body := strings.TrimSpace(string(apiErr.Body)) | ||
| if body == "" || body == "{}" || body == "[]" || body == "null" { | ||
| return "" | ||
| } | ||
| return body |
There was a problem hiding this comment.
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 👍 / 👎.
Author
Type
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()。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与聊天 SSEerror事件,并持久化写入历史消息metadata.error_args,整页刷新后通过GET /bots/:bot_id/messages恢复;IM 渠道继续仅展示本地化文案;同步更新spec/、@memohai/sdk与docs/errors.md。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 typecheckmise 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)。Test Connection:401鉴权失败在 HoverCard 原样展示HTTP 401 · invalid_api_key与Provider Request ID;未监听端口(127.0.0.1:18199)在 HoverCard 展示完整传输层连接拒绝详情;429限流原样展示上游限流信息(无正则脱敏)。Test:gpt-mock-400与gpt-mock-401均在行内原样展示上游错误摘要与Provider Request ID。gpt-mock-400报错,核验实时 SSE 与整页刷新后展开Details均完整恢复HTTP 400 · context_length_exceeded原文与Provider Request ID: req_mock_chat_400。Screenshots / Recordings
Provider
Test Connection(401 原样透传 / 网络不可达内部详情 / 429 原样透传)Model
Test(400 与 401 行内原样透传)对话错误卡片
Details(实时报错与整页刷新后持久化恢复)Human QA