Repository navigation
Conversation
remove() used to abandon an active action without any hook, leaving it ACTIVE forever. It now closes the agent, cancels the active action with on_progress(), on_stop() and on_cancel(), and cancels every interrupted action it started that is still referenced, in start order. Removal never completes an action and queues no wake. The agent tracks the actions it started weakly, so an interrupted action the model dropped isn't kept alive; pickling still works. Refs #4120 Assisted-by: Claude Opus 5.5
Merged
1 task done
Member
Author
|
Folded into #4172: these four PRs review as one contract, so they're combined there as separate commits. |
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, section 3.3 (
remove()). Removal with hooks answers @codebreaker32's point 2: CANCELED should meanon_cancel()ran.Summary
Removing an agent now cancels its actions with their hooks, instead of abandoning the active one in ACTIVE forever. Part 5 of 6.
Motive
On
main,remove()on a busy agent cancels the completion event and leaves the action ACTIVE, with no hook (reproduced by @AshNicolus in #4120). A model that needs cleanup has to overrideremove(), and a reservation held through an interruption is never released if the agent is removed mid-break.Implementation
remove():start_action(),resume()andinterrupt_for()raiseValueError, and no wake is queued;on_progress(delta),on_stop(),on_cancel(). Removal never completes an action, even a due one: it is the one exception to completion wins (added to the decisions entry);on_cancel();super().remove().The hooks run while the agent is still in the model. The agent tracks the actions it started in a
WeakValueDictionarykeyed by start order (added at the first start, dropped when final), so an interrupted action the model dropped isn't kept alive and the order is deterministic. PENDING actions aren't tracked. A hook that removes the agent again during removal is a no-op.Pickling. The proposal didn't cover this: models with action agents pickle on
main, and aWeakValueDictionarycan't be pickled.HasActionsgets__getstate__/__setstate__that store the tracked actions as a list and rebuild the weak mapping; a test round-trips a model with an interrupted action.Usage Examples
An override of
remove()that callscancel_action()first still works; it's no longer needed.Additional Notes
model.remove_all_agents()now fires these hooks for every busy agent, in the model's agent order.Written with help from Claude Code (Claude Opus 5.5).