You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: emit cancel:requested/cancel:completed events and call trigger_callbacks()
The kernel defines CANCEL_REQUESTED and CANCEL_COMPLETED event constants
and CancellationToken.trigger_callbacks(), but no orchestrator emitted
those events or called the callback mechanism — making them dead code.
Changes:
- Import CANCEL_REQUESTED and CANCEL_COMPLETED from amplifier_core.events
- Add _cancel_requested_emitted instance flag (reset per execution) to
ensure cancel:requested is only emitted once per turn, regardless of
how many cancellation check points are hit
- At all four cancellation exit paths in execute():
1. Top-of-loop is_cancelled check
2. Post-provider is_immediate check (immediate cancel after LLM call)
3. asyncio.CancelledError block (immediate cancel during tool gather)
4. Post-tool-gather is_immediate check (graceful cancel path)
Sequence at each path (first detection only for cancel:requested):
1. Emit cancel:requested with orchestrator, state, and turn_count
2. Call trigger_callbacks() to run registered cleanup callbacks
(errors in callbacks are caught and logged; they don't block exit)
3. Emit cancel:completed with was_immediate flag
This wires up the cancel event infrastructure so hooks can react to
cancellation for cleanup (e.g. closing containers, releasing resources).
0 commit comments