feat: add full cancellation support to recipe executor #5
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.
Summary
Adds graceful cancellation support to recipe execution, enabling users to cancel long-running recipes at any nesting depth via Ctrl+C or the
recipes(operation="cancel")tool call.Changes
SessionManager (
session.py)CancellationStatusenum with states: NONE, REQUESTED, IMMEDIATE, CANCELLEDrequest_cancellation(session_id, project_path, immediate=False)- Request graceful or immediate cancellationclear_cancellation(session_id, project_path)- Clear cancellation status for resumptionget_cancellation_status(session_id, project_path)- Get current statusis_cancellation_requested(session_id, project_path)- Check if cancellation requestedis_immediate_cancellation(session_id, project_path)- Check if immediate cancellationmark_cancelled(session_id, project_path, cancelled_at_step)- Mark session as cancelledRecipeExecutor (
executor.py)CancellationRequestedErrorexception with context (session_id, is_immediate, current_step)_check_cancellation()method to check session state_check_coordinator_cancellation()to integrate with amplifier-core's CancellationTokenparent_session_idpropagation for nested recipe cancellationRecipesTool (
__init__.py)CancellationRequestedErrorandCancellationStatuscanceloperation with optionalimmediateflagTests
test_cancellation.py) with 18 testsTesting
All 304 tests pass (286 existing + 18 new cancellation tests).
Usage
Cancellation also integrates with CLI's Ctrl+C signal handling via the coordinator's CancellationToken.
🤖 Generated with Amplifier
Co-Authored-By: Amplifier [email protected]