Skip to content

fix(api): accept an abort request without a body - #6309

Merged
qinxuye merged 4 commits into
xorbitsai:mainfrom
David-Wu1119:fix/abort-request-empty-body
Dec 4, 2026
Merged

qinxuye merged 4 commits into
xorbitsai:mainfrom
David-Wu1119:fix/abort-request-empty-body

Conversation

@David-Wu1119

@David-Wu1119 David-Wu1119 commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Bug

POST /v1/models/{model_uid}/requests/{request_id}/abort reads its body with request.json() inside the handler's catch-all except Exception. The 3D model guide (doc/source/models/model_abilities/3d.rst) documents the call as a plain POST to that path, and block_duration has a default, but a request without a body answers 500 and never reaches the supervisor:

curl -X POST http://127.0.0.1:9997/v1/models/<uid>/requests/<request_id>/abort
{"detail":"Expecting value: line 1 column 1 (char 0)"}   # HTTP 500
Body main this change
none, or only whitespace 500 Expecting value ... 200, block_duration 30
{"block_duration": 0} 200 200
{ 500 Expecting property name ... 400 Request body must be valid JSON
[] 500 'list' object has no attribute 'get' 400 Request body must be a JSON object
null 500 'NoneType' object has no attribute 'get' 400 Request body must be a JSON object
{"block_duration": "30"}, null or [30] 500 '>' not supported between instances of ..., after the abort was forwarded 400 block_duration must be a number, nothing forwarded
{"block_duration": 1.5} 200 200

The Python clients and the Web UI always send {"block_duration": ...}, so they are not affected.

Fix

Parse the body before the catch-all. An empty body becomes {}, so block_duration keeps XINFERENCE_DEFAULT_CANCEL_BLOCK_DURATION. A body that is not valid JSON, or not a JSON object, answers 400. A block_duration that is not a number also answers 400, checked before the abort is forwarded. On main it reaches the supervisor, and CancelMixin._cancel_running_task (used by the model actor and by this route) cancels the running task before it compares block_duration with 0, so the client gets a 500 for an abort that has partly happened. With the supervisor stubbed, the 500 comes from the route's own _cancel_running_task after the supervisor call returned. A JSON object body with a numeric block_duration takes the same path as before.

Docs: a paragraph after the request_id notes in doc/source/user_guide/client_api.rst, with its translation in all ten client_api.po catalogs (de, es, fr, it, ja, ja_JP, ko, pt_BR, zh_CN, zh_TW), says the abort body is optional and so is block_duration in it (the default block applies without either), and that a non-object body, or a block_duration that is present and not a number, returns 400 while the request keeps running. The Korean catalog also gets a markup fix (no particle right after a closing inline literal), including the media request_id paragraph from #6294.

Types: block_duration is annotated float through the cancellation path (CancelMixin._cancel_running_task, ModelActor.abort_request, SupervisorActor.abort_request) and in both clients' abort_request, since the route accepts fractional values (asyncio.sleep takes a float).

Inputs treated differently from main: only the bodies in the table above that answered 500. Not changed: true is still accepted as a number (it was a 1 s block on main), and a negative block_duration still means no block.

Tests

  • New test_abort_route_body_is_optional in xinference/api/tests/test_llm_request_abort.py sends the bodies above through the real route with the supervisor stubbed. On main source 8 cases fail (500) and the {"block_duration": 0} and 1.5 controls pass; with this change all 10 pass, the supervisor gets block_duration 30 for an empty body, and invalid bodies do not reach it.
  • test_llm_request_abort.py, test_non_streaming_request_abort.py and test_anthropic_request_abort.py in xinference/api/tests: 167 passed. On main source the same files give 159 passed and 8 failed, the new cases only.
  • msgfmt --check passes on the ten updated catalogs; the localized docs were not built.
  • pre-commit run --from-ref=origin/main --to-ref=HEAD passes, and so does pre-commit run mypy --files xinference/api/restful_api.py xinference/core/utils.py xinference/core/model.py xinference/core/supervisor.py.
  • Not run: no model was launched; the supervisor is stubbed.

Found while auditing xinference's request cancellation with Claude Code, which also wrote the fix and the tests.

🤖 Generated with Claude Code

David-Wu1119 and others added 2 commits December 3, 2026 10:19
POST /v1/models/{model_uid}/requests/{request_id}/abort read the body
with request.json() inside the handler's catch-all, so a call without a
body, as the 3D guide shows it, answered 500 "Expecting value" and never
reached the supervisor. A body that was valid JSON but not an object
also answered 500, and so did a block_duration that was not a number,
after the abort had already been forwarded: the model compares it with
0 once it has cancelled the running task.

An empty body now keeps the default block_duration. A body that is not
valid JSON, is not a JSON object, or has a non-number block_duration
answers 400 before anything is forwarded. Requests with a numeric
block_duration behave as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add a paragraph after the request_id notes in client_api.rst, with the
translation in every client_api.po catalog: the abort body is optional,
the default block applies without one, and a body that is not a JSON
object or a non-number block_duration returns HTTP 400 while the
request keeps running.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings December 3, 2026 21:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-03T21:55:12.849962Z c55ce9f PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@qinxuye qinxuye 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.

I ran the three request-abort suites on c55ce9f6 and got 167 passes. The remaining findings are inline.

Comment thread xinference/api/restful_api.py Resolved
Comment thread doc/source/user_guide/client_api.rst Resolved
David-Wu1119 and others added 2 commits December 4, 2026 01:27
…path

The route now accepts a fractional block_duration (1.5 is tested), but
CancelMixin._cancel_running_task, ModelActor.abort_request and
SupervisorActor.abort_request were annotated int, so mypy failed on
restful_api.py once the route narrowed the value to int | float.
asyncio.sleep already takes a float; annotate block_duration as float
there and in both clients' abort_request.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Say that block_duration can be left out of a JSON object body and that
the number rule applies only when it is present, in client_api.rst and
every client_api.po catalog. In the Korean catalog, put a noun after
the inline literals instead of a particle directly after the closing
backticks, which the built page showed as literal backticks; this also
fixes the media request ID paragraph.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@qinxuye qinxuye 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

@qinxuye
qinxuye merged commit ba310b7 into xorbitsai:main Dec 4, 2026
43 of 44 checks passed
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.

3 participants