fix: improve interrupt responsiveness during concurrent tool execution and follow-up turns (#10935)

Three targeted fixes for the 'agent stuck on terminal command' report:

1. **Concurrent tool wait loop now checks interrupts** (run_agent.py)
   The sequential path checked _interrupt_requested before each tool call,
   but the concurrent path's wait loop just blocked with 30s timeouts.
   Now polls every 5s and cancels pending futures on interrupt, giving
   already-running tools 3s to notice the per-thread interrupt signal.

2. **Cancelled concurrent tools get proper interrupt messages** (run_agent.py)
   When a concurrent tool is cancelled or didn't return a result due to
   interrupt, the tool result message says 'skipped due to user interrupt'
   instead of a generic error.

3. **Typing indicator fires before follow-up turn** (gateway/run.py)
   After an interrupt is acknowledged and the pending message dequeued,
   the gateway now sends a typing indicator before starting the recursive
   _run_agent call. This gives the user immediate visual feedback that
   the system is processing their new message (closing the perceived
   'dead air' gap between the interrupt ack and the response).

Reported by @_SushantSays.
This commit is contained in:
Teknium
2026-04-16 02:44:56 -07:00
committed by GitHub
parent 3f6c4346ac
commit 333cb8251b
3 changed files with 194 additions and 13 deletions

View File

@@ -9443,6 +9443,19 @@ class GatewayRunner:
return result
next_message_id = getattr(pending_event, "message_id", None)
# Restart typing indicator so the user sees activity while
# the follow-up turn runs. The outer _process_message_background
# typing task is still alive but may be stale.
_followup_adapter = self.adapters.get(source.platform)
if _followup_adapter:
try:
await _followup_adapter.send_typing(
source.chat_id,
metadata=_status_thread_metadata,
)
except Exception:
pass
return await self._run_agent(
message=next_message,
context_prompt=context_prompt,