LoopForge icon indicating copy to clipboard operation
LoopForge copied to clipboard

[Bug] AI 对话切换 Claude Code 必定 400「不支持的执行器」:assistantEngineClaude 与 executorModelCatalogs 键名不一致

Open tanjunxiaoge opened this issue 2 weeks ago • 2 comments

摘要

在 AI 对话里把执行器切到 Claude Code,页面提示「不支持的执行器」,模型下拉为空,消息发不出去。CodeBuddy / Codex / DeepSeek Harness 均正常。

对应接口:GET /api/assistant/models?executor=claude-code

环境

  • LoopForge v0.3.8(ghcr.io/tencent/loopforge:0.3.8,revision 39f4fe76f9d757fff5fdba21da0e68dab8e68d9f)
  • Linux aarch64 / Docker Compose 自托管,AGENTFLOW_LOCAL_SANDBOX=docker

复现

curl -s -o /dev/null -w '%{http_code} %{size_download}\n' \
  -b 'agentflow_user=<session>' \
  'http://127.0.0.1:8090/api/assistant/models?executor=claude-code'
# 实际:400 33        ← {"error":"不支持的执行器"}

对照其他 id:

?executor=claude      → 200 1376
?executor=codex       → 200 874
?executor=dsh         → 200 293
?executor=claude-code → 400 33      ← 只有这一个挂

服务端日志(59 = 33 字节响应 gzip 后):

[HTTP] GET /api/assistant/models -> 400 (59 bytes, 1ms)

根因

internal/httpapi/assistant_engines.go

assistantEngineClaude = "claude-code"   // 引擎 id

internal/httpapi/executor_models.go

return map[string]executorModelCatalog{
    "codebuddy": {...}, "codex": {...},
    "claude": {...},   // ← 键是 "claude",不是 "claude-code"
    ...
}

internal/httpapi/assistant_models.go 的早返回分支直接拿引擎 id 查这张表:

id := assistantExecutor(raw)
catalog, ok := executorModelCatalogs()[id]
if !ok {
    c.JSON(400, gin.H{"error": "不支持的执行器"})
    return
}
...
Family: map[string]string{"codex": "gpt", "claude": "claude"}[id]   // 同样取不到

⇒ executorModelCatalogs()["claude-code"] 恒 miss。

为什么是 bug 而不是设计

  1. 同仓库已有针对该不一致的显式映射,说明作者知道两套 id 需要对齐,只是漏在了 models handler:
// assistant_engines.go
func assistantEngineBuiltinModels(engine string) []assistantDiscoveredModel {
    catalogKey := engine
    if engine == assistantEngineClaude {
        catalogKey = "claude"          // ← 这里转了一次
    }
    for _, model := range executorModelCatalogs()[catalogKey].Models {
  1. 执行器资源侧(web/app/agents.js)白名单用的也是 claude:
const allowed = new Set(['codebuddy','codex','claude','opencode','cursor','agy','kimi','pi','dsh','zcode']);

即"executor 资源 id = claude"与"对话引擎 id = claude-code"是两个命名空间,却被同一个 map 复用。

  1. assistantCLIEngines() 下发的引擎列表里明确是 claude-code(实测 /api/assistant/models 返回 engines: ['codebuddy','codex','claude-code',...])。前端据此选中 claude-code 再回查模型 → 必然 400。

影响面

逐项比对,只有 claude-code 不匹配,其余 9 个(codebuddy / codex / opencode / cursor / agy / kimi / pi / dsh / zcode)正常。 即 v0.3.8 下 Claude Code 完全无法在 AI 对话里使用。同问题在 v0.3.9-rc.1 仍存在(已比对两处源码)。

建议修复(最小改动)

归一化键名,不要动共享 map(其他接口依赖 claude 键):

id := assistantExecutor(raw)
catalogKey := id
if id == assistantEngineClaude {
    catalogKey = "claude"
}
catalog, ok := executorModelCatalogs()[catalogKey]
if !ok {
    c.JSON(400, gin.H{"error": "不支持的执行器"})
    return
}
family := map[string]string{"codex": "gpt", "claude": "claude"}[catalogKey]

更彻底的做法是把这层映射抽成一个函数复用(现在 assistantEngineBuiltinModels 里已有一份拷贝,再抄一份会继续漂)。

tanjunxiaoge avatar Nov 17 '26 07:11 tanjunxiaoge

感谢反馈!理解你的意思是:在 v0.3.8 的 AI 对话里把执行器切到 Claude Code 时,GET /api/assistant/models?executor=claude-code 返回 400「不支持的执行器」,模型下拉为空、消息发不出去,而 CodeBuddy、Codex、DeepSeek Harness 正常。

已经看到,会按现有 Issue 排期查看。版本、复现步骤和对照结果都很完整,谢谢。

cocofhu00 avatar Nov 17 '26 08:11 cocofhu00

Confirmed on the published ghcr.io/tencent/loopforge:0.3.8 image (x86_64), and thanks for the very thorough root-cause analysis — it matches what I reproduced exactly.

Two additional data points that may help with triage/prioritization:

1. Impact is less severe than "messages can't be sent" — chat actually still works. In my deployment the Main Bot conversation with executor claude-code completes normally: assistant_generations.status=completed, a full assistant reply is returned, token usage is recorded in assistant_sessions.payload.messages[].usage, and MCP tool calls (e.g. GitHub issue comments) execute fine. The 400 only surfaces as a red "不支持的执行器" banner in the UI, from the frontend's model-catalog probe. So this is UX-visible rather than a hard functional blocker for chat (SOP runs / role pickers that query the catalog may be more affected).

Verified endpoint matrix with an authenticated session:

?executor=claude-code  -> 400 {"error":"不支持的执行器"}
?executor=claude       -> 200
?executor=codex        -> 200
?executor=dsh          -> 200

2. Verified local hotfix for anyone on 0.3.8 who can't wait for #999: Adding the alias in executorModelCatalogs()'s map (instead of only patching the handler) keeps all callers consistent — the early-return handler, /api/executor-models, and assistantEngineBuiltinModels all read the same map:

catalogs := map[string]executorModelCatalog{ /* ...existing entries... */ }
if claude, ok := catalogs["claude"]; ok {
    catalogs["claude-code"] = claude   // chat engine id -> executor resource id
}
return catalogs

I rebuilt v0.3.8 with this 6-line change (build order matters: run bash scripts/build-chatbot.sh first to generate web/native-chat, otherwise go build fails with embed: pattern all:native-chat: no matching files found; then CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" ./cmd/agentflow), mounted the binary over /app/bin/agentflow, and recreated only the platform container. Re-test: ?executor=claude-code now returns 200 and the banner is gone; chat, credentials and token usage unaffected. Long-term the shared mapping helper suggested in the report is cleaner. Hope #999 lands soon.

Dylan5237 avatar Nov 17 '26 13:11 Dylan5237