Responses API replay can fail on orphan reasoning item after interrupted turn
Summary
Codex can resend an orphan reasoning item when replaying history after an interrupted turn, which causes the Responses API request to fail instead of self-healing.
The concrete API error is:
{
"error": {
"message": "Item rs_... of type reasoning was provided without its required following item.",
"type": "invalid_request_error",
"param": "input"
}
}
Problem shape
A bad persisted/replayed sequence looks like:
- trailing
reasoningitem - synthetic
<turn_aborted>user marker - next real user message
In that shape, the replayed request contains a reasoning item without the model-generated item that originally followed it, and the Responses API rejects the request.
Expected behavior
Codex should detect this narrow invalid-request case, repair the replayed input/history by dropping only the orphan reasoning item, and retry once.
Proposed fix
I implemented a working patch on my fork here:
- Commit:
f3b9e8344c58b50bb0637f7ecdfcb9230cb27e82 - URL: https://github.com/jgrantJump/codex/commit/f3b9e8344c58b50bb0637f7ecdfcb9230cb27e82
The patch does two things:
- normalizes replayed history so incomplete
reasoningitems are removed while preserving<turn_aborted> - retries once for the exact missing-following-item error on both HTTP and websocket Responses transports
Validation on the patch
just fmtjust fix -p codex-corecargo test -p codex-core missing_reasoning -- --nocapture
I couldn’t upstream the PR directly because this repository limits PR creation to collaborators, but the fork commit above should be enough to review or cherry-pick.
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