Skip to content

[Bug]: Yuanbao adapter adds a fixed ~5 second delay during gateway shutdown #40383

Closed

Description

@libo1106

Bug Description

When running Hermes with the Yuanbao platform enabled, stopping the gateway consistently takes approximately 5 seconds even when there are no active sessions.

The shutdown sequence completes immediately for all phases except Yuanbao adapter disconnection.

Relevant logs:

INFO gateway.run: Received SIGINT as a planned gateway stop — exiting cleanly
INFO gateway.run: Stopping gateway...
INFO gateway.run: Shutdown phase: notify_active_sessions done at +0.00s
INFO gateway.run: Shutdown phase: drain done at +0.00s (drain took 0.00s, timed_out=False, active_at_start=0, active_now=0)

INFO gateway.platforms.yuanbao: [Yuanbao] Disconnected
INFO gateway.run: ✓ yuanbao disconnected (5.01s)

INFO gateway.run: Shutdown phase: all adapters disconnected at +5.02s
INFO gateway.run: Gateway stopped (total teardown 5.02s)

The shutdown delay appears to come entirely from the Yuanbao adapter disconnect path.

Steps to Reproduce

  1. Configure and start Hermes with the Yuanbao platform enabled.
  2. Ensure there are no active conversations or running tasks.
  3. Stop the gateway with SIGINT (Ctrl+C).
  4. Observe shutdown timing in logs.

Expected Behavior

Gateway shutdown should complete almost immediately when there are no active sessions or pending Yuanbao operations.

Adapter disconnect should not introduce a fixed multi-second delay.

Actual Behavior

The Yuanbao adapter consistently requires approximately 5 seconds to disconnect:

✓ yuanbao disconnected (5.01s)

As a result, total gateway teardown time is approximately 5 seconds even when the system is otherwise idle.

Affected Component

Gateway (Telegram/Discord/Slack/WhatsApp)

Messaging Platform (if gateway-related)

No response

Debug Report

Report       https://paste.rs/pNwc6
  agent.log    https://paste.rs/Pct7f
  gateway.log  https://paste.rs/llN7Q

Operating System

Debian GNU/Linux 12 (bookworm)

Python Version

3.11.2

Hermes Version

0.16.0

Additional Logs / Traceback (optional)

Root Cause Analysis (optional)

No response

Proposed Fix (optional)

No response

Are you willing to submit a PR for this?

  • I'd like to fix this myself and submit a PR

Activity

  1. added
    type/bugSomething isn't working
    comp/gatewayGateway runner, session dispatch, delivery
    P2Medium — degraded but workaround exists
    on Jun 6, 2026
  2. maxmilian commented on Jun 6, 2026

    @maxmilian

    Picking this up — PR incoming.

    Root cause confirmed against main: ConnectionManager._cleanup_ws() (gateway/platforms/yuanbao.py) awaits ws.close(), and the WS is opened with close_timeout=5. The websockets close handshake blocks up to close_timeout waiting for the server's close-frame echo; on an idle shutdown the server doesn't reply, so it always waits the full ~5s — matching your ✓ yuanbao disconnected (5.01s) log. Fix is to bound the close await on the shutdown path so a non-responsive server can't stall teardown.

    @libo1106 you'd flagged you might PR this yourself — happy to hand it back if you've already started; otherwise I'll have a fix + regression test up shortly.

  3. libo1106 commented on Jun 8, 2026

    @libo1106
    Author

    I saw that this has already been merged in #40607. Thanks, @maxmilian

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium — degraded but workaround existscomp/gatewayGateway runner, session dispatch, deliverytype/bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions