OpenAI WebSocket mode "previous_response_not_found": fix
previous_response_not_found in Responses API WebSocket mode means the ID is not in the connection's cache. Retry with previous_response_id null and full input.
{ "type": "error", "status": 400, "stream_id": "main", "error": { "type": "invalid_request_error", "code": "previous_response_not_found", "message": "Previous response with id 'resp_abc' not found.", "param": "previous_response_id" }}previous_response_not_found means the previous_response_id you sent could not be resolved from the connection's state, and the documented fix is: "Retry with full input context and previous_response_id set to null." Sending the same ID again is not on the list of fixes.
[1] Work out why the ID was missing. WebSocket mode keeps previous-response state in a connection-local in-memory cache and does not write it to disk. When an ID is not cached, store=true lets the service hydrate it from persisted state when available (losing the latency benefit); with store=false, including ZDR, there is no fallback and you get this error. The docs name these cases:
| Situation | What the docs say |
|---|---|
| The connection closed, or you reconnected after the 60-minute limit | The connection-local cache disappears for every lane |
A same-lane continuation got a 4xx or 5xx | The referenced previous_response_id is evicted from the cache |
A cross-lane fork with store=false was still queued | If the source lane advances or fails meanwhile, the parent can be evicted |
The docs say each lane keeps its "latest" cached response. Whether an older response ID from the same lane is still cached was not confirmed in the docs.
[2] Log the error event's code and stream_id. When the server can tie an error to a named lane, the event carries stream_id, and other lanes keep running after a request-scoped error. Here are the three error events from the WebSocket mode guide, saved verbatim and sorted into actions:
$ python3 -I ../ws_error_action.py *.json1-previous-not-found.json: status=400 lane=main code=previous_response_not_found -> retry with previous_response_id=null and the full input context2-connection-limit.json: status=400 lane=(connection) code=websocket_connection_limit_reached -> open a new WebSocket connection, then recover each lane3-stream-limit.json: status=400 lane=agent_33 code=websocket_stream_limit_reached -> reuse an existing stream_id or open a new connectionThe connection-limit event has no stream_id. A closed connection drops the cache for every lane, so recover all of them ([6]).
[3] Keep the conversation history on the client so you can resend it. With store=false it is your only way back. The conversation state guide's manual example appends the user input plus every item in response.output, including encrypted reasoning items, to the history. Applied to one WebSocket lane:
history = [] # every input item sent and output item received on this lane def run_turn(connection, new_items, prev_id): history.extend(new_items) connection.response.create( stream_id="main", model=MODEL, store=False, previous_response_id=prev_id, input=new_items if prev_id else history, ) for event in connection: if event.type == "response.completed": history.extend(event.response.output) return event.response.id if event.type == "error" and event.error.code == "previous_response_not_found": return run_turn(connection, [], None) # start a new response from the full history if event.type in {"response.failed", "response.incomplete", "error"}: raise RuntimeError(event.to_json()) raise RuntimeError("Connection closed before the response finished.")Resending a long history costs input tokens, but the docs also note that with previous_response_id, all previous input tokens in the chain are billed as input tokens anyway.
[4] If you compacted context, restart from the compacted window. The standalone /responses/compact endpoint returns a compacted input window, not a response ID: use it as the new response's input and append the next user or tool items. The docs say "do not prune the returned window". With server-side compaction (context_management), keep continuing with the latest previous_response_id as usual.
[5] Let a fork start before advancing its source lane. With store=false, a cross-lane fork needs its parent to stay in the cache. The docs say to wait until the fork lane emits response.in_progress before advancing the source lane, or retry with previous_response_id set to null and the full input context.
[6] For websocket_connection_limit_reached, open a new connection. Connections last up to 60 minutes, and the docs say "Reconnect at the limit." The new connection starts with an empty cache, so recover lane by lane: if you stored a prior response (store=true) and have a valid ID, continue with it and new input items; otherwise start a new response with full input as in [3].
The guide lists two more per-connection limits. A connection can have up to 16 in-flight responses across lanes, and extras are queued. It accepts up to 32 distinct named stream_id values (the default lane does not count); past that you get websocket_stream_limit_reached, so reuse a stream_id or open a new connection.
If Codex CLI is the one dropping its WebSocket, that is a different problem: see Codex "stream disconnected" errors.