fix(gateway): tear down cached agents on stop (salvage #12917) - #16207
Merged
Conversation
1 task
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Gateway shutdown now shuts down memory providers on idle cached agents, not just mid-turn ones. Closes leak of Hindsight/Honcho/Mnemoria clients + terminal sandboxes + browser daemons at systemd stop.
Salvage of #12917 by @Tranquil-Flow. Single contributor commit cherry-picked onto current main; author attribution preserved via rebase merge.
Root cause
_drain_active_agentssnapshots only_running_agents. Agents that had ended their turn and were living in_agent_cache(warm cache / idle TTL sweep pool) never receivedshutdown_memory_provider()orclose(), so their memory-provider network clients, terminal sandboxes, and browser daemons stayed alive until process exit.Changes
_stop_impl: after_finalize_shutdown_agents(active_agents), sweep_agent_cacheunder_agent_cache_lock, then call_cleanup_agent_resourceson each entry (handles tuple and bare-agent forms).Validation
_running_agentsonly_running_agents+_agent_cacheCloses #12917 (original PR, merged via salvage). Addresses #11205.