mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #2481] [Engine] decouple request lifecycle from blocked console output #4066
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#4066
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/2481
Author: @KeyanHu-git
Created: 10/14/2026
Status: 🔄 Open
Base:
main← Head:fix/2432-console-state-locks📝 Commits (2)
0dc828a[Engine] decouple request lifecycle from blocked console outputfa31622[Engine] simplify diagnostic ownership and preserve planning output📊 Changes
19 files changed (+1471 additions, -200 deletions)
View changed files
➕
docs/CONSOLE_OUTPUT.md(+39 -0)📝
serve/cache_drop.py(+3 -1)➕
serve/console.py(+190 -0)📝
serve/frontend.py(+4 -2)📝
serve/images.py(+6 -4)📝
serve/mcp.py(+8 -7)📝
serve/replicas.py(+6 -4)📝
serve/server.py(+176 -154)📝
serve/session_save_retry.py(+4 -2)📝
serve/structured.py(+5 -4)📝
serve/telemetry.py(+3 -1)➕
serve/test_console.py(+509 -0)➕
serve/test_console_handover.py(+141 -0)➕
serve/test_console_requests.py(+299 -0)➕
serve/test_console_support.py(+31 -0)📝
serve/test_server.py(+17 -17)📝
serve/test_tool_call_envelope.py(+2 -2)📝
sycl/serve/server_intel.py(+2 -2)➕
tests/terminal/test_console_capture.py(+26 -0)📄 Description
Problem and result
Pausing a terminal or filling its output pipe can prevent a cancelled request from handing the engine to the next request. Completion diagnostics can also keep an HTTP admission reservation occupied after generation finishes. These writes are still inside the lifetime of request resources, even when moved outside a state lock.
This change publishes runtime diagnostics to one bounded background writer so cancellation, engine cleanup and HTTP completion can proceed while output remains blocked.
Related discussion
Fixes #2432. Fixes #4479. Base:
46c152a1.Approach
The queue keeps at most 128 pending records and 64 KiB of text, with a 4 KiB limit per record. A single progress slot replaces stale samples; request cleanup removes its pending sample by identity.
Each destination owns an unbuffered, non-inheritable descriptor. Records retain that owner until delivery or discard. Two caches reuse the current stdout/stderr destinations, so stable output does not duplicate a descriptor for each record. Closing the caller's stream or reusing its descriptor cannot redirect a delayed write. A failure affects that destination's write, without permanently disabling future stdout or stderr destinations.
Configuration helpers keep synchronous output: the CLI captures their notes immediately. Runtime restart, recovery and shutdown diagnostics use the writer. Engine traffic, model tokens, HTTP responses, ready files and structured lifecycle events retain their existing paths. Server errors retain the request peer and traceback.
before_loadstdout/stderr go to a temporary file, with the last 3072 bytes published when the hook ends. Capture failures do not replace its exit status, timeout or strict-mode decision. The telemetry error diagnostic uses the same writer: a synchronous daemon print can otherwise retain Python's buffered stdout lock during interpreter shutdown.Validation
Candidate:
fa316228. Python 3.12 on macOS and Windows 11 unless noted. Service tests use actual handlers and mock engines; they load no model.Passed:
python -m unittest serve.test_console serve.test_console_requests serve.test_console_handover tests.terminal.test_console_capture tests.terminal.test_runtime.RuntimeTests.test_foreground_jsonl_emits_ready_and_stop_without_human_stdout tests.terminal.test_ready -v— 30 run, 29 passed, one Windows-only skip; 9.943 s. Includes real CLI JSONL/quiet/signal subcases and ready-file lifecycle.python -m unittest serve.test_console serve.test_console_requests serve.test_console_handover -v— 26 run, 25 passed, one POSIX-only skip; 5.994 s. Includes native Unicode console readback at CP437/CP936, newline behavior, and a real unread output pipe. Transferred sources were hash-checked against the submitted candidate.python -m unittest serve.test_console_requests serve.test_console_handover serve.test_server serve.test_tool_call_envelope— 374 passed. After the progress interface correction, the affected request/handover/ThinkingBudget subset passed 26 tests. Hook capture create/read/close failures are crossed with successful, failing and timed-out commands.Telemetry._loopwith synchronous output to a full pipe aborted with_enter_buffered_busy; routing the same diagnostic asynchronously exited normally.python -m compileall -q serve sycl/serve/server_intel.pyandgit diff --checkpassed. The SYCL Python image-warning path was invoked separately to check the new diagnostic API.Failed: the first foreground CLI run exited before server startup because the test virtualenv lacked yaml, psutil and numpy. After installing the repository-pinned dependencies in that test environment, the CLI/ready tests passed. No unresolved final focused-test failures.
Not run: manual QuickEdit selection, live-model execution and native CUDA/HIP/SYCL/Metal builds. No native engine source is changed. The PR remains draft for expanded-scope review and remaining platform acceptance.
Limits
Diagnostics are best-effort: long messages are truncated, overflow can drop records, and shutdown waits at most 0.2 seconds for the writer. A timeout does not close a destination still being written. Cached destinations can remain open until replaced or the writer exits. Hook output can grow its temporary file. External logging handlers and commands opening their own console are separate paths. See console diagnostics.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.