[PR #603] serve: drain a stopped request to its DONE with one conversation (later requests got the previous answer) #622

Open
opened 2026-10-29 21:27:34 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/mw00/project-maya/pull/603
Author: @merbanan
Created: 10/28/2026
Status: 🔄 Open

Base: main ← Head: pr/serve-drain


📝 Commits (1)

  • e7e87e9 serve: a stopped request is drained to its DONE with one conversation - the drain went on after STRATA_DRAIN_S while the engine was still reading the prompt chunk (STOP is looked at between chunks, over a minute deep in a long context), and every later request read the one before's answer

📊 Changes

2 files changed (+86 additions, -7 deletions)

View changed files

📝 serve/server.py (+23 -7)
📝 serve/test_multi.py (+63 -0)

📄 Description

What

With one conversation (no --parallel), a request that's stopped is drained until its DONE. Before this change, the drain gave up after MAYA_DRAIN_S (60 s). If the engine was still working on the stopped request at that point, its T … DONE lines stayed in the shared line queue. The next request then read them as its own, and every request after that got the previous request's answer.

Seen on the live service. A client went away 70 s into reading a long prompt.

  • The engine checks STOP only between the prompt's chunks, and one 32K chunk deep in a 140K context takes more than a minute. So the drain logged stopped, and the engine did not say the request had ended within 60 s - going on.
  • From then on, the next request got the stopped one's tokens and DONE, and the request after that got its predecessor's answer. In the log this shows as done: 52 tokens in 0 s (95200 tok/s) and done: 0 tokens … (length).
  • One user asked a question in the web chat and then another in opencode; opencode received the web chat's answer. Only a restart cleared it.

The change

  • The single-stream drain waits for the stopped request's DONE (or ERR, or the engine's end). The engine is busy with that request either way, so going on early gains nothing.
  • A stuck engine still ends the drain. It uses the same stall watchdog as the read loop (MAYA_ENGINE_STALL_S: no CPU, disk or GPU work for that long), which ends the engine. The next request then starts it again.
  • MAYA_DRAIN_S is now when the drain logs that it's still waiting. When the request finally ends, the drain logs how long it took.
  • Unchanged:
    • The multi-conversation drain. Its lines are routed by rid, so a late DONE is dropped there, not handed to another request.
    • The handling of ERR and of the engine's end (_done_after_err, None put back).

Tests

serve/test_multi.py::AStoppedLongPrompt uses a fake single-stream engine that looks at STOP only after a 1.5 s "chunk", with DRAIN_S at 0.3 s. A request is stopped mid-prompt, and the next request must get its own tokens.

  • On main, it gets []: the stopped request's DONE ends it.
  • With this PR, it gets its own tokens.

serve/test_multi.py, test_server.py, test_fair.py and test_stop.py: 149 passed, 1 skipped.

The fix has been running on the live V100 GLM service since then.


🔄 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/mw00/project-maya/pull/603 **Author:** [@merbanan](https://github.com/merbanan) **Created:** 10/28/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `pr/serve-drain` --- ### 📝 Commits (1) - [`e7e87e9`](https://github.com/mw00/project-maya/commit/e7e87e9d9aca99a216adbd16c24ed1b8c53308ec) serve: a stopped request is drained to its DONE with one conversation - the drain went on after STRATA_DRAIN_S while the engine was still reading the prompt chunk (STOP is looked at between chunks, over a minute deep in a long context), and every later request read the one before's answer ### 📊 Changes **2 files changed** (+86 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `serve/server.py` (+23 -7) 📝 `serve/test_multi.py` (+63 -0) </details> ### 📄 Description ## What With one conversation (no `--parallel`), a request that's stopped is drained until its `DONE`. Before this change, the drain gave up after `MAYA_DRAIN_S` (60 s). If the engine was still working on the stopped request at that point, its `T … DONE` lines stayed in the shared line queue. The next request then read them as its own, and every request after that got the previous request's answer. **Seen on the live service.** A client went away 70 s into reading a long prompt. - The engine checks `STOP` only between the prompt's chunks, and one 32K chunk deep in a 140K context takes more than a minute. So the drain logged `stopped, and the engine did not say the request had ended within 60 s - going on`. - From then on, the next request got the stopped one's tokens and `DONE`, and the request after that got its predecessor's answer. In the log this shows as `done: 52 tokens in 0 s (95200 tok/s)` and `done: 0 tokens … (length)`. - One user asked a question in the web chat and then another in opencode; opencode received the web chat's answer. Only a restart cleared it. ## The change - **The single-stream drain waits** for the stopped request's `DONE` (or `ERR`, or the engine's end). The engine is busy with that request either way, so going on early gains nothing. - **A stuck engine still ends the drain.** It uses the same stall watchdog as the read loop (`MAYA_ENGINE_STALL_S`: no CPU, disk or GPU work for that long), which ends the engine. The next request then starts it again. - **`MAYA_DRAIN_S` is now when the drain logs** that it's still waiting. When the request finally ends, the drain logs how long it took. - **Unchanged:** - The multi-conversation drain. Its lines are routed by rid, so a late `DONE` is dropped there, not handed to another request. - The handling of `ERR` and of the engine's end (`_done_after_err`, `None` put back). ## Tests `serve/test_multi.py::AStoppedLongPrompt` uses a fake single-stream engine that looks at `STOP` only after a 1.5 s "chunk", with `DRAIN_S` at 0.3 s. A request is stopped mid-prompt, and the next request must get its own tokens. - On main, it gets `[]`: the stopped request's `DONE` ends it. - With this PR, it gets its own tokens. `serve/test_multi.py`, `test_server.py`, `test_fair.py` and `test_stop.py`: 149 passed, 1 skipped. The fix has been running on the live V100 GLM service since then. --- <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 labels
pull-request
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
mw00/project-maya#622
No description provided.