fix(core): add explicit empty log guard in A2A pushMessage#26198
fix(core): add explicit empty log guard in A2A pushMessage#26198adamfweidman merged 1 commit intomainfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a potential fragility in the A2A result reassembly logic. By introducing an explicit check for an empty message log, the code avoids relying on implicit JavaScript behavior when accessing array indices, ensuring more robust and readable message handling. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request fixes an issue in A2AResultReassembler where the first message was not correctly added to an empty message log, and includes a new test case to verify the fix. The reviewer suggested using Array.prototype.at(-1) to simplify the logic for checking the last message in the log, which would improve readability and conciseness.
|
Size Change: -25 B (0%) Total Size: 33.9 MB
ℹ️ View Unchanged
|
Avoids accessing array[-1] when messageLog is empty, making the duplicate check more robust. Fixes #24894
dac9385 to
9acbc5f
Compare
Summary
This PR adds an explicit guard for an empty message log in the A2A
pushMessageutility.Details
In
A2AResultReassembler.pushMessage, the code was accessingthis.messageLog[this.messageLog.length - 1]to check for duplicate consecutive messages. WhenmessageLogis empty, this evaluates tomessageLog[-1], which returnsundefined. While JavaScript's behavior allowed this to work (the first message would still be pushed becauseundefined !== text), it is non-idiomatic and potentially fragile. This PR adds an explicitlength === 0check.Related Issues
Fixes #24894
How to Validate
Run the unit tests in
@google/gemini-cli-core:npm test -w @google/gemini-cli-core -- src/agents/a2aUtils.test.tsThe newly added test case "should correctly push the first message when messageLog is empty (Issue #24894)" verifies the fix.
Pre-Merge Checklist