fix: FixedCell setter atomically adds agent before updating reference (fixes #3411)#3415
Merged
fix: FixedCell setter atomically adds agent before updating reference (fixes #3411)#3415
Conversation
quaquel
reviewed
Mar 2, 2026
mesa/discrete_space/cell_agent.py
Outdated
| self._mesa_cell = cell | ||
|
|
||
| def cell(self, cell: Cell | None) -> None: | ||
| if self._mesa_cell is not None and cell is not self._mesa_cell: |
Member
There was a problem hiding this comment.
This still allows reassigning the same cell. I would just block any assignment after self._mesa_cell is no longer None.
Contributor
Author
There was a problem hiding this comment.
simplified it just blocks any assignment once _mesa_cell is set
quaquel
approved these changes
Mar 2, 2026
Member
|
There is an indentation error. Can you fix that? As a general rule, I suggest running all tests locally before committing changes. |
|
Performance benchmarks:
|
Contributor
Author
|
Sorry about that Fixed the indentation and ran tests locally before pushing this time |
Contributor
Author
|
@quaquel all done |
EwoutH
pushed a commit
that referenced
this pull request
Mar 15, 2026
EwoutH
pushed a commit
that referenced
this pull request
Mar 15, 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.
Problem
FixedAgent kept a dangling reference to a cell that rejected it due to capacity.
After a failed cell.add_agent(), agent.cell was set but the cell had no record of the agent.
Fix
Swap the order in FixedCell.cell.setter — call cell.add_agent(self) FIRST,
then update self._mesa_cell only if it succeeds. This is the same atomic
pattern already used in HasCell (PR #3374).
Fixes #3411