Skip to content

[Bug]: Feishu WebSocket sessions not closed on gateway restart — zombie sessions accumulate in DB #9090

@CrazyMed

Description

@CrazyMed

Bug Description

When the Hermes gateway restarts, Feishu WebSocket connections are dropped but active sessions are NOT properly closed in the session DB. This causes zombie sessions (with ) to accumulate indefinitely.

Every gateway restart produces new zombie sessions. Over time, the DB accumulates dozens of stale sessions.

Environment

  • Hermes Agent: Latest (running from NousResearch/hermes-agent)
  • Platform: Feishu (WebSocket mode, not webhook)
  • Session DB: SQLite at

Steps to Reproduce

  1. Start Hermes gateway with Feishu WebSocket adapter active
  2. Send messages — sessions are created normally
  3. Restart the gateway (e.g., ✓ User service restart requested)
  4. Check DB: sessions that were active at restart time have and

Expected Behavior

On gateway shutdown, all active sessions should be closed in the session store with .

Actual Behavior

Sessions remain in DB with . These are the symptoms:

  1. cleans up the WebSocket thread and event loop
  2. BUT it does NOT call or for any active sessions
  3. The in also does not close platform sessions when an adapter disconnects
  4. Result: zombie sessions accumulate across every restart cycle

Root Cause

In , calls for each platform adapter, but:

  • The disconnect handler in only cancels internal background tasks and the WebSocket thread
  • No call to to mark active sessions as ended

Normal session cleanup paths ( with reason , , ) are bypassed during crash/restart because those paths are only hit through the normal message handling loop.

Session DB Evidence

All properly closed sessions have set (session_reset, compression, session_switch). Zombie sessions always have .

Suggested Fix

In (or in before calling ), close all active sessions for that platform:

Or more generally — the gateway should close all sessions when shutting down, not rely on each platform adapter to do it.

Are you willing to submit a PR?

No — reporting for awareness and tracking.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium — degraded but workaround existscomp/gatewayGateway runner, session dispatch, deliveryplatform/feishuFeishu / Lark adaptertype/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions