Skip to content

Commit

Permalink
refactor: Modify cache warming mechanism with ok_to_warm_cache flag
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-gauthier committed Feb 8, 2025
1 parent 35f30bd commit f7dd0fc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
15 changes: 7 additions & 8 deletions aider/coders/base_coder.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ def create(
use_kwargs.update(kwargs) # override passed kwargs

kwargs = use_kwargs
from_coder.ok_to_warm_cache = False

for coder in coders.__all__:
if hasattr(coder, "edit_format") and coder.edit_format == edit_format:
Expand Down Expand Up @@ -264,7 +265,7 @@ def get_announcements(self):

return lines

_cache_warming_stop = False
ok_to_warm_cache = False

def __init__(
self,
Expand Down Expand Up @@ -1198,25 +1199,23 @@ def format_messages(self):
return chunks

def warm_cache(self, chunks):
dump(self.add_cache_headers)
dump(self.num_cache_warming_pings)
if not self.add_cache_headers:
return
if not self.num_cache_warming_pings:
return
if not self.ok_to_warm_cache:
return

delay = 5 # * 60 - 5
delay = 5 * 60 - 5
self.next_cache_warm = time.time() + delay
self.warming_pings_left = self.num_cache_warming_pings
self.cache_warming_chunks = chunks
self._cache_warming_stop = False

if self.cache_warming_thread:
return

def warm_cache_worker():
while not self._cache_warming_stop:
dump(self.warming_pings_left)
while self.ok_to_warm_cache:
time.sleep(1)
if self.warming_pings_left <= 0:
continue
Expand Down Expand Up @@ -1543,7 +1542,7 @@ def lint_edited(self, fnames):

def __del__(self):
"""Cleanup when the Coder object is destroyed."""
self._cache_warming_stop = True
self.ok_to_warm_cache = False

def add_assistant_reply_to_cur_messages(self):
if self.partial_response_content:
Expand Down
3 changes: 3 additions & 0 deletions aider/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1060,10 +1060,13 @@ def get_io(pretty):

while True:
try:
coder.ok_to_warm_cache = True
coder.run()
analytics.event("exit", reason="Completed main CLI coder.run")
return
except SwitchCoder as switch:
coder.ok_to_warm_cache = False

kwargs = dict(io=io, from_coder=coder)
kwargs.update(switch.kwargs)
if "show_announcements" in kwargs:
Expand Down

0 comments on commit f7dd0fc

Please sign in to comment.