{"record":{"id":"1227b1bd245c24a7","repo":"BigPizzaV3/CodexPlusPlus","slug":"llm-bridge-1227b1","errorCode":null,"errorMessage":"LLM Bridge 响应体过大","messagePattern":"LLM Bridge 响应体过大","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/codex-plus-core/src/routes.rs","lineNumber":756,"sourceCode":"        .redirect(reqwest::redirect::Policy::none())\n        .build()?;\n    let response = client\n        .post(url)\n        .headers(llm_proxy_headers(&payload)?)\n        .body(body)\n        .send()\n        .await?;\n    let http_status = response.status().as_u16();\n    let ok = response.status().is_success();\n    let content_type = response\n        .headers()\n        .get(reqwest::header::CONTENT_TYPE)\n        .and_then(|value| value.to_str().ok())\n        .unwrap_or_default()\n        .to_string();\n    if let Some(length) = response.content_length() {\n        if length > 4 * 1024 * 1024 {\n            anyhow::bail!(\"LLM Bridge 响应体过大\");\n        }\n    }\n    let bytes = response.bytes().await?;\n    if bytes.len() > 4 * 1024 * 1024 {\n        anyhow::bail!(\"LLM Bridge 响应体过大\");\n    }\n    let body_text = String::from_utf8_lossy(&bytes).to_string();\n    let body_json = if content_type\n        .split(';')\n        .next()\n        .map(str::trim)\n        .is_some_and(|value| value.eq_ignore_ascii_case(\"application/json\"))\n    {\n        serde_json::from_slice::<Value>(&bytes).ok()\n    } else {\n        None\n    };\n","sourceCodeStart":738,"sourceCodeEnd":774,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/routes.rs#L738-L774","documentation":"llm_proxy_value caps the upstream response at 4 MiB. It checks the Content-Length header first, then re-checks the actual byte count after reading, rejecting responses that exceed the limit either way.","triggerScenarios":"The proxied LLM endpoint returns a response whose Content-Length (or streamed body size) exceeds 4 * 1024 * 1024 bytes.","commonSituations":"Model returns an extremely long completion; upstream echoes large input; a non-LLM endpoint behind the bridge returns big JSON/binary payloads.","solutions":["Reduce max_tokens / prompt size so responses stay under 4 MiB","Point the bridge at an endpoint returning concise output","If large responses are required, raise the limit in llm_proxy_value (crates/codex-plus-core/src/routes.rs) — noting the safety tradeoff"],"exampleFix":"// before\nlet bytes = response.bytes().await?; // may exceed 4 MiB\n// after\nlet bytes = response.bytes().await?;\nif bytes.len() > 4 * 1024 * 1024 {\n    return Err(anyhow::anyhow!(\"LLM Bridge 响应体过大\")); // keep, but client should request smaller outputs\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match llm_proxy_value(payload).await {\n    Err(e) if e.to_string().contains(\"响应体过大\") => {\n        payload[\"body\"] = serde_json::json!(shrink_request_for_smaller_reply(payload));\n        retry(payload)\n    }\n    other => other,\n}","preventionTips":["Cap max_tokens in the upstream request so replies stay well under 4 MiB","Avoid pointing the bridge at endpoints returning large non-LLM payloads","If large replies are expected, raise the limit consciously rather than treating the error as transient"],"tags":["http","response-size","llm-bridge"],"backgroundTag":"payload-too-large","analyzedSha":"b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6","analyzedAt":"2026-09-19T23:35:21.129Z","contentChangedAt":"2026-09-19T23:35:21.129Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}