Skip to content

Notify class observers after batching signals - #3972

Merged
quaquel merged 1 commit into
mesa:mainfrom
ska2704:fix-batched-class-observers
Oct 24, 2026
Merged

quaquel merged 1 commit into
mesa:mainfrom
ska2704:fix-batched-class-observers

Conversation

@ska2704

@ska2704 ska2704 commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Pre-PR Checklist

  • This PR is a bug fix, not a new feature or enhancement.

Summary

Deliver batched signals to class-level observers even when no instance-level observer is registered. Otherwise, a class-wide monitor receives ordinary agent updates but silently misses updates inside batch().

Bug / Issue

Fixes #3971. The issue includes a minimal reproducer: two batched assignments should produce one notification with the initial and final values, but currently produce none.

Implementation

Use _has_subscribers() when dispatching aggregated signals, matching the ordinary notification path. It checks both subscription scopes, and _mesa_notify() already delivers to both. Aggregation stays unchanged.

Testing

  • pytest tests/experimental/test_batching.py tests/experimental/test_mesa_signals.py -q: 68 passed.
  • pytest tests/ --ignore=tests/visualization -Werror -Wdefault::PendingDeprecationWarning -q: 794 passed.
  • pytest tests/visualization -Werror -Wdefault::PendingDeprecationWarning -q: 126 passed, including browser tests.
  • All applicable pre-commit hooks passed for both changed files.

The eight new cases produce two assertion failures and six passes against unchanged production code. Both failures are class-only observers with a net change. Coverage includes scalar and list observables, nested batches, mixed class/instance subscriptions, and no-net-change suppression.

Additional Notes

Local verification used Python 3.12.11 on macOS. Other supported platforms and Python versions are left to CI.

@github-actions github-actions Bot added experimental Release notes label testing Release notes label labels Oct 23, 2026
@ska2704

ska2704 commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

The examples job fails on unchanged main (949dc8c5) too. Both jobs stop during collection at examples/warehouse/warehouse/model.py:9 with ModuleNotFoundError: No module named 'mesa.meta_agents':

The branch is current with main. The failing import is in the separate mesa-examples checkout.

@github-actions

Copy link
Copy Markdown

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🔵 +0.1% [-0.8%, +0.9%] 🔵 -1.0% [-1.2%, -0.8%]
BoltzmannWealth large 🔵 -1.1% [-1.8%, -0.4%] 🟢 -7.3% [-8.8%, -5.8%]
Schelling small 🔵 +1.3% [+0.2%, +2.3%] 🔵 +0.8% [-0.0%, +1.6%]
Schelling large 🔵 -1.0% [-1.7%, -0.4%] 🔵 -3.3% [-6.1%, -0.5%]
WolfSheep small 🔵 +1.8% [+0.8%, +2.9%] 🔵 +2.3% [-2.0%, +6.6%]
WolfSheep large 🔵 +2.2% [+0.6%, +3.7%] 🔴 +6.3% [+4.4%, +8.0%]
SugarscapeG1mt small 🔵 +0.5% [-0.6%, +1.7%] 🔵 -1.2% [-2.7%, +0.5%]
SugarscapeG1mt large 🔴 +6.8% [+3.8%, +10.1%] 🔵 +0.3% [-0.7%, +1.3%]
BoidFlockers small 🔵 -1.3% [-1.9%, -0.8%] 🔵 -1.5% [-1.9%, -1.1%]
BoidFlockers large 🔵 +1.3% [+0.8%, +1.8%] 🔵 -1.8% [-2.2%, -1.5%]
MultiLevelAllianceModel small 🟢 -5.8% [-6.8%, -4.8%] 🔵 +0.3% [-0.1%, +0.7%]
MultiLevelAllianceModel large 🔵 -3.6% [-4.7%, -2.3%] 🟢 -8.0% [-10.2%, -5.6%]

@quaquel quaquel added the bug Release notes label label Oct 24, 2026
@quaquel
quaquel merged commit 0b057dc into mesa:main Oct 24, 2026
16 of 17 checks passed
@ska2704
ska2704 deleted the fix-batched-class-observers branch November 5, 2026 01:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Release notes label experimental Release notes label testing Release notes label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Class-level observers miss signals emitted inside batch()

2 participants