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

Offen Anfängerfreundlich
#986 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@jiangjiang248 arbeitet bereits daran.

Seit 17.11.2026.

  • #999 von @jiangjiang248 — offen

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
74/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
go
Bereich
api, backend

Rechercherichtung

Beginne in internal/httpapi/assistant_models.go beim Handler für GET /api/assistant/models und vergleiche anschließend dessen Katalogsuche mit der Claude-Schlüsselzuordnung in internal/httpapi/assistant_engines.go und den Katalogschlüsseln in internal/httpapi/executor_models.go. Prüfe die Tests des Handlers für den claude-code-Executor oder ergänze Tests, falls keine vorhanden sind. Als erledigt gilt die Aufgabe, wenn die Anfrage nach den Claude Code-Modellen mit ihrem Modellkatalog erfolgreich zurückkommt und andere Executor-IDs weiterhin funktionieren.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

摘要

在 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 里已有一份拷贝,再抄一份会继续漂)。

Vorherrschende Sprache
Go
Sterne
711
Forks
114
Ø Merge
1 T. 10 Std.
Gemergte PRs (30 T.)
116

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus Tencent/LoopForge

Alle Issues in Tencent/LoopForge

Ähnliche Issues

Weitere Issues zu Go

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.