fix(a2a-server): normalize CRLF line endings to LF in getProposedContent - #28531
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 functional issue in the local agent backend where text replacement operations failed on Windows environments. By normalizing file content to LF line endings before processing, the system now correctly matches search and replacement blocks generated by the model, ensuring that diff views are properly populated. 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 the 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 counterproductive. 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
|
|
📊 PR Size: size/M
|
There was a problem hiding this comment.
Code Review
This pull request introduces CRLF line ending normalization in packages/a2a-server/src/agent/task.ts by converting \r\n to \n in the raw file content before applying replacements, and adds corresponding unit tests. The reviewer correctly pointed out that old_string and new_string should also be normalized to LF to prevent replacement failures if they contain CRLF line endings.
Normalize raw file content line endings from CRLF (\r\n) to LF (\n) before applying replacements in the local agent backend. This resolves a silent search-and-replace failure on Windows that caused empty diff views and subsequent 400 INVALID_ARGUMENT API crashes.
43ed638 to
b89919d
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces CRLF line ending normalization in Task.getProposedContent to ensure string replacements succeed regardless of the file's line endings, along with corresponding unit tests. The reviewer feedback correctly points out that unconditionally converting CRLF files to LF in the proposed content can cause full-file diff mismatches in IDEs. It is recommended to detect the original line endings and restore CRLF if it was present, and to update the new unit tests to assert that CRLF line endings are preserved.
63c416c to
25af965
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces CRLF line ending normalization in Task.getProposedContent to ensure consistent replacement behavior regardless of the file's line endings. It normalizes the file content, the search string, and the replacement string to LF before applying the replacement, and restores CRLF line endings if they were originally present. Additionally, unit tests have been added to verify this behavior. There are no review comments, so I have no feedback to provide.
Summary
This PR resolves an issue where the side-by-side diff view in Gemini Code Assist
(GCA) on Windows fails to highlight any changes when code is generated or
modified. The root cause is a line ending mismatch (CRLF vs. LF) in the local
agent backend (
a2a-serverpackage) that prevents text replacement frommatching correctly.
Details
On Windows, local files default to CRLF (
\r\n) line endings, while the modelgenerates search and replacement blocks using standard LF (
\n) line endings.When GCA requests a diff view, the local agent backend intercepts the
replacetool call to pre-calculate the proposed content. However, it reads the local
file without normalizing its line endings. This causes
safeLiteralReplacetofail the substring match and silently return the original content unmodified,
resulting in an empty diff view.
This PR updates
packages/a2a-server/src/agent/task.tsto normalize the rawfile content to LF (
\n) before applying the replacement, aligning itsbehavior with the core package's
EditTool.Related Issues
How to Validate
npm installandnpm run buildto compile the monorepo.task.test.tspass successfully, including thenew
getProposedContent (CRLF Line Ending Normalization)test.Pre-Merge Checklist