Repository navigation
ds: honor partial-device-allowed setting for d400/d500 USB enumeration - #15057
Conversation
Nir-Az
left a comment
There was a problem hiding this comment.
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.
…e_only, fail on missing hub/port
| 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() ) ) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
✅ 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_infodev_info and log against device name/serial, vs. 2d4xx/d5xx_info::create_deviceouter catches that log against PID and return a partialrs400_device/rs500_devicefallback. 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.
…or d400/d500 USB enumeration (#15057)
TL;DR: Wire the existing
partial-device-allowedcontext 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_failedflag andLOG_ERROR-only-on-fail messaging.Summary
ds::is_partial_device_allowed(ctx)(previously declared and defined insrc/ds/ds-private.cppbut never called) into the catch blocks ofd400-motion(all three motion ctors),d400-factory,d500-motion,d500-factory.partial-device-allowedin the context JSON) already defaults tofalse(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._has_motion_module_failedflag (adds it tod500_motionto matchd400_motion_base). Both classes'get_motion_intrinsicsare 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_ERRORnow only fires when the device is actually being failed (re-thrown); whenpartial-device-allowed=trueallows the fallback, a singleLOG_WARNINGcarries the original exception detail.This does change behavior for callers that don't explicitly set
partial-device-allowed:No HID info provided, IMU is disabledwarningpartial-device-allowed: truein context JSONLOG_WARNING)The pre-PR behavior was a side effect of PR #14650 ("Enabling failing sensors") adding the
try/catcharound 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.hardware_reset()Python stress on D455 (default settings)partial-device-allowed: truerestores legacy permissive behavior