Commit fd3e0e0
Add LLM-powered automatic patch fixing for version bumps (#5013)
* Add LLM-powered automatic patch fixing for version bumps
This commit introduces an intelligent patch fixing system that uses AWS Bedrock
(Claude Sonnet 4.5) to automatically update patches when upstream versions change.
Key Features:
- Automatic patch conflict resolution using LLM analysis
- Smart context extraction showing current vs expected file state
- Pristine content capture before patch application for accurate context
- Iterative fixing with up to 3 attempts per patch
- Special handling for kubernetes/autoscaler project (cloud provider removal)
- Rate limiting and cost tracking for Bedrock API calls
- Comprehensive validation (semantic and build checks)
Implementation Details:
- Uses git apply --reject to identify conflicts and generate .rej files
- Extracts ±50 lines of context around conflict points
- Provides LLM with original patch intent and current file state
- Validates generated patches match original semantic changes
- Supports both release-branched and non-release-branched projects
Special Cases:
- kubernetes/autoscaler: Automated cloud provider removal and go mod tidy
- Handles complex multi-file patches with mixed success/failure states
- Preserves exact indentation and formatting from current files
Prompt Engineering:
- Explicit instructions to use current file content, not original patch context
- Critical warnings about indentation matching (tabs vs spaces)
- Structured format with metadata preservation
- Context pruning for large patches to stay within token limits
Core Components:
- fixpatches.go: Main orchestration and patch application logic
- llm.go: AWS Bedrock API integration with rate limiting
- context.go: Smart context extraction from .rej files and pristine content
- applier.go: Git operations for patch application and validation
- validator.go: Semantic and build validation of fixed patches
- autoscaler.go: Special handling for kubernetes/autoscaler project
- types/fixpatches.go: Type definitions for patch context and results
This enables automated maintenance of patches across version bumps, reducing
manual effort and ensuring patches stay current with upstream changes.
Tested on:
- kubernetes/autoscaler (1-29, 1-30)
- kube-vip/kube-vip
- linuxkit/linuxkit
- fluxcd/source-controller
- kubernetes-sigs/kind
* Move git commands to separate file and remove repitive code patterns
Signed-off-by: Rahul <[email protected]>
* Update documentation about fix-patches command
Signed-off-by: Rahul <[email protected]>
---------
Signed-off-by: Rahul <[email protected]>
Co-authored-by: Rahul <[email protected]>1 parent 0a2c5d9 commit fd3e0e0
File tree
16 files changed
+4291
-2
lines changed- tools/version-tracker
- cmd
- pkg
- commands
- fixpatches
- upgrade
- constants
- types
16 files changed
+4291
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
204 | 204 | | |
205 | 205 | | |
206 | 206 | | |
| 207 | + | |
| 208 | + | |
207 | 209 | | |
208 | 210 | | |
209 | 211 | | |
| |||
234 | 236 | | |
235 | 237 | | |
236 | 238 | | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
237 | 327 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
8 | 12 | | |
9 | 13 | | |
10 | 14 | | |
11 | 15 | | |
12 | 16 | | |
| 17 | + | |
13 | 18 | | |
14 | 19 | | |
15 | 20 | | |
16 | 21 | | |
17 | 22 | | |
18 | 23 | | |
19 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
20 | 29 | | |
21 | 30 | | |
22 | 31 | | |
23 | 32 | | |
24 | 33 | | |
25 | 34 | | |
26 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
27 | 52 | | |
28 | 53 | | |
| 54 | + | |
| 55 | + | |
29 | 56 | | |
30 | 57 | | |
31 | 58 | | |
32 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
33 | 63 | | |
34 | 64 | | |
35 | 65 | | |
| 66 | + | |
| 67 | + | |
36 | 68 | | |
37 | 69 | | |
38 | 70 | | |
| 71 | + | |
39 | 72 | | |
40 | 73 | | |
| 74 | + | |
41 | 75 | | |
42 | 76 | | |
43 | 77 | | |
| 78 | + | |
44 | 79 | | |
45 | 80 | | |
46 | 81 | | |
| 82 | + | |
47 | 83 | | |
48 | 84 | | |
49 | 85 | | |
| |||
61 | 97 | | |
62 | 98 | | |
63 | 99 | | |
| 100 | + | |
64 | 101 | | |
| 102 | + | |
65 | 103 | | |
66 | 104 | | |
67 | 105 | | |
68 | 106 | | |
69 | 107 | | |
70 | 108 | | |
71 | 109 | | |
72 | | - | |
73 | | - | |
74 | 110 | | |
| 111 | + | |
75 | 112 | | |
76 | 113 | | |
77 | 114 | | |
| |||
0 commit comments