Skip to content

fix(settings): diagnose CodeBuddy discovery and test live connections - #1534

Open
Robert0622 wants to merge 4 commits into
Tencent:mainfrom
Robert0622:codex/codebuddy-model-probe
Open

Robert0622 wants to merge 4 commits into
Tencent:mainfrom
Robert0622:codex/codebuddy-model-probe

Conversation

@Robert0622

@Robert0622 Robert0622 commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

What changed

  • Report the specific catalog failure when CodeBuddy CLI is missing, exits unsuccessfully, times out, returns unrecognized help output, or lists zero selectable models. Accept whitespace and line wrapping in the model heading.
  • Make Test connection on official CodeBuddy settings send one short, tool-free, non-persistent model request. It uses the first model in the form when available and otherwise uses DeepSeek V4.1 Flash. Users can test a manually entered model while catalog discovery is failing.
  • Label model suggestions as coming from CodeBuddy CLI, since CLI help can list models even when a key fails a live request.

Scope

  • Platform core / API

Compatibility

The existing model probe accepts optional connectOnly and model request fields. Requests without those fields still perform model discovery.

Validation

  • CodeBuddy HTTP API regression tests passed, including wrapped help, timeouts, credential redaction, and authentication errors reported by a CLI process that exits successfully.
  • The full web settings and platform UI regression suite passed (396 tests), including the model and operation sent by Test connection.
  • Node 22 chatbot build and tests passed (571 tests). The Go vet and public-content checks passed. Gitleaks found zero leaks.
  • Chromium acceptance passed on the patched platform in an isolated Docker instance (25 public browser tests and 3 separate first-run tests). Three additional paid-model cases were skipped in the public suite; the targeted live test is listed below.
  • Real Chromium and CodeBuddy CLI 2.167.0, using only deepseek-v4.1-flash: domestic catalog returned 20 models and Test connection succeeded. Forced malformed CLI help produced the specific error and retry control. A manually entered model still passed Test connection and returned PONG in chat. The iOA authentication failure appeared in Test connection while the catalog could still load.
  • The full macOS Go run encountered a Unix socket path limit and timeouts in broader suites. The socket test passed when repeated with a shorter temporary directory.

Safety

  • The diff contains no credentials, internal endpoints, or production data.
  • Work and live testing used isolated checkouts and instances.

@Robert0622

Copy link
Copy Markdown
Collaborator Author

CR @ 436436a(19:00 定时评审)

结论:主体修复有效,本机部署实测通过;发现 1 个 P3(不阻塞合入,建议修):测试连接时,模型 ID 写错或在当前网络环境不可用,提示的是「AI 助手生成中断,未返回完整回答,请重试」,会让人以为是偶发故障、去反复重试。

P3:模型 ID 无效时,测试连接给出误导性提示

  • 复现:iOA 环境,模型目录第一项填 deepseek-v4.1-flsh(拼错),点「测试连接」→ 6 秒后显示「AI 助手生成中断,未返回完整回答,请重试」。
  • CLI 原始输出其实写得很清楚:assistant 消息是 400 model [deepseek-v4.1-flsh] service info not found … Currently supported models for your account: …,result 是 subtype=error_during_execution、result=""。
  • 原因:testOfficialCodeBuddyConnection 只把 err.Error() 交给 classifyAssistantFailureText;decodeAssistantCLIResult 在 result 为空时只返回 errAssistantMissingResult,不带上 assistant 文本,所以落到了 MISSING_RESULT。另外 assistantModelMissingRe 也匹配不到 model [x] service info not found 这种写法。
  • 建议:连接测试里遇到 errAssistantMissingResult 时,提示「CodeBuddy 没有返回回答,请确认模型 <id> 在当前网络环境可用」;或者把流里的 assistant 错误文本带进分类,并让 service info not found 归到 MODEL_UNAVAILABLE。PR 描述里明确支持「目录拉取失败时,手动填模型来测试连接」,填错 ID 正是这个场景下最常见的情况。

typo model

实测环境

本机 MariaDB + 源码构建,同时部署 main f3c1fcd5 和 PR 436436ae 两个实例。CodeBuddy CLI 2.187.0,iOA 环境真实 Key,模型只用 deepseek-v4.1-flash(另测了 glm-5.3-flash-ioa 和 deepseek-v4-flash)。Chromium 真实点击「个人配置 → 执行器配置 → CodeBuddy」。

场景 main PR
测试连接(已存 Key) 「此执行器可读取模型目录,请发起一次对话验证模型服务。」(没有真实请求) 「连接成功 · 7077 ms」,请求体带 connectOnly:true, model:"deepseek-v4.1-flash"(目录第一项)
表单填错误 Key 后测试连接 同上,看不出 Key 是错的 「CodeBuddy 拒绝了你的 API Key(401/403)…」,3.5 秒
网络环境选 international,用 iOA 的 Key — 401/403 提示(API)
获取可用模型 36 个,「来自官方服务」 36 个,「来自 CodeBuddy CLI」
CLI --help 输出不可识别 「CodeBuddy CLI 没有返回模型,请检查 CLI 和个人凭据」 「无法解析 CodeBuddy CLI 的模型列表…」+ 重试按钮;测试连接仍成功
CLI --help 退出码 17 同上笼统提示 「CodeBuddy CLI 获取模型时异常退出(退出码 17)…」;测试连接仍成功
CLI --help 卡住 15 秒后笼统提示 20 秒后「获取 CodeBuddy 模型列表超时,请重试或手动添加模型」;测试连接仍成功
手动模型 glm-5.3-flash-ioa / deepseek-v4-flash — 均连接成功
拼错的模型 ID — 误导性提示(见上面的 P3)

错误 Key 的报错文本、响应体里都没有回显 Key;页面上没有 JS 错误。

截图

main 测试连接:
main connect
PR 测试连接:
pr connect
PR 错误 Key:
pr badkey
main 错误 Key:
main badkey
PR 获取可用模型:
pr probe
PR CLI 帮助不可识别 → 获取模型:
pr malformed probe
PR CLI 帮助不可识别 → 测试连接:
pr malformed connect
PR CLI 帮助卡住 → 超时:
pr slow probe

自动化

  • go vet ./internal/httpapi 通过;新增的 TestProbeOfficialCodeBuddyModelsReportsSpecificResults、TestProbeOfficialCodeBuddyConnectionUsesFormOrSavedCredentials 和其他 CodeBuddy/Probe 相关用例都通过。
  • go test ./internal/httpapi 全量跑下来只有 TestMainBotBrowserStartsAndDrivesRunBrowser、TestBrowserStreamPushesFramesAndRunsCommands 失败,main 上也同样失败(本机没有浏览器环境),和本 PR 无关。
  • webtest 全量 396/396 通过(含改过的 runner-codebuddy-environment 用例)。
  • CI 16/16 通过。

其他小点(不阻塞)

  • 「测试连接」用的是目录里的第一个模型。如果用户把 claude-opus-5.5 这类贵模型排在第一位,每点一次都会真实请求一次贵模型(只回一个 OK,花费很小),可以考虑在按钮旁边提示用的是哪个模型。
  • 连接测试的响应里是 "models":null,前端能处理,只是和其他分支的字段风格不一样。

(评论人这个 token 是 PR 作者本人,GitHub 不允许给自己的 PR 点 Approve,所以这里只评论。)

crispinhu27
crispinhu27 previously approved these changes Nov 28, 2026

@crispinhu27 crispinhu27 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

审查结论:APPROVE(head 436436ae,base 697b63c8)

初审。审查范围:assistant_models.go / cli_models_probe.go 的 CodeBuddy 目录诊断与「测试连接」、新增的两个 Go 测试、web/app/workbench.js 的 probeCredentialCatalog、webtest/tests/runner-codebuddy-environment.test.mjs。

实际执行的验证(全部在 head 436436ae 上)

  • go build ./...、go vet ./internal/httpapi/ 通过;go test ./internal/httpapi/ -run 'Model|Probe|CodeBuddy' 通过。
  • 全量 go test ./internal/httpapi/ 有 17 个失败,全部在基线 697b63c8 上逐项复现(缺 bwrap、Chromium 的 SSH/终端/浏览器类用例),与本 PR 无关。
  • webtest 全量 396/396 通过;直接跑 runner-codebuddy-environment.test.mjs 8/8 通过。
  • 凭据不泄露:CLI 把 API Key 打到 stderr(退出码非 0、输出不可解析两种路径)时返回的都是固定文案,诊断日志里 key 显示为 <redacted>。
  • 兼容性:connectOnly / model 只在 engine==codebuddy && baseURL=="" 分支读取,其他引擎与自定义 Base URL 路径行为不变。
  • 连接测试超时:父 ctx 300ms 截止时约 301ms 返回「测试 CodeBuddy 连接超时」,errors.Is(err, context.DeadlineExceeded) 正确命中。

