Skip to content

fix(reward): ignore git extended headers and mode lines in diff norma… - #137

Open
shobhitagnihotri69 wants to merge 2 commits into
huggingface:mainfrom
shobhitagnihotri69:fix/diff-reward-extended-headers
Open

shobhitagnihotri69 wants to merge 2 commits into
huggingface:mainfrom
shobhitagnihotri69:fix/diff-reward-extended-headers

Conversation

@shobhitagnihotri69

Copy link
Copy Markdown

Summary

Ensures _normalize_diff in repo2rlenv.reward strips git extended headers (e.g. new file mode, old mode, deleted file mode, similarity index, and rename metadata) as well as \ No newline at end of file markers.

Problem

When evaluating agent-generated patches in calculate_diff_similarity_reward, if the model output matches the oracle code changes but differs in permission bits, file creation modes, or newline markers, the unstripped metadata lines cause the reward to degrade (e.g., scoring ~0.88 instead of 1.0). In an RL training loop, this introduces false reward penalties on valid solutions.

Solution

  • Added _GIT_EXTENDED_HEADER_RE to ignore mode changes and copy/rename metadata lines.
  • Added _NO_NEWLINE_RE to ignore git newline notice markers.
  • Added unit test test_normalization_ignores_git_extended_headers_and_mode_changes verifying identical code changes with extended headers score 1.0.

Verification

  • pytest tests/test_reward.py: All 6 tests passing.
  • pytest tests/test_grading.py: All 6 tests passing.
  • ruff check: All checks passed.

…lization

- Ignore git extended headers (new/deleted file mode, old/new mode, similarity index, copy/rename metadata) in _normalize_diff
- Ignore '\ No newline at end of file' diff markers
- Prevent false reward degradation when predicted patch matches oracle code changes but differs in permission bits or file modes
- Add unit test verifying identical code changes with extended headers score 1.0
@adithya-s-k

Copy link
Copy Markdown
Collaborator

Thanks, tested this and found a regression: an identical mode-only patch (100644 to 100755) scores 0 instead of 1 because normalization removes the whole oracle. Please preserve mode/rename-only changes and add regression tests. Also run ruff format on tests/test_reward.py; the extra blank line currently fails the check.

…changes

- Update _normalize_diff to preserve mode-only and rename-only changes
- Retain git extended headers and file path headers when no hunks are present so metadata-only patches are not normalized to empty diffs
- Add regression tests for identical mode-only, mode mismatch, and rename-only patches
- Fix ruff formatting in tests/test_reward.py
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.

2 participants