[codex] Validate tool inputs before execution#49
Conversation
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7980123e9b
ℹ️ 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".
|
|
||
| for (const field of required) { | ||
| if ( | ||
| !Object.prototype.hasOwnProperty.call(input, field) || |
There was a problem hiding this comment.
Guard non-object tool inputs before required checks
When a provider returns a malformed function call whose arguments parse to null, the OpenAI adapters currently cast JSON.parse(...) directly to Record<string, unknown> (for example in src/models/openai-responses.ts:327 and src/models/openai.ts:275). This new validation path then calls hasOwnProperty on that value and throws TypeError before the executor can return the structured validation tool result, so that malformed tool call still aborts the run instead of letting the model recover.
Useful? React with 👍 / 👎.
Summary
Adds defensive validation for registered tool inputs before a tool is executed. The registry now checks required fields and primitive property types from the tool JSON schema, returning a structured tool error when model output is malformed.
The executor now validates before policy evaluation, so a malformed
run_commandcall like{}returns a clear tool result instead of reaching the command policy path and crashing oninput.command.trim().Root Cause
Tool schemas advertised required fields, but the runner trusted model-provided input and passed malformed objects through to policy and tool execution. For
run_command, the default policy assumedinput.commandwas a string and trimmed it directly.Impact
Malformed tool calls now stay inside the normal tool-result flow. The model receives an actionable error such as
Invalid input for tool "run_command": missing required field "command"., and the run can continue instead of crashing the tool runner.Validation
npm run buildnpm test