From c80fc883ba2a051f6f4b6bea99b1eec808857f68 Mon Sep 17 00:00:00 2001 From: nanobot Date: Mon, 3 Aug 2026 23:29:14 +0800 Subject: [PATCH] local triggers: support mid-turn interruption via origin_metadata {"interrupt": true} --- nanobot/triggers/local_turns.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/nanobot/triggers/local_turns.py b/nanobot/triggers/local_turns.py index a468d42e..63f429f7 100644 --- a/nanobot/triggers/local_turns.py +++ b/nanobot/triggers/local_turns.py @@ -44,7 +44,15 @@ def _should_defer_local_trigger_turn( session_key: str, active_session_keys: Iterable[str], ) -> bool: - return local_trigger(msg.metadata) is not None and session_key in active_session_keys + if not (local_trigger(msg.metadata) is not None and session_key in active_session_keys): + return False + # Mid-turn interruption requested: the trigger was created with + # origin_metadata {"interrupt": true} (copied verbatim into msg.metadata + # by the local runner). Skip deferral so the message routes into the + # session's pending queue and is injected at the next tool-call boundary. + if msg.metadata.get("interrupt"): + return False + return True def _local_trigger_id(msg: InboundMessage) -> str | None: