模型路由:选 xai/grok-4.6 却被落到 OpenCode Go 的裸 grok-4.6(401);Claude Code 子代理丢 provider 落到网关(403)
- Dominant language
- TypeScript
- Stars
- 2.7k
- Forks
- 395
- Avg merge
- 21h 48m
- Merged PRs (30d)
- 776
Description
**提交人**: 匿名
**客户端版本**: 0.1.73
---
## 环境
- Cindy 0.1.73,内置 Claude Code harness 2.1.259,macOS 27.0
- 已连接来源:xAI(SuperGrok 订阅 OAuth)、Anthropic、OpenAI、XD Gateway、OpenCode Go、DeepSeek、MiniMax
- 发生日期 2026-09-05(下文时间 UTC)
## 现象
多个任务在 UI 里显示为「Grok 授权错误」,但 xAI 账号本身正常(同时段几十个 Grok 会话正常完成,用量快照可读)。排查后是两个路由问题:
### 1) `send_to_session` 传 `model: "xai/grok-4.6"`,会话却落到 provider `opencode-go` 的裸 `grok-4.6`
- 错误原文:`Failed to authenticate. API Error: 401 Model grok-4.6 is not supported for format anthropic`,`sdkError: authentication_failed`,`providerId: opencode-go`
- 这些会话在库里 `sessions.model` = `grok-4.6`(无 `xai/` 前缀)、`provider_id` = `opencode-go`;调用方传的是 `model: "xai/grok-4.6"`(该工具无 provider 参数)。
- 同一调用方、相同参数,07:32 和 08:03:48 创建的会话都正确落到 `xai`;只有 08:03:30–08:04:28 这一分钟内的 4 个会话落到 `opencode-go`,重建后又正常。疑似 xAI 来源瞬时不可用(token 刷新?)时按模型名后缀回退到了另一来源。
- `list_available_models` 里确有两条:`xai/grok-4.6`(xai)与 `grok-4.6`(opencode-go);后者在 Claude Code 下不可用(网关不支持 anthropic 格式,必 401)。
### 2) provider=xai 的 Claude Code 会话里的 Agent 子代理丢失父会话 provider,落到网关白名单报 403
- 错误原文(Agent 的 tool_result):`Agent terminated early due to an API error: Failed to authenticate. API Error: 403 user not allowed to access model. This user can only access models=['tencent/hy4-preview', 'qwen/qwen3.8-flash', ...]`(这是 XD Gateway 的清单)
- 父会话 runtime baseline/effective 均为 `claude-code / xai/grok-4.6 / provider_id: xai`,父会话正常;当日 6 次子代理调用 2 次这样失败。前一日绑定 Grok 会话的定时任务也出过同形 `403 user not allowed to access model` / `403 Request not allowed`。
## 期望
1. 调用方指定了带来源前缀的模型 id 时不应回退到另一来源的同名模型;来源不可用应报结构化错误(工具描述写的「不静默换模型」)。
2. 目录不该把当前 harness 下不可用的条目列为可用或作为回退目标。
3. Agent 子代理应继承父会话的 provider(或完整 `provider/model` id)。
4. 希望 `send_to_session` 支持显式 provider 参数(create_worker 已支持 provider_id)。
## 复现思路
连接 xAI 订阅 + OpenCode Go;在 Claude Code 会话里用 `send_to_session`(create)传 `model: "xai/grok-4.6"` 频繁建会话,观察 `sessions.provider_id`(我们一天约 40 次中 4 次错路,集中在同一分钟);在 provider=xai 的会话里调 Agent 子代理,部分会报上述 403。
## 目前规避
建会话后用 `get_session_runtime` 核 `effective.provider_id`,错了归档重建;Grok 会话里不用 Agent 子代理;Orca worker 显式传 `provider_id: "xai"`。
已去掉会话 id、标题、业务内容与凭据;需要更完整的本地记录可再提供。
---
## 提交时的任务环境
仅代表提交时快照,不一定是故障环境。OS 来自提交客户端本机,不含 SSH 远端主机;Harness / 模型来自当前任务。与运行环境无关的反馈可忽略本段。
**OS**: darwin arm64 (27.0.0)
**Harness**: Claude Code
**Model ID**: ` claude-fable-5-1 `
**界面语言**: zh-CN
Contributor guide
Research direction
Start at the send_to_session model-resolution path and compare it with create_worker's provider_id handling. Trace list_available_models filtering, provider fallback, and Agent child-session creation using the reported xai/grok-4.6 cases. Done means prefixed models never silently switch providers, incompatible entries are excluded, and child agents inherit the parent provider or full model id, with structured errors for unavailable sources.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- ai, backend-api-design
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100