refactor(agent): unify session message admission
This commit is contained in:
1 parent
7208fb663f
commit
b669c2036c
17 files changed
+284
-257
No files matched your search
@@ -0,0 +1,12 @@
|
||||
"""Session-worker completion helpers for integration tests."""
|
||||
|
||||
import asyncio
|
||||
|
||||
from nanobot.agent.loop import AgentLoop
|
||||
from nanobot.bus.events import InboundMessage
|
||||
|
||||
|
||||
async def run_session(loop: AgentLoop, msg: InboundMessage) -> None:
|
||||
"""Submit input and wait for its session worker to finish."""
|
||||
loop._enqueue_session_message(msg)
|
||||
await asyncio.gather(*loop._active_tasks[loop._effective_session_key(msg)])
|
||||
@@ -6,6 +6,7 @@ from unittest.mock import AsyncMock, MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
from agent.session_helpers import run_session
|
||||
from nanobot.agent.context import TranscriptInput
|
||||
from nanobot.agent.hooks import create_file_edit_activity_hook
|
||||
from nanobot.agent.loop import AgentLoop
|
||||
@@ -298,7 +299,7 @@ class TestToolEventProgress:
|
||||
chat_id="chat1",
|
||||
content="run ls",
|
||||
)
|
||||
await loop._dispatch(msg)
|
||||
await run_session(loop, msg)
|
||||
|
||||
# Drain all outbound messages and find the one carrying tool events.
|
||||
outbound = []
|
||||
@@ -421,7 +422,7 @@ class TestToolEventProgress:
|
||||
),
|
||||
)
|
||||
|
||||
await loop._dispatch(InboundMessage(
|
||||
await run_session(loop, InboundMessage(
|
||||
channel="websocket",
|
||||
sender_id="u1",
|
||||
chat_id="chat1",
|
||||
@@ -468,7 +469,7 @@ class TestToolEventProgress:
|
||||
loop = AgentLoop(bus=bus, provider=provider, workspace=tmp_path, model="openai-codex/gpt-5.5")
|
||||
loop.tools.get_definitions = MagicMock(return_value=[])
|
||||
|
||||
await loop._dispatch(InboundMessage(
|
||||
await run_session(loop, InboundMessage(
|
||||
channel="whatsapp",
|
||||
sender_id="u1",
|
||||
chat_id="chat1",
|
||||
@@ -506,7 +507,7 @@ class TestToolEventProgress:
|
||||
_attach_webui_runtime_events(loop, bus)
|
||||
loop.tools.get_definitions = MagicMock(return_value=[])
|
||||
|
||||
await loop._dispatch(InboundMessage(
|
||||
await run_session(loop, InboundMessage(
|
||||
channel="websocket",
|
||||
sender_id="u1",
|
||||
chat_id="chat1",
|
||||
@@ -559,7 +560,7 @@ class TestToolEventProgress:
|
||||
_attach_webui_runtime_events(loop, bus)
|
||||
loop.tools.get_definitions = MagicMock(return_value=[])
|
||||
|
||||
await loop._dispatch(InboundMessage(
|
||||
await run_session(loop, InboundMessage(
|
||||
channel="websocket",
|
||||
sender_id="u1",
|
||||
chat_id="chat1",
|
||||
@@ -595,7 +596,7 @@ class TestToolEventProgress:
|
||||
calls += 1
|
||||
if calls == 1:
|
||||
await on_content_delta("old partial")
|
||||
await loop._dispatch(InboundMessage(
|
||||
loop._enqueue_session_message(InboundMessage(
|
||||
channel="websocket", sender_id="u", chat_id="test", content="new question",
|
||||
))
|
||||
return LLMResponse(content="old partial", finish_reason="length")
|
||||
@@ -605,7 +606,7 @@ class TestToolEventProgress:
|
||||
|
||||
loop.provider.chat_stream_with_retry = chat
|
||||
try:
|
||||
await loop._dispatch(InboundMessage(
|
||||
await run_session(loop, InboundMessage(
|
||||
channel="websocket", sender_id="u", chat_id="test", content="old question",
|
||||
metadata={"_wants_stream": True},
|
||||
))
|
||||
@@ -652,7 +653,7 @@ class TestToolEventProgress:
|
||||
_attach_webui_runtime_events(loop, bus)
|
||||
loop.tools.get_definitions = MagicMock(return_value=[])
|
||||
|
||||
await loop._dispatch(InboundMessage(
|
||||
await run_session(loop, InboundMessage(
|
||||
channel="websocket",
|
||||
sender_id="u1",
|
||||
chat_id="chat1",
|
||||
@@ -694,7 +695,7 @@ class TestToolEventProgress:
|
||||
loop.max_iterations = 1
|
||||
loop.tools.get_definitions = MagicMock(return_value=[])
|
||||
|
||||
await loop._dispatch(InboundMessage(
|
||||
await run_session(loop, InboundMessage(
|
||||
channel="websocket",
|
||||
sender_id="u1",
|
||||
chat_id="chat1",
|
||||
@@ -739,7 +740,7 @@ class TestToolEventProgress:
|
||||
loop._process_message = cancel_after_merge # type: ignore[method-assign]
|
||||
|
||||
with pytest.raises(asyncio.CancelledError):
|
||||
await loop._dispatch(InboundMessage(
|
||||
await run_session(loop, InboundMessage(
|
||||
channel="websocket",
|
||||
sender_id="u1",
|
||||
chat_id="chat1",
|
||||
@@ -781,7 +782,7 @@ class TestToolEventProgress:
|
||||
_attach_webui_runtime_events(loop, bus)
|
||||
loop.tools.get_definitions = MagicMock(return_value=[])
|
||||
|
||||
await loop._dispatch(InboundMessage(
|
||||
await run_session(loop, InboundMessage(
|
||||
channel="websocket",
|
||||
sender_id="u1",
|
||||
chat_id="chat1",
|
||||
@@ -852,7 +853,7 @@ class TestToolEventProgress:
|
||||
session.add_message("user", "Run this in the background")
|
||||
session.metadata.update({"webui": True, "title": "Existing title"})
|
||||
loop.sessions.save(session)
|
||||
dispatch = asyncio.create_task(loop._dispatch(InboundMessage(
|
||||
dispatch = asyncio.create_task(run_session(loop, InboundMessage(
|
||||
channel="system",
|
||||
sender_id="subagent",
|
||||
chat_id=session_key,
|
||||
@@ -978,7 +979,7 @@ class TestToolEventProgress:
|
||||
_attach_webui_runtime_events(loop, bus)
|
||||
loop.tools.get_definitions = MagicMock(return_value=[])
|
||||
|
||||
await loop._dispatch(InboundMessage(
|
||||
await run_session(loop, InboundMessage(
|
||||
channel="websocket",
|
||||
sender_id="u1",
|
||||
chat_id="chat1",
|
||||
@@ -1076,7 +1077,7 @@ class TestToolEventProgress:
|
||||
_attach_webui_runtime_events(loop, bus)
|
||||
loop.tools.get_definitions = MagicMock(return_value=[])
|
||||
|
||||
await loop._dispatch(InboundMessage(
|
||||
await run_session(loop, InboundMessage(
|
||||
channel="websocket",
|
||||
sender_id="u1",
|
||||
chat_id="chat1",
|
||||
@@ -1113,7 +1114,7 @@ class TestToolEventProgress:
|
||||
|
||||
loop._process_message = raise_from_turn # type: ignore[method-assign]
|
||||
|
||||
await loop._dispatch(InboundMessage(
|
||||
await run_session(loop, InboundMessage(
|
||||
channel="websocket",
|
||||
sender_id="u1",
|
||||
chat_id="chat1",
|
||||
@@ -1159,7 +1160,7 @@ class TestToolEventProgress:
|
||||
_attach_webui_runtime_events(loop, bus)
|
||||
loop.tools.get_definitions = MagicMock(return_value=[])
|
||||
|
||||
await asyncio.wait_for(loop._dispatch(InboundMessage(
|
||||
await asyncio.wait_for(run_session(loop, InboundMessage(
|
||||
channel="websocket",
|
||||
sender_id="u1",
|
||||
chat_id="chat1",
|
||||
@@ -1228,7 +1229,7 @@ class TestToolEventProgress:
|
||||
|
||||
loop.schedule_background = schedule_background # type: ignore[method-assign]
|
||||
|
||||
await loop._dispatch(InboundMessage(
|
||||
await run_session(loop, InboundMessage(
|
||||
channel="websocket",
|
||||
sender_id="u1",
|
||||
chat_id="chat1",
|
||||
@@ -1310,7 +1311,7 @@ class TestToolEventProgress:
|
||||
|
||||
loop.schedule_background = schedule_background # type: ignore[method-assign]
|
||||
|
||||
await loop._dispatch(InboundMessage(
|
||||
await run_session(loop, InboundMessage(
|
||||
channel="websocket",
|
||||
sender_id="u1",
|
||||
chat_id="chat1",
|
||||
@@ -1345,7 +1346,7 @@ class TestToolEventProgress:
|
||||
scheduled: list[object] = []
|
||||
loop.schedule_background = scheduled.append # type: ignore[method-assign]
|
||||
|
||||
await loop._dispatch(InboundMessage(
|
||||
await run_session(loop, InboundMessage(
|
||||
channel="websocket",
|
||||
sender_id="u1",
|
||||
chat_id="chat1",
|
||||
@@ -1364,7 +1365,7 @@ class TestToolEventProgress:
|
||||
loop = AgentLoop(bus=bus, provider=provider, workspace=tmp_path, model="test-model")
|
||||
loop.tools.get_definitions = MagicMock(return_value=[])
|
||||
|
||||
await loop._dispatch(InboundMessage(
|
||||
await run_session(loop, InboundMessage(
|
||||
channel="slack",
|
||||
sender_id="u1",
|
||||
chat_id="chat1",
|
||||
|
||||
@@ -7,6 +7,7 @@ from unittest.mock import AsyncMock, MagicMock
|
||||
import pytest
|
||||
from loguru import logger
|
||||
|
||||
from agent.session_helpers import run_session
|
||||
from nanobot.agent.context import ContextBuilder, TranscriptInput
|
||||
from nanobot.agent.loop import AgentLoop
|
||||
from nanobot.agent.runner import AgentRunResult
|
||||
@@ -1511,7 +1512,7 @@ async def test_internal_continuation_preserves_streaming_route_metadata(
|
||||
|
||||
loop._run_agent_loop = fake_run_agent_loop # type: ignore[method-assign]
|
||||
|
||||
await loop._dispatch(InboundMessage(
|
||||
await run_session(loop, InboundMessage(
|
||||
channel="feishu",
|
||||
sender_id="u1",
|
||||
chat_id="c-stream",
|
||||
@@ -1573,7 +1574,7 @@ async def test_websocket_internal_continuation_keeps_single_visible_run(
|
||||
|
||||
loop._run_agent_loop = fake_run_agent_loop # type: ignore[method-assign]
|
||||
|
||||
await loop._dispatch(InboundMessage(
|
||||
await run_session(loop, InboundMessage(
|
||||
channel="websocket",
|
||||
sender_id="u1",
|
||||
chat_id="c-auto",
|
||||
|
||||
@@ -3,6 +3,7 @@ from unittest.mock import AsyncMock, MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
from agent.session_helpers import run_session
|
||||
from nanobot.agent.loop import AgentLoop
|
||||
from nanobot.bus.events import (
|
||||
INBOUND_META_RUNTIME_CONTROL,
|
||||
@@ -81,7 +82,7 @@ async def test_transient_session_stays_outside_unified_session(tmp_path) -> None
|
||||
key = "websocket:transient-unified"
|
||||
transient = loop.sessions.get_or_create_transient(key)
|
||||
|
||||
await loop._dispatch(_message(key, "private question"))
|
||||
await run_session(loop, _message(key, "private question"))
|
||||
|
||||
assert [message["content"] for message in transient.messages] == [
|
||||
"private question",
|
||||
|
||||
@@ -9,7 +9,7 @@ from unittest.mock import AsyncMock, MagicMock, patch
|
||||
import pytest
|
||||
|
||||
from agent.runner_helpers import make_run_spec
|
||||
from nanobot.agent.automation_turns import publish_next_deferred_turn
|
||||
from agent.session_helpers import run_session
|
||||
from nanobot.agent.context import TranscriptInput
|
||||
from nanobot.agent.tools.context import RequestContext
|
||||
from nanobot.config.schema import AgentDefaults
|
||||
@@ -1100,7 +1100,7 @@ async def test_no_injections_flag_is_false_by_default():
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_pending_queue_cleanup_on_dispatch(tmp_path):
|
||||
"""_pending_queues should be cleaned up after _dispatch completes."""
|
||||
"""The session worker removes its inbox after processing all messages."""
|
||||
loop = _make_loop(tmp_path)
|
||||
|
||||
async def chat_stream_with_retry(**kwargs):
|
||||
@@ -1114,7 +1114,7 @@ async def test_pending_queue_cleanup_on_dispatch(tmp_path):
|
||||
# The queue should not exist before dispatch
|
||||
assert msg.session_key not in loop._pending_queues
|
||||
|
||||
await loop._dispatch(msg)
|
||||
await run_session(loop, msg)
|
||||
|
||||
# The queue should be cleaned up after dispatch
|
||||
assert msg.session_key not in loop._pending_queues
|
||||
@@ -1132,7 +1132,7 @@ async def test_direct_dispatch_joins_active_session_queue_without_waiting_for_lo
|
||||
active_pending = asyncio.Queue()
|
||||
loop._pending_queues[session_key] = active_pending
|
||||
|
||||
await loop._dispatch(
|
||||
loop._enqueue_session_message(
|
||||
InboundMessage(channel="cli", sender_id="u", chat_id="c", content="queued")
|
||||
)
|
||||
|
||||
@@ -1149,7 +1149,6 @@ async def test_followup_routed_to_pending_queue(tmp_path):
|
||||
|
||||
loop = _make_loop(tmp_path)
|
||||
loop._unified_session = True
|
||||
loop._dispatch = AsyncMock() # type: ignore[method-assign]
|
||||
|
||||
pending = asyncio.Queue(maxsize=20)
|
||||
loop._pending_queues[UNIFIED_SESSION_KEY] = pending
|
||||
@@ -1163,7 +1162,7 @@ async def test_followup_routed_to_pending_queue(tmp_path):
|
||||
loop.stop()
|
||||
await asyncio.wait_for(run_task, timeout=2)
|
||||
|
||||
assert loop._dispatch.await_count == 0
|
||||
assert loop._active_tasks == {}
|
||||
assert queued_msg.content == "follow-up"
|
||||
assert queued_msg.session_key == UNIFIED_SESSION_KEY
|
||||
|
||||
@@ -1176,7 +1175,6 @@ async def test_websocket_followup_is_admitted_before_recovery_queue(tmp_path):
|
||||
admission = MagicMock()
|
||||
admission.admit = AsyncMock(return_value=True)
|
||||
loop = _make_loop(tmp_path, recovery_admission=admission)
|
||||
loop._dispatch = AsyncMock() # type: ignore[method-assign]
|
||||
|
||||
session_key = "websocket:chat"
|
||||
pending = asyncio.Queue(maxsize=20)
|
||||
@@ -1210,7 +1208,6 @@ async def test_unified_websocket_followup_admits_effective_session(tmp_path):
|
||||
admission.admit = AsyncMock(return_value=True)
|
||||
loop = _make_loop(tmp_path, recovery_admission=admission)
|
||||
loop._unified_session = True
|
||||
loop._dispatch = AsyncMock() # type: ignore[method-assign]
|
||||
|
||||
pending = asyncio.Queue(maxsize=20)
|
||||
loop._pending_queues[UNIFIED_SESSION_KEY] = pending
|
||||
@@ -1239,7 +1236,6 @@ async def test_mid_turn_subagent_result_does_not_resolve_a_new_turn_route(tmp_pa
|
||||
from nanobot.bus.events import InboundMessage
|
||||
|
||||
loop = _make_loop(tmp_path)
|
||||
loop._dispatch = AsyncMock() # type: ignore[method-assign]
|
||||
route_policy = MagicMock(side_effect=lambda _msg, _key, route: route)
|
||||
loop.turn_delivery_factory.route_policy = route_policy
|
||||
|
||||
@@ -1267,7 +1263,7 @@ async def test_mid_turn_subagent_result_does_not_resolve_a_new_turn_route(tmp_pa
|
||||
await asyncio.wait_for(run_task, timeout=2)
|
||||
|
||||
assert queued_msg is msg
|
||||
assert loop._dispatch.await_count == 0
|
||||
assert loop._active_tasks == {}
|
||||
route_policy.assert_not_called()
|
||||
|
||||
|
||||
@@ -1281,7 +1277,6 @@ async def test_cron_turn_deferred_while_session_active(tmp_path):
|
||||
)
|
||||
|
||||
loop = _make_loop(tmp_path)
|
||||
loop._dispatch = AsyncMock() # type: ignore[method-assign]
|
||||
|
||||
session_key = "websocket:chat-1"
|
||||
pending = asyncio.Queue(maxsize=20)
|
||||
@@ -1310,17 +1305,13 @@ async def test_cron_turn_deferred_while_session_active(tmp_path):
|
||||
await asyncio.wait_for(run_task, timeout=2)
|
||||
|
||||
assert pending.empty()
|
||||
assert loop._dispatch.await_count == 0
|
||||
assert loop._active_tasks == {}
|
||||
assert loop._cron_turns.deferred_queues[session_key] == [msg]
|
||||
assert loop.pending_cron_job_ids_for_session(session_key) == {"job-1"}
|
||||
|
||||
await publish_next_deferred_turn(
|
||||
deferred_queues=loop._cron_turns.deferred_queues,
|
||||
publish_inbound=loop.bus.publish_inbound,
|
||||
session_key=session_key,
|
||||
)
|
||||
queued = await asyncio.wait_for(loop.bus.consume_inbound(), timeout=0.5)
|
||||
assert queued is msg
|
||||
loop._process_message = AsyncMock(return_value=None)
|
||||
await loop._run_session_queue(session_key, pending)
|
||||
assert loop._process_message.await_args.args[0] is msg
|
||||
assert session_key not in loop._cron_turns.deferred_queues
|
||||
assert loop.pending_cron_job_ids_for_session(session_key) == set()
|
||||
|
||||
@@ -1332,7 +1323,6 @@ async def test_local_trigger_turn_deferred_while_session_active(tmp_path):
|
||||
from nanobot.triggers.local_session_turns import LOCAL_TRIGGER_META
|
||||
|
||||
loop = _make_loop(tmp_path)
|
||||
loop._dispatch = AsyncMock() # type: ignore[method-assign]
|
||||
|
||||
session_key = "websocket:chat-1"
|
||||
pending = asyncio.Queue(maxsize=20)
|
||||
@@ -1364,17 +1354,13 @@ async def test_local_trigger_turn_deferred_while_session_active(tmp_path):
|
||||
await asyncio.wait_for(run_task, timeout=2)
|
||||
|
||||
assert pending.empty()
|
||||
assert loop._dispatch.await_count == 0
|
||||
assert loop._active_tasks == {}
|
||||
assert loop._local_trigger_turns.deferred_queues[session_key] == [msg]
|
||||
assert loop.pending_local_trigger_ids_for_session(session_key) == {"trg_123"}
|
||||
|
||||
assert await publish_next_deferred_turn(
|
||||
deferred_queues=loop._local_trigger_turns.deferred_queues,
|
||||
publish_inbound=loop.bus.publish_inbound,
|
||||
session_key=session_key,
|
||||
) is True
|
||||
queued = await asyncio.wait_for(loop.bus.consume_inbound(), timeout=0.5)
|
||||
assert queued is msg
|
||||
loop._process_message = AsyncMock(return_value=None)
|
||||
await loop._run_session_queue(session_key, pending)
|
||||
assert loop._process_message.await_args.args[0] is msg
|
||||
assert session_key not in loop._local_trigger_turns.deferred_queues
|
||||
assert loop.pending_local_trigger_ids_for_session(session_key) == set()
|
||||
|
||||
@@ -1386,7 +1372,7 @@ async def test_submitted_cron_turn_reports_pending_until_completed(tmp_path):
|
||||
from nanobot.cron.session_turns import CRON_TRIGGER_META
|
||||
|
||||
loop = _make_loop(tmp_path)
|
||||
loop._running = True
|
||||
loop._cron_turns._enqueue = MagicMock()
|
||||
|
||||
session_key = "websocket:chat-1"
|
||||
msg = InboundMessage(
|
||||
@@ -1399,9 +1385,7 @@ async def test_submitted_cron_turn_reports_pending_until_completed(tmp_path):
|
||||
)
|
||||
|
||||
submit_task = asyncio.create_task(loop.submit_cron_turn(msg))
|
||||
queued = await asyncio.wait_for(loop.bus.consume_inbound(), timeout=0.5)
|
||||
|
||||
assert queued is msg
|
||||
await asyncio.sleep(0)
|
||||
assert loop.pending_cron_job_ids_for_session(session_key) == {"job-1"}
|
||||
|
||||
response = OutboundMessage(
|
||||
@@ -1422,7 +1406,7 @@ async def test_submitted_local_trigger_turn_reports_pending_until_completed(tmp_
|
||||
from nanobot.triggers.local_session_turns import LOCAL_TRIGGER_META
|
||||
|
||||
loop = _make_loop(tmp_path)
|
||||
loop._running = True
|
||||
loop._local_trigger_turns._enqueue = MagicMock()
|
||||
|
||||
session_key = "websocket:chat-1"
|
||||
msg = InboundMessage(
|
||||
@@ -1441,9 +1425,7 @@ async def test_submitted_local_trigger_turn_reports_pending_until_completed(tmp_
|
||||
)
|
||||
|
||||
submit_task = asyncio.create_task(loop.submit_local_trigger_turn(msg))
|
||||
queued = await asyncio.wait_for(loop.bus.consume_inbound(), timeout=0.5)
|
||||
|
||||
assert queued is msg
|
||||
await asyncio.sleep(0)
|
||||
assert loop.pending_local_trigger_ids_for_session(session_key) == {"trg_123"}
|
||||
|
||||
response = OutboundMessage(
|
||||
@@ -1465,7 +1447,7 @@ async def test_local_trigger_turn_cancellation_reports_agent_failure(tmp_path):
|
||||
from nanobot.triggers.local_session_turns import LOCAL_TRIGGER_META
|
||||
|
||||
loop = _make_loop(tmp_path)
|
||||
loop._running = True
|
||||
loop._local_trigger_turns._enqueue = MagicMock()
|
||||
|
||||
session_key = "websocket:chat-1"
|
||||
msg = InboundMessage(
|
||||
@@ -1484,7 +1466,7 @@ async def test_local_trigger_turn_cancellation_reports_agent_failure(tmp_path):
|
||||
)
|
||||
|
||||
submit_task = asyncio.create_task(loop.submit_local_trigger_turn(msg))
|
||||
assert await asyncio.wait_for(loop.bus.consume_inbound(), timeout=0.5) is msg
|
||||
await asyncio.sleep(0)
|
||||
|
||||
loop._local_trigger_turns.complete(msg, error=asyncio.CancelledError())
|
||||
|
||||
@@ -1706,7 +1688,7 @@ async def test_persistent_conversion_error_does_not_drop_later_session_inputs(tm
|
||||
calls += 1
|
||||
if calls == 1:
|
||||
for content in ["before", "bad", "after"]:
|
||||
await loop._dispatch(InboundMessage(
|
||||
loop._enqueue_session_message(InboundMessage(
|
||||
channel="cli", sender_id="u", chat_id="c", content=content,
|
||||
))
|
||||
return LLMResponse(content="answer", finish_reason="stop")
|
||||
@@ -1719,7 +1701,7 @@ async def test_persistent_conversion_error_does_not_drop_later_session_inputs(tm
|
||||
provider.chat_stream_with_retry = chat
|
||||
loop.register_runtime_context_provider(context_provider)
|
||||
try:
|
||||
await loop._dispatch(InboundMessage(
|
||||
await run_session(loop, InboundMessage(
|
||||
channel="cli", sender_id="u", chat_id="c", content="root",
|
||||
))
|
||||
loop.sessions.invalidate("cli:c")
|
||||
|
||||
@@ -5,11 +5,14 @@ from unittest.mock import AsyncMock, MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
from agent.session_helpers import run_session
|
||||
from nanobot.agent.automation_turns import AutomationTurnError
|
||||
from nanobot.agent.loop import AgentLoop
|
||||
from nanobot.agent.tools.context import current_request_context
|
||||
from nanobot.bus.events import InboundMessage
|
||||
from nanobot.agent.tools.cron import CronTool
|
||||
from nanobot.bus.events import InboundMessage, OutboundMessage
|
||||
from nanobot.bus.queue import MessageBus
|
||||
from nanobot.cron.service import CronService
|
||||
from nanobot.cron.session_turns import CRON_DEFER_UNTIL_IDLE_META, CRON_TRIGGER_META
|
||||
from nanobot.providers.base import GenerationSettings, LLMResponse, ToolCallRequest
|
||||
from nanobot.runtime_context import public_history_messages
|
||||
@@ -56,7 +59,8 @@ def _automation_message(kind: str, name: str) -> InboundMessage:
|
||||
|
||||
@pytest.mark.parametrize("first_kind", ["cron", "local_trigger"])
|
||||
@pytest.mark.parametrize("second_fails", [False, True])
|
||||
async def test_startup_automation_turns_complete_independently(loop, first_kind, second_fails):
|
||||
@pytest.mark.parametrize("bus_running", [False, True])
|
||||
async def test_automation_turns_complete_independently(loop, first_kind, second_fails, bus_running):
|
||||
started, release = asyncio.Event(), asyncio.Event()
|
||||
release_second = asyncio.Event()
|
||||
senders = []
|
||||
@@ -75,8 +79,12 @@ async def test_startup_automation_turns_complete_independently(loop, first_kind,
|
||||
loop.provider.chat_stream_with_retry = chat
|
||||
second_kind = "local_trigger" if first_kind == "cron" else "cron"
|
||||
submit = {"cron": loop.submit_cron_turn, "local_trigger": loop.submit_local_trigger_turn}
|
||||
tasks = []
|
||||
if bus_running:
|
||||
tasks.append(asyncio.create_task(loop.run()))
|
||||
await asyncio.sleep(0)
|
||||
first = asyncio.create_task(submit[first_kind](_automation_message(first_kind, "first")))
|
||||
tasks = [first]
|
||||
tasks.append(first)
|
||||
try:
|
||||
await asyncio.wait_for(started.wait(), timeout=3)
|
||||
second = asyncio.create_task(submit[second_kind](_automation_message(second_kind, "second")))
|
||||
@@ -121,7 +129,7 @@ async def test_cancelled_session_completes_queued_automation_waiters(loop):
|
||||
await asyncio.Event().wait()
|
||||
|
||||
loop.provider.chat_stream_with_retry = chat
|
||||
worker = asyncio.create_task(loop._dispatch(InboundMessage(
|
||||
worker = asyncio.create_task(run_session(loop, InboundMessage(
|
||||
channel="websocket", sender_id="u", chat_id="test", content="user request",
|
||||
)))
|
||||
tasks = [worker]
|
||||
@@ -133,7 +141,7 @@ async def test_cancelled_session_completes_queued_automation_waiters(loop):
|
||||
))
|
||||
tasks.extend([cron, trigger])
|
||||
await asyncio.sleep(0)
|
||||
assert loop._pending_queues["websocket:test"].qsize() == 2
|
||||
assert len(loop._deferred_automation_turns["websocket:test"]) == 2
|
||||
worker.cancel()
|
||||
with pytest.raises(asyncio.CancelledError):
|
||||
await worker
|
||||
@@ -152,13 +160,17 @@ async def test_cancelled_session_completes_queued_automation_waiters(loop):
|
||||
await asyncio.gather(*tasks, return_exceptions=True)
|
||||
|
||||
|
||||
async def test_stop_before_startup_worker_runs_completes_automation(loop):
|
||||
@pytest.mark.parametrize("action", ["stop", "close"])
|
||||
async def test_cancel_before_worker_runs_completes_automation(loop, action):
|
||||
loop.provider.chat_stream_with_retry = AsyncMock(return_value=LLMResponse(content="unused"))
|
||||
submit = asyncio.create_task(loop.submit_cron_turn(_automation_message("cron", "queued")))
|
||||
try:
|
||||
await asyncio.sleep(0)
|
||||
assert "websocket:test" in loop._pending_queues
|
||||
await loop._cancel_active_tasks("websocket:test")
|
||||
if action == "stop":
|
||||
await loop._cancel_active_tasks("websocket:test")
|
||||
else:
|
||||
await loop.aclose()
|
||||
with pytest.raises(AutomationTurnError, match="CancelledError"):
|
||||
await asyncio.wait_for(submit, timeout=3)
|
||||
loop.provider.chat_stream_with_retry.assert_not_awaited()
|
||||
@@ -170,6 +182,116 @@ async def test_stop_before_startup_worker_runs_completes_automation(loop):
|
||||
await asyncio.gather(submit, return_exceptions=True)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("bus_running", [False, True])
|
||||
async def test_ingress_sources_share_one_session_worker(loop, bus_running):
|
||||
started, release = asyncio.Event(), asyncio.Event()
|
||||
handled = []
|
||||
workers = []
|
||||
key = "websocket:test"
|
||||
|
||||
async def process(msg, **kwargs):
|
||||
handled.append(msg.content)
|
||||
workers.append(asyncio.current_task())
|
||||
if msg.content == "first":
|
||||
started.set()
|
||||
await release.wait()
|
||||
return OutboundMessage(channel=msg.channel, chat_id=msg.chat_id, content=msg.content)
|
||||
|
||||
loop._process_message = process
|
||||
tasks = []
|
||||
if bus_running:
|
||||
tasks.append(asyncio.create_task(loop.run()))
|
||||
try:
|
||||
first = InboundMessage(channel="websocket", sender_id="u", chat_id="test", content="first")
|
||||
if bus_running:
|
||||
await loop.bus.publish_inbound(first)
|
||||
else:
|
||||
loop._enqueue_session_message(first)
|
||||
await asyncio.wait_for(started.wait(), timeout=3)
|
||||
cron = asyncio.create_task(loop.submit_cron_turn(_automation_message("cron", "cron")))
|
||||
trigger = asyncio.create_task(loop.submit_local_trigger_turn(
|
||||
_automation_message("local_trigger", "trigger"),
|
||||
))
|
||||
tasks.extend([cron, trigger])
|
||||
await asyncio.sleep(0)
|
||||
second = InboundMessage(channel="websocket", sender_id="u", chat_id="test", content="second")
|
||||
if bus_running:
|
||||
await loop.bus.publish_inbound(second)
|
||||
async with asyncio.timeout(3):
|
||||
while loop._pending_queues[key].empty():
|
||||
await asyncio.sleep(0)
|
||||
else:
|
||||
loop._enqueue_session_message(second)
|
||||
compact = InboundMessage(channel="websocket", sender_id="u", chat_id="test", content="/compact")
|
||||
await loop._dispatch_command_inline(compact, key, compact.content, loop.commands.dispatch)
|
||||
assert len(loop._active_tasks[key]) == 1
|
||||
release.set()
|
||||
results = await asyncio.wait_for(asyncio.gather(cron, trigger), timeout=3)
|
||||
assert [result.content for result in results] == ["cron", "trigger"]
|
||||
assert handled == ["first", "second", "/compact", "cron", "trigger"]
|
||||
assert len(set(workers)) == 1
|
||||
assert loop.bus.inbound_size == 0
|
||||
assert key not in loop._pending_queues
|
||||
assert key not in loop._deferred_automation_turns
|
||||
finally:
|
||||
release.set()
|
||||
for task in tasks:
|
||||
if not task.done():
|
||||
task.cancel()
|
||||
await asyncio.gather(*tasks, return_exceptions=True)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("start_with_cron", [False, True])
|
||||
async def test_cron_restriction_follows_the_current_turn(loop, tmp_path, start_with_cron):
|
||||
cron = CronService(tmp_path / "jobs.json")
|
||||
tool = CronTool(cron)
|
||||
started, release = asyncio.Event(), asyncio.Event()
|
||||
attempts = []
|
||||
workers = []
|
||||
|
||||
async def chat(**kwargs):
|
||||
workers.append(asyncio.current_task())
|
||||
result = await tool.execute(action="add", message="reminder", every_seconds=60)
|
||||
attempts.append(result)
|
||||
if len(attempts) == 1:
|
||||
started.set()
|
||||
await release.wait()
|
||||
return LLMResponse(content="done")
|
||||
|
||||
loop.provider.chat_stream_with_retry = chat
|
||||
if start_with_cron:
|
||||
first = asyncio.create_task(loop.submit_cron_turn(_automation_message("cron", "first")))
|
||||
else:
|
||||
first = asyncio.create_task(run_session(loop, InboundMessage(
|
||||
channel="websocket", sender_id="u", chat_id="test", content="first",
|
||||
)))
|
||||
tasks = [first]
|
||||
try:
|
||||
await asyncio.wait_for(started.wait(), timeout=3)
|
||||
if not start_with_cron:
|
||||
tasks.append(asyncio.create_task(loop.submit_cron_turn(
|
||||
_automation_message("cron", "cron"),
|
||||
)))
|
||||
tasks.append(asyncio.create_task(loop.submit_local_trigger_turn(
|
||||
_automation_message("local_trigger", "trigger"),
|
||||
)))
|
||||
await asyncio.sleep(0)
|
||||
release.set()
|
||||
await asyncio.wait_for(asyncio.gather(*tasks), timeout=3)
|
||||
assert [result.startswith("Created job") for result in attempts] == (
|
||||
[False, True] if start_with_cron else [True, False, True]
|
||||
)
|
||||
blocked = attempts[0 if start_with_cron else 1]
|
||||
assert blocked == "Error: cannot schedule new jobs from within a cron job execution"
|
||||
assert len(set(workers)) == 1
|
||||
finally:
|
||||
release.set()
|
||||
for task in tasks:
|
||||
if not task.done():
|
||||
task.cancel()
|
||||
await asyncio.gather(*tasks, return_exceptions=True)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("complete_on_followup", [False, True])
|
||||
async def test_goal_continuation_after_followup_keeps_control_identity(loop, complete_on_followup):
|
||||
loop.max_iterations = 1
|
||||
|
||||
@@ -16,6 +16,7 @@ from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from agent.session_helpers import run_session
|
||||
from nanobot.agent.loop import AgentLoop
|
||||
from nanobot.bus.queue import MessageBus
|
||||
from nanobot.session.recovery import RUNTIME_CHECKPOINT_KEY
|
||||
@@ -44,13 +45,10 @@ def _make_loop(tmp_path: Path) -> AgentLoop:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_dispatch_cancellation_restores_checkpoint():
|
||||
"""Regression for #2966: /stop interrupting _dispatch must materialize the
|
||||
"""Regression for #2966: /stop interrupting a session worker must materialize the
|
||||
in-flight runtime checkpoint into session.messages before the cancellation
|
||||
unwinds, so the next turn can see the partial work.
|
||||
|
||||
This exercises the real _dispatch path (locks, pending queues, the
|
||||
CancelledError handler), so a future refactor that drops the cancel-time
|
||||
restore is caught by CI instead of silently regressing.
|
||||
"""
|
||||
from nanobot.bus.events import InboundMessage
|
||||
from nanobot.bus.queue import MessageBus
|
||||
@@ -105,7 +103,7 @@ async def test_dispatch_cancellation_restores_checkpoint():
|
||||
msg = InboundMessage(channel="test", sender_id="u1", chat_id="c1", content="work")
|
||||
|
||||
with pytest.raises(asyncio.CancelledError):
|
||||
await loop._dispatch(msg)
|
||||
await run_session(loop, msg)
|
||||
|
||||
roles = [m.get("role") for m in session.messages]
|
||||
assert roles == ["user", "assistant", "tool"], (
|
||||
@@ -145,7 +143,7 @@ async def test_dispatch_cancellation_keeps_checkpoint_for_gateway_shutdown(tmp_p
|
||||
from nanobot.bus.events import InboundMessage
|
||||
|
||||
with pytest.raises(asyncio.CancelledError):
|
||||
await loop._dispatch(
|
||||
await run_session(loop,
|
||||
InboundMessage(channel="test", sender_id="u1", chat_id="c1", content="work")
|
||||
)
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from agent.session_helpers import run_session
|
||||
from nanobot.bus.outbound_events import StreamDeltaEvent, StreamEndEvent
|
||||
from nanobot.config.schema import AgentDefaults
|
||||
from nanobot.providers.base import GenerationSettings
|
||||
@@ -271,7 +272,7 @@ class TestDispatch:
|
||||
loop._process_message = AsyncMock(
|
||||
return_value=OutboundMessage(channel="test", chat_id="c1", content="hi")
|
||||
)
|
||||
await loop._dispatch(msg)
|
||||
await run_session(loop, msg)
|
||||
out = await asyncio.wait_for(bus.consume_outbound(), timeout=1.0)
|
||||
assert out.content == "hi"
|
||||
|
||||
@@ -300,7 +301,7 @@ class TestDispatch:
|
||||
|
||||
loop._process_message = fake_process
|
||||
|
||||
await loop._dispatch(msg)
|
||||
await run_session(loop, msg)
|
||||
first = await asyncio.wait_for(bus.consume_outbound(), timeout=1.0)
|
||||
second = await asyncio.wait_for(bus.consume_outbound(), timeout=1.0)
|
||||
|
||||
@@ -332,9 +333,9 @@ class TestDispatch:
|
||||
msg1 = InboundMessage(channel="test", sender_id="u1", chat_id="c1", content="a")
|
||||
msg2 = InboundMessage(channel="test", sender_id="u1", chat_id="c1", content="b")
|
||||
|
||||
t1 = asyncio.create_task(loop._dispatch(msg1))
|
||||
t1 = asyncio.create_task(run_session(loop, msg1))
|
||||
await asyncio.wait_for(first_started.wait(), timeout=1.0)
|
||||
t2 = asyncio.create_task(loop._dispatch(msg2))
|
||||
t2 = asyncio.create_task(run_session(loop, msg2))
|
||||
await asyncio.sleep(0)
|
||||
assert order == ["start-a"]
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
"""Tests for unified_session feature.
|
||||
|
||||
Covers:
|
||||
- AgentLoop._dispatch() rewrites session_key to "unified:default" when enabled
|
||||
- Session admission rewrites session_key to "unified:default" when enabled
|
||||
- Existing session_key_override is respected (not overwritten)
|
||||
- Feature is off by default (no behavior change for existing users)
|
||||
- Config schema serialises unified_session as camelCase "unifiedSession"
|
||||
- onboard-generated config.json contains "unifiedSession" key
|
||||
- /new command correctly clears the shared session in unified mode
|
||||
- /new is NOT a priority command (goes through _dispatch, key rewrite applies)
|
||||
- /new is NOT a priority command; the effective session key applies
|
||||
- Context window consolidation is unaffected by unified_session
|
||||
"""
|
||||
|
||||
@@ -19,6 +19,7 @@ from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from agent.session_helpers import run_session
|
||||
from nanobot.agent.loop import AgentLoop
|
||||
from nanobot.agent.tools.file_state import FileStateStore
|
||||
from nanobot.bus.events import InboundMessage
|
||||
@@ -78,7 +79,7 @@ def _make_msg(channel: str = "telegram", chat_id: str = "111",
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
class TestUnifiedSessionDispatch:
|
||||
"""AgentLoop._dispatch() session key rewriting logic."""
|
||||
"""Session admission applies the unified-session routing policy."""
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_unified_session_rewrites_key_to_unified_default(self, tmp_path: Path):
|
||||
@@ -94,7 +95,7 @@ class TestUnifiedSessionDispatch:
|
||||
loop._process_message = fake_process # type: ignore[method-assign]
|
||||
|
||||
msg = _make_msg(channel="telegram", chat_id="111")
|
||||
await loop._dispatch(msg)
|
||||
await run_session(loop, msg)
|
||||
|
||||
assert captured == ["unified:default"]
|
||||
|
||||
@@ -111,9 +112,9 @@ class TestUnifiedSessionDispatch:
|
||||
|
||||
loop._process_message = fake_process # type: ignore[method-assign]
|
||||
|
||||
await loop._dispatch(_make_msg(channel="telegram", chat_id="111"))
|
||||
await loop._dispatch(_make_msg(channel="discord", chat_id="222"))
|
||||
await loop._dispatch(_make_msg(channel="cli", chat_id="direct"))
|
||||
await run_session(loop, _make_msg(channel="telegram", chat_id="111"))
|
||||
await run_session(loop, _make_msg(channel="discord", chat_id="222"))
|
||||
await run_session(loop, _make_msg(channel="cli", chat_id="direct"))
|
||||
|
||||
assert captured == ["unified:default", "unified:default", "unified:default"]
|
||||
|
||||
@@ -131,7 +132,7 @@ class TestUnifiedSessionDispatch:
|
||||
loop._process_message = fake_process # type: ignore[method-assign]
|
||||
|
||||
msg = _make_msg(channel="telegram", chat_id="999")
|
||||
await loop._dispatch(msg)
|
||||
await run_session(loop, msg)
|
||||
|
||||
assert captured == ["telegram:999"]
|
||||
|
||||
@@ -149,7 +150,7 @@ class TestUnifiedSessionDispatch:
|
||||
loop._process_message = fake_process # type: ignore[method-assign]
|
||||
|
||||
msg = _make_msg(channel="telegram", chat_id="111", session_key_override="telegram:thread:42")
|
||||
await loop._dispatch(msg)
|
||||
await run_session(loop, msg)
|
||||
|
||||
assert captured == ["telegram:thread:42"]
|
||||
|
||||
@@ -222,8 +223,7 @@ class TestCmdNewUnifiedSession:
|
||||
"""/new command routing and session-clear behaviour in unified mode."""
|
||||
|
||||
def test_new_is_not_a_priority_command(self):
|
||||
"""/new must NOT be in the priority table — it must go through _dispatch()
|
||||
so the unified session key rewrite applies before cmd_new runs."""
|
||||
"""/new uses the effective session key before its command handler runs."""
|
||||
router = CommandRouter()
|
||||
register_builtin_commands(router)
|
||||
assert router.is_priority("/new") is False
|
||||
@@ -267,7 +267,7 @@ class TestCmdNewUnifiedSession:
|
||||
|
||||
msg = InboundMessage(
|
||||
channel="telegram", sender_id="user1", chat_id="111", content="/new",
|
||||
session_key_override="unified:default", # as _dispatch() would set it
|
||||
session_key_override="unified:default",
|
||||
)
|
||||
ctx = CommandContext(
|
||||
msg=msg,
|
||||
@@ -350,23 +350,10 @@ class TestStopCommandWithUnifiedSession:
|
||||
# Create a message from telegram channel
|
||||
msg = _make_msg(channel="telegram", chat_id="123456")
|
||||
|
||||
# Mock _dispatch to complete immediately
|
||||
async def fake_dispatch(m):
|
||||
pass
|
||||
|
||||
loop._dispatch = fake_dispatch # type: ignore[method-assign]
|
||||
|
||||
# Simulate the task creation flow (from _run loop)
|
||||
effective_key = UNIFIED_SESSION_KEY if loop._unified_session and not msg.session_key_override else msg.session_key
|
||||
task = asyncio.create_task(loop._dispatch(msg))
|
||||
loop._active_tasks.setdefault(effective_key, set()).add(task)
|
||||
|
||||
# Wait for task to complete
|
||||
await task
|
||||
|
||||
# Verify the task is stored under UNIFIED_SESSION_KEY, not the original channel:chat_id
|
||||
assert UNIFIED_SESSION_KEY in loop._active_tasks
|
||||
assert "telegram:123456" not in loop._active_tasks
|
||||
loop._process_message = AsyncMock(return_value=None)
|
||||
loop._enqueue_session_message(msg)
|
||||
assert set(loop._active_tasks) == {UNIFIED_SESSION_KEY}
|
||||
await asyncio.gather(*loop._active_tasks[UNIFIED_SESSION_KEY])
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_stop_command_finds_task_in_unified_mode(self, tmp_path: Path):
|
||||
|
||||
@@ -146,7 +146,7 @@ class TestRestartCommand:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_restart_intercepted_in_run_loop(self):
|
||||
"""Verify /restart is handled at the run-loop level, not inside _dispatch."""
|
||||
"""Verify /restart is handled at the run-loop level, without starting a session worker."""
|
||||
loop, bus = _make_loop()
|
||||
loop.restart_mode = "exec"
|
||||
msg = InboundMessage(channel="telegram", sender_id="u1", chat_id="c1", content="/restart")
|
||||
@@ -166,7 +166,7 @@ class TestRestartCommand:
|
||||
create_task=_capture_task,
|
||||
)
|
||||
|
||||
with patch.object(loop, "_dispatch", new_callable=AsyncMock) as mock_dispatch, \
|
||||
with patch.object(loop, "_enqueue_session_message", new_callable=MagicMock) as mock_dispatch, \
|
||||
patch("nanobot.command.builtin.asyncio", new=fake_asyncio), \
|
||||
patch("nanobot.command.builtin.os.execv"):
|
||||
await bus.publish_inbound(msg)
|
||||
@@ -192,7 +192,7 @@ class TestRestartCommand:
|
||||
loop, bus = _make_loop()
|
||||
msg = InboundMessage(channel="telegram", sender_id="u1", chat_id="c1", content="/status")
|
||||
|
||||
with patch.object(loop, "_dispatch", new_callable=AsyncMock) as mock_dispatch:
|
||||
with patch.object(loop, "_enqueue_session_message", new_callable=MagicMock) as mock_dispatch:
|
||||
await bus.publish_inbound(msg)
|
||||
|
||||
loop._running = True
|
||||
|
||||
@@ -5,6 +5,7 @@ from datetime import datetime, timedelta
|
||||
from unittest.mock import AsyncMock, MagicMock
|
||||
|
||||
import pytest
|
||||
from agent.session_helpers import run_session
|
||||
|
||||
from nanobot.agent.loop import AgentLoop
|
||||
from nanobot.bus.events import InboundMessage
|
||||
@@ -155,7 +156,7 @@ async def test_empty_compact_finishes_silently_and_does_not_schedule_idle_archiv
|
||||
completions = []
|
||||
loop.bus.subscribe(completions.append, TurnCompleted)
|
||||
|
||||
await loop._dispatch(InboundMessage(
|
||||
await run_session(loop, InboundMessage(
|
||||
channel="websocket", sender_id="user", chat_id="test", content="/compact",
|
||||
metadata={"webui_turn_id": "compact-turn"},
|
||||
))
|
||||
@@ -246,17 +247,17 @@ async def test_compact_is_a_fifo_barrier_during_an_active_turn(loop) -> None:
|
||||
return LLMResponse(content="answer", finish_reason="stop")
|
||||
|
||||
loop.provider.chat_stream_with_retry = chat
|
||||
task = asyncio.create_task(loop._dispatch(InboundMessage(
|
||||
task = asyncio.create_task(run_session(loop, InboundMessage(
|
||||
channel="cli", sender_id="u", chat_id="test", content="initial question",
|
||||
)))
|
||||
try:
|
||||
await asyncio.wait_for(started.wait(), timeout=5)
|
||||
await loop._dispatch(InboundMessage(
|
||||
loop._enqueue_session_message(InboundMessage(
|
||||
channel="cli", sender_id="u", chat_id="test", content="before compaction",
|
||||
))
|
||||
command = InboundMessage(channel="cli", sender_id="u", chat_id="test", content="/compact")
|
||||
await loop._dispatch_command_inline(command, key, command.content, loop.commands.dispatch)
|
||||
await loop._dispatch(InboundMessage(
|
||||
loop._enqueue_session_message(InboundMessage(
|
||||
channel="cli", sender_id="u", chat_id="test", content="after compaction",
|
||||
))
|
||||
release.set()
|
||||
@@ -290,10 +291,10 @@ async def test_stop_completes_compact_queued_behind_an_active_turn(loop) -> None
|
||||
loop.provider.chat_stream_with_retry = chat
|
||||
completions = []
|
||||
loop.bus.subscribe(completions.append, TurnCompleted)
|
||||
task = asyncio.create_task(loop._dispatch(InboundMessage(
|
||||
loop._enqueue_session_message(InboundMessage(
|
||||
channel="websocket", sender_id="u", chat_id="test", content="question",
|
||||
)))
|
||||
loop._track_active_task(key, task)
|
||||
))
|
||||
task = next(iter(loop._active_tasks[key]))
|
||||
await asyncio.wait_for(started.wait(), timeout=5)
|
||||
command = InboundMessage(
|
||||
channel="websocket", sender_id="u", chat_id="test", content="/compact",
|
||||
@@ -329,8 +330,8 @@ async def test_stop_finishes_inflight_compaction_as_cancelled(loop) -> None:
|
||||
channel="websocket", sender_id="user", chat_id="test", content="/compact",
|
||||
metadata={"webui_turn_id": "compact-turn"},
|
||||
)
|
||||
task = asyncio.create_task(loop._dispatch(msg))
|
||||
loop._track_active_task(key, task)
|
||||
loop._enqueue_session_message(msg)
|
||||
task = next(iter(loop._active_tasks[key]))
|
||||
await asyncio.wait_for(entered.wait(), timeout=5)
|
||||
|
||||
reply = await cmd_stop(CommandContext(
|
||||
|
||||
Reference in new issue
Block a user