feat(manager): resolve correlation in outbound dispatch
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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"
|
||||
Reference in New Issue
Block a user