D3D12.X: batch used-pipelines.txt writes off the bind lock #2635

Open
github-bot wants to merge 1 commit from github-bot/gh-2635 into main AGit
Owner

@⁠Decodere on GitHub · 2026-11-26 03:37 UTC · original
Decodere:fix-pso-async-batch-used-writes → main · +480 −26 · 3 files · 1 commits · open

What is in it

Part of #2508
Part of #1833

pso_async::used::note() (crates/xcl/src/hle/d3d12x/pso_async.rs) previously ran synchronous create_dir_all, OpenOptions::open, and unbuffered writeln!(f, "{key:016x}") syscalls while holding the global used::now mutex on the title's command-recording / bind thread (Pending::note_use, called from resolve and resolve_wait_for). During world-load pipeline bursts, every newly used pipeline serialized bind threads behind disk I/O.

Changes (3 files: crates/xcl/src/hle/d3d12x/pso_async.rs, crates/xcl/src/host.rs, crates/xcl/src/eh.rs):

  • Extracted used::Journal backed by a single lightweight writer thread (xcl-pso-used), Mutex<JournalState>, wake_cv, and flushed_cv.
    • Journal::note(key) performs zero filesystem syscalls on the caller thread or under the state mutex: it inserts into seen, appends to pending (continuing to queue keys while fallback_path is set even if writer spawn failed), and notifies wake_cv only on empty-to-nonempty (1) and burst-threshold (64) transitions.
    • writer_loop coalesces bursts up to 25 ms (draining immediately at 64 unique keys), drains pending via std::mem::take, drops the mutex before I/O, lazily creates parent directories and opens used-pipelines.txt, performs a single batched write_all + flush, and updates completed_seq = completed_seq.max(batch_seq) so a slow batch never regresses completed_seq below a timed-out flush_bounded() drain. I/O failures clear the cached handle and never panic or break in-memory deduplication.
    • Kept if cfg!(test) isolated from the user's cache file (Journal::in_memory, with a test-only XCL_TEST_USED_STATIC_PATH env hook for subprocess exit verification) and left counts() un-flushed (present.rs calls it on PresentX).
  • Process-exit persistence for static U: OnceLock<Used> (addressing @luckyteagirl's exit-flush review and @KDenKC's follow-up review):
    • Wrapped Journal::writer in Mutex<Option<JoinHandle<()>>> so Journal::shutdown(&self) flushes pending keys and joins xcl-pso-used through a shared &'static reference (Drop delegates to shutdown()), draining any remaining pending keys to fallback_path if no writer thread was spawned; added Journal::flush_bounded(&self, timeout) with a direct-append fallback to fallback_path if xcl-pso-used times out (e.g., blocked on the Windows loader lock during a fast ExitProcess) or failed to spawn.
    • Registered CRT atexit(on_process_exit) -> used::shutdown() when used::init_from_path initializes the file-backed static journal (covering ordinary main() return).
    • Wired pso_async::shutdown_used() into crates/xcl/src/host.rs on both normal shutdown boundaries (XCL_RUN_SECONDS before real::end_title(0) and normal return from loader::run_main).
    • Wired pso_async::flush_used_bounded(100 ms) into crates/xcl/src/eh.rs::hk_nt_terminate_process alongside crate::log::flush() so titles exiting directly via Win32 ExitProcess flush pending keys before NtTerminateProcess ends worker threads.
  • Added pure-CPU unit tests in pso_async::used_tests:
    • used_note_does_not_block_on_slow_writer
    • used_burst_coalesces_writes_and_deduplicates_keys
    • used_flush_drop_lazy_file_and_io_error_are_graceful
    • used_static_once_lock_flushes_on_process_exit (subprocess test covering normal return via atexit, Win32 ExitProcess via eh::install_crash_handler + std::process::exit(0), explicit shutdown_used(), and flush_used_bounded() without dropping a local Journal, using a 60 s coalesce window)
    • used_flush_bounded_timeout_and_spawn_failure_fallback_are_sound (verifying completed_seq stays monotonic across a timed-out flush_bounded() so a subsequent flush() never hangs, and verifying note() + flush_bounded() / shutdown() persist keys directly to fallback_path when writer thread spawn fails).

