Repository navigation
Conversation
…ardown Port of NousResearch/hermes-agent#80372, closed there when Home Assistant moved to this plugin. The WebSocket handshake, the explicit closes on the connect and disconnect paths and the listen-task cancel in disconnect() now have a deadline. A failed or cancelled connect runs the same bounded close on its local session, and a close that does not finish in time stays tracked instead of being awaited forever, so a hung handshake or a wedged close can no longer leave the adapter stuck (NousResearch/hermes-agent#67470). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
7 of 11 tasks
This was referenced Nov 19, 2026
Closed
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ported from NousResearch/hermes-homeassistant#1 by @Sora-bluesky. The
hermes-homeassistantrepo moved into this monorepo (see the README), so this is the same commit applied underhomeassistant/, authorship kept. Review continues here.Original description:
What does this PR do?
Ports NousResearch/hermes-agent#80372 to this repo, as suggested when that PR was closed after Home Assistant moved out of core.
The adapter could go silently deaf (NousResearch/hermes-agent#67470): several awaits on the connect and teardown paths have no bound, so a hung auth handshake or a wedged WebSocket or session close leaves the adapter stuck while the gateway still reports it as running. On
mainhere these are the threereceive_json()calls in_ws_connect(adapter.py:159,:163,:167),obj.close()in_close(:180) and the listen-task wait indisconnect(:193)._ws_connect()builds the session into a local, boundsws_connectand every handshake send and receive with_HANDSHAKE_TIMEOUT(30 s), and runs the bounded close on the local socket and session on failure, timeout or cancellation.self._sessionandself._wsare only set once the handshake has succeeded._run_bounded_close()(_DRAIN_TIMEOUT, 5 s). Theasync withsessions insend()and_standalone_send()are not changed. A close that does not finish in time is logged and abandoned, and its task stays referenced until it ends.disconnect()cancels the listen task through_cancel_task_bounded(), so a task that ignores cancellation cannot hold teardown.There is no watchdog or stall detection in this PR, only the bounded waits.
Related Issue
NousResearch/hermes-agent#67470 (closed there when the adapter moved). Port of NousResearch/hermes-agent#80372.
Type of Change
Changes Made
adapter.py(+144/-30): the #80372 diff merged three-way onto this repo's adapter. The one overlap, the new module constants next toNOTIFICATION_TITLE, keeps both sides._connect_error_detail,Platform("homeassistant")and the registration in__init__.pyare untouched.tests/test_homeassistant_network_reconnect.py(new): the 15 tests from #80372 with the import switched tohomeassistant_plugin. One of them,test_cancel_task_bounded_abandons_uncancellable_task, now watches the helper withasyncio.waitand releases its uncancellable task in afinally, so a regression fails the test instead of hanging it.How to Test
PYTHONPATH=/path/to/hermes-agent python -m pytest tests -q: 78 passed, 2 skipped here (Windows 11, Python 3.11, hermes-agentmainat8b66a51036).adapter.pyput back tomain's version, the new file fails 15 of 15._cancel_task_boundedreplaced by a plainawait task,test_cancel_task_bounded_abandons_uncancellable_taskfails in about 2 s instead of hanging.ruff check adapter.py tests/test_homeassistant_network_reconnect.pyis clean.Not exercised against a live Home Assistant instance; the tests drive fake sockets and sessions.
Checklist
pytest tests -qand all tests passInfographic