fix(mcp): do not verify _background_session is present in stop() #876
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.
Description
There was a race condition in #833, where if the session never got set we triggered the exception in
The fix here is that we actually do not need to check for the existence of the _background_thread_session. The
_invoke_on_background_threadis more so targeted for post-connection operations so it validates. But forstop()we just want to set the_close_eventwhich does not depend on the session existing.It is possible that the session has died in
_async_background_thread. But in this case setting the_close_eventdoes nothing and we will still safelyjoin()the thread.Related Issues
#833
Documentation PR
N/A
Type of Change
Bug fix
Testing
How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli
hatch run prepareChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.