Skip to content

[Bug] Upstream HTTP 413 is not mapped to context_length_exceeded on the web-search/images sidecar path #7316

Closed

Description

@2991495215

Client or integration

Codex App (desktop) pointed at a local OpenCodex endpoint

Area

Proxy and routing

Summary

When an upstream returns HTTP 413, OpenCodex normally converts it into a terminating context_length_exceeded event so the client compacts and retries with a smaller request. That conversion is not applied on the web-search sidecar path (and the images/video sidecar path). The 413 leaks out as a generic upstream error, and Codex just resends the same oversized payload until it gives up.

Reproduction

  1. Run OpenCodex with the web-search sidecar enabled and a Codex client on the local endpoint.
  2. Send a turn large enough for the upstream to reject the body. Here: two inline screenshots (~2.8 MB as base64), and the upstream gateway answered 413 with a plain-text body.
  3. The client reports the error below and retries four times with the identical payload. No compaction is triggered and nothing in the message tells the client what to shrink.

Version

Affects 2.81.0. I unpacked the published 2.88.0 tarball and the same two throw sites are still there, so it is not fixed on latest.

Operating system

Linux

Provider and model

An OpenAI-compatible chat upstream behind a relay (openai-chat adapter), routed to a non-OpenAI model. The bug is not provider-specific, but a plain-text 413 body matters; see the root cause below.

Logs or error output

unexpected status 413 Payload Too Large: Provider error 413, url: http://127.0.0.1:10100/v1/responses

Four attempts, roughly 125 s apart, each lasting ~125 s before failing, always the same body. The upstream itself returned Request body exceeds the 8 MiB limit., but none of that text reaches the client.

Root cause

  • The mapping already exists: src/server/responses/context-overflow.ts turns an upstream 413 into a terminating event with code: context_length_exceeded, explicitly so the client compacts instead of resending.
  • It is only wired into adapter-dispatch.ts:1550, passthrough-delivery.ts:574, core-combo.ts:1047 and :1191, plus the local inbound rejection at request-prepare.ts:1335.
  • The sidecar bypasses it. src/web-search/loop.ts:621 and :634 throw new LoopError(prepared.response.status, "Provider error " + status + suffix), and jsonError() (loop.ts:253) returns it as {error:{message, type:"upstream_error", code:null}}. src/images/loop.ts:711 and :724 are the same shape.
  • Nothing re-checks on the way out: the runWithWebSearch(...) result at sidecar-execution.ts:545 is returned directly from core.ts:137.
  • suffix is only appended when formatErrorBody can extract text from the body. A plain-text 413 parses to an empty string by design, which is why the message is the bare Provider error 413 with no size hint.
  • In 2.88.0 the same throw sites are at src/web-search/loop.ts:494 and :507, and src/images/loop.ts:766 and :779, with no context-overflow handling added.

Suggested fix

Reuse context-overflow.ts on the sidecar error path, ideally once at the sidecar-execution boundary so both the web-search and images loops are covered, and let a 413 from either sidecar terminate as context_length_exceeded the way the main path already does.

Relation to #4112

Not the same path. #4112 was about the non-streaming branch in adapter-dispatch, and that mapping works on this version. This report is only about the sidecar bypass.

Screenshots and supporting files

None. Everything here is redacted.

Redacted configuration

Web-search sidecar enabled, upstream is an OpenAI-compatible relay. Endpoint host, account details and model routing have been removed.

Checks

  • I searched existing issues for 413, context_length_exceeded and sidecar, and found nothing covering this path.
  • I confirmed the behaviour on the latest published version, not just my installed one.

Activity

  1. added
    bug
    proxy
    tools
    on Oct 18, 2026
  2. Ingwannu commented on Oct 19, 2026

    @Ingwannu
    Owner

    Confirmed the missing sidecar path on current dev d11f067: the fetch search/image loops turned an upstream 413 into a generic LoopError rather than the shared context-overflow envelope. Eight focused plain-text/JSON and streaming/buffered cases failed before the fix.

    A minimal local patch now reuses the existing context-overflow event/response helper, preserves HTTP 413 inside Combo until its outer client boundary, and keeps the existing named free-tier-cap hop. The final focused run is 114 passed / 0 failed across five files, including Responses-entry search/Combo controls, image-loop coverage, unchanged 400/429 behavior and a synthetic-local refusal control; layout/file-size/import-cycle checks (11 tests) and structure SSOT also pass. These are isolated Linux/Bun 1.4.3 fixtures, not real provider or video-generation acceptance.

    Root typecheck exceeded this host's fixed 300-second validation envelope; no pass is claimed. The patch remains a local review artifact while publication/required hosted validation is pending. No upstream PR has been published for this patch, no fixing dev commit or release is claimed, and this issue stays open. No installed proxy or service was changed.

  3. github-actions commented on Oct 19, 2026

    @github-actions
    Contributor

    Automated translation bookkeeping — detected language: English.

  4. lidge-jun commented on Oct 19, 2026

    @lidge-jun
    Owner

    Fixed by #7352 (merged into dev as 0a995db). Sidecar (web search / images) provider overflows, including bare HTTP 413, now map to context_length_exceeded like the main path. Ships in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugproxytools

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions