{"record":{"id":"b24890080fb536ec","repo":"clockworklabs/SpacetimeDB","slug":"environment-read-response-exceeds-limit","errorCode":null,"errorMessage":"Environment read response exceeds limit","messagePattern":"Environment read response exceeds limit","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/cli/src/subcommands/env.rs","lineNumber":110,"sourceCode":"\nasync fn fetch(request: reqwest::RequestBuilder, query: Query) -> anyhow::Result<String> {\n    use futures::StreamExt;\n    let response = request\n        .timeout(std::time::Duration::from_secs(30))\n        .body(query.sql()?)\n        .send()\n        .await?;\n    ensure!(\n        response.status().is_success(),\n        \"Environment read failed with HTTP {}\",\n        response.status()\n    );\n    let mut body = Vec::new();\n    let limit = MAX_ENV_VARS * (MAX_ENV_KEY_BYTES + MAX_ENV_VALUE_BYTES) * 6 + 64 * 1024;\n    let mut stream = response.bytes_stream();\n    while let Some(chunk) = stream.next().await {\n        let chunk = chunk?;\n        ensure!(\n            body.len().saturating_add(chunk.len()) <= limit,\n            \"Environment read response exceeds limit\"\n        );\n        body.extend_from_slice(&chunk);\n    }\n    render(&body, &query)\n}\n\nfn render(body: &[u8], query: &Query) -> anyhow::Result<String> {\n    // Validate the requested projection before rendering any response values.\n    let results: Vec<spacetimedb_client_api_messages::http::SqlStmtResult<Vec<String>>> =\n        serde_json::from_slice(body).map_err(|_| anyhow::anyhow!(\"Invalid environment read response\"))?;\n    ensure!(results.len() == 1, \"Invalid environment read result count\");\n    let result = &results[0];\n    let expected: &[&str] = match query {\n        Query::List => &[\"key\", \"value\"],\n        Query::Get(_) => &[\"value\"],\n    };","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/eddf9f5014579a50d4b67630e28b6e15cad9c4af/crates/cli/src/subcommands/env.rs#L92-L128","documentation":"Thrown by `fetch` while streaming the HTTP response body for an environment read. The body is accumulated chunk-by-chunk and rejected as soon as its size would exceed `MAX_ENV_VARS * (MAX_ENV_KEY_BYTES + MAX_ENV_VALUE_BYTES) * 6 + 64 * 1024` bytes — the maximum plausible size of a fully populated env-var table. This protects the CLI from unbounded/hijacked responses.","triggerScenarios":"The server (or an intermediary) returns more than the computed limit of bytes on the `bytes_stream()` of the environment-read query — e.g. a misbehaving proxy, a wrong endpoint returning a large payload, or a server bug dumping the whole database.","commonSituations":"Pointing the CLI at a non-SpacetimeDB endpoint that answers the SQL request with a large HTML/JSON body; a compromised or misconfigured reverse proxy; a server version whose response format changed drastically.","solutions":["Verify the server URL points at a real SpacetimeDB node, not another HTTP service.","Retry; a one-off large error page from a proxy could be the cause.","Check for reverse proxies/load balancers rewriting or enlarging responses.","If legitimately huge, reduce the number of environment variables or value sizes stored in the environment."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err.contains(\"Environment read response exceeds limit\") {\n    // verify server URL / proxy, then retry; fail permanently if it recurs\n}","preventionTips":["Point the CLI only at genuine SpacetimeDB endpoints.","Audit proxies/load balancers for response rewriting.","Keep env var counts and sizes small."],"tags":["cli","http","response-size","spacetimedb"],"backgroundTag":"payload-too-large","analyzedSha":"eddf9f5014579a50d4b67630e28b6e15cad9c4af","analyzedAt":"2026-09-20T12:15:59.611Z","contentChangedAt":"2026-09-20T12:15:59.611Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}