-
Notifications
You must be signed in to change notification settings - Fork 4.3k
[MLA-1474] detect recursion on Agent methods and throw #4573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks, good. I added one suggestion.
$"{m_MethodName} called recursively. " + | ||
"This might happen if you call EnvironmentStep() or EndEpisode() from custom " + | ||
"code such as CollectObservations() or OnActionReceived()." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be more general if instead of passing methodName as argument, we passed the whole error instead. The constructor would look like :
new RecursionChecker("CollectObservations() was called recursively. Make sure there are ...");
This would make the error messages more clear, and the code future proofer, but I do not have a strong opinion on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really know how to make the errors messages more clear and still catch all possible permutations that users could set up. I'm afraid if we say something like "don't call EndEpisode from CollectObservations" and someone manages to hit CollectObservations recursively some other way, it will be more confusing.
Proposed change(s)
It was possible for user implementations of Agent.CollectObservations() and Agent.OnEpisodeBegin() to get stuck in infinite recursion if EndEpisode was called from them. We now detect the recursive calls and throw an exception.
This generalizes the approach from a similar issue on Academy.
Useful links (Github issues, JIRA tickets, ML-Agents forum threads etc.)
Fixes some (but not all) of the concerns in #4558
https://jira.unity3d.com/browse/MLA-1474
#4227
Types of change(s)
Checklist
Other comments