Skip to content

fix(gateway): dispatch memory session-end hooks on expiry - #11304

Closed
LeonSGP43 wants to merge 1 commit into
NousResearch:mainfrom
LeonSGP43:fix/gateway-session-end-memory-hook
Closed

fix(gateway): dispatch memory session-end hooks on expiry#11304
LeonSGP43 wants to merge 1 commit into
NousResearch:mainfrom
LeonSGP43:fix/gateway-session-end-memory-hook

Conversation

@LeonSGP43

Copy link
Copy Markdown
Contributor

Summary\n- dispatch MemoryProvider session-end hooks from the live gateway agent before the flush worker tears the session down\n- keep the existing flush-agent behavior intact for builtin memory and skills\n- add a regression test covering cached gateway agents\n\nWhy\n- gateway session expiry/reset currently runs the flush worker but never calls the live memory manager's \ hook\n- memory providers that rely on end-of-session extraction therefore miss their final pass on gateway platforms\n\nFixes #11205\n\nTesting\n- python3 -m pytest -o addopts='' tests/gateway/test_flush_memory_stale_guard.py

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery tool/memory Memory tool and memory providers labels Apr 25, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate pair: this and #11410 fix the same issue (#11205). #15132 (merged) partially addressed this with on_session_finalize. Maintainer should pick one or confirm #15132 already covers the gap.

@kshitijk4poor

Copy link
Copy Markdown
Collaborator

Thanks @LeonSGP43 — your instinct was right: session expiry (not idle eviction) is the correct boundary for dispatching MemoryProvider.on_session_end(), and you targeted the flush path deliberately.

Closing in favor of #57378 (merged / merging), for two reasons:

  1. The integration point this PR hooks — _flush_memories_for_session — no longer exists on current main. That flush path was refactored away; the gateway now fires on_session_end via _cleanup_agent_resourcesshutdown_memory_provider(session_messages). So the diff no longer applies cleanly.

  2. Even conceptually, dispatching from the flush/expiry path alone doesn't close the underlying race: if the cached agent was already soft-evicted (by the idle-TTL sweep or the LRU cap) before the session expired, the live agent is gone and the hook is skipped regardless.

#57378 fixes it at the source — it keeps a finalizable agent in cache until the session actually expires (idle sweep), and commits on_session_end via the live agent on the LRU-cap path — so the hook fires for every session across every eviction path.

Your correct framing (expiry is the boundary) is credited in the salvage. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists tool/memory Memory tool and memory providers type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants