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

Resolved 💬 14 comments Opened Apr 22, 2025 by ansh-info Closed Apr 22, 2025
💡 Likely answer: A maintainer (tibo-openai, collaborator) responded on this thread — see the highlighted reply below.

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?

<img width="912" alt="Image" src="https://github.com/user-attachments/assets/fc042e30-4c82-480d-a995-f173803fab1d" />

Steps to reproduce:

  1. Install Codex CLI:

``bash
npm install -g @openai/codex
``

  1. Set the OpenAI API key:

``bash
export OPENAI_API_KEY="your-api-key-here"
``

  1. Create the configuration file at ~/.codex/config.json with the following content:

``json
{
"model": "o4-mini",
"approvalMode": "suggest",
"fullAutoErrorMode": "ask-user",
"notify": true
}
``

  1. Run the Codex CLI:

``bash
codex
``

  1. At the prompt, enter:

``bash
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.

View original on GitHub ↗

14 Comments

XxUnkn0wnxX · 1 year ago

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.
jillesvangurp · 1 year ago

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

pae23 · 1 year ago

I encountered an issue with the latest version. You can install the previous stable version instead: @openai/codex@0.1.2504211509.

ansh-info · 1 year ago
I encountered an issue with the latest version. You can install the previous stable version instead: @openai/codex@0.1.2504211509.

Thank you for sharing, @openai/codex@0.1.2504211509 versions works

aitorcalero · 1 year ago

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."

aghioldi · 1 year ago

Same thing here in Windows 11, also using @openai/codex@0.1.2504211509. , 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'..

Jakc4der · 1 year ago
I encountered an issue with the latest version. You can install the previous stable version instead: @openai/codex@0.1.2504211509.

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.

djs959 · 1 year ago

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

MrRobot1370 · 1 year ago

@openai/codex@0.1.2504211509 version works fine in Windows 11

unknowncoder05 · 1 year ago

Same in ubuntu

The-Obstacle-Is-The-Way · 1 year ago

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.

sabari245 · 1 year ago

did anyone made any pr with this change?

VLSantos2 · 1 year ago

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/codex@0.1.2504211509

tibo-openai collaborator · 1 year ago

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