openclaw - ✅(Solved) Fix [Bug]: Open-WebUI creates new session per message instead of reusing persistent session [1 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#78091Fetched 2026-05-06 06:17:01
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
2
Author
Timeline (top)
labeled ×2commented ×1cross-referenced ×1

When using OpenClaw as an OpenAI-compatible backend for Open-WebUI, each user message creates a new session with a random UUID (agent:< agentId>:openai:<uuid>), instead of reusing a single persistent session for the chat. This results in:

  • Massive session proliferation (44 sessions from a single conversation)
  • No conversation continuity — each turn starts fresh
  • WebUI works around this by injecting [Chat messages since your last reply - for context] into each message, but this is fragile and burn s tokens
  • Session store bloat and wasted disk space

Root Cause

Root Cause Hypothesis

Fix Action

Fix / Workaround

Each session's first user message contains WebUI's workaround:

  • Token waste: System prompt + full context re-sent every turn
  • Session store bloat: Dozens of dead sessions per conversation
  • No memory continuity: Agent cannot maintain state between turns
  • Workaround fragility: WebUI's context injection is lossy and doesn't include tool calls or internal state

PR fix notes

PR #78124: fix(openai-compat): derive stable session from X-Chat-Id / X-Thread-Id headers (#78091)

Description (problem / solution / changelog)

Summary

  • Each request to the OpenAI-compat /v1/chat/completions endpoint generated a random-UUID session key when the user field was absent, causing Open-WebUI (and similar frontends) to create a new isolated session per message instead of reusing one session per conversation.
  • Now checks X-Chat-Id (Open-WebUI) and X-Thread-Id (Langchain / other clients) headers first; when either is present a deterministic session key <prefix>-chat:<id> is derived, so all turns in one conversation land in the same session.
  • X-OpenClaw-Session-Key and the user-field path are fully preserved and still take higher precedence.

Closes #78091

Testing

pnpm vitest run src/gateway/http-utils.request-context.test.ts
 Test Files  3 passed (3)
      Tests  51 passed (51)
   Start at  19:24:25
   Duration  3.97s

Real behavior proof

  • Behavior: Open-WebUI sends X-Chat-Id: <uuid> per the Open-WebUI OpenAI backend docs when configured to use a custom OpenAI-compatible backend; without this fix every message creates agent:<id>:openai:<random-uuid>, reproducing 44+ dead sessions per conversation as shown in the issue.
  • Tested via targeted vitest test added in this PR. No live OpenClaw runtime available — please apply maintainer proof: override or advise on evidence format.

Changed files

  • src/gateway/http-utils.request-context.test.ts (modified, +50/-0)
  • src/gateway/http-utils.ts (modified, +15/-0)

Code Example

## Evidence

Session keys observed:

agent:sky:openai:17a95d23-8031-46cd-926c-9640e6ead873
agent:sky:openai:525e5460-bbc4-47ff-ad2e-122fe8565b0e
agent:sky:openai:db5dcd06-a0ea-4b2b-9064-e5248ad4c081
... (44 total from one conversation)


Each session's first user message contains WebUI's workaround:

[Chat messages since your last reply - for context]
User: Hello?
Assistant: Hey Wurdzy. 🦞

I'm here. Ready when you are.
User: <actual new message>


## Environment

- OpenClaw version: 2026.5.2 (observed), still present in 2026.5.4
- OS: Linux (EL10, x86_64)
- Provider: llama.cpp via OpenAI-compatible API (openai-completions)
- Frontend: Open-WebUI connecting via OpenAI API to OpenClaw gateway

## Root Cause Hypothesis

The OpenAI-compatible endpoint in the gateway generates a new session key per request instead of extracting and reusing a conversation/thread ID from the incoming request. Open-WebUI may not be sending a consistent `thread_id` or `metadata` that OpenClaw can use to correlate requests to the same conversation.

Possible fixes:
1. OpenClaw could use a stable identifier from the request (e.g., `X-Chat-Id` header, or a consistent `metadata` field)
2. OpenClaw could fall back to a single persistent `agent:<agentId>:openai:default` session when no conversation ID is provided
3. OpenClaw could hash the requesting IP + user agent as a session key for stateless clients

## Impact

- **Token waste**: System prompt + full context re-sent every turn
- **Session store bloat**: Dozens of dead sessions per conversation
- **No memory continuity**: Agent cannot maintain state between turns
- **Workaround fragility**: WebUI's context injection is lossy and doesn't include tool calls or internal state
RAW_BUFFERClick to expand / collapse

Bug type

Behavior bug (incorrect output/state without crash)

Beta release blocker

No

Summary

When using OpenClaw as an OpenAI-compatible backend for Open-WebUI, each user message creates a new session with a random UUID (agent:< agentId>:openai:<uuid>), instead of reusing a single persistent session for the chat. This results in:

  • Massive session proliferation (44 sessions from a single conversation)
  • No conversation continuity — each turn starts fresh
  • WebUI works around this by injecting [Chat messages since your last reply - for context] into each message, but this is fragile and burn s tokens
  • Session store bloat and wasted disk space

Steps to reproduce

  1. Configure OpenClaw with an OpenAI-compatible provider (e.g., llama.cpp on port 11437)
  2. Set up Open-WebUI to use the OpenClaw gateway as its OpenAI backend
  3. Start a conversation in Open-WebUI
  4. Send multiple messages
  5. Check ~/.openclaw/agents/<agentId>/sessions/sessions.json — each message created a separate agent:<agentId>:openai:<uuid> session

Expected behavior

  • All messages in a single WebUI chat should route to the same session
  • Session key should be derived from the WebUI chat/conversation ID, not randomly generated per request
  • Conversation history should persist naturally in the session transcript

Actual behavior

  • Each message creates a new session with key agent:<agentId>:openai:<random-uuid>
  • Each session is independent — no shared context between turns
  • Sessions are marked done after each turn
  • WebUI compensates by injecting prior conversation as context in each new message

OpenClaw version

2026.5.2

Operating system

EL10

Install method

npm

Model

qwen3.6:27b

Provider / routing chain

Open-WebUI -> openclaw -> llama.cpp

Additional provider/model setup details

No response

Logs, screenshots, and evidence

## Evidence

Session keys observed:

agent:sky:openai:17a95d23-8031-46cd-926c-9640e6ead873
agent:sky:openai:525e5460-bbc4-47ff-ad2e-122fe8565b0e
agent:sky:openai:db5dcd06-a0ea-4b2b-9064-e5248ad4c081
... (44 total from one conversation)


Each session's first user message contains WebUI's workaround:

[Chat messages since your last reply - for context]
User: Hello?
Assistant: Hey Wurdzy. 🦞

I'm here. Ready when you are.
User: <actual new message>


## Environment

- OpenClaw version: 2026.5.2 (observed), still present in 2026.5.4
- OS: Linux (EL10, x86_64)
- Provider: llama.cpp via OpenAI-compatible API (openai-completions)
- Frontend: Open-WebUI connecting via OpenAI API to OpenClaw gateway

## Root Cause Hypothesis

The OpenAI-compatible endpoint in the gateway generates a new session key per request instead of extracting and reusing a conversation/thread ID from the incoming request. Open-WebUI may not be sending a consistent `thread_id` or `metadata` that OpenClaw can use to correlate requests to the same conversation.

Possible fixes:
1. OpenClaw could use a stable identifier from the request (e.g., `X-Chat-Id` header, or a consistent `metadata` field)
2. OpenClaw could fall back to a single persistent `agent:<agentId>:openai:default` session when no conversation ID is provided
3. OpenClaw could hash the requesting IP + user agent as a session key for stateless clients

## Impact

- **Token waste**: System prompt + full context re-sent every turn
- **Session store bloat**: Dozens of dead sessions per conversation
- **No memory continuity**: Agent cannot maintain state between turns
- **Workaround fragility**: WebUI's context injection is lossy and doesn't include tool calls or internal state

Impact and severity

No response

Additional information

No response

extent analysis

TL;DR

The most likely fix involves modifying OpenClaw to reuse a single persistent session for each conversation by extracting a stable identifier from the incoming request.

Guidance

  • Investigate the request headers and metadata sent by Open-WebUI to identify a consistent identifier that can be used as a session key.
  • Consider implementing a fallback mechanism in OpenClaw to use a default session key when no conversation ID is provided.
  • Evaluate the feasibility of hashing the requesting IP and user agent as a session key for stateless clients.
  • Review the OpenAI-compatible endpoint in the OpenClaw gateway to ensure it can handle session key extraction and reuse.

Example

No code snippet is provided due to the lack of specific implementation details in the issue.

Notes

The solution may require modifications to both OpenClaw and Open-WebUI to ensure consistent session key generation and reuse. The choice of session key mechanism will depend on the specific requirements and constraints of the system.

Recommendation

Apply a workaround by modifying OpenClaw to use a stable identifier from the request, such as a custom header or metadata field, to correlate requests to the same conversation. This approach allows for a more robust and efficient solution than relying on IP and user agent hashing or default session keys.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

  • All messages in a single WebUI chat should route to the same session
  • Session key should be derived from the WebUI chat/conversation ID, not randomly generated per request
  • Conversation history should persist naturally in the session transcript

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - ✅(Solved) Fix [Bug]: Open-WebUI creates new session per message instead of reusing persistent session [1 pull requests, 1 comments, 2 participants]