Skip to content

Commit e6b1323

Browse files
committed
fix(a2a): remove unnecessary duck-typing in cancel(), fix stale comment
- Remove AttributeError/NotImplementedError catch since self.agent is typed as Agent which always has cancel() - Update comment from 'we guard with hasattr' to reflect actual impl - Update docstring to remove 'if available' language Addresses review feedback from @mkmeral on executor.py:327
1 parent a66e210 commit e6b1323

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

src/strands/multiagent/a2a/executor.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,8 @@ async def cancel(self, context: RequestContext, event_queue: EventQueue) -> None
296296
"""Cancel an ongoing execution.
297297
298298
Transitions the task to the canceled state and attempts to stop the agent.
299-
The agent's cancel() method is called if available to signal cooperative
300-
cancellation of in-flight execution.
299+
The agent's cancel() method is called to signal cooperative cancellation
300+
of in-flight execution.
301301
302302
Note: This transitions the A2A task state. The underlying agent execution
303303
may still complete its current model call before stopping.
@@ -314,13 +314,10 @@ async def cancel(self, context: RequestContext, event_queue: EventQueue) -> None
314314
logger.warning("context_id=<%s> | cancel requested but no current task found", context.context_id)
315315
raise ServerError(error=UnsupportedOperationError()) from None
316316

317-
# Attempt to cooperatively cancel the agent's execution (best-effort).
318-
# Agent.cancel() may not exist on all implementations, so we guard with hasattr.
317+
# Cooperatively cancel the agent's execution (best-effort).
318+
# Agent.cancel() is always available since self.agent is typed as Agent.
319319
try:
320320
self.agent.cancel()
321-
except (AttributeError, NotImplementedError):
322-
# Agent doesn't support cancel — proceed with state transition only
323-
pass
324321
except Exception:
325322
logger.debug("task_id=<%s> | agent cancel signal failed (non-critical)", task.id)
326323

0 commit comments

Comments
 (0)