Repository navigation
Let completion win on time, and schedule it before on_start - #4173
Merged
EwoutH merged 1 commit intoNov 22, 2026
Merged
Conversation
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
Member
Author
Merged
1 task done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pre-PR Checklist
Approval Link
#4120, sections 3.6 and 3.7. Defining "completion wins" on time rather than progress came from @codebreaker32 and @atul-upadhyay-7.
Summary
An action that is due completes, even when it is interrupted, canceled or preempted at that same time. And the completion event is scheduled before
on_start()/on_resume()run, so a hook that ends or restarts its own action leaves no stale completion. Part 3 of 6.Motive
Two bugs from section 1 of #4120, both reproduced on
main:start()still schedules the completion afteron_start()cancels it, so a later resume ends early (Don't schedule a completion for an action its own hook ended #4121). A hook that interrupts and then resumes its own action leaves two completion events.Implementation
start_time + duration * (1 - progress).interrupt(),cancel()andinterrupt_for()complete an action withmodel.time >= deadlinethere and then (it may still fail its completion requirements). This is checked beforeinterruptible, so a due action never blocks its successor.progressis exactly 1.0 from the deadline on. Accumulated progress can sit at 0.9999999999999999 at the deadline after a few interrupts (duration=7, interrupts at 0.7 and 1.4); a test pins that case.interrupt_for()gains steps 2 and 4: passing the current action while it is due completes it and returns False, and a due current action completes before the policy is asked.Usage Examples
Additional Notes
cancel()from its ownon_start()completes it. Refusing to start is whatstart_requirementsare for (as discussed on Claim the action slot when the action becomes active #4111). A test documents this.interrupt()/resume(), and @atul-upadhyay-7 is credited as co-author of the commit. Thanks!Written with help from Claude Code (Claude Opus 5.5).