fix(triggers): require channel enablement predicate

This commit is contained in:
chengyongru
2026-07-19 22:33:29 +08:00
committed by chengyongru
parent 91514ad0b1
commit 7aaac37bca
4 changed files with 31 additions and 10 deletions
+1 -1
View File
@@ -2076,7 +2076,7 @@ def _run_gateway(
run_local_trigger_queue(
store=trigger_store,
submit_turn=getattr(agent, "submit_local_trigger_turn", None),
is_channel_available=lambda name: name in channels.channels,
is_channel_enabled=lambda name: channels.get_channel(name) is not None,
),
name="nanobot-local-triggers",
),
+4 -4
View File
@@ -21,7 +21,7 @@ async def run_local_trigger_queue(
*,
store: LocalTriggerStore,
submit_turn: Callable[[InboundMessage], Awaitable[OutboundMessage | None]] | None = None,
is_channel_available: Callable[[str], bool] | None = None,
is_channel_enabled: Callable[[str], bool],
poll_interval_s: float = 0.5,
batch_size: int = 20,
) -> None:
@@ -47,7 +47,7 @@ async def run_local_trigger_queue(
store,
delivery,
submit_turn=submit_turn,
is_channel_available=is_channel_available,
is_channel_enabled=is_channel_enabled,
)
store.complete_delivery(delivery)
except asyncio.CancelledError as exc:
@@ -132,14 +132,14 @@ async def _deliver_delivery(
delivery: TriggerDelivery,
*,
submit_turn: Callable[[InboundMessage], Awaitable[OutboundMessage | None]],
is_channel_available: Callable[[str], bool] | None = None,
is_channel_enabled: Callable[[str], bool],
) -> None:
trigger = store.get(delivery.trigger_id)
if trigger is None:
raise _TerminalDeliveryError("trigger not found")
if not trigger.enabled:
raise _TerminalDeliveryError("trigger is disabled")
if is_channel_available is not None and not is_channel_available(trigger.channel):
if not is_channel_enabled(trigger.channel):
raise _TerminalDeliveryError(f"target channel is not enabled: {trigger.channel}")
store.write_delivery_run_record(delivery, trigger=trigger, status="processing")