Skip to content

fix: keep rejected actions from leaving an occupied slot - #4063

Closed
atul-upadhyay-7 wants to merge 5 commits into
mesa:mainfrom
atul-upadhyay-7:fix-4062-rejected-actions
Closed

atul-upadhyay-7 wants to merge 5 commits into
mesa:mainfrom
atul-upadhyay-7:fix-4062-rejected-actions

Conversation

@atul-upadhyay-7

@atul-upadhyay-7 atul-upadhyay-7 commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Pre-PR Checklist

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

Summary

makes start_action clear the agent's slot when start() raises before the action becomes active.

Bug / Issue

Part of #4062.
an invalid duration (e.g. negative) or restarting a completed action raised inside start() but left current_action set. the agent stayed busy and every later start_action was rejected.

Implementation

start_action still assigns current_action before start(), so duration=0 works. it now wraps start() in try/except and, if the action is not ACTIVE when it raises, resets current_action to None and re-raises. the duration callable is still called once. an action that already became active is not rolled back.

Testing

  • 3 new tests in tests/experimental/test_actions.py: a raising duration callable, restarting a completed action, and on_start raising after activation (slot is kept). the first two fail on main and pass with the fix.
  • tests/experimental: 465 passed. ruff clean on changed files.
  • one earlier 3.12 CI run failed in test_epstein_civil_violence_model with the locator("img") resolved to 2 elements error described in Flaky Playwright viz tests: initial screenshots hit a strict mode violation #4094. it passes on the latest run.

Additional Notes

leaves the interrupt_for part of #4062 for a follow-up, as discussed with @EwoutH.

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

Copy link
Copy Markdown

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🔵 -2.8% [-3.6%, -2.1%] 🔵 +1.0% [+0.8%, +1.2%]
BoltzmannWealth large 🔵 -1.4% [-2.4%, -0.6%] 🔵 -4.8% [-7.2%, -2.9%]
Schelling small 🔵 -0.7% [-1.5%, +0.1%] 🔵 +1.2% [+0.4%, +1.9%]
Schelling large 🔵 +1.5% [+0.7%, +2.3%] 🔵 +6.8% [+2.8%, +10.1%]
WolfSheep small 🔴 +7.0% [+6.2%, +7.8%] 🔵 +2.7% [-1.8%, +7.1%]
WolfSheep large 🔴 +4.6% [+3.7%, +5.6%] 🔴 +14.0% [+11.4%, +17.2%]
SugarscapeG1mt small 🔴 +5.5% [+4.6%, +6.5%] 🔵 +3.3% [+1.5%, +5.1%]
SugarscapeG1mt large 🔵 +4.1% [+1.4%, +7.2%] 🔵 +0.5% [-1.2%, +2.2%]
BoidFlockers small 🔵 +1.0% [+0.3%, +1.7%] 🔵 +0.7% [+0.4%, +1.0%]
BoidFlockers large 🔵 +2.1% [+1.1%, +3.1%] 🔵 +1.1% [+0.9%, +1.4%]
MultiLevelAllianceModel small 🔵 +1.1% [-0.5%, +2.6%] 🔵 +0.8% [+0.5%, +1.2%]
MultiLevelAllianceModel large 🔵 +2.2% [+0.2%, +3.9%] 🔴 +7.6% [+3.0%, +11.6%]

@atul-upadhyay-7

Copy link
Copy Markdown
Contributor Author

@quaquel, could you review this fix when you have time? the checks passed. the callable-duration limit is explained in the notes.

@EwoutH

EwoutH commented Nov 14, 2026

Copy link
Copy Markdown
Member

Thanks. The stuck-busy case is clearly a bug and worth fixing. I'd like to keep this atomic though: the PR now covers both the start_action case (an idle agent stays busy forever) and the interrupt_for ownership/state case, with 19 new tests.

Could you narrow it to the start_action fix first, with one or two regression tests? The interrupt_for part and the duration-after-interruption gap can follow once @codebreaker32 has settled the validation split in #4062.

@atul-upadhyay-7

atul-upadhyay-7 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor Author

@EwoutH pushed. narrowed to just the start_action fix with 2 regression tests. interrupt_for stays for #4062.

@atul-upadhyay-7

Copy link
Copy Markdown
Contributor Author

@codebreaker32 @EwoutH updated #4063: it's now just the start_action fix (clears the slot if start() raises before activation) with 3 small tests. interrupt_for stays for #4062. happy to adjust whatever you prefer.

@EwoutH

EwoutH commented Nov 15, 2026

Copy link
Copy Markdown
Member

Thanks for picking this up! I posted a broader look in #4062 (comment): I think the rollback here treats a symptom, and the root fix is to have the action claim the slot only when it becomes ACTIVE (and run hooks only after the completion event is scheduled).

One concrete thing already: the on_start test asserts that an action whose on_start() raised keeps the slot as ACTIVE. In that case no completion event is ever scheduled, so the agent stays busy for good. That shouldn't become the tested contract.

Could you keep this as a draft until the design in #4062 is settled? If you're up for it, this PR could then be reworked into the first step there.

@EwoutH
EwoutH marked this pull request as draft November 15, 2026 08:22
@atul-upadhyay-7

Copy link
Copy Markdown
Contributor Author

thanks, makes sense. i see it's a draft now, i'll leave it as is until #4062 settles. happy to rework it into the first step if you and codebreaker32 want that.

@mesa-triage-bot

Copy link
Copy Markdown

Thanks for the rejected-start reproducers, @atul-upadhyay-7. Current main now includes #4111: actions claim the slot only when becoming ACTIVE, and both rejected-start regression tests are included. This draft also has merge conflicts.

@EwoutH, I recommend treating this draft as superseded by #4111, with interruption validation continuing in #4112. Is there any distinct work here to retain?

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

agreed, #4111 covers the start_action case and its tests, so there's nothing left here to keep. closing this. thanks for the review on it.

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

Labels

experimental Release notes label testing Release notes label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants