Don't call NotifyDone in Agent.OnDisable if Academy is shut down #4489
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Proposed change(s)
We currently get warnings when stopping training in the GridFoodCollector scene, because the AcademyFixedUpdateStepper is recreated. This happens because in Agent.OnDisable, we try to send the observations to the communicator (which has been shut down already). For the case of GridFoodCollector, this ends up calling Academy.Instance.TrainerCapabilities here
ml-agents/com.unity.ml-agents/Runtime/Communicator/GrpcExtensions.cs
Line 279 in 7c1cfab
which recreates the Academy instance.
There are some narrower fixes, like checking Academy.IsInitialized in GetObservationProto, or make RpcCommunicator early out when it has been shutdown (checking
m_IsOpen). But in general it feels like a bug if the Agent is trying to do any sort of "work" when everything is shut down.I'm currently targeting the release branch but I'd be willing to wait and make it on master instead if you think it's too risky/too late in the process.
Useful links (Github issues, JIRA tickets, ML-Agents forum threads etc.)
Types of change(s)
Checklist
Other comments