CoreML fails to decrypt a model

We've 10 CoreML models in our app, each encrypted with a separate key generated in XCode.

After opening and closing the app 6-7 times, the app crashes at model initialization with error:

Code Block
2021-04-21 13:52:47.711729+0300 MyApp[95443:7341643] Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=com.apple.CoreML Code=9 "Failed to generate key request for 08494FB2-B070-440F-A8A5-CBD0823A258E with error: -42905" UserInfo={NSLocalizedDescription=Failed to generate key request for 08494FB2-B070-440F-A8A5-CBD0823A258E with error: -42905}: file MyApp/Model.swift, line 43


Looks like iPhone is blocking the app for suspicious behavior and the app fails to decrypt the model.

We noticed that after ~10 hours the app is unlocked, it successfully decrypts and initializes the model.

Opening and closing the app many times in a short period of time is indeed unnatural, but the most important question is how to avoid blocking? Would Apple block the app if a user opens and closes it 10 times during a day? How does the number of models in the app affect probability that the app will be blocked?

Thanks!
I had this error show up today, despite the same app working fine yesterday. The only difference, was that this morning macOS 11.3.1 and iOS 14.5.1 were released to fix a security issue with (I think?) Safari.

I had updated macOS to 11.3.1, but my iPad was still on 14.5. After updating my iPad to 14.5.1, and doing all the normal Xcode stuff like clearing derived data and cleaning the build folder (for the umpteenth time!), it started working again. I have no idea if updating iOS fixed it or not, but if you can, it's worth a shot?

I'm also not entire sure about the device blocking the app... how can you tell if it is?

Ok, well... the iOS update wasn't the answer. Yesterday, the problem came back. It was at the end of my work day, so I just power cycled the iPad and left it alone overnight. This morning, it start working again ¯\_(ツ)_/¯

Had a similar error: Error Domain=com.apple.CoreML Code=9 "Failed to set up decrypt context for XXXX/XXXX.mlmodelc. error:-42905" UserInfo={NSLocalizedDescription=Failed to set up decrypt context for XXXX/XXXX.mlmodelc. error:-42905} - same error code 9 "Internal Error" and error -42905 as reported in original question. Mine was the only device displaying this error - other developers didn't report this issue - so something to do with my device - perhaps the phone blocking access due to suspicious looking behaviour, but hard to know. It did NOT display the error when building onto the device for the first time after app/data deletion, but when run subsequently without deletion, the error displayed every time.

Power cycling the device seems to have solved the problem (at least for now). Didn't need to leave overnight or 10 hours.

Also having this issue. I found that it's related to encryption. The way we're able to reproduce is to delete app, fresh build. It'll work, but if we re-initialize the models a few times (for us models are initialized at launch so this means closing / opening the app 5-6 times), then it looks like Apple fails to decrypt the model. Presumably some sort of throttle on # encryptions per device. Deleting / reinstalling will refresh and you start again....

Having the same error popping out of nowhere today

My application also encountered this issue during the TestFlight period, a small portion of users faced problems.

Same, randomly. No clue how to reproduce.

CoreML fails to decrypt a model
 
 
Q