Repository navigation
server: cancel a running or queued request by its id - #3193
Merged
Merged
Conversation
This was referenced Nov 13, 2026
POST /v1/requests/{id}/cancel finds a request by the chatcmpl-, cmpl- or resp_ id its client got and sends the
engine the cancel a disconnect sends; the reply ends "cancelled" with the tokens it had, a queued one with none, and
other streams are unchanged. 404 request_not_found for an id no request holds.
The ids are held for the whole client request in openai.runNamed, and the ask rides on chat.Input, so every
generation for that request reads it (compaction's reply, Cortheon's rounds) and server-made ones never do. A
Cortheon turn stops after a cancelled round. A Responses reply ends with status "cancelled" in its
response.incomplete event, without completed_at, and a Responses socket keeps it like an incomplete one.
Who may cancel: with API keys, a full or [admin] key (the key gate refuses scoped keys, and the route checks the
matched key again). Without keys, only a caller whose socket is on loopback: the peer address from accept(), never
a header, including listener.peerText's IPv4-mapped form, which IpAddress.parse refuses. A keyless request that
carries Forwarded, X-Forwarded-For, X-Forwarded-Host, X-Real-IP, Via, CF-Connecting-IP or True-Client-IP is refused,
since a reverse proxy on the same machine makes every caller loopback. Refusals answer 403 loopback_only.
Fixes #3172
ashhart
force-pushed
the
lead/cancel-request-by-id
branch
from
November 13, 2026 17:02
1607ff4 to
6485ff4
Compare
ashhart
added a commit
that referenced
this pull request
Nov 13, 2026
…ays at 600 lines Main's cancel registration (#3193) and this PR's n dispatch together took openai.zig to 604 lines. The four VTable field notes move onto their lines; no code changes.
ashhart
added a commit
that referenced
this pull request
Nov 14, 2026
…ays at 600 lines Main's cancel registration (#3193) and this PR's n dispatch together took openai.zig to 604 lines. The four VTable field notes move onto their lines; no code changes.
ashhart
added a commit
that referenced
this pull request
Nov 15, 2026
…ays at 600 lines Main's cancel registration (#3193) and this PR's n dispatch together took openai.zig to 604 lines. The four VTable field notes move onto their lines; no code changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
POST /v1/requests/{id}/cancel(or/requests/{id}/cancel) cancels a running or queued request by the id the server returned: a chat completion'schatcmpl-, a completion'scmpl-or a Responsesresp_id. The engine gets the same cancel a client disconnect sends, so other streams are unchanged. The reply ends well formed with the tokens it had (none if it was still queued):finish_reason: "cancelled", or a Responsesstatus: "cancelled"in itsresponse.incompleteevent. A Cortheon turn runs no further rounds. An unknown or finished id answers 404request_not_found. The id is held for the whole client request, so compaction and Cortheon rounds honour the cancel, and the server's own requests (compaction notes, warm prefills) never take it.Who may cancel:
[admin]key. A scoped key gets 403insufficient_scopeand a missing key 401, before the body is read; the route checks the matched key again.Forwarded,X-Forwarded-For,X-Forwarded-Host,X-Real-IP,Via,CF-Connecting-IP,True-Client-IP) is refused, since a reverse proxy on the same machine makes every caller look local. Everyone else gets 403loopback_only.docs/api.mddocuments the route and says to give a proxied server keys.Tests (host only): a stream cancelled mid-decode through the route ends
cancelledwith its tokens so far and one engine cancel; a queued request ends at once with no tokens while the running stream's text is unchanged; a Responses turn cancelled by itsresp_id endscancelled; unknown ids answer 404; keyless refusals from remote IPv4 and IPv6 addresses and from a proxied loopback request; over sockets, scoped keys 403, no key 401, full keys 200. Ranzig build test-server-cpu(1351 pass),test-key-scopes-host,test-server-security,test-security-golden-hostandtest-connection-admission-host.Fixes #3172