codex - 💡(How to fix) Fix openai-codex-sdk: FileChangeItem.status Literal rejects 'in_progress' from streaming patch updates [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openai/codex#17829Fetched 2026-04-15 06:27:29
View on GitHub
Comments
0
Participants
1
Timeline
8
Reactions
0
Author
Participants
Timeline (top)
labeled ×5unlabeled ×3

openai-codex-sdk==0.1.11 crashes when consuming the streamed event loop on any agent-mode run that uses the patch/edit tool on a non-trivial file. The Codex CLI emits FileChangeItem payloads with status=\"in_progress\" while a patch is being applied, but the SDK's Pydantic model only allows \"completed\" or \"failed\". Pydantic raises ValidationError inside the async iterator, terminating the stream before any file changes reach the caller.

Error Message

1 validation error for FileChangeItem
status
  Input should be 'completed' or 'failed' [type=literal_error, input_value='in_progress', input_type=str]
    For further information visit https://errors.pydantic.dev/2.13/v/literal_error

Root Cause

openai_codex_sdk/types.py:

# line 108
PatchApplyStatus = Literal[\"completed\", \"failed\"]

# line 111
class FileChangeItem(BaseModel):
    ...
    status: PatchApplyStatus  # line 117

CommandExecutionStatus already includes intermediate states; PatchApplyStatus is the outlier.

Fix Action

Workaround

Monkey-patch and rebuild the model before opening a thread:

from typing import Literal
from openai_codex_sdk import types as _t
_t.PatchApplyStatus = Literal[\"in_progress\", \"completed\", \"failed\"]
_t.FileChangeItem.model_fields[\"status\"].annotation = _t.PatchApplyStatus
_t.FileChangeItem.model_rebuild(force=True)

Code Example

from openai_codex_sdk import Codex
codex = Codex()
thread = codex.start_thread({\"model\": \"gpt-5.4\", \"sandbox_mode\": \"workspace-write\", \"working_directory\": \"/tmp/scratch\"})
streamed = await thread.run_streamed(\"Create hello.py with print('hi')\")
async for event in streamed.events:   # raises ValidationError on first patch update
    ...

---

1 validation error for FileChangeItem
status
  Input should be 'completed' or 'failed' [type=literal_error, input_value='in_progress', input_type=str]
    For further information visit https://errors.pydantic.dev/2.13/v/literal_error

---

# line 108
PatchApplyStatus = Literal[\"completed\", \"failed\"]

# line 111
class FileChangeItem(BaseModel):
    ...
    status: PatchApplyStatus  # line 117

---

PatchApplyStatus = Literal[\"in_progress\", \"completed\", \"failed\"]

---

from typing import Literal
from openai_codex_sdk import types as _t
_t.PatchApplyStatus = Literal[\"in_progress\", \"completed\", \"failed\"]
_t.FileChangeItem.model_fields[\"status\"].annotation = _t.PatchApplyStatus
_t.FileChangeItem.model_rebuild(force=True)
RAW_BUFFERClick to expand / collapse

Summary

openai-codex-sdk==0.1.11 crashes when consuming the streamed event loop on any agent-mode run that uses the patch/edit tool on a non-trivial file. The Codex CLI emits FileChangeItem payloads with status=\"in_progress\" while a patch is being applied, but the SDK's Pydantic model only allows \"completed\" or \"failed\". Pydantic raises ValidationError inside the async iterator, terminating the stream before any file changes reach the caller.

Version / environment

  • openai-codex-sdk==0.1.11
  • Python 3.12, Linux (WSL2)
  • pydantic 2.x

Repro

Any agent-mode call where the model edits a file. Minimal pseudo-repro:

from openai_codex_sdk import Codex
codex = Codex()
thread = codex.start_thread({\"model\": \"gpt-5.4\", \"sandbox_mode\": \"workspace-write\", \"working_directory\": \"/tmp/scratch\"})
streamed = await thread.run_streamed(\"Create hello.py with print('hi')\")
async for event in streamed.events:   # raises ValidationError on first patch update
    ...

Error

1 validation error for FileChangeItem
status
  Input should be 'completed' or 'failed' [type=literal_error, input_value='in_progress', input_type=str]
    For further information visit https://errors.pydantic.dev/2.13/v/literal_error

Root cause

openai_codex_sdk/types.py:

# line 108
PatchApplyStatus = Literal[\"completed\", \"failed\"]

# line 111
class FileChangeItem(BaseModel):
    ...
    status: PatchApplyStatus  # line 117

CommandExecutionStatus already includes intermediate states; PatchApplyStatus is the outlier.

Suggested fix

PatchApplyStatus = Literal[\"in_progress\", \"completed\", \"failed\"]

(Or whatever the canonical set of states the CLI emits for apply_patch updates is — happy to PR if the maintainers confirm the desired set.)

Workaround

Monkey-patch and rebuild the model before opening a thread:

from typing import Literal
from openai_codex_sdk import types as _t
_t.PatchApplyStatus = Literal[\"in_progress\", \"completed\", \"failed\"]
_t.FileChangeItem.model_fields[\"status\"].annotation = _t.PatchApplyStatus
_t.FileChangeItem.model_rebuild(force=True)

extent analysis

TL;DR

Update the PatchApplyStatus type in openai_codex_sdk/types.py to include the "in_progress" state to fix the ValidationError.

Guidance

  • Verify that the error occurs due to the PatchApplyStatus type not allowing the "in_progress" state by checking the error message and the openai_codex_sdk/types.py file.
  • Update the PatchApplyStatus type to include the "in_progress" state, as suggested in the issue: PatchApplyStatus = Literal["in_progress", "completed", "failed"].
  • Alternatively, apply the provided workaround by monkey-patching the PatchApplyStatus type and rebuilding the FileChangeItem model before opening a thread.
  • Test the fix by running the agent-mode call that previously caused the error and verify that the ValidationError is no longer raised.

Example

The suggested fix can be applied by modifying the openai_codex_sdk/types.py file:

PatchApplyStatus = Literal["in_progress", "completed", "failed"]

Or by using the provided workaround:

from typing import Literal
from openai_codex_sdk import types as _t
_t.PatchApplyStatus = Literal["in_progress", "completed", "failed"]
_t.FileChangeItem.model_fields["status"].annotation = _t.PatchApplyStatus
_t.FileChangeItem.model_rebuild(force=True)

Notes

The fix assumes that the "in_progress" state is a valid state for the PatchApplyStatus type. If this is not the case, further investigation may be required to determine the correct set of states.

Recommendation

Apply the workaround by monkey-patching the PatchApplyStatus type and rebuilding the FileChangeItem model, as this provides a temporary solution until the openai_codex_sdk library is updated to include the correct set of states for the PatchApplyStatus type.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

codex - 💡(How to fix) Fix openai-codex-sdk: FileChangeItem.status Literal rejects 'in_progress' from streaming patch updates [1 participants]