A2AResultReassembler.pushMessage in packages/core/src/agents/a2aUtils.ts checks messageLog[messageLog.length - 1] to avoid pushing duplicate consecutive messages. When messageLog is empty, length - 1 is -1 and array[-1] returns undefined in JavaScript.
While the current behavior happens to work correctly (since undefined !== text evaluates to true, the first message still gets pushed), the code relies on an implicit JavaScript quirk rather than expressing intent clearly. An explicit empty-array guard makes the duplicate check self-documenting and prevents potential issues if the comparison logic changes in the future.
Steps to reproduce
- Create a new
A2AResultReassembler instance
- Call
pushMessage with any text
- Observe that
messageLog[-1] is accessed (returns undefined)
Expected behavior
An explicit length check should guard the last-element access.
Actual behavior
array[-1] is accessed, which returns undefined — works by coincidence, not by design.
A2AResultReassembler.pushMessageinpackages/core/src/agents/a2aUtils.tschecksmessageLog[messageLog.length - 1]to avoid pushing duplicate consecutive messages. WhenmessageLogis empty,length - 1is-1andarray[-1]returnsundefinedin JavaScript.While the current behavior happens to work correctly (since
undefined !== textevaluates totrue, the first message still gets pushed), the code relies on an implicit JavaScript quirk rather than expressing intent clearly. An explicit empty-array guard makes the duplicate check self-documenting and prevents potential issues if the comparison logic changes in the future.Steps to reproduce
A2AResultReassemblerinstancepushMessagewith any textmessageLog[-1]is accessed (returnsundefined)Expected behavior
An explicit length check should guard the last-element access.
Actual behavior
array[-1]is accessed, which returnsundefined— works by coincidence, not by design.