[GH-ISSUE #3675] [Engine] a client cancel during a single-stage prompt read does not stop the read (it runs to its DONE) #1519

Closed
opened 2026-11-04 01:51:55 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @ipriyaaanshu on GitHub (Oct 22, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/3675

Problem: a client cancel/disconnect during a prompt read does not stop the read on a single-GPU (single-stage) engine: the prompt is read to the end anyway, and any request queued behind it waits for the full read.

Environment: engine v0.2.0-beta-1-gf0774897 (built from source, Metal), macOS 27.0.1, Apple M4 Pro 48 GB unified memory, single GPU (no layer split), Qwen3.8-Flash-Next GSQ-RCO Q2_0 at 262144 context, --prefill auto --spec 2, conversation cache on. Read rate on this box ~200-250 tok/s.

Reproduce (streaming endpoint, fresh unique prompt so nothing is reused):

# 1. POST a ~49k-token prompt with stream:true, kill the connection 8 s in (curl -m 8)
# 2. immediately POST a 5-token request and time it

Expected: the read stops at the next prompt chunk after the disconnect, and the queued request proceeds. On 0.1.39/CUDA this is what happens (measured in #962: read stopped within ~4 s at the next 8192-token chunk, tiny follow-up 0.6 s).

Actual: the read does not stop. Reproduced live, once, plus the same signature across production logs:

strata serve: prompt 49197 tokens = 0 reused + 49192 of 49197 read in 213567 ms (230.3 tok/s), 0 generated in 0 ms (0.0 tok/s), drafts accepted 0 of 0, 4 checkpoints (cancelled)
  • Client gone at t=8.1 s; the engine kept reading for the remaining ~205 s.
  • A 5-token request sent immediately after the cancel answered after 207 s (it queued behind the dead read).
  • Production log shows the same at ~25k-token conversations: reads of 120-157 s that finish after the cancel, e.g. prompt 31410 tokens = 0 reused + 31405 of 31410 read in 157288 ms (199.7 tok/s) ... (cancelled).

serve is not the problem: it forwards the disconnect promptly (the #1182 half, confirmed merged — its merge commit says "the engine half (stop between prompt chunks) is open"). serve's own comment still documents the outcome: "true sends STOP once (the request is then read to its DONE)".

Suspected mechanism (unconfirmed static analysis, verifying with STRATA_TRACE next): in src/prefill/prefill.cpp the only should_stop check (line 2654 on this tree) sits inside the per-chunk loop:

for (int64_t c0 = 0; c0 < n; c0 += C) {
    if (should_stop && should_stop()) { err = "cancelled"; return false; }

but on a single-stage device plan_chunk() returns 0 (if (pipe <= 0.0 || hand_in_ != nullptr || stages < 2) return 0;), so C = m.T — the buffers' whole size. A 49k prompt then reads in one chunk and the check has no boundary to fire on. On the 0.1.39/CUDA box in #962 the auto chunk was 8192, so the same check landed within seconds. If STRATA_TRACE confirms one prompt chunk 0 of 49197 iteration for this read, that is the whole story.

Related: #962 (root report, closed in the 3-day sweep with "a new issue that links this one works too" — this is that issue), #471 (log accounting of a cancelled read, fixed in 0.1.36 — the N of M read format above is that fix), #1182 (serve half, merged 0.1.40.2), #2821 (interrupting a long response; a different half of interactivity).

Reproduction status: reproduced locally (three times in production logs + one live repro above); the single-chunk mechanism is static analysis until the STRATA_TRACE run.

Proposed scope (happy to send the PR): make a cancel land within seconds on single-stage reads too — e.g. bound the effective read granularity for the single-stage path (the layer-split path already reads in planned chunks), keep the checkpoints of the chunks that were read (the (cancelled) path already banks them — a re-send of the same prompt reuses 25491 tokens in ~300 ms here, which is a nice property worth keeping), and leave the queued-request preemption itself out (that is #2821's scope). Asking here first per CONTRIBUTING since it touches read granularity on the fast path — if bounding the chunk changes auto-scan throughput on some rig, an alternative is consulting should_stop at the internal batch boundaries inside the chunk.

Originally created by @ipriyaaanshu on GitHub (Oct 22, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/3675 Problem: a client cancel/disconnect during a prompt read does not stop the read on a single-GPU (single-stage) engine: the prompt is read to the end anyway, and any request queued behind it waits for the full read. Environment: engine v0.2.0-beta-1-gf0774897 (built from source, Metal), macOS 27.0.1, Apple M4 Pro 48 GB unified memory, single GPU (no layer split), Qwen3.8-Flash-Next GSQ-RCO Q2_0 at 262144 context, `--prefill auto --spec 2`, conversation cache on. Read rate on this box ~200-250 tok/s. Reproduce (streaming endpoint, fresh unique prompt so nothing is reused): ```sh # 1. POST a ~49k-token prompt with stream:true, kill the connection 8 s in (curl -m 8) # 2. immediately POST a 5-token request and time it ``` Expected: the read stops at the next prompt chunk after the disconnect, and the queued request proceeds. On 0.1.39/CUDA this is what happens (measured in #962: read stopped within ~4 s at the next 8192-token chunk, tiny follow-up 0.6 s). Actual: the read does not stop. Reproduced live, once, plus the same signature across production logs: ``` strata serve: prompt 49197 tokens = 0 reused + 49192 of 49197 read in 213567 ms (230.3 tok/s), 0 generated in 0 ms (0.0 tok/s), drafts accepted 0 of 0, 4 checkpoints (cancelled) ``` - Client gone at t=8.1 s; the engine kept reading for the remaining ~205 s. - A 5-token request sent immediately after the cancel answered after **207 s** (it queued behind the dead read). - Production log shows the same at ~25k-token conversations: reads of 120-157 s that finish *after* the cancel, e.g. `prompt 31410 tokens = 0 reused + 31405 of 31410 read in 157288 ms (199.7 tok/s) ... (cancelled)`. serve is not the problem: it forwards the disconnect promptly (the #1182 half, confirmed merged — its merge commit says "the engine half (stop between prompt chunks) is open"). serve's own comment still documents the outcome: *"true sends STOP once (the request is then read to its DONE)"*. Suspected mechanism (**unconfirmed static analysis**, verifying with STRATA_TRACE next): in `src/prefill/prefill.cpp` the only `should_stop` check (line 2654 on this tree) sits inside the per-chunk loop: ```cpp for (int64_t c0 = 0; c0 < n; c0 += C) { if (should_stop && should_stop()) { err = "cancelled"; return false; } ``` but on a single-stage device `plan_chunk()` returns 0 (`if (pipe <= 0.0 || hand_in_ != nullptr || stages < 2) return 0;`), so `C = m.T` — the buffers' whole size. A 49k prompt then reads in one chunk and the check has no boundary to fire on. On the 0.1.39/CUDA box in #962 the auto chunk was 8192, so the same check landed within seconds. If STRATA_TRACE confirms one `prompt chunk 0 of 49197` iteration for this read, that is the whole story. Related: #962 (root report, closed in the 3-day sweep with "a new issue that links this one works too" — this is that issue), #471 (log accounting of a cancelled read, fixed in 0.1.36 — the `N of M read` format above is that fix), #1182 (serve half, merged 0.1.40.2), #2821 (interrupting a long *response*; a different half of interactivity). Reproduction status: reproduced locally (three times in production logs + one live repro above); the single-chunk mechanism is static analysis until the STRATA_TRACE run. Proposed scope (happy to send the PR): make a cancel land within seconds on single-stage reads too — e.g. bound the effective read granularity for the single-stage path (the layer-split path already reads in planned chunks), keep the checkpoints of the chunks that were read (the `(cancelled)` path already banks them — a re-send of the same prompt reuses 25491 tokens in ~300 ms here, which is a nice property worth keeping), and leave the queued-request preemption itself out (that is #2821's scope). Asking here first per CONTRIBUTING since it touches read granularity on the fast path — if bounding the chunk changes auto-scan throughput on some rig, an alternative is consulting `should_stop` at the internal batch boundaries inside the chunk.
Author
Owner

@ipriyaaanshu commented on GitHub (Oct 22, 2026):

Filed the repro, and opened a minimal fix: Niko1221/Strata#3686 (Metal: the prompt read now stops at the next chunk on a client cancel — g_prompt_stop_req set from the stdin reader's STOP handler, checked in the prompt-read's on_chunk, cleared per request with stop_req). Numbers in the PR match this issue's repro (tiny-after-cancel: 207 s before → 3-15 s after).

<!-- gh-comment-id:6332824458 --> @ipriyaaanshu commented on GitHub (Oct 22, 2026): Filed the repro, and opened a minimal fix: Niko1221/Strata#3686 (Metal: the prompt read now stops at the next chunk on a client cancel — `g_prompt_stop_req` set from the stdin reader's STOP handler, checked in the prompt-read's `on_chunk`, cleared per request with `stop_req`). Numbers in the PR match this issue's repro (tiny-after-cancel: 207 s before → 3-15 s after).
Author
Owner

@Niko1221 commented on GitHub (Nov 5, 2026):

Thanks for taking the time to report this.

Strata has changed a lot since this was opened, and 0.2.11 is out now, so many older reports no longer apply. We're closing issues older than a week that have had no new reports in the last week. Closed here does not mean rejected.

To reopen it takes about two minutes:

  1. Re-test on 0.2.11. It may already be fixed. Write down what you see.
  2. Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other].
  3. Fill in the parts of the issue form: what happened, the Strata version, your graphics card, memory and system.
  4. Comment /reopen. A check runs and either reopens the issue or lists what is still missing.

The rules are in CONTRIBUTING.md.

<!-- gh-comment-id:6659599988 --> @Niko1221 commented on GitHub (Nov 5, 2026): Thanks for taking the time to report this. Strata has changed a lot since this was opened, and 0.2.11 is out now, so many older reports no longer apply. We're closing issues older than a week that have had no new reports in the last week. Closed here does not mean rejected. To reopen it takes about two minutes: 1. Re-test on 0.2.11. It may already be fixed. Write down what you see. 2. Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other]. 3. Fill in the parts of the issue form: what happened, the Strata version, your graphics card, memory and system. 4. Comment `/reopen`. A check runs and either reopens the issue or lists what is still missing. The rules are in [CONTRIBUTING.md](https://github.com/Niko1221/Strata/blob/main/CONTRIBUTING.md).
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#1519
No description provided.