一处已确认但非阻塞的问题(P3,建议后续修)

进程退出后仍有子进程占着 stdout 时,已完整输出的模型列表会被当成「超时」丢掉(internal/httpapi/assistant_models.go:120 的 cmd.WaitDelay 与 :126 的 errors.Is(err, exec.ErrWaitDelay) 分支)。

  • 触发:codebuddy --help 已打印完整列表并退出,但它派生的后台子进程仍持有 stdout 且存活超过 1s。
  • 预期:照常解析已读到的输出(仓库内 internal/runtime/process.go:99-101 就是这么处理 ErrWaitDelay 的)。实际:readCodeBuddyModels 返回「获取 CodeBuddy 模型列表超时」,discoverCodeBuddyModels 也随之返回空。
  • 复现(临时 Go 测试,已删除未推送):假 CLI 为 ( /bin/sleep 3 ) & printf 'Currently supported: (fixture-model)\n'。
    • head:models=[] err=获取 CodeBuddy 模型列表超时… elapsed=1.001s
    • 基线 697b63c8:models=[fixture-model] elapsed=3.001s
  • 建议:命中 exec.ErrWaitDelay 时不要直接判超时,改用已拿到的 out 继续解析;只有 ctx.Err()==DeadlineExceeded 才报超时。真实 CLI 是否会产生这种子进程未验证,故不阻塞。

未验证的怀疑(不作为结论)

  • 连接测试默认模型写死 deepseek-v4.1-flash,三个官方站点是否有该模型需真实 key 才能确认。
  • 前端用目录里第一个模型发起连接测试,该模型在当前环境不可用时即使 key 有效也会显示失败。这两项都需要真实 CodeBuddy 服务,本次未验证。

…sult

A mistyped or unavailable model ID makes CodeBuddy stream the reason only in
an assistant text block ("400 model [x] service info not found") and finish
with an empty result payload, so the connection test classified it as a
generic MISSING_RESULT and told the user to retry. Keep the last assistant
text and pass it to the failure classifier, accept the bracketed model form,
and have the connection test name the model it could not use.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@Robert0622

Copy link
Copy Markdown
Collaborator Author

已按上轮 P3 修复并实测,新 head eeaa38e1。

改动(4 文件 +78/−1)

  • runAssistantCLI:保留最后一个 assistant 文本块;decodeAssistantCLIResult 返回 errAssistantMissingResult 时把这段文本附到错误里(… ; assistant=400 model [x] service info not found),分类器因此能看到真实原因。
  • assistantModelMissingRe:接受 model [id] service info not found 这种带方括号的写法。
  • testOfficialCodeBuddyConnection:MODEL_UNAVAILABLE / MISSING_RESULT 都点名模型(「CodeBuddy 无法使用模型 deepseek-v4.1-flsh,请确认模型 ID 拼写正确,并在当前网络环境下可用」),不再提示「生成中断,请重试」。
  • 新增 2 个用例:方括号 / 裸 ID 两种模型报错都归到 MODEL_UNAVAILABLE;拼错模型时连接测试的点名提示(先跑红再修绿)。

部署实测(本机 MariaDB 11.8 + 源码构建 head eeaa38e1,CodeBuddy CLI 2.187.0,iOA 环境真实 Key,只用了 flash 模型)

场景 修复前 修复后
拼错模型 deepseek-v4.1-flsh 测试连接 「AI 助手生成中断,未返回完整回答,请重试」 「CodeBuddy 无法使用模型 deepseek-v4.1-flsh,请确认模型 ID 拼写正确,并在当前网络环境下可用」,5.9s
正确模型 deepseek-v4.1-flash 连接成功 连接成功 {connected:true, source:"official"}
错误 Key 401/403 提示 不变,401/403 提示,无回显 Key

验证:go test ./internal/httpapi/(唯一失败 TestWorkspacePreparationAPISeparatesReadersAndWriters 因本机无 bwrap,main 上同样失败)、go vet、新增用例全绿。

loopforge-pr-review:eeaa38e1a03c082f37942de6315a711f3dd7bfff

… error

Appending every narration block changed the error text main's Claude
recovery path asserts, so only model/auth rejections are appended.

Co-Authored-By: Claude Code <noreply@anthropic.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