startup: add bounded per-reason refusal census per pipeline key #2293

Merged
stan495 merged 2 commits from upstream-pr/2301 into main 2026-11-25 11:10:48 +00:00
stan495 commented 2026-11-25 10:55:48 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by stan495 on 2026-11-25T10:55:48Z.


Summary

Refs #2274 (Part B: Per-reason refusal census).

Adds a standalone, lock-protected per-(key, reason) refusal census in src/startup_stubs/per_reason_refusal_census.h so multiple refusal reasons on the same pipeline key are counted independently rather than overwriting earlier reasons with the last refusal.

  • PerReasonRefusalCensus: bounded table (max_entries = 128, sanitized 64-byte reason buffer, detail_entries = 8 first-seen hint, overflow accounting past the cap) using std::mutex.
  • Periodic and forced reporting (report(emit, only_if_changed)): skips unchanged periodic reports, prints only changed (key, reason) entries on periodic ticks, and keeps delta tracking intact across forced reports.
  • tests/startup_per_reason_refusal_census_check.cpp + CMake/CTest registration: tests interleaved multi-reason counts on two keys, reason normalization/sanitization, detail/overflow limits, periodic deltas, and two WILL_FAIL controls compiled against the real PerReasonRefusalCensus class (-DX2W_CENSUS_KEEP_LAST and -DX2W_CENSUS_KEEP_FIRST) that print both expected reasons with their counts on mismatch.
  • docs/startup-runtime.md: documents the standalone header, its limits, and its test command.

Ready to wire directly into runtime refusal callers (such as slot-67 compute dispatch and binding) once the preceding Part B dispatch PRs land.

Verification

Commit 55ab0dec4d016604f3525354ad5a64e3dbe5a26c on Windows 11 (26200.9974, MSVC 19.44.35228.0):

. .\tools\dev.ps1
cmake --preset dev
cmake --build --preset dev --target startup_per_reason_refusal_census_check startup_per_reason_refusal_census_keep_last_control startup_per_reason_refusal_census_keep_first_control startup_memory_srv_census_check
ctest --preset dev --no-tests=error -R '^startup_(per_reason_refusal|memory_srv)_census' -V

cmake --preset release
cmake --build --preset release --target startup_per_reason_refusal_census_check startup_per_reason_refusal_census_keep_last_control startup_per_reason_refusal_census_keep_first_control startup_memory_srv_census_check
ctest --preset release --no-tests=error -R '^startup_(per_reason_refusal|memory_srv)_census' -V

python -B tests/docs_links_check.py
python -B tests/bidi_controls_check.py
python -B tests/form_coverage_check.py
  • dev CTest (startup_memory_srv_census, startup_per_reason_refusal_census, startup_per_reason_refusal_census_keep-last_control, startup_per_reason_refusal_census_keep-first_control): 4/4 passed.
  • release (/O2) CTest: 4/4 passed.
  • docs_links_check.py: passed (18 Markdown files, 437 links).
  • bidi_controls_check.py: passed (1586 tracked files).
  • form_coverage_check.py: passed.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6602873098 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2301). Originally posted by [stan495](https://github.com/stan495) on 2026-11-25T10:55:48Z. --- ## Summary Refs #2274 (Part B: Per-reason refusal census). Adds a standalone, lock-protected per-`(key, reason)` refusal census in `src/startup_stubs/per_reason_refusal_census.h` so multiple refusal reasons on the same pipeline key are counted independently rather than overwriting earlier reasons with the last refusal. - `PerReasonRefusalCensus`: bounded table (`max_entries = 128`, sanitized 64-byte reason buffer, `detail_entries = 8` first-seen hint, overflow accounting past the cap) using `std::mutex`. - Periodic and forced reporting (`report(emit, only_if_changed)`): skips unchanged periodic reports, prints only changed `(key, reason)` entries on periodic ticks, and keeps delta tracking intact across forced reports. - `tests/startup_per_reason_refusal_census_check.cpp` + CMake/CTest registration: tests interleaved multi-reason counts on two keys, reason normalization/sanitization, detail/overflow limits, periodic deltas, and two `WILL_FAIL` controls compiled against the real `PerReasonRefusalCensus` class (`-DX2W_CENSUS_KEEP_LAST` and `-DX2W_CENSUS_KEEP_FIRST`) that print both expected reasons with their counts on mismatch. - `docs/startup-runtime.md`: documents the standalone header, its limits, and its test command. Ready to wire directly into runtime refusal callers (such as slot-67 compute dispatch and binding) once the preceding Part B dispatch PRs land. ## Verification Commit `55ab0dec4d016604f3525354ad5a64e3dbe5a26c` on Windows 11 (`26200.9974`, MSVC `19.44.35228.0`): ```powershell . .\tools\dev.ps1 cmake --preset dev cmake --build --preset dev --target startup_per_reason_refusal_census_check startup_per_reason_refusal_census_keep_last_control startup_per_reason_refusal_census_keep_first_control startup_memory_srv_census_check ctest --preset dev --no-tests=error -R '^startup_(per_reason_refusal|memory_srv)_census' -V cmake --preset release cmake --build --preset release --target startup_per_reason_refusal_census_check startup_per_reason_refusal_census_keep_last_control startup_per_reason_refusal_census_keep_first_control startup_memory_srv_census_check ctest --preset release --no-tests=error -R '^startup_(per_reason_refusal|memory_srv)_census' -V python -B tests/docs_links_check.py python -B tests/bidi_controls_check.py python -B tests/form_coverage_check.py ``` - `dev` CTest (`startup_memory_srv_census`, `startup_per_reason_refusal_census`, `startup_per_reason_refusal_census_keep-last_control`, `startup_per_reason_refusal_census_keep-first_control`): 4/4 passed. - `release` (`/O2`) CTest: 4/4 passed. - `docs_links_check.py`: passed (18 Markdown files, 437 links). - `bidi_controls_check.py`: passed (1586 tracked files). - `form_coverage_check.py`: passed.
tedin7 commented 2026-11-25 11:02:28 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T10:58:20Z.

Review: COMMENTED


Review of head d1be384d0dff79b18c6f71a1a3a10dc976f1b4ce (4 files, +366).

Verdict: logic is correct; one test-quality P2 and a few nits. No P1.

Commands executed locally (Linux, g++ -std=c++17 -Wall -Wextra):

  • g++ -std=c++17 -Wall -Wextra -Isrc tests/startup_per_reason_refusal_census_check.cpp -> no warnings; run prints PASS (distinct keys=2, pairs=4, detail=8, max=128).
  • --mutate keep-last -> exit 1 (FAIL key2 keeps interleaved missing_root with calls=1, 5 checks); controls fail as intended.
  • Real mutations of the header, each followed by git checkout -- .:
    • lookup matches on key only (drops the reason compare) -> killed (exit 1, 3+ FAILs).
    • reported_ = total_ made unconditional (forced report eats the periodic delta) -> killed (forced report does not hide next periodic delta).
    • removed ++distinct_keys_ -> killed (summary line mismatch).
  • python3 tests/docs_links_check.py -> pass (18 files, 437 links). python3 tests/bidi_controls_check.py -> pass. git diff --check origin/main...HEAD -> clean.
  • Header read in full: the per-pair lookup, the cap and overflow accounting, the sanitize copy (always NUL-terminated, CR/LF replaced) and the lock use all look right.

Windows jobs were still pending at review time. This is header-only and device-free, so I did not queue a WARP/GPU run.

P2

  1. tests/startup_per_reason_refusal_census_check.cpp:~70-105: the keep-last / keep-first controls do not exercise PerReasonRefusalCensus. They rebuild a fake single-slot table in the test and overwrite observed, so they would fail whatever the header does. They prove the assertions are strict, but not that the header regresses visibly. The real-header mutations above are killed by the main run, so coverage is fine. Either say in the CMake comment and docs that the controls are simulated, or drop them in favor of a compile-time -DX2W_CENSUS_KEEP_LAST style mutation of the real class.

Nits
2. per_reason_refusal_census.h:50: memcpy(entry.reason, reason, sizeof(reason)) copies uninitialized bytes after the NUL. Use strcpy or zero-init reason[] = {} (valgrind/MSan noise only).
3. Header is not included by any production code yet; the PR text says wiring follows. Fine, but the doc section may be read as "wired".
4. note() linear scan is O(128) under the mutex per refusal; fine for a refusal path, worth a comment if it ever lands on a hot path.
5. PR body has stray escape glitches (\report, \tests, a leading BOM, unfenced powershell). Cosmetic.
6. Title and body are neutral; clean-room and MIT constraints look fine; mergeable.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6056315255 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2301#pullrequestreview-6056315255). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T10:58:20Z. **Review:** COMMENTED --- Review of head `d1be384d0dff79b18c6f71a1a3a10dc976f1b4ce` (4 files, +366). **Verdict: logic is correct; one test-quality P2 and a few nits. No P1.** Commands executed locally (Linux, g++ -std=c++17 -Wall -Wextra): - `g++ -std=c++17 -Wall -Wextra -Isrc tests/startup_per_reason_refusal_census_check.cpp` -> no warnings; run prints `PASS (distinct keys=2, pairs=4, detail=8, max=128)`. - `--mutate keep-last` -> exit 1 (`FAIL key2 keeps interleaved missing_root with calls=1`, 5 checks); controls fail as intended. - Real mutations of the header, each followed by `git checkout -- .`: - lookup matches on key only (drops the reason compare) -> killed (exit 1, 3+ FAILs). - `reported_ = total_` made unconditional (forced report eats the periodic delta) -> killed (`forced report does not hide next periodic delta`). - removed `++distinct_keys_` -> killed (summary line mismatch). - `python3 tests/docs_links_check.py` -> pass (18 files, 437 links). `python3 tests/bidi_controls_check.py` -> pass. `git diff --check origin/main...HEAD` -> clean. - Header read in full: the per-pair lookup, the cap and overflow accounting, the sanitize copy (always NUL-terminated, CR/LF replaced) and the lock use all look right. Windows jobs were still pending at review time. This is header-only and device-free, so I did not queue a WARP/GPU run. **P2** 1. `tests/startup_per_reason_refusal_census_check.cpp:~70-105`: the `keep-last` / `keep-first` controls do not exercise `PerReasonRefusalCensus`. They rebuild a fake single-slot table in the test and overwrite `observed`, so they would fail whatever the header does. They prove the assertions are strict, but not that the header regresses visibly. The real-header mutations above are killed by the main run, so coverage is fine. Either say in the CMake comment and docs that the controls are simulated, or drop them in favor of a compile-time `-DX2W_CENSUS_KEEP_LAST` style mutation of the real class. **Nits** 2. `per_reason_refusal_census.h:50`: `memcpy(entry.reason, reason, sizeof(reason))` copies uninitialized bytes after the NUL. Use `strcpy` or zero-init `reason[] = {}` (valgrind/MSan noise only). 3. Header is not included by any production code yet; the PR text says wiring follows. Fine, but the doc section may be read as "wired". 4. `note()` linear scan is O(128) under the mutex per refusal; fine for a refusal path, worth a comment if it ever lands on a hot path. 5. PR body has stray escape glitches (`\report`, `\tests`, a leading BOM, unfenced `powershell`). Cosmetic. 6. Title and body are neutral; clean-room and MIT constraints look fine; mergeable. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-25 12:01:43 +00:00
stan495 commented 2026-11-25 12:01:52 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by stan495 on 2026-11-25T11:04:29Z.


Addressed the P2 and nits in 55ab0dec4d016604f3525354ad5a64e3dbe5a26c:

  • P2 (real-class negative controls): removed the simulated map from tests/startup_per_reason_refusal_census_check.cpp and added compile-time X2W_CENSUS_KEEP_LAST / X2W_CENSUS_KEEP_FIRST control targets in CMakeLists.txt so both WILL_FAIL controls exercise PerReasonRefusalCensus directly (keep-last fails 7 checks, keep-first fails 6 checks, each printing both expected key1 reasons with counts alongside the observed output).
  • Nit 2: zero-initialized char reason[max_reason_bytes] = {}; in note() before copy_sanitized() so memcpy never copies uninitialized tail bytes.
  • Nit 3: clarified in docs/startup-runtime.md that PerReasonRefusalCensus is currently a standalone header/check not yet wired into d3d12_xs_device.cpp or the five-second report.
  • Nit 4: added a brief comment on the bounded linear scan under mutex_.
  • Nit 5: cleaned up the PR description (removed BOM/escaping artifacts and fenced the PowerShell commands).

Re-verified on Windows 11 (dev and release /O2 presets: 4/4 CTest cases passed; docs_links_check.py, bidi_controls_check.py, and form_coverage_check.py passed).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7160551660 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2301#issuecomment-7160551660). Originally posted by [stan495](https://github.com/stan495) on 2026-11-25T11:04:29Z. --- Addressed the P2 and nits in `55ab0dec4d016604f3525354ad5a64e3dbe5a26c`: - **P2 (real-class negative controls):** removed the simulated map from `tests/startup_per_reason_refusal_census_check.cpp` and added compile-time `X2W_CENSUS_KEEP_LAST` / `X2W_CENSUS_KEEP_FIRST` control targets in `CMakeLists.txt` so both `WILL_FAIL` controls exercise `PerReasonRefusalCensus` directly (`keep-last` fails 7 checks, `keep-first` fails 6 checks, each printing both expected `key1` reasons with counts alongside the observed output). - **Nit 2:** zero-initialized `char reason[max_reason_bytes] = {};` in `note()` before `copy_sanitized()` so `memcpy` never copies uninitialized tail bytes. - **Nit 3:** clarified in `docs/startup-runtime.md` that `PerReasonRefusalCensus` is currently a standalone header/check not yet wired into `d3d12_xs_device.cpp` or the five-second report. - **Nit 4:** added a brief comment on the bounded linear scan under `mutex_`. - **Nit 5:** cleaned up the PR description (removed BOM/escaping artifacts and fenced the PowerShell commands). Re-verified on Windows 11 (`dev` and `release` `/O2` presets: 4/4 CTest cases passed; `docs_links_check.py`, `bidi_controls_check.py`, and `form_coverage_check.py` passed).
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!2293
No description provided.