WIP: fix(input): broker gamepads outside the Windows mod sandbox #2016

Draft
snaildev99 wants to merge 1165 commits from snaildev99/Longshot:fix/windows-controller-broker into mod-api
Contributor

Summary

With the Mod API's Windows AppContainer enabled, SDL's native HID drivers cannot open controllers. Enabling WGI makes a PS4 and Switch Pro appear, but the reporter still gets no usable input. Disabling the sandbox restores input.

Keep the game confined and move SDL gamepad device access into the existing authenticated Windows broker. The game receives bounded snapshots for up to eight controllers and retains its existing mapping, deadzone, motion and input-merge logic. Sensor enable/disable and ordinary motor commands go back through the dedicated controller connection. No device paths, handles, raw HID reports, keyboard or mouse requests cross this interface.

This PR targets mod-api, as a focused contribution to #1958. It does not replace or duplicate that API proposal. See #2010. The earlier WGI-only patch branch is superseded by this implementation; WGI is not enabled by this patch.

Read host/pad_broker_windows.c and host/pad_broker.h first, then the routing in host/hos_sdl.c and the connection dispatch in host/broker_windows.c. The latter also makes the receive buffer private to each request: separate channel locks cannot protect a shared static buffer.

Testing

Tested: Windows 11 Pro 23H2, RTX 3090, NVIDIA 610.88, SDL 3.4.20; PS4 and Switch Pro connected simultaneously. The sandbox-off diagnostic worked, the WGI-only candidate did not, and the reporter confirmed the broker candidate works in actual gameplay. The confined game logged both real controller names through SDL via broker, with gyro capabilities. The final bounded headless startup also rendered frames successfully.

The game-tested local commit is 9ac1daf6; its controller implementation was carried onto API head 2749e506. All six changed controller/broker C/header files were byte-identical between that tested commit and the earlier PR head dd7027bf; those sources have changed since that comparison. Windows play was also recorded at c62410c0. The later API tree as a whole has not been rebuilt or played here.

  • The routing regression fails on API base 2749e506 for missing broker stick input, and passes here.
  • 15 targeted checks pass, with zero failures/skips: controller routing/state/startup, SDL diagnostics, Windows sandbox/framing, Steam filtering, gyro rearm, rumble refresh/mapping/HD fallback, stick rest, headless signals, SDL desktop size/monitor names/audio loading.
  • The state fixture compiles the real client/server and exercises two devices, SDL2 instance ID zero, hotplug, session ownership/release, malformed requests, motor bounds, sensor failures/rollback/recovery and clearing held input after a failed exchange.
  • The modified Windows game code was compiled and linked into the played runtime with llvm-mingw. The published Windows sandbox fixture also syntax-checks its Windows sources. GCC-named executables on this machine are Clang shims, not an independent GCC result.
  • An independent cold review covered ownership, threads and timing. Findings on stale input, SDL2 ID zero, sensor acknowledgment/rollback, rumble fallback and device-open timeout were addressed.
  • A broader strict-suite attempt was interrupted and included failures not yet compared against baseline. It is not a complete suite pass. This is why the review checklist remains incomplete.

Still to test:

  • Complete strict suite and baseline comparison of failures, plus Linux host build/independent GCC checks (by hand, contributor/CI).
  • Build and play this exact newer API tree (by hand).
  • Hotplug/reconnect, gyro aiming/rearming and ordinary rumble with physical devices; only gameplay input has been confirmed by the reporter (by hand). Trigger rumble is unavailable through the controller broker.
  • Xbox/Steam Input, SDL2, other Windows controllers and Linux non-regression (by hand/CI).
  • Interleaved input-latency, CPU/frame-time and memory measurements, including a slow Bluetooth open (by hand). Simulated time in the fixture does not test real pipe timeout behavior.

Measurements

Verdict: the observed controller-input failure is fixed on the reporter's Windows PC; performance and latency have not yet been measured sufficiently for readiness.

Baseline: the applicable baseline is the API branch, not main, because main does not contain this AppContainer path. The table compares the earlier WGI candidate to the broker implementation; the successful game run was at local 9ac1daf6, whose controller code matches PR head dd7027bf.

Observation Before: WGI candidate @ 8b6b7c9d After: played build @ 9ac1daf6
Devices opened in confined game 2 through WGI 2 through native SDL in broker
Reporter gameplay input Does not work Works
Device names / gyro capabilities PS4 and generic HID controller; no gyros advertised PS4 and Nintendo Switch Pro; gyros advertised

No FPS, latency, CPU or memory improvement is claimed. Matched interleaved performance measurements remain outstanding. The incremental final build took 28 seconds; this is operational build evidence, not a controlled build-speed comparison. No lifter, shader, renderer or build flags are changed.

Risks

This adds a bounded controller operation to the trusted broker. Existing AppContainer/job authentication is retained. One controller session owns at most eight native SDL handles; disconnect closes them. Requests are validated before device operations. Motor levels are 16-bit and durations capped at one second. Lost exchanges clear input. Reconnection is rate limited.

SDL device initialization/hotplug can block the controller poller; the five-second request timeout allows Bluetooth setup rather than repeatedly destroying newly opened devices. Its latency cost still needs measurement. Raw HD haptic effects are not transported; confined controllers select ordinary motor vibration. Other controller/Steam Input behavior needs hardware testing. Unconfined Windows and Linux retain native SDL. Existing HOS_SANDBOX=0 remains the diagnostic workaround; reverting this patch restores prior behavior. No save format, settings keys or cache format changes.

Checklist

Ready for review

  • One topic, on current mod-api rather than main because this fixes #1958; Conventional Commit title.
  • Tested on my own PC in the game, as Testing describes, with reporter confirmation.
  • mise run test passes (any failure that also fails on main is named). The prior attempt was interrupted; complete suite and baseline comparison remain pending.
  • Measured against main, or Measurements says why there is nothing to measure. This targets mod-api; performance/latency measurements remain pending.
  • No game files, build output or hand-edited generated files; third_party/ untouched; GPL-compatible authored code only.

When it applies

  • A fix: a game-free regression fails on the applicable API baseline and passes here.
  • A check under tests/ that reads changed source is updated, not weakened.
  • Host code builds on both Windows and Linux: Windows built; Linux pending.
  • Docs updated.
  • AI assistance recorded in commit trailers.

Ready to merge

  • Everything in Still to test has run, with results recorded.
  • Affected Tier 1 hardware is tested.
  • Approved in review, every comment answered.
  • CI passes on the head; applicable base and measurements remain current.
## Summary With the Mod API's Windows AppContainer enabled, SDL's native HID drivers cannot open controllers. Enabling WGI makes a PS4 and Switch Pro appear, but the reporter still gets no usable input. Disabling the sandbox restores input. Keep the game confined and move SDL gamepad device access into the existing authenticated Windows broker. The game receives bounded snapshots for up to eight controllers and retains its existing mapping, deadzone, motion and input-merge logic. Sensor enable/disable and ordinary motor commands go back through the dedicated controller connection. No device paths, handles, raw HID reports, keyboard or mouse requests cross this interface. This PR targets **mod-api**, as a focused contribution to #1958. It does not replace or duplicate that API proposal. See #2010. The earlier WGI-only patch branch is superseded by this implementation; WGI is not enabled by this patch. Read `host/pad_broker_windows.c` and `host/pad_broker.h` first, then the routing in `host/hos_sdl.c` and the connection dispatch in `host/broker_windows.c`. The latter also makes the receive buffer private to each request: separate channel locks cannot protect a shared static buffer. ## Testing **Tested:** Windows 11 Pro 23H2, RTX 3090, NVIDIA 610.88, SDL 3.4.20; PS4 and Switch Pro connected simultaneously. The sandbox-off diagnostic worked, the WGI-only candidate did not, and the reporter confirmed the broker candidate works in actual gameplay. The confined game logged both real controller names through SDL via broker, with gyro capabilities. The final bounded headless startup also rendered frames successfully. The game-tested local commit is `9ac1daf6`; its controller implementation was carried onto API head `2749e506`. All six changed controller/broker C/header files were byte-identical between that tested commit and the earlier PR head `dd7027bf`; those sources have changed since that comparison. Windows play was also recorded at `c62410c0`. The later API tree as a whole has not been rebuilt or played here. - The routing regression fails on API base `2749e506` for missing broker stick input, and passes here. - 15 targeted checks pass, with zero failures/skips: controller routing/state/startup, SDL diagnostics, Windows sandbox/framing, Steam filtering, gyro rearm, rumble refresh/mapping/HD fallback, stick rest, headless signals, SDL desktop size/monitor names/audio loading. - The state fixture compiles the real client/server and exercises two devices, SDL2 instance ID zero, hotplug, session ownership/release, malformed requests, motor bounds, sensor failures/rollback/recovery and clearing held input after a failed exchange. - The modified Windows game code was compiled and linked into the played runtime with llvm-mingw. The published Windows sandbox fixture also syntax-checks its Windows sources. GCC-named executables on this machine are Clang shims, not an independent GCC result. - An independent cold review covered ownership, threads and timing. Findings on stale input, SDL2 ID zero, sensor acknowledgment/rollback, rumble fallback and device-open timeout were addressed. - A broader strict-suite attempt was interrupted and included failures not yet compared against baseline. It is **not** a complete suite pass. This is why the review checklist remains incomplete. **Still to test:** - Complete strict suite and baseline comparison of failures, plus Linux host build/independent GCC checks (by hand, contributor/CI). - Build and play this exact newer API tree (by hand). - Hotplug/reconnect, gyro aiming/rearming and ordinary rumble with physical devices; only gameplay input has been confirmed by the reporter (by hand). Trigger rumble is unavailable through the controller broker. - Xbox/Steam Input, SDL2, other Windows controllers and Linux non-regression (by hand/CI). - Interleaved input-latency, CPU/frame-time and memory measurements, including a slow Bluetooth open (by hand). Simulated time in the fixture does not test real pipe timeout behavior. ## Measurements **Verdict:** the observed controller-input failure is fixed on the reporter's Windows PC; performance and latency have not yet been measured sufficiently for readiness. Baseline: the applicable baseline is the API branch, not main, because main does not contain this AppContainer path. The table compares the earlier WGI candidate to the broker implementation; the successful game run was at local `9ac1daf6`, whose controller code matches PR head `dd7027bf`. | Observation | Before: WGI candidate @ 8b6b7c9d | After: played build @ 9ac1daf6 | |---|---|---| | Devices opened in confined game | 2 through WGI | 2 through native SDL in broker | | Reporter gameplay input | Does not work | Works | | Device names / gyro capabilities | PS4 and generic HID controller; no gyros advertised | PS4 and Nintendo Switch Pro; gyros advertised | No FPS, latency, CPU or memory improvement is claimed. Matched interleaved performance measurements remain outstanding. The incremental final build took 28 seconds; this is operational build evidence, not a controlled build-speed comparison. No lifter, shader, renderer or build flags are changed. ## Risks This adds a bounded controller operation to the trusted broker. Existing AppContainer/job authentication is retained. One controller session owns at most eight native SDL handles; disconnect closes them. Requests are validated before device operations. Motor levels are 16-bit and durations capped at one second. Lost exchanges clear input. Reconnection is rate limited. SDL device initialization/hotplug can block the controller poller; the five-second request timeout allows Bluetooth setup rather than repeatedly destroying newly opened devices. Its latency cost still needs measurement. Raw HD haptic effects are not transported; confined controllers select ordinary motor vibration. Other controller/Steam Input behavior needs hardware testing. Unconfined Windows and Linux retain native SDL. Existing `HOS_SANDBOX=0` remains the diagnostic workaround; reverting this patch restores prior behavior. No save format, settings keys or cache format changes. ## Checklist ### Ready for review - [x] One topic, on current `mod-api` rather than `main` because this fixes #1958; Conventional Commit title. - [x] Tested on my own PC in the game, as Testing describes, with reporter confirmation. - [ ] `mise run test` passes (any failure that also fails on `main` is named). The prior attempt was interrupted; complete suite and baseline comparison remain pending. - [ ] Measured against `main`, or Measurements says why there is nothing to measure. This targets mod-api; performance/latency measurements remain pending. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; GPL-compatible authored code only. ### When it applies - [x] A fix: a game-free regression fails on the applicable API baseline and passes here. - [x] A check under `tests/` that reads changed source is updated, not weakened. - [ ] Host code builds on both Windows and Linux: Windows built; Linux pending. - [x] Docs updated. - [x] AI assistance recorded in commit trailers. ### Ready to merge - [ ] Everything in Still to test has run, with results recorded. - [ ] Affected Tier 1 hardware is tested. - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; applicable base and measurements remain current.
Assisted-by: OpenAI Codex

Co-Authored-By: Codex <[email protected]>
fix(input): broker Windows sandbox controllers through native SDL
Some checks failed
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
Website / Website on Cloudflare (pull_request) Has been cancelled
dd7027bfbb
Assisted-by: OpenAI Codex

Co-Authored-By: Codex <[email protected]>
Author
Contributor

Tested in game: Windows 11 Pro 23H2, RTX 3090, NVIDIA 610.88, SDL 3.4.20: PS4 and Switch Pro connected. Confined game opens both through the native SDL broker; reporter confirms gameplay input works. Played local implementation 9ac1daf6; the six changed controller/broker source files are identical at PR head dd7027bf. Newer API tree as a whole, physical gyro/rumble/reconnect, and performance checks remain pending.

Tested in game: Windows 11 Pro 23H2, RTX 3090, NVIDIA 610.88, SDL 3.4.20: PS4 and Switch Pro connected. Confined game opens both through the native SDL broker; reporter confirms gameplay input works. Played local implementation 9ac1daf6; the six changed controller/broker source files are identical at PR head dd7027bf. Newer API tree as a whole, physical gyro/rumble/reconnect, and performance checks remain pending.
Author
Contributor

Clarified the API/WGI measurement baseline and preserved the outstanding validation checklist; reporter-confirmed gameplay and 15 passing targeted checks are recorded.

Clarified the API/WGI measurement baseline and preserved the outstanding validation checklist; reporter-confirmed gameplay and 15 passing targeted checks are recorded.
BeanBot requested changes 2026-11-21 05:58:09 +00:00
Dismissed
BeanBot left a comment

Recommendation: Request changes. The reporter regained gameplay input on two controllers, but a slow broker request can leave the game acting on a held button or stick for five seconds, and a quick reconnect can leave gyro disabled. The new state fixture also fails to compile on Linux because it enables GNU declarations after the system headers have already been included.

Moves Windows AppContainer gamepad access into the existing broker and keeps bindings, deadzones, and input merging in the game. This restores input on the reported setup while keeping the sandbox enabled. The cost is a synchronous pipe exchange in the controller poll loop, a second SDL instance, and reduced haptics support.

@fix will do (17)

  1. L1 host/broker_windows.c:208: The pipe wait blocks the poller that publishes the game's input. (more on the line)
  2. L2 host/pad_broker_windows.c:46: A failed exchange clears the samples but keeps the local handle IDs, which can match again when a new session reopens the same SDL instance before the one-second client scan. (more on the line)
  3. L3 host/pad_sdl.c:236: The sensor failure path can leave one sensor enabled. A device can accept accelerometer enable, reject gyro enable, then reject the attempted accelerometer disable. The client ignores the rollback result and sets motion_on to zero, so switching motion off can leave the accelerometer running until the pad closes. Reconcile both sensors from the acknowledged state and retry a failed disable. Cover a partial enable and a failed rollback in the actual motion policy test. The state fixture currently makes both enables fail together and calls rollback itself.
  4. L4 host/pad_sdl.c:728: Confined startup still starts the Switch 2 USB worker inside the AppContainer, while pads_start skips local joystick initialization and all pad enumeration goes to the broker. A Switch 2 Pro using Longshot's USB driver cannot supply input through this path, even if its HID open succeeds, because its virtual SDL gamepad is local to the game process. Route the input side of that driver through the broker with an explicit lifetime, or gate off the unusable worker and explicitly settle the support loss. Include the USB model in the startup and device checks.
  5. L5 host/pad_broker_windows.c:136: SDL is initialized on the first pipe worker and kept initialized after that worker exits. (more on the line)
  6. L6 host/broker_windows.c:733: The dedicated controller role exists only on the client side. (more on the line)
  7. L7 host/hos_sdl.c:1088: The Xbox trigger operation added to the wire cannot be reached from confined gameplay. (more on the line)
  8. L8 tests/test_pad_broker_state.py:157: The Linux fixture includes stdio before broker_frame.h defines _GNU_SOURCE. (more on the line)
  9. L9 (minor) host/broker_windows.c:208: The exact reply-size check uses a clipped length. (more on the line)
  10. L10 (minor) host/broker_frame.h:56: The shared parser now accepts the Windows-only controller message on Linux, where serve has no matching case and sends no reply. (more on the line)
  11. L11 (minor) host/pad_broker_windows.c:206: A UTF-8 device or custom mapping name that crosses the 127-byte cutoff in the middle of a character is copied to the log and Controls as invalid UTF-8. (more on the line)
  12. L12 (minor) host/broker_windows.c:200: Backoff covers opening the pipe but excludes controller service failures. (more on the line)
  13. L13 (minor) host/pad_sdl.c:117: The route treats any AppContainer as one with a Longshot controller broker. (more on the line)
  14. L14 (minor) tests/test_pad_broker_route.py:30: The routing fixture substitutes its own PAD_REMOTE macro, so it still passes if the production macro's Windows predicate is broken. (more on the line)
  15. L15 (minor) docs/dev/reference/sandbox.md:242: The sandbox page still says Windows has never run, while this PR records a successful confined run. Update it with the verified pads and the specific untested cases. Also document the basic-motor fallback in the input and switch references, including the loss of wired DualSense fine haptics and the limits of HOS_HD_RUMBLE and HOS_RUMBLE_BACKEND in confined play. The Controls status should attribute the fallback to the sandbox instead of telling a player with RenHDrum installed that the library is missing.
  16. L16 (minor): The gameplay table labels the after column dd7027bf, although the full tree played was 9ac1daf6. Label the gameplay run with the commit that ran and separate the API-base fixture result from the WGI comparison. Record the exact-head Windows play result and the strict-suite and lint results as they become available.
  17. L17 (its part an edit can do) host/broker_windows.c:124: Use completion-driven pipe I/O for the controller path, batch sensor changes, and move slow opens out of the input publication path. Send device metadata on change or limit the reply to populated slots.

For the author (1) (a run, a measurement or a decision)

  • L17 host/broker_windows.c:124: The hot path adds a synchronous round trip before each poll, with a two-millisecond sleep whenever the first peek misses the reply. It also transfers a full eight-pad snapshot with no controllers attached. Measure matched, repeated input and rumble latency, poll jitter, CPU, frame times and broker working set on the exact build. Include a working native SDL comparison for latency and a Bluetooth hotplug while another pad is active.

Checks: Still running: Guide screenshots / Guide images and local UI source review (pull_request), Third-party parts / As their notes say (pull_request), Third-party parts / The same as upstream (pull_request), Website / Website on Cloudflare (pull_request).

More: does it help, other systems, switches, what was read

Does it help: Yes for the reported input failure. On Windows 11 with SDL 3.4.20, the WGI candidate enumerated two pads with zero usable gameplay input. The reporter could play with the broker candidate, which enumerated both pads and advertised gyro. The played commit was 9ac1daf6. The author reports that its six controller and broker source files match dd7027bf, and that the routing fixture fails on API base 2749e506 and passes on head. The exact integrated build, physical gyro and rumble, and input latency and resource costs remain unproven.

Other systems: Confined Windows Xbox fallback depends on the SDL controller count, and Steam Input, SDL2, physical hotplug and restart still need validation. Switch 2 USB has a separate driver and is affected directly. Linux and unconfined Windows keep native controller polling. Linux broker framing changes because the type range is shared. The Windows receive-buffer change also affects the main and performance-report connections. The diff leaves the renderer, audio, keyboard and mouse routes, saves, settings formats, and build flags alone. The reported headless run rendered frames on NVIDIA. Affected Tier 1 AMD and Linux/Steam Deck coverage remains pending.

Switches: No new or removed switches. HOS_HD_RUMBLE and HOS_RUMBLE_BACKEND still default to on where supported and auto respectively, but confined Windows forces basic motors for both. Update their switch table and player docs and validate the fallback on affected pads. HOS_SWITCH2 still defaults to on over USB on Windows, but the confined route bypasses its virtual pad. HOS_NO_SDL still defaults to SDL on, HOS_SDL_VERSION still prefers SDL3 with SDL2 fallback, and HOS_XINPUT still defaults to fallback only. HOS_SANDBOX still defaults to confinement with a script mod enabled and has the existing diagnostic override.

Reviewed: dd7027bfbb against 2749e50672: Read the diff and both commit messages, AGENTS.md, CONTRIBUTING.md, docs/dev/standards.md, the Forgejo template, and all 12 changed files. Traced callers and dependencies in sandbox startup, Linux broker dispatch, native SDL loading, Switch 2, HID input, vibration, Steam filtering, build source discovery, and test discovery. Reviewed the supplied comments and CI status. No docs/review-checklist.md or adjacent Tooling checkout was present. The played and WGI candidate commits were unavailable locally, so their comparison and the reported runs rely on the supplied notes. No translations or generated files changed.; nothing run (a code review).

Checked and fine:

  • The two commits are on one topic and both carry AI assistance trailers. The diff contains source, documentation and authored fixtures, with no game-derived data, vendored edits or generated changes.
  • The Windows parser bounds the frame, request validation precedes SDL calls, motor fields are bounded, and the existing AppContainer SID and job authentication still applies. The operation carries no raw device paths, handles or reports.
  • The private receive buffer removes sharing across separate channel locks. Session allocation failure releases the ownership flag, and normal disconnect closes the session's open pads.
  • The SDL2 instance ID zero case is represented by a nonzero wire ID. Linux compiles out remote SDL routing, and host build source discovery includes the new translation unit. The renderer and Mod API interfaces did not change.

Testing: Read-only review. The author reports 15 targeted passes and a played Windows candidate. The strict suite was interrupted, the exact newer API tree has not been played, and Linux GCC and physical reconnect, motion, rumble, Xbox and Steam Input verification remain pending. Four CI checks were still running, with no head-only failures reported.

Overlaps and merge order: This builds on the mod-api work for #1958 and addresses #2010. Review it on mod-api and include it before that branch merges to main. The earlier WGI-only candidate is superseded. The PR is reported unmergeable, and the supplied context gives no conflict details.


Automated code review by BeanBot (gpt-6.2-sol), on the pull request's opening. Nothing was run; a maintainer decides.

