Skip to content

Feat: When a Wait Node precedes a Message Node within a Loop Node, the outgoing message is split into two separate messages. - #14839

Merged
JinHai-CN merged 2 commits into
infiniflow:mainfrom
cike8899:fix-agent-explore
May 12, 2026
Merged

JinHai-CN merged 2 commits into
infiniflow:mainfrom
cike8899:fix-agent-explore

Conversation

@cike8899

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Feat: When a Wait Node precedes a Message Node within a Loop Node, the outgoing message is split into two separate messages.

Type of change

  • New Feature (non-breaking change which adds functionality)

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label May 12, 2026
@cike8899 cike8899 added ci Continue Integration and removed size:L This PR changes 100-499 lines, ignoring generated files. labels May 12, 2026
@cike8899
cike8899 marked this pull request as draft May 12, 2026 09:31
@cike8899
cike8899 marked this pull request as ready for review May 12, 2026 09:31
@coderabbitai

coderabbitai Bot commented May 12, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR corrects a typo in the chat-logic hook name, removes an unused canvasId parameter, and adds message-splitting functionality with wait-suffix tracking. The chat awaiting logic now sends form messages without agent_id when shared, and incoming assistant messages can be split into answer and wait-state entries for rendering.

Changes

Agent Chat Message Splitting and Hook Refactoring

Layer / File(s) Summary
Hook signature correction and waiting-state rename
web/src/pages/agent/hooks/use-chat-logic.ts, web/src/pages/agent/chat/box.tsx, web/src/pages/agent/share/index.tsx
Fixes misspelled export useAwaitCompentData → useAwaitComponentData, removes canvasId parameter, and renames waiting flag isWaitting → isWaiting across the hook definition and both call sites.
Message wait-suffix constant and splitting utility
web/src/pages/agent/constant/chat.ts, web/src/pages/agent/utils/chat.ts
Introduces MessageWaitSuffix ('-wait') constant and shouldSplitMessage utility that scans event lists to determine when an assistant message should be split into two UI entries based on event ordering and content presence.
Message ID normalization for split messages
web/src/pages/agent/hooks/use-cache-chat-log.ts
Adds resolveMessageId helper to strip wait-suffix from message IDs, ensuring split messages are consistently keyed during event filtering and matching by resolved ID.
Message sending with splitting and payload updates
web/src/pages/agent/chat/use-send-agent-message.ts
Integrates message splitting into the hook: conditionally emits two answer entries with wait-suffix ID when split condition is true; updates sendFormMessage payload to include agent_id only when not shared, always include session_id, and conditionally include release.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested labels

🧰 typescript, size:M

Suggested reviewers

  • dcc123456

Poem

🐰 A chat hook hops from typo'd names,
Waits no more for canvas claims,
Messages split with suffixed care,
IDs resolve without despair!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main feature being implemented: splitting messages when a Wait Node precedes a Message Node within a Loop Node.
Description check ✅ Passed The description includes the required template sections (problem statement and type of change) with the new feature checkbox selected, though the problem statement simply repeats the title rather than providing additional context.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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 and usage tips.

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

@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: 1

🧹 Nitpick comments (1)
web/src/pages/agent/hooks/use-cache-chat-log.ts (1)

15-16: ⚡ Quick win

Prefer string methods over RegExp constructor for simple static patterns.

The static analysis warning flags a potential ReDoS risk. While the risk is negligible here (the pattern is simple and constant), constructing a RegExp on every call is less efficient and less readable than using string methods.

♻️ Proposed alternatives

Option 1: Use string methods (recommended for simplicity)

-const resolveMessageId = (messageId: string) =>
-  messageId?.replace(new RegExp(`${MessageWaitSuffix}$`), '');
+const resolveMessageId = (messageId: string) => {
+  if (messageId?.endsWith(MessageWaitSuffix)) {
+    return messageId.slice(0, -MessageWaitSuffix.length);
+  }
+  return messageId;
+};

Option 2: Module-level compiled regex (if you prefer regex)

+const WAIT_SUFFIX_REGEX = new RegExp(`${MessageWaitSuffix}$`);
+
-const resolveMessageId = (messageId: string) =>
-  messageId?.replace(new RegExp(`${MessageWaitSuffix}$`), '');
+const resolveMessageId = (messageId: string) =>
+  messageId?.replace(WAIT_SUFFIX_REGEX, '');
🤖 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/agent/hooks/use-cache-chat-log.ts` around lines 15 - 16, The
resolveMessageId function uses new RegExp(`${MessageWaitSuffix}$`) which is
unnecessary and flagged for ReDoS; replace the RegExp usage with a simple string
check and slice using MessageWaitSuffix (e.g., if
messageId.endsWith(MessageWaitSuffix) then return messageId.slice(0,
-MessageWaitSuffix.length) else return messageId) to avoid constructing a regex
on every call and improve readability and performance.
🤖 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/agent/chat/use-send-agent-message.ts`:
- Around line 464-488: The split branch can create an invalid ID like
"undefined-wait" because id (from findMessageFromList(answerList)) may be
undefined; update the logic around shouldSplitMessage/ addNewestOneAnswer to
ensure id is defined before constructing `${id}${MessageWaitSuffix}`—either bail
out of the split path, derive a safe fallback ID (e.g., generate a unique id or
use a guaranteed string like `newMessageId()` or `temporary-${timestamp}`), or
use the original message's id when available; modify the code that calls
findMessageFromList, the split branch that calls addNewestOneAnswer, and any
reliance on MessageWaitSuffix so the wait message ID is never "undefined-wait".

