startup: stop the stand-ins' first-calls log counters at their limit #1987

Manually merged
github merged 1 commit from gh-pr/1987/head into gh-pr/1987/base 2026-11-26 23:47:57 +00:00
Owner

@⁠rasptum on GitHub · 2026-11-24 22:37 UTC · original
rasptum:startup/log-limiter-saturate → main · +86 −36 · 9 files · 1 commits · merged 2026-11-24 23:04 UTC

The stand-ins limit many log lines to the first N calls with InterlockedIncrement(&counter) <= N, and x2w_local::first_calls in src/startup_stubs/local_log.h uses the same expression. The counter counts every call. A consumer that polls a status in a loop drives it past 2^31; it turns negative, and from then on every call is logged again. In a local run this produced millions of lines a minute and stalled the process.

  • x2w_local::first_calls now stops incrementing at the limit, using a compare-exchange loop with no lock. Output for the first N calls is unchanged.
  • These raw gates now use the helper: xcrdapi.cpp (13), xg_xs.cpp (3), d3d12_draw.inl (3), runtime_proxy.cpp (tracked_logged) and the X2W_D3D12_DUMP_PSO per-slot gate in d3d12_xs_device.cpp. The device's own first_calls forwards to the helper.
  • Three counters also feed statistics, so they keep counting and only log while the count is positive: render_draws, shown_frames and the runtime proxy's per-slot call_counts.
  • Left as they are:
    • shape_checks: it checks < 32 before incrementing, so it cannot wrap.
    • The checks & 63 periodic device check: the mask still works after a wrap.
    • Counters used as indexes, tokens or frame numbers: they are not log gates.
  • startup_local_log now expects the counter to stay at the limit (3, 0 for a zero or negative limit, exactly 10 under 4 threads). It also checks a counter set to 0x7FFFFFFE: with a limit of 4, none of 16 calls may pass.
  • The new negative control startup_local_log_wrap_control (--mutate wrap) runs that wrap case with the old counting expression. It passes only on the line FAIL first_calls passes no call at the wrap point, so any other failure makes the control fail.

A local check, not part of this change: putting the old expression back into the header made startup_local_log fail its saturation and wrap cases.

Test (both presets, throttled build of the touched targets, plus d3d12_xs_shim to compile the device file):

ctest --preset dev --no-tests=error -R '^(startup_local_log.*|startup_stubs|startup_acphal_apu_free|startup_dstorage_destination|startup_gameinput_(history|keys)|startup_heartbeat_commit|startup_storage_(alloc_failure|directory_batch|refusal_order|failure_counts.*)|startup_xapu_queue)$' -V
  • dev: 17 passed, 0 failed, 0 skipped (startup_local_log: 92 cases; startup_local_log_wrap_control passed on its expected FAIL line).
  • release: the same command with --preset release: 17 passed, 0 failed, 0 skipped.
  • tests/docs_links_check.py and tests/bidi_controls_check.py pass.

docs/startup-runtime.md (Local switches) describes the saturating gate and names the new control.

🤖 Generated with Claude Code

**@⁠rasptum** on GitHub · 2026-11-24 22:37 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1987) `rasptum:startup/log-limiter-saturate` → `main` · +86 −36 · 9 files · 1 commits · merged 2026-11-24 23:04 UTC The stand-ins limit many log lines to the first N calls with `InterlockedIncrement(&counter) <= N`, and `x2w_local::first_calls` in `src/startup_stubs/local_log.h` uses the same expression. The counter counts every call. A consumer that polls a status in a loop drives it past 2^31; it turns negative, and from then on every call is logged again. In a local run this produced millions of lines a minute and stalled the process. - `x2w_local::first_calls` now stops incrementing at the limit, using a compare-exchange loop with no lock. Output for the first N calls is unchanged. - These raw gates now use the helper: `xcrdapi.cpp` (13), `xg_xs.cpp` (3), `d3d12_draw.inl` (3), `runtime_proxy.cpp` (`tracked_logged`) and the `X2W_D3D12_DUMP_PSO` per-slot gate in `d3d12_xs_device.cpp`. The device's own `first_calls` forwards to the helper. - Three counters also feed statistics, so they keep counting and only log while the count is positive: `render_draws`, `shown_frames` and the runtime proxy's per-slot `call_counts`. - Left as they are: - `shape_checks`: it checks `< 32` before incrementing, so it cannot wrap. - The `checks & 63` periodic device check: the mask still works after a wrap. - Counters used as indexes, tokens or frame numbers: they are not log gates. - `startup_local_log` now expects the counter to stay at the limit (3, 0 for a zero or negative limit, exactly 10 under 4 threads). It also checks a counter set to `0x7FFFFFFE`: with a limit of 4, none of 16 calls may pass. - The new negative control `startup_local_log_wrap_control` (`--mutate wrap`) runs that wrap case with the old counting expression. It passes only on the line `FAIL first_calls passes no call at the wrap point`, so any other failure makes the control fail. A local check, not part of this change: putting the old expression back into the header made `startup_local_log` fail its saturation and wrap cases. Test (both presets, throttled build of the touched targets, plus `d3d12_xs_shim` to compile the device file): ```powershell ctest --preset dev --no-tests=error -R '^(startup_local_log.*|startup_stubs|startup_acphal_apu_free|startup_dstorage_destination|startup_gameinput_(history|keys)|startup_heartbeat_commit|startup_storage_(alloc_failure|directory_batch|refusal_order|failure_counts.*)|startup_xapu_queue)$' -V ``` - dev: 17 passed, 0 failed, 0 skipped (`startup_local_log`: 92 cases; `startup_local_log_wrap_control` passed on its expected FAIL line). - release: the same command with `--preset release`: 17 passed, 0 failed, 0 skipped. - `tests/docs_links_check.py` and `tests/bidi_controls_check.py` pass. `docs/startup-runtime.md` (Local switches) describes the saturating gate and names the new control. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The stand-ins limit many log lines to the first N calls with
InterlockedIncrement(&counter) <= N. The counter counts every call, so a
consumer that polls a status in a loop drives it past 2^31; it turns
negative and from then on every call is logged again.

