Skip to content

fix(gateway): track background task references in GatewayRunner - #3254

Merged
teknium1 merged 1 commit into
mainfrom
hermes/hermes-dfd0d467
Mar 26, 2026
Merged

fix(gateway): track background task references in GatewayRunner#3254
teknium1 merged 1 commit into
mainfrom
hermes/hermes-dfd0d467

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

Salvage of PR #3167 by @memosr, cherry-picked onto current main.

What this fixes

Fire-and-forget asyncio.create_task() calls without stored references are vulnerable to garbage collection silently canceling the task mid-execution. This adds a self._background_tasks set to GatewayRunner using the standard add_done_callback(discard) pattern.

Tasks now tracked:

  • /background command task
  • Session-reset memory flush task
  • Session-resume memory flush task

Cleanup on shutdown: stop() cancels all pending background tasks before clearing adapters.

What was excluded from the original PR

The original PR also deleted ~30 lines of DM topic auto-skill loading code (shipped in #2598) without explanation. That deletion was excluded from this salvage.

Test fixes

Three test files construct GatewayRunner via object.__new__() bypassing __init__. Updated their fixtures to include the new _background_tasks attribute.

Gateway suite: 1461 passed, 21 skipped.

Closes #3167

Asyncio tasks created with create_task() but never stored can be
garbage collected mid-execution. Add self._background_tasks set to
hold references, with add_done_callback cleanup. Tracks:
- /background command task
- session-reset memory flush task
- session-resume memory flush task
Cancel all pending tasks in stop().

Update test fixtures that construct GatewayRunner via object.__new__()
to include the new _background_tasks attribute.

Cherry-picked from PR #3167 by memosr. The original PR also deleted
the DM topic auto-skill loading code — that deletion was excluded
from this salvage as it removes a shipped feature (#2598).
@teknium1
teknium1 merged commit e9e7fb0 into main Mar 26, 2026
1 of 2 checks passed
angelburgosrosado pushed a commit to angelburgosrosado/hermes-agent that referenced this pull request Apr 27, 2026
…Research#3254)

Asyncio tasks created with create_task() but never stored can be
garbage collected mid-execution. Add self._background_tasks set to
hold references, with add_done_callback cleanup. Tracks:
- /background command task
- session-reset memory flush task
- session-resume memory flush task
Cancel all pending tasks in stop().

Update test fixtures that construct GatewayRunner via object.__new__()
to include the new _background_tasks attribute.

Cherry-picked from PR NousResearch#3167 by memosr. The original PR also deleted
the DM topic auto-skill loading code — that deletion was excluded
from this salvage as it removes a shipped feature (NousResearch#2598).

Co-authored-by: memosr.eth <96793918+memosr@users.noreply.github.com>
02356abc pushed a commit to 02356abc/hermes-agent that referenced this pull request May 14, 2026
…Research#3254)

Asyncio tasks created with create_task() but never stored can be
garbage collected mid-execution. Add self._background_tasks set to
hold references, with add_done_callback cleanup. Tracks:
- /background command task
- session-reset memory flush task
- session-resume memory flush task
Cancel all pending tasks in stop().

Update test fixtures that construct GatewayRunner via object.__new__()
to include the new _background_tasks attribute.

Cherry-picked from PR NousResearch#3167 by memosr. The original PR also deleted
the DM topic auto-skill loading code — that deletion was excluded
from this salvage as it removes a shipped feature (NousResearch#2598).

Co-authored-by: memosr.eth <96793918+memosr@users.noreply.github.com>
gweeteve pushed a commit to gweeteve/hermes-agent that referenced this pull request Jun 2, 2026
…Research#3254)

Asyncio tasks created with create_task() but never stored can be
garbage collected mid-execution. Add self._background_tasks set to
hold references, with add_done_callback cleanup. Tracks:
- /background command task
- session-reset memory flush task
- session-resume memory flush task
Cancel all pending tasks in stop().

Update test fixtures that construct GatewayRunner via object.__new__()
to include the new _background_tasks attribute.

Cherry-picked from PR NousResearch#3167 by memosr. The original PR also deleted
the DM topic auto-skill loading code — that deletion was excluded
from this salvage as it removes a shipped feature (NousResearch#2598).

Co-authored-by: memosr.eth <96793918+memosr@users.noreply.github.com>
waefrebeorn pushed a commit to waefrebeorn/slermes that referenced this pull request Jul 2, 2026
…Research#3254)

Asyncio tasks created with create_task() but never stored can be
garbage collected mid-execution. Add self._background_tasks set to
hold references, with add_done_callback cleanup. Tracks:
- /background command task
- session-reset memory flush task
- session-resume memory flush task
Cancel all pending tasks in stop().

Update test fixtures that construct GatewayRunner via object.__new__()
to include the new _background_tasks attribute.

Cherry-picked from PR NousResearch#3167 by memosr. The original PR also deleted
the DM topic auto-skill loading code — that deletion was excluded
from this salvage as it removes a shipped feature (NousResearch#2598).

Co-authored-by: memosr.eth <96793918+memosr@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