---

Nitpick comments:
In `@web/src/pages/agent/hooks/use-cache-chat-log.ts`:
- Around line 15-16: The resolveMessageId function uses new
RegExp(`${MessageWaitSuffix}$`) which is unnecessary and flagged for ReDoS;
replace the RegExp usage with a simple string check and slice using
MessageWaitSuffix (e.g., if messageId.endsWith(MessageWaitSuffix) then return
messageId.slice(0, -MessageWaitSuffix.length) else return messageId) to avoid
constructing a regex on every call and improve readability and performance.
🪄 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: 6f7cfde2-8afd-441f-a5e2-c16c4e8dfa3a

📥 Commits

Reviewing files that changed from the base of the PR and between 14332dd and 56be3b4.

📒 Files selected for processing (7)
  • web/src/pages/agent/chat/box.tsx
  • web/src/pages/agent/chat/use-send-agent-message.ts
  • web/src/pages/agent/constant/chat.ts
  • web/src/pages/agent/hooks/use-cache-chat-log.ts
  • web/src/pages/agent/hooks/use-chat-logic.ts
  • web/src/pages/agent/share/index.tsx
  • web/src/pages/agent/utils/chat.ts

Comment on lines +464 to +488
const shouldSplit = shouldSplitMessage(answerList, content);

if (shouldSplit) {
addNewestOneAnswer({
answer: answer ?? '',
audio_binary: audio_binary,
attachment: attachment as IAttachment,
downloads,
id,
});
addNewestOneAnswer({
answer: '',
...inputAnswer,
id: `${id}${MessageWaitSuffix}`,
});
} else {
addNewestOneAnswer({
answer: answer ?? '',
audio_binary: audio_binary,
attachment: attachment as IAttachment,
downloads,
id,
...inputAnswer,
});
}

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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Potential undefined message ID in split logic.

When shouldSplitMessage returns true, the wait message ID is constructed as ${id}${MessageWaitSuffix} (line 477). However, id comes from findMessageFromList(answerList) which can return undefined if eventList[0]?.message_id is falsy. This could produce an ID like "undefined-wait".

Consider adding a guard to ensure id is defined before splitting, or handle the undefined case explicitly.

🛡️ Proposed fix
   if (answerList.length > 0) {
     const shouldSplit = shouldSplitMessage(answerList, content);
 
-    if (shouldSplit) {
+    if (shouldSplit && id) {
       addNewestOneAnswer({
         answer: answer ?? '',
📝 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 shouldSplit = shouldSplitMessage(answerList, content);
if (shouldSplit) {
addNewestOneAnswer({
answer: answer ?? '',
audio_binary: audio_binary,
attachment: attachment as IAttachment,
downloads,
id,
});
addNewestOneAnswer({
answer: '',
...inputAnswer,
id: `${id}${MessageWaitSuffix}`,
});
} else {
addNewestOneAnswer({
answer: answer ?? '',
audio_binary: audio_binary,
attachment: attachment as IAttachment,
downloads,
id,
...inputAnswer,
});
}
const shouldSplit = shouldSplitMessage(answerList, content);
if (shouldSplit && id) {
addNewestOneAnswer({
answer: answer ?? '',
audio_binary: audio_binary,
attachment: attachment as IAttachment,
downloads,
id,
});
addNewestOneAnswer({
answer: '',
...inputAnswer,
id: `${id}${MessageWaitSuffix}`,
});
} else {
addNewestOneAnswer({
answer: answer ?? '',
audio_binary: audio_binary,
attachment: attachment as IAttachment,
downloads,
id,
...inputAnswer,
});
}
🤖 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/agent/chat/use-send-agent-message.ts` around lines 464 - 488,
The split branch can create an invalid ID like "undefined-wait" because id (from
findMessageFromList(answerList)) may be undefined; update the logic around
shouldSplitMessage/ addNewestOneAnswer to ensure id is defined before
constructing `${id}${MessageWaitSuffix}`—either bail out of the split path,
derive a safe fallback ID (e.g., generate a unique id or use a guaranteed string
like `newMessageId()` or `temporary-${timestamp}`), or use the original
message's id when available; modify the code that calls findMessageFromList, the
split branch that calls addNewestOneAnswer, and any reliance on
MessageWaitSuffix so the wait message ID is never "undefined-wait".

@codecov

codecov Bot commented May 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.16%. Comparing base (14332dd) to head (56be3b4).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #14839   +/-   ##
=======================================
  Coverage   94.16%   94.16%           
=======================================
  Files          10       10           
  Lines         703      703           
  Branches      112      112           
=======================================
  Hits          662      662           
  Misses         25       25           
  Partials       16       16           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JinHai-CN
JinHai-CN merged commit 3f41f8c into infiniflow:main May 12, 2026
1 check passed
Ricardo-M-L pushed a commit to Ricardo-M-L/ragflow that referenced this pull request Aug 17, 2026
…e outgoing message is split into two separate messages. (infiniflow#14839)

### What problem does this PR solve?

Feat: When a Wait Node precedes a Message Node within a Loop Node, the
outgoing message is split into two separate messages.

### Type of change


- [x] New Feature (non-breaking change which adds functionality)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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