Skip to content

Conversation

qandrew
Copy link
Contributor

@qandrew qandrew commented Sep 26, 2025

Summary:
First part of fixing #25697

we can first fix this error

RuntimeError: Attempted to exit cancel scope in a different task than it was entered in

by not initializing the tool servers if the request doesn't need tools.

Test Plan:

  • non stream request with tools still gets tools
  • stream without tools no longer outputs the error
  • stream with tools still works (but it still outputs the error above)
  • pytest -sv tests/entrypoints/openai/test_serving_responses.py

Differential Revision: D83387320

@facebook-github-bot
Copy link

@qandrew has exported this pull request. If you are a Meta employee, you can view the originating diff in D83387320.

@qandrew qandrew changed the title disable tool server initialization if no tool in request [gpt-oss] disable tool server initialization if no tool in request Sep 26, 2025
@mergify mergify bot added frontend gpt-oss Related to GPT-OSS models labels Sep 26, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a targeted fix to prevent a RuntimeError by avoiding tool server initialization when a request does not specify any tools. This is achieved by refactoring the initialization logic into a new _initialize_tool_sessions method, which now includes a guard clause to check for the presence of tools in the request. The refactoring is cleanly applied to both streaming and non-streaming response generation paths. The change is correct and improves the robustness of the tool handling logic. I have one suggestion to remove some potentially confusing commented-out code to improve maintainability.

Summary:
First part of fixing vllm-project#25697

we can first fix this error
```
RuntimeError: Attempted to exit cancel scope in a different task than it was entered in
```
by not initializing the tool servers if the request doesn't need tools.

Test Plan:
- non stream request with tools still gets tools
- stream without tools no longer outputs the error
- stream with tools still works (but it still outputs the error)

Differential Revision: D83387320

Signed-off-by: Andrew Xia <[email protected]>
context: ConversationContext,
exit_stack: AsyncExitStack):
# we should only initialize the tool session if the request needs tools
if len(request.tools) == 0:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i believe @Hanchenli also mentioned this issue. can we also cover this in unit test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me know if you have any thoughts @Hanchenli ?

I added a UT, should be ready for review

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change looks good to me. The issue I mentioned was that the model might generate function_call requests even if we do not provide tools to them.

@lacora
Copy link
Contributor

lacora commented Sep 27, 2025

@qandrew could you try if this resolve the issue #24388 ? seems similar purpose

@qandrew
Copy link
Contributor Author

qandrew commented Oct 1, 2025

@qandrew could you try if this resolve the issue #24388 ? seems similar purpose

@lacora I tried to run it but i think the PR is out of sync after we added headers. This should resolve the same issue.

Signed-off-by: Andrew Xia <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
frontend gpt-oss Related to GPT-OSS models
Projects
Status: To Triage
Development

Successfully merging this pull request may close these issues.

5 participants