WIP: fix(input): broker gamepads outside the Windows mod sandbox #2016
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2016
Loading…
Reference in a new issue
No description provided.
Delete branch "snaildev99/Longshot:fix/windows-controller-broker"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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.candhost/pad_broker.hfirst, then the routing inhost/hos_sdl.cand the connection dispatch inhost/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 head2749e506. All six changed controller/broker C/header files were byte-identical between that tested commit and the earlier PR headdd7027bf; those sources have changed since that comparison. Windows play was also recorded atc62410c0. The later API tree as a whole has not been rebuilt or played here.2749e506for missing broker stick input, and passes here.Still to test:
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 headdd7027bf.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=0remains the diagnostic workaround; reverting this patch restores prior behavior. No save format, settings keys or cache format changes.Checklist
Ready for review
mod-apirather thanmainbecause this fixes #1958; Conventional Commit title.mise run testpasses (any failure that also fails onmainis named). The prior attempt was interrupted; complete suite and baseline comparison remain pending.main, or Measurements says why there is nothing to measure. This targets mod-api; performance/latency measurements remain pending.third_party/untouched; GPL-compatible authored code only.When it applies
tests/that reads changed source is updated, not weakened.Ready to merge
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.Clarified the API/WGI measurement baseline and preserved the outstanding validation checklist; reporter-confirmed gameplay and 15 passing targeted checks are recorded.
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.
@fixwill do (17)host/broker_windows.c:208: The pipe wait blocks the poller that publishes the game's input. (more on the line)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)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.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.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)host/broker_windows.c:733: The dedicated controller role exists only on the client side. (more on the line)host/hos_sdl.c:1088: The Xbox trigger operation added to the wire cannot be reached from confined gameplay. (more on the line)tests/test_pad_broker_state.py:157: The Linux fixture includes stdio before broker_frame.h defines _GNU_SOURCE. (more on the line)host/broker_windows.c:208: The exact reply-size check uses a clipped length. (more on the line)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)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)host/broker_windows.c:200: Backoff covers opening the pipe but excludes controller service failures. (more on the line)host/pad_sdl.c:117: The route treats any AppContainer as one with a Longshot controller broker. (more on the line)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)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.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.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)
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 base2749e506and 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:
dd7027bfbbagainst2749e50672: 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:
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.
@ -54,3 +54,3 @@Downloads, 1 the home folder), u8 0, the folder it was saved in: copied there, the folderopened when show (broker_download_reply_put) */BROKER_TYPE_LAST = 10,BROKER_PADS = 11, /* Windows only: bounded controller snapshot and motor commands (pad_broker.h) */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) {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. Thepoller's device scan can take that long locally too; don't continuallytear 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;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.
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: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) {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;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);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));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.
@ -110,0 +114,4 @@/* Device access belongs to the broker. WGI can enumerate a Switch Pro in anAppContainer without delivering its input; do not start competing localcontroller backends here. hos_sdl.c routes the poller's calls to the broker. */if (hos_sandbox_confined()) {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)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)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.
@fix
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 withmod-api. I edited the pull request's description too (1 edit).Changed
Changed in part (the rest is for the author)
Still for the author (no edit does these)
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.
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.
@fixwill do (13)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.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.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.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.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.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.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.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.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.dd7027bf. The controller sources have changed since that comparison. Record Windows play at c62410c0 and add the strict-suite and lint results when available.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.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)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)
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.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
2749e506and 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:
265e73bda6against2749e50672: 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:
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.
@ -671,1 +704,4 @@}#ifdef _WIN32static void switch2_start_if_available(void) {if (hos_sandbox_confined()) {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));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.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.
@fix
I changed this pull request where an edit could (the rest needs runs, measurements or decisions): the new head is
33091af1b6. I mergedmod-api(b184b67c22) into it, as it has merge commits.Conflicts resolved
Changed
Not done this time (still open: the next
@fixtakes it)Still for the author (no edit does these)
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.
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.
@fixwill do (4)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.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.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.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)
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.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:
33091af1b6againstb184b67c22: 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:
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.
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.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.