Skip to content

Import MetaAgents from its new home in mesa.experimental - #499

Merged
quaquel merged 1 commit into
mesa:mainfrom
lahari936:fix-meta-agents-import
Oct 28, 2026
Merged

quaquel merged 1 commit into
mesa:mainfrom
lahari936:fix-meta-agents-import

Conversation

@lahari936

Copy link
Copy Markdown
Contributor

Summary

The warehouse example imports MetaAgents from a module that no longer exists, which aborts collection for the whole examples suite.

from mesa.meta_agents import MetaAgents

The Meta-Agents Rewrite (mesa/mesa#3811, mesa/mesa#3875) moved the package to mesa.experimental.meta_agents, and mesa no longer exports meta_agents at the top level.

Bug / Issue

test_examples.py imports every model module, so this is not one failing test — collection stops and nothing runs:

ImportError while importing test module '.../mesa-examples/test_examples.py'
E   ModuleNotFoundError: No module named 'mesa.meta_agents'
1 error in 23.30s

That is the examples job currently red on mesa main (run 39246413239), and so on every open mesa PR.

Implementation

-from mesa.meta_agents import MetaAgents
+from mesa.experimental.meta_agents import MetaAgents

mesa's migration guide gives this path directly: "Meta-agents still live in mesa.experimental.meta_agents". Nothing else in the example needs changing — the rest already uses the rewritten API through model.meta_agents (create, members_of, groups_of, query_memberships), so only the import was stale. Ruff moved the line up to keep import order.

Testing

Against a worktree of current mesa main:

before:  1 error in 23.30s          (collection aborted, 0 tests run)
after:   1 failed, 24 passed        in 11.38s

test_model_steps[WarehouseModel] passes, and examples/warehouse/app.py imports cleanly and builds its page.

The one remaining failure is test_model_steps[VirusAntibodyModel] — ValueError: sequence of length 3 does not match the number of agents (20). That is a separate pre-existing bug, fixed by #496 (with the duplication half in #498). The import error was masking it; with this merged, #496 should take the job fully green.

ruff check, ruff format, pyupgrade, codespell all pass.

Additional Notes

Worth a thought for maintainers: mesa's CI runs mesa-examples against mesa main, so a rename in mesa breaks this repo with no signal until a mesa PR goes red. Nothing here needs to change for that, but a periodic scheduled run against mesa main on this repo would surface it where it can be fixed.

The Meta-Agents Rewrite (mesa/mesa#3811, mesa/mesa#3875) moved the package
from mesa.meta_agents to mesa.experimental.meta_agents, and mesa no longer
exports meta_agents at the top level. The warehouse example still imported
the old path:

    from mesa.meta_agents import MetaAgents

Since test_examples.py imports every model module, that ModuleNotFoundError
aborts collection, so the whole examples suite fails before a single test
runs. That is the examples job currently red on mesa main, and therefore on
every open mesa PR.

mesa's own migration guide gives the new path: "Meta-agents still live in
mesa.experimental.meta_agents". Nothing else in the example needs changing,
since the rest already uses the rewritten API through model.meta_agents.

Against mesa main, test_examples.py goes from 1 collection error, 0 tests run
to 24 passed / 1 failed. The remaining failure is VirusAntibodyModel, a
separate pre-existing bug fixed by mesa#496.
Copilot AI balanced review requested due to automatic review settings October 21, 2026 02:50

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@lahari936

Copy link
Copy Markdown
Contributor Author

Some evidence on how long this has been broken, and a correction to my own note above.

First the correction: I suggested a scheduled run against mesa main would help surface this. That already exists — test_examples.yml has both a build-main job and a weekly cron: '0 6 * * 1'. Coverage was never the gap, so please ignore that paragraph.

The gap is that the scheduled run has been failing every Monday since 14 September, nine weeks:

2026-10-19  schedule  failure  main
2026-10-12  schedule  failure  main
2026-10-05  schedule  failure  main
2026-09-28  schedule  failure  main
2026-09-21  schedule  failure  main
2026-09-14  schedule  failure  main

A canary that has been red for nine weeks stops being a signal, which is why this particular rename could sit unnoticed until it turned up in unrelated contributors' PRs.

The part I had wrong in the PR description, and which makes this more urgent than I claimed: both CI jobs fail on it, not just the one that tracks mesa main. From the most recent scheduled run (39249544354):

build-main: failure   ModuleNotFoundError: No module named 'mesa.meta_agents'
build-pre:  failure   ModuleNotFoundError: No module named 'mesa.meta_agents'

build-pre installs mesa[network] --pre from PyPI, so this is not only an unreleased-mesa problem. Anyone who pip install --pre mesa today and opens the warehouse example hits the same ModuleNotFoundError. That makes it a user-facing break in a published pre-release, not just a CI annoyance.

Two independent causes account for the whole nine weeks, and both are now in flight:

cause fixed by
ModuleNotFoundError: No module named 'mesa.meta_agents' — aborts collection, 0 tests run this PR
ValueError: sequence of length 3 does not match the number of agents (20) in VirusAntibodyModel #496, with the duplication half in #498

I verified the interaction locally against a worktree of current mesa main: with this PR alone the suite goes from 1 error / 0 tests run to 1 failed, 24 passed, and the remaining failure is the VirusAntibody one. So this PR plus #496 should take the weekly job green for the first time since mid-September.

@lahari936

Copy link
Copy Markdown
Contributor Author

@tpike3 @quaquel — could one of you take a look when you have a moment? It is a one-line import change, and it is currently the thing holding the examples suite down.

Short version: the Meta-Agents Rewrite moved the package to mesa.experimental.meta_agents, the warehouse example still imports mesa.meta_agents, and because test_examples.py imports every model module, collection aborts and no example test runs at all.

Why it is worth a few minutes rather than sitting in the queue:

  • The weekly scheduled run has failed every Monday since 14 September, nine weeks. A canary that has been red that long stops being read, which is how this went unnoticed.
  • It is not only an unreleased-mesa problem. build-pre installs mesa[network] --pre from PyPI and fails identically, so anyone who pip install --pre mesa today and opens the warehouse example hits the same ModuleNotFoundError.
  • It is currently turning the examples check red on every open mesa PR, including other contributors' work.

One practical thing that would help: the Test example models workflow on this PR is sitting at action_required and has never actually run, since workflow runs from a first-time contributor need maintainer approval. If you approve it, CI will show the result directly rather than you having to take my word for it. Locally, against a worktree of current mesa main, it goes from 1 error with 0 tests run to 1 failed, 24 passed.

The one remaining failure after this is VirusAntibodyModel, a separate pre-existing bug that #496 fixes. This PR plus #496 should take the weekly job green for the first time since mid-September.

No rush if you are mid-release — mainly flagging that the blast radius is wider than the one-line diff suggests.

@lahari936

Copy link
Copy Markdown
Contributor Author

@quaquel — gentle nudge on this one, with a bit of context I did not have when I first pinged.

I had assumed this PR was simply queued. Looking at the repo, that is not quite it: nothing has merged here since 14 September, and the last non-bot PR was #483 on 31 August. There are 79 open PRs, the oldest from December 2025. So this is a review-capacity problem rather than anything about this change, and I do not want to add noise to it.

The reason I am nudging anyway is that this particular one is not just another queued example fix — it is the thing keeping the examples check red on mesa PRs:

  • The scheduled run here has failed every Monday since 14 September, nine weeks, because collection aborts before any test runs.
  • Both jobs fail, including build-pre, which installs mesa[network] --pre from PyPI. So pip install --pre mesa plus the warehouse example is broken for real users today, not only against unreleased mesa.
  • It turns the examples check red on every open mesa PR, which is currently misleading contributors into thinking they broke something.

The diff is one import line. #483 moved this example onto the new meta-agents API, and the later move of the package into mesa.experimental left this one import behind:

-from mesa.meta_agents import MetaAgents
+from mesa.experimental.meta_agents import MetaAgents

If it is easier, the Test example models workflow here is still sitting at action_required and has never run — approving it would show the result without you having to read anything. Locally against current mesa main it goes from 1 error with 0 tests run to 1 failed, 24 passed, the remaining failure being the VirusAntibodyModel one that #496 fixes.

Happy to leave it be if the queue is the queue — mainly wanted the nine-weeks-of-red and the published-pre-release part on the record, since neither is obvious from a one-line diff.

@quaquel
quaquel merged commit 9112701 into mesa:main Oct 28, 2026
4 checks passed
tpike3 pushed a commit that referenced this pull request Nov 1, 2026
…error (#502)

* Report an unimportable example as one failing test, not a collection error

`get_models()` runs inside the `@pytest.mark.parametrize` decorator, so every
`model.py` under `examples/` is imported while pytest is still collecting. The
import is unguarded, so one `ImportError` propagates out of collection and
pytest stops with

    ERROR test_examples.py
    Interrupted: 1 error during collection

That is not one failing example. It is zero tests run, for every example in
the repository, and the summary line says nothing about the other 25.

This is what made the recent breakages invisible rather than merely broken.
The warehouse example's stale `mesa.meta_agents` import (#499) aborted
collection, so mesa's own `examples` job went red and stayed red for 24
consecutive runs on `main` without ever reporting on the examples that were
fine. A new breakage introduced during that window would have looked
identical to the standing one.

Guard the import and turn a failure into a single parametrized case that
fails with the underlying exception, keyed by module name. One broken example
now costs exactly one red test.

Demonstrated on 9112701 by adding a throwaway example whose `model.py`
imports a missing module:

    before   1 error in 11.87s        (Interrupted during collection, 0 ran)
    after    1 failed, 25 passed      (FAILED ...[examples.zz_broken_demo.model])

With a healthy tree the behaviour is unchanged: 25 passed, and the test ids
for working examples stay as they were (`test_model_steps[AcoTspModel]`).

Co-Authored-By: Claude Opus 5 <[email protected]>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: Claude Opus 5 <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants