fix: preserve real cancellation in MCP paths

This commit is contained in:
adabarbulescu
2026-07-18 17:36:35 +08:00
committed by Xubin Ren
parent 07ad0bafa8
commit d4f5abe004
5 changed files with 80 additions and 9 deletions
+5 -1
View File
@@ -81,6 +81,7 @@ from nanobot.session.manager import (
replay_max_messages_for_context,
)
from nanobot.triggers.local_turns import LocalTriggerTurnCoordinator
from nanobot.utils.cancellation import task_is_cancelling
from nanobot.utils.document import extract_documents, reference_non_image_attachments
from nanobot.utils.helpers import image_placeholder_text
from nanobot.utils.helpers import truncate_text as truncate_text_fn
@@ -998,8 +999,11 @@ class AgentLoop:
except asyncio.CancelledError:
# Preserve real task cancellation so shutdown can complete cleanly.
# Only ignore non-task CancelledError signals that may leak from integrations.
if not self._running or asyncio.current_task().cancelling():
if not self._running or task_is_cancelling():
raise
logger.warning(
"Ignoring leaked CancelledError while consuming inbound messages"
)
continue
except Exception as e:
logger.warning("Error consuming inbound message: {}, continuing...", e)