Skip to content

fix(a2a-server): normalize CRLF line endings to LF in getProposedContent - #28531

Merged
DavidAPierce merged 2 commits into
google-gemini:mainfrom
luisfelipe-alt:bugfix/WT-engineer_524655745
Jul 27, 2026
Merged

fix(a2a-server): normalize CRLF line endings to LF in getProposedContent#28531
DavidAPierce merged 2 commits into
google-gemini:mainfrom
luisfelipe-alt:bugfix/WT-engineer_524655745

Conversation

@luisfelipe-alt

Copy link
Copy Markdown
Contributor

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-server package) that prevents text replacement from
matching correctly.

Details

On Windows, local files default to CRLF (\r\n) line endings, while the model
generates search and replacement blocks using standard LF (\n) line endings.

When GCA requests a diff view, the local agent backend intercepts the replace
tool call to pre-calculate the proposed content. However, it reads the local
file without normalizing its line endings. This causes safeLiteralReplace to
fail 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.ts to normalize the raw
file content to LF (\n) before applying the replacement, aligning its
behavior with the core package's EditTool.

Related Issues

How to Validate

  1. Run npm install and npm run build to compile the monorepo.
  2. Run the newly added unit test to verify the fix:
    npx vitest run packages/a2a-server/src/agent/task.test.ts
  3. Verify that all 18 tests in task.test.ts pass successfully, including the
    new getProposedContent (CRLF Line Ending Normalization) test.
  4. Run the linter to ensure no style regressions:
    npm run lint

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

@luisfelipe-alt
luisfelipe-alt requested a review from a team as a code owner July 24, 2026 22:02
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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

  • Line Ending Normalization: Implemented CRLF to LF normalization in the getProposedContent method to ensure compatibility with Windows file systems.
  • Bug Fix: Resolved an issue where side-by-side diffs failed to display on Windows due to line ending mismatches preventing successful substring matching.
  • Regression Testing: Added a new unit test in task.test.ts to verify that content replacement works correctly when files contain CRLF line endings.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions github-actions Bot added the size/m A medium sized PR label Jul 24, 2026
@github-actions

github-actions Bot commented Jul 24, 2026

Copy link
Copy Markdown

📊 PR Size: size/M

  • Lines changed: 118
  • Additions: +113
  • Deletions: -5
  • Files changed: 2

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread packages/a2a-server/src/agent/task.ts
@gemini-cli gemini-cli Bot added the status/need-issue Pull requests that need to have an associated issue. label Jul 24, 2026
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.
@luisfelipe-alt

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread packages/a2a-server/src/agent/task.ts
Comment thread packages/a2a-server/src/agent/task.test.ts Outdated
Comment thread packages/a2a-server/src/agent/task.test.ts Outdated
@luisfelipe-alt
luisfelipe-alt force-pushed the bugfix/WT-engineer_524655745 branch from 63c416c to 25af965 Compare July 25, 2026 00:09
@luisfelipe-alt

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@DavidAPierce DavidAPierce left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/m A medium sized PR status/need-issue Pull requests that need to have an associated issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants