Repository navigation
Conversation
|
ran this locally: 147 tests pass. one regression for state-dependent durations: if should_interrupt() refuses the incoming action, interrupt_for() has already called its duration callable and cached the result, so a later start uses the old value. e.g. speed is 5 at the refused interrupt_for and 1 at the later start_action: duration comes out as 5 here, 1 on #4111. resolving the duration after should_interrupt() returns True keeps the check before the interruption. i tried that locally: 147 pass and the stale value is gone. |
|
Performance benchmarks:
|
e75d6a6 to
fff8d36
Compare
980a94a to
487308a
Compare
|
Reworked this into one commit. @atul-upadhyay-7 your ordering fixes the stale duration, but a duration callable can also rely on a start requirement ( @codebreaker32 that drops the resolve-once helper you suggested; the cost is that a negative duration still leaves the old action interrupted, like a failed requirement. |
interrupt_for() interrupted the current action first and only then let start_action() check the incoming one. An incoming action from another agent, or one that is COMPLETED or FAILED, raised after the current action had already been interrupted and its completion cancelled. interrupt_for() now runs those checks before it interrupts. They are limited to what on_interrupt() can't change, so every call that raises now also raised before, and every call that worked still does: the duration is still resolved at start, after the interruption, and passing the current action still restarts it. Closes #4062. Assisted-by: Claude Opus 5.5
487308a to
979bbe3
Compare
|
checked this against main and the pr head. one behaviour change the description doesn't mention: when the current action is non-interruptible (or should_interrupt refuses), interrupt_for() used to return False for an incoming action from another agent or a finished one. now it raises before should_interrupt runs. cur = a.start_action(Action(a, duration=5, interruptible=False))
a.interrupt_for(Action(b, duration=1)) # b is another agent
# main: False, cur stays ACTIVE
# this branch: ValueErrorsame for a completed incoming action. the docstring still says a refusal returns False. moving the owner and state checks to after the should_interrupt check, and before current_action.interrupt(), keeps the point of the pr (nothing is interrupted before the raise) and keeps a refusal as False. 146 tests pass with that order and those cases match main again. if raising there is intended, a line in the description and in Returns would cover it. |
cancel() now ends an action for good, in the new CANCELED state, and fires on_cancel(). The old resumable cancel is interrupt(force=True). An INTERRUPTED action continues with resume(); start() is private and agents start PENDING actions with start_action(). state and current_action are read-only. interrupt_for() validates the new action before interrupting, takes a PENDING or INTERRUPTED action, returns True without changes for the current action, and asks whether the slot is free afterwards rather than what interrupt() returned. Resolved durations must be finite and >= 0, priorities not NaN. Supersedes #4112. Refs #4120 Assisted-by: Claude Opus 5.5
Pre-PR Checklist
Summary
interrupt_for()no longer interrupts the current action for an incoming action that is then rejected.Bug / Issue
Closes #4062, together with #4111 (merged).
interrupt_for()interrupted the current action first and only then letstart_action()check the incoming one. An incoming action belonging to another agent, or in a finished state, raised after the current action had already been interrupted and its completion event cancelled. The agent was left idle with the old action INTERRUPTED.Implementation
interrupt_for()checks ownership and state before it interrupts. It only checks conditions thaton_interrupt()can't change, so every call that raises now also raised on main, and every call that worked on main still does. Small_check_owner()and_check_startable()helpers keep these checks in one place forstart_action()/start()andinterrupt_for().The duration is still resolved at start, after the interruption: a duration callable may read state that
on_interrupt()changes, or rely on a start requirement holding. So a negative duration, like a failed start requirement, still leaves the old action interrupted, as documented. Passing the current action itself still interrupts and restarts it, so the state check skips it.Testing
interrupt_for(current_action)still restarts it, as on main.tests/experimental/test_actions.pyandtests/test_agent.py: 146 passed.Additional Notes
Written with help from Claude Code (Claude Opus 5.5).