xcl run: echo log lines on a thread of their own, never blocking a caller #3430
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3430"
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?
Imported from ivall/xcl. Originally posted by vakaobr on 2026-11-29T15:41:17Z.
log::writecopies every Info line to stderr on the thread that logged it, after the file line. When nothing reads stderr, that write blocks: a pipe whose reader stopped, or a Windows console with text selected in it. Each thread that logs then stops right after its file line, including the title's own threads inside a console call, and the title freezes with nothing in the log to say why. Part of #258.What is in it
crates/xcl/src/log.rs: the stderr copy goes through a bounded queue (4096 lines) to anxcl-stderrthread, so a caller never waits. With the queue full a line is dropped and counted, and the next line copied says how many were left out. The file write is unchanged and still comes first.log::flushgives the copy up to 200 ms to catch up.an_unread_stderr_does_not_stop_the_thread_that_logs: runs the test binary again as a child whose stderr is a pipe the test never reads; the child logs 4000 lines and must exit within 30 s. It fails without the change ("logging stopped on a stderr nobody reads").Tested
x86_64-pc-windows-gnu; head4a99fceonmain9dfbe3e.log::tests(debug,--test-threads=4): 2 passed, 0 failed. With the old blocking echo put back,an_unread_stderr_does_not_stop_the_thread_that_logsfails after 30 s.xcl.logended at 69 lines; after, 240 s at 60 fps to the end, 402 log lines, exit code 0 (measured on my Mac branch with the same change).Regression run
scripts/smoke.ps1. I am asking on #258 for a pair.Not tested
AI use
Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-29T15:55:35Z.
Native Windows check on Ryzen 7 5700X3D, Rust 1.100.0 MSVC. I compiled the
log.rsmodules unchanged atbc2cbb72and218bc95bin a small native harness that imports the same Win32 calls. Both stock logger tests passed on the PR, serially.The separate overflow control used four producers, 8,192 numbered Info lines and a parent process that deliberately left the child's stderr pipe unread until the producers and
flush()had returned. The base reached 50 file lines and was still blocked at the 3 s watchdog. On the PR, producers finished in 60–67 ms across the runs and the bounded flush returned in 201–205 ms. Every file held all 8,192 unique IDs. After resuming the reader, stderr held 4,143 unique messages plus a summary of 4,049 dropped echoes. The totals reconciled on every run.One scope detail for the test suite: a direct Rust
eprintln!in the same process still waited through a 150 ms observation and completed once the reader resumed. The stock unread-stderr test also restored the process-wide stderr handle while queued lines remained, and some lines printed after the test reported completion. An isolated child would keep that handle change and its pending writes away from parallel tests. This concerns direct stderr calls. Thelog::writeproducers completed before the reader resumed.This exercises the logger and native Windows pipe behavior without a GPU or retail smoke run. AI disclosure: OpenAI Codex (GPT-6.2 Sol) implemented and ran the process harness and drafted this report.
Imported from ivall/xcl. Originally posted by vakaobr on 2026-11-30T13:21:14Z.
@andrewDoing thanks for the native check, and for the point about the test. I changed it as you suggested (
4a99fce): the logging now runs in a child process of the test binary whose stderr is a pipe the test never reads, so neither the blocked pipe nor the queued lines reach the other tests. On a Mac (CrossOver 26.3),log::testspasses running 4 at a time, and no child line shows up in the test output any more. With the old blocking echo put back, the test fails after its 30 s limit (logging stopped on a stderr nobody reads (child: None)). Directeprintln!calls are outside this PR, as you say.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T08:52:20Z.
Review (head
4a99fce5, diff read, not a merge-check; draft,PR descriptionred, no Windows run):flush()can now cost 200 ms every time (log.rs~134-138). It sleeps until the echo queue is empty or 200 ms pass. Some paths always pay the full 200 ms:end_title(real.rs~4897 on main) has already suspended thexcl-stderrthread, so what the drain logs is never echoed.DLL_PROCESS_DETACH(loader.rs~434) ExitProcess has already ended the echo thread, and this sleep then runs under the loader lock.Skipping the wait when the echo thread can't run, or making it a single wait at exit, would avoid that. What was still queued at a crash or at exit doesn't reach the console. The file has it, but the description should say so.
The "N lines not echoed" note (~108-112) is printed before the next queued line, which is older than the dropped ones, so it shows up early in the console.
The queue is bounded at 4096 lines, not bytes. Some lines are several KB (the thread dump at
eh.rs~986), so a long-paused console can hold several MB.The test logs 4000 lines, fewer than the queue holds, so the drop path and the note are never run. Nothing checks that the file still gets every line.
Still missing: a Windows suite run and the smoke pair (this is a runtime change). It will conflict textually with #2634, #2286 and #1589, which edit the same code.
Fine: the file write is unchanged and still comes first, so
xcl.logkeeps its order.try_sendnever blocks a caller, and the echo thread never logs, so it can't deadlock on itself. The thread is spawned lazily without holding a log lock, a failed spawn just skips the echo, and the pending count is kept right on a failed send. The test runs in a child process, so its blocked pipe doesn't affect other tests.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T09:54:31Z.
Triage (#1607) – head
4a99fceNo open or merged PR moves the stderr echo off the logging thread; #2286 and #2634 only add stderr messages when the log cannot be written, and #1831 adds a separate error writer. Part of #258.
The test exercises the change:
ECHOdefaults to true, and the child writes throughstd::io::stderr(), which test output capture does not intercept.Minor: lines the echo thread writes can now reach stderr after direct
eprintln!output written later (e.g. host start errors), andlog::flushwaits up to 200 ms whenever stderr is blocked; its callers are exit and watchdog paths, so that is bounded.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.