Skip to content

fix: handle agent-protocol fields the Qwen3.5 template rejects - #635

Open
rubik-hua wants to merge 1 commit into
InfiniTensor:mainfrom
rubik-hua:agent-fix
Open

rubik-hua wants to merge 1 commit into
InfiniTensor:mainfrom
rubik-hua:agent-fix

Conversation

@rubik-hua

Copy link
Copy Markdown
Contributor

Agent traffic through the OpenAI-compatible endpoint hit template and
parser limitations that turned recoverable situations into 500s or dead
streams:

  • reasoning_effort=high: the Qwen3.5 template only accepts xhigh/medium/low while standard clients send low/medium/high. Map high to xhigh for the qwen3_coder parser only; all other model families pass through untouched.

  • reasoning_effort=none: clients send it to disable thinking, but the templates gate thinking on a separate switch. Translate it to enable_thinking=false (renamed to thinking for kimi_k3) and treat an explicit null as "not specified".

  • mid-conversation system messages: the template raises on any system message after the first, while agent clients send operator instructions mid-conversation. Merge their text into the leading system entry (list content keeps its parts and gains a text part).

  • truncated tool calls: generation ending inside a tool call (typically max_tokens exhausted) failed a stream that already went out with 200. Flush the partial text as content and let the real finish_reason reach the client.

  • final abort notification: after a client cancel, delivering the final abort output into the already-closed output queue raised janus.ShutDown and logged a misleading warning on every cancel. The abort reason is committed before the put, so drop it silently; other delivery failures still warn.

  1. reasoning_effort=high 返回 500

标准 OpenAI 协议中 reasoning_effort 的取值是 low/medium/high(vLLM、SGLang 均按此实现),但 Qwen3.5 的 chat template
只接受 xhigh/medium/low,标准值 high 不在枚举内,Jinja 渲染时直接抛异常,请求返回 500。典型触发方:Claude Code(最高只能发
high)。修复:qwen3_coder parser 下将 high 映射为模板最强档 xhigh;其他模型族不做任何改写,保持原有透传行为。
image
image

  1. reasoning_effort=none 返回 500

agent 客户端用 none 表示“关闭思考”,但 Qwen3.5 模板中思考开关是独立的 enable_thinking 参数,不是 effort 的一个档位,none
同样撞枚举报错。修复:将 none 翻译为 enable_thinking=false(kimi_k3 分支由既有改名逻辑转为
thinking),模板因此输出空思考块、真正不思考,且跳过 effort 校验;同时将显式 null
视为“未指定”,避免其击穿模板的默认值逻辑。
image
image

  1. 对话中间的 system 消息返回 500

Qwen3.5 模板只在首条消息前渲染 system 块,遇到任何后续 system 消息直接抛 System message must be at the beginning.。而
agent 客户端(Claude Code 经协议网关)会在对话中间合法地发送 system 消息(操作者指令、状态注入),请求因此
500。修复:将非开头 system 的文本合并进首条 system——字符串内容追加合并文本,分段列表内容保留原有分段并以新 text
分段追加,无文本的空 system 直接丢弃,信息不丢失。
image

  1. 工具调用被截断导致整个流报错

生成长度耗尽(max_tokens 用完)时,模型可能停在工具调用 XML 的中间。此时流式响应已发出 HTTP 200 和大半数据,parser
在流末尾抛 Truncated tool call,客户端收到的是半途 error,连 finish_reason: length 都拿不到,无法续传,整个 turn
报废。截断本是良性、可恢复的事件。修复:不再抛异常,将残缺文本作为 content 输出,让真实的 finish_reason(length/canceled
等)正常到达客户端,由客户端自行决定续传或重试。

  1. 客户端取消时每次都刷误导性警告

客户端断开(用户取消、agent 并行工具调用的批量收尾)时,request.close() 会关闭输出队列,而 step 线程可能仍向其投递最终
abort 通知,抛 janus.ShutDown 并打印 Final abort output could not be delivered
警告——每次取消一条,看起来像数据丢失,实际 abort
原因在投递前就已提交到请求上,消费者已不存在,投递失败是预期结果。修复:显式捕获 janus.ShutDown
并静默;其他真正的投递失败仍保留警告。
image

服务启动:
exec /opt/conda/bin/python python/infinilm/server/inference_server.py
--device metax
--model=/mnt/infini/infrahi/models/qwen38_27B
--tp 8
--max-batch-size 256
--enable-paged-attn
--attn flash-attn
--disable-prefix-caching
--tool-call-parser qwen3_coder
--max-new-tokens 65536
--num-blocks 4096
--chunked-prefill-size 8192
--log-level INFO

使用new-api接入模型

问题修复后,claude code 和 wordbuddy 验证使用正常

image image image image

@rubik-hua
rubik-hua requested a review from a team December 1, 2026 06:10
  Agent traffic through the OpenAI-compatible endpoint hit template and
  parser limitations that turned recoverable situations into 500s or dead
  streams:

  - reasoning_effort=high: the Qwen3.5 template only accepts
    xhigh/medium/low while standard clients send low/medium/high. Map high
    to xhigh for the qwen3_coder parser only; all other model families
    pass through untouched.

  - reasoning_effort=none: clients send it to disable thinking, but the
    templates gate thinking on a separate switch. Translate it to
    enable_thinking=false (renamed to thinking for kimi_k3) and treat an
    explicit null as "not specified".

  - mid-conversation system messages: the template raises on any system
    message after the first, while agent clients send operator
    instructions mid-conversation. Merge their text into the leading
    system entry (list content keeps its parts and gains a text part).

  - truncated tool calls: generation ending inside a tool call (typically
    max_tokens exhausted) failed a stream that already went out with 200.
    Flush the partial text as content and let the real finish_reason
    reach the client.

  - final abort notification: after a client cancel, delivering the final
    abort output into the already-closed output queue raised
    janus.ShutDown and logged a misleading warning on every cancel. The
    abort reason is committed before the put, so drop it silently; other
    delivery failures still warn.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant