Repository navigation
Stop stepping in ModelController once model.running is False - #4024
Merged
quaquel merged 1 commit intoNov 2, 2026
Merged
Conversation
quaquel
approved these changes
Nov 2, 2026
EwoutH
pushed a commit
that referenced
this pull request
Nov 22, 2026
(cherry picked from commit b0c4ffd)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Pre-PR Checklist
Summary
When Render Interval is set above 1, the Step and Play buttons keep stepping the model after it has set
running = False. A single click can run the model many steps past its end condition, so the plots and collected data include steps that should never have happened.Bug / Issue
No separate issue, the bug is described here.
I came across this while reading through
ModelControllerto understand how stepping works, and then confirmed it in the Schelling example. It affects any model that ends itself throughmodel.running = False, for example when all agents are happy or a population dies out. With Render Interval above 1, the UI keeps callingstep()until the full interval is used up, even though the model already reported it was done.Reproducer
solara run app.pyinmesa/examples/basic/schellingmain: Time 100.0Cause
In
ModelController.do_step()the loop copiesmodel.runninginto therunningreactive on every iteration, but never breaks on it. The Play branch only breaks whenplayingturns off; the Step branch never breaks.The
runningcheck was added in 4e45300, whendo_stepadvanced a single step. Therender_intervalloop came later (#2596) and the check was not carried into it.Implementation
Break out of the loop in both branches as soon as
running.valueisFalse.force_update()still runs after the loop, so the UI shows the final state and the buttons get disabled as before.Testing
test_step_button_stops_when_model_stops_runningintests/visualization/test_solara_viz.py. It rendersModelControllerwithrender_interval=10, clicks Step on a model that stops after 3 steps, and checks thatstep()ran exactly 3 times. Fails onmain(assert 10 == 3), passes with this change.pytest tests/ -Werror -Wdefault::PendingDeprecationWarning→ 1022 passed.ruff checkpasses.Before (
main): Time 100.0After (this PR): Time 1.0
Additional Notes
I used Claude Code while learning the Mesa codebase. It helped me find this bug, check that no existing issue covers it, and write the test . I reproduced the bug in the Schelling example myself, reviewed the changes, and ran the full test suite locally.