Repository navigation
Emit stored values as new in ObservableList SET signal - #3908
Closed
Shivansh1205 wants to merge 1 commit into
Closed
Shivansh1205 wants to merge 1 commit into
Shivansh1205 wants to merge 1 commit into
Conversation
ObservableList.__set__ builds a SignalingList from the assigned iterable and then emitted the original object as the SET signal's new value. For a generator or other one-shot iterable, SignalingList has already consumed it, so subscribers received an exhausted iterator. For a plain list, the payload aliased the caller's list. Emit a snapshot of the stored values instead, matching the SET signal that batching already produces in _aggregate_list. Fixes mesa#3907
|
Performance benchmarks:
|
dietcoke-17
suggested changes
Oct 8, 2026
dietcoke-17
left a comment
Contributor
There was a problem hiding this comment.
Thanks for the fix, @Shivansh1205. The change itself looks right to me. Emitting a snapshot (list(new_list.data)) rather than new_list.data avoids exposing the list's internal storage, and it matches _aggregate_list and the slice branch of SignalingList.__setitem__, which already do list(...).
Test suggestions
- The snapshot check mutates
source, butSignalingListalready copies its input, so it would also pass withnew=new_list.data. To actually pin the copy, mutate the stored list after assignment:
source = [1, 2]
agent.inventory = source
agent.inventory.append(3)
assert handler.call_args.args[0].additional_kwargs["new"] == [1, 2]The handler only observes SET, so the append doesn't fire it. Keeping the source.append(3) check as well is fine.
list(message.additional_kwargs["new"]) == [0, 2, 4]passes for any iterable, including a liveSignalingList. Comparing directly with== [0, 2, 4]also asserts thatnewis a list. Addingassert handler.call_count == 2before the second check would also make it clear thatcall_argsrefers to the latest call.
Non-blocking
newis now always alist. Previously a tuple or set was forwarded as-is. Probably worth a line in the release notes.- The benchmark bot shows Schelling large run +6.0% and MultiLevelAllianceModel small init +4.4%. This only touches
ObservableListassignment, so it's likely noise, but a rerun would confirm. - Possible follow-up in a separate PR:
oldis still inconsistent. Unbatched it is the detachedSignalingList(or the sharedfallback_valueon first assignment), while batched it is a list snapshot.
Otherwise LGTM once the test is tightened.
Member
|
@Shivansh1205 do you plan to implement the suggestions or not? there are now also conflicts because of another merged PR. |
Member
|
closing this as stale |
1 task done
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
Assigning a generator to an
ObservableListemitted aSETsignal whosenewwas the already-consumed generator, so subscribers received no values.Bug / Issue
Fixes #3907
ObservableList.__set__accepts any iterable andSignalingListconsumes it withlist(iterable), but the signal forwarded the original object. For a plain list,newalso aliased the caller's list.Implementation
The
SignalingListis built first, andnew=list(new_list.data)is emitted: a snapshot of the stored values. This matches the batched path (_aggregate_listalready emitsnew = list(getattr(owner, name))), so aSETpayload no longer depends on whether the assignment happened insidebatch().oldis unchanged.Testing
test_observable_list_set_signal_new_valueintests/experimental/test_mesa_signals.py. It checks that a generator assignment yieldsnew == [0, 2, 4], and that mutating the source list after assignment does not change the emitted payload.assert [] == [0, 2, 4], and passes after.tests/experimental: 313 passed, including all batching tests.ruff check/ruff format --checkclean.Additional Notes
For a plain list, subscribers now get an equal copy rather than the caller's own list object. Nothing in Mesa relies on identity here, and the batched signal already behaved this way.