Skip to content

fix: issue with memory error message display - #16738

Merged
wangq8 merged 1 commit into
infiniflow:mainfrom
dcc123456:fix/memory-error-message-0708-1
Jul 8, 2026
Merged

wangq8 merged 1 commit into
infiniflow:mainfrom
dcc123456:fix/memory-error-message-0708-1

Conversation

@dcc123456

Copy link
Copy Markdown
Collaborator

Summary

fix: issue with memory error message display

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 8, 2026
@coderabbitai

coderabbitai Bot commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The 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.

Changes

Message action and status toggle updates

Layer / File(s) Summary
Mutation handlers validate API response codes
web/src/pages/memory/memory-message/hook.ts
Delete mutation and handleUpdateMessageState now check data.code === 0 before showing success toast and invalidating FetchMemoryMessage; handleUpdateMessageState is now async and returns Promise<boolean>, returning false on error; handleClickUpdateMessageState sets selected message and returns that promise.
Optimistic StatusSwitch component
web/src/pages/memory/memory-message/message-table.tsx
Adds a StatusSwitch component with local optimistic status state, disables interaction while pending, reverts on failed update, and syncs via useEffect; replaces the inline status Switch cell, wiring onUpdate to handleClickUpdateMessageState.

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
Loading

Possibly related PRs

  • infiniflow/ragflow#16690: Both PRs modify handleUpdateMessageState in the same hook.ts to gate success toast and query invalidation on data.data.code === 0.

Poem

A switch that flips with hopeful hop,
If codes don't match, it knows to stop,
Back it bounces, no harm done,
Optimism paired with a safety run,
Hooray, hooray, the toggle's spun! 🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The description only repeats the title and lacks the background/context requested by the template. Expand the Summary with the problem context, what changed, and the expected user-facing behavior.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title matches the main change: fixing memory message display behavior.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@dcc123456
dcc123456 requested a review from wangq8 July 8, 2026 05:10
@dcc123456 dcc123456 added 🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration labels Jul 8, 2026
@dcc123456
dcc123456 marked this pull request as draft July 8, 2026 05:10
@dcc123456
dcc123456 marked this pull request as ready for review July 8, 2026 05:11

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5baf408 and 4650181.

📒 Files selected for processing (2)
  • web/src/pages/memory/memory-message/hook.ts
  • web/src/pages/memory/memory-message/message-table.tsx

Comment on lines +81 to +90
.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]);

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.

🎯 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.

Suggested change
.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.

Comment on lines 92 to 113
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],
);

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.

🎯 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.

Suggested change
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.

Comment on lines +108 to +113
onUpdate(row.original, val).then((success) => {
setPending(false);
if (!success) {
setOptimisticStatus(serverStatus);
}
});

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.

🩺 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.

Suggested change
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.

@wangq8
wangq8 merged commit 3d16720 into infiniflow:main Jul 8, 2026
12 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants