Unity Editor Freezing with InvokeRepeating

I’m experiencing editor freezing issues when using InvokeRepeating with Sentis model predictions. Interestingly, the freezing only occurs when I use a boolean flag to check the prediction state - removing this flag prevents the freezing.

Code

Here’s my implementation based on the Sentis documentation:

// PredictionModelServer class
public void startPredict()
{
    currentState = PredictionState.Predicting;
    tensor = new Tensor<float>(shape, data.ToArray());
    worker.Schedule(tensor);
    outputTensor = worker.PeekOutput() as Tensor<float>;
    outputTensor.ReadbackRequest();
}

public void PredictResult()
{
    var outputArray = outputTensor.DownloadToArray();
    /* display outputArray[0] */
    outputTensor.Dispose();
    tensor.Dispose();
    currentState = PredictionState.Ready;
}
// In another class - this gets called by InvokeRepeating
public void InvokedFunction() 
{
    if (isPredict) // <-- Causes freezing when this flag is present
    {
        if (ModelServer.Model.IsReady())
        {
            ModelServer.Model.startPredict();
        }
        else if (ModelServer.Model.IsPredicting())
        {
            ModelServer.Model.PredictResult();
        }
    }
}

When isPredict flag is present: Editor freezes
When isPredict flag is removed: Works fine, no freezing

P.S. I’ve tried to use the editor version 2022.3.39, 2022.3.56 and 2023.2.20 and the problem exposed same.

When isPredict is false, InvokedFunction() does nothing. Is this the desired behaviour?

Could you debug and identify where the freeze occurs?

Yes, When isPredict is false it won’t done anything as desired behaviour.
Now I tried add the Debug before the if-else statement, And the editor seems to be freezed even before the Debug done.
As a code below:

public void InvokedFunction() 
{
    // boolean before start using model.
    Debug.Log($"[SENTIS_LOG] boolean flag is [{willPredict}].");

    if (isPredict) // <-- Causes freezing when this flag is present
    {
            Debug.Log($"[SENTIS_LOG][condition] The function will be call.");
        if (ModelServer.Model.IsReady())
        {
            ModelServer.Model.startPredict();
        }
        else if (ModelServer.Model.IsPredicting())
        {
            ModelServer.Model.PredictResult();
        }
    } else {
            Debug.Log($"[SENTIS_LOG][condition] The function will NOT be call.");
  }
}

And this is the console log appearances:


The current inspection is using Editor 2022.3.39f1

It looks like a synchronization issue. We would need the full scripts, if possible, to be able to debug on our side.