Skip to content

[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

Merged
merged 6 commits into from
Oct 19, 2020

Conversation

chriselion
Copy link
Contributor

@chriselion chriselion commented Oct 16, 2020

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)

  • Bug fix
  • New feature
  • Code refactor
  • Breaking change
  • Documentation update
  • Other (please describe)

Checklist

  • Added tests that prove my fix is effective or that my feature works
  • Updated the changelog (if applicable)
  • Updated the documentation (if applicable)
  • Updated the migration guide (if applicable)

Other comments

Copy link
Contributor

@andrewcoh andrewcoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chriselion chriselion mentioned this pull request Oct 19, 2020
10 tasks
Copy link
Contributor

@vincentpierre vincentpierre left a 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.

Comment on lines +20 to +22
$"{m_MethodName} called recursively. " +
"This might happen if you call EnvironmentStep() or EndEpisode() from custom " +
"code such as CollectObservations() or OnActionReceived()."
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@chriselion chriselion merged commit 8bbf49c into master Oct 19, 2020
@delete-merged-branch delete-merged-branch bot deleted the MLA-1474-stop-recursion branch October 19, 2020 21:34
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants