@@ -5,11 +5,13 @@ package patching
55
66import (
77 "encoding/json"
8+ "slices"
89
910 "github.com/google/syzkaller/pkg/aflow"
1011 "github.com/google/syzkaller/pkg/aflow/action/crash"
1112 "github.com/google/syzkaller/pkg/aflow/action/kernel"
1213 "github.com/google/syzkaller/pkg/aflow/ai"
14+ "github.com/google/syzkaller/pkg/aflow/tool/codeeditor"
1315 "github.com/google/syzkaller/pkg/aflow/tool/codeexpert"
1416 "github.com/google/syzkaller/pkg/aflow/tool/codesearcher"
1517)
@@ -40,7 +42,7 @@ type Outputs struct {
4042}
4143
4244func init () {
43- tools := append ([]aflow.Tool {codeexpert .Tool }, codesearcher .Tools ... )
45+ commonTools := slices . Clip ( append ([]aflow.Tool {codeexpert .Tool }, codesearcher .Tools ... ) )
4446
4547 aflow .Register [Inputs , Outputs ](
4648 ai .WorkflowPatching ,
@@ -60,17 +62,23 @@ func init() {
6062 Temperature : 1 ,
6163 Instruction : debuggingInstruction ,
6264 Prompt : debuggingPrompt ,
63- Tools : tools ,
65+ Tools : commonTools ,
6466 },
6567 kernel .CheckoutScratch ,
66- & aflow.LLMAgent {
67- Name : "diff-generator" ,
68- Model : aflow .BestExpensiveModel ,
69- Reply : "PatchDiff" ,
70- Temperature : 1 ,
71- Instruction : diffInstruction ,
72- Prompt : diffPrompt ,
73- Tools : tools ,
68+ & aflow.DoWhile {
69+ Do : aflow .Pipeline (
70+ & aflow.LLMAgent {
71+ Name : "patch-generator" ,
72+ Model : aflow .BestExpensiveModel ,
73+ Reply : "PatchExplanation" ,
74+ Temperature : 1 ,
75+ Instruction : patchInstruction ,
76+ Prompt : patchPrompt ,
77+ Tools : append (commonTools , codeeditor .Tool ),
78+ },
79+ crash .TestPatch , // -> PatchDiff or TestError
80+ ),
81+ While : "TestError" ,
7482 },
7583 & aflow.LLMAgent {
7684 Name : "description-generator" ,
@@ -79,6 +87,7 @@ func init() {
7987 Temperature : 1 ,
8088 Instruction : descriptionInstruction ,
8189 Prompt : descriptionPrompt ,
90+ Tools : commonTools ,
8291 },
8392 ),
8493 },
@@ -104,19 +113,43 @@ The crash is:
104113{{.CrashReport}}
105114`
106115
107- const diffInstruction = `
108- You are an experienced Linux kernel developer tasked with creating a patch for a kernel bug.
109- Your final reply should contain only the code diff in patch format.
116+ const patchInstruction = `
117+ You are an experienced Linux kernel developer tasked with creating a fix for a kernel bug.
118+ Use the codeedit tool to do code edits.
119+ Note: you will not see your changes when looking at the code using codesearch tools.
120+ Your final reply should contain explanation of what you did in the patch and why.
110121`
111122
112- const diffPrompt = `
123+ const patchPrompt = `
113124The crash that corresponds to the bug is:
114125
115126{{.CrashReport}}
116127
117128The explanation of the root cause of the bug is:
118129
119130{{.BugExplanation}}
131+
132+ {{if .TestError}}
133+ Another developer tried to fix this bug, and come up with the following patch:
134+
135+ {{.PatchDiff}}
136+
137+ and the following explanation:
138+
139+ {{.PatchExplanation}}
140+
141+ However, the patch testing failed with the following error:
142+
143+ {{.TestError}}
144+
145+ If the error is fixable, and the fix patch is correct overall,
146+ the create a new fixed patch based on the provided one with the errors fixed.
147+ If the error points to a fundamental issue with the approach in the patch,
148+ then create a new patch from scratch.
149+ Note: in both cases the source tree does not contain the patch yet
150+ (so if you want to create a new fixed patch, you need to recreate it
151+ in its entirety from scratch using the codeeditor tool).
152+ {{end}}
120153`
121154
122155const descriptionInstruction = `
@@ -140,4 +173,8 @@ The explanation of the root cause of the bug is:
140173The diff of the bug fix is:
141174
142175{{.PatchDiff}}
176+
177+ Additional description of the patch:
178+
179+ {{.PatchExplanation}}
143180`
0 commit comments