x2w_local::first_calls now stops incrementing at the limit (a
compare-exchange loop, no lock), and the raw InterlockedIncrement gates in
xcrdapi.cpp, xg_xs.cpp, runtime_proxy.cpp, d3d12_draw.inl and the pipeline
dump in d3d12_xs_device.cpp use it. The device's own first_calls forwards
to it. Three counters that also feed statistics (render_draws, shown_frames
and the runtime proxy's per-slot call counts) keep counting and gate on a
positive value instead. Output for the first N calls is unchanged.

startup_local_log now expects the counter to stay at the limit and checks a
counter set near the wrap point; startup_local_log_wrap_control shows the old
counting gate letting calls through there.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:47:55 +00:00
github manually merged commit f360d30a83 into gh-pr/1987/base 2026-11-26 23:47:57 +00:00
Author
Owner

@⁠ChazY11 on GitHub · 2026-11-24 22:48 UTC · original

Built and ran it; both ways back to the bug are caught

Windows 11 build 26300.9974, MSVC 19.44, dev preset:

cmake --build --preset dev --target startup_local_log_check    # exit 0
ctest --preset dev -R 'local_log'
1/5 startup_local_log ......................... Passed 3.03
2/5 startup_local_log_guard_drop_control ...... Passed 3.04
3/5 startup_local_log_reopen_control .......... Passed 0.73
4/5 startup_local_log_cache_failure_control ... ***Not Run
5/5 startup_local_log_wrap_control ............ Passed 0.03

startup_local_log_cache_failure_control did not run because its executable was not in my build selection — my environment, not the PR. The
four that ran are green, and the log-flood output the fix is about is visible in their output:

recovery child: 1144774 lines on an unusable path in 1000 ms took 4 open attempts

~1.1 million lines per second on the unusable path is the rate that made the counter matter; the fix keeps that burst to the configured
limit instead of letting it resume at 2^31.

Mutations

mutation in src/startup_stubs/local_log.h result
first_calls back to return InterlockedIncrement(&counter) <= limit; (the original bug) caught
the compare-exchange loop bound seen < limit → seen <= limit (off-by-one at the cap) caught

The first is the important one: restoring the exact pre-change expression makes the fixture fail, so the regression it prevents is pinned
rather than assumed. The second shows the cap is the limit, not "somewhere near it" — an off-by-one would have let one extra line through
and left the counter at limit + 1, which is the same class of runaway the fix exists to stop, just slower.

Why the helper and not the call sites

The same expression appeared at 13 + 3 + 3 + 1 + 1 sites. Capping it once in first_calls is the only version that cannot drift, and the
call sites that were converted are listed in the description so a reviewer can check the count rather than trust it. The three counters that
also feed statistics (render_draws, shown_frames, runtime proxy slot counts) keeping their full count while logging only while positive
is the right split: a counter that stops counting breaks the statistic, a counter that keeps counting breaks the gate.

What is unverified

Nothing process-level beyond this fixture: the 2^31 turn is exercised by the counter arithmetic, not by driving a real provider past two
billion calls. Whether a title's own polling loop hits the same path is a claim about the provider, not about this header.

Verdict

Reviewed. The bug is real, the fix is in the one place that cannot be forgotten, and both the old expression and an off-by-one fail the
fixture.

Notes

  • AI-assisted review.
**@⁠ChazY11** on GitHub · 2026-11-24 22:48 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1987#issuecomment-7146671410) ## Built and ran it; both ways back to the bug are caught Windows 11 build 26300.9974, MSVC 19.44, `dev` preset: ```powershell cmake --build --preset dev --target startup_local_log_check # exit 0 ctest --preset dev -R 'local_log' 1/5 startup_local_log ......................... Passed 3.03 2/5 startup_local_log_guard_drop_control ...... Passed 3.04 3/5 startup_local_log_reopen_control .......... Passed 0.73 4/5 startup_local_log_cache_failure_control ... ***Not Run 5/5 startup_local_log_wrap_control ............ Passed 0.03 ``` `startup_local_log_cache_failure_control` did not run because its executable was not in my build selection — my environment, not the PR. The four that ran are green, and the log-flood output the fix is about is visible in their output: ```text recovery child: 1144774 lines on an unusable path in 1000 ms took 4 open attempts ``` ~1.1 million lines per second on the unusable path is the rate that made the counter matter; the fix keeps that burst to the configured limit instead of letting it resume at 2^31. ## Mutations | mutation in `src/startup_stubs/local_log.h` | result | |---|---| | `first_calls` back to `return InterlockedIncrement(&counter) <= limit;` (the original bug) | **caught** | | the compare-exchange loop bound `seen < limit` → `seen <= limit` (off-by-one at the cap) | **caught** | The first is the important one: restoring the exact pre-change expression makes the fixture fail, so the regression it prevents is pinned rather than assumed. The second shows the cap is the *limit*, not "somewhere near it" — an off-by-one would have let one extra line through and left the counter at `limit + 1`, which is the same class of runaway the fix exists to stop, just slower. ## Why the helper and not the call sites The same expression appeared at 13 + 3 + 3 + 1 + 1 sites. Capping it once in `first_calls` is the only version that cannot drift, and the call sites that were converted are listed in the description so a reviewer can check the count rather than trust it. The three counters that also feed statistics (`render_draws`, `shown_frames`, runtime proxy slot counts) keeping their full count while logging only while positive is the right split: a counter that stops counting breaks the statistic, a counter that keeps counting breaks the gate. ## What is unverified Nothing process-level beyond this fixture: the 2^31 turn is exercised by the counter arithmetic, not by driving a real provider past two billion calls. Whether a title's own polling loop hits the same path is a claim about the provider, not about this header. ## Verdict Reviewed. The bug is real, the fix is in the one place that cannot be forgotten, and both the old expression and an off-by-one fail the fixture. ## Notes - AI-assisted review.
This discussion has been locked. Commenting is limited to contributors.
No description provided.