Repository navigation
Claim the action slot when the action becomes active - #4111
Conversation
|
Performance benchmarks:
|
|
ran this locally: 143 tests pass and a direct start() on a busy agent is now refused. the failing "examples" job looks unrelated: test_model_steps[WarehouseModel] in mesa-examples raises CellFullException with no seed, about 3% of runs on main too (17/500 on main, 16/500 on this branch in my runs). one thing not covered here: if on_start() cancels its own action, start() still schedules a completion event afterwards, so a resume at t=3 of a duration-10 action completes at t=10 instead of 13. a state check right after the hook fixes it. happy to add a test for that. |
|
Performance benchmarks:
|
|
Thanks for testing @atul-upadhyay-7! I reproduced the Would you like to open a follow-up PR with your state check after the hook and the test? It would help to mention how a model would run into it, since |
start_action() filled the agent's slot before Action.start() validated the action, so an action rejected for its state or duration, or whose duration callable raised, stayed in the slot and left the agent busy for good. Conversely, calling Action.start() directly ran the action outside the slot, so the agent could run a second action alongside it. Action.start() now checks that the agent is idle, and claims the slot only when it sets the action ACTIVE. The slot then holds an action exactly while it is active. A failed start requirement never claims the slot, so start() schedules the idle wake itself. start_action() keeps only the ownership check. Part of #4062. Co-authored-by: Atul Upadhyay <[email protected]> Assisted-by: Claude Opus 5.5
78a9475 to
46a3da6
Compare
Pre-PR Checklist
Summary
An action that
start()rejects (invalid state, negative duration, or a duration callable that raises) no longer leaves the agent busy for good, and callingAction.start()directly can no longer run a second action next to the one in the slot.Bug / Issue
Part of #4062, the first step of the approach discussed there.
start_action()filled the agent's slot beforeAction.start()validated the action, so a rejected action stayed in the slot as PENDING and every laterstart_action()was refused. In the other direction,Action.start()called directly ran the action outside the slot, so the agent could start a second action alongside it.Implementation
Action.start()checks that the agent is idle and claims the slot when it sets the action ACTIVE, so the slot holds an action exactly while that action is active.start()schedules the idle wake itself;on_idlestill fires after a failed start.duration=0still completes synchronously insidestart().start_action()keeps only the ownership check.Testing
Three tests in
TestErrorHandling: a raising duration callable and a completed action both leave the agent usable, and a directstart()claims the slot and refuses a second action. All three fail on main. The existing wake test for a failed start still passes.tests/experimental/test_actions.pyandtests/test_agent.py: 140 passed.Additional Notes
Action.start()now raises if the agent is busy, and a directly started action now holds the slot and wakes the agent when it ends.mesa.experimentalallows this.current_actionread-only (Tracking issue for Action preconditions, preemption and continuation #3798).