Repository navigation
Conversation
forgetSessionLocked removes a session's registry entry but leaves its per-session references intact, so a lingering reference to the clientSession (for example the list_changed sink a backend connector holds after the session's MultiSession is closed) keeps the per-session go-sdk server — and its converted tool schemas — plus the tools/resources/prompts overlays alive. Add clientSession.release, which clears boundServer, goSession, owner, the capability/protocol bookkeeping, and the overlay maps, and call it from forgetSessionLocked before closing the notify channel. Co-Authored-By: Claude Code <noreply@anthropic.com>
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.
Summary
forgetSessionLockedremoves a session's registry entry and closes its notify channel, but leaves every per-session reference on theclientSessionintact. When theclientSessionstays reachable through some other path — ToolHive's list_changed sink captures theClientSessionand lives inside the session'sMultiSessionbackend connectors — those references keep the per-session go-sdk server (and its converted tool schemas) and the tools/resources/prompts overlays alive long after the session is deleted.This contributes to
stacklok/toolhive#6932, where a per-session tool set (~several MB) is retained underinitialize→DELETEchurn.What changed
Add
clientSession.release, which clearsboundServer,goSession,owner, the capability/protocol bookkeeping (initializedOn,negotiated), and thetools/resources/resourceTemplates/prompts/sdkToolNamesoverlays.forgetSessionLockednow callsrelease()before closing the notify channel, so forgetting a session eagerly drops the per-session state it owns.releaseis idempotent and safe to run concurrently with the setters: after release,SetSessionTools(and friends) still record their overlay but no longer reconcile it onto a live server (boundServer/ownerare nil), which is the correct behavior for a session that is already gone.Type of change
Test plan
TestClientSessionRelease, which populates every cleared field and assertsreleasenils them all.go test ./mcpcompat/server/passes.go build ./...andgo vet ./mcpcompat/server/pass.Note:
go test ./...has a pre-existing failure inpermissions(TestMountDeclaration_Parse) on Windows — path-separator expectation (/vs\), unrelated to this change.🤖 Generated with Claude Code