startup: open the trap log once per module #1750

Merged
rasptum merged 6 commits from upstream-pr/1757 into main 2026-11-24 22:08:31 +00:00
rasptum commented 2026-11-24 18:10:03 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by rasptum on 2026-11-24T18:10:03Z.


Problem

The startup stand-ins append their diagnostic lines to the file named by X2W_TRAP_LOG. Each of the four copies of that code opened the file, wrote one line and closed it again, for every line. Under the startup launcher every file open is a traced call that stops the process, so the log alone caused a steady stream of stops.

Change

x2w_trap::append_log(line, size, flush) in src/startup_stubs/trap.h replaces the four copies:

Site File Flush
x2w_trap::record() (trap, continue and fail lines) src/startup_stubs/trap.h yes
x2w_local::logf src/startup_stubs/local_log.h no
log() src/startup_stubs/d3d12_xs_device.cpp no
log() src/startup_stubs/xcrdapi.cpp no

No other copy of the open/append/close block exists in src/.

Contract:

  • The handle is opened lazily on the first line, with FILE_APPEND_DATA and shared read, write and delete. Other modules and live readers keep working, and a reader or test can still delete the log between lines.
  • The handle is published race-free with InterlockedCompareExchangePointer. A thread that loses the race closes its own handle.
  • Only a successful open is kept. While no handle is kept, a failed open makes ordinary lines wait 250 ms (log_retry_ms) before the next open attempt. Lines in that wait are dropped, as the per-line writer dropped a line it could not open for. Trap lines always attempt the open, so a trap still reaches the log once the path is usable. An unusable path costs at most one open attempt per 250 ms per module (measured: 4 attempts for 78,000 to 231,000 lines in one second).
  • The trap path still calls FlushFileBuffers before the process can be terminated. Ordinary lines do not flush.
  • Each line is still one WriteFile, so lines from concurrent threads do not interleave within a line.
  • Callers that preserved GetLastError (logf) still do.
  • The output is unchanged byte for byte. When X2W_TRAP_LOG is unset or too long, nothing is opened or written, as before.
  • The variable is still read on every line. That is an environment read, not a file call. A line for a path other than the kept one (the variable changed in-process) is appended the old way: open, write, close.

In a 600 s startup run of a console executable on Windows 10 19045, the traced opens of the log file fell from 5,076 to 8 (one per stand-in module).

Tests

Windows 10 19045, MSVC, dev and release presets:

cmake --build --preset dev --target startup_local_log_check startup_local_log_cache_failure_check startup_trap_header_check startup_stub_acphal startup_stub_chad startup_stub_xapu startup_stub_xcrdapi startup_stub_xg_xs startup_stub_gameinput xmem_shim d3d12_xs_shim startup_stub_consumer
ctest --preset dev --no-tests=error -R '^(startup_local_log(_guard_drop_control|_reopen_control|_cache_failure_control)?|startup_stubs|startup_trap_header(_prefix_control|_precedence_control)?)$' -V

Result: 8/8 passed in dev and 8/8 passed in release, 0 skipped.

  • startup_local_log runs 8 threads × 2,000 logf lines in a child process, so its module starts with no log handle. Observed: opens=1 lines=16001 bad=0 missing=0 duplicate=0. Every line is present exactly once and intact.
  • The child then deletes the log while its module still holds the handle; the delete must succeed.
  • The existing logf path checks (CRLF, 1533-byte clamp, MAX_PATH limits, GetLastError on open failure, stderr copy) are unchanged. Before them the test keeps the module's handle on NUL, so those checks exercise the changed-path route and their files stay removable.
  • startup_local_log_guard_drop_control (existing, WILL_FAIL) still fails only on its guard-page expectation.
  • startup_local_log_reopen_control (new, WILL_FAIL) is the negative control. After the first line, the child respells the path as the same file (<dir>\.\trap.log), so every following line reopens the file. Observed: opens=16001, all 16,001 lines intact, and the only failure is trap log is opened once per module. The child exits 3 only when the open count is its sole failure. The parent returns failure only for exit code 3, so a lost or torn line, a crash, or a child that never starts makes the control fail rather than pass.
  • Open-failure recovery, each case in a fresh child process:
    • X2W_TRAP_LOG points into a directory that does not exist, so the first append fails and its line is dropped. The child creates the directory, waits past the interval, and a later append must land as the file's only line; 100 more lines follow in order without another open.
    • The same with the file held by CreateFileW without sharing (a sharing violation), then released.
    • Right after a failed open, a trap (flush) line must open the log without waiting.
    • In both recovery cases, an unusable path is logged to for one second and must cost at most one open attempt per 250 ms.
  • startup_local_log_cache_failure_control (new, WILL_FAIL) builds the same check against a generated copy of trap.h whose failed open is kept forever. It passes only when the two recovery checks are its sole failures. Observed: both recovery children exit 3, failing a later line reaches the log once the path is usable; every other check passes.
  • startup_stubs (the stand-in DLL check that also reads X2W_TRAP_LOG) and startup_trap_header with its two controls (from #1555) pass.
  • tests/docs_links_check.py and tests/bidi_controls_check.py pass.

Compatibility with #1555

#1555 (now in main) adds startup_trap_header. Its step 4 calls DeleteFileW on the log after in-process record() calls, then expects a child process to write a fresh log. A kept handle without delete sharing made that delete fail. The child then appended to the old file, and the folder could not be removed. The kept handle therefore also shares delete. startup_trap_header and its two controls pass on this branch in both presets.

Not covered

  • File systems without POSIX delete semantics. There, a deleted log stays delete-pending until the module exits, so a new file cannot be created at that path in the meantime.
  • A log deleted mid-run: lines written afterwards by a module that already holds the handle are lost, where the old code recreated the file.
  • Ordinary lines written during the 250 ms wait after a failed open are dropped, not buffered.
  • The d3d12_xs and XCRDAPI call sites are covered by startup_stubs and the shared helper test, not by a dedicated multi-threaded fixture each.

AI-assisted (Claude Code).
🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6588344840 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1757). Originally posted by [rasptum](https://github.com/rasptum) on 2026-11-24T18:10:03Z. --- ## Problem The startup stand-ins append their diagnostic lines to the file named by `X2W_TRAP_LOG`. Each of the four copies of that code opened the file, wrote one line and closed it again, for every line. Under the startup launcher every file open is a traced call that stops the process, so the log alone caused a steady stream of stops. ## Change `x2w_trap::append_log(line, size, flush)` in `src/startup_stubs/trap.h` replaces the four copies: | Site | File | Flush | |---|---|---| | `x2w_trap::record()` (trap, continue and fail lines) | `src/startup_stubs/trap.h` | yes | | `x2w_local::logf` | `src/startup_stubs/local_log.h` | no | | `log()` | `src/startup_stubs/d3d12_xs_device.cpp` | no | | `log()` | `src/startup_stubs/xcrdapi.cpp` | no | No other copy of the open/append/close block exists in `src/`. Contract: - The handle is opened lazily on the first line, with `FILE_APPEND_DATA` and shared read, write and delete. Other modules and live readers keep working, and a reader or test can still delete the log between lines. - The handle is published race-free with `InterlockedCompareExchangePointer`. A thread that loses the race closes its own handle. - Only a successful open is kept. While no handle is kept, a failed open makes ordinary lines wait 250 ms (`log_retry_ms`) before the next open attempt. Lines in that wait are dropped, as the per-line writer dropped a line it could not open for. Trap lines always attempt the open, so a trap still reaches the log once the path is usable. An unusable path costs at most one open attempt per 250 ms per module (measured: 4 attempts for 78,000 to 231,000 lines in one second). - The trap path still calls `FlushFileBuffers` before the process can be terminated. Ordinary lines do not flush. - Each line is still one `WriteFile`, so lines from concurrent threads do not interleave within a line. - Callers that preserved `GetLastError` (`logf`) still do. - The output is unchanged byte for byte. When `X2W_TRAP_LOG` is unset or too long, nothing is opened or written, as before. - The variable is still read on every line. That is an environment read, not a file call. A line for a path other than the kept one (the variable changed in-process) is appended the old way: open, write, close. In a 600 s startup run of a console executable on Windows 10 19045, the traced opens of the log file fell from 5,076 to 8 (one per stand-in module). ## Tests Windows 10 19045, MSVC, `dev` and `release` presets: ```powershell cmake --build --preset dev --target startup_local_log_check startup_local_log_cache_failure_check startup_trap_header_check startup_stub_acphal startup_stub_chad startup_stub_xapu startup_stub_xcrdapi startup_stub_xg_xs startup_stub_gameinput xmem_shim d3d12_xs_shim startup_stub_consumer ctest --preset dev --no-tests=error -R '^(startup_local_log(_guard_drop_control|_reopen_control|_cache_failure_control)?|startup_stubs|startup_trap_header(_prefix_control|_precedence_control)?)$' -V ``` Result: 8/8 passed in `dev` and 8/8 passed in `release`, 0 skipped. - `startup_local_log` runs 8 threads × 2,000 `logf` lines in a child process, so its module starts with no log handle. Observed: `opens=1 lines=16001 bad=0 missing=0 duplicate=0`. Every line is present exactly once and intact. - The child then deletes the log while its module still holds the handle; the delete must succeed. - The existing `logf` path checks (CRLF, 1533-byte clamp, `MAX_PATH` limits, `GetLastError` on open failure, stderr copy) are unchanged. Before them the test keeps the module's handle on `NUL`, so those checks exercise the changed-path route and their files stay removable. - `startup_local_log_guard_drop_control` (existing, `WILL_FAIL`) still fails only on its guard-page expectation. - `startup_local_log_reopen_control` (new, `WILL_FAIL`) is the negative control. After the first line, the child respells the path as the same file (`<dir>\.\trap.log`), so every following line reopens the file. Observed: `opens=16001`, all 16,001 lines intact, and the only failure is `trap log is opened once per module`. The child exits 3 only when the open count is its sole failure. The parent returns failure only for exit code 3, so a lost or torn line, a crash, or a child that never starts makes the control fail rather than pass. - Open-failure recovery, each case in a fresh child process: - `X2W_TRAP_LOG` points into a directory that does not exist, so the first append fails and its line is dropped. The child creates the directory, waits past the interval, and a later append must land as the file's only line; 100 more lines follow in order without another open. - The same with the file held by `CreateFileW` without sharing (a sharing violation), then released. - Right after a failed open, a trap (flush) line must open the log without waiting. - In both recovery cases, an unusable path is logged to for one second and must cost at most one open attempt per 250 ms. - `startup_local_log_cache_failure_control` (new, `WILL_FAIL`) builds the same check against a generated copy of `trap.h` whose failed open is kept forever. It passes only when the two recovery checks are its sole failures. Observed: both recovery children exit 3, failing `a later line reaches the log once the path is usable`; every other check passes. - `startup_stubs` (the stand-in DLL check that also reads `X2W_TRAP_LOG`) and `startup_trap_header` with its two controls (from #1555) pass. - `tests/docs_links_check.py` and `tests/bidi_controls_check.py` pass. ## Compatibility with #1555 #1555 (now in main) adds `startup_trap_header`. Its step 4 calls `DeleteFileW` on the log after in-process `record()` calls, then expects a child process to write a fresh log. A kept handle without delete sharing made that delete fail. The child then appended to the old file, and the folder could not be removed. The kept handle therefore also shares delete. `startup_trap_header` and its two controls pass on this branch in both presets. ## Not covered - File systems without POSIX delete semantics. There, a deleted log stays delete-pending until the module exits, so a new file cannot be created at that path in the meantime. - A log deleted mid-run: lines written afterwards by a module that already holds the handle are lost, where the old code recreated the file. - Ordinary lines written during the 250 ms wait after a failed open are dropped, not buffered. - The `d3d12_xs` and `XCRDAPI` call sites are covered by `startup_stubs` and the shared helper test, not by a dedicated multi-threaded fixture each. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
tedin7 commented 2026-11-24 19:01:21 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T18:49:56Z.

Review: COMMENTED


Reviewed at 7955a4f1f2d8b8d906a8c48af07152c778f64343.

No P1 or P2 defects found in local verification. x2w_trap::append_log in src/startup_stubs/trap.h safely publishes the first module-wide Log entry (handle + path) via InterlockedCompareExchangePointer after initializing it, opens with FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE so concurrent readers and DeleteFileW cleanup continue to work, caches failed opens as INVALID_HANDLE_VALUE so they are not retried per line, and falls back to open/write/close when %X2W_TRAP_LOG% changes in-process. src/startup_stubs/local_log.h, src/startup_stubs/d3d12_xs_device.cpp, and src/startup_stubs/xcrdapi.cpp all delegate to x2w_trap::append_log, and tests/startup_local_log_check.cpp verifies 8-thread x 2,000-line concurrency with opens == 1 plus the startup_local_log_reopen_control negative control.

Verification executed:

  • git diff --check origin/main...HEAD -> pass
  • /root/.local/share/x2w-rev-venv/bin/python -B tests/docs_links_check.py -> pass (17 Markdown files, 364 links)
  • /root/.local/share/x2w-rev-venv/bin/python -B tests/bidi_controls_check.py -> pass (1287 tracked files)
  • python3 /root/.local/state/xbox2windows/pipeline/x2w_pipe.py win2025 1757 --targets startup_local_log_check,d3d12_xs_shim,startup_stub_xcrdapi --regex '^startup_local_log(_guard_drop_control|_reopen_control)?$' --wait 600 -> pass on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP): Debug (--preset dev) 3/3 passed (startup_local_log, startup_local_log_guard_drop_control, startup_local_log_reopen_control), Release /O2 (--preset release) 3/3 passed
  • Local mutation check: bypassed the kept-handle reuse check in src/startup_stubs/trap.h (if (false && current && !std::wcscmp(current->path, path))) and ran python3 /root/.local/state/xbox2windows/pipeline/x2w_pipe.py win2025 1757 --wt /tmp/rev-sm2-rexa/1757 --targets startup_local_log_check --regex '^startup_local_log$' --wait 600; startup_local_log failed as expected (opens=16001, FAIL trap log is opened once per module, FAIL append_log reuses the kept handle), then restored with git checkout -- ..

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6045339763 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1757#pullrequestreview-6045339763). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T18:49:56Z. **Review:** COMMENTED --- Reviewed at `7955a4f1f2d8b8d906a8c48af07152c778f64343`. No P1 or P2 defects found in local verification. `x2w_trap::append_log` in `src/startup_stubs/trap.h` safely publishes the first module-wide `Log` entry (`handle` + `path`) via `InterlockedCompareExchangePointer` after initializing it, opens with `FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE` so concurrent readers and `DeleteFileW` cleanup continue to work, caches failed opens as `INVALID_HANDLE_VALUE` so they are not retried per line, and falls back to open/write/close when `%X2W_TRAP_LOG%` changes in-process. `src/startup_stubs/local_log.h`, `src/startup_stubs/d3d12_xs_device.cpp`, and `src/startup_stubs/xcrdapi.cpp` all delegate to `x2w_trap::append_log`, and `tests/startup_local_log_check.cpp` verifies 8-thread x 2,000-line concurrency with `opens == 1` plus the `startup_local_log_reopen_control` negative control. Verification executed: - `git diff --check origin/main...HEAD` -> pass - `/root/.local/share/x2w-rev-venv/bin/python -B tests/docs_links_check.py` -> pass (17 Markdown files, 364 links) - `/root/.local/share/x2w-rev-venv/bin/python -B tests/bidi_controls_check.py` -> pass (1287 tracked files) - `python3 /root/.local/state/xbox2windows/pipeline/x2w_pipe.py win2025 1757 --targets startup_local_log_check,d3d12_xs_shim,startup_stub_xcrdapi --regex '^startup_local_log(_guard_drop_control|_reopen_control)?$' --wait 600` -> pass on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP): Debug (`--preset dev`) 3/3 passed (`startup_local_log`, `startup_local_log_guard_drop_control`, `startup_local_log_reopen_control`), Release `/O2` (`--preset release`) 3/3 passed - Local mutation check: bypassed the kept-handle reuse check in `src/startup_stubs/trap.h` (`if (false && current && !std::wcscmp(current->path, path))`) and ran `python3 /root/.local/state/xbox2windows/pipeline/x2w_pipe.py win2025 1757 --wt /tmp/rev-sm2-rexa/1757 --targets startup_local_log_check --regex '^startup_local_log$' --wait 600`; `startup_local_log` failed as expected (`opens=16001`, `FAIL trap log is opened once per module`, `FAIL append_log reuses the kept handle`), then restored with `git checkout -- .`. AI-assisted; commands listed were executed locally.
rasptum commented 2026-11-24 19:01:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by rasptum on 2026-11-24T18:52:08Z.


