Skip to content

fix(agent): stabilize review item fingerprints - #732

Open
Linxiushen wants to merge 1 commit into
alibaba:mainfrom
Linxiushen:fix/stable-review-fingerprints
Open

fix(agent): stabilize review item fingerprints#732
Linxiushen wants to merge 1 commit into
alibaba:mainfrom
Linxiushen:fix/stable-review-fingerprints

Conversation

@Linxiushen

Copy link
Copy Markdown
Contributor

Description

Normalize trailing CR/LF delimiters before hashing per-file review diffs. The patch splitter can leave an extra line ending on whichever file is last in a multi-file patch, which previously changed that file's fingerprint and defeated --resume reuse even when its hunks were unchanged.

The normalization is limited to line-ending characters. Real unified-diff content lines keep their leading marker and remain fingerprint-significant. Existing sessions may incur one clean re-review across this change; fingerprints are stable after that transition.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactoring (no functional changes)
  • Documentation update
  • CI / Build / Tooling

How Has This Been Tested?

  • Full Go test suite: go test ./...
  • Targeted agent and diff package tests
  • Static analysis: go vet ./...
  • Manual testing (describe below)

Checklist

  • My code follows the project's coding style (gofmt, go vet)
  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective or my feature works
  • New and existing unit tests pass locally with my changes
  • I have updated the documentation accordingly (not applicable; no user-facing configuration change)
  • I have signed the CLA

Related Issues

Closes #718

Normalize position-dependent trailing line endings before hashing per-file diffs so unchanged files can be reused across resumed reviews.
@CLAassistant

CLAassistant commented Aug 5, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

🔍 OpenCodeReview found 1 issue(s) in this PR.

  • ✅ Successfully posted inline: 1 comment(s)

Comment thread internal/agent/agent.go
// The patch splitter can leave extra line endings on the final file in a
// multi-file patch. Unified diff content lines always carry a marker, so
// trimming CR/LF here removes only that position-dependent delimiter.
diffText := strings.TrimRight(d.Diff, "\r\n")

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.

[bug · low]
Potential issue: strings.TrimRight strips all trailing characters in the cutset (\r, \n), not just one trailing newline sequence. If the diff legitimately contains trailing blank lines (e.g., a context line that is empty, or a "\ No newline at end of file" scenario where the final line content itself ends with \r or \n), those would also be stripped — collapsing distinct diffs into the same fingerprint.

Consider using a more precise trim that only removes a single trailing line ending, e.g. strings.TrimSuffix applied once for \r\n then \n, to match what the comment describes ("removes only that position-dependent delimiter").

Suggestion:

Suggested change
diffText := strings.TrimRight(d.Diff, "\r\n")
diffText := d.Diff
diffText = strings.TrimSuffix(diffText, "\n")
diffText = strings.TrimSuffix(diffText, "\r")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Keeping TrimRight here intentionally. In a unified diff, every payload line carries a marker: context lines start with a space, additions/deletions with +/- and the no-newline marker with a backslash. A real empty trailing context line is therefore represented as a space-bearing line, never as bare CR/LF bytes. Any run of bare line endings after the final marked line is splitter delimiter noise, and trimming only one would reintroduce the cross-file-position instability this change fixes. The regression test covers both sides: multiple bare trailing newlines normalize to the same fingerprint, while a real empty context line (newline + space) changes it.

@lizhengfeng101

Copy link
Copy Markdown
Collaborator

Hi @Linxiushen, thanks for your contributions! I noticed that you've submitted several PRs but haven't signed our Contributor License Agreement (CLA) yet. Unfortunately, we are unable to review or merge any PRs until the CLA is signed. Could you please sign it at your earliest convenience? Once completed, we'll be happy to proceed with the review. Thank you!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Per-file diff fingerprint depends on the file's position in the patch (trailing-newline artifact), silently defeating --resume reuse

3 participants