feat(manager): resolve correlation in outbound dispatch

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-22 07:22:42 +00:00
parent e1987c7fa5
commit ca8376c4a6
2 changed files with 29 additions and 2 deletions
+5 -2
View File
@@ -204,13 +204,16 @@ class ChannelManager:
self.bus.consume_outbound(),
timeout=1.0
)
# Resolve any pending correlation (hook request-response)
self.bus.resolve_correlation(msg)
if msg.metadata.get("_progress"):
if msg.metadata.get("_tool_hint") and not self.config.channels.send_tool_hints:
continue
if not msg.metadata.get("_tool_hint") and not self.config.channels.send_progress:
continue
channel = self.channels.get(msg.channel)
if channel:
try:
+24
View File
@@ -0,0 +1,24 @@
"""Tests for correlation resolution in outbound dispatch."""
import asyncio
import pytest
from unittest.mock import AsyncMock, MagicMock
from nanobot.bus.queue import MessageBus
from nanobot.bus.events import OutboundMessage
@pytest.mark.asyncio
async def test_dispatch_resolves_correlation_before_channel_send():
"""Correlation Future should be resolved when outbound message is dispatched."""
bus = MessageBus()
future = bus.register_correlation("corr-1")
msg = OutboundMessage(channel="telegram", chat_id="123", content="response", metadata={"correlation_id": "corr-1"})
await bus.publish_outbound(msg)
# Simulate what _dispatch_outbound does: consume + resolve
consumed = await asyncio.wait_for(bus.consume_outbound(), timeout=1.0)
bus.resolve_correlation(consumed)
assert future.done()
assert future.result() == "response"