Skip to content

Mattermost plugin: send_message fails with 'Timeout context manager should be used inside a task' (v0.15.x) #37005

Open

Description

@agent00bob

Description

The Mattermost platform plugin adapter fails on every send_message call with:

Plugin platform send failed: Timeout context manager should be used inside a task

Environment

  • Hermes Agent v0.15.2
  • macOS 26.4.1 (Mac Mini M4)
  • Mattermost 10.5.0

Steps to Reproduce

  1. Configure Mattermost gateway with valid credentials
  2. Start gateway
  3. In a Mattermost DM session, agent attempts send_message to any Mattermost target
  4. Observe the error

Workaround

The CLI hermes send -t mattermost:target "message" works correctly. This confirms Mattermost connectivity and credentials are valid. The bug is specific to the in-gateway plugin adapter path.

Impact

  • Agent cannot send proactive Mattermost messages from within conversations
  • LLM-powered cron jobs with mattermost delivery will fail on delivery (no_agent script-based cron deliveries use a different path and are unaffected)

Notes

  • Reproduced on both v0.15.1 and v0.15.2
  • Error suggests an asyncio.timeout() being called outside an async task context in the Mattermost adapter

Activity

  1. added
    type/bugSomething isn't working
    P3Low — cosmetic, nice to have
    comp/pluginsPlugin system and bundled plugins
    comp/gatewayGateway runner, session dispatch, delivery
    on Jun 2, 2026
  2. vbashkirtsev commented on Jun 2, 2026

    @vbashkirtsev

    The issue is that aiohttp runs in another event loop. In send_message_tool.py in function _send_via_adapter() it does:

    adapter = runner.adapters.get(platform)

    That adapter has self._session which was created in gateway's event loop. Then it calls:

    result = await adapter.send(chat_id=chat_id, content=chunk, metadata=metadata)

    which causes call to _api_post() which then fails with the error "Timeout context manager should be used inside a task"

    I made runner = None unconditional and it forced call to:

    result = await entry.standalone_sender_fn()

    instead which creates new aiohttp session and does not fail. Also it can send media_files. But there another bug in adapter.py _standalone_send() - media_files is array of tuples and

    for media, is_voice in media_files:

    should be used.

    So clean way to solve this issue is to ensure that send_message_tool.py will avoid use of adapter from gateway and use standalone_sender_fn for Mattermost.

    PS: apologies for this messy message - I did debug it for many hours straight and very tired to put things together coherently...

  3. GottZ commented on Jul 28, 2026

    @GottZ

    This was generated by AI during triage.

    Summary

    Six PRs are associated with this complex: #37599 and #39877 replace Mattermost aiohttp timeout usage with asyncio.wait_for, #38563 and #38902 additionally route cross-loop requests through the session-owning loop, #38525 changes the generic synchronous-to-async bridge, and #55011 only caps Matrix response bodies. Against #37005’s reported gateway-adapter/session-loop mismatch, #38563 is the most complete scoped fix, while #38525 and #55011 do not modify that failing path.

    Related pull requests

    Duplicates

    #38563 and #38902 are substantially duplicate cross-loop Mattermost implementations, with #38902 additionally including the model_tools task-wrapping change. #37599 and #39877 overlap in replacing Mattermost aiohttp timeout handling with asyncio.wait_for, but neither is equivalent to #38563’s session-owning-loop routing.

    Suggested consolidation

    Merge #38563 as the consolidation target after carrying forward or confirming its supplied _RawResponse async context-manager fix, which explicitly addresses the contributor’s blocking review. Treat #38902 as superseded by #38563; #37599 and #39877 can remain closed or be closed as overlapping partial implementations, with #39877’s keep_open review explicitly outweighed by its non-reproducing tests and overbroad diff; exclude #38525 and #55011 as unrelated to the verified Mattermost adapter cause.

    Complex graph

    flowchart TD
        classDef open fill:#dbeafe,stroke:#1d4ed8,color:#1e3a8a
        classDef merged fill:#dcfce7,stroke:#15803d,color:#14532d
        classDef closed fill:#e5e7eb,stroke:#6b7280,color:#1f2937
        classDef unverified fill:#f3f4f6,stroke:#9ca3af,color:#374151
        classDef best stroke-width:3px,stroke:#b45309
        classDef target stroke-width:3px,stroke:#4338ca
        I37005(["issue #37005 (open)"])
        I39836(["issue #39836 (open)"])
        I55009(["issue #55009 (open)"])
        P37599["PR #37599 (open)"]
        P39877["PR #39877 (closed)"]
        P55011["PR #55011 (open)"]
        subgraph Dup38563 ["PRs duplicating each other"]
            P38563["PR #38563 (closed)"]
            P38902["PR #38902 (closed)"]
        end
        P37599 -.->|partial| I37005
        P38563 -->|best fix| I37005
        P38902 -->|fixes| I37005
        P39877 -.->|partial| I37005
        P55011 -->|best fix| I55009
        class I37005 open
        class I39836 open
        class I55009 open
        class I37005 target
        class P37599 open
        class P38563 closed
        class P38902 closed
        class P39877 closed
        class P55011 open
        class P38563 best
        class P55011 best
        click I37005 "https://github.com/NousResearch/hermes-agent/issues/37005"
        click I39836 "https://github.com/NousResearch/hermes-agent/issues/39836"
        click I55009 "https://github.com/NousResearch/hermes-agent/issues/55009"
        click P37599 "https://github.com/NousResearch/hermes-agent/pull/37599"
        click P38563 "https://github.com/NousResearch/hermes-agent/pull/38563"
        click P38902 "https://github.com/NousResearch/hermes-agent/pull/38902"
        click P39877 "https://github.com/NousResearch/hermes-agent/pull/39877"
        click P55011 "https://github.com/NousResearch/hermes-agent/pull/55011"
    
    Loading

    Graph: solid arrow = fixes / best fix, dashed arrow = partial or unverified (see edge label); boxed group = PRs duplicating each other; amber border = best fix; indigo border = target; gray node = closed or no verify verdict yet (state tag in the node label).

    Cross-PR triage: Reviewed 6 pull requests and 3 issues in this complex. Each diff was read against this issue; Assessment working set: 94 kB of PR diffs, 20 kB of issue/PR text, 8 kB of discussion (8 comments), 21 verify verdicts. verdicts reflect diff content, not PR titles. Part of an automated triage batch.

  4. andrexibiza commented on Aug 3, 2026

    @andrexibiza

    Duplicate-consolidation (2-wave blind swarm, 2026-08-03).

    Canonical: #39836 — this issue is a duplicate and should be closed in favor of #39836.

  5. andrexibiza commented on Aug 3, 2026

    @andrexibiza

    Triage (swarm dedup campaign): confirmed same root cause as #39836/#76799. The send_message tool path hits the identical cross-loop bug: send_message_tool runs _send_to_platform via _run_async (model_tools.py:103), which spawns a worker thread with asyncio.new_event_loop() when invoked inside a running loop (e.g. gateway), so _send_via_adapter reuses the live Mattermost adapter's gateway-loop-bound ClientSession and aiohttp raises Timeout context manager should be used inside a task.

    Fix: PR #77378 gates the live-adapter shortcut on _adapter_session_is_usable() (session open + bound to current loop); on mismatch it uses the plugin's standalone_sender_fn with a fresh session — mirroring the merged Weixin fix a22465e.

    Verification: 3 new regression tests — RED on unpatched main (2 failed / 1 control passed), GREEN with fix (3 passed); full file 50 passed; footgun lint + git diff --check clean. PR carries Fixes #39836, #76799, #37005 — this issue auto-closes on merge.

  6. added
    comp/toolsTool registry, model_tools, toolsets
    sweeper:risk-message-deliverySweeper risk: may drop, duplicate, misroute, or suppress messages
    and removed
    comp/toolsTool registry, model_tools, toolsets
    on Aug 3, 2026
  7. GottZ commented on Aug 3, 2026

    @GottZ

    This was generated by AI during triage.

    Delta since our previous triage comment

    Since the previous comment, @andrexibiza reported that the current head of open PR #77378 already contains the complete salvage scope: the generic live-adapter session guard, standalone-sender fallback, and foreign-loop, closed-session, and same-loop regression tests. The same comment explicitly addresses the [contributor:184 commits] duplicate objection against #62956, distinguishing #77378's shared tools/send_message_tool.py::_send_via_adapter path from #62956's scheduler and Matrix-specific paths, and reports a clean mergeable state with the required checks passing.

    Changed pull requests

    Suggested consolidation

    Recommendation unchanged: keep #77378 open for maintainer review in the fresh merge lane; #38563 remains the Verify-designated best existing fix, while #77378 is the current generic-path consolidation candidate.

    Complex graph

    flowchart TD
        classDef open fill:#dbeafe,stroke:#1d4ed8,color:#1e3a8a
        classDef merged fill:#dcfce7,stroke:#15803d,color:#14532d
        classDef closed fill:#e5e7eb,stroke:#6b7280,color:#1f2937
        classDef unverified fill:#f3f4f6,stroke:#9ca3af,color:#374151
        classDef best stroke-width:3px,stroke:#b45309
        classDef target stroke-width:3px,stroke:#4338ca
        I37005(["issue #37005 (open)"])
        I39836(["issue #39836 (open)"])
        I55009(["issue #55009 (open)"])
        I76799(["issue #76799 (open)"])
        P55011["PR #55011 (open)"]
        P77378["PR #77378 (open)"]
        subgraph Dup37599 ["PRs duplicating each other"]
            P37599["PR #37599 (open)"]
            P39877["PR #39877 (closed)"]
        end
        subgraph Dup38525 ["PRs duplicating each other"]
            P38525["PR #38525 (closed)"]
            P38563["PR #38563 (closed)"]
            P38902["PR #38902 (closed)"]
        end
        P37599 -.->|partial| I37005
        P38563 -->|best fix| I37005
        P38902 -->|fixes| I37005
        P39877 -.->|partial| I37005
        P77378 -->|best fix| I37005
        P38563 -->|best fix| I39836
        P77378 -->|best fix| I39836
        P55011 -->|best fix| I55009
        P37599 -.->|partial| I76799
        P38563 -->|best fix| I76799
        P38902 -->|fixes| I76799
        P39877 -.->|partial| I76799
        P77378 -->|best fix| I76799
        class I37005 open
        class I39836 open
        class I55009 open
        class I76799 open
        class I37005 target
        class P37599 open
        class P38525 closed
        class P38563 closed
        class P38902 closed
        class P39877 closed
        class P55011 open
        class P77378 open
        class P38563 best
        class P38563 best
        class P38563 best
        class P55011 best
        class P77378 best
        class P77378 best
        class P77378 best
        click I37005 "https://github.com/NousResearch/hermes-agent/issues/37005"
        click I39836 "https://github.com/NousResearch/hermes-agent/issues/39836"
        click I55009 "https://github.com/NousResearch/hermes-agent/issues/55009"
        click I76799 "https://github.com/NousResearch/hermes-agent/issues/76799"
        click P37599 "https://github.com/NousResearch/hermes-agent/pull/37599"
        click P38525 "https://github.com/NousResearch/hermes-agent/pull/38525"
        click P38563 "https://github.com/NousResearch/hermes-agent/pull/38563"
        click P38902 "https://github.com/NousResearch/hermes-agent/pull/38902"
        click P39877 "https://github.com/NousResearch/hermes-agent/pull/39877"
        click P55011 "https://github.com/NousResearch/hermes-agent/pull/55011"
        click P77378 "https://github.com/NousResearch/hermes-agent/pull/77378"
        classDef changedSince stroke:#dc2626,stroke-width:3px,stroke-dasharray: 6 3
        class I37005,I39836,I55009,I76799,P37599,P38525,P38563,P38902,P39877,P55011 changedSince
    
    Loading

    Graph: solid arrow = fixes / best fix, dashed arrow = partial or unverified (see edge label); boxed group = PRs duplicating each other; amber border = best fix; indigo border = target; gray node = closed (state tag in the node label).
    Dashed red border = changed since our previous triage comment (21 added/updated, 0 removed graph elements).

    Cross-PR triage: Reviewed 7 pull requests and 4 issues in this complex. Each diff was read against this issue; Assessment working set: 103 kB of PR diffs, 27 kB of issue/PR text, 14 kB of discussion (16 comments), 25 verify verdicts. verdicts reflect diff content, not PR titles. Part of an automated triage batch.

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

    P3Low — cosmetic, nice to havecomp/gatewayGateway runner, session dispatch, deliverycomp/pluginsPlugin system and bundled pluginssweeper:risk-message-deliverySweeper risk: may drop, duplicate, misroute, or suppress messagestype/bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions