[GH-ISSUE #2432] Server deadlocks when the console window is paused (QuickEdit selection): the finish path prints the done line while holding status_lock #987

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

Originally created by @anwang888 on GitHub (Oct 14, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/2432

Summary

On Windows, selecting text in the server's console window (QuickEdit) pauses the console — and that permanently deadlocks the server: the per-request finish path prints the [strata] done: line while holding status_lock, so the print blocks forever holding the lock, and every later request hangs on status_lock (in _progress / _note). The engine itself stays alive and healthy. Reproduced 3 times in real use on 0.1.43.1 (both IQ3_S and Unsloth UD-IQ4_XS); the same structure exists in 0.1.42 and 0.1.43.

Root cause

serve/server.py, the request-finish finally block (line numbers for 0.1.43.1; the same shape in 0.1.43 at 4029–4084 and 0.1.42 at 3935–3990):

finally:
    with self.status_lock:          # :4169
        ... ~50 lines of stats settlement ...
        print(f"[strata] done: {n} tokens in {el:.0f} s ({rate:.1f} tok/s) "
              f"({finish}, cancel={cancel.is_set()}){hit_msg}", flush=True)   # :4224 — inside the lock

When the console is paused (QuickEdit selection), print() blocks in WriteConsole while the lock is held. Three more print() calls sit inside this same with block (repeated-reasoning, max-tokens-while-thinking, etc.).

_progress() takes the same lock (with self.status_lock: at :3798), so the next request's first progress line parks there forever. /v1/status shows the request in_flight; the engine log's last line is the engine-side stats — the [strata] done: line is missing, which is the blocked print itself.

Reproduction (100%)

  1. Windows, start the model with the stock run-<model>.bat (a console window).
  2. Select any text in that console window with the mouse (QuickEdit) — e.g. to copy a log line. Do not press Esc.
  3. Send any chat request. The engine completes it (the engine's own stats line appears in the log), but the HTTP response never arrives.
  4. Every later request hangs too: py-spy shows request threads parked at _progress (serve/server.py:3798) (with self.status_lock:), double-sampled 12 s apart, identical; no thread in the process is inside status_lock at that point (the holder is the finish thread, blocked in the console write).
  5. Control experiment: the same server with stdout redirected to a file (no console) never hangs — same requests complete in ~2 s, done: lines print normally. A console-window run hangs again on the next selection.

Pressing Esc/Enter in the window should release the console and let the print finish (not tested here; we always restarted, which also recovers).

Suggested fix

Compute the done message inside the lock if needed, but move every print() in the finish path outside the with self.status_lock: block. The same applies to the other lock-held prints found in the finish/unload/error paths (_progress itself already prints outside its lock, which is the right pattern).

A wrapper that disables ENABLE_QUICK_EDIT_MODE at startup also mitigates it for anyone running the stock .bat files, but redirecting-vs-console is user-visible only after the fact — moving the prints out of the lock is the real fix.

Environment

  • Strata 0.1.43.1, engine self-built for sm_80 (CMP 170HX 64 GB), Windows 10 19045
  • Quantizations: ISTA-DASLab IQ3_S and Unsloth UD-IQ4_XS — both reproduce; quantization is irrelevant
  • Serving coding-agent sessions over the local API (/v1/messages and /v1/chat/completions)

Happy to attach py-spy dumps or the exact log excerpts if useful.

Originally created by @anwang888 on GitHub (Oct 14, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/2432 ## Summary On Windows, selecting text in the server's console window (QuickEdit) pauses the console — and that permanently deadlocks the server: the per-request finish path prints the `[strata] done:` line **while holding `status_lock`**, so the print blocks forever holding the lock, and every later request hangs on `status_lock` (in `_progress` / `_note`). The engine itself stays alive and healthy. Reproduced 3 times in real use on 0.1.43.1 (both IQ3_S and Unsloth UD-IQ4_XS); the same structure exists in 0.1.42 and 0.1.43. ## Root cause `serve/server.py`, the request-finish `finally` block (line numbers for 0.1.43.1; the same shape in 0.1.43 at 4029–4084 and 0.1.42 at 3935–3990): ```python finally: with self.status_lock: # :4169 ... ~50 lines of stats settlement ... print(f"[strata] done: {n} tokens in {el:.0f} s ({rate:.1f} tok/s) " f"({finish}, cancel={cancel.is_set()}){hit_msg}", flush=True) # :4224 — inside the lock ``` When the console is paused (QuickEdit selection), `print()` blocks in `WriteConsole` while the lock is held. Three more `print()` calls sit inside this same `with` block (repeated-reasoning, max-tokens-while-thinking, etc.). `_progress()` takes the same lock (`with self.status_lock:` at :3798), so the next request's first progress line parks there forever. `/v1/status` shows the request `in_flight`; the engine log's last line is the engine-side stats — **the `[strata] done:` line is missing**, which is the blocked print itself. ## Reproduction (100%) 1. Windows, start the model with the stock `run-<model>.bat` (a console window). 2. Select any text in that console window with the mouse (QuickEdit) — e.g. to copy a log line. Do not press Esc. 3. Send any chat request. The engine completes it (the engine's own stats line appears in the log), but the HTTP response never arrives. 4. Every later request hangs too: py-spy shows request threads parked at `_progress (serve/server.py:3798)` (`with self.status_lock:`), double-sampled 12 s apart, identical; no thread in the process is inside `status_lock` at that point (the holder is the finish thread, blocked in the console write). 5. Control experiment: the same server with stdout redirected to a file (no console) never hangs — same requests complete in ~2 s, `done:` lines print normally. A console-window run hangs again on the next selection. Pressing Esc/Enter in the window should release the console and let the print finish (not tested here; we always restarted, which also recovers). ## Suggested fix Compute the `done` message inside the lock if needed, but move every `print()` in the finish path **outside** the `with self.status_lock:` block. The same applies to the other lock-held prints found in the finish/unload/error paths (`_progress` itself already prints outside its lock, which is the right pattern). A wrapper that disables `ENABLE_QUICK_EDIT_MODE` at startup also mitigates it for anyone running the stock `.bat` files, but redirecting-vs-console is user-visible only after the fact — moving the prints out of the lock is the real fix. ## Environment - Strata 0.1.43.1, engine self-built for sm_80 (CMP 170HX 64 GB), Windows 10 19045 - Quantizations: ISTA-DASLab IQ3_S and Unsloth UD-IQ4_XS — both reproduce; quantization is irrelevant - Serving coding-agent sessions over the local API (`/v1/messages` and `/v1/chat/completions`) Happy to attach py-spy dumps or the exact log excerpts if useful.
Author
Owner

@qiuzan2001 commented on GitHub (Oct 15, 2026):

Confirmed in main 296b59d2 (Linux): the [strata] done print at serve/server.py:4490 (and 4493, 4497) runs inside with self.status_lock (line 4435), so a console that stops reading (QuickEdit on Windows, a full stdout pipe elsewhere) blocks every thread that next takes that lock. Open PR #2481's AST check (serve/test_lock_io.py) lists 9 such sites on main (server.py:1601, 1604, 4490, 4493, 4497; mcp.py:396, 445, 446; structured.py:48) and passes on that branch.

<!-- gh-comment-id:6184267218 --> @qiuzan2001 commented on GitHub (Oct 15, 2026): Confirmed in main 296b59d2 (Linux): the `[strata] done` print at serve/server.py:4490 (and 4493, 4497) runs inside `with self.status_lock` (line 4435), so a console that stops reading (QuickEdit on Windows, a full stdout pipe elsewhere) blocks every thread that next takes that lock. Open PR #2481's AST check (`serve/test_lock_io.py`) lists 9 such sites on main (server.py:1601, 1604, 4490, 4493, 4497; mcp.py:396, 445, 446; structured.py:48) and passes on that branch.
Author
Owner

@Niko1221 commented on GitHub (Oct 19, 2026):

Thanks for taking the time to report this.

We're resetting the tracker for 0.2.0-beta. There are more than 1,300 open issues and pull requests, too many for us to read properly, so we're closing everything that isn't being worked on right now. Closed here does not mean rejected.

To reopen it takes about two minutes:

  1. Re-test on 0.2.0-beta. 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:6271042666 --> @Niko1221 commented on GitHub (Oct 19, 2026): Thanks for taking the time to report this. We're resetting the tracker for 0.2.0-beta. There are more than 1,300 open issues and pull requests, too many for us to read properly, so we're closing everything that isn't being worked on right now. Closed here does not mean rejected. To reopen it takes about two minutes: 1. Re-test on 0.2.0-beta. 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#987
No description provided.