Tested

  • Hardware & toolchain: Windows 11 Home (build 26200), Intel Core i5-11400F (6C/12T), 32 GB RAM, NVIDIA GeForce RTX 4060 8 GB (driver 621.14), rustc 1.100.0, DXC 1.9.2609.5 (01b62ad4), release builds.
  • Failing-first reproduction on unmodified PR head bd9b4008:
    • used_static_once_lock_flushes_on_process_exit failed immediately (0 passed; 1 failed: static OnceLock journal lost keys on process exit: NotFound) because static U: OnceLock<Used> did not run Drop on process exit before the coalesce window elapsed.
  • WARP (XCL_ADAPTER=warp, XCL_WARP=1): cargo test --release -p xcl --lib -- hle::d3d12x::pso_async:: --test-threads=4 --nocapture -> 19 passed; 0 failed; 0 ignored (0 skipped, 0.82 s).
  • RTX 4060 targeted: cargo test --release -p xcl --lib -- hle::d3d12x::pso_async:: --test-threads=4 --nocapture -> 19 passed; 0 failed; 0 ignored (0 skipped, 0.81 s).
  • Full release workspace on RTX 4060: cargo test --release --workspace --no-fail-fast -- --test-threads=4 --nocapture: 37 test binaries, 1440 passed, 0 failed, 47 ignored (0 new warnings), 29 pre-existing host-gated SKIPPED lines (none in pso_async):
    • 21 wave64-only GPU tests (no wave64 on RTX 4060 32-lane waves)
    • 3 per-lane wave32 shader tests (refused)
    • 3 D3D12 debug layer tests (no d3d12SDKLayers.dll / debug layer unavailable)
    • 1 heap-window OOM fallback test (no heap windows)
    • 1 PSO driver-cache measurement test (cannot disable the driver cache)

Regression run

Paired 60 s retail smoke (scripts/smoke.ps1, RTX 4060): both base (889ef3e8, ancestor of b49be183 and 24e584ca) and HEAD sustained 60 60 60 presents per 2 s with 0 device removals and 0 crashes (1582 vs 1550 total frames, 102.1%; 13982 MB vs 13981 MB peak commit).

Base (origin/main ancestor):

xcl-smoke v1
commit: 889ef3e8aa7f267323ab4879e735e65da6bcef10
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1550 (PresentX 1550)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13981 MB

HEAD (fix-pso-async-batch-used-writes):

xcl-smoke v1
commit: 24e584cab16069e3d83d186e757c42bb607fea53
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1582 (PresentX 1582)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13982 MB

Not tested

  • Retail title mid-world-load PSO burst micro-benchmarks (the 60 s smoke run covers startup/intro/menus) and abrupt external TerminateProcess from outside the process (which bypasses user-mode hooks and atexit).
  • The 29 host/environment-skipped workspace tests listed above (native wave64 GPUs, D3D12 debug layer SDK, heap windows, driver-cache-disabled PSO measurement) and non-Windows / Wine hosts.
  • The 47 #[ignore] tests.

AI use

Google Antigravity (Gemini 4 Neon) authored the batched used::Journal writer, process-exit flush/shutdown wiring (atexit, host::host_main, eh::hk_nt_terminate_process), monotonic-sequence and spawn-failure fallback handling, subprocess and unit regression tests, and verification runs; verified via failing-first subprocess reproduction, WARP and RTX 4060 unit tests, full RTX 4060 release workspace tests, and paired 60 s retail smoke runs.

**@⁠Decodere** on GitHub · 2026-11-26 03:37 UTC · [original](https://github.com/xcl-dev/xcl/pull/2635) `Decodere:fix-pso-async-batch-used-writes` → `main` · +480 −26 · 3 files · 1 commits · open **What is in it** Part of #2508 Part of #1833 `pso_async::used::note()` (`crates/xcl/src/hle/d3d12x/pso_async.rs`) previously ran synchronous `create_dir_all`, `OpenOptions::open`, and unbuffered `writeln!(f, "{key:016x}")` syscalls while holding the global `used::now` mutex on the title's command-recording / bind thread (`Pending::note_use`, called from `resolve` and `resolve_wait_for`). During world-load pipeline bursts, every newly used pipeline serialized bind threads behind disk I/O. Changes (3 files: `crates/xcl/src/hle/d3d12x/pso_async.rs`, `crates/xcl/src/host.rs`, `crates/xcl/src/eh.rs`): - Extracted `used::Journal` backed by a single lightweight writer thread (`xcl-pso-used`), `Mutex<JournalState>`, `wake_cv`, and `flushed_cv`. - `Journal::note(key)` performs zero filesystem syscalls on the caller thread or under the state mutex: it inserts into `seen`, appends to `pending` (continuing to queue keys while `fallback_path` is set even if writer spawn failed), and notifies `wake_cv` only on empty-to-nonempty (`1`) and burst-threshold (`64`) transitions. - `writer_loop` coalesces bursts up to `25 ms` (draining immediately at `64` unique keys), drains `pending` via `std::mem::take`, drops the mutex before I/O, lazily creates parent directories and opens `used-pipelines.txt`, performs a single batched `write_all` + `flush`, and updates `completed_seq = completed_seq.max(batch_seq)` so a slow batch never regresses `completed_seq` below a timed-out `flush_bounded()` drain. I/O failures clear the cached handle and never panic or break in-memory deduplication. - Kept `if cfg!(test)` isolated from the user's cache file (`Journal::in_memory`, with a test-only `XCL_TEST_USED_STATIC_PATH` env hook for subprocess exit verification) and left `counts()` un-flushed (`present.rs` calls it on `PresentX`). - Process-exit persistence for `static U: OnceLock<Used>` (addressing `@luckyteagirl`'s exit-flush review and `@KDenKC`'s follow-up review): - Wrapped `Journal::writer` in `Mutex<Option<JoinHandle<()>>>` so `Journal::shutdown(&self)` flushes pending keys and joins `xcl-pso-used` through a shared `&'static` reference (`Drop` delegates to `shutdown()`), draining any remaining `pending` keys to `fallback_path` if no writer thread was spawned; added `Journal::flush_bounded(&self, timeout)` with a direct-append fallback to `fallback_path` if `xcl-pso-used` times out (e.g., blocked on the Windows loader lock during a fast `ExitProcess`) or failed to spawn. - Registered CRT `atexit(on_process_exit)` -> `used::shutdown()` when `used::init_from_path` initializes the file-backed static journal (covering ordinary `main()` return). - Wired `pso_async::shutdown_used()` into `crates/xcl/src/host.rs` on both normal shutdown boundaries (`XCL_RUN_SECONDS` before `real::end_title(0)` and normal return from `loader::run_main`). - Wired `pso_async::flush_used_bounded(100 ms)` into `crates/xcl/src/eh.rs::hk_nt_terminate_process` alongside `crate::log::flush()` so titles exiting directly via Win32 `ExitProcess` flush pending keys before `NtTerminateProcess` ends worker threads. - Added pure-CPU unit tests in `pso_async::used_tests`: - `used_note_does_not_block_on_slow_writer` - `used_burst_coalesces_writes_and_deduplicates_keys` - `used_flush_drop_lazy_file_and_io_error_are_graceful` - `used_static_once_lock_flushes_on_process_exit` (subprocess test covering `normal` return via `atexit`, Win32 `ExitProcess` via `eh::install_crash_handler` + `std::process::exit(0)`, explicit `shutdown_used()`, and `flush_used_bounded()` without dropping a local `Journal`, using a 60 s coalesce window) - `used_flush_bounded_timeout_and_spawn_failure_fallback_are_sound` (verifying `completed_seq` stays monotonic across a timed-out `flush_bounded()` so a subsequent `flush()` never hangs, and verifying `note()` + `flush_bounded()` / `shutdown()` persist keys directly to `fallback_path` when writer thread spawn fails). **Tested** - Hardware & toolchain: Windows 11 Home (build 26200), Intel Core i5-11400F (6C/12T), 32 GB RAM, NVIDIA GeForce RTX 4060 8 GB (driver 621.14), `rustc 1.100.0`, DXC `1.9.2609.5 (01b62ad4)`, release builds. - Failing-first reproduction on unmodified PR head `bd9b4008`: - `used_static_once_lock_flushes_on_process_exit` failed immediately (`0 passed; 1 failed`: `static OnceLock journal lost keys on process exit: NotFound`) because `static U: OnceLock<Used>` did not run `Drop` on process exit before the coalesce window elapsed. - WARP (`XCL_ADAPTER=warp`, `XCL_WARP=1`): `cargo test --release -p xcl --lib -- hle::d3d12x::pso_async:: --test-threads=4 --nocapture` -> `19 passed; 0 failed; 0 ignored` (`0` skipped, `0.82 s`). - RTX 4060 targeted: `cargo test --release -p xcl --lib -- hle::d3d12x::pso_async:: --test-threads=4 --nocapture` -> `19 passed; 0 failed; 0 ignored` (`0` skipped, `0.81 s`). - Full release workspace on RTX 4060: `cargo test --release --workspace --no-fail-fast -- --test-threads=4 --nocapture`: `37` test binaries, `1440` passed, `0` failed, `47` ignored (`0` new warnings), `29` pre-existing host-gated `SKIPPED` lines (none in `pso_async`): - `21` wave64-only GPU tests (`no wave64` on RTX 4060 32-lane waves) - `3` per-lane wave32 shader tests (`refused`) - `3` D3D12 debug layer tests (`no d3d12SDKLayers.dll` / debug layer unavailable) - `1` heap-window OOM fallback test (`no heap windows`) - `1` PSO driver-cache measurement test (`cannot disable the driver cache`) **Regression run** Paired 60 s retail smoke (`scripts/smoke.ps1`, RTX 4060): both base (`889ef3e8`, ancestor of `b49be183` and `24e584ca`) and HEAD sustained `60 60 60` presents per 2 s with `0` device removals and `0` crashes (`1582` vs `1550` total frames, `102.1%`; `13982 MB` vs `13981 MB` peak commit). Base (`origin/main` ancestor): ``` xcl-smoke v1 commit: 889ef3e8aa7f267323ab4879e735e65da6bcef10 gpu: NVIDIA GeForce RTX 4060 title: 29640639 seconds: 60 exit: 0x0 frames shown: 1550 (PresentX 1550) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 13981 MB ``` HEAD (`fix-pso-async-batch-used-writes`): ``` xcl-smoke v1 commit: 24e584cab16069e3d83d186e757c42bb607fea53 gpu: NVIDIA GeForce RTX 4060 title: 29640639 seconds: 60 exit: 0x0 frames shown: 1582 (PresentX 1582) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 13982 MB ``` **Not tested** - Retail title mid-world-load PSO burst micro-benchmarks (the 60 s smoke run covers startup/intro/menus) and abrupt external `TerminateProcess` from outside the process (which bypasses user-mode hooks and `atexit`). - The 29 host/environment-skipped workspace tests listed above (native wave64 GPUs, D3D12 debug layer SDK, heap windows, driver-cache-disabled PSO measurement) and non-Windows / Wine hosts. - The 47 `#[ignore]` tests. **AI use** Google Antigravity (Gemini 4 Neon) authored the batched `used::Journal` writer, process-exit flush/shutdown wiring (`atexit`, `host::host_main`, `eh::hk_nt_terminate_process`), monotonic-sequence and spawn-failure fallback handling, subprocess and unit regression tests, and verification runs; verified via failing-first subprocess reproduction, WARP and RTX 4060 unit tests, full RTX 4060 release workspace tests, and paired 60 s retail smoke runs.
Move used-pipelines.txt directory creation, lazy file open, formatting,
and disk writes out of the used::note bind mutex onto a lightweight
background writer thread (`xcl-pso-used`) with 25 ms burst coalescing
(immediate drain at 64 keys), deterministic `Journal::flush()`, and
flush-on-drop persistence. Keeps `cfg!(test)` isolated from the user's
cache file and tolerates I/O failures without panicking or breaking
in-memory deduplication.

Part of #2508
Part of #1833

Assisted-by: Google Antigravity (Gemini 4 Neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:35:22 +00:00
github-bot force-pushed github-bot/gh-2635 from bd9b400884 to ad798f3b5c 2026-11-26 06:17:53 +00:00 Compare
Author
Owner

@⁠sage-sage on GitHub · 2026-11-26 05:18 UTC · original

Test report: passes on NVIDIA. Exact head bd9b4008 (its base is current main b49be18, so head = merged).

Tested

  • RTX 4080 SUPER (driver 621.40), Ryzen 5 7600X, Windows 11 26H2 build 26300.10075, rustc 1.100.0 MSVC, DXC 1.9.2602.17 (Windows SDK 10.0.26100), debug build
  • cargo test --workspace -- --test-threads=4: 1438 passed, 0 failed, 47 ignored; the three new used_tests pass
  • SKIPPED (29 lines, the same as on main on this machine): 21 wave64 tests (NVIDIA is wave32 only), 3 per-lane wave32 f16/f32 forms (refused), 3 D3D12 debug layer (d3d12SDKLayers.dll not installed), 1 no heap windows, 1 pso_measurement_compiles_an_exact_synthetic_record (Developer Mode off)

Not tested

  • No game, so not the timing on a real first-bind burst.

Claude Code (Claude Opus 5.5) ran the tests and wrote this report.

**@⁠sage-sage** on GitHub · 2026-11-26 05:18 UTC · [original](https://github.com/xcl-dev/xcl/pull/2635#issuecomment-7183362532) **Test report: passes on NVIDIA.** Exact head `bd9b4008` (its base is current `main` `b49be18`, so head = merged). **Tested** - RTX 4080 SUPER (driver 621.40), Ryzen 5 7600X, Windows 11 26H2 build 26300.10075, rustc 1.100.0 MSVC, DXC 1.9.2602.17 (Windows SDK 10.0.26100), debug build - `cargo test --workspace -- --test-threads=4`: 1438 passed, 0 failed, 47 ignored; the three new `used_tests` pass - SKIPPED (29 lines, the same as on `main` on this machine): 21 wave64 tests (NVIDIA is wave32 only), 3 per-lane wave32 f16/f32 forms (refused), 3 D3D12 debug layer (`d3d12SDKLayers.dll` not installed), 1 `no heap windows`, 1 `pso_measurement_compiles_an_exact_synthetic_record` (Developer Mode off) **Not tested** - No game, so not the timing on a real first-bind burst. Claude Code (Claude Opus 5.5) ran the tests and wrote this report.
Author
Owner

@⁠Decodere on GitHub · 2026-11-26 05:18 UTC · original

@⁠luckyteagirl Great catch — pushed ad798f3b addressing static OnceLock<Used> exit persistence across all Windows exit paths:

  • Wrapped Journal::writer in Mutex<Option<JoinHandle<()>>> so Journal::shutdown(&self) flushes pending keys and joins xcl-pso-used through the static reference (Drop delegates to shutdown()), and registered CRT atexit(on_process_exit) when used::init_from_path initializes the file-backed journal.
  • Wired pso_async::shutdown_used() into host::host_main on normal return and XCL_RUN_SECONDS (right before real::end_title(0) suspends threads / terminates), and wired pso_async::flush_used_bounded(100 ms) into eh::hk_nt_terminate_process alongside log::flush() with a direct-append fallback to used-pipelines.txt if xcl-pso-used is blocked on the Windows loader lock during a fast ExitProcess.
  • Added used_static_once_lock_flushes_on_process_exit (subprocess test with a 60 s coalesce window, no local Journal drop) covering normal process return (atexit), Win32 ExitProcess (eh::install_crash_handler + std::process::exit(0)), explicit shutdown_used(), and flush_used_bounded() (reproduced failing-first on bd9b4008, now 18/18 passing on WARP and RTX 4060). Thanks for the review!
**@⁠Decodere** on GitHub · 2026-11-26 05:18 UTC · [original](https://github.com/xcl-dev/xcl/pull/2635#issuecomment-7183371533) @⁠luckyteagirl Great catch — pushed `ad798f3b` addressing static `OnceLock<Used>` exit persistence across all Windows exit paths: - Wrapped `Journal::writer` in `Mutex<Option<JoinHandle<()>>>` so `Journal::shutdown(&self)` flushes pending keys and joins `xcl-pso-used` through the static reference (`Drop` delegates to `shutdown()`), and registered CRT `atexit(on_process_exit)` when `used::init_from_path` initializes the file-backed journal. - Wired `pso_async::shutdown_used()` into `host::host_main` on normal return and `XCL_RUN_SECONDS` (right before `real::end_title(0)` suspends threads / terminates), and wired `pso_async::flush_used_bounded(100 ms)` into `eh::hk_nt_terminate_process` alongside `log::flush()` with a direct-append fallback to `used-pipelines.txt` if `xcl-pso-used` is blocked on the Windows loader lock during a fast `ExitProcess`. - Added `used_static_once_lock_flushes_on_process_exit` (subprocess test with a 60 s coalesce window, no local `Journal` drop) covering normal process return (`atexit`), Win32 `ExitProcess` (`eh::install_crash_handler` + `std::process::exit(0)`), explicit `shutdown_used()`, and `flush_used_bounded()` (reproduced failing-first on `bd9b4008`, now 18/18 passing on WARP and RTX 4060). Thanks for the review!
Author
Owner

@⁠KDenKC on GitHub · 2026-11-26 05:53 UTC · original

Source review of head ad798f3b, no run. Two small things in the journal, both low impact today:

  1. completed_seq can go backwards (pso_async.rs, writer_loop: completed_seq = batch_seq). The writer takes batch 1 (batch_seq = 1) and is slow in write_batch. Meanwhile a new key arrives (enqueued_seq = 2), and flush_bounded times out, appends it itself and sets completed_seq = 2. The writer then finishes and stores 1. With pending empty and completed_seq < enqueued_seq, a later flush() waits forever. Today flush() is only called from tests, and the exit path is flush_bounded (with a timeout) followed by shutdown, which still joins. So this is a latent hang, not a live one. g.completed_seq = g.completed_seq.max(batch_seq); closes it.
  2. The spawn-failure fallback never has keys to write. with_sink sets writer_stopped = true when the thread fails to spawn, and note() returns early on writer_stopped. Nothing reaches pending, so the "or failed to spawn" branch in flush_bounded writes nothing and the run's keys are silently not recorded. If keys should survive that case, note() could still push while fallback_path is set.

Not tested: no build or run of this head on our side.

AI use: Gemini (Antigravity) did a first-pass review; Claude Code (Claude Opus 5.5) checked both points against the source at ad798f3b and wrote this.

**@⁠KDenKC** on GitHub · 2026-11-26 05:53 UTC · [original](https://github.com/xcl-dev/xcl/pull/2635#issuecomment-7183902779) Source review of head `ad798f3b`, no run. Two small things in the journal, both low impact today: 1. **`completed_seq` can go backwards** (`pso_async.rs`, `writer_loop`: `completed_seq = batch_seq`). The writer takes batch 1 (`batch_seq = 1`) and is slow in `write_batch`. Meanwhile a new key arrives (`enqueued_seq = 2`), and `flush_bounded` times out, appends it itself and sets `completed_seq = 2`. The writer then finishes and stores `1`. With `pending` empty and `completed_seq < enqueued_seq`, a later `flush()` waits forever. Today `flush()` is only called from tests, and the exit path is `flush_bounded` (with a timeout) followed by `shutdown`, which still joins. So this is a latent hang, not a live one. `g.completed_seq = g.completed_seq.max(batch_seq);` closes it. 2. **The spawn-failure fallback never has keys to write.** `with_sink` sets `writer_stopped = true` when the thread fails to spawn, and `note()` returns early on `writer_stopped`. Nothing reaches `pending`, so the "or failed to spawn" branch in `flush_bounded` writes nothing and the run's keys are silently not recorded. If keys should survive that case, `note()` could still push while `fallback_path` is set. Not tested: no build or run of this head on our side. AI use: Gemini (Antigravity) did a first-pass review; Claude Code (Claude Opus 5.5) checked both points against the source at `ad798f3b` and wrote this.
Author
Owner

@⁠luckyteagirl on GitHub · 2026-11-26 04:14 UTC · original · reviewed

Used is held in a static OnceLock, so its Journal::Drop (which joins and drains the worker) does not run on ordinary process exit. After note() returns, the writer can wait up to COALESCE_WINDOW (25 ms) before opening/writing used-pipelines.txt; if the title exits during that window, those last-used keys are lost. The old synchronous path appended them before returning. Could the normal shutdown path explicitly flush/join this journal, and could a subprocess test record a key then exit without dropping a local Journal? The current drop test only covers a stack-owned journal.

**@⁠luckyteagirl** on GitHub · 2026-11-26 04:14 UTC · [original](https://github.com/xcl-dev/xcl/pull/2635#pullrequestreview-6068465427) · **reviewed** `Used` is held in a `static OnceLock`, so its `Journal::Drop` (which joins and drains the worker) does not run on ordinary process exit. After `note()` returns, the writer can wait up to `COALESCE_WINDOW` (25 ms) before opening/writing `used-pipelines.txt`; if the title exits during that window, those last-used keys are lost. The old synchronous path appended them before returning. Could the normal shutdown path explicitly flush/join this journal, and could a subprocess test record a key then exit without dropping a local `Journal`? The current drop test only covers a stack-owned journal.
github-bot force-pushed github-bot/gh-2635 from ad798f3b5c to 24e584cab1 2026-11-26 06:58:58 +00:00 Compare
Author
Owner

@⁠Decodere on GitHub · 2026-11-26 06:56 UTC · original

@⁠KDenKC Good catches on both points — pushed 24e584ca addressing both:

  1. Monotonic completed_seq: writer_loop now stores g.completed_seq = g.completed_seq.max(batch_seq), so a slow batch completing after a timed-out flush_bounded() fallback drain can never regress completed_seq below enqueued_seq.
  2. Spawn-failure fallback: Journal::note() now continues queuing keys while fallback_path.is_some() even if writer_stopped is set, and Journal::shutdown() also drains any remaining pending keys to fallback_path so both flush_bounded() and shutdown() persist keys if xcl-pso-used fails to spawn.
  3. Added used_flush_bounded_timeout_and_spawn_failure_fallback_are_sound covering both cases; re-verified release WARP & RTX 4060 pso_async:: (19/0/0), full release workspace (1440/0/47), and paired 60 s RTX 4060 smoke (1582 frames, 60 60 60, 0 removals/crashes).
**@⁠Decodere** on GitHub · 2026-11-26 06:56 UTC · [original](https://github.com/xcl-dev/xcl/pull/2635#issuecomment-7184941455) @⁠KDenKC Good catches on both points — pushed `24e584ca` addressing both: 1. **Monotonic `completed_seq`:** `writer_loop` now stores `g.completed_seq = g.completed_seq.max(batch_seq)`, so a slow batch completing after a timed-out `flush_bounded()` fallback drain can never regress `completed_seq` below `enqueued_seq`. 2. **Spawn-failure fallback:** `Journal::note()` now continues queuing keys while `fallback_path.is_some()` even if `writer_stopped` is set, and `Journal::shutdown()` also drains any remaining `pending` keys to `fallback_path` so both `flush_bounded()` and `shutdown()` persist keys if `xcl-pso-used` fails to spawn. 3. Added `used_flush_bounded_timeout_and_spawn_failure_fallback_are_sound` covering both cases; re-verified release WARP & RTX 4060 `pso_async::` (`19/0/0`), full release workspace (`1440/0/47`), and paired 60 s RTX 4060 smoke (`1582` frames, `60 60 60`, `0` removals/crashes).
Author
Owner

@⁠KDenKC on GitHub · 2026-11-26 07:14 UTC · original

Checked at 24e584ca: writer_loop stores completed_seq.max(batch_seq), and note() keeps queuing while a fallback_path exists. Both points are addressed, thanks @⁠Decodere.

AI use: Claude Code (Claude Opus 5.5) checked the source and wrote this.

**@⁠KDenKC** on GitHub · 2026-11-26 07:14 UTC · [original](https://github.com/xcl-dev/xcl/pull/2635#issuecomment-7185244767) Checked at `24e584ca`: `writer_loop` stores `completed_seq.max(batch_seq)`, and `note()` keeps queuing while a `fallback_path` exists. Both points are addressed, thanks @⁠Decodere. AI use: Claude Code (Claude Opus 5.5) checked the source and wrote this.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2635/head:github-bot/gh-2635'
git switch 'github-bot/gh-2635'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2635'
git switch 'github-bot/gh-2635'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2635'
git switch 'github-bot/gh-2635'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2635'
git switch 'main'
git merge --squash 'github-bot/gh-2635'
git switch 'main'
git merge --ff-only 'github-bot/gh-2635'
git switch 'main'
git merge 'github-bot/gh-2635'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.