Skip to content

gemini-4 全系在部分账户被标为 field79 后台任务(kind=2)后,CreateInteraction 把模型名误写入 agent 槽位被上游 400 #321

Done

Description

@likeravine233

发生了什么

某账户自 2026-11-24 起,其 ListModels 目录中 gemini-4 全系模型(hydrogen / argon / neon / carbon 及 -search 变体)的 field 79 InteractionConfig 变为 [null,null,1,2],即 background=1 且 kind=2(模型),被解析标记为 interaction_task。此后该账户上全部 gemini-4 请求经 CreateInteraction + GetInteractionStream 后台任务路径生成,被上游拒绝:

AI Studio CreateInteraction returned HTTP 400, protocol error code 3:
'gemini-4-hydrogen' refers to a model, but was provided in the 'agent' field. Please use the 'model' field instead.

argon 同样报错('gemini-4-argon' refers to a model, ...)。同池另一账户目录中相同模型 field79=null,走 GenerateContent 完全正常——Google 在按账户灰度把 gemini-4 迁移到 Interactions 后端,该账户恰好被迁入。

复现

curl -X POST http://127.0.0.1:2048/v1/chat/completions \
  -H "Authorization: Bearer $KEY" -H "Content-Type: application/json" \
  -d '{"model":"gemini-4-hydrogen","messages":[{"role":"user","content":"hi"}]}'

请求轮换到该账户 100% 复现(另一账户正常);catalog.json 中该模型行 field79=[null,null,1,2],同账户 deep-research / antigravity 为 [null,null,1,1](kind=1,真 agent,工作正常)。

源码定位(供参考)

  • internal/aistudio/models.go:interaction_task 取 field79 索引 2,interaction_stream 为 kind==2 && !interaction_task——kind=2 的模型被 background 位错误地排除出流式路径,落入后台任务路径
  • internal/aistudio/interaction.go EncodeCreateInteractionRequest:field 19 目标构造为 [<request.Model>, null, <cfg>],把模型名写入 agent 槽位。对 kind=1 的真 agent 正确,但上游对 kind=2 期望模型目标,400 文案证实服务端区分 agent/model 两个命名空间
  • 按 docs/protocol.md,kind=2 模型(Omni 系)经 CreateInteractionStream 时 interaction 索引 17 为 ["models/<MODEL_ID>", <cfg>]——被迁移的 gemini-4 大概率应走同一条流式路径(即 interaction_stream 判定或应只看 kind==2;若上游确要求后台任务路径,则任务编码需按 kind 区分 agent/model 目标)

日志佐证:失败请求 rpc=GetInteractionStream,~500ms 即返回 400;同秒同模型落在另一账户走 GenerateContent 200 正常返回。

版本

v0.3.14(ghcr.io/mag1cfall/aistudio2api:latest,image revision 529043e,linux/amd64,WAA_BACKEND=camoufox)

