fix(api): route each session_id to its own chat

Derive the request chat route from the existing API session key for both
JSON responses and SSE. Keep JSON identity conversion, multipart trimming,
the shared default session and persisted history unchanged.

Exercise concurrent HTTP/SSE requests through the real agent runtime, tools
and storage with an offline model. Verify old-history replay, restart,
rollback, session ordering and stable model-request prefixes.

Refs HKUDS/nanobot#5798
This commit is contained in:
ljluestc authored and Xubin Ren committed 2026-10-24 21:59:12 +08:00
1 parent 67f6a0d26e
commit 0e0df327c8
6 files changed
+252 -9

No files matched your search

+9 -3
View File
@@ -322,7 +322,12 @@ async def test_multipart_defaults_text_when_missing(aiohttp_client, mock_agent,
@pytest.mark.skipif(not HAS_AIOHTTP, reason="aiohttp not installed")
@pytest.mark.asyncio
async def test_multipart_with_session_id(aiohttp_client, mock_agent, tmp_path) -> None:
@pytest.mark.parametrize(("session_id", "chat_id"), [
("my-session", "my-session"), (" my-session ", "my-session"), (" ", "default"),
])
async def test_multipart_with_session_id(
aiohttp_client, mock_agent, tmp_path, session_id, chat_id,
) -> None:
"""Multipart upload with session_id uses custom session key."""
import os
original_cwd = os.getcwd()
@@ -338,11 +343,12 @@ async def test_multipart_with_session_id(aiohttp_client, mock_agent, tmp_path) -
resp = await client.post(
"/v1/chat/completions",
headers=AUTH_HEADERS,
data={"message": "hello", "session_id": "my-session", "files": data},
data={"message": "hello", "session_id": session_id, "files": data},
)
assert resp.status == 200
call_kwargs = mock_agent.process_direct.call_args.kwargs
assert call_kwargs["session_key"] == "api:my-session"
assert call_kwargs["session_key"] == f"api:{chat_id}"
assert call_kwargs["chat_id"] == chat_id
finally:
os.chdir(original_cwd)