Thanks for the review and the mutation check.

The review raises no defects and has no inline comments, so the PR needs no code change; the head stays at 7955a4f1. Your mutation result matches what the fixture is meant to catch. With the kept-handle reuse bypassed, startup_local_log reports opens=16001 and fails both trap log is opened once per module and append_log reuses the kept handle, independently of the startup_local_log_reopen_control negative control.

Last local run on this head (Windows 10 19045, MSVC, dev and release):

ctest --preset dev --no-tests=error -R '^(startup_local_log(_guard_drop_control|_reopen_control)?|startup_stubs)$' -V

Result: 4/4 passed in dev and 4/4 passed in release, 0 skipped.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7141265089 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1757#issuecomment-7141265089). Originally posted by [rasptum](https://github.com/rasptum) on 2026-11-24T18:52:08Z. --- Thanks for the review and the mutation check. The review raises no defects and has no inline comments, so the PR needs no code change; the head stays at 7955a4f1. Your mutation result matches what the fixture is meant to catch. With the kept-handle reuse bypassed, `startup_local_log` reports `opens=16001` and fails both `trap log is opened once per module` and `append_log reuses the kept handle`, independently of the `startup_local_log_reopen_control` negative control. Last local run on this head (Windows 10 19045, MSVC, `dev` and `release`): ```powershell ctest --preset dev --no-tests=error -R '^(startup_local_log(_guard_drop_control|_reopen_control)?|startup_stubs)$' -V ``` Result: 4/4 passed in `dev` and 4/4 passed in `release`, 0 skipped. AI-assisted (Claude Code).
tedin7 commented 2026-11-24 22:00:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T21:31:22Z.

Review: COMMENTED


Re-review at head d33f2d189521a13159a161aefc8a11e7c396d5ef (previously reviewed at 7955a4f1f2d8b8d906a8c48af07152c778f64343).

Verdict: no P1, no P2. Nothing in the PR changed; the push only merged origin/main.

What changed since the last review

  • git diff origin/main...7955a4f1 and git diff origin/main...d33f2d18 are the same 7 files, 234 insertions / 45 deletions. Compared line by line, they differ only in the index lines and in the hunk offsets and surrounding context of CMakeLists.txt (startup_trap_header_check landed in main next to the new test). The code, test and doc edits are identical, so the earlier read-through of trap.h (compare-exchange publication of the module-wide handle, full share mode, failed open cached as INVALID_HANDLE_VALUE, fallback to open/write/close when %X2W_TRAP_LOG% changes) still stands.

Commands run locally

  • git diff --check origin/main...HEAD: exit 0.
  • tests/docs_links_check.py: 18 Markdown files, 376 links, passed. tests/bidi_controls_check.py: 1337 files, no bidirectional controls.
  • Windows Server 2025 (Build 26100, MSVC 14.44 + D3D12 WARP) via the pipeline, targets startup_local_log_check d3d12_xs_shim startup_stub_xcrdapi, regex ^startup_local_log(_guard_drop_control|_reopen_control)?$: Debug 3/3 and Release /O2 3/3 passed.

Mutation (reverted with git checkout -- .)

  • In src/startup_stubs/trap.h:84, disabled the kept-handle reuse (if (false && current && ...)) and ran startup_local_log on Windows with a patched worktree: FAILED as expected (opens=16001, "trap log is opened once per module", "append_log reuses the kept handle").
  • Limit: only this one mutation was run again, because the PR content is unchanged from the previous review, where the same mutation was already checked. The C++ code cannot be built on Linux here, so mutations need the Windows runner.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6047743526 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1757#pullrequestreview-6047743526). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T21:31:22Z. **Review:** COMMENTED --- Re-review at head `d33f2d189521a13159a161aefc8a11e7c396d5ef` (previously reviewed at `7955a4f1f2d8b8d906a8c48af07152c778f64343`). **Verdict: no P1, no P2. Nothing in the PR changed; the push only merged `origin/main`.** ### What changed since the last review - `git diff origin/main...7955a4f1` and `git diff origin/main...d33f2d18` are the same 7 files, 234 insertions / 45 deletions. Compared line by line, they differ only in the `index` lines and in the hunk offsets and surrounding context of `CMakeLists.txt` (`startup_trap_header_check` landed in main next to the new test). The code, test and doc edits are identical, so the earlier read-through of `trap.h` (compare-exchange publication of the module-wide handle, full share mode, failed open cached as `INVALID_HANDLE_VALUE`, fallback to open/write/close when `%X2W_TRAP_LOG%` changes) still stands. ### Commands run locally - `git diff --check origin/main...HEAD`: exit 0. - `tests/docs_links_check.py`: 18 Markdown files, 376 links, passed. `tests/bidi_controls_check.py`: 1337 files, no bidirectional controls. - Windows Server 2025 (Build 26100, MSVC 14.44 + D3D12 WARP) via the pipeline, targets `startup_local_log_check d3d12_xs_shim startup_stub_xcrdapi`, regex `^startup_local_log(_guard_drop_control|_reopen_control)?$`: Debug 3/3 and Release /O2 3/3 passed. ### Mutation (reverted with `git checkout -- .`) - In `src/startup_stubs/trap.h:84`, disabled the kept-handle reuse (`if (false && current && ...)`) and ran `startup_local_log` on Windows with a patched worktree: FAILED as expected (`opens=16001`, "trap log is opened once per module", "append_log reuses the kept handle"). - Limit: only this one mutation was run again, because the PR content is unchanged from the previous review, where the same mutation was already checked. The C++ code cannot be built on Linux here, so mutations need the Windows runner. AI-assisted; commands listed were executed locally.
