fix(reward): ignore git extended headers and mode lines in diff norma… - #137
Open
shobhitagnihotri69 wants to merge 2 commits into
Open
shobhitagnihotri69 wants to merge 2 commits into
shobhitagnihotri69 wants to merge 2 commits into
Conversation
…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
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Ensures
_normalize_diffinrepo2rlenv.rewardstrips 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 filemarkers.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
_GIT_EXTENDED_HEADER_REto ignore mode changes and copy/rename metadata lines._NO_NEWLINE_REto ignore git newline notice markers.test_normalization_ignores_git_extended_headers_and_mode_changesverifying 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.