fix(gateway): track background task references in GatewayRunner (#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 #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).

Co-authored-by: memosr.eth <96793918+memosr@users.noreply.github.com>
This commit is contained in:
Teknium 2026-03-26 14:33:48 -07:00 committed by GitHub
parent 76ed15dd4d
commit e9e7fb0683
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 20 additions and 3 deletions

View file

@ -38,6 +38,7 @@ def _make_runner():
runner._provider_routing = {}
runner._fallback_model = None
runner._running_agents = {}
runner._background_tasks = set()
mock_store = MagicMock()
runner.session_store = mock_store