R0Y00 commented 2026-11-24 22:00:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T21:34:05Z.

Review: CHANGES_REQUESTED


The concurrent append benchmark establishes the useful fast path. One recovery behavior changes: if the first open fails while the parent directory is absent or the file is temporarily inaccessible, caching INVALID_HANDLE_VALUE permanently drops every later line for that path. The old writer retries, so a later trap can still reach the log. Please avoid permanently caching open failure (a bounded retry/backoff is fine if steady-state tracing cost matters). Add a source-built first-open failure followed by a directory creation and a successful later append. Keep the one-open count for an available, unchanged path.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6047776650 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1757#pullrequestreview-6047776650). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T21:34:05Z. **Review:** CHANGES_REQUESTED --- The concurrent append benchmark establishes the useful fast path. One recovery behavior changes: if the first open fails while the parent directory is absent or the file is temporarily inaccessible, caching INVALID_HANDLE_VALUE permanently drops every later line for that path. The old writer retries, so a later trap can still reach the log. Please avoid permanently caching open failure (a bounded retry/backoff is fine if steady-state tracing cost matters). Add a source-built first-open failure followed by a directory creation and a successful later append. Keep the one-open count for an available, unchanged path.
rasptum commented 2026-11-24 22:01:05 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by rasptum on 2026-11-24T21:54:54Z.


Thanks, agreed: caching the failed open was a recovery regression. Changes in 148d6daa (after merging main at 3920220f):

Failed opens are no longer cached. append_log keeps a handle only after a successful open. While no handle is kept, a failed open makes ordinary lines wait log_retry_ms (250 ms) before the next open attempt. Lines in that wait are dropped, as the per-line writer dropped a line it could not open for; nothing is buffered. Trap lines (flush) always attempt the open, so a later trap still reaches the log as soon as the path is usable. Cost on a path that stays unusable: at most one open attempt per 250 ms per module for ordinary lines. Measured: 4 attempts while 78,000 to 231,000 lines were logged in one second; the per-line writer would have tried once per line.

