MID selection can fail due to an ecc_agent_capability_m2m record with orphaned referencesIssue When running Discovery, such as Cloud Discovery in the below example, you note MID selection failures and locate a stack trace similar to the following: com.snc.automation_common.integration.exceptions.NoSuitableMidServerFoundException: Unable to find any validated MID Server based on status (degraded), and application: Cloud Management, and capability: ({Capability: Cloud Management, value: null},{Capability: AWS, value: us-east-1}): com.snc.mid.util.midselector.MidSelector.throwNoMidExceptionWithMsg(MidSelector.java:740)com.snc.mid.util.midselector.MidSelector.selectMidServersFromMidList(MidSelector.java:685)com.snc.mid.util.midselector.MidSelector.selectMidServers(MidSelector.java:204)com.snc.mid.util.midselector.MidSelector.selectMidServers(MidSelector.java:261)com.snc.mid.util.midselector.MidSelector.selectMidServersWithOverrideFilter(MidSelector.java:300)com.snc.mid.util.midselector.MidSelector.selectMidServersWithOverrideFilter(MidSelector.java:281)com.snc.mid.util.midselector.MidSelector.selectOneMidWithOverrideSelector(MidSelector.java:411)com.snc.mid.util.midselector.MidSelector.selectOneMidWithOverrideSelector(MidSelector.java:401)com.snc.core_automation.js.MidSelectorJSAdapter.selectMid(MidSelectorJSAdapter.java:332)com.snc.core_automation.js.MidSelectorJS.jsFunction_selectMid(MidSelectorJS.java:226)ReleaseAllCauseThis can be due to an orphaned ecc_agent_capability_m2m record that's breaking the script process. It's possible that it's another cause (e.g: misconfiguration) so that should be ruled out as wellResolutionRun the following background script to identify any bad m2m records for cleanup: var gr = new GlideRecord('ecc_agent_capability_m2m');gr.query();while (gr.next()) {if (!gr.agent.name || !gr.capability.capability) {gs.info("NOT FOUND: " + gr.sys_id);}}