fix: reject Java optimizations with unused additions and unchanged target method#1947
Open
mashraf-222 wants to merge 2 commits intomainfrom
Open
fix: reject Java optimizations with unused additions and unchanged target method#1947mashraf-222 wants to merge 2 commits intomainfrom
mashraf-222 wants to merge 2 commits intomainfrom
Conversation
…rget method Adds a wiring check in replace_function() that detects when the AI generates "optimizations" adding fields/helpers that the target method never references. Previously these passed through because benchmark noise produced fake speedups. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
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.
Problem
The AI optimizer sometimes generates "optimizations" that add new fields or helper methods to a Java class without changing the target method at all. Because benchmark noise produces small timing variations, these fake optimizations pass the speedup critic and create PRs with no real improvement.
Example: 4 commons-lang PRs each added
private static final Supplier<String> NULL_SUPPLIER = Suppliers.nul();but the target methods (getJavaAwtHeadless,getJavaIoTmpdir, etc.) were never modified to use it — yet reported 7-151% speedups.Root Cause
replace_function()inreplacement.pyaccepts any optimization that changes the file, even if the target method body is identical to the original. The dedup check compares the entire candidate (function + helpers/fields), so adding a new field makes it "different" from the original, bypassing the identity check.Fix
Added
_has_unused_additions()inreplacement.pythat:This causes
replace_function_definitions_for_language()to returnFalse(no update), which skips the candidate.Validation
/home/ubuntu/e2e-sessions/2026-04-01_15-45_cf1081-unused-additions/Test Coverage
New
TestUnusedAdditionsRejectionclass with 5 tests:test_unchanged_method_with_unused_field_rejected— unchanged method + unused field → rejectedtest_unchanged_method_with_unused_helper_rejected— unchanged method + unused helper → rejectedtest_changed_method_with_used_field_accepted— changed method + used field → acceptedtest_changed_method_without_additions_accepted— normal optimization → acceptedtest_unchanged_method_with_used_helper_accepted— method uses new helper → acceptedCloses CF-1081