Skip to content

Let completion win on time, and schedule it before on_start - #4173

Merged
EwoutH merged 1 commit into
lifecycle-actions-vocabularyfrom
lifecycle-actions-completion-wins
Nov 22, 2026
Merged

EwoutH merged 1 commit into
lifecycle-actions-vocabularyfrom
lifecycle-actions-completion-wins

Conversation

@EwoutH

@EwoutH EwoutH commented Nov 22, 2026

Copy link
Copy Markdown
Member

Pre-PR Checklist

  • I linked an issue/discussion where a maintainer approved this enhancement/feature for implementation.

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:

  • An interrupt at the exact completion time leaves the action INTERRUPTED with progress 1.0; resuming it then completes it, and partial credit is paid twice (reproduced by @AshNicolus: energy 60 instead of 30).
  • A hook that ends its own action is overwritten: start() still schedules the completion after on_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

  • Each attempt gets a deadline, start_time + duration * (1 - progress). interrupt(), cancel() and interrupt_for() complete an action with model.time >= deadline there and then (it may still fail its completion requirements). This is checked before interruptible, so a due action never blocks its successor.
  • progress is 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.
  • The completion event is scheduled before the hook; a zero-duration action completes after the hook only if the same attempt is still current and ACTIVE.
  • A decisions entry describes completion wins as a Mesa policy.

Usage Examples

# At t=10, before the completion event of a duration-10 action:
action.interrupt()   # returns False: it completed instead
action.state         # COMPLETED, on_complete() fired once

Additional Notes

Written with help from Claude Code (Claude Opus 5.5).

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
@EwoutH EwoutH added the breaking Release notes label label Nov 22, 2026
@EwoutH
EwoutH added this pull request to stack #4178 November 22, 2026 09:40
@github-actions github-actions Bot added ci Release notes label docs Release notes label experimental Release notes label testing Release notes label labels Nov 22, 2026
@EwoutH
EwoutH removed this pull request from stack #4178 November 22, 2026 09:43
@EwoutH
EwoutH merged commit 3a28958 into lifecycle-actions-vocabulary Nov 22, 2026
15 of 16 checks passed
@EwoutH

EwoutH commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Folded into #4172: these four PRs review as one contract, so they're combined there as separate commits. GitHub shows this one as merged only because #4172's branch now contains its commit; nothing reached main.

@EwoutH
EwoutH deleted the lifecycle-actions-completion-wins branch November 22, 2026 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking Release notes label ci Release notes label 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.

1 participant