flm serve: /v1/completions, /api/generate and /api/chat keep decoding after the client disconnects

未关闭
#760 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
68/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
cpp

调研方向

Start in src/server/rest_handler.cpp at the /v1/completions, /api/generate, and /api/chat handlers, comparing them with handle_openai_chat_completion and the cancellation setup in src/server/server.cpp. Read generate_with_prompt in src/include/AutoModel/automodel.hpp, then use a client-disconnect probe during streaming and non-streaming requests. Done means all listed routes stop decoding promptly and release the NPU lock after cancellation.

由索引模型根据 Issue 内容生成。

描述

Everything below comes from reading the source on main at 39ff855. None of it has been measured.

What looks wrong

The server creates a CancellationToken for every request. The token is cancelled when the client socket closes (server.cpp:357-388) or when /api/cancel is called. /v1/chat/completions uses it: it calls cancellation_token->reset() and passes [&] { return cancellation_token->cancelled(); } to both insert() and generate() (rest_handler.cpp:1194-1236, :1257-1288).

The other generation routes accept the token and never read it:

So if a client drops mid-request on one of these routes, the server should keep decoding to max_tokens / num_predict (default 4096). For /api/generate and /api/chat, that also holds the NPU lock and blocks the queue behind it. /v1/completions isn't queued at all (see #759). /api/cancel has no effect on these routes for the same reason.

Expected

Cancelling on disconnect behaves the same on every generation route as it does on /v1/chat/completions.

Suggested fix

In each of these handlers, call cancellation_token->reset() and pass the same [&] { return cancellation_token->cancelled(); } predicate to insert() and generate(), as handle_openai_chat_completion does. Non-streaming /api/chat would need either a predicate on generate_with_prompt() or a switch to insert() + generate(). The second option changes output for Qwen3.5, Qwen3.6-MoE and GPT-OSS, whose generate_with_prompt() differs from that pair.

A probe that closes the connection mid-stream should confirm it: eval_count in the log stops short, and NPU Lock Released! follows promptly. We haven't run it yet.

Environment

Found by reading the source; checked against main at 39ff855 and v1.0.6.

Related, but a different resource: #680, where client aborts leak connection slots.

主要语言
C++
星标
2.1k
派生
184
平均合并
12 小时 22 分钟
30 天内合并 PR
239

环境准备

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

ROCm/FastFlowLM 的其他 Issue

查看 ROCm/FastFlowLM 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。