codex icon indicating copy to clipboard operation
codex copied to clipboard

Invalid schema error: Missing 'workdir' in function 'shell'​

Open ansh-info opened this issue 1 year ago • 14 comments

What version of Codex is running?

0.1.2504220136

Which model were you using?

o4-mini

What platform is your computer?

Darwin 24.4.0 arm64 arm

What steps can reproduce the bug?

Image

Steps to reproduce:

  1. Install Codex CLI:

    npm install -g @openai/codex
    
  2. Set the OpenAI API key:

    export OPENAI_API_KEY="your-api-key-here"
    
  3. Create the configuration file at ~/.codex/config.json with the following content:

    {
      "model": "o4-mini",
      "approvalMode": "suggest",
      "fullAutoErrorMode": "ask-user",
      "notify": true
    }
    
  4. Run the Codex CLI:

    codex
    
  5. At the prompt, enter:

    hello
    

What is the expected behavior?

Expected behavior:

The CLI should process the input and provide a response without errors.

What do you see instead?

Actual behavior:

The CLI returns a 400 error indicating a missing 'workdir' in the function schema.

Additional information

The configuration file is correctly set up, and the API key is exported. Despite this, the error persists.​

Describe the bug:

When running the Codex CLI, I encounter the following error:


⚠️  OpenAI rejected the request (request ID: req_XXXXXXXXXXXX). 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.

ansh-info avatar Apr 22 '25 09:04 ansh-info

yep getting this issue as well as soon as I updated this on NPM OS: macOS

    system
    ⚠️  OpenAI rejected the request (request ID: req_XXXXXXXX). 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.

XxUnkn0wnxX avatar Apr 22 '25 09:04 XxUnkn0wnxX

same here, looks broken currently. Was just trying it out. Also mac.

jillesvangurp avatar Apr 22 '25 09:04 jillesvangurp

I encountered an issue with the latest version. You can install the previous stable version instead: @openai/[email protected].

pae23 avatar Apr 22 '25 09:04 pae23

I encountered an issue with the latest version. You can install the previous stable version instead: @openai/[email protected].

Thank you for sharing, @openai/[email protected] versions works

ansh-info avatar Apr 22 '25 10:04 ansh-info

Same thing here in Windows

"OpenAI rejected the request (request ID: req_d4468dd0095cea7e29a4ffbe9f7314a2). 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."

aitorcalero avatar Apr 22 '25 11:04 aitorcalero

Same thing here in Windows 11, also using @openai/[email protected]. , error persist I'm using WSL Debian under Windows 11

OpenAI rejected the request (request ID: req_xxxxxxx). 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'..

aghioldi avatar Apr 22 '25 12:04 aghioldi

I encountered an issue with the latest version. You can install the previous stable version instead: @openai/[email protected].

ahahaha yeah, i spent ages, thought i might be able to inject the payload directly through terminal but to no avail. going back to the earlier as mentioned worked for me.

Jakc4der avatar Apr 22 '25 12:04 Jakc4der

Same issue for me. Reverting to old version until this is fixed.

djs959 avatar Apr 22 '25 13:04 djs959

@openai/[email protected] version works fine in Windows 11

MrRobot1370 avatar Apr 22 '25 13:04 MrRobot1370

Same in ubuntu

unknowncoder05 avatar Apr 22 '25 13:04 unknowncoder05

For all users -- Here's what works for me, or roll back versioning:

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 13:04 The-Obstacle-Is-The-Way

did anyone made any pr with this change?

sabari245 avatar Apr 22 '25 15:04 sabari245

Back to the previous available that was working npm uninstall -g @openai/codex npm view @openai/codex versions -- If you wanna see the latest npm install -g @openai/[email protected]

VLSantos2 avatar Apr 22 '25 17:04 VLSantos2

Should be fixed in latest release, please install 0.1.2504221401 and re-open if this is still an issue you encounter.

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