codex icon indicating copy to clipboard operation
codex copied to clipboard

bug: openai rejected the request

Open sh4ka opened this issue 1 year ago • 11 comments

What version of Codex is running?

0.1.2504220136

Which model were you using?

gpt-4.1-mini-2025-04-14

What platform is your computer?

darwin | arm64 | 24.3.0

What steps can reproduce the bug?

  • test
    
    • 0 reasoning | 0 tool

What is the expected behavior?

Processing any command.

What do you see instead?

⚠️ OpenAI rejected the request (request ID: req_cf222b4f730bcfc1e7dc415a35977eb4). Error details: Status: 400, Code: invalid_function_parameters, Type: invalid_request_error, Message: 400 Invalid schema for function 'shell': In context=(), 'required' is required to be supplied and to be an array including every key in properties. Missing 'workdir'.. Please verify your settings and try again.

Additional information

No response

sh4ka avatar Apr 22 '25 09:04 sh4ka

I am also getting this issue. No model works, brand new install using npm.

tobyward avatar Apr 22 '25 09:04 tobyward

Roll back to the previous version before the issue :) npm install -g @openai/[email protected]

ianskea avatar Apr 22 '25 09:04 ianskea

That did it for the time being, thanks @ianskea

sh4ka avatar Apr 22 '25 09:04 sh4ka

Same here, rolling back the version @ianskea describes helps

memcmp avatar Apr 22 '25 10:04 memcmp

we're so back

spookyuser avatar Apr 22 '25 11:04 spookyuser

Same Here

linslouis avatar Apr 22 '25 11:04 linslouis

Rollback works for me

enricoyounglabs avatar Apr 22 '25 12:04 enricoyounglabs

Same error for me.

djs959 avatar Apr 22 '25 12:04 djs959

+1

juan-frvr avatar Apr 22 '25 13:04 juan-frvr

Solution to error for those who want to fix it themselves before update:

Bug Found & Fixed: Invalid Schema for Function 'shell'

After investigating this issue, I found that the OpenAI API has changed its validation requirements for function schemas. The API now requires that all properties defined in a schema must be included in the required array.

Root Cause

In codex-cli/src/utils/agent/agent-loop.ts, the 'shell' function schema defines properties for command, workdir, and timeout, but the required array only includes command.

Fix

The solution is to include all properties in the required array:

parameters: {
  type: "object",
  properties: {
    command: { type: "array", items: { type: "string" } },
    workdir: {
      type: "string",
      description: "The working directory for the command.",
    },
    timeout: {
      type: "number",
      description: "The maximum time to wait for the command to complete in milliseconds.",
    },
  },
-  required: ["command"],
+  required: ["command", "workdir", "timeout"],
  additionalProperties: false,
},

How to Apply the Fix

  1. Edit codex-cli/src/utils/agent/agent-loop.ts
  2. Find the shell function schema definition (around line 651)
  3. Update the required array to include all properties as shown above
  4. Build and reinstall the package:
cd /path/to/codex
cd codex-cli
pnpm run build
npm install -g .

After applying this fix, the tool should work correctly. The error occurs because the OpenAI API now enforces stricter schema validation, requiring all defined properties to be listed in the required array, even if they should be optional in practice.

The-Obstacle-Is-The-Way avatar Apr 22 '25 14:04 The-Obstacle-Is-The-Way

This is now fixed in the latest release, please update! Thanks all for collectively identifying a workaround and then the necessary fix, you're awesome.

See https://github.com/openai/codex/pull/559 for the new release notes.

tibo-openai avatar Apr 22 '25 22:04 tibo-openai