Skip to content

fix: fail closed for callable needs_approval on invalid/non-object JSON - #3870

Closed
baiyuxi930826 wants to merge 1 commit into
openai:mainfrom
baiyuxi930826:fix/needs-approval-fail-closed-invalid-json
Closed

baiyuxi930826 wants to merge 1 commit into
openai:mainfrom
baiyuxi930826:fix/needs-approval-fail-closed-invalid-json

Conversation

@baiyuxi930826

Copy link
Copy Markdown

Summary

Fixes #3863.

When needs_approval is a callable, invalid tool-call JSON was previously swallowed and replaced with {} before the predicate ran. Content-based gates (e.g. "refund" in params.get("subject", "")) then returned False and skipped HITL.

This change fails closed:

  • JSONDecodeError → require approval (True)
  • non-dict JSON (null, [], scalars) → require approval (True)
  • valid object JSON → unchanged predicate behavior
  • bool needs_approval=True → unchanged

Same fix in the realtime session path.

Test plan

  • pytest tests/test_function_needs_approval_invalid_json.py (5 passed)
  • Covers invalid JSON, non-object JSON, valid refund/non-refund, bool path

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

Copy link
Copy Markdown

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.

Reviewed commit: dc5f5bf56a

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

if callable(function_tool.needs_approval):
try:
parsed_args = json.loads(tool_call.arguments or "{}")
parsed = json.loads(tool_call.arguments or "{}")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Reject empty argument strings before evaluating approval

When a provider emits arguments="", the or "{}" fallback converts that invalid JSON into an empty object, so a callable approval predicate can return False. Because _parse_function_tool_json_input() in src/agents/tool.py also treats an empty string as {}, a tool with no required parameters can then execute and produce side effects without approval. The same bypass exists in the Realtime path at src/agents/realtime/session.py:553; handle the empty string as fail-closed in both paths rather than substituting {}.

Useful? React with 👍 / 👎.

@seratch

seratch commented Jul 17, 2026

Copy link
Copy Markdown
Member

Resolved by #3867

@seratch seratch closed this Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Callable needs_approval fails open when tool arguments are invalid JSON

3 participants