Skip to content

Router wasn't propagating the client disconnects fully to the child, the response wait could cause a delayed cancellation - #29707

Merged
ngxson merged 3 commits into
ggml-org:masterfrom
Me42019:upstream/router-request-cancellation
Oct 20, 2026
Merged

ngxson merged 3 commits into
ggml-org:masterfrom
Me42019:upstream/router-request-cancellation

Conversation

@Me42019

@Me42019 Me42019 commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

When someone closes a request to the llama.cpp router while a model is still generating, the router should stop the request it sent to the child llama-server. Before this fix, the router stopped reading the child’s response but left its downstream HTTP request running. The child could keep generating tokens for a client that had gone away.
The fix closes both gaps in that cancellation path. The router proxy now calls the existing HTTP client’s stop() method when it cleans up.The child’s response wait now uses a fixed timeout, so other wakeups cannot indefinitely postpone its check for a closed connection. The regression test starts generation through the router, disconnects the client, and checks that the child slot becomes idle.
Cancellation is not necessarily instantaneous: a token already in flight may finish while the signal travels through the router. In the live HIP test, the child stopped and released its slot about 0.4 seconds after the upstream socket closed; a normal request through the router still worked afterward.

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: Yes
    AI supported the investigation, implementation, and testing, while I focused on reviewing and understanding the changes.

…the response wait could cause a delayed cancellation
@Me42019
Me42019 requested a review from a team as a code owner September 30, 2026 07:14
@ggml-gh-bot

ggml-gh-bot Bot commented Sep 30, 2026

Copy link
Copy Markdown

Hi @Me42019, thanks for your contribution!

Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:

  • PR Template not respected: Please respect the template when creating a new pull request. Make sure to fill out all required sections.

Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below.

@ggml-gh-bot ggml-gh-bot Bot added the draft PR will be changed to draft by github-actions bot label Sep 30, 2026
@github-actions
github-actions Bot marked this pull request as draft September 30, 2026 07:21
@github-actions github-actions Bot removed the draft PR will be changed to draft by github-actions bot label Sep 30, 2026
@Me42019 Me42019 changed the title Router wasn't propagating the client disconnects fully to the child, … Router wasn't propagating the client disconnects fully to the child, the response wait could cause a delayed cancellation Sep 30, 2026
@Me42019
Me42019 marked this pull request as ready for review September 30, 2026 07:42

@ServeurpersoCom ServeurpersoCom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, nice catch: in streaming mode the router already notices a disconnect on the next chunk write and the child stops right away, but in non-streaming mode the child writes nothing until the end, so the router never noticed and the child kept generating for nobody. With cli->stop() the child now sees the closed connection through the same should_stop and cancel path as a direct client, and the deadline makes that check happen every second even when other slots are busy, so both modes now behave the same.

Comment thread tools/server/tests/unit/test_router.py Outdated
Comment on lines +67 to +72
def test_router_disconnect_stops_child_generation():
global server
server.server_slots = True
server.n_ctx = 8192
server.n_threads = 1
server.start()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test is quite time-sensitive so I don't think it will be reliable on CI. maybe just remove this test for now

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the timing-sensitive test as suggested. Thanks.

@ngxson
ngxson merged commit 4e20138 into ggml-org:master Oct 20, 2026
12 checks passed
edwardyoon pushed a commit to edwardyoon/focus-llama that referenced this pull request Oct 24, 2026
… child, the response wait could cause a delayed cancellation (ggml-org#29707)

* Router wasn't propagating the client disconnects fully to the child, the response wait could cause a delayed cancellation

* tests: satisfy router disconnect type check

* server : remove timing-sensitive router cancellation test

Assisted-by: Codex
auRose94 pushed a commit to auRose94/llama.cpp that referenced this pull request Oct 28, 2026
… child, the response wait could cause a delayed cancellation (ggml-org#29707)

* Router wasn't propagating the client disconnects fully to the child, the response wait could cause a delayed cancellation

* tests: satisfy router disconnect type check

* server : remove timing-sensitive router cancellation test

Assisted-by: Codex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants