LoopForge icon indicating copy to clipboard operation
LoopForge copied to clipboard

[Bug]: GET /api/assistant/models?executor=<cli> drops the user's saved models, so the composer sends the "default" sentinel as a model name

Open baofengqqwwff opened this issue 1 week ago • 2 comments

Component / host

Platform — web / API

Edition

Platform

LoopForge version

ghcr.io/tencent/loopforge:0.4.0 (server reports (devel), linux/arm64). The code paths below were re-checked at eb2e368 and the API gap is still there.

What happened?

The two model-catalog endpoints disagree about a user's saved models, and the composer falls into the gap.

  1. For a custom-model agent CLI (pi, opencode, zcode, dsh, kimi) a user configures API Key + Base URL + several models in 个人配置 and saves them.

  2. GET /api/assistant/models returns them correctly (verified against a live instance):

    {"engine":"pi","id":"pi:group/self-use-models","name":"Self-Use-Models"}
    {"engine":"pi","id":"pi:group/haid-use-models","name":"Haid-Use-Models"}
    
  3. But GET /api/assistant/models?executor=pi — the request the composer makes as soon as its in-memory catalog snapshot has no entry for the selected CLI — returns only the sentinel:

    {"default":"default","models":[{"id":"default","name":"CLI default","family":"","credits":"","efforts":null}]}
    
  4. So the composer's model menu contains a single item, CLI default. Sending a turn puts the literal string default in the request, and the CLI forwards model: "default" to the configured Base URL. An OpenAI-compatible gateway that has no model literally named default answers 404 and the generation fails:

    调用 1 · pi  default  退出码 0 · http://<gateway> (chat)
    404: {"error": {"message": "no model \"default\" ...", "type": "not_found_error"}}
    

Expected: a CLI selected with saved personal models lists those models; the default sentinel means "run the CLI's own default", so it must never reach the provider as a model name.

Reproduction

  1. docker compose up the platform, sign in, open 个人配置 → pick pi (or opencode / zcode / dsh / kimi).
  2. Enter an API Key and a Base URL of an OpenAI-compatible gateway, click 获取可用模型, save 2 or more models.
  3. Open AI 对话 without reloading the page (a catalog snapshot loaded before the save reproduces this; a hard reload hides it).
  4. Select Pi in the composer and open the model menu → only CLI default is listed.
  5. In devtools, GET /api/assistant/models?executor=pi returns only {"id":"default"}.
  6. Send a message → the CLI sends model: "default" to the gateway → 404, and the run fails with GENERATION_FAILED.

Where it comes from

Two code paths build the same catalog:

  • internal/httpapi/assistant_models.go:180-215 — the ?executor= branch delegates to executorModelCatalogs(...) and returns the fixed per-CLI catalog only. builtinExecutorModels[<agent CLI>] is empty for pi / opencode / zcode / dsh / kimi, so the response carries nothing but the default entry.
  • internal/httpapi/executor_models.go:213-234 (catalogHandlers.executorModels, i.e. GET /api/executor-models) — the same catalogs, but it substitutes the user's saved models via assistantDiscoveredModelsFor(...) and marks Source: "personal".

So the saved models exist and are reachable through one endpoint, but not the one the composer uses as its fallback:

// chatbot/src/useChat.js:692-698
const listed = engineModels(models, executor);
const usesProviderCatalog = !!executor && !codeBuddy && (!!agyAccountKey || !listed.length);
const catalogToLoad = usesProviderCatalog && !providerCatalog ? agyAccountKey || executor : "";
const executorModels = usesProviderCatalog
  ? (providerCatalog?.models || []).filter((model) => concreteModel(model, executor))
  : listed;

Suggested fix

Either make the ?executor= branch return the same personal models as /api/executor-models (share one builder for both handlers), or have the composer call /api/executor-models for custom-model CLIs. Independently, strip the default sentinel before it reaches a CLI engine so a placeholder can never be sent to a provider as a model name.

Environment

  • Platform: compose.yaml deployment, platform container + MySQL in Docker on macOS (arm64).
  • Browser: Chromium-based, zh UI.
  • CLI: pi, custom Base URL speaking the chat protocol against an OpenAI-compatible gateway.
  • No runner involved: the turn ran on the platform's own CLI execution path.

baofengqqwwff avatar Nov 22 '26 17:11 baofengqqwwff

Thanks for the report. As I understand it, after personal models are saved for a custom-model CLI, the composer request that asks for that executor's catalog only comes back with the default sentinel, and a later turn can send that literal name to the gateway so generation fails.

We've seen this and will review it along with the current issue queue.

cocofhu00 avatar Nov 22 '26 17:11 cocofhu00

我在最新 main(`d2462fa`)上复现了这个问题。

为 Pi 配置自定义 Base URL,并保存两个个人模型后:

```text
GET /api/executor-models
=> 能正常返回保存的个人模型

GET /api/assistant/models?executor=pi
=> 返回空目录;受影响版本中只返回 default

原因是这两个接口使用了不同的模型目录逻辑。/api/executor-models 会读取用户保存的模型,但 composer 使用的 /api/assistant/models?executor=pi 只读取固定的 CLI 目录。Pi、OpenCode 等 CLI 没有内置模型列表,所以个人模型被丢掉了。

最小修复可以是:

  1. 在 GET /api/assistant/models?executor=<cli> 中复用 assistantDiscoveredModelsFor(...),返回用户保存的个人模型;
  2. 在调用 CLI 前把 default 当作内部 sentinel 处理,不能继续作为真实模型名传给 provider。对于 Pi,目前会生成 agentflow/default,最终可能导致网关返回 404。

这样可以直接修复当前的模型菜单问题和后续的 GENERATION_FAILED。

Zhong-Chenchen avatar Nov 24 '26 07:11 Zhong-Chenchen