Skip to content

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

Closed
Beandon13 wants to merge 1 commit into
openclaw:mainfrom
Beandon13:fix/openclaw-78091-openwebui-session-reuse
Closed

Beandon13 wants to merge 1 commit into
openclaw:mainfrom
Beandon13:fix/openclaw-78091-openwebui-session-reuse

Conversation

@Beandon13

Copy link
Copy Markdown
Contributor

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.

…d headers (openclaw#78091)

OpenAI-compatible frontends like Open-WebUI that do not set the `user`
field caused a new random-UUID session to be created on every request,
leading to session proliferation (44+ sessions per conversation) and
lost conversation continuity.

`resolveSessionKey` now checks the `X-Chat-Id` header (sent by
Open-WebUI) and the `X-Thread-Id` header (Langchain, etc.) before
falling back to a random UUID.  `X-OpenClaw-Session-Key` still takes
highest precedence, and the existing `user`-field path is unchanged.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 5, 2026
@clawsweeper

clawsweeper Bot commented May 5, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Keep open: this PR targets a real source-level OpenAI-compatible session-continuity problem and is the direct candidate for the linked Open-WebUI issue, but it is not merge-ready because the patch changes established session precedence, misses Open-WebUI's default forwarded chat-id header, broadens shared Responses behavior, and still lacks real after-fix proof.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #78091
Summary: This PR is the direct open fix candidate for the linked Open-WebUI per-message random-session issue; related Open-WebUI/session reports are adjacent or broader and do not safely supersede it.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Canonical path: Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review.

So I’m closing this here because the remaining work is already tracked in the canonical issue.

Review details

Best possible solution:

Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review.

Do we have a high-confidence way to reproduce the issue?

Yes at source level: /v1/chat/completions passes payload.user into the shared resolver, and current main falls back to a random UUID when no explicit OpenClaw session key or OpenAI user exists. I did not run a live Open-WebUI setup in this read-only review.

Is this the best way to solve the issue?

No, not as-is: header-based correlation is plausible, but this patch changes precedence, misses Open-WebUI's default forwarded header, and broadens the shared resolver without enough endpoint coverage. The safer path is a maintainer-confirmed session contract with explicit precedence and live proof.

Security review:

Security review cleared: No dependency, workflow, secret, permission, lockfile, generated-code, or supply-chain surface is changed by this source/test-only diff.

AGENTS.md: found and applied where relevant.

What I checked:

  • stale F-rated PR: PR was opened 2026-05-05T23:25:07Z, is older than 60 days, and the latest review rated it F.
  • proof blocker: real behavior proof is mock_only and proof tier is F, so this branch is not merge-ready without contributor follow-up.
  • no human follow-up: live comments and timeline hydrated by apply contain no non-automation activity after the ClawSweeper review.

Likely related people:

  • vincentkoc: Introduced and recently maintained major OpenAI-compatible Gateway routing and endpoint surfaces, including the agent-first contract and current release snapshot containing these files. (role: feature owner / recent area contributor; confidence: high; commits: d10669629d73, eaad4ad1be38, e085fa1a3ffd; files: src/gateway/http-utils.ts, src/gateway/openai-http.ts, src/gateway/openresponses-http.ts)
  • steipete: Path history and shortlog show repeated Gateway HTTP/docs maintenance and compatibility fixes around the same endpoint family. (role: area history contributor; confidence: medium; commits: 0633406ff608, afca9540bf82, 39ad51426c64; files: src/gateway/http-utils.ts, src/gateway/openai-http.ts, src/gateway/openresponses-http.ts)
  • RichardCao: Co-authored the recent reserved-session-key override hardening commit that touched this resolver, adjacent tests, both HTTP endpoints, and public docs. (role: recent session-routing contributor; confidence: medium; commits: 8694fe7e81f2; files: src/gateway/http-utils.ts, src/gateway/http-utils.request-context.test.ts, src/gateway/openai-http.ts)
  • zhang-guiping: Recently changed the shared OpenAI-compatible request-context path for agent selector validation across Chat Completions and Responses. (role: recent Gateway HTTP contributor; confidence: medium; commits: 8eb1fa09c66e; files: src/gateway/http-utils.ts, src/gateway/openai-http.ts, src/gateway/openresponses-http.ts)
  • Lellansin Huang: Recently changed Chat Completions and Responses behavior/tests around the same endpoint family. (role: adjacent OpenAI-compatible HTTP contributor; confidence: medium; commits: 0dfcf73a5762, fe3c3ac5cdf1; files: src/gateway/openai-http.ts, src/gateway/openresponses-http.ts, src/gateway/openai-http.test.ts)

Codex review notes: model internal, reasoning high; reviewed against 010b61746379.

@RomneyDa

Copy link
Copy Markdown
Member

Heads up: this PR needs to be updated against current main before the new required Dependency Guard check can pass.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Jun 14, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added stale Marked as stale due to inactivity triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. and removed stale Marked as stale due to inactivity labels Jul 20, 2026
@clawsweeper

clawsweeper Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

@Beandon13 thanks for the PR. ClawSweeper is still waiting on real behavior proof before this can move forward.

Useful proof can be a screenshot, short video, terminal output, copied live output, linked artifact, or redacted logs that show the changed behavior after the fix. Please redact private tokens, phone numbers, private endpoints, customer data, and anything else sensitive.

Once proof is added to the PR body or a comment, ClawSweeper or a maintainer can re-check it.

@steipete

Copy link
Copy Markdown
Contributor

Closing per ClawSweeper review verdict duplicate_or_superseded (decision packet 2026-07-03T21:09:18.835Z). This item was part of the audited close backlog (openclaw/clawsweeper#920) stranded by an apply-lane defect, drained manually after re-verification. If this is wrong, reopen and ClawSweeper will re-review.

@steipete steipete closed this Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Open-WebUI creates new session per message instead of reusing persistent session

3 participants