Skip to content

Preserve Open WebUI UUID sessions across Control UI - #55351

Closed
SHAREN wants to merge 9 commits into
openclaw:mainfrom
SHAREN:codex/openclaw-webui-session-fix-v2026.3.24
Closed

SHAREN wants to merge 9 commits into
openclaw:mainfrom
SHAREN:codex/openclaw-webui-session-fix-v2026.3.24

Conversation

@SHAREN

@SHAREN SHAREN commented Mar 26, 2026

Copy link
Copy Markdown

Summary

  • preserve Open WebUI UUID chat ids instead of canonicalizing them to agent:main:<uuid> in the gateway session store
  • normalize agent:main:<uuid> back to the original bare UUID when the Control UI reads or writes chat URLs
  • pass agent context into transcript lookup so agent-scoped histories resolve the correct transcript file
  • add regression coverage for UUID preservation, transcript fallback, and Control UI URL normalization

Problem

Open WebUI uses opaque UUIDs for chat ids. When the same chat is opened through the OpenClaw Control UI, OpenClaw currently treats that UUID like an ordinary bare session key and canonicalizes it into an agent-prefixed key.

In practice, one Open WebUI conversation can end up with two identities:

  • aa28595d-ef49-4381-b332-e3c990300d74
  • agent:main:aa28595d-ef49-4381-b332-e3c990300d74

Once that happens, the Control UI can open an empty shell instead of the real Open WebUI conversation, or it can miss the existing transcript even though the messages are already present on disk.

This is a narrow integration bug rather than a broad session cleanup issue. It shows up when Open WebUI is used as a multi-chat frontend for OpenClaw and the same UUID-backed chat is later opened in the Control UI.

Why this matters

Open WebUI is a useful ChatGPT-style frontend for OpenClaw because it makes it easy to keep multiple long-running topic-specific chats in the browser. Without this fix, that workflow still requires a downstream monkey patch after upgrades, because the shared Open WebUI/OpenClaw session identity drifts apart.

What changed

  1. Gateway session-key resolution now preserves opaque bare UUIDs instead of rewriting them to agent-scoped keys.
  2. The Control UI normalizes agent:main:<uuid> URLs back to the original bare UUID and keeps that normalized form in the address bar.
  3. Session history loading now carries agentId through transcript lookup so agent-scoped stores resolve the right transcript path for these chats.
  4. Regression tests cover the gateway store key, transcript fallback, and Control UI URL behavior.

Scope

This PR intentionally stays focused on shared session identity and transcript lookup for Open WebUI-backed chats.

It does not try to mirror external turns into Open WebUI's own SQLite history database. That visual-sync behavior is a separate follow-up concern.

Testing

  • pnpm exec vitest run --config vitest.gateway.config.ts src/gateway/session-utils.fs.test.ts -t "uses agentId fallback to read agent-scoped transcripts from OPENCLAW_HOME"
  • pnpm exec vitest run --config vitest.gateway.config.ts src/gateway/session-utils.test.ts -t "preserves opaque bare UUID session keys"
  • pnpm exec vitest run --config vitest.unit.config.ts ui/src/ui/app-settings.test.ts
  • manual verification against a deployed Open WebUI + OpenClaw setup on v2026.3.24: opening the same UUID-backed chat in the Control UI reused the existing history instead of splitting into a second session

Fixes #49202

What changed:
- preserve opaque bare UUID session keys in gateway session-store resolution instead of canonicalizing them to agent-scoped keys
- normalize Control UI chat URLs from agent:main:<uuid> back to the original bare UUID and keep that normalized form when syncing the URL
- pass agent context into transcript lookup so agent-scoped session stores resolve the correct transcript file
- add regression coverage for the gateway, transcript-path fallback, and Control UI URL normalization flows
- include the new app-settings regression file in the active Vitest unit suites

Why:
- Open WebUI uses opaque UUID chat ids for its conversations while OpenClaw's gateway and Control UI usually canonicalize bare keys into agent-prefixed session keys
- that mismatch can split one Open WebUI conversation into a bare UUID session and an agent:main:<uuid> session, which makes history look missing or incomplete depending on which path is opened
- the bug is narrow to the Open WebUI integration path, but it breaks the multi-chat workflow that makes Open WebUI useful as a ChatGPT-style frontend for OpenClaw

Impact:
- Open WebUI and OpenClaw Control UI now converge on the same session key for main-agent UUID chats
- opening an Open WebUI chat in Control UI reuses the existing history instead of creating a second session shell
- session history loading follows the agent-scoped transcript location consistently for these chats

