xcl run: echo log lines on a thread of their own, never blocking a caller #3430

Open
vakaobr wants to merge 1 commit from upstream-pr/3430 into main
vakaobr commented 2026-11-29 15:41:17 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by vakaobr on 2026-11-29T15:41:17Z.


log::write copies 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 an xcl-stderr thread, 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::flush gives the copy up to 200 ms to catch up.
  • New test 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

  • M5 Pro, macOS 27.2.1, CrossOver 26.3 (Wine) with D3DMetal, Rust 1.100, x86_64-pc-windows-gnu; head 4a99fce on main 9dfbe3e.
  • 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_logs fails after 30 s.
  • The test title presenting on the 60 Hz frame clock with stderr to a pipe nobody reads: before, frames stopped about 2 s in and xcl.log ended 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).
  • Windows: andrewDoing's native harness check above (Ryzen 7 5700X3D, MSVC).

Regression run

  • None yet: I have no Windows machine for scripts/smoke.ps1. I am asking on #258 for a pair.

Not tested

  • Windows (any GPU), the whole suite, a retail title.

AI use

  • Claude Code with Claude Opus 5.5: reproduced the freeze with the test title, wrote the change and the test, ran them on my Mac, and drafted this description. I checked it before opening.
<!-- greyfinch-sync:ivall/xcl:issue:5552299730 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3430). Originally posted by [vakaobr](https://github.com/vakaobr) on 2026-11-29T15:41:17Z. --- `log::write` copies 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 an `xcl-stderr` thread, 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::flush` gives the copy up to 200 ms to catch up. - New test `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** - M5 Pro, macOS 27.2.1, CrossOver 26.3 (Wine) with D3DMetal, Rust 1.100, `x86_64-pc-windows-gnu`; head `4a99fce` on `main` `9dfbe3e`. - `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_logs` fails after 30 s. - The test title presenting on the 60 Hz frame clock with stderr to a pipe nobody reads: before, frames stopped about 2 s in and `xcl.log` ended 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). - Windows: andrewDoing's native harness check above (Ryzen 7 5700X3D, MSVC). **Regression run** - None yet: I have no Windows machine for `scripts/smoke.ps1`. I am asking on #258 for a pair. **Not tested** - Windows (any GPU), the whole suite, a retail title. **AI use** - Claude Code with Claude Opus 5.5: reproduced the freeze with the test title, wrote the change and the test, ran them on my Mac, and drafted this description. I checked it before opening.
andrewDoing commented 2026-11-29 15:55:35 +00:00 (Migrated from github.com)

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.rs modules unchanged at bc2cbb72 and 218bc95b in 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. The log::write producers 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.

<!-- greyfinch-sync:ivall/xcl:comment:7258477304 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3430#issuecomment-7258477304). Originally posted by [andrewDoing](https://github.com/andrewDoing) on 2026-11-29T15:55:35Z. --- Native Windows check on Ryzen 7 5700X3D, Rust 1.100.0 MSVC. I compiled the `log.rs` modules unchanged at `bc2cbb72` and `218bc95b` in 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. The `log::write` producers 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.
vakaobr commented 2026-11-30 13:21:14 +00:00 (Migrated from github.com)

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::tests passes 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)). Direct eprintln! calls are outside this PR, as you say.

<!-- greyfinch-sync:ivall/xcl:comment:7279721757 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3430#issuecomment-7279721757). Originally posted by [vakaobr](https://github.com/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::tests` passes 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)`). Direct `eprintln!` calls are outside this PR, as you say.
Foniass commented 2026-12-01 08:52:20 +00:00 (Migrated from github.com)

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 description red, 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 the xcl-stderr thread, so what the drain logs is never echoed.
    • At DLL_PROCESS_DETACH (loader.rs ~434) ExitProcess has already ended the echo thread, and this sleep then runs under the loader lock.
    • With a blocked console (the case this PR is for), the stop-file path, which flushes 4-5 times, adds about a second.

    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.log keeps its order. try_send never 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.

<!-- greyfinch-sync:ivall/xcl:comment:7305895729 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3430#issuecomment-7305895729). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T08:52:20Z. --- Review (head 4a99fce5, diff read, not a merge-check; draft, `PR description` red, 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 the `xcl-stderr` thread, so what the drain logs is never echoed. - At `DLL_PROCESS_DETACH` (`loader.rs` ~434) ExitProcess has already ended the echo thread, and this sleep then runs under the loader lock. - With a blocked console (the case this PR is for), the stop-file path, which flushes 4-5 times, adds about a second. 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.log` keeps its order. `try_send` never 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.
Foniass commented 2026-12-01 09:54:31 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T09:54:31Z.


Triage (#1607) – head 4a99fce

No 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: ECHO defaults to true, and the child writes through std::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), and log::flush waits 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.

<!-- greyfinch-sync:ivall/xcl:comment:7307382737 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3430#issuecomment-7307382737). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T09:54:31Z. --- **Triage (#1607)** – head 4a99fce No 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: `ECHO` defaults to true, and the child writes through `std::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), and `log::flush` waits 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.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3430:upstream-pr/3430'
git switch 'upstream-pr/3430'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/3430'
git switch 'upstream-pr/3430'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3430'
git switch 'upstream-pr/3430'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3430'
git switch 'main'
git merge --squash 'upstream-pr/3430'
git switch 'main'
git merge --ff-only 'upstream-pr/3430'
git switch 'main'
git merge 'upstream-pr/3430'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
xcl-dev/xcl!3430
No description provided.