hermes - ✅(Solved) Fix Feishu plugin: RuntimeError Executor shutdown prevents message replies [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
NousResearch/hermes-agent#18740Fetched 2026-05-03 04:54:35
View on GitHub
Comments
0
Participants
1
Timeline
5
Reactions
0
Author
Participants
Timeline (top)
labeled ×4cross-referenced ×1

Error Message

RuntimeError: Executor shutdown has been called

Root Cause

In gateway/platforms/feishu.py line ~3919, the _send_raw_message method accesses self._bot_name:

if app_name and not self._bot_name:

This access occurs inside asyncio.to_thread() (thread pool executor). On macOS, the default ThreadPoolExecutor can be shut down by system events after extended gateway uptime, causing all send operations to fail with:

RuntimeError: Executor shutdown has been called

Fix Action

Workaround

Restart the gateway: hermes gateway restart

PR fix notes

PR #18772: fix(feishu): recover from executor shutdown on long-running gateway

Description (problem / solution / changelog)

Summary

After extended gateway uptime (~2 days on macOS), the default ThreadPoolExecutor used by asyncio.to_thread() can be shut down by system events, causing all Feishu SDK calls to fail with:

RuntimeError: Executor shutdown has been called

This makes the bot unable to send any replies until the gateway is manually restarted.

Changes

  • gateway/platforms/feishu.py: Add _run_in_executor() helper method to FeishuAdapter that wraps asyncio.to_thread() with executor-shutdown recovery. When the default executor is dead, it creates a fresh ThreadPoolExecutor, installs it via loop.set_default_executor(), and retries. All 19 asyncio.to_thread() call sites now use this helper.
  • tests/gateway/test_feishu.py: Add TestRunInExecutor with two tests: successful recovery from shutdown, and propagation of unrelated RuntimeError.

How it works

async def _run_in_executor(self, func, *args):
    try:
        return await asyncio.to_thread(func, *args)
    except RuntimeError as exc:
        if 'shutdown' not in str(exc).lower():
            raise
        logger.warning('[Feishu] Default executor shut down — creating a replacement: %s', exc)
        loop = asyncio.get_running_loop()
        loop.set_default_executor(concurrent.futures.ThreadPoolExecutor())
        return await asyncio.to_thread(func, *args)

Testing

python -m pytest tests/gateway/test_feishu.py::TestRunInExecutor -xvs
# 2 passed

Closes #18740

Changed files

  • gateway/platforms/feishu.py (modified, +33/-17)
  • tests/gateway/test_feishu.py (modified, +49/-0)

Code Example

if app_name and not self._bot_name:

---

RuntimeError: Executor shutdown has been called

---

File "...feishu.py", line 3919, in _send_raw_message
    if app_name and not self._bot_name:
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "...asyncio/threads.py", line 25, in to_thread
    return await loop.run_in_executor(None, func_call)
  File "...asyncio/base_events.py", line 823, in run_in_executor
    self._check_default_executor()
  File "...asyncio/base_events.py", line 524, in _check_default_executor
    raise RuntimeError('Executor shutdown has been called')
RuntimeError: Executor shutdown has been called
RAW_BUFFERClick to expand / collapse

Bug Description

The Feishu plugin fails to send replies after running for an extended period. All incoming messages are processed but the reply fails silently (from the user's perspective) or with RuntimeError: Executor shutdown has been called.

Root Cause

In gateway/platforms/feishu.py line ~3919, the _send_raw_message method accesses self._bot_name:

if app_name and not self._bot_name:

This access occurs inside asyncio.to_thread() (thread pool executor). On macOS, the default ThreadPoolExecutor can be shut down by system events after extended gateway uptime, causing all send operations to fail with:

RuntimeError: Executor shutdown has been called

Error Traceback

File "...feishu.py", line 3919, in _send_raw_message
    if app_name and not self._bot_name:
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "...asyncio/threads.py", line 25, in to_thread
    return await loop.run_in_executor(None, func_call)
  File "...asyncio/base_events.py", line 823, in run_in_executor
    self._check_default_executor()
  File "...asyncio/base_events.py", line 524, in _check_default_executor
    raise RuntimeError('Executor shutdown has been called')
RuntimeError: Executor shutdown has been called

Environment

  • macOS
  • Hermes Agent (git-installed)
  • Python 3.11
  • Gateway uptime: ~2 days before failure

Reproduction

  1. Start hermes gateway run
  2. Leave running for 1-2 days
  3. Send a message via Feishu — the bot processes it but cannot reply

Suggested Fix

The send path in feishu.py should handle RuntimeError from executor shutdown by either:

  1. Catching the error and retrying with a fresh executor
  2. Moving self._bot_name access outside of to_thread() context
  3. Using a dedicated long-lived executor for bot name lookups

Workaround

Restart the gateway: hermes gateway restart

extent analysis

TL;DR

The Feishu plugin's failure to send replies after an extended period can be addressed by handling the RuntimeError from executor shutdown, potentially by catching and retrying with a fresh executor or moving self._bot_name access outside of to_thread() context.

Guidance

  • Verify the Executor Shutdown: Confirm that the RuntimeError: Executor shutdown has been called is indeed the cause of the failure by checking the error traceback.
  • Assess Retry Mechanism: Evaluate the feasibility of implementing a retry mechanism for the _send_raw_message method to handle temporary executor shutdowns.
  • Review Executor Configuration: Investigate if the default ThreadPoolExecutor configuration on macOS can be adjusted to prevent shutdown after extended periods of inactivity.
  • Consider Dedicated Executor: Explore the option of using a dedicated, long-lived executor for bot name lookups to isolate this critical operation from the general executor pool.

Example

try:
    # Existing code within asyncio.to_thread()
except RuntimeError as e:
    if "Executor shutdown has been called" in str(e):
        # Retry with a fresh executor or handle the error appropriately
        pass

Notes

The provided suggestions assume that the issue is primarily related to the executor shutdown on macOS. However, the effectiveness of these suggestions may vary depending on the specific environment and the underlying causes of the executor shutdown.

Recommendation

Apply workaround: Restart the gateway (hermes gateway restart) as a temporary solution until a more permanent fix, such as handling the RuntimeError or adjusting the executor configuration, can be implemented. This is because restarting the gateway is a straightforward and immediate way to restore functionality, albeit not a long-term solution.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

hermes - ✅(Solved) Fix Feishu plugin: RuntimeError Executor shutdown prevents message replies [1 pull requests, 1 participants]