Skip to content

Commit 4596232

Browse files
author
Your Name
committed
refactor: Make agent mode interruptions more robust
Co-authored-by: cecli (openai/gemini_cli_local/gemini-2.5-pro)
1 parent 6caa11b commit 4596232

3 files changed

Lines changed: 29 additions & 4 deletions

File tree

cecli/coders/agent_coder.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,13 @@ async def gather_and_await():
745745

746746
if self.auto_lint and used_write_tool:
747747
edited = list(self.files_edited_by_tools)
748-
lint_errors = self.lint_edited(edited, show_output=False)
748+
lint_coro = self.lint_edited(edited, show_output=False)
749+
lint_errors, interrupted = await self.coroutines.interruptible(
750+
lint_coro, self.interrupt_event
751+
)
752+
if interrupted:
753+
raise KeyboardInterrupt("Interrupted during linting")
754+
749755
self.lint_outcome = not lint_errors
750756

751757
if lint_errors:
@@ -847,7 +853,12 @@ async def reply_completed(self):
847853
" its outputs are no longer necessary"
848854
)
849855
self.io.tool_output(waiting_msg)
850-
await asyncio.sleep(command_timeout / 2)
856+
sleep_coro = asyncio.sleep(command_timeout / 2)
857+
_res, interrupted = await self.coroutines.interruptible(
858+
sleep_coro, self.interrupt_event
859+
)
860+
if interrupted:
861+
raise KeyboardInterrupt("Interrupted while waiting for background commands")
851862
return True
852863

853864
# Check for recently finished commands that need reflection

cecli/coders/base_coder.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2200,7 +2200,15 @@ async def send_message(self, inp):
22002200
import asyncio
22012201

22022202
loop = asyncio.get_running_loop()
2203-
result = await loop.run_in_executor(None, self.format_messages)
2203+
2204+
async def format_in_executor():
2205+
return await loop.run_in_executor(None, self.format_messages)
2206+
2207+
result, interrupted = await self.coroutines.interruptible(
2208+
format_in_executor(), self.interrupt_event
2209+
)
2210+
if interrupted:
2211+
raise KeyboardInterrupt("Interrupted during message formatting")
22042212
messages = result
22052213

22062214
if not await self.check_tokens(messages):

cecli/models.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1278,7 +1278,13 @@ async def send_completion(
12781278

12791279
if override_kwargs:
12801280
kwargs = deep_merge(kwargs, override_kwargs)
1281-
res = await litellm.acompletion(**kwargs)
1281+
completion_coro = litellm.acompletion(**kwargs)
1282+
res, interrupted = await coroutines.interruptible(
1283+
completion_coro, interrupt_event
1284+
)
1285+
if interrupted:
1286+
raise KeyboardInterrupt("Interrupted during acompletion")
1287+
12821288
return hash_object, res
12831289
except litellm.ContextWindowExceededError as err:
12841290
raise err

0 commit comments

Comments
 (0)