fix(server): stop per-session toolsets on session delete - #3884
Open
EronWright wants to merge 1 commit into
Open
fix(server): stop per-session toolsets on session delete#3884EronWright wants to merge 1 commit into
EronWright wants to merge 1 commit into
Conversation
A session materialised via teamloader owns a team whose toolsets may hold external resources — notably stdio MCP subprocesses. DeleteSession cancelled the runtime context but never called team.StopToolSets, so those subprocesses leaked until the server process exited; BatchDeleteSessions had the same gap. Track the per-session team on activeRuntimes and, once the session's stream has drained, call StopToolSets from both delete paths, bounding it by the originating request's deadline. Nil for attached runtimes (AttachRuntime), whose toolset lifecycle belongs to the embedder, so it is a no-op there.
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.
fix(server): stop per-session toolsets on session delete
Problem
A session materialised via
teamloaderowns ateamwhose toolsets may holdexternal resources — notably stdio MCP subprocesses.
DeleteSessioncancels theruntime context but never calls
team.StopToolSets, andBatchDeleteSessionshasthe same gap (
LocalRuntime.Closeonly stops background agents;StopToolSetswasotherwise reached only via the transient
GetAgentToolCount). So a deleted session'sMCP subprocesses leak until the server process exits.
Fix
Track the per-session
teamonactiveRuntimes; once the session's stream hasdrained, call
StopToolSetsfrom both delete paths. The drain runs in a backgroundgoroutine that outlives the originating request, on a detached context
(
WithoutCancel) carrying its ownsessionDrainTimeout(5 min) budget — the samebudget already bounds the drain wait, so it now bounds the whole teardown (drain +
StopToolSets). Nil for attached runtimes (AttachRuntime), whose toolset lifecyclebelongs to the embedder — a no-op there.
Test
go test ./pkg/server/green. Verified against a multi-tenant host: the per-sessionsubprocess count returns to zero on delete and after server shutdown (previously it
stayed pinned until exit).