{"record":{"id":"e1817bc930954a4a","repo":"Hmbown/CodeWhale","slug":"the-codewhale-service-returned-an-unexpectedly-lar","errorCode":null,"errorMessage":"The Codewhale service returned an unexpectedly large response","messagePattern":"The Codewhale service returned an unexpectedly large response","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/cli/src/cloud.rs","lineNumber":249,"sourceCode":"        if let Some(token) = request.bearer {\n            builder = builder.bearer_auth(token);\n        }\n        if let Some(body) = request.body {\n            builder = builder\n                .header(reqwest::header::CONTENT_TYPE, \"application/json\")\n                .body(body);\n        }\n        let response = builder\n            .send()\n            .context(\"could not reach the Codewhale service\")?;\n        let status = response.status().as_u16();\n        let mut body = Vec::new();\n        response\n            .take(MAX_RESPONSE_BYTES + 1)\n            .read_to_end(&mut body)\n            .context(\"failed to read the Codewhale service response\")?;\n        if body.len() as u64 > MAX_RESPONSE_BYTES {\n            bail!(\"The Codewhale service returned an unexpectedly large response\");\n        }\n        Ok(CloudResponse { status, body })\n    }\n}\n\n#[derive(Deserialize)]\n#[serde(rename_all = \"camelCase\")]\nstruct DeviceStart {\n    device_code: String,\n    user_code: String,\n    verification_uri: String,\n    verification_uri_complete: String,\n    expires_in: u64,\n    interval: u64,\n}\n\n#[derive(Deserialize)]\nstruct MeResponse {","sourceCodeStart":231,"sourceCodeEnd":267,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/0c42157ee52f9d55af2b506d71b46249910f77d3/crates/cli/src/cloud.rs#L231-L267","documentation":"The CLI cloud transport caps any Codewhale service response at MAX_RESPONSE_BYTES (256 KiB) by reading MAX_RESPONSE_BYTES+1 bytes and bailing if the body exceeds the cap. This bounds memory and rejects responses that cannot be legitimate small JSON API payloads (device-code start, token, me, key acknowledgements).","triggerScenarios":"A cloud API endpoint (e.g. /api/cli/device/token, /api/me, /api/model-keys/...) answering with a body larger than 256 KiB — typically an HTML error page from a gateway, a captive-portal response, or a misrouted endpoint returning bulk data.","commonSituations":"Corporate proxy or captive portal intercepting the request and returning a large interstitial page, wrong --api-base pointing at a website instead of the JSON API, or a service-side incident serving oversized error documents.","solutions":["Run the same request with curl -H 'Accept: application/json' against the configured API base and inspect Content-Type and size of what comes back.","If a proxy/captive portal is injecting HTML, fix network egress or bypass the proxy for the API host.","Verify the configured API base URL is the real Codewhale account API origin, not a web front end.","If the genuine API response grew past 256 KiB, report it — the payload contract for these endpoints is small JSON."],"exampleFix":"# before\n--api-base https://corp-portal.example.com\n\n# after (point at the real API origin)\n--api-base https://api.codewhale.net","handlingStrategy":"validation","validationCode":"// Pre-flight the API base before any cloud call\nlet resp = reqwest::Client::new().get(format!(\"{api_base}/api/me\"))\n    .header(ACCEPT, \"application/json\").send().await?;\nif resp.headers().get(CONTENT_TYPE).map(|v| v.as_bytes().starts_with(b\"application/json\")).unwrap_or(false) == false {\n    anyhow::bail!(\"API base is not serving JSON; check proxies/DNS\");\n}","typeGuard":null,"tryCatchPattern":"match transport.execute(req).await {\n    Ok(r) => r,\n    Err(e) if e.to_string().contains(\"unexpectedly large response\") => {\n        // response cannot be a valid small JSON payload — fix egress/proxy, do not retry\n        anyhow::bail!(\"cloud API egress broken (oversized non-JSON response): {e}\")\n    }\n    Err(e) => Err(e),\n}","preventionTips":["Verify egress to the API host returns JSON (curl) in new network environments.","Exclude the API host from captive-portal/proxy paths.","Pin --api-base to the real API origin."],"tags":["http","response-size-limit","cloud","cli"],"backgroundTag":"http-response-too-large","analyzedSha":"0c42157ee52f9d55af2b506d71b46249910f77d3","analyzedAt":"2026-08-20T21:50:45.477Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}