mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #3686] [Engine] Metal: honor a client cancel during the prompt read (stop at the next chunk) #4750
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#4750
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/3686
Author: @ipriyaaanshu
Created: 10/22/2026
Status: 🔄 Open
Base:
main← Head:fix/cancel-prompt-read-metal-b📝 Commits (1)
00a0697Metal: honor a client cancel during the prompt read📊 Changes
1 file changed (+12 additions, -1 deletions)
View changed files
📝
src/program/generate.cpp(+12 -1)📄 Description
Problem
On Metal, a client cancel mid-prefill is honored only after the engine reads the whole prompt: the response is dead, but any next request queues behind the read for the remainder (issues: the repro in the linked issue; also the shape of #962's "cancel is ignored" reports).
Root cause
Prefill::runonSTRATA_GPU_METALreads the whole prompt in onemetal_engine::prompt_runcall, so theshould_stopchunk loop inprefill.cpponly runs on the CUDA-style backends.Window::promptdoes chunk the read (STRATA_METAL_PROMPT_CHUNK, default 2048) and aborts cleanly when itson_chunkreturnsfalse— but nothing returned false on a cancel.Fix (4 lines + comments)
STOPhandler also sets a file-scope atomicg_prompt_stop_req(the reader thread and the in-sharedstop_reqlive below where the E-9on_chunklambda needs the flag);on_chunklambda checks it and stops the read at the next chunk withe = "cancelled";stop_req(a STOP that arrived between requests is stale — without this the next request's read aborts instantly).Validation
Environment: Apple M4 Pro (MPS/Metal), macOS 27.0.1, branch built from
upstream/main(local revision00a06970on this PR's HEAD), pack Qwen3.8-Flash-Next-GSQ-RCO-Q2_0, served throughserve/server.pyto :8098 (--prefill 2048 --spec 2 --max-context 65536), prod instance untouched.02a8193da): 49k-token prompt, client disconnect at 8 s → engine log49192 of 49197 read in 213567 ms (230.3 tok/s), 0 generated (cancelled); a tiny request sent right after waited 207 s. Same shape on a local build of this base (cancel ignored).0 of 13409 read ... (cancelled)(with--prefill 2048) and1024 of 13407/3072 of 13408 read (cancelled)with--prompt-cache-every 1024; the tiny request right after every cancel served in 2.5-15 s (2.5-6 s at the 1024 cadence).The leftover work between the cancel and the stop is at most one chunk (
--prefill/STRATA_METAL_PROMPT_CHUNKtokens — seconds) instead of the remaining prompt (minutes at 262K).🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.