Skip to content

Conversation

@chaunceyjiang
Copy link
Collaborator

@chaunceyjiang chaunceyjiang commented Nov 10, 2025

Purpose

Test Plan

Test Result


Essential Elements of an Effective PR Description Checklist
  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results
  • (Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model.
  • (Optional) Release notes update. If your change is user facing, please update the release notes draft in the Google Doc.

Andrew Xia and others added 3 commits November 6, 2025 09:56
Signed-off-by: Andrew Xia <axia@fb.com>
Signed-off-by: chaunceyjiang <chaunceyjiang@gmail.com>
@chaunceyjiang chaunceyjiang changed the title [DEBUG] Tool converter [WIP][DEBUG] Tool converter Nov 10, 2025
@mergify mergify bot added the frontend label Nov 10, 2025
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines 67 to 76
def convert_tool_responses_to_completions_format(tool: dict) -> dict:
"""
Convert a flat tool schema:
{"type": "function", "name": "...", "description": "...", "parameters": {...}}
into:
{"type": "function", "function": {...}}
"""
return {
"type": "function",
"function": tool,

Choose a reason for hiding this comment

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

P1 Badge Preserve non-function tool types when converting schema

The new convert_tool_responses_to_completions_format wraps every tool dict as {"type": "function", "function": tool} regardless of the original tool["type"]. Responses requests may contain non-function tools such as code_interpreter, file_search, or MCP tools, and _make_request now runs this conversion over them before passing tool_dicts into _preprocess_chat. After this change those tools are reported to the model as type function, so built‑in tools can no longer be enabled or invoked correctly. The conversion should only wrap tools whose type is function and should not rewrite other tool types.

Useful? React with 👍 / 👎.

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 refactors tool-related utility functions and introduces a converter to adapt tool definitions to the format expected by the completions API. The changes include moving extract_tool_types to a shared utility file and adding convert_tool_responses_to_completions_format. My review has identified a critical issue where an exception handler has been commented out, likely for debugging, which poses a risk to server stability. Additionally, there's a high-severity bug in the new tool converter function that incorrectly handles non-function tool types. These issues should be addressed before merging.

Comment on lines +526 to +531
# try:
generator = await handler.create_responses(request, raw_request)
# except Exception as e:
# raise HTTPException(
# status_code=HTTPStatus.INTERNAL_SERVER_ERROR.value, detail=str(e)
# ) from e
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

This try...except block, which handles generic exceptions during response creation, has been commented out. While this can be helpful for debugging by allowing exceptions to propagate, it removes a critical error handling layer for the API endpoint. Without this, unexpected errors in handler.create_responses could lead to unhandled exceptions, potentially crashing the server or leaking internal error details to clients. This change should be reverted before merging into a main branch to ensure the server's stability and robustness.

Suggested change
# try:
generator = await handler.create_responses(request, raw_request)
# except Exception as e:
# raise HTTPException(
# status_code=HTTPStatus.INTERNAL_SERVER_ERROR.value, detail=str(e)
# ) from e
try:
generator = await handler.create_responses(request, raw_request)
except Exception as e:
raise HTTPException(
status_code=HTTPStatus.INTERNAL_SERVER_ERROR.value, detail=str(e)
) from e

Comment on lines 67 to 77
def convert_tool_responses_to_completions_format(tool: dict) -> dict:
"""
Convert a flat tool schema:
{"type": "function", "name": "...", "description": "...", "parameters": {...}}
into:
{"type": "function", "function": {...}}
"""
return {
"type": "function",
"function": tool,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The convert_tool_responses_to_completions_format function incorrectly assumes all tools are of type 'function' by hardcoding "type": "function" in the returned dictionary. This will cause issues for other tool types, such as 'mcp', by wrapping them in an incorrect 'function' tool structure, which will likely cause downstream processing errors. The function should be updated to handle only 'function' type tools and return other tool types unmodified.

Suggested change
def convert_tool_responses_to_completions_format(tool: dict) -> dict:
"""
Convert a flat tool schema:
{"type": "function", "name": "...", "description": "...", "parameters": {...}}
into:
{"type": "function", "function": {...}}
"""
return {
"type": "function",
"function": tool,
}
def convert_tool_responses_to_completions_format(tool: dict) -> dict:
"""
Convert a flat tool schema:
{"type": "function", "name": "...", "description": "...", "parameters": {...}}
into:
{"type": "function", "function": {...}}
"""
if tool.get("type") == "function":
return {
"type": "function",
"function": tool,
}
return tool

@chaunceyjiang chaunceyjiang added the ready ONLY add when PR is ready to merge/full CI is needed label Nov 10, 2025
Signed-off-by: chaunceyjiang <chaunceyjiang@gmail.com>
@mergify mergify bot added the v1 label Nov 10, 2025
Signed-off-by: chaunceyjiang <chaunceyjiang@gmail.com>
Signed-off-by: chaunceyjiang <chaunceyjiang@gmail.com>
Signed-off-by: chaunceyjiang <chaunceyjiang@gmail.com>
Signed-off-by: chaunceyjiang <chaunceyjiang@gmail.com>
Signed-off-by: chaunceyjiang <chaunceyjiang@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

frontend ready ONLY add when PR is ready to merge/full CI is needed v1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant