Partial backport of Core PR14119
Rationale for partially completing this out-of-order backport:
- We get the benefits of this change today with minimal negative impact on future backporting efforts.
- The original PR is a bit large and could do with splitting up the review. Only two additional lines of code are necessary to make this backport digestible in chunks (and then all TODOs can be removed once completed).
- Improves robustness for D3863