refactor(sessions)!: retire the global shared session (#6621)

Co-authored-by: chengyongru <chengyongru.ai@gmail.com>
This commit is contained in:
Xubin Renandchengyongru authored and GitHub committed 2026-11-12 09:55:55 +08:00
1 parent 28d73b6942
commit e6b0aec2a8
77 files changed
+311 -1255

No files matched your search

+3 -8
View File
@@ -8,7 +8,6 @@ from nanobot.bus.queue import MessageBus
from nanobot.channels.websocket.runtime import WebSocketChannel, WebSocketConfig
from nanobot.cli.gateway_runtime import _deliver_to_channel
from nanobot.session.display_history import HISTORY_GENERATION_METADATA_KEY
from nanobot.session.keys import UNIFIED_SESSION_KEY
from nanobot.session.manager import SessionManager
from nanobot.webui.gateway_services import build_gateway_services
@@ -125,16 +124,12 @@ async def webui_delivery(delivery, tmp_path, monkeypatch):
@pytest.mark.parametrize("caption", ["caption", ""])
async def test_unified_webui_media_keeps_its_display_generation(webui_delivery, caption):
async def test_webui_media_keeps_its_display_generation(webui_delivery, caption):
sessions, bus, tool, channel = webui_delivery
alias = await sessions.state.get_header("websocket:chat")
canonical = await sessions.state.get_header(UNIFIED_SESSION_KEY)
tool.set_send_callback(partial(
_deliver_to_channel, bus=bus, session_manager=sessions, unified_session=True,
))
with request_context(RequestContext(
"websocket", "chat", session_key=canonical.key,
session_generation=canonical.generation,
"websocket", "chat", session_key=alias.key,
session_generation=alias.generation,
metadata={HISTORY_GENERATION_METADATA_KEY: alias.generation},
)):
result = await tool.execute(content=caption, media=["attachment.txt"])
-36
View File
@@ -1998,42 +1998,6 @@ def test_heartbeat_target_skips_archived_webui_sessions():
assert target == ("websocket", "active")
def test_heartbeat_target_uses_last_channel_for_unified_session():
from nanobot.cli.gateway_runtime import _pick_heartbeat_target_from_sessions
from nanobot.session.keys import LAST_CHANNEL_METADATA_KEY, UNIFIED_SESSION_KEY
target = _pick_heartbeat_target_from_sessions(
enabled_channels=["telegram", "discord"],
archived_keys=[],
sessions=[{"key": UNIFIED_SESSION_KEY}],
unified_session_metadata={LAST_CHANNEL_METADATA_KEY: "discord:chat-42"},
)
assert target == ("discord", "chat-42")
@pytest.mark.parametrize(
"metadata",
[
{"last_channel": "telegram:chat-42"},
{"last_channel": "cli:direct"},
{"last_channel": "invalid"},
],
)
def test_heartbeat_target_rejects_unroutable_unified_metadata(metadata):
from nanobot.cli.gateway_runtime import _pick_heartbeat_target_from_sessions
from nanobot.session.keys import UNIFIED_SESSION_KEY
target = _pick_heartbeat_target_from_sessions(
enabled_channels=["discord"],
archived_keys=[],
sessions=[{"key": UNIFIED_SESSION_KEY}],
unified_session_metadata=metadata,
)
assert target == ("cli", "direct")
def _write_instance_config(tmp_path: Path) -> Path:
config_file = tmp_path / "instance" / "config.json"
config_file.parent.mkdir(parents=True)