mirror of
https://github.com/open-webui/open-webui.git
synced 2026-07-16 23:21:44 -05:00
[PR #24170] [CLOSED] fix(chat): recover from malformed history.currentId instead of infinite loading #98571
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/24170
Author: @SymbolStar
Created: 4/27/2026
Status: ❌ Closed
Base:
main← Head:fix/chat-history-malformed-message-recovery📝 Commits (1)
65ba772fix(chat): recover from malformed history.currentId instead of infinite loading📊 Changes
2 files changed (+67 additions, -0 deletions)
View changed files
📝
src/lib/components/chat/Chat.svelte(+21 -0)📝
src/lib/utils/index.ts(+46 -0)📄 Description
Summary
Fixes #24157 — when an upstream OpenAI-compatible provider returns a safety-rejection or content-filter response that lacks the standard message schema (no
role/childrenIds), the malformed object can end up persisted inchat.history.messagesand assigned ashistory.currentId. The chat view then locks up on an infinite Loading spinner because downstream renderers rely on those fields.Approach
Add two small helpers in
src/lib/utils/index.ts:isRenderableMessage(message)— predicate that requires bothrole(string) andchildrenIds(array) before treating a node as safe to render.findLastRenderableAncestor(history, startId)— walks the parent chain (cycle-safe viaSet) and returns the first renderable ancestor, ornullif none exists.Wire them into
Chat.svelte#loadChat: right after the chat content is loaded, ifhistory.currentIdpoints at a non-renderable message, log a console warning and resethistory.currentIdto the last valid ancestor (ornullif no valid ancestor exists). This lets the chat recover automatically and the malformed node is preserved inhistory.messagesfor diagnostics.Behavior
currentIdpoints at valid messagecurrentIdpoints at malformed node, valid ancestor existscurrentIdpoints at malformed node, no valid ancestorhistory.messagesempty / nocurrentIdThe malformed message is not deleted — preserved for forensics. Upstream provider responsibility (returning valid OpenAI-compatible JSON) is unchanged; this just makes Open WebUI defensively robust against bad shapes.
Verification
prettier --check: ✅npm run check(svelte-check): ✅ no new errors introduced (existing 9361 errors are preexisting inmain)utils/index.test.tsto extend; happy to add one if maintainers prefer.Refs
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.