[PR #4196] [Engine] keep batch waits alive and cancel before admission #4944

Open
opened 2026-11-07 16:31:31 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4196
Author: @wujian47
Created: 10/26/2026
Status: 🔄 Open

Base: main ← Head: codex/batch-wait-cancellation


📝 Commits (1)

  • 0a5cb48 [Engine] keep batch waits alive and cancel before admission

📊 Changes

2 files changed (+226 additions, -2 deletions)

View changed files

📝 serve/server.py (+23 -2)
➕ serve/test_batch_waits.py (+203 -0)

📄 Description

Problem and result

When every batch slot is occupied, the admission loop can keep reacquiring an available control lock without yielding an HTTP keep-alive. A queued streaming client then stays silent until a slot opens. A disconnected client can also reach GEN/BGEN when control acquisition or slot selection succeeds immediately, and a quiet decoding slot can take ten seconds to receive BSTOP.

Keep full-slot waiters alive every ten seconds, check cancellation at admission boundaries, and poll quiet slot output at 0.5-second intervals. Cancellation still retains the slot until BDONE; the existing ten-second stream heartbeat is preserved.

Searched open and closed PRs for batch heartbeats, full slots and cancellation. #1673/#1619 concern the single-turn queue, and #1182 concerns quiet prompt/control reads; these fixes remain intact. This addresses the separate full-slot wait and slot-output paths. No new setting, default change or native-engine change is proposed.

Approach

Keep a heartbeat clock across full-slot waits instead of relying on a newly entered control-lock wait. Recheck cancellation before sending a command. Separate the short cancellation poll from the HTTP heartbeat in the slot reader, preserving existing STOP/BSTOP, DONE/BDONE and cleanup ownership.

Validation

Windows 11 x64, Python 3.12.0rc3. Base 4b9e05a2a806a3fe24f7b2560d98626c37dade35; tested candidate 0a5cb48c98eec9054018eac086491bf1b917dd14 (the committed tree is the tree tested).

Passed:

python -m unittest serve.test_batch_waits serve.test_control_cancel serve.test_quiet_cancel serve.test_queue_keepalive serve.test_parallel serve.test_parallel_yield serve.test_admit_order serve.test_slots serve.test_slot_alloc serve.test_restart_waiters serve.test_fatal_recovery -v
# Ran 118 tests in 121.810s; OK (skipped=1)
git diff HEAD^ HEAD --check

The six new tests exercise the real Python generators with in-memory pipes and a simulated clock. They cover silent full-slot waits, pre-cancelled/immediately admitted requests, cancellation during lock/slot acquisition, prompt BSTOP delivery, BDONE ownership and heartbeat cadence. Existing scripted-process and HTTP regressions also run in the command above.

Failed:

Before applying the fix, python -m unittest serve.test_batch_waits -v on the base above reproduced eight failing assertions across five test methods: no full-slot heartbeats, cancelled GEN/BGEN commands, and ten-second quiet-slot cancellation. After the fix all six methods passed. No remaining failure was observed in the selected candidate run.

Not run:

GPU/model inference on this current-main candidate, other operating systems and full repository discovery. These Python-only changes do not modify a native backend; CUDA/HIP/SYCL/Metal builds were not run for this PR.

Limits

This improves server-side keep-alives and cancellation delivery; it does not bound how quickly native GPU work responds to BSTOP, add strict FIFO admission or claim an inference-throughput gain. Separate older-version hardware backports are not presented as tests of this PR head.

Prepared and reviewed with OpenAI coding assistants; the commands and reported outcomes were checked against actual output.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/4196 **Author:** [@wujian47](https://github.com/wujian47) **Created:** 10/26/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `codex/batch-wait-cancellation` --- ### 📝 Commits (1) - [`0a5cb48`](https://github.com/Niko1221/Strata/commit/0a5cb48c98eec9054018eac086491bf1b917dd14) [Engine] keep batch waits alive and cancel before admission ### 📊 Changes **2 files changed** (+226 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `serve/server.py` (+23 -2) ➕ `serve/test_batch_waits.py` (+203 -0) </details> ### 📄 Description ## Problem and result When every batch slot is occupied, the admission loop can keep reacquiring an available control lock without yielding an HTTP keep-alive. A queued streaming client then stays silent until a slot opens. A disconnected client can also reach GEN/BGEN when control acquisition or slot selection succeeds immediately, and a quiet decoding slot can take ten seconds to receive BSTOP. Keep full-slot waiters alive every ten seconds, check cancellation at admission boundaries, and poll quiet slot output at 0.5-second intervals. Cancellation still retains the slot until BDONE; the existing ten-second stream heartbeat is preserved. ## Related discussion Searched open and closed PRs for batch heartbeats, full slots and cancellation. #1673/#1619 concern the single-turn queue, and #1182 concerns quiet prompt/control reads; these fixes remain intact. This addresses the separate full-slot wait and slot-output paths. No new setting, default change or native-engine change is proposed. ## Approach Keep a heartbeat clock across full-slot waits instead of relying on a newly entered control-lock wait. Recheck cancellation before sending a command. Separate the short cancellation poll from the HTTP heartbeat in the slot reader, preserving existing STOP/BSTOP, DONE/BDONE and cleanup ownership. ## Validation Windows 11 x64, Python 3.12.0rc3. Base `4b9e05a2a806a3fe24f7b2560d98626c37dade35`; tested candidate `0a5cb48c98eec9054018eac086491bf1b917dd14` (the committed tree is the tree tested). **Passed:** ```sh python -m unittest serve.test_batch_waits serve.test_control_cancel serve.test_quiet_cancel serve.test_queue_keepalive serve.test_parallel serve.test_parallel_yield serve.test_admit_order serve.test_slots serve.test_slot_alloc serve.test_restart_waiters serve.test_fatal_recovery -v # Ran 118 tests in 121.810s; OK (skipped=1) git diff HEAD^ HEAD --check ``` The six new tests exercise the real Python generators with in-memory pipes and a simulated clock. They cover silent full-slot waits, pre-cancelled/immediately admitted requests, cancellation during lock/slot acquisition, prompt BSTOP delivery, BDONE ownership and heartbeat cadence. Existing scripted-process and HTTP regressions also run in the command above. **Failed:** Before applying the fix, `python -m unittest serve.test_batch_waits -v` on the base above reproduced eight failing assertions across five test methods: no full-slot heartbeats, cancelled GEN/BGEN commands, and ten-second quiet-slot cancellation. After the fix all six methods passed. No remaining failure was observed in the selected candidate run. **Not run:** GPU/model inference on this current-main candidate, other operating systems and full repository discovery. These Python-only changes do not modify a native backend; CUDA/HIP/SYCL/Metal builds were not run for this PR. ## Limits This improves server-side keep-alives and cancellation delivery; it does not bound how quickly native GPU work responds to BSTOP, add strict FIFO admission or claim an inference-throughput gain. Separate older-version hardware backports are not presented as tests of this PR head. Prepared and reviewed with OpenAI coding assistants; the commands and reported outcomes were checked against actual output. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#4944
No description provided.