Skip to content

fix(chat): write correct shape in setCurrentChat - #2402

Merged
openai0229 merged 4 commits into
OtterMind:mainfrom
Aias00:fix/setcurrentchat-shape-catch-2401
Aug 3, 2026
Merged

fix(chat): write correct shape in setCurrentChat#2402
openai0229 merged 4 commits into
OtterMind:mainfrom
Aias00:fix/setcurrentchat-shape-catch-2401

Conversation

@Aias00

@Aias00 Aias00 commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

What

setCurrentChat optimistically wrote currentChat[page] = chat (the whole Record) instead of chat[page] (the ChatVO). That left the slot with the wrong shape while details loaded, so currentChat[page].id/.title/.chatDetails could be undefined.

Location

src/store/chat/slices/common/action.ts:150-169

Fix

  • Set [page]: chat[page] instead of the whole chat Record.
  • Use functional Zustand updates so concurrent currentChat changes are merged against the latest state.
  • Keep getChatDetailById rejections observable to callers. resetChatDetails(page) already clears stale details before the request starts, so no failure catch/state rewrite is needed.

Verification

  • The existing else branch already uses chat[page]; both branches now use the same shape.
  • All state updates merge against state.currentChat.
  • Focused ESLint passes for the changed action file.

Fixes #2401

🤖 Generated with Claude Code

…lure (OtterMind#2401)

setCurrentChat optimistically set currentChat[page] to the whole chat object
(a Record with workspace/dashboard/chat slots) instead of the ChatVO at
chat[page], and chained getChatDetailById without a .catch — so a fetch
rejection left the wrong-shape Record in the slot, making
currentChat[page].id/.title/.chatDetails undefined (blank title, empty
list) until a later successful fetch. Set [page]: chat[page] and restore the
slot to chat[page] on fetch failure.

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: liuhy <liuhongyu@apache.org>
Copilot AI review requested due to automatic review settings August 3, 2026 06:45
@Aias00
Aias00 requested a review from openai0229 as a code owner August 3, 2026 06:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Fixes an incorrect currentChat state shape being written during optimistic updates and ensures fetch failures don’t leave subscribers reading undefined fields for the current chat.

Changes:

  • Write currentChat[page] = chat[page] (a ChatVO) instead of chat (the whole Record) in the if branch.
  • Add a .catch() to restore state and clear chat details when getChatDetailById fails.

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

Comment thread chat2db-community-client/src/store/chat/slices/common/action.ts Outdated
Comment thread chat2db-community-client/src/store/chat/slices/common/action.ts Outdated
Comment thread chat2db-community-client/src/store/chat/slices/common/action.ts Outdated
@openai0229 openai0229 changed the title fix(chat): write correct shape in setCurrentChat and handle fetch failure fix(chat): write correct shape in setCurrentChat Aug 3, 2026

@openai0229 openai0229 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.

Reviewed the final state-management change after syncing with the latest main. It writes the correct ChatVO shape, merges against current Zustand state, clears stale details before fetching, and preserves promise rejection for callers. Focused ESLint passes.

Comment thread chat2db-community-client/src/store/chat/slices/common/action.ts Outdated
@openai0229
openai0229 merged commit 647b59a into OtterMind:main Aug 3, 2026
20 of 21 checks passed
@openai0229 openai0229 moved this from In Review to Done in Chat2DB Community Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

bug(chat): setCurrentChat writes the wrong shape and lacks a catch on fetch failure

3 participants