Skip to content

fix: reject duplicate run ids before running scenarios - #4078

Closed
atul-upadhyay-7 wants to merge 2 commits into
mesa:mainfrom
atul-upadhyay-7:fix/reject-duplicate-runids
Closed

atul-upadhyay-7 wants to merge 2 commits into
mesa:mainfrom
atul-upadhyay-7:fix/reject-duplicate-runids

Conversation

@atul-upadhyay-7

Copy link
Copy Markdown
Contributor

Pre-PR Checklist

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

Summary

Reject duplicate run ids before a sweep starts, instead of silently replacing earlier results.

Bug / Issue

Fixes #4076.

Two spawn_replications(2) calls on the same parent create four seed streams but repeat the same two run ids. The default InMemoryStore keeps only the later results.

Implementation

Check (scenario_id, replication_id) pairs before creating a writer, registering the input or submitting work. Raise ValueError with the duplicate id. Keep spawn_replications numbering and seeds unchanged.

Document the error and add a release note.

Testing

  • New tests on unchanged main: 8 fail, 8 valid-input controls pass.
  • Patched regression tests: 16 pass in each of five runs.
  • Scenario, runner and store tests: 153 passed.
  • Full test suite: 1134 passed (10 upstream multiprocessing warnings).
  • Broader non-visual test run: 999 passed.
  • Project pre-commit checks passed, including pinned Ruff, pyupgrade, codespell and Vale.
  • Sphinx HTML preview built with notebook execution disabled; the new error documentation was visually checked. The normal notebook-executing build did not complete, so this is not a full docs-build claim.

Tests cover repeated spawn batches, manually repeated ids, the same object twice, list and generator inputs, default/memory/disk stores, no writes or task submission on invalid input, and valid single-batch or distinct-parent inputs.

Additional Notes

This checks duplicates within one run_scenarios input. It does not add resume handling, guard direct write_scenarios calls or allocate ids across repeated spawn calls.

AI tools helped investigate the issue, prepare the patch and tests, and check the results.

@github-actions github-actions Bot added docs Release notes label experimental Release notes label testing Release notes label labels Nov 13, 2026
@github-actions

Copy link
Copy Markdown

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🟢 -10.0% [-10.7%, -9.2%] 🔵 +0.3% [+0.1%, +0.6%]
BoltzmannWealth large 🔵 -3.7% [-5.2%, -2.3%] 🟢 -18.7% [-20.4%, -16.9%]
Schelling small 🟢 -6.1% [-6.8%, -5.4%] 🔴 +4.7% [+4.0%, +5.5%]
Schelling large 🔵 -2.4% [-5.5%, +0.5%] 🟢 -12.4% [-14.7%, -10.1%]
WolfSheep small 🟢 -7.2% [-8.3%, -6.0%] 🔵 -0.2% [-4.8%, +4.6%]
WolfSheep large 🔵 +1.1% [-2.2%, +4.6%] 🔵 -3.4% [-8.9%, +2.5%]
SugarscapeG1mt small 🔵 -2.4% [-4.3%, -0.4%] 🔵 +3.1% [+1.3%, +5.1%]
SugarscapeG1mt large 🔵 -1.5% [-3.8%, +0.8%] 🔵 +4.1% [+2.8%, +5.5%]
BoidFlockers small 🔴 +5.6% [+4.7%, +6.6%] 🔴 +5.4% [+4.4%, +6.4%]
BoidFlockers large 🔵 +4.0% [+2.5%, +5.3%] 🔴 +5.2% [+4.2%, +6.1%]
MultiLevelAllianceModel small 🔵 +3.8% [+2.0%, +5.4%] 🔴 +5.1% [+3.9%, +6.1%]
MultiLevelAllianceModel large 🔵 +2.6% [+1.1%, +4.0%] 🔴 +5.6% [+4.4%, +6.7%]

@atul-upadhyay-7

Copy link
Copy Markdown
Contributor Author

@quaquel this implements the duplicate-id check proposed in #4076, without changing spawn numbering or seeds. all checks are passing now. could you review it when you have time?

@mesa-triage-bot

Copy link
Copy Markdown

Thanks for the reproducer and the regression tests. I reproduced four distinct seed streams leaving only two stored results on main.

@atul-upadhyay-7, please explain how you encountered this in a real model and why that workflow combines batches from repeated spawn_replications calls, so reviewers can assess the use case behind the fix.

Automated note by an AI model; it can be wrong, and maintainers make the decisions. About this bot.

@atul-upadhyay-7

Copy link
Copy Markdown
Contributor Author

@quaquel honest answer: i found this from a small script, not a real model. the case is calling spawn_replications twice to get more runs (say 10, then 10 more) and passing both to one run_scenarios. the ids repeat, so the later results replace the earlier ones and every run shows succeeded. this pr only raises a clear error for repeated ids, nothing else changes. if you'd rather not have the check, i can close it.

@mesa-triage-bot

Copy link
Copy Markdown

Thanks for clarifying how you found this, @atul-upadhyay-7. That answers the earlier use-case question.

@quaquel, is the script-level reproducer in #4076 sufficient to proceed with this guard, or should it wait for a real-model report? I'd proceed: the current store replaces results with matching IDs, and this focused check prevents that loss without changing replication numbering or seeds.

Automated note by an AI model; it can be wrong, and maintainers make the decisions. About this bot.

@quaquel

quaquel commented Nov 19, 2026

Copy link
Copy Markdown
Member

I disagree with this fix and therefore am closing this PR. Let's first agree in the issue on how to proceed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Release notes label experimental Release notes label testing Release notes label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Repeated spawn_replications calls reuse RunIds and overwrite results

2 participants