Repository navigation
fix: issue with memory error message display - #16738
Conversation
📝 WalkthroughWalkthroughThe delete and update-message-state handlers in the memory message hook now inspect API response codes before showing success feedback or invalidating queries, with handleUpdateMessageState refactored to return a Promise. The message table introduces a StatusSwitch component providing optimistic UI updates with revert-on-failure. ChangesMessage action and status toggle updates
Estimated code review effort: 2 (Simple) | ~12 minutes Sequence Diagram(s)sequenceDiagram
participant User
participant StatusSwitch
participant handleClickUpdateMessageState
participant memoryService
participant QueryClient
User->>StatusSwitch: toggle switch
StatusSwitch->>StatusSwitch: set optimisticStatus, disable
StatusSwitch->>handleClickUpdateMessageState: onUpdate()
handleClickUpdateMessageState->>memoryService: updateMessageState()
memoryService-->>handleClickUpdateMessageState: response code
alt code === 0
handleClickUpdateMessageState->>QueryClient: invalidate FetchMemoryMessage
handleClickUpdateMessageState-->>StatusSwitch: true
else error or code != 0
handleClickUpdateMessageState-->>StatusSwitch: false
StatusSwitch->>StatusSwitch: revert optimisticStatus
end
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@web/src/pages/memory/memory-message/hook.ts`:
- Around line 92-113: The status update handler in handleUpdateMessageState
silently returns false when memoryService.updateMessageState succeeds
technically but data.code is non-zero, so add a message.error using the returned
business error message before returning false. Keep the existing success path
and query invalidation unchanged, and mirror the error handling pattern already
used by fetchMessageContent so StatusSwitch reverts with visible feedback.
- Around line 81-90: The delete flow in the memory message hook currently
handles success in the .then branch but ignores the non-zero business error
case, so add explicit error feedback in the same handler when data.data.code !==
0. Update the delete callback in hook.ts to mirror the existing
fetchMessageContent pattern by calling message.error with the server-provided
message on failure, and only close the dialog after the request outcome is
handled so the user sees whether the delete succeeded or failed.
In `@web/src/pages/memory/memory-message/message-table.tsx`:
- Around line 108-113: The update flow in message-table.tsx leaves the switch
stuck disabled if onUpdate rejects because setPending(false) only runs inside
the .then() branch. Update the onUpdate(row.original, val) chain in the relevant
handler so pending is cleared in a defensive .catch() or .finally() path, while
preserving the existing optimisticStatus rollback logic for failed updates in
the same callback flow.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 2b98c5ac-fcd1-40b6-b57d-b552296ddf00
📒 Files selected for processing (2)
web/src/pages/memory/memory-message/hook.tsweb/src/pages/memory/memory-message/message-table.tsx
| .then((data: any) => { | ||
| if (data.data.code === 0) { | ||
| message.success(t('message.deleted')); | ||
| queryClient.invalidateQueries({ | ||
| queryKey: [MemoryApiAction.FetchMemoryMessage], | ||
| }); | ||
| } | ||
| }); | ||
| setShowDeleteDialog(false); | ||
| }, [selectedMessage.message_id, queryClient]); | ||
| }, [selectedMessage.message_id, queryClient, memoryId]); |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Show error feedback when delete fails at the business level.
When data.data.code !== 0, the handler silently does nothing — no error toast, no user feedback. The dialog closes immediately (line 89) regardless of outcome, so the user has no indication the delete failed. This is directly at odds with the PR's objective of fixing memory error message display. The existing fetchMessageContent handler (lines 144–149) already follows the pattern of calling message.error(res.data.message) on non-zero codes.
🛡️ Proposed fix: add error toast on non-zero code
.then((data: any) => {
if (data.data.code === 0) {
message.success(t('message.deleted'));
queryClient.invalidateQueries({
queryKey: [MemoryApiAction.FetchMemoryMessage],
});
+ } else {
+ message.error(data.data.message);
}
});📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| .then((data: any) => { | |
| if (data.data.code === 0) { | |
| message.success(t('message.deleted')); | |
| queryClient.invalidateQueries({ | |
| queryKey: [MemoryApiAction.FetchMemoryMessage], | |
| }); | |
| } | |
| }); | |
| setShowDeleteDialog(false); | |
| }, [selectedMessage.message_id, queryClient]); | |
| }, [selectedMessage.message_id, queryClient, memoryId]); | |
| .then((data: any) => { | |
| if (data.data.code === 0) { | |
| message.success(t('message.deleted')); | |
| queryClient.invalidateQueries({ | |
| queryKey: [MemoryApiAction.FetchMemoryMessage], | |
| }); | |
| } else { | |
| message.error(data.data.message); | |
| } | |
| }); | |
| setShowDeleteDialog(false); | |
| }, [selectedMessage.message_id, queryClient, memoryId]); |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@web/src/pages/memory/memory-message/hook.ts` around lines 81 - 90, The delete
flow in the memory message hook currently handles success in the .then branch
but ignores the non-zero business error case, so add explicit error feedback in
the same handler when data.data.code !== 0. Update the delete callback in
hook.ts to mirror the existing fetchMessageContent pattern by calling
message.error with the server-provided message on failure, and only close the
dialog after the request outcome is handled so the user sees whether the delete
succeeded or failed.
| const handleUpdateMessageState = useCallback( | ||
| (messageInfo: IMessageInfo, enable: boolean) => { | ||
| // delete message | ||
| const selectedMessageInfo = messageInfo || selectedMessage; | ||
| memoryService | ||
| .updateMessageState({ | ||
| async (messageInfo: IMessageInfo, enable: boolean): Promise<boolean> => { | ||
| try { | ||
| const { data } = await memoryService.updateMessageState({ | ||
| memory_id: memoryId, | ||
| message_id: selectedMessageInfo.message_id, | ||
| message_id: messageInfo.message_id, | ||
| status: enable || false, | ||
| }) | ||
| .then((data: any) => { | ||
| if (data.data.code === 0) { | ||
| message.success(t('message.updated')); | ||
| queryClient.invalidateQueries({ | ||
| queryKey: [MemoryApiAction.FetchMemoryMessage], | ||
| }); | ||
| } | ||
| }); | ||
| setShowDeleteDialog(false); | ||
| if (data.code === 0) { | ||
| message.success(t('message.updated')); | ||
| queryClient.invalidateQueries({ | ||
| queryKey: [MemoryApiAction.FetchMemoryMessage], | ||
| }); | ||
| return true; | ||
| } | ||
| return false; | ||
| } catch { | ||
| return false; | ||
| } | ||
| }, | ||
| [selectedMessage, queryClient, memoryId], | ||
| [queryClient, memoryId], | ||
| ); |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Show error feedback when status update fails at the business level.
When data.code !== 0, the handler returns false without any error toast. The StatusSwitch reverts visually, but the user gets no explanation. The fetchMessageContent handler at lines 144–149 already uses message.error(res.data.message) for this pattern — apply the same here.
🛡️ Proposed fix: add error toast before returning false
if (data.code === 0) {
message.success(t('message.updated'));
queryClient.invalidateQueries({
queryKey: [MemoryApiAction.FetchMemoryMessage],
});
return true;
}
+ message.error(data.message);
return false;📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const handleUpdateMessageState = useCallback( | |
| (messageInfo: IMessageInfo, enable: boolean) => { | |
| // delete message | |
| const selectedMessageInfo = messageInfo || selectedMessage; | |
| memoryService | |
| .updateMessageState({ | |
| async (messageInfo: IMessageInfo, enable: boolean): Promise<boolean> => { | |
| try { | |
| const { data } = await memoryService.updateMessageState({ | |
| memory_id: memoryId, | |
| message_id: selectedMessageInfo.message_id, | |
| message_id: messageInfo.message_id, | |
| status: enable || false, | |
| }) | |
| .then((data: any) => { | |
| if (data.data.code === 0) { | |
| message.success(t('message.updated')); | |
| queryClient.invalidateQueries({ | |
| queryKey: [MemoryApiAction.FetchMemoryMessage], | |
| }); | |
| } | |
| }); | |
| setShowDeleteDialog(false); | |
| if (data.code === 0) { | |
| message.success(t('message.updated')); | |
| queryClient.invalidateQueries({ | |
| queryKey: [MemoryApiAction.FetchMemoryMessage], | |
| }); | |
| return true; | |
| } | |
| return false; | |
| } catch { | |
| return false; | |
| } | |
| }, | |
| [selectedMessage, queryClient, memoryId], | |
| [queryClient, memoryId], | |
| ); | |
| const handleUpdateMessageState = useCallback( | |
| async (messageInfo: IMessageInfo, enable: boolean): Promise<boolean> => { | |
| try { | |
| const { data } = await memoryService.updateMessageState({ | |
| memory_id: memoryId, | |
| message_id: messageInfo.message_id, | |
| status: enable || false, | |
| }); | |
| if (data.code === 0) { | |
| message.success(t('message.updated')); | |
| queryClient.invalidateQueries({ | |
| queryKey: [MemoryApiAction.FetchMemoryMessage], | |
| }); | |
| return true; | |
| } | |
| message.error(data.message); | |
| return false; | |
| } catch { | |
| return false; | |
| } | |
| }, | |
| [queryClient, memoryId], | |
| ); |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@web/src/pages/memory/memory-message/hook.ts` around lines 92 - 113, The
status update handler in handleUpdateMessageState silently returns false when
memoryService.updateMessageState succeeds technically but data.code is non-zero,
so add a message.error using the returned business error message before
returning false. Keep the existing success path and query invalidation
unchanged, and mirror the error handling pattern already used by
fetchMessageContent so StatusSwitch reverts with visible feedback.
| onUpdate(row.original, val).then((success) => { | ||
| setPending(false); | ||
| if (!success) { | ||
| setOptimisticStatus(serverStatus); | ||
| } | ||
| }); |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Add .catch() to prevent permanently disabled switch on promise rejection.
If onUpdate ever rejects, the .then() callback never fires, so pending stays true and the switch is permanently disabled. Although handleUpdateMessageState has a catch block that prevents rejection today, a defensive .catch() (or .finally()) here protects against future changes to the handler.
🔒️ Proposed fix: add `.catch()` and `.finally()`
onUpdate(row.original, val)
.then((success) => {
- setPending(false);
if (!success) {
setOptimisticStatus(serverStatus);
}
})
+ .catch(() => {
+ setOptimisticStatus(serverStatus);
+ })
+ .finally(() => {
+ setPending(false);
+ });📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| onUpdate(row.original, val).then((success) => { | |
| setPending(false); | |
| if (!success) { | |
| setOptimisticStatus(serverStatus); | |
| } | |
| }); | |
| onUpdate(row.original, val) | |
| .then((success) => { | |
| if (!success) { | |
| setOptimisticStatus(serverStatus); | |
| } | |
| }) | |
| .catch(() => { | |
| setOptimisticStatus(serverStatus); | |
| }) | |
| .finally(() => { | |
| setPending(false); | |
| }); |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@web/src/pages/memory/memory-message/message-table.tsx` around lines 108 -
113, The update flow in message-table.tsx leaves the switch stuck disabled if
onUpdate rejects because setPending(false) only runs inside the .then() branch.
Update the onUpdate(row.original, val) chain in the relevant handler so pending
is cleared in a defensive .catch() or .finally() path, while preserving the
existing optimisticStatus rollback logic for failed updates in the same callback
flow.
Summary
fix: issue with memory error message display