startup: add a voice-lifecycle control with explicit diagnostic and system providers #1399

Manually merged
github merged 2 commits from gh-pr/1399/head into gh-pr/1399/base 2026-11-26 23:04:11 +00:00
Owner

@⁠triggered02 on GitHub · 2026-11-24 10:30 UTC · original
triggered02:startup/audio-provider-control → main · +467 −0 · 2 files · 2 commits · merged 2026-11-24 10:45 UTC

Second slice of #1145, following the direction on the issue: a source-built client with an explicit
diagnostic XAudio2 provider rather than an intercepting tap.

One client drives a steady and a bursty submission plan through a small provider interface with two
implementations:

  • diagnostic: records the voice lifecycle, buffer arguments and callbacks, and advances a virtual
    clock as the plan waits; it touches no device and stores no audio;
  • system: calls XAudio2Create and the real IXAudio2 directly. There is no import patching and no
    hooking anywhere, so the diagnostics-disabled arm visibly calls the system provider.

The precondition the slice starts from is that the diagnostic window is faithful, so the fixture checks
that both arms observe the same lifecycle and the same buffer arguments for the same plan, and fails on
divergence with the first differing event. Only after that does it report timing.

Recorded per arm: timestamps, frame counts, buffer counts, callbacks, drops, queue depth and clock
progress. Audio bytes and user data are never recorded or stored — the system arm submits silence.

Measured here (shared-mode endpoint, XAudio2_9, 48 kHz stereo 16-bit, 120 blocks of 10 ms):

steady: faithful=yes
  diagnostic: events=243 frames=57600 callbacks=120 drops=0 depth_max=480  clock=57600 elapsed=1907ms
  system    : events=243 frames=57600 callbacks=120 drops=0 depth_max=480  clock=57600 elapsed=1875ms
bursty: faithful=yes
  diagnostic: events=243 frames=57600 callbacks=120 drops=0 depth_max=2880 clock=57600 elapsed=4704ms
  system    : events=243 frames=57600 callbacks=120 drops=0 depth_max=2880 clock=57600 elapsed=4719ms

Two defects this control found in its own diagnostic arm while it was being built, both fixed: the arm
did not advance its clock during withholding gaps (so the bursty arm was unfaithful by construction and
diverged at event 3), and it reported queue depth in frames for one arm and buffers for the other.

Skips (77) when no shared-mode endpoint is available.

What this slice does not establish, restating the limit on the issue: a steady submission stream
would narrow the fault to after submission, and would still leave voice state, queued playback and
endpoint scheduling to verify. This fixture measures the client/provider boundary; it does not locate
the title's stutter.

**@⁠triggered02** on GitHub · 2026-11-24 10:30 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1399) `triggered02:startup/audio-provider-control` → `main` · +467 −0 · 2 files · 2 commits · merged 2026-11-24 10:45 UTC Second slice of #1145, following the direction on the issue: a source-built client with an explicit diagnostic XAudio2 provider rather than an intercepting tap. One client drives a steady and a bursty submission plan through a small provider interface with two implementations: - **diagnostic**: records the voice lifecycle, buffer arguments and callbacks, and advances a virtual clock as the plan waits; it touches no device and stores no audio; - **system**: calls `XAudio2Create` and the real `IXAudio2` directly. There is no import patching and no hooking anywhere, so the diagnostics-disabled arm visibly calls the system provider. The precondition the slice starts from is that the diagnostic window is faithful, so the fixture checks that both arms observe the same lifecycle and the same buffer arguments for the same plan, and fails on divergence with the first differing event. Only after that does it report timing. Recorded per arm: timestamps, frame counts, buffer counts, callbacks, drops, queue depth and clock progress. **Audio bytes and user data are never recorded or stored** — the system arm submits silence. Measured here (shared-mode endpoint, XAudio2_9, 48 kHz stereo 16-bit, 120 blocks of 10 ms): ``` steady: faithful=yes diagnostic: events=243 frames=57600 callbacks=120 drops=0 depth_max=480 clock=57600 elapsed=1907ms system : events=243 frames=57600 callbacks=120 drops=0 depth_max=480 clock=57600 elapsed=1875ms bursty: faithful=yes diagnostic: events=243 frames=57600 callbacks=120 drops=0 depth_max=2880 clock=57600 elapsed=4704ms system : events=243 frames=57600 callbacks=120 drops=0 depth_max=2880 clock=57600 elapsed=4719ms ``` Two defects this control found in its own diagnostic arm while it was being built, both fixed: the arm did not advance its clock during withholding gaps (so the bursty arm was unfaithful by construction and diverged at event 3), and it reported queue depth in frames for one arm and buffers for the other. Skips (77) when no shared-mode endpoint is available. **What this slice does not establish**, restating the limit on the issue: a steady submission stream would narrow the fault to *after* submission, and would still leave voice state, queued playback and endpoint scheduling to verify. This fixture measures the client/provider boundary; it does not locate the title's stutter.
Second slice of #1145, per the direction on the issue.

