fix(input): a controller swapped onto a reused hidraw node while Motion controls is off is another device #3297

Merged
HumanBean merged 1 commit from sandymac/Longshot:feat/hid-imu-uniq-device-id into main 2026-12-06 01:50:56 +00:00
Contributor

Summary

Follows #3045 (controller gyro under Steam Input), whose review left this open: BeanBot's L2, item 1 of #3276.

The game keeps each controller's learned gyroscope bias by the builder's device id (motion_hid_bias in
host/pad_sdl.c). That id was hid_imu::device_id(path, plugged): the node's path hashed with the count of devices the
node has had. The count only moves while the reader looks (a read that says the device is gone, or a look that no longer
finds the node), and with Motion controls off the reader is stopped. So on main, on Linux:

  1. Motion controls on, controller A read through /dev/hidrawN; its bias learned.
  2. Motion controls off.
  3. Unplug A, connect controller B, which Linux gives the same /dev/hidrawN.
  4. Motion controls on: B gets A's device id, and the game restores A's bias for it, so B drifts briefly until the filter
    learns its own.

This PR mixes the device's own identity into the id where the system gives one: Linux's HID_UNIQ from the hidraw
node's uevent (a Bluetooth controller's address, a USB serial where the device has one), read beside HID_ID. A
different controller on a reused node gets another id. A controller that stays connected keeps its id across Motion
controls off and on. A controller that comes back to the node is recognized as itself again.

  • Node::uniq (new): Sys::nodes fills it from HID_UNIQ on Linux (hid_uniq, beside hid_id). It stays empty on
    Windows, whose node path already holds the device instance id.
  • device_id(path, uniq, plugged) hashes it between the path and the count. An empty uniq adds nothing, so the id
    for a device without one (and every id on Windows) is the same as on main.
  • The reader's pads: motion: <family> found on <node> log line now gives the device id ((device xxxxxxxx)), so a
    log shows which id each controller got. It logs the id, a hash, never the address.
  • docs/dev/reference/input.md: the device-id sentence updated.

Read first: device_id, Node, hid_uniq and Sys::nodes (Linux) in builder/crates/build-core/src/hid_imu.rs, then
a_controller_swapped_onto_a_node_while_motion_is_off_is_another_device in hid_imu/tests.rs.

See #3276 (item 1; item 2 is testing #3045 on other hardware and stays open there).

Testing

Tested: SteamOS on a Steam Machine (AMD, RADV NAVI33), build gyro-5d33df41 (this change before the rebase onto
8c0beeec, which touches none of its files), two DualSense controllers over Bluetooth, near the start of the game.
Motion controls on, aimed with controller 1; Motion controls off in the menu; controller 1 turned off, controller 2 on;
Motion controls on, aimed with controller 2; the same again back to controller 1. Both controllers got /dev/hidraw9,
and the log's lines give each its own id, controller 1 its first one back:

pads: motion: the DualSense found on /dev/hidraw9 (device 44a03390), read from the controller beside Steam Input
pads: motion: the DualSense found on /dev/hidraw9 (device cfe3fb26), read from the controller beside Steam Input
pads: motion: the DualSense found on /dev/hidraw9 (device 44a03390), read from the controller beside Steam Input

Controller 1 getting 44a03390 back shows the reader didn't see either swap (its count stayed at 1), so on main
all three would have been one id. Aiming with each worked in the game.

Checks:

  • cargo test -p build-core on Windows (31 hid_imu tests) and on Linux (WSL, 264 tests), at the head: pass. The new test
    a_controller_swapped_onto_a_node_while_motion_is_off_is_another_device fails on main's device_id
    (another device: the same id for the second controller) and passes here. hid_uniq and device_id have unit
    tests in only_known_hid_nodes_by_their_ids and a_node_s_id_is_its_path_s_hash_and_a_device_s_its_count_on_it.
  • cargo clippy -p build-core -p longshot-game --all-targets -- -D warnings: clean. rustfmt --check on the changed
    files: clean.
  • tests/run_all.py: test_hid_imu test_steam_pads test_switch_table test_builder_pads_route test_pads_after_menu test_pad_motion_policy test_gyro_rearm test_sdl_pad_diagnostics: pass.
  • mise run test --container (CI's container, WSL, at 5d33df41 before the rebase): 897 passed, 42 failed, 13 skipped, the same failures as main at
    48f85101 run the same way (none new). Among them, ffi-gen --check (host/game_host.h:338, rx_menu_open) and
    settings_now::tests::a_file_of_every_frozen_key_is_read_and_written_back_byte_identical, both failing on main.
  • Windows: no game run needed. uniq is empty there, so every id is the same as on main (the unit tests above, run on
    Windows, check that an empty uniq leaves the id unchanged).

Still to test:

  • Steam Deck (LCD or OLED), Motion controls on, the built-in controls: aim with the gyro as on main. The Deck's
    built-in controls may report a HID_UNIQ, which changes their id (not their behaviour). (@Beanstalk steamdeck)

Measurements

Nothing to measure: one more line read from a uevent file the reader already reads (at most every 2 s, on its own thread), and a few more bytes hashed once per device found; no frame, build or load path changes.

Risks

  • A Steam Controller (2026) through its receiver: the receiver's slot nodes report an empty HID_UNIQ (seen on a
    SteamOS box: 28de:1304/1305, one node giving the receiver's own serial), so two controllers swapped on one slot
    while Motion is off still share an id there, as on main. Bluetooth controllers (a DualSense's address) are told apart.
  • Two controllers that both report an empty HID_UNIQ on the same reused node still share an id while the reader isn't
    looking, as on main (the issue's remaining case).
  • uniq is taken from the reader's last look at the nodes (at most 2 s old). A swap between that look and the open of
    the node is still the narrow window it was on main.
  • If a device reported a HID_UNIQ that changes while it stays connected, it would get a new id and relearn its bias.
  • Nothing changes after updating: the learned biases live only for a run, and nothing is saved by device id.
  • A revert is enough.

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says.
  • mise run test passes (any failure that also fails on main is named).
  • Measured against main, or Measurements says why there is nothing to measure.
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A fix: a game-free test that fails on main and passes here.
  • Docs updated.
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.

🤖 Generated with Claude Code

## Summary Follows #3045 (controller gyro under Steam Input), whose review left this open: BeanBot's L2, item 1 of #3276. The game keeps each controller's learned gyroscope bias by the builder's device id (`motion_hid_bias` in `host/pad_sdl.c`). That id was `hid_imu::device_id(path, plugged)`: the node's path hashed with the count of devices the node has had. The count only moves while the reader looks (a read that says the device is gone, or a look that no longer finds the node), and with Motion controls off the reader is stopped. So on `main`, on Linux: 1. Motion controls on, controller A read through `/dev/hidrawN`; its bias learned. 2. Motion controls off. 3. Unplug A, connect controller B, which Linux gives the same `/dev/hidrawN`. 4. Motion controls on: B gets A's device id, and the game restores A's bias for it, so B drifts briefly until the filter learns its own. This PR mixes the device's own identity into the id where the system gives one: Linux's `HID_UNIQ` from the hidraw node's `uevent` (a Bluetooth controller's address, a USB serial where the device has one), read beside `HID_ID`. A different controller on a reused node gets another id. A controller that stays connected keeps its id across Motion controls off and on. A controller that comes back to the node is recognized as itself again. - `Node::uniq` (new): `Sys::nodes` fills it from `HID_UNIQ` on Linux (`hid_uniq`, beside `hid_id`). It stays empty on Windows, whose node path already holds the device instance id. - `device_id(path, uniq, plugged)` hashes it between the path and the count. An empty `uniq` adds nothing, so the id for a device without one (and every id on Windows) is the same as on `main`. - The reader's `pads: motion: <family> found on <node>` log line now gives the device id (`(device xxxxxxxx)`), so a log shows which id each controller got. It logs the id, a hash, never the address. - `docs/dev/reference/input.md`: the device-id sentence updated. Read first: `device_id`, `Node`, `hid_uniq` and `Sys::nodes` (Linux) in `builder/crates/build-core/src/hid_imu.rs`, then `a_controller_swapped_onto_a_node_while_motion_is_off_is_another_device` in `hid_imu/tests.rs`. See #3276 (item 1; item 2 is testing #3045 on other hardware and stays open there). ## Testing **Tested:** SteamOS on a Steam Machine (AMD, RADV NAVI33), build gyro-5d33df41 (this change before the rebase onto 8c0beeec, which touches none of its files), two DualSense controllers over Bluetooth, near the start of the game. Motion controls on, aimed with controller 1; Motion controls off in the menu; controller 1 turned off, controller 2 on; Motion controls on, aimed with controller 2; the same again back to controller 1. Both controllers got `/dev/hidraw9`, and the log's lines give each its own id, controller 1 its first one back: ``` pads: motion: the DualSense found on /dev/hidraw9 (device 44a03390), read from the controller beside Steam Input pads: motion: the DualSense found on /dev/hidraw9 (device cfe3fb26), read from the controller beside Steam Input pads: motion: the DualSense found on /dev/hidraw9 (device 44a03390), read from the controller beside Steam Input ``` Controller 1 getting `44a03390` back shows the reader didn't see either swap (its count stayed at 1), so on `main` all three would have been one id. Aiming with each worked in the game. Checks: - `cargo test -p build-core` on Windows (31 `hid_imu` tests) and on Linux (WSL, 264 tests), at the head: pass. The new test `a_controller_swapped_onto_a_node_while_motion_is_off_is_another_device` fails on `main`'s `device_id` (`another device`: the same id for the second controller) and passes here. `hid_uniq` and `device_id` have unit tests in `only_known_hid_nodes_by_their_ids` and `a_node_s_id_is_its_path_s_hash_and_a_device_s_its_count_on_it`. - `cargo clippy -p build-core -p longshot-game --all-targets -- -D warnings`: clean. `rustfmt --check` on the changed files: clean. - `tests/run_all.py`: `test_hid_imu test_steam_pads test_switch_table test_builder_pads_route test_pads_after_menu test_pad_motion_policy test_gyro_rearm test_sdl_pad_diagnostics`: pass. - `mise run test --container` (CI's container, WSL, at 5d33df41 before the rebase): 897 passed, 42 failed, 13 skipped, the same failures as `main` at 48f85101 run the same way (none new). Among them, `ffi-gen --check` (`host/game_host.h:338`, `rx_menu_open`) and `settings_now::tests::a_file_of_every_frozen_key_is_read_and_written_back_byte_identical`, both failing on `main`. - Windows: no game run needed. `uniq` is empty there, so every id is the same as on `main` (the unit tests above, run on Windows, check that an empty `uniq` leaves the id unchanged). **Still to test:** - Steam Deck (LCD or OLED), Motion controls on, the built-in controls: aim with the gyro as on `main`. The Deck's built-in controls may report a `HID_UNIQ`, which changes their id (not their behaviour). (@Beanstalk steamdeck) ## Measurements Nothing to measure: one more line read from a `uevent` file the reader already reads (at most every 2 s, on its own thread), and a few more bytes hashed once per device found; no frame, build or load path changes. ## Risks - A Steam Controller (2026) through its receiver: the receiver's slot nodes report an empty `HID_UNIQ` (seen on a SteamOS box: `28de:1304`/`1305`, one node giving the receiver's own serial), so two controllers swapped on one slot while Motion is off still share an id there, as on `main`. Bluetooth controllers (a DualSense's address) are told apart. - Two controllers that both report an empty `HID_UNIQ` on the same reused node still share an id while the reader isn't looking, as on `main` (the issue's remaining case). - `uniq` is taken from the reader's last look at the nodes (at most 2 s old). A swap between that look and the open of the node is still the narrow window it was on `main`. - If a device reported a `HID_UNIQ` that changes while it stays connected, it would get a new id and relearn its bias. - Nothing changes after updating: the learned biases live only for a run, and nothing is saved by device id. - A revert is enough. ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. - [x] Tested on my own PC, in the game for a change the game runs, as Testing says. - [x] `mise run test` passes (any failure that also fails on `main` is named). - [x] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [x] A fix: a game-free test that fails on `main` and passes here. - [x] Docs updated. - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
fix(input): a controller swapped onto a reused hidraw node while Motion controls is off is another device
Some checks are pending
CI / What the change needs (pull_request) Blocked by required conditions
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Blocked by required conditions
CI / Third-party parts and guide screenshots (pull_request) Blocked by required conditions
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Blocked by required conditions
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Blocked by required conditions
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Blocked by required conditions
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Blocked by required conditions
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Blocked by required conditions
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
PR description / Title and description (pull_request_target) Waiting to run
beanstalk/approval not approved yet
7978400afe
The gyro reader's device id (`hid_imu::device_id`, what the game keeps a
controller's learned gyroscope bias by) was the node's path and the count of
devices the node has had. The count only moves while the reader looks, so a
controller unplugged and another given the same /dev/hidrawN while Motion
controls is off took the first one's id and its bias.

The id now also hashes the device's own identity where the system gives one:
Linux's HID_UNIQ from the hidraw node's uevent (a Bluetooth address, a USB
serial), read beside HID_ID. Empty on Windows, whose node path already holds
the instance id; an empty one leaves the id as before.

Refs #3276, follows #3045.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Contributor

Tested in game: SteamOS, Steam Machine (AMD RADV NAVI33), build gyro-5d33df41 (this change before a rebase that touched none of its files). Two DualSense controllers over Bluetooth: Motion controls off in the menu, controller swapped, Motion controls on, then back again. Both got /dev/hidraw9 with their own device ids (44a03390, cfe3fb26, then 44a03390 again for the first one); on main all three would share one id. Gyro aiming worked with each.

Tested in game: SteamOS, Steam Machine (AMD RADV NAVI33), build gyro-5d33df41 (this change before a rebase that touched none of its files). Two DualSense controllers over Bluetooth: Motion controls off in the menu, controller swapped, Motion controls on, then back again. Both got /dev/hidraw9 with their own device ids (44a03390, cfe3fb26, then 44a03390 again for the first one); on main all three would share one id. Gyro aiming worked with each.
sandymac changed title from WIP: fix(input): a controller swapped onto a reused hidraw node while Motion controls is off is another device to fix(input): a controller swapped onto a reused hidraw node while Motion controls is off is another device 2026-12-06 01:25:17 +00:00
Author
Contributor

@Beanstalk steamdeck: Motion controls on, aim with the Steam Deck's built-in gyro near the start of the game; it should aim as on main. The log's 'pads: motion: the Steam Deck ... found on' line gives the device id.

@Beanstalk steamdeck: Motion controls on, aim with the Steam Deck's built-in gyro near the start of the game; it should aim as on main. The log's 'pads: motion: the Steam Deck ... found on' line gives the device id.
Member

@sandymac only members of BigBeans can start the farm. One of them can approve this request by reacting 👍 to it or to this comment.

@sandymac only members of `BigBeans` can start the farm. One of them can approve this request by reacting 👍 to it or to this comment.
Owner
@review
BeanBot left a comment

Recommendation: Approve. The code is ready: only testing is left. The reported controller swap is fixed in the game-free test and worked with two Bluetooth DualSense controllers in the game. The requested Steam Deck run and head CI results are still pending. Recommend approval; not approved on the forge.

The reader includes Linux HID_UNIQ in the device ID, so controllers with distinct identities do not share learned gyro bias when they replace one another on a reused node while Motion controls is off. Devices without an identity retain the previous behavior.

Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)

  • L1 builder/crates/build-core/src/hid_imu.rs:1173: The Steam Deck built-in gyro run is still outstanding. (more on the line) Do: Run the requested Steam Deck test with Motion controls on and confirm gyro aiming works near the start of the game.

Checks: Still running: 11 checks.

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

Does it help: Yes for the tested case: the game-free swap test reportedly fails on main and passes here, and an in-game SteamOS run gave the two DualSense controllers different IDs and restored the first controller's ID when swapped back. Controllers with empty HID_UNIQ remain indistinguishable in this case.

Other systems: Windows supplies an empty identity and retains its existing ID calculation. Linux controllers with empty HID_UNIQ retain the existing limitation. Steam Deck built-in gyro behavior remains to be checked in game; the change does not alter rendering or the motion report parser.

Switches: None added, changed or removed.

Reviewed: 7978400afe against 8c0beeec5d: Read the repository rules, PR template, standards, commit, complete diff, changed identity and reader code, the new tests, and the host bias storage and restore path. Skimmed the remaining portions of hid_imu.rs, hid_imu/tests.rs and input.md; the combined full-file output was truncated. Tooling's adjacent AGENTS.md and docs/review-checklist.md were absent.; nothing run (a code review).

Checked and fine:

  • The empty-identity hash preserves the previous calculation.
  • The changed commit records AI assistance; the diff contains no generated output or game files.
  • The new test exercises stopping the reader, swapping identities on the same node, and returning to the first identity.

Testing: No commands from the project or tests were run, as requested. The PR reports passing Rust and game-free checks; Forgejo CI is still running.

Overlaps and merge order: Not checked; network access is unavailable.


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

**Recommendation: Approve.** The code is ready: only testing is left. The reported controller swap is fixed in the game-free test and worked with two Bluetooth DualSense controllers in the game. The requested Steam Deck run and head CI results are still pending. Recommend approval; not approved on the forge. The reader includes Linux HID_UNIQ in the device ID, so controllers with distinct identities do not share learned gyro bias when they replace one another on a reused node while Motion controls is off. Devices without an identity retain the previous behavior. **Testing before merging (1)** (runs on the systems it can change; it doesn't hold the recommendation) - **L1** `builder/crates/build-core/src/hid_imu.rs:1173`: The Steam Deck built-in gyro run is still outstanding. (more on the line) **Do:** Run the requested Steam Deck test with Motion controls on and confirm gyro aiming works near the start of the game. **Checks:** Still running: 11 checks. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Yes for the tested case: the game-free swap test reportedly fails on main and passes here, and an in-game SteamOS run gave the two DualSense controllers different IDs and restored the first controller's ID when swapped back. Controllers with empty HID_UNIQ remain indistinguishable in this case. **Other systems:** Windows supplies an empty identity and retains its existing ID calculation. Linux controllers with empty HID_UNIQ retain the existing limitation. Steam Deck built-in gyro behavior remains to be checked in game; the change does not alter rendering or the motion report parser. **Switches:** None added, changed or removed. **Reviewed:** 7978400afe18 against 8c0beeec5d6c: Read the repository rules, PR template, standards, commit, complete diff, changed identity and reader code, the new tests, and the host bias storage and restore path. Skimmed the remaining portions of hid_imu.rs, hid_imu/tests.rs and input.md; the combined full-file output was truncated. Tooling's adjacent AGENTS.md and docs/review-checklist.md were absent.; nothing run (a code review). **Checked and fine:** - The empty-identity hash preserves the previous calculation. - The changed commit records AI assistance; the diff contains no generated output or game files. - The new test exercises stopping the reader, swapping identities on the same node, and returning to the first identity. **Testing:** No commands from the project or tests were run, as requested. The PR reports passing Rust and game-free checks; Forgejo CI is still running. **Overlaps and merge order:** Not checked; network access is unavailable. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.</sub>
@ -1154,3 +1171,3 @@
let (vendor, product) = hid_id(&t)?;
family(vendor, product)?;
Some(Node { path: format!("/dev/{n}"), vendor, product })
Some(Node { path: format!("/dev/{n}"), vendor, product, uniq: hid_uniq(&t).to_owned() })
Member

L1 (should fix): The Steam Deck built-in gyro run is still outstanding.

When: On a Deck whose built-in HID node reports an identity, the new ID path is used; the supplied game run covers external DualSense controllers, not the Deck's built-in controls.

Do: Run the requested Steam Deck test with Motion controls on and confirm gyro aiming works near the start of the game.

**L1** (should fix): The Steam Deck built-in gyro run is still outstanding. *When:* On a Deck whose built-in HID node reports an identity, the new ID path is used; the supplied game run covers external DualSense controllers, not the Deck's built-in controls. **Do:** Run the requested Steam Deck test with Motion controls on and confirm gyro aiming works near the start of the game.
HumanBean deleted branch feat/hid-imu-uniq-device-id 2026-12-06 01:50:56 +00:00
Some checks are pending
CI / What the change needs (pull_request) Blocked by required conditions
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Blocked by required conditions
CI / Third-party parts and guide screenshots (pull_request) Blocked by required conditions
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Blocked by required conditions
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Blocked by required conditions
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Blocked by required conditions
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Blocked by required conditions
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Blocked by required conditions
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
PR description / Title and description (pull_request_target) Waiting to run
beanstalk/approval not approved yet
Some workflows are waiting to be reviewed.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
4 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!3297
No description provided.