Properly marshall diagnostic codes to the managed layer

Could you also address the `TODO`?