One client drives a steady and a bursty submission plan through a provider interface with two
implementations: a diagnostic recorder that never touches a device, and the system provider that calls
XAudio2Create and the real IXAudio2 directly (no import patching, no hooking).

The fixture first verifies the diagnostic window is faithful - both arms must observe the same
lifecycle and buffer arguments for the same plan - and fails on divergence with the first differing
event, because a timing number from an unfaithful window would be worthless.

Per arm it records timestamps, frame and buffer counts, callbacks, drops, queue depth and clock
progress. Audio bytes and user data are never recorded; the system arm submits silence.

Measured (48 kHz stereo 16-bit, 120 blocks of 10 ms, shared-mode endpoint):
  steady: both arms 243 events, 57600 frames, 120 callbacks, depth_max 480,  clock 57600
  bursty: both arms 243 events, 57600 frames, 120 callbacks, depth_max 2880, clock 57600

Two defects found and fixed in the diagnostic arm while building it: it did not advance its clock
during withholding gaps (making the bursty arm unfaithful by construction), and it mixed queue-depth
units between arms.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:04:08 +00:00
github manually merged commit 04bc596ef9 into gh-pr/1399/base 2026-11-26 23:04:11 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 10:31 UTC · original · edited 2026-11-24 10:33 UTC

Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T10:33:35.602947Z e607142 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@⁠codex review" or "@⁠codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 10:31 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1399#issuecomment-7128886924) · edited 2026-11-24 10:33 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"e60714288a1ba2e6142a9672053726d9a247c72c","has_any_findings":true,"has_unresolved_findings":true,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-24T10:33:35.602947Z">2026-11-24T10:33:35.602947Z</relative-time> | `e607142` | PR opened | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@⁠codex review" or "@⁠codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 10:33 UTC · original

P2 Badge Size the PCM storage in bytes

On any run that reaches the XAudio2 system arm, the 48 kHz stereo 16-bit plan allocates 960 bytes for a 480-frame block, while submit() advertises 1,920 bytes via AudioBytes. XAudio2 can therefore read beyond pcm_ for every queued buffer, so the system arm is not submitting silence and may play unrelated heap contents or fault; allocate bits / 8 bytes per sample as well.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 10:33 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1399#discussion_r4678682816) **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Size the PCM storage in bytes** On any run that reaches the XAudio2 system arm, the 48 kHz stereo 16-bit plan allocates 960 bytes for a 480-frame block, while `submit()` advertises 1,920 bytes via `AudioBytes`. XAudio2 can therefore read beyond `pcm_` for every queued buffer, so the system arm is not submitting silence and may play unrelated heap contents or fault; allocate `bits / 8` bytes per sample as well. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 10:33 UTC · original

P2 Badge Synchronize callback trace updates

When OnBufferEnd runs on XAudio2's processing thread, it updates this non-atomic count and events while run_plan reads trace().callbacks and the producer appends submit events. These unsynchronized accesses race, including concurrent std::vector::push_back calls, so the lifecycle comparison can be corrupted or crash; collect callback records through synchronized state and merge them on the main thread.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 10:33 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1399#discussion_r4678682827) **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Synchronize callback trace updates** When `OnBufferEnd` runs on XAudio2's processing thread, it updates this non-atomic count and `events` while `run_plan` reads `trace().callbacks` and the producer appends submit events. These unsynchronized accesses race, including concurrent `std::vector::push_back` calls, so the lifecycle comparison can be corrupted or crash; collect callback records through synchronized state and merge them on the main thread. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-24 10:41 UTC · original

I fixed the two review findings in 04bc596e. The silence buffer is sized in bytes and checked before submission. The callback only updates atomic completion state, and the test checks completion order and count separately from caller-side events, which can interleave differently on the system clock. A rejected submission or missing completion now fails the test. Windows Release ran both providers and passed startup_audio_provider on this revision. This is still a source-built voice control for #1145.

