{"record":{"id":"72d2e255545452f9","repo":"router-for-me/CLIProxyAPI","slug":"codex-live-request-body-too-large","errorCode":null,"errorMessage":"Codex live request body too large","messagePattern":"Codex live request body too large","errorType":"http","errorClass":null,"httpStatus":413,"severity":"error","filePath":"internal/client/codex/live/live.go","lineNumber":506,"sourceCode":"func (h *Handler) selectOAuth(ctx context.Context, model string, opts coreexecutor.Options) (*auth.HomeDispatchSelection, *auth.Auth, error) {\n\tvar selection *auth.HomeDispatchSelection\n\tvar selected *auth.Auth\n\tvar errSelect error\n\tif h.authManager.HomeEnabled() {\n\t\tselection, errSelect = h.authManager.SelectHomeAuthByKind(ctx, \"codex\", model, auth.AuthKindOAuth, opts)\n\t\tif selection != nil {\n\t\t\tselected = selection.CloneAuth()\n\t\t}\n\t} else {\n\t\tselected, errSelect = h.authManager.SelectAuthByKind(ctx, \"codex\", \"\", auth.AuthKindOAuth, opts)\n\t}\n\tif errSelect != nil && selection != nil {\n\t\tselection.End(\"selection_failed\")\n\t}\n\treturn selection, selected, errSelect\n}\n\nvar errBodyTooLarge = errors.New(\"Codex live request body too large\")\n\nfunc readBody(body io.Reader) ([]byte, error) {\n\tpayload, errRead := readLimitedBody(body)\n\tif errRead != nil {\n\t\tif errors.Is(errRead, errBodyTooLarge) {\n\t\t\treturn nil, errRead\n\t\t}\n\t\treturn nil, fmt.Errorf(\"failed to read Codex live request: %w\", errRead)\n\t}\n\treturn payload, nil\n}\n\nfunc readLimitedBody(body io.Reader) ([]byte, error) {\n\tif body == nil {\n\t\treturn nil, nil\n\t}\n\tpayload, errRead := io.ReadAll(io.LimitReader(body, maxBodySize+1))\n\tif errRead != nil {","sourceCodeStart":488,"sourceCodeEnd":524,"githubUrl":"https://github.com/router-for-me/CLIProxyAPI/blob/78f0c4079e3e6273d65d03b5549cffc898703264/internal/client/codex/live/live.go#L488-L524","documentation":"Raised when io.ReadAll on the upstream HTTP response body fails inside the plugin host's HTTP bridge (Do). Before returning, the bridge already recorded the error via helps.RecordAPIResponseError for observability; the returned error wraps the read failure with %w.","triggerScenarios":"A plugin's host.http request succeeds at the transport level but the body read is interrupted: connection reset mid-body, context cancelled while reading, proxy dropping the stream, or a Content-Length larger than what the peer sends.","commonSituations":"Flaky upstream networks; aggressive timeouts on the caller's context; proxies (forwarded via NewProxyAwareHTTPClient) terminating long responses; very large streaming-ish bodies the server truncates.","solutions":["Retry the request with idempotent methods (GET) — transient resets are the most common cause.","Check whether the caller's context was cancelled; decouple long plugin HTTP reads from short request deadlines.","Inspect proxy configuration (config.yaml proxy settings / NewProxyAwareHTTPClient env) if a proxy sits in the path.","Verify upstream server behavior with curl to rule out truncated responses."],"exampleFix":"// plugin side: retry transient body-read failures for idempotent GETs\nresp, err := http.Do(ctx, req)\nfor attempt := 0; err != nil && attempt < 2 && req.Method == \"GET\"; attempt++ {\n    time.Sleep(backoff(attempt))\n    resp, err = http.Do(ctx, req)\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"resp, err := http.Do(ctx, req)\nif err != nil {\n    if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {\n        return err // do not retry caller cancellation\n    }\n    var netErr net.Error\n    if errors.As(err, &netErr) && netErr.Timeout() && isIdempotent(req.Method) {\n        return retryWithBackoff(ctx, func() error { _, e := http.Do(ctx, req); return e })\n    }\n    return err\n}","preventionTips":["Avoid coupling large-body reads to tight caller deadlines.","Monitor upstream reliability; resets mid-body are usually transient.","Check recorded API response error metadata (helps.RecordAPIResponseError) in host telemetry to correlate."],"tags":["pluginhost","network","http"],"backgroundTag":null,"analyzedSha":"78f0c4079e3e6273d65d03b5549cffc898703264","analyzedAt":"2026-08-15T12:26:37.444Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}