**Recommendation: Request changes.** The reporter regained gameplay input on two controllers, but a slow broker request can leave the game acting on a held button or stick for five seconds, and a quick reconnect can leave gyro disabled. The new state fixture also fails to compile on Linux because it enables GNU declarations after the system headers have already been included. Moves Windows AppContainer gamepad access into the existing broker and keeps bindings, deadzones, and input merging in the game. This restores input on the reported setup while keeping the sandbox enabled. The cost is a synchronous pipe exchange in the controller poll loop, a second SDL instance, and reduced haptics support. **`@fix` will do (17)** 1. **L1** `host/broker_windows.c:208`: The pipe wait blocks the poller that publishes the game's input. (more on the line) 2. **L2** `host/pad_broker_windows.c:46`: A failed exchange clears the samples but keeps the local handle IDs, which can match again when a new session reopens the same SDL instance before the one-second client scan. (more on the line) 3. **L3** `host/pad_sdl.c:236`: The sensor failure path can leave one sensor enabled. A device can accept accelerometer enable, reject gyro enable, then reject the attempted accelerometer disable. The client ignores the rollback result and sets motion_on to zero, so switching motion off can leave the accelerometer running until the pad closes. Reconcile both sensors from the acknowledged state and retry a failed disable. Cover a partial enable and a failed rollback in the actual motion policy test. The state fixture currently makes both enables fail together and calls rollback itself. 4. **L4** `host/pad_sdl.c:728`: Confined startup still starts the Switch 2 USB worker inside the AppContainer, while pads_start skips local joystick initialization and all pad enumeration goes to the broker. A Switch 2 Pro using Longshot's USB driver cannot supply input through this path, even if its HID open succeeds, because its virtual SDL gamepad is local to the game process. Route the input side of that driver through the broker with an explicit lifetime, or gate off the unusable worker and explicitly settle the support loss. Include the USB model in the startup and device checks. 5. **L5** `host/pad_broker_windows.c:136`: SDL is initialized on the first pipe worker and kept initialized after that worker exits. (more on the line) 6. **L6** `host/broker_windows.c:733`: The dedicated controller role exists only on the client side. (more on the line) 7. **L7** `host/hos_sdl.c:1088`: The Xbox trigger operation added to the wire cannot be reached from confined gameplay. (more on the line) 8. **L8** `tests/test_pad_broker_state.py:157`: The Linux fixture includes stdio before broker_frame.h defines _GNU_SOURCE. (more on the line) 9. **L9** (minor) `host/broker_windows.c:208`: The exact reply-size check uses a clipped length. (more on the line) 10. **L10** (minor) `host/broker_frame.h:56`: The shared parser now accepts the Windows-only controller message on Linux, where serve has no matching case and sends no reply. (more on the line) 11. **L11** (minor) `host/pad_broker_windows.c:206`: A UTF-8 device or custom mapping name that crosses the 127-byte cutoff in the middle of a character is copied to the log and Controls as invalid UTF-8. (more on the line) 12. **L12** (minor) `host/broker_windows.c:200`: Backoff covers opening the pipe but excludes controller service failures. (more on the line) 13. **L13** (minor) `host/pad_sdl.c:117`: The route treats any AppContainer as one with a Longshot controller broker. (more on the line) 14. **L14** (minor) `tests/test_pad_broker_route.py:30`: The routing fixture substitutes its own PAD_REMOTE macro, so it still passes if the production macro's Windows predicate is broken. (more on the line) 15. **L15** (minor) `docs/dev/reference/sandbox.md:242`: The sandbox page still says Windows has never run, while this PR records a successful confined run. Update it with the verified pads and the specific untested cases. Also document the basic-motor fallback in the input and switch references, including the loss of wired DualSense fine haptics and the limits of HOS_HD_RUMBLE and HOS_RUMBLE_BACKEND in confined play. The Controls status should attribute the fallback to the sandbox instead of telling a player with RenHDrum installed that the library is missing. 16. **L16** (minor): The gameplay table labels the after column dd7027bf, although the full tree played was 9ac1daf6. Label the gameplay run with the commit that ran and separate the API-base fixture result from the WGI comparison. Record the exact-head Windows play result and the strict-suite and lint results as they become available. 17. **L17** (its part an edit can do) `host/broker_windows.c:124`: Use completion-driven pipe I/O for the controller path, batch sensor changes, and move slow opens out of the input publication path. Send device metadata on change or limit the reply to populated slots. **For the author (1)** (a run, a measurement or a decision) - **L17** `host/broker_windows.c:124`: The hot path adds a synchronous round trip before each poll, with a two-millisecond sleep whenever the first peek misses the reply. It also transfers a full eight-pad snapshot with no controllers attached. Measure matched, repeated input and rumble latency, poll jitter, CPU, frame times and broker working set on the exact build. Include a working native SDL comparison for latency and a Bluetooth hotplug while another pad is active. **Checks:** Still running: `Guide screenshots / Guide images and local UI source review (pull_request)`, `Third-party parts / As their notes say (pull_request)`, `Third-party parts / The same as upstream (pull_request)`, `Website / Website on Cloudflare (pull_request)`. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Yes for the reported input failure. On Windows 11 with SDL 3.4.20, the WGI candidate enumerated two pads with zero usable gameplay input. The reporter could play with the broker candidate, which enumerated both pads and advertised gyro. The played commit was 9ac1daf6. The author reports that its six controller and broker source files match dd7027bf, and that the routing fixture fails on API base 2749e506 and passes on head. The exact integrated build, physical gyro and rumble, and input latency and resource costs remain unproven. **Other systems:** Confined Windows Xbox fallback depends on the SDL controller count, and Steam Input, SDL2, physical hotplug and restart still need validation. Switch 2 USB has a separate driver and is affected directly. Linux and unconfined Windows keep native controller polling. Linux broker framing changes because the type range is shared. The Windows receive-buffer change also affects the main and performance-report connections. The diff leaves the renderer, audio, keyboard and mouse routes, saves, settings formats, and build flags alone. The reported headless run rendered frames on NVIDIA. Affected Tier 1 AMD and Linux/Steam Deck coverage remains pending. **Switches:** No new or removed switches. HOS_HD_RUMBLE and HOS_RUMBLE_BACKEND still default to on where supported and auto respectively, but confined Windows forces basic motors for both. Update their switch table and player docs and validate the fallback on affected pads. HOS_SWITCH2 still defaults to on over USB on Windows, but the confined route bypasses its virtual pad. HOS_NO_SDL still defaults to SDL on, HOS_SDL_VERSION still prefers SDL3 with SDL2 fallback, and HOS_XINPUT still defaults to fallback only. HOS_SANDBOX still defaults to confinement with a script mod enabled and has the existing diagnostic override. **Reviewed:** dd7027bfbb30 against 2749e50672bb: Read the diff and both commit messages, AGENTS.md, CONTRIBUTING.md, docs/dev/standards.md, the Forgejo template, and all 12 changed files. Traced callers and dependencies in sandbox startup, Linux broker dispatch, native SDL loading, Switch 2, HID input, vibration, Steam filtering, build source discovery, and test discovery. Reviewed the supplied comments and CI status. No docs/review-checklist.md or adjacent Tooling checkout was present. The played and WGI candidate commits were unavailable locally, so their comparison and the reported runs rely on the supplied notes. No translations or generated files changed.; nothing run (a code review). **Checked and fine:** - The two commits are on one topic and both carry AI assistance trailers. The diff contains source, documentation and authored fixtures, with no game-derived data, vendored edits or generated changes. - The Windows parser bounds the frame, request validation precedes SDL calls, motor fields are bounded, and the existing AppContainer SID and job authentication still applies. The operation carries no raw device paths, handles or reports. - The private receive buffer removes sharing across separate channel locks. Session allocation failure releases the ownership flag, and normal disconnect closes the session's open pads. - The SDL2 instance ID zero case is represented by a nonzero wire ID. Linux compiles out remote SDL routing, and host build source discovery includes the new translation unit. The renderer and Mod API interfaces did not change. **Testing:** Read-only review. The author reports 15 targeted passes and a played Windows candidate. The strict suite was interrupted, the exact newer API tree has not been played, and Linux GCC and physical reconnect, motion, rumble, Xbox and Steam Input verification remain pending. Four CI checks were still running, with no head-only failures reported. **Overlaps and merge order:** This builds on the mod-api work for #1958 and addresses #2010. Review it on mod-api and include it before that branch merges to main. The earlier WGI-only candidate is superseded. The PR is reported unmergeable, and the supplied context gives no conflict details. </details> --- <sub>Automated code review by BeanBot (gpt-6.2-sol), on the pull request's opening. Nothing was run; a maintainer decides.</sub>
@ -54,3 +54,3 @@
Downloads, 1 the home folder), u8 0, the folder it was saved in: copied there, the folder
opened when show (broker_download_reply_put) */
BROKER_TYPE_LAST = 10,
BROKER_PADS = 11, /* Windows only: bounded controller snapshot and motor commands (pad_broker.h) */
Member

L10 (minor): The shared parser now accepts the Windows-only controller message on Linux, where serve has no matching case and sends no reply. An unsupported request that previously caused the channel to close now leaves the peer waiting. Reject this type on the Linux dispatch path and cover the platform distinction in framing tests.

