Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions gateway/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -4347,10 +4347,15 @@ async def start(self) -> bool:
# Drain any recovered process watchers (from crash recovery checkpoint)
try:
from tools.process_registry import process_registry
while process_registry.pending_watchers:
watcher = process_registry.pending_watchers.pop(0)
watchers = process_registry.pending_watchers
# Process in batches of 100 with event-loop yield points to avoid
# O(n^2) event-loop blocking when recovering thousands of watchers.
for i, watcher in enumerate(watchers):
asyncio.create_task(self._run_process_watcher(watcher))
logger.info("Resumed watcher for recovered process %s", watcher.get("session_id"))
if i % 100 == 99:
await asyncio.sleep(0)
watchers.clear()
except Exception as e:
logger.error("Recovered watcher setup error: %s", e)

Expand Down Expand Up @@ -7665,7 +7670,7 @@ async def _do_undo():
result = await result
return str(result) if result else None
except Exception as e:
logger.debug("Plugin command dispatch failed (non-fatal): %s", e)
logger.warning("Plugin command dispatch failed: %s", e)

# Skill slash commands: /skill-name loads the skill and sends to agent.
# resolve_skill_command_key() handles the Telegram underscore/hyphen
Expand Down Expand Up @@ -7697,7 +7702,7 @@ async def _do_undo():
)
# Fall through to normal message processing with bundle content
except Exception as exc:
logger.debug("Bundle dispatch failed (non-fatal): %s", exc)
logger.warning("Bundle dispatch failed: %s", exc)

if command and not locals().get("_bundle_handled", False):
try:
Expand Down Expand Up @@ -8849,9 +8854,12 @@ async def _handle_message_with_agent(self, event, source, _quick_key: str, run_g
# Check for pending process watchers (check_interval on background processes)
try:
from tools.process_registry import process_registry
while process_registry.pending_watchers:
watcher = process_registry.pending_watchers.pop(0)
watchers = process_registry.pending_watchers
for i, watcher in enumerate(watchers):
asyncio.create_task(self._run_process_watcher(watcher))
if i % 100 == 99:
await asyncio.sleep(0)
watchers.clear()
except Exception as e:
logger.error("Process watcher setup error: %s", e)

Expand Down