fix: target the correct HIL action when clearing pending messages#6615
fix: target the correct HIL action when clearing pending messages#6615sanahkapoor wants to merge 1 commit into
Conversation
…ctions When an agentflow contains more than one Human-In-The-Loop (Proceed/Reject) node, more than one chat message can have a pending action at the same time. Both the resume handler and the frontend button handler assumed there was only ever one pending action and located it positionally (the most recently created message with an action on the server, the last message in the list on the client) instead of by identity. Resolving one HIL node would therefore clear the wrong message's action, making it look like every other pending HIL block had also been actioned. - server: extract findChatMessageActionToClear() and match on humanInput.startNodeId instead of taking the newest message with any action. - ui: match the clicked action's id against message.action.id instead of always clearing the last message in the array. Fixes FlowiseAI#4787
There was a problem hiding this comment.
Code Review
This pull request addresses an issue where multiple Human-In-The-Loop (HIL) nodes are pending simultaneously. It ensures that resuming a node clears the action on the specific message tied to that node rather than simply clearing the newest pending action. This logic is updated in both the backend flow execution and the frontend chat interface, supported by new unit tests. Feedback on the frontend changes points out a potential bug where comparing action IDs directly could lead to incorrect matches (e.g., if both IDs are undefined or if one action is a string and the other is an object), and recommends using a robust helper function to safely parse and compare the IDs.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| allMessages[allMessages.length - 1].action = null | ||
| // Clear the action on the message this button belongs to, not just the last message - a flow | ||
| // can have multiple pending HIL nodes at once. See #4787. | ||
| const targetIndex = allMessages.findIndex((msg) => msg.action && action && msg.action.id === action.id) |
There was a problem hiding this comment.
Issue: Potential incorrect matching or runtime errors when comparing action IDs
There are two main concerns with the current comparison logic:
- Accidental matches on
undefined: If bothmsg.actionandactionare objects but neither has anidproperty (or if they are both strings, making.idevaluate toundefined),msg.action.id === action.idwill evaluate totrue(sinceundefined === undefinedistrue). This can cause the wrong message's action to be cleared. - Mixed types (String vs. Object): Depending on whether the message was loaded from history or newly streamed,
msg.actionandactioncan be either a JSON string or a parsed object. If one is a string and the other is an object, comparing.iddirectly will fail to match.
Recommendation
Implement a robust helper to safely extract the action ID, handling both stringified and parsed object formats, and explicitly verify that both IDs are defined before comparing them.
const getActionId = (act) => {
if (!act) return null
if (typeof act === 'string') {
try {
return JSON.parse(act)?.id
} catch {
return null
}
}
return act.id
}
const targetActionId = getActionId(action)
const targetIndex = allMessages.findIndex((msg) => {
const msgActionId = getActionId(msg.action)
return !!(msgActionId && targetActionId && msgActionId === targetActionId)
})References
- When using a heuristic for detection (e.g., for content type), ensure a safe fallback mechanism is in place to correctly handle cases where the heuristic fails.
Summary
Fixes incorrect action clearing when multiple Human-In-The-Loop (HIL) nodes have pending actions.
The server previously selected a pending action by message position, while the UI always cleared the last message. This could target the wrong HIL action when multiple approvals were pending.
Changes
Testing
Addresses #4787