Skip to content

ds: honor partial-device-allowed setting for d400/d500 USB enumeration - #15057

Merged
Nir-Az merged 9 commits into
realsenseai:developmentfrom
Nir-Az:partial-device-allowed-cfg
May 17, 2026
Merged

Nir-Az merged 9 commits into
realsenseai:developmentfrom
Nir-Az:partial-device-allowed-cfg

Conversation

@Nir-Az

@Nir-Az Nir-Az commented May 15, 2026 •

Copy link
Copy Markdown
Collaborator

TL;DR: Wire the existing partial-device-allowed context setting into the d400/d500 USB enumeration path so applications can reject a partial device (no IMU) instead of silently receiving one — and align d400/d500 around the same _has_motion_module_failed flag and LOG_ERROR-only-on-fail messaging.

Summary

  • Wires ds::is_partial_device_allowed(ctx) (previously declared and defined in src/ds/ds-private.cpp but never called) into the catch blocks of d400-motion (all three motion ctors), d400-factory, d500-motion, d500-factory.
  • The setting key (partial-device-allowed in the context JSON) already defaults to false (src/ds/ds-private.cpp:125); the DDS factory already honors it (src/dds/rsdds-device-factory.cpp:160). This PR makes the USB d400/d500 path honor the same default.
  • Aligns d400 and d500 around the existing _has_motion_module_failed flag (adds it to d500_motion to match d400_motion_base). Both classes' get_motion_intrinsics are now gated on the flag, and both classes' matchers (rs455_device::create_matcher, rs_d585_device::create_matcher, rs_d585s_device::create_matcher) skip motion streams when motion construction failed.
  • LOG_ERROR now only fires when the device is actually being failed (re-thrown); when partial-device-allowed=true allows the fallback, a single LOG_WARNING carries the original exception detail.
  • Companion to Stop FW error polling cleanly on device destruction #15056 / mf-backend: defer device-watcher callback until HID Sensor binding completes #15058: where those PRs auto-fix the partial-enumeration race by superseding/debouncing, this PR lets a caller (or the default policy) reject the partial state outright instead of silently surfacing a device with a missing IMU.

⚠️ Behavior change with default settings

This does change behavior for callers that don't explicitly set partial-device-allowed:

Scenario Before this PR After this PR (default settings)
Partial USB enumeration (e.g. UVC ready, HID Sensor Collection not yet bound) Device surfaces without Motion Module + No HID info provided, IMU is disabled warning Device construction throws; partial device is not surfaced to the user callback
partial-device-allowed: true in context JSON Same as today Same as today (opt back in, partial fallback logged as LOG_WARNING)

The pre-PR behavior was a side effect of PR #14650 ("Enabling failing sensors") adding the try/catch around motion-sensor construction without wiring the policy gate. This PR completes that intent.

Applications that explicitly want the legacy permissive behavior should set:

{ "partial-device-allowed": true }

Why

Today the USB d400/d500 path silently swallows the motion-sensor construction failure and falls back to a less-capable device. On Windows the failure mode is the late-HID-binding race that surfaces a UVC-only camera (Motion Module missing). The DDS factory already gates its own partial fallback on this setting; the USB factories now do the same.

Test plan

  • unit-tests/live/hw-reset/pytest-hub-recycle-imu.py (added in this PR) — hub-recycle stress that asserts the re-enumerated device exposes a Motion Module after each port recycle. Markers: device_each("D400*") + device_each("D500*") + device_type("USB") + context("nightly") + timeout(300). Runtime skip if the device has no Motion Module sensor (covers D435 etc.). 5 iterations on nightly, 20 on weekly.
  • Build clean on Windows VS 2022 (verified locally)
  • 100/100 PASS in local hardware_reset() Python stress on D455 (default settings)
  • Smoke that a manually-set partial-device-allowed: true restores legacy permissive behavior

@Nir-Az Nir-Az left a comment

Copy link
Copy Markdown
Collaborator Author

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

Reviewed all 5 changed files (cloned from Nir-Az:partial-device-allowed-cfg). No Copilot reviewer assigned — proceeding with full review.

Summary: 1 critical bug, 2 bugs, 2 enhancements, 1 test-coverage gap. Details in inline comments below.

Comment thread src/ds/d500/d500-factory.cpp Resolved
Comment thread src/ds/d500/d500-motion.cpp Resolved
Comment thread src/ds/d400/d400-motion.cpp Resolved
@Nir-Az
Nir-Az requested a review from OhadMeir May 17, 2026 06:12
Comment thread src/ds/d400/d400-factory.cpp Resolved
Comment thread src/ds/d400/d400-motion.cpp Resolved
Comment thread src/ds/d500/d500-motion.h Resolved
Comment thread src/ds/d500/d500-motion.cpp Resolved
auto device_name = get_info( RS2_CAMERA_INFO_NAME );
auto serial = get_info( RS2_CAMERA_INFO_SERIAL_NUMBER );
LOG_ERROR( device_name << " #" << serial << " - UVC Motion Sensor Failure! " << e.what() );
if( ! ds::is_partial_device_allowed( dev_info->get_context() ) )

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Identical partial-device gating and logging logic duplicated in multiple catch blocks; extract into a helper to avoid repeating _has_motion_module_failed + ds::is_partial_device_allowed checks

Details

✨ AI Reasoning
​A third catch block in this file was changed to the same pattern introduced above: setting _has_motion_module_failed then gating on ds::is_partial_device_allowed(...) to decide whether to LOG_ERROR and rethrow or LOG_WARNING and continue. This is a verbatim repetition of the same handling logic, introduced by this PR, and suggests a single helper would reduce duplicated maintenance points.

🔧 How do I fix it?
Delete extra code. Extract repeated code sequences into reusable functions or methods. Use loops or data structures to eliminate repetitive patterns.

Reply @AikidoSec feedback: [FEEDBACK] to get better review comments in the future.
Reply @AikidoSec ignore: [REASON] to ignore this issue.
More info

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@AikidoSec ignore: The 6 catch blocks share shape but differ in context — 4 motion-class ctors that take a d4xx_info / d5xx_info dev_info and log against device name/serial, vs. 2 d4xx/d5xx_info::create_device outer catches that log against PID and return a partial rs400_device/rs500_device fallback. Extracting a single helper would force the two paths through one signature, hiding the policy choice behind an abstraction. Verbatim repetition here is intentional — clearer at the call site than a unified helper would be.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Based on your feedback, we ignored this issue because of the following reason:

The 6 catch blocks share shape but differ in context — 4 motion-class ctors that take a d4xx_info / d5xx_info dev_info and log against device name/serial, vs. 2 d4xx/d5xx_info::create_device outer catches that log against PID and return a partial rs400_device/rs500_device fallback. Extracting a single helper would force the two paths through one signature, hiding the policy choice behind an abstraction. Verbatim repetition here is intentional — clearer at the call site than a unified helper would be.

@Nir-Az
Nir-Az merged commit 141b0f8 into realsenseai:development May 17, 2026
30 checks passed
@Nir-Az
Nir-Az deleted the partial-device-allowed-cfg branch May 17, 2026 12:29
Nir-Az added a commit that referenced this pull request May 18, 2026
Nir-Az added a commit that referenced this pull request May 18, 2026
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.

2 participants