Elffuss BraidHub

kikocis/auto-code-rover public

Initial implementation of fix localization mode
Changeset645e8ae0bdf2c9a2aa08e07758959c1b6b83cdbc47d0ba7eb78de700120a7d5b
AuthorMartin Mirchev <mirchevmartin2203@gmail.com> · 2024-07-18 12:59 +08:00
CommitterMartin Mirchev <mirchevmartin2203@gmail.com> · 2024-07-18 13:49 +08:00
Parents61cc3168abed

Browse the files at this changeset

3 files changed

modified app/globals.py +6 −0
@@ -29,3 +29,9 @@
2929
3030 # timeout for test cmd execution, currently set to 5 min
3131 test_exec_timeout: int = 300
32+
33+# A special mode to only collect fix locations and exit
34+disable_patch_generation: bool = False
35+
36+# Used with disable_patch_generation - constrains or extends the amount of context retrieval rounds
37+context_generation_limit: int = -1
modified app/inference.py +26 −13
@@ -93,7 +93,15 @@
9393 msg_thread.add_user(prompt)
9494
9595 round_no = start_round_no
96- for round_no in range(start_round_no, globals.conv_round_limit + 1):
96+
97+ round_count = range(start_round_no, globals.conv_round_limit + 1)
98+
99+ if globals.disable_patch_generation:
100+ round_count = range(
101+ start_round_no, start_round_no + globals.context_generation_limit + 1
102+ )
103+
104+ for round_no in round_count:
97105 api_manager.start_new_tool_call_layer()
98106
99107 conversation_file = pjoin(output_dir, f"conversation_round_{round_no}.json")
@@ -167,13 +175,17 @@
167175 ):
168176 msg_thread.add_user(collated_tool_response)
169177
170- print_banner("PATCH GENERATION")
171- logger.debug("Gathered enough information. Invoking write_patch.")
172- print_acr(
173- collated_tool_response,
174- "patch generation round 1",
175- print_callback=print_callback,
176- )
178+ if globals.disable_patch_generation:
179+ logger.debug("Gathered enough information. Skipping patch generation due to feature flag.")
180+ Path(output_dir, "fix_locations.json").write_text(json.dumps(buggy_locations, indent=4))
181+ else:
182+ print_banner("PATCH GENERATION")
183+ logger.debug("Gathered enough information. Invoking write_patch.")
184+ print_acr(
185+ collated_tool_response,
186+ "patch generation round 1",
187+ print_callback=print_callback,
188+ )
177189 break
178190
179191 msg = "The buggy locations is not precise. You may need to check whether the arguments are correct and search more information."
@@ -242,12 +254,13 @@
242254
243255 round_no += 1
244256
245- api_manager.start_new_tool_call_layer()
257+ if not globals.disable_patch_generation:
258+ api_manager.start_new_tool_call_layer()
246259
247- write_patch_intent = FunctionCallIntent("write_patch", {}, None)
248- api_manager.dispatch_intent(
249- write_patch_intent, msg_thread, print_callback=print_callback
250- )
260+ write_patch_intent = FunctionCallIntent("write_patch", {}, None)
261+ api_manager.dispatch_intent(
262+ write_patch_intent, msg_thread, print_callback=print_callback
263+ )
251264
252265 conversation_file = pjoin(output_dir, f"conversation_round_{round_no}.json")
253266 msg_thread.save_to_file(conversation_file)
modified app/main.py +31 −8
@@ -88,6 +88,8 @@
8888 globals.enable_angelic = args.enable_angelic
8989 globals.enable_perfect_angelic = args.enable_perfect_angelic
9090 globals.only_save_sbfl_result = args.save_sbfl_result
91+ globals.disable_patch_generation = args.output_fix_locs
92+ globals.context_generation_limit = args.output_fix_limit
9193
9294 subcommand = getattr(args, subparser_dest_attr_name)
9395 if subcommand == "swe-bench":
@@ -242,6 +244,20 @@
242244 default=1,
243245 help="Number of processes to run the tasks in parallel.",
244246 )
247+ parser.add_argument(
248+ "--output-fix-locs",
249+ action="store_true",
250+ required=False,
251+ default=False,
252+ help="Output fix locations to file and do not repair.",
253+ )
254+ parser.add_argument(
255+ "--output-fix-limit",
256+ type=int,
257+ required=False,
258+ default=10,
259+ help="Limit output of content retrieval rounds",
260+ )
245261
246262
247263 def make_swe_tasks(
@@ -438,18 +454,25 @@
438454
439455 log.log_and_always_print(run_status_message)
440456
441- final_patch_path = get_final_patch_path(task_output_dir)
442- if final_patch_path is not None:
457+ if globals.disable_patch_generation:
443458 log.log_and_always_print(
444- f"Please find the generated patch at: {final_patch_path}"
459+ f"Patch generation is disabled. Please find fix locations at: {task_output_dir}/fix_locations.json"
445460 )
446- if isinstance(task, RawSweTask):
461+ else:
462+ final_patch_path = get_final_patch_path(task_output_dir)
463+ if final_patch_path is not None:
447464 log.log_and_always_print(
448- "[SWE-bench mode] Note that the patch may be move to other paths in SWE-bench mode. "
449- "Please check the SWE-bench input file containing generated patches for all tasks."
465+ f"Please find the generated patch at: {final_patch_path}"
466+ )
467+ if isinstance(task, RawSweTask):
468+ log.log_and_always_print(
469+ "[SWE-bench mode] Note that the patch may be move to other paths in SWE-bench mode. "
470+ "Please check the SWE-bench input file containing generated patches for all tasks."
471+ )
472+ else:
473+ log.log_and_always_print(
474+ "No patch generated. You can try running ACR again."
450475 )
451- else:
452- log.log_and_always_print("No patch generated. You can try running ACR again.")
453476
454477 return run_ok
455478