Skip to content

Commit

Permalink
fix(autofix): Prevent long wait times for insights threadpool at end …
Browse files Browse the repository at this point in the history
…of run (#1631)

Issue #1630 

I discovered in profiling that when the root cause step completed, there
was sometimes a huge wait (the case I saw was 6 seconds) for the thread
pool to finish it's last insight card generation, before moving onto the
root cause formatter. (similar for the coding step)

Why? Because we started a new insight sharing thread after every LLM
call, including the final call of the agent run. Due to Zach's changes
that make us wait for threads to complete before ending the run, this
caused big delays.

Solutions in this PR:
1. Don't generate an insight card on the final output of the run. That
was somewhat redundant anyway if we're about to show the final output
card, plus this avoids starting a new thread from scratch that blocks
everything else.
2. Adds a second thread worker. That way while running in parallel with
the main agent, one insight doesn't have to wait for the previous to
complete, and it's unlikely that insights will "fall behind" the main
agent.

We could completely eliminate this delay if we didn't wait for the
threads to be completed, and I'm not sure that's a bad idea, but I'm
still assuming we don't want to sacrifice that safety. This PR mitigates
most of the issue while maintaining thread safety.
  • Loading branch information
roaga authored Dec 16, 2024
1 parent 13dcc90 commit bf00249
Show file tree
Hide file tree
Showing 4 changed files with 1,582 additions and 379 deletions.
7 changes: 4 additions & 3 deletions src/seer/automation/autofix/autofix_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,10 @@ def run_iteration(self, run_config: RunConfig):
# log thoughts to the user
cur = self.context.state.get()
if (
completion.message.content
and self.config.interactive
completion.message.content # only if we have something to summarize
and self.config.interactive # only in interactive mode
and not cur.request.options.disable_interactivity
and completion.message.tool_calls # only if the run is in progress
):
text_before_tag = completion.message.content.split("<")[0]
text = text_before_tag
Expand Down Expand Up @@ -171,7 +172,7 @@ def run_iteration(self, run_config: RunConfig):
@contextlib.contextmanager
def manage_run(self):
self.futures = []
self.executor = ThreadPoolExecutor(max_workers=1, initializer=copy_modules_initializer())
self.executor = ThreadPoolExecutor(max_workers=2, initializer=copy_modules_initializer())
with super().manage_run(), self.executor:
yield
for future in self.futures:
Expand Down
Loading

0 comments on commit bf00249

Please sign in to comment.