Repository navigation
fix(discrete_space): do not flip empty flag when add_agent is rejected (#3883) - #3889
Merged
Merged
Conversation
|
Performance benchmarks:
|
rishiiicreates
force-pushed
the
fix/cell-add-agent-empty-flag
branch
from
September 29, 2026 03:11
2019820 to
dcf4a90
Compare
Contributor
Author
|
hey, just noting: the |
Cell.add_agent previously set self.empty = False before verifying capacity, leaving empty out of sync with is_empty when CellFullException was raised. Now self.empty is set only after the agent is successfully appended. Fixes mesa#3883
rishiiicreates
force-pushed
the
fix/cell-add-agent-empty-flag
branch
from
October 3, 2026 13:39
dcf4a90 to
626597e
Compare
quaquel
approved these changes
Oct 24, 2026
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.
Note
Use this template for bug fixes only. For enhancements/new features, use the feature template and get maintainer approval in an issue/discussion before opening a PR.
Pre-PR Checklist
Summary
Fixes an issue where
Cell.add_agentsetsself.empty = Falsebefore checking cell capacity. When addition is rejected with aCellFullException,self.emptyremainedFalse, leaving it out of sync withself.is_empty.Bug / Issue
Fixes #3883.
When calling
cell.add_agent(agent)on a cell that has reached its capacity limit, aCellFullExceptionis raised. However, becauseself.empty = Falsewas previously placed before the capacity check, the cell was marked as non-empty even though no agent was added.Implementation
Moved
self.empty = FalseinCell.add_agentto run after the capacity validation passes andself._agents.append(agent)succeeds. This matches the pattern inCell.remove_agentwhere empty state is updated only after mutating_agents.Testing
tests/discrete_space/test_discrete_space.pychecking thatcell.emptyandcell.is_emptyremainTruewhenCellFullExceptionis raised.pytest tests/discrete_space/test_discrete_space.py: 98 passed.ruff checkandruff format --check: all clean.