Activity

  1. likeravine233 commented on Nov 24, 2026

    @likeravine233
    ContributorAuthor

    已在被迁移账户上定位并修复,见 #323。实测 gemini-4-hydrogen / argon 经 CreateInteractionStream(模型目标)单轮与多轮均返回 200。

  2. likeravine233 commented on Nov 24, 2026

    @likeravine233
    ContributorAuthor

    补充决定性证据(同一被迁移账户的官网前端抓包):

    前端对 gemini-4-hydrogen 实际调用 CreateInteraction + GetInteractionStream(而非 CreateInteractionStream)。真实请求体:

    interaction[17] = ["models/gemini-4-hydrogen", [null,null,null,null,null,4,1,65536]]   // field 18 模型目标:[模型名, generation config]
    interaction[26] = [[[[[[["hi"]]]]]]]                                                  // field 27 输入 steps
    envelope = [null,1,1,interaction,proof,1]
    

    对照目录 flag 分布:[.,.,null,2] 的 gemini-omni 走 CreateInteractionStream;[.,.,1,2] 的 gemini-4 与 [.,.,1,1] 的 agent 都走 CreateInteraction+GetInteractionStream,区别仅在 index 17 写模型目标、index 18 写 agent 目标。

    修正根因表述:路由本身没错——background=1 本来就该走任务路径;错的是编码器对 kind=2 模型也按 index 18 的 agent 目标格式([名称,nil,config])写入。正确修法:编码器按 field79 kind 区分——kind=2 在 index 17 写 ["models/X", genConfig](与 CreateInteractionStream 的模型目标同构),kind=1 维持 index 18 agent 目标不变。

    另确认官网 GetInteractionStream 请求体 [id,1,null,null,proof,1,"models/X"] 与现有实现一致,无需改动。

  3. likeravine233 commented on Nov 24, 2026

    @likeravine233
    ContributorAuthor

    补充一组实测结果(来源:一个 Google AI Pro 账号的 Chrome DevTools 抓包 + AIS 运行日志;样本为单账号、单日,结论边界在最后说明)。

    1. 官网前端对 kind=2 模型的真实请求格式(抓包实锤)

    在被标记的账号上,gemini-4-hydrogen 走 CreateInteraction + GetInteractionStream(任务路径),不是 CreateInteractionStream:

    • CreateInteraction 内 interaction[17] = ["models/gemini-4-hydrogen", [null×5, 4, 1, 65536]]——模型目标:field 1 模型名、field 2 生成配置;interaction[26] 为 steps;信封 [null,1,1,interaction,"<proof>",1]
    • GetInteractionStream 请求体 ["<id>",1,null,null,"<proof>",1,"models/X"]

    结论:现有代码"background→任务路径"的路由方向没错,bug 只在编码——AIS 把模型名按 agent 格式写到 field 18,kind=2 需要 field 17 的模型目标格式。PR #323 第一个 commit 按此修复。

    2. 终态 status 2 = requires_action(函数调用)

    实测:模型输出 function call 后上游以 status 2 结束 interaction,decodeInteractionEvent 抛"未识别的最终状态 %d"导致 502。仓库 docs/protocol.md 亦记载"函数调用为 requires_action";js-genai 官方 SDK 的 InteractionStatus 枚举顺序(in_progress/requires_action/completed/failed/cancelled/incomplete)与已实测的 3/4/5/6 映射完全吻合。

    PR 第二个 commit 补此终态:从终态 interaction 的 steps(索引 26)递归提取 content[10] 的函数调用([name, args, id?],与 GenerateContent part 同构),发 EventToolCall + finish_reason="tool_calls"。该解码路径尚未在真实 requires_action 事件上验证过(账号配额见底无法再触发,见第 4 条),但 502 崩溃本身是实测的。

    3. kind=2 目标编码曾丢失 tools

    encodeModelInteractionTarget 不写 interaction[7],请求声明的 tools 到不了上游(模型回复"工具不在工具集内")。PR 第三个 commit 补上编码(仅在请求显式声明 tools 时写 field 7,不注入目录默认工具,与官网抓包一致)。任务路径端到端未验证(429 挡住)。

    4. 任务路径配额远小于 GenerateContent(实测现象,口径未知)

    同一 Pro 账号上观察到:

    • 约 15 次成功的任务路径调用后,后续持续返回 HTTP 429 + RESOURCE_EXHAUSTED(google.rpc code 8)
    • 特征:账号停用约 40 分钟后重新启用的第一条请求即 429;且发生在太平洋零点(本地 16:00 +08)日配额重置之后
    • 同一时段、同一账号的 GenerateContent 路径完全正常

    可确认:任务路径的配额池与 GenerateContent 不同且小得多。不可确认:窗口口径(滚动/日/月)、是否与 deep-research 等代理任务共池——我没有任何关于池语义的数据,只是观察到现象。

    5. flagged 账号上 GenerateContent 仍被服务端接受(单账号单日样本)

    实验:在目录解析层抹掉 kind=2 的 interaction 能力标记,让该账号的 gemini-4 走 GenerateContent——服务端正常 200,含 tool_calls 响应。说明目前对 kind=2 的迁移是目录层引导而非后端强制。

    结论边界

    • GenerateContent 可用性只在一个 flagged 账号、一天内验证过,不能推出普遍成立,也不能排除 Google 日后收紧
    • 对"无未标记账号可用"的用户,PR 的任务路径修复仍是必需的;若 GenerateContent 在 flagged 账号上普遍可用,"忽略 flag 走默认路径"或作为 fallback 也是可行方案,供参考
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions