Skip to content

fix: resource leaks and crashes in long-running gateway#993

Open
Himess wants to merge 1 commit intoNousResearch:mainfrom
Himess:fix/gateway-resource-leaks
Open

fix: resource leaks and crashes in long-running gateway#993
Himess wants to merge 1 commit intoNousResearch:mainfrom
Himess:fix/gateway-resource-leaks

Conversation

@Himess
Copy link
Contributor

@Himess Himess commented Mar 12, 2026

Fixes #990

Four fixes for issues that compound in long-running gateway processes:

  • Log handler accumulation: guard RotatingFileHandler addition with a module-level flag so it only runs once
  • Delivery dedup mismatch: (Platform.LOCAL, None)(Platform.LOCAL, None, None) to match the 3-tuple in seen_platforms
  • Context compressor crash: (content or "").strip() to handle None API responses
  • Thread pool leak: shutdown(wait=False) old executor before replacing in resize_tool_pool()

- Prevent RotatingFileHandler accumulation: each AIAgent.__init__ was
  appending a new handler to the root logger without checking if one
  already exists. After N messages the same log line is written N times.
  Guard with a module-level flag.

- Fix delivery dedup tuple mismatch: seen_platforms stores 3-tuples
  (platform, chat_id, thread_id) but the local check used a 2-tuple
  that never matches, causing duplicate LOCAL deliveries.

- Fix AttributeError in context compressor: content can be None when
  the API returns no text, calling .strip() on None crashes.

- Shutdown old ThreadPoolExecutor in resize_tool_pool: the previous
  executor was replaced without shutdown(), leaking threads.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Log handler accumulates on every AIAgent init, degrading gateway performance

1 participant