fix: cap wildcard import expansion to avoid token explosion#1951
fix: cap wildcard import expansion to avoid token explosion#1951mashraf-222 wants to merge 1 commit intomainfrom
Conversation
…ute stalls Wildcard imports like `import org.jooq.*` expand to 870+ types, causing 5 minutes of disk I/O per function before the token budget check kicks in. 89% of jOOQ functions were skipped due to this. When a wildcard expands to >50 types, filter to only types referenced in the target method's code. This turns a 5-minute failure into a <1 second resolution with only the relevant types included. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Claude finished @mashraf-222's task in 4m 36s —— View job PR Review Summary
Prek Checks
Mypy reports 3 errors on lines 901, 936, 1104 of Code ReviewThe fix is correct and well-targeted. The probe-then-filter approach (call with One design concern worth considering: Double directory traversal ( However, if No issues that would crash at runtime or break existing behavior. The new parameters to Duplicate DetectionNo duplicates detected. Test CoverageNew test
One gap: No test for the "no priority types available → cap at 50" fallback path ( Optimization PRsPR #1943 (⚡️ Last updated: 2026-04-01T16:23 UTC |
Problem
Wildcard imports like
import org.jooq.*expand to 870+ types, causing 5 minutes of disk I/O per function before discovering the 4000-token skeleton budget is exceeded. In jOOQ, 89% of functions (70/79) were skipped due to token overflow from wildcard imports.The
expand_wildcard_import()function globs all.javafiles in the package directory unconditionally, and the token budget check inget_java_imported_type_skeletons()only fires after reading each file and parsing its skeleton — by which point hundreds of files have already been read from disk.Root Cause
context.py:933-940: Wildcard expansion happens without any count limit or early bailout.import_resolver.py:223-252:expand_wildcard_import()returns all types unconditionally.Fix
import_resolver.pymax_typesparameter toexpand_wildcard_import()for early terminationfilter_namesparameter to only include types matching a given setcontext.pyMAX_WILDCARD_TYPES_UNFILTERED = 50constantfilter_names=priority_types(only referenced types)This turns a 5-minute failure into <1 second resolution with only the relevant types included.
Test Coverage
New test
test_large_wildcard_is_filtered_to_referenced_types:All 4 existing edge case tests pass unchanged.
Closes CF-1085
🤖 Generated with Claude Code