Skip to content

Fix Windows slow-IMU partial device: HID gate uses device_path - #15216

Merged
Nir-Az merged 2 commits into
realsenseai:developmentfrom
AviaAv:imu-deferral-test
Jun 17, 2026
Merged

Nir-Az merged 2 commits into
realsenseai:developmentfrom
AviaAv:imu-deferral-test

Conversation

@AviaAv

@AviaAv AviaAv commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Windows-only fix for the slow-IMU "partial device" race.

The win_event_device_watcher HID-binding deferral gate (hid_binding_in_progress) read uvc_device_info.id, which is only populated by the Linux v4l2 backend and is always empty on Windows (MF sets device_path). The empty path made cm_node::from_device_path resolve nothing, so the gate always returned false and never deferred — the device was emitted as partial (no Motion Module) whenever the IMU HID interface enumerated slower than the UVC interfaces (~6-13s on D455/D585).

Changes (src/mf/mf-backend.cpp):

  • Use uvc.device_path (the Windows-populated path) so the gate resolves the composite and detects the IMU HID still binding.
  • Raise MAX_DEFERRAL 5s -> 10s to cover observed IMU boot times.

No-IMU / EOL units are unaffected: no HID-class child -> gate stays false -> they appear immediately with their full sensor set.

@AviaAv
AviaAv requested a review from Nir-Az June 17, 2026 06:44

@sysrsbuild-gh-agentic sysrsbuild-gh-agentic left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[rs-agentic-bot] Automated review — PR #15216

The core fix (switching uvc.id → uvc.device_path) is correct and addresses the root cause clearly. Two inline notes below — one a minor hardening suggestion, one a potential gap in the deferral cap. Additionally, two pre-existing issues noticed while reading the surrounding code that are worth tracking:


🐛 Pre-existing: hdevnotify_sensor handle overwrite in DoRegisterDeviceInterfaceToHwnd

Inside DoRegisterDeviceInterfaceToHwnd, data->hdevnotify_sensor is assigned twice: first for KSCATEGORY_SENSOR_CAMERA, then unconditionally overwritten for GUID_DEVINTERFACE_HID. The first handle is leaked — it is never passed to UnregisterDeviceNotification. This means sensor-camera arrival/removal events are silently re-registered under the HID handle, and the original handle is lost. Relevant lines (pre-existing, not part of this diff):

data->hdevnotify_sensor = RegisterDeviceNotification(hWnd, &di_sensor, ...);
// ... error check ...
data->hdevnotify_sensor = RegisterDeviceNotification(hWnd, &hid_sensor, ...); // ← overwrites previous

Suggestion: use a dedicated hdevnotify_hid field for the HID registration, similar to hdevnotifyHW / hdevnotifyUVC.


🐛 Pre-existing: hdevnotifyUSB not unregistered in run() cleanup

The cleanup block at the end of run() unregisters hdevnotifyHW, hdevnotifyUVC, and hdevnotify_sensor, but omits hdevnotifyUSB. This leaks a device-notification registration every time the watcher is stopped.


🧪 Missing tests

No unit tests are added for the hid_binding_in_progress gate logic or the deferral timer behaviour. Given this function guards against a subtle timing race, a test that exercises it with mock backend_device_group snapshots (HID child present/absent in CM tree, Sensor API returning/not returning a matching unique_id) would significantly reduce regression risk. See .github/skills/testing.md for the test infrastructure.

Comment thread src/mf/mf-backend.cpp Resolved
Comment thread src/mf/mf-backend.cpp Outdated
// never bound) doesn't make the device invisible
// forever.
static constexpr auto MAX_DEFERRAL = std::chrono::milliseconds( 5000 );
static constexpr auto MAX_DEFERRAL = std::chrono::milliseconds( 10000 );

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[rs-agentic-bot] ⚠️ Potential BUG — 10 s cap may be insufficient for worst-case hardware

The PR description states observed IMU binding times of ~6–13 s on D455/D585. Raising MAX_DEFERRAL to 10 s covers the typical case but leaves the 11–13 s tail unprotected: units that bind slower than 10 s will still exhaust the deadline and emit a partial device — the exact failure mode this fix is intended to eliminate.

Suggestions:

  1. Raise the cap to 15 s (or higher) to cover the full observed range plus headroom — the fallback path for misbehaving/no-HID hardware still triggers correctly after the timeout expires, so the only risk of a larger value is a longer one-time wait on broken hardware.
  2. Alternatively, expose it as a named constant at file scope (e.g. HID_BINDING_MAX_DEFERRAL_MS) with a comment documenting the empirical range, making field adjustments straightforward without digging into the logic.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mostly under 10s, but since some cases are borderline (9s) upped it to 15s

@Nir-Az
Nir-Az merged commit 97f4837 into realsenseai:development Jun 17, 2026
29 of 30 checks passed
@AviaAv
AviaAv deleted the imu-deferral-test branch June 17, 2026 08:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants