[GH-ISSUE #328] server: KeyError 'tail' in OpenAI API streaming handler with multiple sessions #159

Closed
opened 2026-11-04 01:40:32 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @jinkang06 on GitHub (Oct 1, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/328

## Description

I found a small server-side bug when running multiple OpenAI-compatible API sessions simultaneously.

The model engine continues running normally, but the HTTP request handler crashes with:

KeyError: 'tail'


This happened while using OpenClaw with multiple sessions connected to the same Strata server.

## Environment

- Strata: v0.1.30
- OS: Ubuntu 22.04.5 LTS
- GPU: NVIDIA RTX A4500 20GB
- CUDA: 13.0
- Model: Qwen3.8-Flash-Next IQ3_S
- Context: 262144
- API: OpenAI-compatible endpoint
- Client: OpenClaw

## Reproduction

1. Start Strata server.
2. Connect two OpenAI-compatible clients/sessions simultaneously.
3. Send requests through both sessions.

One request succeeds, but another request may trigger:

Exception occurred during processing of request

Traceback (most recent call last):
File ".../server.py", line ...
self._note(n, evs)
File ".../server.py", line 958, in _note
s["tail"] = (s["tail"] + (ev.text or ""))[-600:]
KeyError: 'tail'


The engine itself keeps running. There is no CUDA error, OOM, or engine restart.

## Analysis

The issue appears to be caused by a request/session state dictionary being created without initializing:

```python
s["tail"]

before _note() appends streaming text.

Proposed fix

Change:

s["tail"] = (s["tail"] + (ev.text or ""))[-600:]

to:

s["tail"] = (s.get("tail", "") + (ev.text or ""))[-600:]

or initialize tail when creating the session state:

s["tail"] = ""

This should preserve existing behavior while avoiding failures when a new streaming state does not yet contain tail.

Additional notes

The model engine and conversation cache continue working after this exception. The issue appears limited to the HTTP server bookkeeping path.

I can provide full logs if needed.


Originally created by @jinkang06 on GitHub (Oct 1, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/328 ```markdown ## Description I found a small server-side bug when running multiple OpenAI-compatible API sessions simultaneously. The model engine continues running normally, but the HTTP request handler crashes with: ``` KeyError: 'tail' ``` This happened while using OpenClaw with multiple sessions connected to the same Strata server. ## Environment - Strata: v0.1.30 - OS: Ubuntu 22.04.5 LTS - GPU: NVIDIA RTX A4500 20GB - CUDA: 13.0 - Model: Qwen3.8-Flash-Next IQ3_S - Context: 262144 - API: OpenAI-compatible endpoint - Client: OpenClaw ## Reproduction 1. Start Strata server. 2. Connect two OpenAI-compatible clients/sessions simultaneously. 3. Send requests through both sessions. One request succeeds, but another request may trigger: ``` Exception occurred during processing of request Traceback (most recent call last): File ".../server.py", line ... self._note(n, evs) File ".../server.py", line 958, in _note s["tail"] = (s["tail"] + (ev.text or ""))[-600:] KeyError: 'tail' ``` The engine itself keeps running. There is no CUDA error, OOM, or engine restart. ## Analysis The issue appears to be caused by a request/session state dictionary being created without initializing: ```python s["tail"] ``` before `_note()` appends streaming text. ## Proposed fix Change: ```python s["tail"] = (s["tail"] + (ev.text or ""))[-600:] ``` to: ```python s["tail"] = (s.get("tail", "") + (ev.text or ""))[-600:] ``` or initialize `tail` when creating the session state: ```python s["tail"] = "" ``` This should preserve existing behavior while avoiding failures when a new streaming state does not yet contain `tail`. ## Additional notes The model engine and conversation cache continue working after this exception. The issue appears limited to the HTTP server bookkeeping path. I can provide full logs if needed. ```
Author
Owner

@Niko1221 commented on GitHub (Oct 1, 2026):

Fixed in 0.1.31 (#266): a request's status is recorded while it still holds the queue. Please update; reopen if it happens on 0.1.31.

<!-- gh-comment-id:5925957070 --> @Niko1221 commented on GitHub (Oct 1, 2026): Fixed in 0.1.31 (#266): a request's status is recorded while it still holds the queue. Please update; reopen if it happens on 0.1.31.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#159
No description provided.