Validation:
- pnpm exec vitest run --config vitest.gateway.config.ts src/gateway/session-utils.fs.test.ts -t "uses agentId fallback to read agent-scoped transcripts from OPENCLAW_HOME"
- pnpm exec vitest run --config vitest.gateway.config.ts src/gateway/session-utils.test.ts -t "preserves opaque bare UUID session keys"
- pnpm exec vitest run --config vitest.unit.config.ts ui/src/ui/app-settings.test.ts
- manually verified on the deployed Open WebUI + Control UI flow that the same UUID chat opens with shared history instead of splitting into a second session
@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui gateway Gateway runtime size: S labels Mar 26, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 652d131924

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +660 to +661
if (looksLikeSessionId(rawLower)) {
return rawLower;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep legacy agent-scoped UUID keys addressable

Returning bare UUIDs here drops the legacy agent:<id>:<uuid> alias path for upgraded stores. In deployments that already persisted keys like agent:main:<uuid>, a bare UUID from Open WebUI (or the Control UI URL normalization added in ui/src/ui/app-settings.ts) no longer resolves to the existing store entry, because lookup scans only the bare key/case variants and never the agent-prefixed UUID form; sessions.get then returns an empty history for an existing chat. Please preserve a fallback alias/migration path so pre-existing prefixed UUID sessions remain readable after upgrade.

Useful? React with 👍 / 👎.

@greptile-apps

greptile-apps Bot commented Mar 26, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a narrow but real session-identity split that occurs when the same UUID-backed Open WebUI chat is opened in the OpenClaw Control UI. Three orthogonal changes accomplish this: (1) the gateway's resolveSessionStoreKey / canonicalizeSessionKeyForAgent now short-circuits for bare UUID keys via looksLikeSessionId, preventing them from acquiring an agent:main: prefix; (2) the Control UI's new normalizeChatUrlSessionKey helper strips the prefix on the read path (URL → settings) and write path (settings → URL); (3) readSessionMessages / resolveSessionTranscriptCandidates gain an optional agentId so agent-scoped transcripts are resolved correctly even when the session key itself is a bare UUID.\n\nThe changes are well-scoped, and the regression tests cover all three code paths.\n\nKey finding:\n- The local looksLikeUuid helper in app-settings.ts uses a stricter RFC 4122 v1–5 regex while the gateway's SESSION_ID_RE accepts any 8-4-4-4-12 hex UUID. UUID v6 and v7 (used by newer storage backends) pass the gateway guard but fail the UI guard, so normalizeChatUrlSessionKey would leave their agent:main: prefix intact — recreating the same split-identity issue for those UUID variants. Aligning the regex with SESSION_ID_RE (or importing looksLikeSessionId) would close this gap.

Confidence Score: 4/5

Safe to merge for the current Open WebUI (UUID v4) use case; one regex tightness issue could reintroduce the bug for v6/v7 UUIDs in a future Open WebUI release.

The fix is correct and well-tested for the stated scope (UUID v4 Open WebUI sessions). A single concrete divergence between the UI's looksLikeUuid regex and the gateway's SESSION_ID_RE leaves v6/v7 UUIDs un-normalized in the Control UI URL path, which could silently recreate the split-identity problem if Open WebUI adopts newer UUID variants. Addressing that before merge would make the fix future-proof.

ui/src/ui/app-settings.ts — the looksLikeUuid regex should be aligned with SESSION_ID_RE.

Important Files Changed

Filename Overview
src/gateway/session-utils.ts Adds looksLikeSessionId guard in both canonicalizeSessionKeyForAgent and resolveSessionStoreKey to bypass agent-prefixing for bare UUID keys. Logic is correct and the guard is placed before any canonicalization path.
src/gateway/session-utils.fs.ts Threads the optional agentId param through readSessionMessages → resolveSessionTranscriptCandidates. Existing callers pass undefined and retain current behavior; the new gateway handler passes an inferred agentId to find agent-scoped transcripts.
src/gateway/server-methods/sessions.ts Infers agentId from the target's canonical key (falling back to the default agent) before calling readSessionMessages. For bare UUID keys parseAgentSessionKey returns null so the default agent is used — correct for the Open WebUI use case.
ui/src/ui/app-settings.ts Adds normalizeChatUrlSessionKey to strip agent:main:<uuid> prefixes from URL session params and propagates it through applySettingsFromUrl, syncUrlWithTab, and syncUrlWithSessionKey. One issue: the local looksLikeUuid regex is more restrictive than the gateway's SESSION_ID_RE, leaving v6/v7 UUIDs un-normalized.
src/gateway/session-utils.test.ts Two new unit tests validate bare UUID preservation in resolveSessionStoreKey and in the combined store. Coverage is solid for the primary happy path.
src/gateway/session-utils.fs.test.ts New filesystem integration test validates the agentId fallback transcript lookup path using a temp dir and OPENCLAW_HOME stub. Test properly restores env with finally/unstubAllEnvs.
ui/src/ui/app-settings.test.ts Adds coverage for normalizeChatUrlSessionKey (round-trip and identity cases), applySettingsFromUrl URL normalization, and syncUrlWithSessionKey. The added setTestWindowUrl in setTabFromRoute's beforeEach also improves test isolation.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: ui/src/ui/app-settings.ts
Line: 41-43

Comment:
**UUID regex diverges from gateway-side `SESSION_ID_RE`**

The gateway uses `SESSION_ID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i` (accepts any hex UUID), while this helper enforces RFC 4122 versions `[1-5]` and variant bits `[89ab]`. Any UUID that the gateway preserves as a bare key but whose version nibble is outside the range `1–5` — notably **UUID v6** and **UUID v7** — will not be stripped of the `agent:main:` prefix by this function.

Concretely: if a future Open WebUI release uses v7 UUIDs (a growing pattern), a URL with an `agent:main:<v7-uuid>` session param would not be normalized by `normalizeChatUrlSessionKey`, and the user would end up with the prefixed form stored in settings — recreating the same split-identity bug this PR is meant to fix.

The simplest fix is to align with the already-established `SESSION_ID_RE` semantics, either by importing `looksLikeSessionId` from `../../../src/sessions/session-id.js` or by dropping the version and variant constraints here:

```suggestion
function looksLikeUuid(value: string): boolean {
  return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(value);
}
```

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "Preserve Open WebUI UUID sessions across..." | Re-trigger Greptile

Comment thread ui/src/ui/app-settings.ts Resolved
What changed:
- add a legacy agent-scoped UUID alias to gateway session-store scan targets so upgraded stores still resolve old `agent:<id>:<uuid>` entries
- switch Control UI URL normalization to the shared `looksLikeSessionId` helper instead of a narrower local UUID regex
- add regression tests for the legacy alias path and for future UUID variants that still match the gateway session id format

Why:
- automated review surfaced two real edge cases in the original Open WebUI fix
- upgraded installs could lose history for chats that were previously stored under `agent:main:<uuid>` once the Control UI starts normalizing those URLs back to bare UUIDs
- the UI regex also diverged from the gateway-side session id matcher, which could recreate the same split bug for newer UUID versions

Impact:
- pre-existing prefixed Open WebUI chat keys remain readable after upgrade
- the Control UI and gateway now agree on which UUID strings should be treated as opaque session ids

Validation:
- pnpm exec vitest run --config vitest.gateway.config.ts src/gateway/session-utils.test.ts -t "resolveSessionStoreKey preserves opaque bare UUID session keys"
- pnpm exec vitest run --config vitest.gateway.config.ts src/gateway/session-utils.test.ts -t "resolveGatewaySessionStoreTarget keeps legacy agent-scoped UUID aliases addressable"
- pnpm exec vitest run --config vitest.unit.config.ts ui/src/ui/app-settings.test.ts -t "normalizeChatUrlSessionKey"
@SHAREN

SHAREN commented Mar 27, 2026

Copy link
Copy Markdown
Author

Addressed both automated review comments in e9bd322.

  • Added a legacy agent-scoped UUID alias in the gateway lookup path so upgraded stores with existing agent-prefixed UUID keys remain readable after the Control UI normalizes back to bare UUIDs.
  • Switched the Control UI URL normalization check to the shared gateway session-id helper and added coverage for a future UUID variant that still matches the gateway session-id format.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e9bd3225e0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +740 to +742
const legacyAgentScopedUuidKey = looksLikeSessionId(params.canonicalKey)
? `agent:${params.agentId}:${params.canonicalKey}`
: null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Add bare UUID lookup for agent-scoped UUID keys

buildGatewaySessionStoreScanTargets only adds the legacy alias in one direction (<uuid> → agent:<id>:<uuid>). After this change, bare-key mutations can prune the prefixed legacy key, but lookups that still use agent:main:<uuid> (older Control UI links/clients) never probe the bare UUID key, so sessions.get/preview resolve as missing and show empty history. Please include the reciprocal fallback (agent:<id>:<uuid> → <uuid>) so upgraded stores remain readable from both key forms.

Useful? React with 👍 / 👎.

What changed:
- extend gateway session-store scan targets to probe the bare UUID form when the incoming key is the legacy agent-scoped UUID alias
- add a regression test that covers prefixed legacy links resolving a store entry that already lives under the bare UUID key

Why:
- the earlier Open WebUI fix preserved upgraded prefixed UUID sessions when a bare UUID lookup arrived, but older Control UI links could still arrive in the opposite direction as agent:main:<uuid>
- without the reciprocal fallback, upgraded stores could still look empty for those legacy links even though the chat had already converged onto the bare UUID form

Impact:
- Open WebUI UUID chats remain readable from both old prefixed links and the normalized bare UUID form during and after migration

Validation:
- pnpm exec vitest run --config vitest.gateway.config.ts src/gateway/session-utils.test.ts
- pnpm exec vitest run --config vitest.gateway.config.ts src/gateway/session-utils.fs.test.ts
- pnpm exec vitest run --config vitest.unit.config.ts ui/src/ui/app-settings.test.ts
- note: src/gateway/session-utils.test.ts still includes a pre-existing unrelated baseline failure in uses persisted active subagent runs when the local worker only has terminal snapshots; the new Open WebUI UUID tests pass in that run
@SHAREN

SHAREN commented Mar 27, 2026

Copy link
Copy Markdown
Author

Addressed the reciprocal bare/prefixed Open WebUI UUID lookup path in abdc6ae. @codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: abdc6ae340

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread ui/src/ui/app-settings.ts
Comment on lines +51 to +52
if (parsed.agentId !== "main") {
return raw;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Normalize legacy UUID links for any default agent

normalizeChatUrlSessionKey only strips the agent: prefix when agentId === "main", but legacy UUID links were previously generated with whatever agent was configured as default (for example agent:ops:<uuid>). In those setups this migration path is skipped, so Control UI keeps the prefixed key and can continue flipping session aliases instead of converging on the bare UUID form, which defeats the intended Open WebUI session unification for non-main defaults.

Useful? React with 👍 / 👎.

Resolve the two PR merge conflicts in vitest include lists by keeping the new upstream unit test patterns (`packages/**/*.test.ts`, `ui/src/ui/chat/**/*.test.ts`) alongside the Open WebUI regression entry for `ui/src/ui/app-settings.test.ts`.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 572bdf66ba

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +643 to +644
if (looksLikeSessionId(lowered)) {
return lowered;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve agent scope for UUID keys in combined store

Returning bare UUIDs in canonicalizeSessionKeyForAgent drops the originating agent identity while loadCombinedSessionStoreForGateway is merging per-agent stores. With default per-agent store paths, this makes a UUID session from a previously-default agent appear as an unscoped key in sessions.list; later sessions.get/patch/delete resolve that bare key against the current default agent store and can return empty history or miss the row entirely. This regression is user-visible after changing the default agent (or when multiple agent stores are present), so UUID keys need to retain enough agent scoping for round-trips.

Useful? React with 👍 / 👎.

Comment on lines +668 to +669
if (looksLikeSessionId(rawLower)) {
return rawLower;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Canonicalize UUID aliases before message subscription keys

The new UUID early-return keeps <uuid> canonical as bare, while agent:main:<uuid> still canonicalizes to its prefixed form, so the same session can now have two canonical keys. Session-message subscriptions and transcript fan-out use exact string keys (see sessions.messages.subscribe and sessionMessageSubscribers.get(...)), which means a legacy client subscribed on agent:main:<uuid> will miss live message events emitted under the bare UUID key. Normalizing both aliases to one canonical subscription key (or subscribing/emitting both forms) avoids this split stream.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 519a0b903b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +668 to +669
if (looksLikeSessionId(rawLower)) {
return rawLower;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Resolve mainKey alias before UUID normalization

The new UUID fast-path returns early for any bare UUID-shaped key, so a configured session.mainKey that happens to look like a UUID no longer maps to the canonical main session key. In that configuration, resolveSessionStoreKey({ sessionKey: <mainKey> }) now returns the bare UUID instead of agent:<default>:<mainKey>, which splits history and breaks clients that use the configured main-key alias. This regression is introduced by checking looksLikeSessionId(...) before the existing rawMainKey alias handling.

Useful? React with 👍 / 👎.

SHAREN added 4 commits April 3, 2026 00:03
What changed:
- reintroduced a runtime agent.getApiKey hook in the embedded attempt path so custom providers can resolve credentials through modelRegistry.getApiKeyForProvider
- wrapped agent.streamFn in applyExtraParamsToAgent with a dedicated Codex proxy transport selector
- added codex-proxy-transport.ts so openai-codex-responses models on non-ChatGPT base URLs can use the proxy-aware WebSocket transport instead of the default simple transport
- preserved bearer auth while synthesizing a separate chatgpt-account-id when proxy transports do not provide one explicitly
- cleaned up a constant-truthiness error branch in the proxy transport so the staged files pass the repository lint gate

Why:
- direct embedded codex-lb runs had been failing because the embedded runtime lost provider credentials after the auth-aware stream path was replaced
- even after credentials were restored, Codex-style proxy backends still needed a different transport contract than the default ChatGPT/OpenAI path
- these changes keep generic embedded runs working while allowing non-OpenAI Codex proxy endpoints to speak the backend /codex/responses transport they actually expect

Impact:
- embedded sessions can once again resolve runtime API keys for custom providers such as codex-lb
- models using openai-codex-responses on proxy base URLs can take the dedicated WebSocket transport path instead of being forced through the default streamSimple contract
- standard providers continue using the existing transport path unless the model explicitly matches the proxy Codex criteria
What changed:
- imported resolveAgentRoute into the gateway send handler
- when callers omit explicitAgentId and sessionKey but provide an accountId, derive a routedAgentId from the configured channel/account route before falling back to the default agent
- kept the existing explicit agent and session-derived agent precedence intact

Why:
- outbound sends that targeted a bound account such as the paperclip Telegram account could still mirror into the default main agent session when no sessionKey was supplied
- that made manual sends land in the wrong agent context even though the route configuration already knew which agent owned the account

Impact:
- account-scoped sends can now inherit the bound agent route automatically
- mirrored session keys and agent ownership stay aligned with the configured channel route instead of drifting back to the default agent when sessionKey is omitted
What changed:
- added a compat auth resolver inside compaction-safeguard.ts that accepts getApiKeyAndHeaders, getApiKeyForProvider, or the legacy getApiKey method on ctx.modelRegistry
- preserved the existing headers-aware safeguard contract so compaction can still proceed when auth is supplied through request headers rather than only a raw API key
- switched the safeguard entrypoint to use that compat resolver before deciding whether compaction must be cancelled
- exported the resolver through __testing and added focused regression coverage in compaction-safeguard.test.ts for new-model-registry auth resolution and the unsupported-interface error case

Why:
- manual and automatic compaction were still calling ctx.modelRegistry.getApiKey(model) directly
- newer pi-coding-agent model registries no longer expose that method, which caused compaction safeguard to cancel with ctx.modelRegistry.getApiKey is not a function
- the embedded runtime had already been patched to use getApiKeyForProvider, so compaction was the remaining incompatible auth path

Impact:
- compaction safeguard can resolve request auth on both old and new model registry interfaces
- custom providers such as codex-lb no longer fail compaction solely because the registry dropped the legacy getApiKey method
- the fix is covered by targeted safeguard tests that passed on the server checkout before commit
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XL and removed size: M labels Apr 2, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1f24a8e1f5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

let socket: WebSocketLike;

try {
socket = new WebSocketCtor(url, { headers: wsHeaders });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Use a WebSocket client that supports custom headers

connectWebSocket instantiates globalThis.WebSocket with { headers: ... }, but in Node/Bun the standard WebSocket constructor only accepts a protocols argument, so these auth headers are not transmitted. That means Authorization/chatgpt-account-id from buildWebSocketHeaders are effectively dropped for proxied openai-codex-responses calls, which can cause authentication/tenant routing failures for every request using this transport.

Useful? React with 👍 / 👎.

model: model.id,
store: false,
stream: true,
instructions: context.systemPrompt,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid duplicating the system prompt in Codex payloads

The request body sets instructions: context.systemPrompt, while convertResponsesMessages(...) already injects the same context.systemPrompt as an input system/developer message. Sending both duplicates prompt content on every call, which increases token usage and can change model behavior (or hit context limits sooner) for long prompts.

Useful? React with 👍 / 👎.

@clawsweeper

clawsweeper Bot commented Apr 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 5, 2026, 12:28 PM ET / 16:28 UTC.

Summary
The branch preserves Open WebUI UUID session keys across gateway session resolution, Control UI URL normalization, and transcript lookup, while also adding Codex proxy/auth, compaction-auth, and send-routing runtime changes.

PR surface: Source +1278, Tests +252, Other +2. Total +1532 across 15 files.

Reproducibility: yes. at source level: current main still sends non-agent raw session keys through agent-scoped canonicalization, matching the linked Open WebUI UUID split. I did not run a live Open WebUI setup in this read-only review.

Review metrics: 3 noteworthy metrics.

  • Unrelated provider/auth runtime surface: 1 added transport, 4 runtime auth/routing hooks. The branch changes credential and provider transport behavior outside the Open WebUI UUID session bug.
  • Session identity surfaces: 3 changed surfaces. Gateway canonicalization, Control UI URL persistence, and transcript lookup all affect stored session identity and upgrade behavior.
  • Legacy provider route: 1 live legacy provider id added. Adding openai-codex to live Codex proxy handling conflicts with the current migration policy that treats it as legacy input.

Stored data model
Persistent data-model change detected: serialized state: src/gateway/session-utils.fs.test.ts, serialized state: src/gateway/session-utils.fs.ts, serialized state: src/gateway/session-utils.test.ts, serialized state: src/gateway/session-utils.ts, unknown-data-model-change: src/gateway/session-utils.test.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #49202
Summary: This PR is the open candidate fix for the closed Open WebUI UUID split report; broader raw external alias reports overlap but are not a safe superseding landing path for this branch today.

Members:

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

Merge readiness
Overall: 🧂 unranked krab
Proof: 🧂 unranked krab
Patch quality: 🧂 unranked krab
Result: blocked until real behavior proof is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P1] Add redacted real behavior proof showing Open WebUI and Control UI reuse the same UUID session without creating a prefixed duplicate.
  • Remove or split the Codex/provider/auth transport changes from this session-state PR.
  • [P1] Rebase onto current main and cover default-agent, UUID-shaped main-key, combined-store alias, and subscription paths before merge.

Proof guidance:

  • [P1] Needs real behavior proof before merge: The PR body claims deployed manual verification, but it does not include inspectable after-fix proof such as a redacted screenshot, recording, terminal output, live output, linked artifact, or logs; private details such as hostnames, IPs, API keys, phone numbers, and chat contents should be redacted. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Proof path suggestion
A browser proof showing an Open WebUI UUID chat opened through Control UI without creating a second session would materially improve review confidence. Mantis is currently scoped to Telegram, Discord, and web UI chat proof, so it is not the right proof path for this surface.
Use maintainer screenshot/manual proof, browser or Playwright proof, Crabbox where appropriate, or normal local artifact proof instead.

Risk before merge

  • [P1] Merging as-is can change persisted session identity and alias behavior while the branch is conflicting and stale against the current session-accessor architecture.
  • [P1] The branch adds Codex/provider auth transport behavior inside a session-state PR, so the UUID tests do not settle credential propagation, provider routing, or Codex protocol compatibility.
  • [P1] The PR body claims manual deployed verification, but no inspectable redacted screenshot, recording, terminal output, live output, linked artifact, or log is attached.
  • [P1] The useful UUID fix may be superseded or need retargeting once the broader raw external alias work is repaired against current main.

Maintainer options:

  1. Split unrelated Codex/auth transport work (recommended)
    Remove the Codex proxy, legacy provider route, compaction auth fallback, and send-routing changes from this session PR before re-reviewing the UUID repair.
  2. Retarget through session accessor
    Rebase the useful UUID work onto current main and implement any alias preservation at the current session-accessor boundary with upgrade coverage.
  3. Pause or close as stale
    If maintainers prefer the broader raw-alias PR or a fresh branch, pause or close this conflicting branch and carry forward only the useful issue context and tests.

Next step before merge

  • [P1] Human review is needed because the branch is conflicting, lacks contributor proof, and needs a maintainer decision to split or reject unrelated Codex/provider transport work.

Maintainer decision needed

  • Question: Should maintainers keep this PR as the UUID session fix after splitting out the Codex/provider transport changes, or retarget the work to the broader raw-alias session contract?
  • Rationale: The remaining blocker is not one mechanical patch: maintainers need to choose the owner boundary for persistent session aliases and reject or split unrelated provider/auth transport changes before any merge path is safe.
  • Likely owner: steipete — The current-main session storage boundary and recent related refactor blame to steipete, making this the best available routing owner for the merge-risk choice.
  • Options:
    • Split and narrow this PR (recommended): Keep only the Open WebUI UUID session identity repair, rebase it onto the current session-accessor code, and require real Open WebUI plus Control UI proof before merge.
    • Retarget to raw-alias work: Preserve any useful UUID tests but move the fix into the broader raw external alias implementation if maintainers want one shared alias contract.
    • Close and replace: Close this stale conflicting branch after opening or selecting a narrower replacement that does not carry unrelated Codex/provider runtime changes.

Security
Needs attention: The intended UUID session repair is not inherently security-sensitive, but the branch adds Codex proxy/auth transport and legacy provider routing that need separate credential-routing review.

Review findings

  • [P1] Split the Codex proxy work out of this session fix — src/agents/pi-embedded-runner/extra-params.ts:305
  • [P1] Remove the live legacy Codex provider route — src/agents/pi-embedded-runner/codex-proxy-transport.ts:33
  • [P1] Keep UUID sessions scoped in combined-store round trips — src/gateway/session-utils.ts:643-645
Review details

Best possible solution:

Land a narrow UUID-preservation or shared raw-alias session repair against the current session-accessor architecture, with upgrade tests and real Open WebUI plus Control UI proof, and move the Codex/provider transport changes to separate review.

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

Yes, at source level: current main still sends non-agent raw session keys through agent-scoped canonicalization, matching the linked Open WebUI UUID split. I did not run a live Open WebUI setup in this read-only review.

Is this the best way to solve the issue?

No. Preserving UUID session identity is a plausible repair, but this branch is too broad, stale, and conflicting; the best fix is a narrow session-key repair or shared raw-alias contract on the current session-accessor boundary.

Full review comments:

  • [P1] Split the Codex proxy work out of this session fix — src/agents/pi-embedded-runner/extra-params.ts:305
    This PR is scoped to Open WebUI UUID session identity, but this line wraps every embedded agent stream with a new Codex proxy transport. That changes provider routing and credential behavior outside the reported session-key bug, so it should be removed from this branch or split into a dedicated Codex/auth PR.
    Confidence: 0.92
  • [P1] Remove the live legacy Codex provider route — src/agents/pi-embedded-runner/codex-proxy-transport.ts:33
    The new transport includes openai-codex as a live provider route even though current OpenClaw policy and docs treat openai-codex as legacy input to migrate into openai. Keeping this live path can reintroduce stale provider/auth routing that doctor is supposed to repair away.
    Confidence: 0.88
  • [P1] Keep UUID sessions scoped in combined-store round trips — src/gateway/session-utils.ts:643-645
    Returning bare UUIDs from agent-store canonicalization drops the source agent identity while combined stores are merged. A UUID session from a previous default agent can list as unscoped and then resolve follow-up get/patch/delete operations against the current default agent store, showing empty history or mutating the wrong row.
    Confidence: 0.82
  • [P2] Normalize UUID links for the configured default agent — ui/src/ui/app-settings.ts:51-52
    normalizeChatUrlSessionKey only strips agent:main:<uuid>, but legacy links were generated with whichever agent was configured as default. For a default such as ops, the Control UI will keep agent:ops:<uuid> and can keep flipping between aliases instead of converging on the bare UUID.
    Confidence: 0.78

Overall correctness: patch is incorrect
Overall confidence: 0.86

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 70f2bef6b4cf.

Label changes

Label justifications:

  • P2: The underlying Open WebUI UUID split is a normal-priority session-state bug limited to affected integrations, not a core-runtime outage.
  • merge-risk: 🚨 compatibility: The PR changes persisted session key canonicalization and legacy alias behavior, which can affect upgrades and existing session stores.
  • merge-risk: 🚨 session-state: The PR can mis-associate, split, or hide session history across bare UUID and agent-prefixed UUID aliases if remaining alias paths are not settled.
  • merge-risk: 🚨 auth-provider: The branch adds Codex proxy/auth transport routing and legacy provider handling unrelated to the session fix.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🧂 unranked krab.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR body claims deployed manual verification, but it does not include inspectable after-fix proof such as a redacted screenshot, recording, terminal output, live output, linked artifact, or logs; private details such as hostnames, IPs, API keys, phone numbers, and chat contents should be redacted. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +1278, Tests +252, Other +2. Total +1532 across 15 files.

View PR surface stats
Area Files Added Removed Net
Source 9 1287 9 +1278
Tests 4 252 0 +252
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 2 2 0 +2
Total 15 1541 9 +1532

Security concerns:

  • [medium] Unrelated Codex credential transport — src/agents/pi-embedded-runner/extra-params.ts:305
    Wrapping all embedded streams in a new Codex proxy transport changes how API keys and headers are resolved and sent, which is credential-routing surface outside the stated session fix.
    Confidence: 0.88
  • [medium] Legacy Codex provider route reintroduced — src/agents/pi-embedded-runner/codex-proxy-transport.ts:33
    Adding openai-codex to live provider handling can route credentials through a legacy provider id that current doctor/docs intend to migrate to canonical openai routing.
    Confidence: 0.84

What I checked:

  • Root and scoped policy read: Root AGENTS.md and scoped policies for src/agents, src/agents/embedded-agent-runner/run, src/gateway, src/gateway/server-methods, and ui were read; the review applied the session/auth/provider compatibility and Codex dependency-inspection requirements. (AGENTS.md:13, 70f2bef6b4cf)
  • Live PR state: GitHub reports the PR open, non-draft, head 1f24a8e, mergeStateStatus DIRTY, mergeable CONFLICTING, with status: needs proof and merge-risk labels still present. (1f24a8e1f511)
  • Current main still canonicalizes bare raw keys: On current main, non-agent raw session keys are still wrapped into agent-scoped store keys by canonicalizeSessionKeyForAgent, so the central reported behavior is not already implemented on main. (src/gateway/session-store-key.ts:31, 70f2bef6b4cf)
  • PR drops agent scope for UUID canonicalization: The PR returns bare UUIDs from canonicalizeSessionKeyForAgent, and the combined-store merge calls that helper for each per-agent store key, so a UUID row can lose the agent owner needed for later list/get/patch/delete round trips. (src/gateway/session-utils.ts:643, 1f24a8e1f511)
  • Unrelated Codex transport added: The PR wraps every embedded agent stream with createCodexProxyTransportWrapper, which is provider/auth transport behavior outside the UUID session-key fix. (src/agents/pi-embedded-runner/extra-params.ts:305, 1f24a8e1f511)
  • Legacy Codex provider route reintroduced: The PR adds openai-codex to live Codex tool-call provider routing, while current docs say openai-codex is legacy migration input and canonical routing uses openai plus the Codex harness. (src/agents/pi-embedded-runner/codex-proxy-transport.ts:33, 1f24a8e1f511)

Likely related people:

  • steipete: Current-main session-store-key, combined-store, and session-accessor boundaries blame to commit 43fd44a, merged through PR 100263 by steipete. (role: recent area contributor and merger; confidence: high; commits: 43fd44a28c89, 70f2bef6b4cf; files: src/gateway/session-store-key.ts, src/config/sessions/combined-store-gateway.ts, src/config/sessions/session-accessor.ts)
  • stainlu: Authored the active related raw external alias PR that covers the broader session alias contract and supplies backend proof for overlapping gateway session-state behavior. (role: adjacent implementation owner; confidence: medium; commits: 1cde6d4a5d22; files: src/gateway/session-store-aliases.ts, src/gateway/session-utils.ts, src/plugins/host-hook-state.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
Review history (2 earlier review cycles)
  • reviewed 2026-07-03T21:04:42.305Z sha 1f24a8e :: needs real behavior proof before merge. :: [P1] Split the Codex proxy work out of this session fix | [P1] Use a WebSocket client that sends auth headers | [P1] Remove the live legacy Codex provider route | [P1] Keep UUID sessions scoped in combined-store round trips | [P2] Normalize UUID links for the configured default agent
  • reviewed 2026-07-05T07:48:39.262Z sha 1f24a8e :: needs real behavior proof before merge. :: [P1] Split the Codex proxy work out of this session fix | [P1] Use a WebSocket client that sends auth headers | [P1] Remove the live legacy Codex provider route | [P1] Keep UUID sessions scoped in combined-store round trips | [P2] Normalize UUID links for the configured default agent

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. label May 19, 2026
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. label May 19, 2026
@clawsweeper

clawsweeper Bot commented May 20, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper PR egg

🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat.

Where did the egg go?
  • The egg game starts only after the PR passes the real-behavior proof check.
  • Before that, no creature or rarity is rolled. The treat waits for real proof.
  • This is still just collectible flavor: proof affects review readiness, not creature quality.

@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 the stale Marked as stale due to inactivity label Jun 6, 2026
@clawsweeper clawsweeper Bot added rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. and removed 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. labels Jun 6, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the stale Marked as stale due to inactivity label Jun 7, 2026
@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. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. and removed rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. 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. labels Jun 14, 2026
@clawsweeper clawsweeper Bot removed 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. labels Jun 27, 2026
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Jun 27, 2026
@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. labels Jun 27, 2026
@steipete

Copy link
Copy Markdown
Contributor

Thanks @SHAREN for the detailed reproduction and investigation. Closing this older implementation in favor of the canonical report #86743 and the broader shared-alias repair in #83368. The underlying raw/canonical session split is not being dismissed; it remains open there.

This branch is no longer a safe implementation vehicle: sessions and transcripts moved to SQLite in #98236, the Control UI architecture changed in #100024, the UUID shortcut loses agent ownership in multi-agent stores, and the branch bundles unrelated legacy Codex transport/auth routing. #83368 addresses the alias contract across lookup and mutation paths on the current owner boundary. If a distinct Open WebUI-specific failure remains after that work, please add current-version proof to #86743. Thank you for surfacing the original split-session failure.

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

Labels

agents Agent runtime and tooling app: web-ui App: web-ui gateway Gateway runtime merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. 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: XL 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-backed UUID chats can split into separate <uuid> and agent:main:<uuid> session records

2 participants