Skip to content

bug: A2A pushMessage accesses array[-1] when messageLog is empty #24894

@KevinZhao

Description

@KevinZhao

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

  1. Create a new A2AResultReassembler instance
  2. Call pushMessage with any text
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/agentIssues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Qualitystatus/need-triageIssues that need to be triaged by the triage automation.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions