Pull requests / #2481

#2481 serve: keep console writes outside shared state locks

open · @KeyanHu-git · 0 comentários · No GitHub

Server & APIWindows

Descrição

## Title

serve: keep console writes outside shared state locks

Issue: Resolves #2432

## Summary

The request-finish path prints its completion line while holding `status_lock`. When Windows QuickEdit pauses the console, that write waits with the lock held, blocking status queries and progress updates.

Build the completion messages while updating state, then print them after releasing both `status_lock` and the serial engine turn (`fifo`). A completed request no longer retains either lock while waiting for its console write. Apply the same state-lock ordering to batch-slot admission, MCP startup and restart, and the optional schema dependency message.

## What changed

Each operation collects its log lines under the state lock and writes them after release. Request completion first settles its statistics and status, exits the engine turn, then writes the saved lines. The request-finish, batch-slot and MCP paths use an outer `finally`, so prepared messages are still written if the operation raises. Messages retain their order within each operation.

The orphan-slot reaper returns the slots it freed to its caller, which reports them outside the condition lock. Locks that serialize engine-pipe writes and configuration updates continue to cover those operations.

## Extra Notes

Four regression tests cover blocked console output, output under state locks and exception paths. The blocked-output test checks that both `status_lock` and `fifo` are available while the completion writer waits. It fails against the earlier revision, which still held `fifo`, and passes with this change on macOS and Windows. The full service suite passes on macOS: 778 tests and 5638 subtests, with 11 skips.

An HTTP check on both platforms pauses the completion-line writer while a request is finishing. `/v1/status` returns HTTP 200 while that writer is blocked, and the chat request completes after the writer is released. These checks use a mock engine and a blocking stdout replacement to reproduce console backpressure. The printing thread waits for the console; shared state and the serial engine turn are available to other handlers. Other synchronous log writes can still wait on a paused console.

No site

Links install, modelos, releases.