The code looks careful enough, but just like any MR that adds special cases, it would be helpful to add conformance tests that cover the newly introduced cases.
Also, I'm not particularly well versed in mmdevapi. Some maintainers may have different opinions. Thanks!