fix(mattermost): avoid aiohttp timeout context in sends - #39877
Conversation
teknium1
left a comment
There was a problem hiding this comment.
Thanks for tracing the standalone Mattermost delivery path.
Problems
- The reported no-task mechanism is not demonstrated on current main. Cron executes the standalone sender through
asyncio.run()incron/scheduler.py:1902-1905; the submitted standalone test likewise calls it throughasyncio.run()intests/tools/test_send_message_missing_platforms.py:108. - The new tests assert that
ClientTimeoutis not called, but do not reproduce the reported error or exercise the cron dispatch path. - The issue identifies
_standalone_send, while this diff also changes live gateway helpers, downloads, uploads, and the adapter session timeout inplugins/platforms/mattermost/adapter.py.
Suggested changes
- Add a regression that reproduces the failure through the real cron standalone-delivery path.
- If confirmed, scope the fix to
_standalone_sendand preserve the existing bounded timeout there; keep live gateway timeout behavior unchanged unless independently reproduced.
Automated hermes-sweeper review.
| @@ -166,7 +166,8 @@ async def test_send_calls_api_post(self): | |||
|
|
|||
| self.adapter._session.post = MagicMock(return_value=mock_resp) | |||
|
|
|||
There was a problem hiding this comment.
This only asserts that ClientTimeout is absent. Please add a regression that reproduces the reported cron standalone-delivery failure; the existing standalone test already uses asyncio.run(), so it does not establish the claimed missing-task context.
|
Closing this broad implementation because the reported mechanism is not reproducible on the current cron path: scheduler delivery enters through asyncio.run(), which creates a task, and a fresh aiohttp ClientSession with ClientTimeout works in that context. The patch also changes gateway upload/download/session timeouts beyond the reported standalone sender. A future fix needs a current-main cron-path regression that reproduces the actual failure first. |
Summary
aiohttp.ClientTimeoutfrom Mattermost send, upload, and download pathsasyncio.wait_for()MattermostAdapter.send()and standalone cron delivery so scheduled Mattermost sends do not hit aiohttp's timeout task-context errorFixes #39836.
Tests
.venv/bin/python -m pytest tests/gateway/test_mattermost.py::TestMattermostSend tests/tools/test_send_message_missing_platforms.py::TestSendMattermost -q -o addopts= --tb=short.venv/bin/python -m pytest tests/gateway/test_mattermost.py tests/tools/test_send_message_missing_platforms.py tests/gateway/test_send_multiple_images.py::TestMattermostMultiImage tests/gateway/test_media_download_retry.py::TestMattermostSendUrlAsFile -q -o addopts= --tb=short.venv/bin/python -m py_compile plugins/platforms/mattermost/adapter.py tests/gateway/test_mattermost.py tests/tools/test_send_message_missing_platforms.py/opt/homebrew/bin/ruff check plugins/platforms/mattermost/adapter.py tests/gateway/test_mattermost.py tests/tools/test_send_message_missing_platforms.pygit diff --checkDuplicate check
gh search prs --repo NousResearch/hermes-agent --state open '39836 Mattermost ClientTimeout timeout context cron'gh search prs --repo NousResearch/hermes-agent --state open 'Mattermost "Timeout context manager should be used inside a task"'