**@⁠R0Y00** on GitHub · 2026-11-24 10:41 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1399#issuecomment-7129110107) I fixed the two review findings in 04bc596e. The silence buffer is sized in bytes and checked before submission. The callback only updates atomic completion state, and the test checks completion order and count separately from caller-side events, which can interleave differently on the system clock. A rejected submission or missing completion now fails the test. Windows Release ran both providers and passed startup_audio_provider on this revision. This is still a source-built voice control for #1145.
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 10:33 UTC · original · reviewed

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e60714288a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@⁠codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@⁠codex address that feedback".

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 10:33 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1399#pullrequestreview-6037619479) · **reviewed** <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `e60714288a` <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@⁠codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@⁠codex address that feedback". </details>
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 10:40 UTC · original · reviewed

Dual-platform peer review of #1399 (e6071428):

Checks

  • git diff --check origin/main...HEAD: clean.
  • Linux: tests/bidi_controls_check.py passed (Checked 1148 tracked source, script and build/CI files: no bidirectional controls.).
  • Win2025 (x2w_pipe.py win2025 1399 --targets startup_audio_provider --regex '^startup_audio_provider$'):
    • Debug (--preset dev): builds cleanly (4.11s); startup_audio_provider skipped (exit 77) (1.96s) — no audio endpoint on the Windows Server 2025 VM.
    • Release (/O2, --preset release): builds cleanly (1.61s); startup_audio_provider skipped (exit 77) (1.88s).

Code audit (tests/startup_audio_provider.cpp)

  1. Buffer size mismatch in SystemVoice::prepare() / submit() (out-of-bounds read):
    • prepare() allocates pcm_.assign(block_frames * format_.channels, 0); (960 bytes for 480 frames * 2 channels), whereas submit() sets buffer.AudioBytes = frames * (format_.bits / 8) * format_.channels; (1920 bytes for 16-bit stereo). prepare() is missing * (format_.bits / 8).
  2. Data race between XAudio2 callback thread and main thread:
    • SystemVoice::OnBufferEnd() executes on XAudio2's audio thread and mutates trace_.callbacks and trace_.events.push_back({"callback", 0}) without synchronization, while run_plan() reads voice->trace().callbacks in a loop and submit()/start()/stop() push to trace_.events on the main thread.
  3. Minor cleanup / consistency notes:
    • SystemProvider::open() leaks engine_ if CreateMasteringVoice() fails, and main() exits early without calling diagnostic.close() when system.open() skips.
    • SystemVoice::state() overwrites trace_.clock_frames = out.played_frames, whereas DiagnosticVoice::advance() accumulates trace_.clock_frames += consumed.
**@⁠tedin7** on GitHub · 2026-11-24 10:40 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1399#pullrequestreview-6037712142) · **reviewed** Dual-platform peer review of #1399 (`e6071428`): ### Checks - `git diff --check origin/main...HEAD`: clean. - Linux: `tests/bidi_controls_check.py` passed (`Checked 1148 tracked source, script and build/CI files: no bidirectional controls.`). - Win2025 (`x2w_pipe.py win2025 1399 --targets startup_audio_provider --regex '^startup_audio_provider$'`): - **Debug (`--preset dev`)**: builds cleanly (`4.11s`); `startup_audio_provider` **skipped (exit 77)** (`1.96s`) — no audio endpoint on the Windows Server 2025 VM. - **Release (`/O2`, `--preset release`)**: builds cleanly (`1.61s`); `startup_audio_provider` **skipped (exit 77)** (`1.88s`). ### Code audit (`tests/startup_audio_provider.cpp`) 1. **Buffer size mismatch in `SystemVoice::prepare()` / `submit()` (out-of-bounds read):** - `prepare()` allocates `pcm_.assign(block_frames * format_.channels, 0);` (960 bytes for 480 frames * 2 channels), whereas `submit()` sets `buffer.AudioBytes = frames * (format_.bits / 8) * format_.channels;` (1920 bytes for 16-bit stereo). `prepare()` is missing `* (format_.bits / 8)`. 2. **Data race between XAudio2 callback thread and main thread:** - `SystemVoice::OnBufferEnd()` executes on XAudio2's audio thread and mutates `trace_.callbacks` and `trace_.events.push_back({"callback", 0})` without synchronization, while `run_plan()` reads `voice->trace().callbacks` in a loop and `submit()`/`start()`/`stop()` push to `trace_.events` on the main thread. 3. **Minor cleanup / consistency notes:** - `SystemProvider::open()` leaks `engine_` if `CreateMasteringVoice()` fails, and `main()` exits early without calling `diagnostic.close()` when `system.open()` skips. - `SystemVoice::state()` overwrites `trace_.clock_frames = out.played_frames`, whereas `DiagnosticVoice::advance()` accumulates `trace_.clock_frames += consumed`.
This discussion has been locked. Commenting is limited to contributors.
No description provided.