Repository navigation
Description
What version of Codex are you using?
Current main as of commit bdd282f in openai/codex.
What issue are you seeing?
After asking Codex to analyze an image for OCR, the thread can become permanently stuck with repeated request-size failures:
unexpected status 413 Payload Too Large: request too large, url: http://127.0.0.1:48111/v1/responses
Once the thread is in this state, sending a follow-up message still fails even when the image attachment is no longer attached to the chat. The oversized payload appears to be persisted in conversation history/rollout state and replayed on resume.
This looks related to #11440, but the concrete path here is image/tool-output history rather than only long text compaction.
Root cause hypothesis
In the current code path, image tool/function output can be prepared into a base64 data URL before being persisted into conversation history. Resume reconstruction later records persisted rollouts into history, and function output image items are preserved without counting the image URL against truncation budgets.
That means one large prepared image data URL can poison a rollout/history record and keep being included in later /v1/responses payloads.
Expected behavior
Codex should bound image payloads that enter model-visible history and should recover by replacing or omitting oversized image items, rather than replaying an unbounded base64 image until every follow-up request fails with 413.
Proposed fix
I have a patch branch here, but this repo currently blocks PR creation from non-collaborators:
Commit:
383ac91 Bound image history payloads
The patch does two things:
- Caps prepared prompt image data URLs at 10 MiB before they are persisted into conversation history, replacing oversized prepared images with the existing image-too-large placeholder.
- Counts function-call output image URLs against the existing byte/token truncation budget instead of preserving them unbounded, so resumed legacy rollouts can omit oversized image items.
Validation run on the patch branch
just fmt
just test -p codex-utils-output-truncation
just test -p codex-core image_preparation
just fix -p codex-utils-output-truncation
just fix -p codex-core
The full just test suite was not run locally.
Activity
github-actions commentedon Jun 28, 2026
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
jroth1111 commentedon Sep 11, 2026
Additional evidence relevant to the proposed per-image cap: many individually sub-10-MiB images can still exceed the aggregate request limit.
A deterministic test with real codex-cli 0.154.0 used an isolated temporary home, twelve distinct generated 1280×1280 PNGs in paired tool-call/output records, and a localhost Responses mock enforcing a 64 MiB JSON-body cap. Every encoded image was below 10 MiB, but the serialized request was 78,732,011 bytes and was rejected. A bounded recovery copy retaining the two newest images sent 13,175,417 bytes, included ten explicit references to archived originals, and completed successfully. The original rollout remained byte-for-byte unchanged. This is a client replay/transport test against a mock, not evidence of the production gateway's exact cap.
There is also an important repair compatibility constraint: newer paginated rollouts have record ordinals and persisted database byte offsets. Shrinking earlier JSONL records can invalidate those offsets. The tested recovery copy preserves the original source, response items, tool-call/output IDs, image originals and metadata; it supplies a bounded replacement checkpoint under a new conversation identity. It refuses unsupported lineage/rollback cases. This is a local workaround, not a supported native repair API.
Continued visual work subsequently regrew the affected active history to approximately 113 MiB. An offline watcher that waits for clients to close cannot prevent that active-session growth. A recovered copy was verified with a live provider turn, but sustained continuation and automatic goal-state transfer were not established.
The detailed measurements, version limitations, pagination findings, and recovery tests are maintained in this report on #41338. Please include aggregate serialized-byte preflight for both inference and compaction, plus a supported recovery path, in the fix criteria. Per-image limits alone do not bound a multi-image conversation.
Only synthetic measurements and sanitized aggregate observations are included. No private conversation IDs, paths, images, source documents, account data, credentials or raw logs are attached.
BuhtigNotes13 commentedon Oct 11, 2026
A related image-limit/recovery observation, checked in recorded task results on October 11, 2026. This differs from the HTTP 413 in the original report; a shared cause is unproven.
A long image-processing task on a connected desktop has a failed turn with HTTP 400, type
invalid_request_error, paraminput, codeimage_request_too_large: “The combined resolved image content is too large. Reduce the number or size of input images.” The visible recovery instruction already requested one-source comparisons and resized previews, but that turn did not complete. We have not measured the actual submitted image payload or established how much history was included.A limited workflow workaround worked in this case: continue the work in a separate task using five-source allocations. That task's completed state was verified, and its output reports completed image batches. This did not repair the original task, and five images is not a measured or generally safe capacity limit; image sizes and accumulated history may differ. We have not verified whether the separate task inherited any earlier image history. App and OS versions were not recorded for this observation.
The size rejection itself may be an expected input limit. The useful recovery question is whether the product can provide a supported way to reduce resolved image input in an existing task and continue it without editing internal history files. No community code was run or device settings changed for this report. No private images, paths, task IDs or raw transcripts are attached. Prepared with AI assistance.
SiyXo511 commentedon Oct 18, 2026
Additional production-path evidence for this failure, from a custom Responses provider.
Environment:
deepseek-flashthrough the official DeepSeek/v1/responsesendpointunexpected status 413 Payload Too Large: Failed to buffer the request body: length limit exceededSanitized measurements from the affected rollout:
view_imageoutputsfunction_call_outputitemsresponse_itemrecordsDeepSeek documents a 48 MiB request-body limit for inline images (50,331,648 bytes), so the serialized response history was already over the transport limit while the token counter showed only about 65% of the context window. The later turn contexts still had
summary: "none"; token-based compaction did not engage.The failing turn grew by a 616,827-byte
view_imagefunction output before the request failed. Sending a follow-up prompt then failed again with the same 413 because the full history was replayed. The thread never recovered in place.lywaterman commentedon Oct 20, 2026
We hit exactly this with Codex 0.162 behind our own OpenAI-compatible gateway. A screenshot-heavy thread grew to 48 MB per request, and once it passed the gateway's body limit, every later turn failed the same way.
Two things keep such a thread stuck:
context_length_exceededinside a streamedresponse.failedevent toContextWindowExceeded(codex-api/src/sse/responses_error.rs). An HTTP 4xx is treated as an ordinary failure, so compaction never runs.fill_to_context_windowaccounting bug in Auto-compaction never triggers #16033 (root cause and patch: Auto-compaction never triggers #16033 (comment)). The "full" marker is recorded as window − cumulative usage, which is 0 once a thread has made a few requests.What makes such threads recover for us:
/v1/responsesrequest with HTTP 200 and an SSEresponse.failedevent,error.code = "context_length_exceeded".last_token_usageis set to the full window (claymorelab@7be6b45).With both in place, the next turn compacts.
compact.rsdrops the oldest items one at a time while the compaction request is still too large, and the compacted history carries no images, so the thread recovers. Measured with a 16 MB gateway limit: 37 retries (cloud) and 53 (local) at about 18–20 MB each, then a successful compaction, after which requests were about 80 KB.That retry loop is expensive: one full-size upload per removed item. That's why we also cap image size and compact on image count (see #28316).
Chuncheng95 commentedon Oct 24, 2026
I published an experimental community toolkit based on a Codex 0.162.x + third-party Responses gateway incident:
https://github.com/Chuncheng95/Codex-DeepSeek-HTTP-413-Recovery
It provides:
Important limitations: this is not an official repair API or a universal 413 fix. Local rollout size is only a risk signal—not the actual HTTP request size—and the project does not claim a universal ~50 MB limit. The live recovery observation came from Codex 0.162.x; newer internal formats may behave differently.
Sharing this as a temporary prevention/recovery option while a supported aggregate-payload limit and recovery path are being discussed.
我根据一次 Codex 0.162.x 配合第三方 Responses 网关的实际故障,整理并开源了一个实验性社区工具包:
https://github.com/Chuncheng95/Codex-DeepSeek-HTTP-413-Recovery
项目包括:
需要特别说明:这不是官方恢复接口,也不是通用的 413 修复器。本地 rollout 大小只能作为风险信号,并不等于实际 HTTP 请求体大小;项目也不宣称普遍存在“约 50 MB”的固定上限。现有在线恢复观察来自 Codex 0.162.x,较新版本的内部格式可能不同。
在官方提供聚合请求体限制及受支持的恢复路径之前,希望这个项目能为遇到相同问题的用户提供临时的预防与恢复方案。
ChenxuBucm commentedon Oct 27, 2026
Additional evidence from Codex desktop on Windows with bundled codex-cli 0.164.0-alpha.11.1, using a third-party Responses relay.
The same image-heavy conversation recovered once and completed a real design task, then failed again during a new task as image outputs accumulated. This recurrence was a normal composer continuation, not an edit of an old message.
Measured request sizes from local transport logs:
The relay returned an nginx HTML HTTP 413. The client retried the same oversized payload five times without reducing it. A short follow-up failed before producing an answer. The last recorded model input usage was approximately 130k tokens against a 258,400-token context window, so transport failure occurred well before the nominal token context limit.
Native thread/compact/start also failed with HTTP 413. This matters because asking the user to compact after the failure does not provide a usable recovery path in this case.
A local, version-specific recovery preserved the original rollout prefix and full backup, archived 22 inline image occurrences (20 unique images) losslessly, and replaced only image content blocks with file references in an appended recovery checkpoint. Text, tool-call/result pairing, and the existing encrypted compaction item were preserved. The next compaction request was 540,754 bytes before compression and 200,926 bytes after compression. Native remote compaction then completed successfully. The original desktop conversation then completed the full interrupted task in 800 seconds. All 28 inference requests returned HTTP 200, with no 413. The largest was 6,448,183 bytes before compression and 4,503,623 bytes after compression. The produced 17-page PDF and offline HTML passed their rendering and interaction checks. Existing-image inspection used bounded previews while full-resolution originals were retained on disk. This confirms sustained completion of one resumed visual task, not a universal fix or proof that future unbounded histories cannot recur. This is an internal-storage workaround, not a supported repair API or a proposed user-facing solution.
Suggested acceptance criteria:
The relay's exact request cap is unknown, and this report does not establish a failure on OpenAI's direct endpoint. The relay rejection and Codex's inability to recover from that rejection are separate observations.
Only sanitized aggregate measurements are shared. No private images, conversation IDs, file paths, account identifiers, raw logs, or credentials are attached. Prepared with AI assistance at the user's request.
ChenxuBucm commentedon Oct 28, 2026
The same design conversation hit 413 again on October 28, after the recovery and successful compaction described in my previous comment.
I'm using Codex desktop on Windows, bundled codex-cli 0.164.0-alpha.11.1, through a third-party Responses relay. I have not reproduced this against OpenAI's direct endpoint.
This time the active history contained 44 inline image occurrences, representing 43 unique images. The transport log showed a 31,318,727-byte request, an nginx HTTP 413 response, and five retries. The UI ended with "stream disconnected before completion: error sending request". The image-generation tool had finished and saved its output; the following model request failed.
For recovery, we backed up the transcript and saved the image bytes without resizing or re-encoding them. We preserved the original transcript prefix, text, tool relationships and encrypted compaction state, then replaced active inline images with archive references in a local checkpoint. That checkpoint was 880,778 bytes. Native compaction succeeded, and a context check retained the latest design choices and unfinished work. This was a version-specific storage workaround, not a supported repair API.
The original conversation then finished the interrupted task in about 850 seconds. Across that run and its completion maintenance, the logs recorded 22 HTTP 200 responses and no new 413. The largest request was 12,917,462 bytes. A final compaction reduced active history to about 161 KB; another context check retained the deliverables and completion state. The originals and full transcript remain available locally.
I'd like to keep using this conversation for design work without opening a separate repair chat whenever its image history grows. Earlier token-based compaction helps, but image bytes and token usage can reach their limits at different times. The request sizes above are observations from this relay, not general limits.
Could the fix cover aggregate request bytes for both inference and compaction, including generated-image outputs? It also needs an in-place recovery path when a compact request is too large, and should stop retrying an unchanged body after a deterministic 413. Please test several rounds of image-heavy work after recovery: the first successful continuation did not prevent this recurrence.
This comment contains aggregate measurements only, with no private images or raw logs. Drafted with AI assistance and checked against local records.
DJNgoma commentedon Oct 28, 2026
Additional evidence and a tested local workaround for aggregate user-image batches, distinct from a single oversized image or tool-output history.
A desktop conversation with 40 user-attached JPEGs repeatedly failed through a custom local Responses bridge. Each inline image was below the bridge's 8 MiB per-image threshold (roughly 1.3–2.3 MB of encoded URL data), while the actual bridge log recorded a 71,459,441-byte request. The bridge's own post-sanitization request limit is 25 MiB. None of the current images triggered its individual-image compression, so retrying or sending a short follow-up repeated the same local 413.
The 25 MiB threshold and error wording here belong to the custom bridge, not an established OpenAI upstream limit. This is not evidence of a production OpenAI gateway rejecting that body.
I implemented a local bridge workaround:
Validation:
These are local serialization and mock-transport results, not a verified successful model continuation of the original desktop chat, nor proof that compressed images retain enough detail for every OCR task. Full-resolution originals remain available for focused inspection.
For a native fix, this reinforces the need for an aggregate serialized-body budget covering user images as well as tool/generated images, inference and compaction, and a supported recovery path that preserves originals. Per-image caps alone do not bound a batch. Image transformation should respect provider capabilities and user needs; a macOS-only
sipshelper and private-rollout fixture would not belong in the upstream Rust client.Following the current contribution policy (which does not accept external code PRs), I am adding the tested mechanism and measurements to this existing issue. No private images, document content, source paths, conversation identifiers, credentials, or raw logs are included.
Chuncheng95 commentedon Nov 1, 2026
What I verified myself
Other reports in this thread describe the same failure from different setups. I am not going to restate their measurements here — they are above, and I would rather not paraphrase numbers I did not produce. This comment is about what I actually ran, and what I need from an official fix as a result.
Context
Codex CLI / Desktop
0.162.x, talking to a third-party OpenAI-compatible endpoint. An image-heavy session started returning413 Payload Too Largeon every turn, including short follow-ups, andcodex resumekept replaying the same oversized history. A fresh session against the same endpoint worked normally.What I built
Codex-DeepSeek-HTTP-413-Recovery— a small toolkit with three parts:HANDOFF.mdprompt, for switching sessions before the thread dies;What I actually measured
From the original incident (this is the run the docs were written around, not a re-run I did while packaging the repo):
codex exec resumeon the new ID returned a normal replySeparately, a probe against that one gateway at that time accepted a 48 MB request (it reached the auth stage) and returned 413 from 52 MB upward. I want to be explicit that this describes that endpoint, that configuration, that moment — it does not establish a ~50 MB limit anywhere else, and I have not repeated the probe.
The repo itself adds synthetic offline tests, actually executed: MIME rewriting, metadata that is not on the first line, rejection of malformed JSONL, preservation of record count, unchanged source hash, detection of the 413 error shape, and path redaction in default output. No real session, no API key and no online service was used for those.
What I did not verify
0.162.x. The rollout is an internal format; newer versions may move directories, change fields, or stop auto-registering copies.What I need from an official fix
These are my requirements, derived from the above; they are not a summary of anyone else's list.
Until there is a supported path, a "copy, compress, validate, resume" tool like mine is the only thing I have found that gets a dead session back — and I would rather it existed in the client than in a separate script.
No real sessions, images, paths, keys or raw logs from my machine are included here; the toolkit keeps those local by design.
Arclabs001 commentedon Nov 4, 2026
Synthetic reproduction and a bounded native recovery approach
This report adds a synthetic reproduction and a tested Rust recovery implementation. It uses generated images, a localhost mock Responses endpoint, and public Codex source. No private conversation or production endpoint is involved.
Fix implementation: Arclabs001/codex@fd204c5 — 14 Rust files, including regression tests. Full diff against the tested base.
Reproduction
Environment: Windows x64,
codex-cli 0.166.0-alpha.5.1, app-server over stdio, an isolated configuration directory, and an HTTP Responses mock with WebSockets disabled. No model subscription is needed for the mock.thread/inject_itemsto add six generated valid 128 x 128 PNGs as inline image history. Exercise user messages, function-call outputs, and custom-tool outputs separately; preserve matching tool-call IDs.thread/compact/start, then send another text-only follow-up. Setstream_max_retries = 1for the characterization.Observed across those cases:
The logical
inputwas unchanged across each retry pair; complete request hashes can differ because of metadata. Both the manual compact request and later text follow-up retained the image payload. A separate characterization returning HTTP 200 with an SSEresponse.failed/payload_too_largealso failed, but the native recovery proposal below deliberately does not cover that error class. Automatic-compaction characterization used synthetic server-reported usage, not measured tokenizer usage.Why image resizing alone does not solve this
Codex already has image preparation and image size/patch limits. This is an aggregate serialized-body and recovery problem: many individually valid images can exceed a transport limit independently of the model's token budget. Retaining fewer images after a successful summary does not make the initial summary request fit.
Proposed native behavior
The linked commit implements the following approach against public base
079e17a422347e49d02501304f79fade7e569362:This is bounded omission from a summary input, not image recompression. A separate aggregate serialized-byte budget for inference and compaction remains useful for prevention.
Validation and limits
The local Rust change passed 21 added regression instances, including four mocked session integration cases. Coverage includes ordinary-turn recovery, remote-to-local compaction fallback, a first summary request that also gets 413, protection of current images and active tool records, failed/empty summaries, strictly smaller reductions, and refusal to classify an error after output as a pre-stream rejection. Focused protocol/core suites passed on Windows with Rust 1.95.0.
This is not whole-workspace, clippy, real-provider, or installed-desktop validation. SSE
payload_too_large, post-output errors, arbitrary WebSocket 413, current-turn-only image overload, and old histories without reliable turn IDs remain outside this recovery scope. No universal provider request-size limit is inferred.Prepared with AI assistance; only public-source analysis and synthetic measurements are included.