Repository navigation
Don't schedule a completion for an action its own hook ended - #4121
atul-upadhyay-7 wants to merge 3 commits into
Conversation
If on_start() or on_resume() cancels the action, start() still scheduled the completion event. The action stayed INTERRUPTED, but resuming it later completed it at the old time instead of after its remaining duration.
|
@EwoutH this is the follow-up you asked for on #4111. you're right that start_requirements is the way to refuse a start, so i'm not claiming a model should do this on purpose. the case is any on_start() or on_resume() that ends its own action (cancel(), or interrupt() through code it calls): main still schedules the completion, so a later resume ends early (t=5 instead of t=6 in the test). i don't have a real model that hits it, so it's about keeping the "completion event only while ACTIVE" invariant you described. |
|
Performance benchmarks:
|
|
Thanks @atul-upadhyay-7 for the two timing regressions. I reproduced completion at t=5/t=6 on main and t=6/t=7 with the guard. @EwoutH, should #4120 support hooks ending their own action, or require hooks to avoid lifecycle transitions and use Automated note by an AI model; it can be wrong, and maintainers make the decisions. About this bot. |
Each attempt now has a deadline. interrupt(), cancel() and interrupt_for() complete an action that has reached it instead of interrupting it, so an interrupt at the completion time no longer leaves a resumable action that pays twice. progress is exactly 1.0 from the deadline on. The completion event is scheduled before on_start()/on_resume() run, so a hook that interrupts, cancels or resumes its own action goes through the normal methods and leaves no stale completion behind. Supersedes #4121; its tests are carried over. Refs #4120 Co-authored-by: atul-upadhyay-7 <[email protected]> Assisted-by: Claude Opus 5.5
|
Hi, I merged current main locally and the only conflicts were in actions.py and test_actions.py. Taking main for both leaves no diff, since #4172 already covers this. Happy to close this one as superseded, or leave it for you to close. Thanks for the redesign. |
|
Thanks for your input, it was valuable! |
Pre-PR Checklist
Summary
if on_start() or on_resume() cancels its own action, start() still schedules the completion event. the action stays INTERRUPTED, but if it is resumed later the old event completes it early.
Bug / Issue
raised in the discussion on lifecycle conventions (#4120), where it was reproduced. on main, an action with duration 5 whose on_start() calls self.cancel() is INTERRUPTED right after start(). resumed at t=1 it should finish at t=6, but the leftover event from the first start fires at t=5 and completes it early. same with on_resume(): cancel in the hook, resume again later, and it ends at the first resume's time.
Implementation
start() returns right after the on_start()/on_resume() hook if the action is no longer ACTIVE, before it works out the remaining time and schedules the completion. the action keeps whatever state the hook gave it. i also added two lines to the docstring.
Testing
two tests in
TestHookEndsAction(cancel in on_start, cancel in on_resume). both fail on main (5.0 instead of 6.0, 6.0 instead of 7.0) and pass with the change. tests/experimental/test_actions.py: 109 passed. ruff check and ruff format --check are clean.