**L10** (minor): The shared parser now accepts the Windows-only controller message on Linux, where serve has no matching case and sends no reply. An unsupported request that previously caused the channel to close now leaves the peer waiting. Reject this type on the Linux dispatch path and cover the platform distinction in framing tests.
@ -190,0 +197,4 @@
static SRWLOCK lock = SRWLOCK_INIT;
static ULONGLONG retry;
size_t n = 0;
if (pads == INVALID_HANDLE_VALUE) {
Member

L12 (minor): Backoff covers opening the pipe but excludes controller service failures. If the old worker still holds the session after a timeout, the new connection receives BROKER_E_BUSY on every poll. SDL startup failure behaves similarly. Apply backoff to acquisition failures and log a bounded diagnostic so players can distinguish a failed broker from a working broker with no attached pads.

**L12** (minor): Backoff covers opening the pipe but excludes controller service failures. If the old worker still holds the session after a timeout, the new connection receives BROKER_E_BUSY on every poll. SDL startup failure behaves similarly. Apply backoff to acquisition failures and log a bounded diagnostic so players can distinguish a failed broker from a working broker with no attached pads.
@ -190,0 +205,4 @@
/* Opening Bluetooth devices can involve several 100 ms exchanges. The
poller's device scan can take that long locally too; don't continually
tear down a newly opened device before its first snapshot is ready. */
return request_in(&pads, &lock, BROKER_PADS, payload, sizeof *payload, out, sizeof *out, &n, 5000) == BROKER_OK && n == sizeof *out;
Member

L1: The pipe wait blocks the poller that publishes the game's input. Plugging in a slow Bluetooth pad while holding forward on an already open pad can leave forward held in the game after the player releases it. A sensor round trip inside motion_poll can also fail after the poll has accumulated buttons and still publish those pre-failure values. Give the game a short freshness limit for published input and motion, and keep slow device work and pipe waits outside publication. Exercise the public input reader with a held sample, a delayed reply and a lost reply.

**L1**: The pipe wait blocks the poller that publishes the game's input. Plugging in a slow Bluetooth pad while holding forward on an already open pad can leave forward held in the game after the player releases it. A sensor round trip inside motion_poll can also fail after the poll has accumulated buttons and still publish those pre-failure values. Give the game a short freshness limit for published input and motion, and keep slow device work and pipe waits outside publication. Exercise the public input reader with a held sample, a delayed reply and a lost reply.
Member

L9 (minor): The exact reply-size check uses a clipped length. request_in sets n to the number of bytes copied, so a snapshot with trailing bytes passes. The client also trusts the name to be NUL-terminated and later passes it to string functions. Check the frame's actual reply length and validate the snapshot before publishing it. Cover oversized replies and unterminated names.

**L9** (minor): The exact reply-size check uses a clipped length. request_in sets n to the number of bytes copied, so a snapshot with trailing bytes passes. The client also trusts the name to be NUL-terminated and later passes it to string functions. Check the frame's actual reply length and validate the snapshot before publishing it. Cover oversized replies and unterminated names.
@ -707,6 +730,10 @@ static DWORD WINAPI client_thread(void *arg) {
if (r == BROKER_OK) reply_handle(cl->pipe, f.type, given);
else reply(cl->pipe, f.type, r, NULL, 0);
break;
case BROKER_PADS:
Member

L6: The dedicated controller role exists only on the client side. Any authenticated job client, including the crash helper, can claim the single controller session on an ordinary connection and hold it for the lifetime of that connection. Bind controller access to an explicitly established game-owned channel with a restart handoff, and reject controller requests on the ordinary and helper channels.

**L6**: The dedicated controller role exists only on the client side. Any authenticated job client, including the crash helper, can claim the single controller session on an ordinary connection and hold it for the lifetime of that connection. Bind controller access to an explicitly established game-owned channel with a restart handoff, and reject controller requests on the ordinary and helper channels.
@ -1070,6 +1086,7 @@ int hos_sdl_pad_wireless(void *pad) {
}
/* an Xbox One or Series pad's trigger motors; 1 when sent */
int hos_sdl_pad_rumble_triggers(void *pad, uint16_t left, uint16_t right, uint32_t ms) {
Member

L7: The Xbox trigger operation added to the wire cannot be reached from confined gameplay. Trigger output comes from the RenHDrum four-motor path, which the confined branch disables. The wrapper would also report success for a queued command that SDL later rejects. Either wire and acknowledge a supported trigger path with a gameplay-level test, or remove the unused broker operation and correct the feature claims.

**L7**: The Xbox trigger operation added to the wire cannot be reached from confined gameplay. Trigger output comes from the RenHDrum four-motor path, which the confined branch disables. The wrapper would also report success for a queued command that SDL later rejects. Either wire and acknowledge a supported trigger path with a gameplay-level test, or remove the unused broker operation and correct the feature claims.
@ -0,0 +43,4 @@
memset(&pending, 0, sizeof pending);
latest = got;
for (int i = 0; i < BROKER_PADS_MAX; i++) {
const BrokerPadState *state = handles[i].id ? find_pad(handles[i].id) : NULL;
Member

L2: A failed exchange clears the samples but keeps the local handle IDs, which can match again when a new session reopens the same SDL instance before the one-second client scan. The game can keep motion_on set even though the new server session starts with both sensors off. The neutral placeholder can also satisfy stick rest detection for a stick that never physically centered. Invalidate local pad state on session loss, reconcile attachments before processing the next sample, and test reconnect with the same SDL ID and device-side sensors reset.

**L2**: A failed exchange clears the samples but keeps the local handle IDs, which can match again when a new session reopens the same SDL instance before the one-second client scan. The game can keep motion_on set even though the new server session starts with both sensors off. The neutral placeholder can also satisfy stick rest detection for a stick that never physically centered. Invalidate local pad state on session loss, reconcile attachments before processing the next sample, and test reconnect with the same SDL ID and device-side sensors reset.
@ -0,0 +133,4 @@
if (steam_pads_without_valve(getenv("SDL_GAMECONTROLLER_IGNORE_DEVICES"), ignore, sizeof ignore) > 0)
hos_sdl_hint_override("SDL_GAMECONTROLLER_IGNORE_DEVICES", ignore);
}
initialized = hos_sdl_init(HOS_SDL_GAMEPAD);
Member

L5: SDL is initialized on the first pipe worker and kept initialized after that worker exits. A reconnect then uses the same subsystem from a new worker, while Windows backends can own thread-affine resources. SDL thread-local allocations on these Win32 workers also lack an SDL cleanup path. Give SDL a stable owner with the required event handling and matched shutdown, or pair initialization, teardown and TLS cleanup on each session's owner. Test teardown and reconnect with the real Windows backend. Ensure a driver call that stalls cannot keep the launcher waiting indefinitely through live_clients after the game exits.

**L5**: SDL is initialized on the first pipe worker and kept initialized after that worker exits. A reconnect then uses the same subsystem from a new worker, while Windows backends can own thread-affine resources. SDL thread-local allocations on these Win32 workers also lack an SDL cleanup path. Give SDL a stable owner with the required event handling and matched shutdown, or pair initialization, teardown and TLS cleanup on each session's owner. Test teardown and reconnect with the real Windows backend. Ensure a driver call that stalls cannot keep the launcher waiting indefinitely through live_clients after the game exits.
@ -0,0 +203,4 @@
v->enabled = s->enabled[i];
const uint64_t steam = hos_sdl_pad_steam_handle(p);
v->steam[0] = (uint32_t)steam; v->steam[1] = (uint32_t)(steam >> 32);
snprintf(v->name, sizeof v->name, "%s", hos_sdl_pad_name(p));
Member

L11 (minor): A UTF-8 device or custom mapping name that crosses the 127-byte cutoff in the middle of a character is copied to the log and Controls as invalid UTF-8. Cut at a whole character as the SDL text-event code does, and test a multibyte name at the limit.

**L11** (minor): A UTF-8 device or custom mapping name that crosses the 127-byte cutoff in the middle of a character is copied to the log and Controls as invalid UTF-8. Cut at a whole character as the SDL text-event code does, and test a multibyte name at the limit.
host/pad_sdl.c Outdated
@ -110,0 +114,4 @@
/* Device access belongs to the broker. WGI can enumerate a Switch Pro in an
AppContainer without delivering its input; do not start competing local
controller backends here. hos_sdl.c routes the poller's calls to the broker. */
if (hos_sandbox_confined()) {
Member

L13 (minor): The route treats any AppContainer as one with a Longshot controller broker. The existing sandbox startup explicitly supports externally created AppContainers without that broker. A pad accessible in such a container now loses native SDL input and the game silently retries a missing pipe. Select the controller route from broker ownership and capability at startup, preserving native SDL where the external container permits it.

**L13** (minor): The route treats any AppContainer as one with a Longshot controller broker. The existing sandbox startup explicitly supports externally created AppContainers without that broker. A pad accessible in such a container now loses native SDL input and the game silently retries a missing pipe. Select the controller route from broker ownership and capability at startup, preserving native SDL where the external container permits it.
@ -0,0 +27,4 @@
static int confined, native_calls;
static int16_t native_axis(void *pad, int axis) { (void)pad; (void)axis; native_calls++; return 0; }
#define CALL(type, fn) native_axis
#define PAD_REMOTE(value) do { if (confined) return (value); } while (0)
Member

L14 (minor): The routing fixture substitutes its own PAD_REMOTE macro, so it still passes if the production macro's Windows predicate is broken. Compile the real macro with a stand-in hos_pad_broker_remote and exercise both native and broker reads. The state fixture should also set or clear SDL_GAMECONTROLLER_IGNORE_DEVICES explicitly before exercising broker startup.

**L14** (minor): The routing fixture substitutes its own PAD_REMOTE macro, so it still passes if the production macro's Windows predicate is broken. Compile the real macro with a stand-in hos_pad_broker_remote and exercise both native and broker reads. The state fixture should also set or clear SDL_GAMECONTROLLER_IGNORE_DEVICES explicitly before exercising broker startup.
@ -0,0 +154,4 @@
with tempfile.TemporaryDirectory(prefix='pad-broker-state-') as tmp:
c, exe = Path(tmp) / 'check.c', Path(tmp) / 'check.exe'
c.write_text(PRELUDE + prototypes + body + MAIN, encoding='utf-8')
subprocess.run([args.cc, '-std=c11', '-Wall', '-Wextra', '-Werror', '-I' + str(ROOT / 'host'), str(c), '-o', str(exe)], check=True)
Member

L8: The Linux fixture includes stdio before broker_frame.h defines _GNU_SOURCE. On glibc, struct ucred and SCM_CREDENTIALS are then unavailable in broker_recv. Define _GNU_SOURCE before any system header or pass it in the compiler arguments as the sandbox fixture does. Verify with Linux GCC and Clang.

**L8**: The Linux fixture includes stdio before broker_frame.h defines _GNU_SOURCE. On glibc, struct ucred and SCM_CREDENTIALS are then unavailable in broker_recv. Define _GNU_SOURCE before any system header or pass it in the compiler arguments as the sandbox fixture does. Verify with Linux GCC and Clang.
Owner
@fix
fix(broker): validate controller snapshots and framing
Some checks failed
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 18s
Third-party parts / As their notes say (pull_request) Successful in 21s
PR description / Description follows the template (pull_request_target) Successful in 2m26s
265e73bda6
As the review on #2016 asked.
Member

I changed this pull request where an edit could (the rest needs runs, measurements or decisions): the new head is 265e73bda6. It was already up to date with mod-api. I edited the pull request's description too (1 edit).

Changed

  • Linux controller-message rejection: host/broker_frame.h:408 rejects controller requests on Linux; tests/test_broker_frame.py:156 covers the shared parser and Linux receive distinction. Tests were not run.
  • UTF-8 controller names: host/pad_broker_windows.c:206 truncates names at a character boundary; tests/test_pad_broker_state.py:92 covers a multibyte character at the limit. Tests were not run.
  • Reconnect with the same SDL ID: Invalidated handles on exchange failure and reconciled sandbox attachments on each poll in host/pad_broker_windows.c:39 and host/pad_sdl.c:471. The fixture now releases the old session and reconnects with the same IDs and reset sensors.
  • Switch 2 USB driver in the sandbox: Gated the worker in host/pad_sdl.c:706, documented the sandbox support loss and workaround, and added startup-policy coverage.
  • Unused trigger-rumble operation: Removed trigger commands from the wire and made the confined wrapper report failure in host/pad_broker.h:23 and host/hos_sdl.c:1089. Updated the protocol documentation and fixture.
  • Truncated controller name fixture: Changed tests/test_pad_broker_state.py:106 to compare the opened handle with the truncated snapshot name.

Changed in part (the rest is for the author)

  • Linux fixture feature macro: Defined _GNU_SOURCE before system headers in tests/test_pad_broker_state.py:21. The author must run the fixture with Linux GCC and Clang; no tests were run here.
  • Input freshness and publication: Session-loss invalidation was added in host/pad_broker_windows.c:39, but publication still waits on device work and sensor exchanges. Freshness limits and the delayed/lost-reply public-reader test remain to be implemented.
  • Sensor rollback and retry: The sensor policy was not changed. It still needs acknowledged-state reconciliation, retry after a failed disable, and a motion-policy test covering partial enable and failed rollback.
  • SDL ownership and stalled-client shutdown: SDL ownership and launcher shutdown were not changed. Matched initialization, teardown and TLS cleanup, bounded shutdown for stalled device calls, and real Windows teardown/reconnect verification remain outstanding.
  • Game-owned controller channel: Channel authorization was not changed. The server still needs an explicit game-owned role, rejection on ordinary and helper channels, and restart handoff.
  • Controller hot path and measurements: Replies now contain only populated slots in host/broker_windows.c:742 and host/pad_broker.h:31. Completion-driven I/O, batched sensor changes and moving slow opens out of publication remain to be implemented. The author must measure matched latency, jitter, CPU, frame times and broker working set on the exact build, including native SDL and Bluetooth hotplug comparisons.
  • Oversized Windows reply test: The validator fixture was updated for variable-length replies in tests/test_pad_broker_state.py:84, but it still does not send a trailing byte through the production Windows receive path. That test remains to be written.

Still for the author (no edit does these)

  • L19 (minor) tests/test_pad_broker_state.py:167: Verify the corrected fixture on glibc with Linux GCC and Clang, using the existing strict compiler flags. The recorded targeted runs predate this commit.

Nothing was built or run: check the change. Its review follows.


Automated fix by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.

I changed this pull request where an edit could (the rest needs runs, measurements or decisions): the new head is 265e73bda62a. It was already up to date with `mod-api`. I edited the pull request's description too (1 edit). **Changed** - **Linux controller-message rejection**: host/broker_frame.h:408 rejects controller requests on Linux; tests/test_broker_frame.py:156 covers the shared parser and Linux receive distinction. Tests were not run. - **UTF-8 controller names**: host/pad_broker_windows.c:206 truncates names at a character boundary; tests/test_pad_broker_state.py:92 covers a multibyte character at the limit. Tests were not run. - **Reconnect with the same SDL ID**: Invalidated handles on exchange failure and reconciled sandbox attachments on each poll in host/pad_broker_windows.c:39 and host/pad_sdl.c:471. The fixture now releases the old session and reconnects with the same IDs and reset sensors. - **Switch 2 USB driver in the sandbox**: Gated the worker in host/pad_sdl.c:706, documented the sandbox support loss and workaround, and added startup-policy coverage. - **Unused trigger-rumble operation**: Removed trigger commands from the wire and made the confined wrapper report failure in host/pad_broker.h:23 and host/hos_sdl.c:1089. Updated the protocol documentation and fixture. - **Truncated controller name fixture**: Changed tests/test_pad_broker_state.py:106 to compare the opened handle with the truncated snapshot name. **Changed in part (the rest is for the author)** - **Linux fixture feature macro**: Defined _GNU_SOURCE before system headers in tests/test_pad_broker_state.py:21. The author must run the fixture with Linux GCC and Clang; no tests were run here. - **Input freshness and publication**: Session-loss invalidation was added in host/pad_broker_windows.c:39, but publication still waits on device work and sensor exchanges. Freshness limits and the delayed/lost-reply public-reader test remain to be implemented. - **Sensor rollback and retry**: The sensor policy was not changed. It still needs acknowledged-state reconciliation, retry after a failed disable, and a motion-policy test covering partial enable and failed rollback. - **SDL ownership and stalled-client shutdown**: SDL ownership and launcher shutdown were not changed. Matched initialization, teardown and TLS cleanup, bounded shutdown for stalled device calls, and real Windows teardown/reconnect verification remain outstanding. - **Game-owned controller channel**: Channel authorization was not changed. The server still needs an explicit game-owned role, rejection on ordinary and helper channels, and restart handoff. - **Controller hot path and measurements**: Replies now contain only populated slots in host/broker_windows.c:742 and host/pad_broker.h:31. Completion-driven I/O, batched sensor changes and moving slow opens out of publication remain to be implemented. The author must measure matched latency, jitter, CPU, frame times and broker working set on the exact build, including native SDL and Bluetooth hotplug comparisons. - **Oversized Windows reply test**: The validator fixture was updated for variable-length replies in tests/test_pad_broker_state.py:84, but it still does not send a trailing byte through the production Windows receive path. That test remains to be written. **Still for the author** (no edit does these) - **L19** (minor) `tests/test_pad_broker_state.py:167`: Verify the corrected fixture on glibc with Linux GCC and Clang, using the existing strict compiler flags. The recorded targeted runs predate this commit. Nothing was built or run: check the change. Its review follows. --- <sub>Automated fix by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.</sub>
BeanBot requested changes 2026-11-21 06:23:18 +00:00
Dismissed
BeanBot left a comment

Recommendation: Request changes. A slow controller exchange can still leave movement or motion active after the player releases the controls. The broker also needs a game-owned controller channel and a shutdown path that can finish when a driver call stalls.

The Windows broker restored gameplay input for the reporter's PS4 and Switch Pro controllers. HEAD resets pad state on session loss, sends only occupied snapshot slots, and removes the unused trigger command. This keeps the existing input mapping and deadzones, at the cost of synchronous pipe I/O, basic-motor vibration in the sandbox, and loss of the built-in Switch 2 Pro USB driver there.

@fix will do (13)

  1. L1 host/broker_windows.c:208: The pipe wait blocks the poller that publishes the game's input. Plugging in a slow Bluetooth pad while holding forward on an already open pad can leave forward held in the game after the player releases it. A sensor round trip inside motion_poll can also fail after the poll has accumulated buttons and still publish those pre-failure values. Give the game a short freshness limit for published input and motion, and keep slow device work and pipe waits outside publication. Exercise the public input reader with a held sample, a delayed reply and a lost reply.
  2. L3 host/pad_sdl.c:236: The sensor failure path can leave one sensor enabled. A device can accept accelerometer enable, reject gyro enable, then reject the attempted accelerometer disable. The client ignores the rollback result and sets motion_on to zero, so switching motion off can leave the accelerometer running until the pad closes. Reconcile both sensors from the acknowledged state and retry a failed disable. Cover a partial enable and a failed rollback in the actual motion policy test. The state fixture currently makes both enables fail together and calls rollback itself.
  3. L5 host/pad_broker_windows.c:136: SDL is initialized on the first pipe worker and kept initialized after that worker exits. A reconnect then uses the same subsystem from a new worker, while Windows backends can own thread-affine resources. SDL thread-local allocations on these Win32 workers also lack an SDL cleanup path. Give SDL a stable owner with the required event handling and matched shutdown, or pair initialization, teardown and TLS cleanup on each session's owner. Test teardown and reconnect with the real Windows backend. Ensure a driver call that stalls cannot keep the launcher waiting indefinitely through live_clients after the game exits.
  4. L6 host/broker_windows.c:733: The dedicated controller role exists only on the client side. Any authenticated job client, including the crash helper, can claim the single controller session on an ordinary connection and hold it for the lifetime of that connection. Bind controller access to an explicitly established game-owned channel with a restart handoff, and reject controller requests on the ordinary and helper channels.
  5. L9 (minor) tests/test_pad_broker_state.py:86: Send a valid eight-slot snapshot plus one trailing byte through the production Windows reply reader and verify that the exchange fails before publication. With one slot the extra byte fits in the destination, so that case cannot catch a return to clipping at the receive capacity.
  6. L12 (minor) host/broker_windows.c:200: Backoff covers opening the pipe but excludes controller service failures. If the old worker still holds the session after a timeout, the new connection receives BROKER_E_BUSY on every poll. SDL startup failure behaves similarly. Apply backoff to acquisition failures and log a bounded diagnostic so players can distinguish a failed broker from a working broker with no attached pads.
  7. L13 (minor) host/pad_sdl.c:117: The route treats any AppContainer as one with a Longshot controller broker. The existing sandbox startup explicitly supports externally created AppContainers without that broker. A pad accessible in such a container now loses native SDL input and the game silently retries a missing pipe. Select the controller route from broker ownership and capability at startup, preserving native SDL where the external container permits it.
  8. L14 (minor) tests/test_pad_broker_route.py:30: The routing fixture substitutes its own PAD_REMOTE macro, so it still passes if the production macro's Windows predicate is broken. Compile the real macro with a stand-in hos_pad_broker_remote and exercise both native and broker reads. The state fixture should also set or clear SDL_GAMECONTROLLER_IGNORE_DEVICES explicitly before exercising broker startup.
  9. L15 (minor) docs/dev/reference/sandbox.md:242: The sandbox page still says Windows has never run, while this PR records a successful confined run. Update it with the verified pads and the specific untested cases. Also document the basic-motor fallback in the input and switch references, including the loss of wired DualSense fine haptics and the limits of HOS_HD_RUMBLE and HOS_RUMBLE_BACKEND in confined play. The Controls status should attribute the fallback to the sandbox instead of telling a player with RenHDrum installed that the library is missing.
  10. L16 (minor): Label the played build 9ac1daf6 and tie the byte-identity comparison to dd7027bf. The controller sources have changed since that comparison. Record Windows play at c62410c0 and add the strict-suite and lint results when available.
  11. L17 (its part an edit can do) host/broker_windows.c:124: Use completion-driven controller pipe I/O, batch sensor changes, move slow opens off the publication path, and send display metadata when it changes.
  12. L20 (minor) host/pad_sdl.c:707: Gating the USB worker also disables physical NFC scanning, but the Scan tag on controller action still tells a confined player with the controller plugged in to plug it in again. (more on the line)
  13. L21 (minor) gpu/vk/switches.def:201: The Switch 2 entries describe Windows USB support and its rumble diagnostic without the sandbox restriction. A confined player can leave HOS_SWITCH2 on or enable HOS_SWITCH2_RUMBLE_TEST and the worker still never starts. Scope both entries to unconfined Windows.

For the author (2) (a run, a measurement or a decision)

  • L17 host/broker_windows.c:124: Measure repeated, matched input and rumble latency, poll jitter, CPU, frame times, and broker working set at HEAD. Compare against working native SDL and include Bluetooth hotplug while another pad is active. Shorter replies cut transfers, while the per-poll wait and synchronous sensor exchanges remain.
  • L19 (minor) tests/test_pad_broker_state.py:167: Verify the corrected fixture on glibc with Linux GCC and Clang, using the existing strict compiler flags. (more on the line)

Since the last review (on dd7027bfbb)
Resolved: L2 (A failed exchange clears the samples but keeps the local handle IDs, which can match again…); L4 (Confined startup still starts the Switch 2 USB worker inside the AppContainer, while pads_…); L7 (The Xbox trigger operation added to the wire cannot be reached from confined gameplay. Tri…); L8 (The Linux fixture includes stdio before broker_frame.h defines _GNU_SOURCE. On glibc, stru…); L10 (The shared parser now accepts the Windows-only controller message on Linux, where serve ha…); L11 (A UTF-8 device or custom mapping name that crosses the 127-byte cutoff in the middle of a…)
Still open: L1 (The pipe wait blocks the poller that publishes the game's input. Plugging in a slow Blueto…); L3 (The sensor failure path can leave one sensor enabled. A device can accept accelerometer en…); L5 (SDL is initialized on the first pipe worker and kept initialized after that worker exits.…); L6 (The dedicated controller role exists only on the client side. Any authenticated job client…); L9 (Send a valid eight-slot snapshot plus one trailing byte through the production Windows rep…); L12 (Backoff covers opening the pipe but excludes controller service failures. If the old worke…); L13 (The route treats any AppContainer as one with a Longshot controller broker. The existing s…); L14 (The routing fixture substitutes its own PAD_REMOTE macro, so it still passes if the produc…); L15 (The sandbox page still says Windows has never run, while this PR records a successful conf…); L16 (Label the played build 9ac1daf6 and tie the byte-identity comparison to dd7027bf. The cont…); L17 (Measure repeated, matched input and rumble latency, poll jitter, CPU, frame times, and bro…)
New: L18 (The new boundary case leaves first_name set to long_name. The first poll copies 126 'a' by…); L19 (Verify the corrected fixture on glibc with Linux GCC and Clang, using the existing strict…); L20 (Gating the USB worker also disables physical NFC scanning, but the Scan tag on controller…); L21 (The Switch 2 entries describe Windows USB support and its rumble diagnostic without the sa…)

Checks: Still running: Guide screenshots / Guide images and local UI source review (pull_request), Third-party parts / As their notes say (pull_request), Third-party parts / The same as upstream (pull_request), Website / Website on Cloudflare (pull_request).

More: does it help, other systems, switches, what was read

Does it help: Yes for the reported input failure on the tested build. On Windows 11 with SDL 3.4.20, the WGI candidate 8b6b7c9d enumerated two pads with unusable input. Both worked in gameplay at 9ac1daf6. The reported API-base fixture failed at 2749e506 and passed on the earlier PR build. The fix at actual HEAD c62410c0 has no recorded gameplay run or matched latency, jitter, CPU, frame-time, or working-set measurements.

Other systems: Linux and unconfined Windows retain native SDL routing by inspection. Linux rejects controller requests at broker receive. Confined Windows changes SDL2, Xbox/XInput fallback, Steam Input, gyro, rumble, and Switch 2 USB input and NFC. Exact-head device and shutdown results are pending. The shared Windows reply reader also changes framing for ordinary broker operations. The diff touches no renderer, audio, save format, or build flags.

Switches: No new switches. HOS_SANDBOX still defaults to confinement when a script mod is on. HOS_SWITCH2 stays on by default outside the Windows sandbox and is now bypassed inside it, along with HOS_SWITCH2_RUMBLE_TEST. The switch table needs the new scope. HOS_HD_RUMBLE and HOS_RUMBLE_BACKEND retain their native defaults, but confined play uses ordinary motors when vibration is enabled. Those limits still need documenting.

Reviewed: 265e73bda6 against 2749e50672: Used actual checkout HEAD c62410c0. Read AGENTS.md, CONTRIBUTING.md, the PR template, and docs/dev/standards.md. The named review checklist file was absent. Reviewed the base and since-ledger diffs, read host/pad_broker.h, host/pad_broker_windows.c, and all three pad fixtures in full, and read the changed regions and relevant callers in the other host and test files. Unrelated portions of the larger files were outside the re-check. Used the supplied comments and test results as recorded evidence.; nothing run (a code review).

Checked and fine:

  • Snapshot lengths match the count and fit the receive buffer at zero through eight slots. The client checks length before accepting controller data.
  • Removing trigger commands preserves the native SDL trigger wrapper and rejects the retired command bit on the broker path.
  • The changes are on one controller-broker topic. No game files, generated output, third-party changes, or new download or install steps appear in the diff.

Testing: The PR records reporter-confirmed gameplay with two controllers and 15 passing targeted checks on earlier code. The strict suite was interrupted. Exact-head Windows play, physical reconnect, gyro, ordinary rumble and Switch 2 USB/NFC checks, Linux compiler and host checks, lint, and matched performance runs remain pending. Supplied CI lists four running checks and no failures. Read-only diff whitespace checks passed. No builds or tests were run during review.

Overlaps and merge order: #1958 is the parent Mod API work. This PR targets mod-api and belongs there before the parent integrates. The description references #2010 and says the earlier WGI-only candidate is superseded.


Automated code review by BeanBot (gpt-6.2-sol), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.

**Recommendation: Request changes.** A slow controller exchange can still leave movement or motion active after the player releases the controls. The broker also needs a game-owned controller channel and a shutdown path that can finish when a driver call stalls. The Windows broker restored gameplay input for the reporter's PS4 and Switch Pro controllers. HEAD resets pad state on session loss, sends only occupied snapshot slots, and removes the unused trigger command. This keeps the existing input mapping and deadzones, at the cost of synchronous pipe I/O, basic-motor vibration in the sandbox, and loss of the built-in Switch 2 Pro USB driver there. **`@fix` will do (13)** 1. **L1** `host/broker_windows.c:208`: The pipe wait blocks the poller that publishes the game's input. Plugging in a slow Bluetooth pad while holding forward on an already open pad can leave forward held in the game after the player releases it. A sensor round trip inside motion_poll can also fail after the poll has accumulated buttons and still publish those pre-failure values. Give the game a short freshness limit for published input and motion, and keep slow device work and pipe waits outside publication. Exercise the public input reader with a held sample, a delayed reply and a lost reply. 2. **L3** `host/pad_sdl.c:236`: The sensor failure path can leave one sensor enabled. A device can accept accelerometer enable, reject gyro enable, then reject the attempted accelerometer disable. The client ignores the rollback result and sets motion_on to zero, so switching motion off can leave the accelerometer running until the pad closes. Reconcile both sensors from the acknowledged state and retry a failed disable. Cover a partial enable and a failed rollback in the actual motion policy test. The state fixture currently makes both enables fail together and calls rollback itself. 3. **L5** `host/pad_broker_windows.c:136`: SDL is initialized on the first pipe worker and kept initialized after that worker exits. A reconnect then uses the same subsystem from a new worker, while Windows backends can own thread-affine resources. SDL thread-local allocations on these Win32 workers also lack an SDL cleanup path. Give SDL a stable owner with the required event handling and matched shutdown, or pair initialization, teardown and TLS cleanup on each session's owner. Test teardown and reconnect with the real Windows backend. Ensure a driver call that stalls cannot keep the launcher waiting indefinitely through live_clients after the game exits. 4. **L6** `host/broker_windows.c:733`: The dedicated controller role exists only on the client side. Any authenticated job client, including the crash helper, can claim the single controller session on an ordinary connection and hold it for the lifetime of that connection. Bind controller access to an explicitly established game-owned channel with a restart handoff, and reject controller requests on the ordinary and helper channels. 5. **L9** (minor) `tests/test_pad_broker_state.py:86`: Send a valid eight-slot snapshot plus one trailing byte through the production Windows reply reader and verify that the exchange fails before publication. With one slot the extra byte fits in the destination, so that case cannot catch a return to clipping at the receive capacity. 6. **L12** (minor) `host/broker_windows.c:200`: Backoff covers opening the pipe but excludes controller service failures. If the old worker still holds the session after a timeout, the new connection receives BROKER_E_BUSY on every poll. SDL startup failure behaves similarly. Apply backoff to acquisition failures and log a bounded diagnostic so players can distinguish a failed broker from a working broker with no attached pads. 7. **L13** (minor) `host/pad_sdl.c:117`: The route treats any AppContainer as one with a Longshot controller broker. The existing sandbox startup explicitly supports externally created AppContainers without that broker. A pad accessible in such a container now loses native SDL input and the game silently retries a missing pipe. Select the controller route from broker ownership and capability at startup, preserving native SDL where the external container permits it. 8. **L14** (minor) `tests/test_pad_broker_route.py:30`: The routing fixture substitutes its own PAD_REMOTE macro, so it still passes if the production macro's Windows predicate is broken. Compile the real macro with a stand-in hos_pad_broker_remote and exercise both native and broker reads. The state fixture should also set or clear SDL_GAMECONTROLLER_IGNORE_DEVICES explicitly before exercising broker startup. 9. **L15** (minor) `docs/dev/reference/sandbox.md:242`: The sandbox page still says Windows has never run, while this PR records a successful confined run. Update it with the verified pads and the specific untested cases. Also document the basic-motor fallback in the input and switch references, including the loss of wired DualSense fine haptics and the limits of HOS_HD_RUMBLE and HOS_RUMBLE_BACKEND in confined play. The Controls status should attribute the fallback to the sandbox instead of telling a player with RenHDrum installed that the library is missing. 10. **L16** (minor): Label the played build 9ac1daf6 and tie the byte-identity comparison to dd7027bf. The controller sources have changed since that comparison. Record Windows play at c62410c0 and add the strict-suite and lint results when available. 11. **L17** (its part an edit can do) `host/broker_windows.c:124`: Use completion-driven controller pipe I/O, batch sensor changes, move slow opens off the publication path, and send display metadata when it changes. 12. **L20** (minor) `host/pad_sdl.c:707`: Gating the USB worker also disables physical NFC scanning, but the Scan tag on controller action still tells a confined player with the controller plugged in to plug it in again. (more on the line) 13. **L21** (minor) `gpu/vk/switches.def:201`: The Switch 2 entries describe Windows USB support and its rumble diagnostic without the sandbox restriction. A confined player can leave HOS_SWITCH2 on or enable HOS_SWITCH2_RUMBLE_TEST and the worker still never starts. Scope both entries to unconfined Windows. **For the author (2)** (a run, a measurement or a decision) - **L17** `host/broker_windows.c:124`: Measure repeated, matched input and rumble latency, poll jitter, CPU, frame times, and broker working set at HEAD. Compare against working native SDL and include Bluetooth hotplug while another pad is active. Shorter replies cut transfers, while the per-poll wait and synchronous sensor exchanges remain. - **L19** (minor) `tests/test_pad_broker_state.py:167`: Verify the corrected fixture on glibc with Linux GCC and Clang, using the existing strict compiler flags. (more on the line) **Since the last review** (on dd7027bfbb30) Resolved: L2 (A failed exchange clears the samples but keeps the local handle IDs, which can match again…); L4 (Confined startup still starts the Switch 2 USB worker inside the AppContainer, while pads_…); L7 (The Xbox trigger operation added to the wire cannot be reached from confined gameplay. Tri…); L8 (The Linux fixture includes stdio before broker_frame.h defines _GNU_SOURCE. On glibc, stru…); L10 (The shared parser now accepts the Windows-only controller message on Linux, where serve ha…); L11 (A UTF-8 device or custom mapping name that crosses the 127-byte cutoff in the middle of a…) Still open: L1 (The pipe wait blocks the poller that publishes the game's input. Plugging in a slow Blueto…); L3 (The sensor failure path can leave one sensor enabled. A device can accept accelerometer en…); L5 (SDL is initialized on the first pipe worker and kept initialized after that worker exits.…); L6 (The dedicated controller role exists only on the client side. Any authenticated job client…); L9 (Send a valid eight-slot snapshot plus one trailing byte through the production Windows rep…); L12 (Backoff covers opening the pipe but excludes controller service failures. If the old worke…); L13 (The route treats any AppContainer as one with a Longshot controller broker. The existing s…); L14 (The routing fixture substitutes its own PAD_REMOTE macro, so it still passes if the produc…); L15 (The sandbox page still says Windows has never run, while this PR records a successful conf…); L16 (Label the played build 9ac1daf6 and tie the byte-identity comparison to dd7027bf. The cont…); L17 (Measure repeated, matched input and rumble latency, poll jitter, CPU, frame times, and bro…) New: L18 (The new boundary case leaves first_name set to long_name. The first poll copies 126 'a' by…); L19 (Verify the corrected fixture on glibc with Linux GCC and Clang, using the existing strict…); L20 (Gating the USB worker also disables physical NFC scanning, but the Scan tag on controller…); L21 (The Switch 2 entries describe Windows USB support and its rumble diagnostic without the sa…) **Checks:** Still running: `Guide screenshots / Guide images and local UI source review (pull_request)`, `Third-party parts / As their notes say (pull_request)`, `Third-party parts / The same as upstream (pull_request)`, `Website / Website on Cloudflare (pull_request)`. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Yes for the reported input failure on the tested build. On Windows 11 with SDL 3.4.20, the WGI candidate 8b6b7c9d enumerated two pads with unusable input. Both worked in gameplay at 9ac1daf6. The reported API-base fixture failed at 2749e506 and passed on the earlier PR build. The fix at actual HEAD c62410c0 has no recorded gameplay run or matched latency, jitter, CPU, frame-time, or working-set measurements. **Other systems:** Linux and unconfined Windows retain native SDL routing by inspection. Linux rejects controller requests at broker receive. Confined Windows changes SDL2, Xbox/XInput fallback, Steam Input, gyro, rumble, and Switch 2 USB input and NFC. Exact-head device and shutdown results are pending. The shared Windows reply reader also changes framing for ordinary broker operations. The diff touches no renderer, audio, save format, or build flags. **Switches:** No new switches. HOS_SANDBOX still defaults to confinement when a script mod is on. HOS_SWITCH2 stays on by default outside the Windows sandbox and is now bypassed inside it, along with HOS_SWITCH2_RUMBLE_TEST. The switch table needs the new scope. HOS_HD_RUMBLE and HOS_RUMBLE_BACKEND retain their native defaults, but confined play uses ordinary motors when vibration is enabled. Those limits still need documenting. **Reviewed:** 265e73bda62a against 2749e50672bb: Used actual checkout HEAD c62410c0. Read AGENTS.md, CONTRIBUTING.md, the PR template, and docs/dev/standards.md. The named review checklist file was absent. Reviewed the base and since-ledger diffs, read host/pad_broker.h, host/pad_broker_windows.c, and all three pad fixtures in full, and read the changed regions and relevant callers in the other host and test files. Unrelated portions of the larger files were outside the re-check. Used the supplied comments and test results as recorded evidence.; nothing run (a code review). **Checked and fine:** - Snapshot lengths match the count and fit the receive buffer at zero through eight slots. The client checks length before accepting controller data. - Removing trigger commands preserves the native SDL trigger wrapper and rejects the retired command bit on the broker path. - The changes are on one controller-broker topic. No game files, generated output, third-party changes, or new download or install steps appear in the diff. **Testing:** The PR records reporter-confirmed gameplay with two controllers and 15 passing targeted checks on earlier code. The strict suite was interrupted. Exact-head Windows play, physical reconnect, gyro, ordinary rumble and Switch 2 USB/NFC checks, Linux compiler and host checks, lint, and matched performance runs remain pending. Supplied CI lists four running checks and no failures. Read-only diff whitespace checks passed. No builds or tests were run during review. **Overlaps and merge order:** #1958 is the parent Mod API work. This PR targets mod-api and belongs there before the parent integrates. The description references #2010 and says the earlier WGI-only candidate is superseded. </details> --- <sub>Automated code review by BeanBot (gpt-6.2-sol), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.</sub>
@ -671,1 +704,4 @@
}
#ifdef _WIN32
static void switch2_start_if_available(void) {
if (hos_sandbox_confined()) {
Member

L20 (minor): Gating the USB worker also disables physical NFC scanning, but the Scan tag on controller action still tells a confined player with the controller plugged in to plug it in again. Give the scan action a sandbox-unavailable status so the menu explains why a connected reader cannot scan.

**L20** (minor): Gating the USB worker also disables physical NFC scanning, but the Scan tag on controller action still tells a confined player with the controller plugged in to plug it in again. Give the scan action a sandbox-unavailable status so the menu explains why a connected reader cannot scan.
@ -0,0 +103,4 @@
int32_t ids[8]; int args[8];
CHECK(hos_pad_broker_list(ids, args, 8) == 2 && ids[0] != 0 && ids[0] != ids[1]);
void *a = hos_pad_broker_open(args[0]), *b = hos_pad_broker_open(args[1]);
CHECK(a && b && a != b && !strcmp(((BrokerPadState *)a)->name, latest.pads[0].name));
Member

L18: The new boundary case leaves first_name set to long_name. The first poll copies 126 'a' bytes into latest, and hos_pad_broker_open copies that same sample into the handle. The later assertion still expects "zero pad", so the fixture fails even with correct UTF-8 truncation. Assert the truncated name on the opened handle, or restore first_name and refresh the snapshot before opening it.

**L18**: The new boundary case leaves first_name set to long_name. The first poll copies 126 'a' bytes into latest, and hos_pad_broker_open copies that same sample into the handle. The later assertion still expects "zero pad", so the fixture fails even with correct UTF-8 truncation. Assert the truncated name on the opened handle, or restore first_name and refresh the snapshot before opening it.
@ -0,0 +164,4 @@
args = parser.parse_args()
source = (ROOT / 'host/pad_broker_windows.c').read_text(encoding='utf-8')
body = between(source, 'static BrokerPadSnapshot latest;', '\n#endif')
# Prototypes are Windows-only in the public header, also provide them for this portable fixture.
Member

L19 (minor): Verify the corrected fixture on glibc with Linux GCC and Clang, using the existing strict compiler flags. The recorded targeted runs predate this commit.

**L19** (minor): Verify the corrected fixture on glibc with Linux GCC and Clang, using the existing strict compiler flags. The recorded targeted runs predate this commit.
Owner
@fix
Member

I changed this pull request where an edit could (the rest needs runs, measurements or decisions): the new head is 33091af1b6. I merged mod-api (b184b67c22) into it, as it has merge commits.

Conflicts resolved

  • docs/dev/reference/sandbox.md: Kept the controller broker documentation and Windows gameplay findings.
  • docs/user/graphics-and-controls.md: Kept the Sprint controls documentation.
  • gpu/vk/vk_api.h: Kept the base branch’s API version 40.
  • gpu/vk/vk_draw.cpp: Kept periodic pipeline cache saves.
  • host/broker_frame.h: Kept the controller broker frame type and Linux rejection.
  • host/broker_windows.c: Kept the controller broker connection and request handling.
  • host/hos_main.c: Kept initialized teleport-check buffers.
  • host/pad_sdl.c: Kept broker sample freshness and the base branch’s Steam Deck input tracking.
  • host/prompts.c: Kept the updated controller function declarations.
  • nx2/oot_patches.py: Kept the Sprint press patch and its reporting.
  • scripts/builder_package.py: Kept the escaped Windows path.
  • scripts/dev.py: Kept the update commands.
  • tests/test_broker_frame.py: Kept controller frame coverage.
  • tests/test_input_background.py: Kept the player activity counter.
  • tests/test_ocb_hold.py: Kept the updated hold-rule coverage and omitted the obsolete text-patch test.
  • tests/test_sandbox_windows.py: Kept the controller frame as the last broker type. I edited the pull request's description too (2 edits).

Changed

  • Acquisition backoff, host/broker_windows.c:201: Backs off connection and service failures, drops failed channels, and logs one failure and recovery per outage.
  • Routing and environment fixtures, tests/test_pad_broker_route.py:24: Compiles the production Windows routing macro with a stand-in predicate and clears the inherited SDL ignore list in tests/test_pad_broker_state.py:82.
  • Sandbox NFC status, host/nn_nfp.c:514: Returns a sandbox-unavailable scan status and explains it in gpu/vk/menu/nfc.cpp:68.
  • Testing description: Corrected the gameplay table's build label and distinguished the earlier byte-identity comparison; recorded the stated c62410c0 Windows play. Strict-suite and lint results remain unavailable.
  • Sandbox and haptics documentation, docs/dev/reference/sandbox.md:181: Documented the verified controllers, outstanding checks and confined haptics limits; Controls reports the sandbox motor fallback in host/pad_sdl.c:678. Updated the menu fixture; no tests or builds were run.
  • External AppContainer routing, host/pad_sdl.c:117: Saved the game broker's advertised capabilities and selected broker routing only when the game adopted a broker advertising controllers; updated the routing and startup fixtures in tests/test_pad_broker_route.py and tests/test_pad_appcontainer.py. Tests were not run.
  • Switch 2 documentation, gpu/vk/switches.def:201: Scoped both Switch 2 entries to unconfined Windows.
  • Sensor rollback, host/pad_sdl.c:235: Track acknowledged sensor states, retry failed disables, and cover partial enable and failed rollback in tests/test_pad_motion_policy.py. Tests were not run.
  • Eight-slot oversized reply fixture: Added a fixture in tests/test_pad_broker_state.py:162 that passes valid and trailing-byte eight-slot replies through the production Windows reader and controller exchange, checking that the oversized reply clears the published snapshot. Tests were not run.

Not done this time (still open: the next @fix takes it)

  • Move slow work off controller publication: The publication path still needs asynchronous device and pipe work, plus a public-reader fixture covering held input and delayed and lost replies.
  • SDL ownership and bounded shutdown: The broker still needs matched SDL ownership and teardown, TLS cleanup, bounded launcher shutdown, and real Windows teardown and reconnect testing.
  • Bind controller access to the game: The broker still needs a game-owned controller channel, rejection on ordinary and helper channels, and restart handoff.
  • Controller transport and performance measurements: Completion-driven I/O, batched sensor changes, asynchronous opens, and change-driven display metadata remain to be implemented. The author must then measure matched input and rumble latency, jitter, CPU, frame times, and broker working set against native SDL, including Bluetooth hotplug.

Still for the author (no edit does these)

  • L19 (minor) tests/test_pad_broker_state.py:167: Verify the corrected fixture on glibc with Linux GCC and Clang, using the existing strict compiler flags. The recorded targeted runs predate this commit.

Nothing was built or run: check the change. It will be reviewed again.


Automated fix by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.

I changed this pull request where an edit could (the rest needs runs, measurements or decisions): the new head is 33091af1b6b6. I merged `mod-api` (b184b67c22d9) into it, as it has merge commits. **Conflicts resolved** - docs/dev/reference/sandbox.md: Kept the controller broker documentation and Windows gameplay findings. - docs/user/graphics-and-controls.md: Kept the Sprint controls documentation. - gpu/vk/vk_api.h: Kept the base branch’s API version 40. - gpu/vk/vk_draw.cpp: Kept periodic pipeline cache saves. - host/broker_frame.h: Kept the controller broker frame type and Linux rejection. - host/broker_windows.c: Kept the controller broker connection and request handling. - host/hos_main.c: Kept initialized teleport-check buffers. - host/pad_sdl.c: Kept broker sample freshness and the base branch’s Steam Deck input tracking. - host/prompts.c: Kept the updated controller function declarations. - nx2/oot_patches.py: Kept the Sprint press patch and its reporting. - scripts/builder_package.py: Kept the escaped Windows path. - scripts/dev.py: Kept the update commands. - tests/test_broker_frame.py: Kept controller frame coverage. - tests/test_input_background.py: Kept the player activity counter. - tests/test_ocb_hold.py: Kept the updated hold-rule coverage and omitted the obsolete text-patch test. - tests/test_sandbox_windows.py: Kept the controller frame as the last broker type. I edited the pull request's description too (2 edits). **Changed** - **Acquisition backoff, host/broker_windows.c:201**: Backs off connection and service failures, drops failed channels, and logs one failure and recovery per outage. - **Routing and environment fixtures, tests/test_pad_broker_route.py:24**: Compiles the production Windows routing macro with a stand-in predicate and clears the inherited SDL ignore list in tests/test_pad_broker_state.py:82. - **Sandbox NFC status, host/nn_nfp.c:514**: Returns a sandbox-unavailable scan status and explains it in gpu/vk/menu/nfc.cpp:68. - **Testing description**: Corrected the gameplay table's build label and distinguished the earlier byte-identity comparison; recorded the stated c62410c0 Windows play. Strict-suite and lint results remain unavailable. - **Sandbox and haptics documentation, docs/dev/reference/sandbox.md:181**: Documented the verified controllers, outstanding checks and confined haptics limits; Controls reports the sandbox motor fallback in host/pad_sdl.c:678. Updated the menu fixture; no tests or builds were run. - **External AppContainer routing, host/pad_sdl.c:117**: Saved the game broker's advertised capabilities and selected broker routing only when the game adopted a broker advertising controllers; updated the routing and startup fixtures in tests/test_pad_broker_route.py and tests/test_pad_appcontainer.py. Tests were not run. - **Switch 2 documentation, gpu/vk/switches.def:201**: Scoped both Switch 2 entries to unconfined Windows. - **Sensor rollback, host/pad_sdl.c:235**: Track acknowledged sensor states, retry failed disables, and cover partial enable and failed rollback in tests/test_pad_motion_policy.py. Tests were not run. - **Eight-slot oversized reply fixture**: Added a fixture in tests/test_pad_broker_state.py:162 that passes valid and trailing-byte eight-slot replies through the production Windows reader and controller exchange, checking that the oversized reply clears the published snapshot. Tests were not run. **Not done this time (still open: the next `@fix` takes it)** - **Move slow work off controller publication**: The publication path still needs asynchronous device and pipe work, plus a public-reader fixture covering held input and delayed and lost replies. - **SDL ownership and bounded shutdown**: The broker still needs matched SDL ownership and teardown, TLS cleanup, bounded launcher shutdown, and real Windows teardown and reconnect testing. - **Bind controller access to the game**: The broker still needs a game-owned controller channel, rejection on ordinary and helper channels, and restart handoff. - **Controller transport and performance measurements**: Completion-driven I/O, batched sensor changes, asynchronous opens, and change-driven display metadata remain to be implemented. The author must then measure matched input and rumble latency, jitter, CPU, frame times, and broker working set against native SDL, including Bluetooth hotplug. **Still for the author** (no edit does these) - **L19** (minor) `tests/test_pad_broker_state.py:167`: Verify the corrected fixture on glibc with Linux GCC and Clang, using the existing strict compiler flags. The recorded targeted runs predate this commit. Nothing was built or run: check the change. It will be reviewed again. --- <sub>Automated fix by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.</sub>
As the review on #2016 asked.
Merge mod-api into fix/windows-controller-broker
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 22s
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 35s
Third-party parts / As their notes say (pull_request) Successful in 37s
33091af1b6
# Conflicts:
#	docs/dev/reference/sandbox.md
#	docs/user/graphics-and-controls.md
#	gpu/vk/vk_api.h
#	gpu/vk/vk_draw.cpp
#	host/broker_frame.h
#	host/broker_windows.c
#	host/hos_main.c
#	host/pad_sdl.c
#	host/prompts.c
#	nx2/oot_patches.py
#	scripts/builder_package.py
#	scripts/dev.py
#	tests/test_broker_frame.py
#	tests/test_input_background.py
#	tests/test_ocb_hold.py
#	tests/test_sandbox_windows.py
BeanBot left a comment

Recommendation: Request changes. The broker still allows any authenticated client to take the controller session, and stalled SDL work can keep the launcher waiting after the game exits. Input publication still waits on device and sensor exchanges, although readers now expire stale samples.

The change moves confined Windows controller access into the broker while retaining the game’s input mapping. It adds stale-sample expiry, sensor rollback tracking, clearer sandbox status, and acquisition backoff; the remaining ownership and blocking-work issues are significant costs.

@fix will do (4)

  1. L1 host/pad_sdl.c:488: The readers now expire old samples, but the poller still waits for device and sensor exchanges before publishing. Move slow device work and pipe waits outside publication and exercise the public readers with held input, delayed replies and lost replies.
  2. L5 host/pad_broker_windows.c:136: SDL is initialized on the first pipe worker and kept initialized after that worker exits. A reconnect then uses the same subsystem from a new worker, while Windows backends can own thread-affine resources. SDL thread-local allocations on these Win32 workers also lack an SDL cleanup path. Give SDL a stable owner with the required event handling and matched shutdown, or pair initialization, teardown and TLS cleanup on each session's owner. Test teardown and reconnect with the real Windows backend. Ensure a driver call that stalls cannot keep the launcher waiting indefinitely through live_clients after the game exits.
  3. L6 host/broker_windows.c:733: The dedicated controller role exists only on the client side. Any authenticated job client, including the crash helper, can claim the single controller session on an ordinary connection and hold it for the lifetime of that connection. Bind controller access to an explicitly established game-owned channel with a restart handoff, and reject controller requests on the ordinary and helper channels.
  4. L17 (its part an edit can do) host/broker_windows.c:124: Use completion-driven controller pipe I/O, batch sensor changes, move slow opens off the publication path, and send display metadata when it changes.

For the author (2) (a run, a measurement or a decision)

  • L17 host/broker_windows.c:124: Measure repeated, matched input and rumble latency, poll jitter, CPU, frame times, and broker working set at HEAD. Compare against working native SDL and include Bluetooth hotplug while another pad is active. Shorter replies cut transfers, while the per-poll wait and synchronous sensor exchanges remain.
  • L19 (minor) tests/test_pad_broker_state.py:167: Verify the corrected fixture on glibc with Linux GCC and Clang, using the existing strict compiler flags. The recorded targeted runs predate this commit.

Since the last review (on 265e73bda6)
Resolved: L3 (The sensor failure path can leave one sensor enabled. A device can accept accelerometer en…); L9 (Send a valid eight-slot snapshot plus one trailing byte through the production Windows rep…); L12 (Backoff covers opening the pipe but excludes controller service failures. If the old worke…); L13 (The route treats any AppContainer as one with a Longshot controller broker. The existing s…); L14 (The routing fixture substitutes its own PAD_REMOTE macro, so it still passes if the produc…); L15 (The sandbox page still says Windows has never run, while this PR records a successful conf…); L16 (Label the played build 9ac1daf6 and tie the byte-identity comparison to dd7027bf. The cont…); L20 (Gating the USB worker also disables physical NFC scanning, but the Scan tag on controller…); L21 (The Switch 2 entries describe Windows USB support and its rumble diagnostic without the sa…)
Still open: L1 (The readers now expire old samples, but the poller still waits for device and sensor excha…); L5 (SDL is initialized on the first pipe worker and kept initialized after that worker exits.…); L6 (The dedicated controller role exists only on the client side. Any authenticated job client…); L17 (Measure repeated, matched input and rumble latency, poll jitter, CPU, frame times, and bro…); L19 (Verify the corrected fixture on glibc with Linux GCC and Clang, using the existing strict…)

More: does it help, other systems, switches, what was read

Does it help: Unproven at this head. The reporter confirmed gameplay input with a PS4 and Switch Pro on an earlier Windows build, but these controller sources have since changed. Matched latency, jitter, CPU, frame-time and memory measurements are absent.

Other systems: Native SDL remains the intended path on Linux and unconfined Windows; external AppContainers now select it when the broker capability is absent. SDL2, Xbox, Steam Input, physical gyro, rumble and reconnect remain unverified, as do Windows backend teardown and Linux host builds.

Switches: No controller switch is added. HOS_SWITCH2 remains on by default and HOS_SWITCH2_RUMBLE_TEST off; their descriptions now scope the USB worker to unconfined Windows. HOS_HD_RUMBLE and HOS_RUMBLE_BACKEND cannot enable HD haptics through the broker, as documented.

Reviewed: 33091af1b6 against b184b67c22: Read the ledger-relevant changes and surrounding controller, broker, sensor, NFC, test and documentation code; read AGENTS.md, CONTRIBUTING.md and the pull request template. The full PR diff and all changed files were not read in full; recorded runs and the supplied range-diff were skimmed. docs/review-checklist.md was absent.; nothing run (a code review).

Checked and fine:

  • The sensor policy fixture exercises the requested failed rollback and retry.
  • The oversized reply fixture reaches the production Windows receive path.
  • The NFC menu and Switch 2 switch descriptions now identify the sandbox restriction.

Testing: No code or tests were run for this review. The supplied report records earlier Windows gameplay and 15 targeted checks, but exact-head gameplay, Linux builds, strict-suite completion and physical-device checks remain pending.

Overlaps and merge order: The PR targets mod-api and identifies #1958 as its parent work and #2010 as related; no other overlap was verified.


Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.

**Recommendation: Request changes.** The broker still allows any authenticated client to take the controller session, and stalled SDL work can keep the launcher waiting after the game exits. Input publication still waits on device and sensor exchanges, although readers now expire stale samples. The change moves confined Windows controller access into the broker while retaining the game’s input mapping. It adds stale-sample expiry, sensor rollback tracking, clearer sandbox status, and acquisition backoff; the remaining ownership and blocking-work issues are significant costs. **`@fix` will do (4)** 1. **L1** `host/pad_sdl.c:488`: The readers now expire old samples, but the poller still waits for device and sensor exchanges before publishing. Move slow device work and pipe waits outside publication and exercise the public readers with held input, delayed replies and lost replies. 2. **L5** `host/pad_broker_windows.c:136`: SDL is initialized on the first pipe worker and kept initialized after that worker exits. A reconnect then uses the same subsystem from a new worker, while Windows backends can own thread-affine resources. SDL thread-local allocations on these Win32 workers also lack an SDL cleanup path. Give SDL a stable owner with the required event handling and matched shutdown, or pair initialization, teardown and TLS cleanup on each session's owner. Test teardown and reconnect with the real Windows backend. Ensure a driver call that stalls cannot keep the launcher waiting indefinitely through live_clients after the game exits. 3. **L6** `host/broker_windows.c:733`: The dedicated controller role exists only on the client side. Any authenticated job client, including the crash helper, can claim the single controller session on an ordinary connection and hold it for the lifetime of that connection. Bind controller access to an explicitly established game-owned channel with a restart handoff, and reject controller requests on the ordinary and helper channels. 4. **L17** (its part an edit can do) `host/broker_windows.c:124`: Use completion-driven controller pipe I/O, batch sensor changes, move slow opens off the publication path, and send display metadata when it changes. **For the author (2)** (a run, a measurement or a decision) - **L17** `host/broker_windows.c:124`: Measure repeated, matched input and rumble latency, poll jitter, CPU, frame times, and broker working set at HEAD. Compare against working native SDL and include Bluetooth hotplug while another pad is active. Shorter replies cut transfers, while the per-poll wait and synchronous sensor exchanges remain. - **L19** (minor) `tests/test_pad_broker_state.py:167`: Verify the corrected fixture on glibc with Linux GCC and Clang, using the existing strict compiler flags. The recorded targeted runs predate this commit. **Since the last review** (on 265e73bda62a) Resolved: L3 (The sensor failure path can leave one sensor enabled. A device can accept accelerometer en…); L9 (Send a valid eight-slot snapshot plus one trailing byte through the production Windows rep…); L12 (Backoff covers opening the pipe but excludes controller service failures. If the old worke…); L13 (The route treats any AppContainer as one with a Longshot controller broker. The existing s…); L14 (The routing fixture substitutes its own PAD_REMOTE macro, so it still passes if the produc…); L15 (The sandbox page still says Windows has never run, while this PR records a successful conf…); L16 (Label the played build 9ac1daf6 and tie the byte-identity comparison to dd7027bf. The cont…); L20 (Gating the USB worker also disables physical NFC scanning, but the Scan tag on controller…); L21 (The Switch 2 entries describe Windows USB support and its rumble diagnostic without the sa…) Still open: L1 (The readers now expire old samples, but the poller still waits for device and sensor excha…); L5 (SDL is initialized on the first pipe worker and kept initialized after that worker exits.…); L6 (The dedicated controller role exists only on the client side. Any authenticated job client…); L17 (Measure repeated, matched input and rumble latency, poll jitter, CPU, frame times, and bro…); L19 (Verify the corrected fixture on glibc with Linux GCC and Clang, using the existing strict…) <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Unproven at this head. The reporter confirmed gameplay input with a PS4 and Switch Pro on an earlier Windows build, but these controller sources have since changed. Matched latency, jitter, CPU, frame-time and memory measurements are absent. **Other systems:** Native SDL remains the intended path on Linux and unconfined Windows; external AppContainers now select it when the broker capability is absent. SDL2, Xbox, Steam Input, physical gyro, rumble and reconnect remain unverified, as do Windows backend teardown and Linux host builds. **Switches:** No controller switch is added. HOS_SWITCH2 remains on by default and HOS_SWITCH2_RUMBLE_TEST off; their descriptions now scope the USB worker to unconfined Windows. HOS_HD_RUMBLE and HOS_RUMBLE_BACKEND cannot enable HD haptics through the broker, as documented. **Reviewed:** 33091af1b6b6 against b184b67c22d9: Read the ledger-relevant changes and surrounding controller, broker, sensor, NFC, test and documentation code; read AGENTS.md, CONTRIBUTING.md and the pull request template. The full PR diff and all changed files were not read in full; recorded runs and the supplied range-diff were skimmed. docs/review-checklist.md was absent.; nothing run (a code review). **Checked and fine:** - The sensor policy fixture exercises the requested failed rollback and retry. - The oversized reply fixture reaches the production Windows receive path. - The NFC menu and Switch 2 switch descriptions now identify the sandbox restriction. **Testing:** No code or tests were run for this review. The supplied report records earlier Windows gameplay and 15 targeted checks, but exact-head gameplay, Linux builds, strict-suite completion and physical-device checks remain pending. **Overlaps and merge order:** The PR targets mod-api and identifies #1958 as its parent work and #2010 as related; no other overlap was verified. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.</sub>
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 22s
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 35s
Third-party parts / As their notes say (pull_request) Successful in 37s
This pull request has changes conflicting with the target branch.
  • docs/dev/reference/architecture.md
  • docs/dev/reference/sandbox.md
  • docs/modding/examples.md
  • docs/modding/system-mods.md
  • docs/modding/ui-channel.md
  • docs/modding/ui.md
  • docs/modding/world.md
  • docs/user/using-mods.md
  • gpu/vk/modui_layout.cpp
  • gpu/vk/modui_layout.h
  • gpu/vk/modui_snapshot.h
  • gpu/vk/shaders/world.frag
  • gpu/vk/shaders/world_frag_spv.h
  • gpu/vk/vk_api.h
  • gpu/vk/vk_draw.cpp
  • gpu/vk/vk_menu.cpp
  • gpu/vk/vk_modui.cpp
  • gpu/vk/vk_world_layer.cpp
  • gpu/vk/vk_world_layer.h
  • gpu/vk/world_layer.h
  • host/broker_frame.h
  • host/broker_windows.c
  • host/modapi/system_mods.h
  • host/modapi/ui.c
  • host/nn_hid.c
  • host/rx_backend.c
  • modapi/examples/enemy-names/README.md
  • modapi/examples/enemy-names/src/main.tsx
  • modapi/examples/enemy-names/test/names.test.ts
  • modapi/packages/api/longshot.d.ts
  • modapi/packages/mod-tools/lib/fake-ui.js
  • modapi/packages/mod-tools/lib/index.d.ts
  • modapi/system/mod-inspector/mod.json
  • modapi/system/mod-inspector/src/main.ts
  • modapi/system/mod-inspector/test/inspector.test.ts
  • modapi/ui/longshot-ui.d.ts
  • tests/modui_test.c
  • tests/test_broker_frame.py
  • tests/test_drawn_page_map.py
  • tests/test_gfx_world.py
  • tests/test_hos_ab.py
  • tests/test_modrt.py
  • tests/test_modui_layout.py
  • tests/test_ocb_hold.py
  • tests/test_sandbox_windows.py
  • tests/world_layer_test.cpp
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'fix/windows-controller-broker:snaildev99-fix/windows-controller-broker'
git switch 'snaildev99-fix/windows-controller-broker'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'mod-api'
git merge --no-ff 'snaildev99-fix/windows-controller-broker'
git switch 'snaildev99-fix/windows-controller-broker'
git rebase 'mod-api'
git switch 'mod-api'
git merge --ff-only 'snaildev99-fix/windows-controller-broker'
git switch 'snaildev99-fix/windows-controller-broker'
git rebase 'mod-api'
git switch 'mod-api'
git merge --no-ff 'snaildev99-fix/windows-controller-broker'
git switch 'mod-api'
git merge --squash 'snaildev99-fix/windows-controller-broker'
git switch 'mod-api'
git merge --ff-only 'snaildev99-fix/windows-controller-broker'
git switch 'mod-api'
git merge 'snaildev99-fix/windows-controller-broker'
git push origin 'mod-api'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Longshot!2016
No description provided.