Skip to content

fix(web): clear stale conversation_id from localStorage on 404 - #39593

Open
6mvp6 wants to merge 4 commits into
langgenius:mainfrom
6mvp6:fix/web-clear-stale-conversation-id-on-404
Open

fix(web): clear stale conversation_id from localStorage on 404#39593
6mvp6 wants to merge 4 commits into
langgenius:mainfrom
6mvp6:fix/web-clear-stale-conversation-id-on-404

Conversation

@6mvp6

@6mvp6 6mvp6 commented Jul 26, 2026

Copy link
Copy Markdown

Fixes #39484.

When a conversation_id persisted in localStorage becomes stale (conversation deleted server-side, or end-user identity changed), the Web App chatbot had no 404 recovery path: useShareChatList retried indefinitely, the error state was never consumed, and removeConversationIdInfo() was never called — trapping the user in an infinite 404 loop on GET /api/messages, with the only workaround being to manually clear site data.

This is the same issue as #34731 (closed, fix never released) and the same fix strategy as #34945 (open, but conflicting + stale CI), rebased onto current main (which has since refactored the localStorage layer into useConversationIdInfo).

Changes (all frontend):

  • web/service/use-share.tsuseShareChatList disables retries for 404 (other errors keep default 3).
  • embedded-chatbot/hooks.tsx — consume the error from useShareChatList; on 404 clear the stale id via the existing removeConversationIdInfo.
  • chat-with-history/hooks.tsx — same, plus a matching removeConversationIdInfo helper.

Tests: added a case to each hook's hooks.spec.tsx asserting the stale conversationIdInfo entry is removed when the chat list returns 404.

Verified locally: pnpm type-check, pnpm lint:oxlint (0 errors), and the relevant vitest suites pass (embedded: 36 passed, chat-with-history: 66 passed).

Copilot AI review requested due to automatic review settings July 26, 2026 12:04
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jul 26, 2026
@github-actions github-actions Bot added the web This relates to changes on the web. label Jul 26, 2026

Copilot AI 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.

Pull request overview

This PR fixes an infinite 404 retry loop in the web chatbot when a stale conversation_id is persisted in localStorage, by making the shared chat-list query stop retrying on 404 and clearing the stored conversation ID so the UI can fall back to starting a new conversation.

Changes:

  • Disable TanStack Query retries specifically for 404s in useShareChatList.
  • Consume the error state in the embedded chatbot and chat-with-history hooks; on 404, clear the persisted conversationIdInfo.
  • Add hook tests to assert conversationIdInfo is cleared when chat list fetch returns 404.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
web/service/use-share.ts Disables retries for 404 responses in useShareChatList while keeping default retry behavior for other errors.
web/service/share.ts Makes fetchChatList silent (suppresses toasts) for stale-conversation 404s.
web/app/components/base/chat/embedded-chatbot/hooks.tsx Clears stale conversationIdInfo on 404 by consuming useShareChatList error state.
web/app/components/base/chat/embedded-chatbot/tests/hooks.spec.tsx Adds test verifying localStorage is cleared on 404.
web/app/components/base/chat/chat-with-history/hooks.tsx Adds 404 recovery by clearing stale conversationIdInfo (plus helper).
web/app/components/base/chat/chat-with-history/tests/hooks.spec.tsx Adds test verifying localStorage is cleared on 404.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread web/service/share.ts Outdated
@6mvp6

6mvp6 commented Jul 26, 2026

Copy link
Copy Markdown
Author

Thanks for the review @copilot! 👍 Dropped silent: true in e453ce8 — the 404-aware retry already prevents the toast loop, so keeping the request non-silent preserves visibility for genuine backend failures (403/500/etc.) as you suggested. share.ts now has no changes in this PR.

@6mvp6

6mvp6 commented Jul 28, 2026

Copy link
Copy Markdown
Author

Hi @hyoban @CodingOnStar @iamjoel @zxhlyh, would appreciate a review when you have a moment 🙂 This fixes the stale conversation_id → infinite 404 loop on the Web App chatbot (#39484; same root cause as the closed #34731, whose fix never landed in a release). Happy to address any feedback. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files. web This relates to changes on the web.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Infinite 404 "Conversation Not Exists" loop still reproducible on v1.15.0 / v1.16.0 (fix from #34731 not merge)

2 participants