Tests, source-built, each case in a fresh child process:

  • Missing directory: X2W_TRAP_LOG points into a directory that does not exist; the first append fails and its line is dropped. The child then creates the directory, waits past the interval, and a later append must land as the file's only line. 100 more lines must follow in order without another open.
  • Temporarily inaccessible: the file is held with CreateFileW and no sharing, so the first append fails with a sharing violation. After the handle is released, a later append must land, with the same follow-up checks. This is deterministic because the same process holds and releases the file.
  • Trap during the wait: right after a failed open, the child creates the directory and immediately writes a flush (trap) line, which must land.
  • Cost: in both recovery cases, an unusable path is logged to for one second and must cost at most one open attempt per 250 ms.
  • Existing: the 8 threads × 2,000 lines check still requires one open for an available, unchanged path (opens=1 lines=16001).
  • New negative control: startup_local_log_cache_failure_control (WILL_FAIL) builds the same check against a generated copy of trap.h whose failed open is kept forever. It passes only when the two recovery checks are its sole failures. Observed: both recovery children exit 3, with a later line reaches the log once the path is usable failing; every other check passes.

Command, Windows 10 19045, MSVC, dev and release:

ctest --preset dev --no-tests=error -R '^(startup_local_log(_guard_drop_control|_reopen_control|_cache_failure_control)?|startup_stubs|startup_trap_header(_prefix_control|_precedence_control)?)$' -V

Result: 8/8 passed in dev and 8/8 passed in release, 0 skipped. tests/docs_links_check.py and tests/bidi_controls_check.py pass.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7145555538 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1757#issuecomment-7145555538). Originally posted by [rasptum](https://github.com/rasptum) on 2026-11-24T21:54:54Z. --- Thanks, agreed: caching the failed open was a recovery regression. Changes in 148d6daa (after merging main at 3920220f): **Failed opens are no longer cached.** `append_log` keeps a handle only after a successful open. While no handle is kept, a failed open makes ordinary lines wait `log_retry_ms` (250 ms) before the next open attempt. Lines in that wait are dropped, as the per-line writer dropped a line it could not open for; nothing is buffered. Trap lines (`flush`) always attempt the open, so a later trap still reaches the log as soon as the path is usable. Cost on a path that stays unusable: at most one open attempt per 250 ms per module for ordinary lines. Measured: 4 attempts while 78,000 to 231,000 lines were logged in one second; the per-line writer would have tried once per line. **Tests**, source-built, each case in a fresh child process: - **Missing directory:** `X2W_TRAP_LOG` points into a directory that does not exist; the first append fails and its line is dropped. The child then creates the directory, waits past the interval, and a later append must land as the file's only line. 100 more lines must follow in order without another open. - **Temporarily inaccessible:** the file is held with `CreateFileW` and no sharing, so the first append fails with a sharing violation. After the handle is released, a later append must land, with the same follow-up checks. This is deterministic because the same process holds and releases the file. - **Trap during the wait:** right after a failed open, the child creates the directory and immediately writes a flush (trap) line, which must land. - **Cost:** in both recovery cases, an unusable path is logged to for one second and must cost at most one open attempt per 250 ms. - **Existing:** the 8 threads × 2,000 lines check still requires one open for an available, unchanged path (`opens=1 lines=16001`). - **New negative control:** `startup_local_log_cache_failure_control` (`WILL_FAIL`) builds the same check against a generated copy of `trap.h` whose failed open is kept forever. It passes only when the two recovery checks are its sole failures. Observed: both recovery children exit 3, with `a later line reaches the log once the path is usable` failing; every other check passes. Command, Windows 10 19045, MSVC, `dev` and `release`: ```powershell ctest --preset dev --no-tests=error -R '^(startup_local_log(_guard_drop_control|_reopen_control|_cache_failure_control)?|startup_stubs|startup_trap_header(_prefix_control|_precedence_control)?)$' -V ``` Result: 8/8 passed in `dev` and 8/8 passed in `release`, 0 skipped. `tests/docs_links_check.py` and `tests/bidi_controls_check.py` pass. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-24 23:03:02 +00:00
R0Y00 commented 2026-11-24 23:03:02 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T22:08:14Z.

Review: APPROVED


Rechecked the exact recovery fix. Windows Release passed all four startup_local_log tests, including the old failed-open configuration as a negative control.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6048180224 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1757#pullrequestreview-6048180224). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T22:08:14Z. **Review:** APPROVED --- Rechecked the exact recovery fix. Windows Release passed all four startup_local_log tests, including the old failed-open configuration as a negative control.
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
R0Y00/Xbox2Windows!1750
No description provided.