Skip to content

fix(gateway): add request timeout to SMS adapter HTTP session#3201

Closed
binhnt92 wants to merge 1 commit intoNousResearch:mainfrom
binhnt92:fix/sms-gateway-http-timeout
Closed

fix(gateway): add request timeout to SMS adapter HTTP session#3201
binhnt92 wants to merge 1 commit intoNousResearch:mainfrom
binhnt92:fix/sms-gateway-http-timeout

Conversation

@binhnt92
Copy link
Copy Markdown
Contributor

@binhnt92 binhnt92 commented Mar 26, 2026

SmsAdapter created aiohttp.ClientSession() without a timeout, so a slow or unresponsive Twilio API could hang the gateway event loop indefinitely. The send_message_tool already uses ClientTimeout(total=30) for its Twilio calls — this just applies the same default to the gateway SMS adapter.

  • Add ClientTimeout(total=30) to the persistent session in connect()
  • 2 tests verifying the session timeout is set

Changes Made

  • gateway/platforms/sms.py: add timeout=aiohttp.ClientTimeout(total=30) to ClientSession constructor in connect()
  • tests/gateway/test_sms_timeout.py: new test file — verifies session timeout on connect and send

How to Test

  1. pytest tests/gateway/test_sms_timeout.py -v — 2 tests pass
  2. pytest tests/gateway/ -v — full gateway suite passes (1454 passed, 3 pre-existing failures unrelated)

Checklist

  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes
  • I've tested on my platform: Ubuntu 22.04

SmsAdapter created aiohttp.ClientSession() without a timeout, so a slow
or unresponsive Twilio API could hang the gateway event loop indefinitely.
The send_message_tool already uses ClientTimeout(total=30) for its Twilio
calls — this applies the same default to the gateway SMS adapter.
teknium1 added a commit that referenced this pull request Mar 26, 2026
…ters

Add timeout=30 to all bare ClientSession, IMAP4_SSL, smtplib.SMTP, and
ws_connect calls that previously had no timeout, preventing indefinite
hangs when an external server is slow or unresponsive.

Adapters hardened:
- HomeAssistant: REST + WS session creation, ws_connect handshake
- Email: all IMAP4_SSL (x2) and smtplib.SMTP (x3) calls
- Mattermost: session creation, _api_get, _api_post, _upload_file (60s)
- SMS: session creation in connect() + fallback session in send()

Salvaged from PRs #3161, #3168, #3170 (memosr) and #3201 (binhnt92).
SMS fallback ClientSession on send() also patched (missed in #3201).

Co-authored-by: memosr <memosr@users.noreply.github.com>
Co-authored-by: nguyen binh <binhnt92@users.noreply.github.com>
@teknium1
Copy link
Copy Markdown
Contributor

Merged via PR #3258 — your SMS adapter timeout was cherry-picked onto current main. We also patched the fallback ClientSession in send() (line 147) which was missing a timeout. Thanks for including tests!

@teknium1 teknium1 closed this Mar 26, 2026
teknium1 added a commit that referenced this pull request Mar 26, 2026
…ters (#3258)

Add timeout=30 to all bare ClientSession, IMAP4_SSL, smtplib.SMTP, and
ws_connect calls that previously had no timeout, preventing indefinite
hangs when an external server is slow or unresponsive.

Adapters hardened:
- HomeAssistant: REST + WS session creation, ws_connect handshake
- Email: all IMAP4_SSL (x2) and smtplib.SMTP (x3) calls
- Mattermost: session creation, _api_get, _api_post, _upload_file (60s)
- SMS: session creation in connect() + fallback session in send()

Salvaged from PRs #3161, #3168, #3170 (memosr) and #3201 (binhnt92).
SMS fallback ClientSession on send() also patched (missed in #3201).

Co-authored-by: memosr <memosr@users.noreply.github.com>
Co-authored-by: nguyen binh <binhnt92@users.noreply.github.com>
StreamOfRon pushed a commit to StreamOfRon/hermes-agent that referenced this pull request Mar 29, 2026
…ters (NousResearch#3258)

Add timeout=30 to all bare ClientSession, IMAP4_SSL, smtplib.SMTP, and
ws_connect calls that previously had no timeout, preventing indefinite
hangs when an external server is slow or unresponsive.

Adapters hardened:
- HomeAssistant: REST + WS session creation, ws_connect handshake
- Email: all IMAP4_SSL (x2) and smtplib.SMTP (x3) calls
- Mattermost: session creation, _api_get, _api_post, _upload_file (60s)
- SMS: session creation in connect() + fallback session in send()

Salvaged from PRs NousResearch#3161, NousResearch#3168, NousResearch#3170 (memosr) and NousResearch#3201 (binhnt92).
SMS fallback ClientSession on send() also patched (missed in NousResearch#3201).

Co-authored-by: memosr <memosr@users.noreply.github.com>
Co-authored-by: nguyen binh <binhnt92@users.noreply.github.com>
angelburgosrosado pushed a commit to angelburgosrosado/hermes-agent that referenced this pull request Apr 27, 2026
…ters (NousResearch#3258)

Add timeout=30 to all bare ClientSession, IMAP4_SSL, smtplib.SMTP, and
ws_connect calls that previously had no timeout, preventing indefinite
hangs when an external server is slow or unresponsive.

Adapters hardened:
- HomeAssistant: REST + WS session creation, ws_connect handshake
- Email: all IMAP4_SSL (x2) and smtplib.SMTP (x3) calls
- Mattermost: session creation, _api_get, _api_post, _upload_file (60s)
- SMS: session creation in connect() + fallback session in send()

Salvaged from PRs NousResearch#3161, NousResearch#3168, NousResearch#3170 (memosr) and NousResearch#3201 (binhnt92).
SMS fallback ClientSession on send() also patched (missed in NousResearch#3201).

Co-authored-by: memosr <memosr@users.noreply.github.com>
Co-authored-by: nguyen binh <binhnt92@users.noreply.github.com>
angelburgosrosado pushed a commit to angelburgosrosado/hermes-agent that referenced this pull request Apr 28, 2026
…ters

Add timeout=30 to all bare ClientSession, IMAP4_SSL, smtplib.SMTP, and
ws_connect calls that previously had no timeout, preventing indefinite
hangs when an external server is slow or unresponsive.

Adapters hardened:
- HomeAssistant: REST + WS session creation, ws_connect handshake
- Email: all IMAP4_SSL (x2) and smtplib.SMTP (x3) calls
- Mattermost: session creation, _api_get, _api_post, _upload_file (60s)
- SMS: session creation in connect() + fallback session in send()

Salvaged from PRs NousResearch#3161, NousResearch#3168, NousResearch#3170 (memosr) and NousResearch#3201 (binhnt92).
SMS fallback ClientSession on send() also patched (missed in NousResearch#3201).

Co-authored-by: memosr <memosr@users.noreply.github.com>
Co-authored-by: nguyen binh <binhnt92@users.noreply.github.com>
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.

2 participants