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

+1 -1
View File
@@ -57,7 +57,7 @@ curl http://127.0.0.1:8900/v1/chat/completions \
- If `/v1/chat/completions` fails, test `nanobot agent -m "Hello!"` first.
- If remote clients cannot connect, check `api.host`, `api.port`, firewall, and API key configuration.
- If sessions mix together, pass unique `session_id` values.
- If sessions mix together, pass a distinct, stable `session_id` for each conversation. Requests without `session_id` all share the `api:default` session. See [session behavior](../openai-api.md#sessions-failures-and-retries) before changing existing IDs.
## Related nanobot docs
+3 -1
View File
@@ -44,7 +44,7 @@ curl http://127.0.0.1:8900/v1/models \
## Behavior
- Conversation history: pass `"session_id"` in the request body to select a conversation; omit for a shared default session (`api:default`). This is not user authentication or a separate workspace.
- Conversation history: pass `"session_id"` in the request body to select a conversation; omit for a shared default session (`api:default`). The request's chat route matches that session for both JSON replies and SSE. This is not user authentication or a separate workspace.
- Single-message input: each request must contain exactly one `user` message
- Fixed model: omit `model`, or pass the same model shown by `/v1/models`
- Streaming: set `stream=true` to receive Server-Sent Events (`text/event-stream`) with OpenAI-compatible delta chunks, terminated by `data: [DONE]`; omit or set `stream=false` for a single JSON response
@@ -59,6 +59,8 @@ The API can start before provider/model setup is complete. Health checks remain
All callers use the same configured API key, agent, workspace, long-term memory, and tool permissions. Any authorized caller can select any `session_id`; the server does not bind it to a user identity. A distinct ID separates conversation history, not access to files or memory. Use [separate instances](./multiple-instances.md) for separate trust boundaries, or enforce user-to-session authorization in your own application before forwarding requests.
Send a stable, non-empty string ID for each conversation. JSON IDs retain surrounding spaces, so `"chat-a"` and `" chat-a "` select different histories. Multipart IDs retain their existing whitespace trimming. Omitted or empty IDs use `api:default`, as does the explicit ID `"default"`. Existing session keys and stored histories are unchanged; no migration is required.
Requests with the same session ID are serialized within one API process. Different sessions can run concurrently and share workspace files; session locking does not make file changes transactional. Send one turn at a time per conversation when ordering matters.
| Failure | Client-visible result |