{"record":{"id":"86fae5423064a6ff","repo":"xai-org/grok-build","slug":"acp-message-exceeds-byte-limit-bytes-read","errorCode":null,"errorMessage":"ACP message exceeds {} byte limit ({} bytes read)","messagePattern":"ACP message exceeds (.+?) byte limit \\((.+?) bytes read\\)","errorType":"exception","errorClass":"io::Error (InvalidData)","httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-acp-lib/src/line_reader.rs","lineNumber":164,"sourceCode":"        let (consumed, done) = {\n            let available = reader.fill_buf().await?;\n            if available.is_empty() {\n                return Ok(buf.len()); // EOF\n            }\n            match available.iter().position(|&b| b == b'\\n') {\n                Some(pos) => {\n                    buf.extend_from_slice(&available[..=pos]);\n                    (pos + 1, true)\n                }\n                None => {\n                    buf.extend_from_slice(available);\n                    (available.len(), false)\n                }\n            }\n        };\n        reader.consume_unpin(consumed);\n        if buf.len() > MAX_LINE_SIZE {\n            return Err(io::Error::new(\n                io::ErrorKind::InvalidData,\n                format!(\n                    \"ACP message exceeds {} byte limit ({} bytes read)\",\n                    MAX_LINE_SIZE,\n                    buf.len()\n                ),\n            ));\n        }\n        if done {\n            return Ok(buf.len());\n        }\n    }\n}\n\n#[cfg(test)]\nmod tests {\n    use futures::{AsyncReadExt as _, io::Cursor};\n","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-acp-lib/src/line_reader.rs#L146-L182","documentation":"Thrown by `read_line_capped` in the ACP (Agent Client Protocol) line reader when a single newline-delimited message exceeds MAX_LINE_SIZE bytes. Because ACP frames are length-unbounded JSON lines, this guard prevents unbounded memory growth from a malicious or buggy peer. The reader consumes the bytes, sees buf.len() > MAX_LINE_SIZE, and returns InvalidData before any parsing occurs.","triggerScenarios":"Reading from an ACP stream whose peer emits a line longer than MAX_LINE_SIZE — an oversized JSON-RPC notification/result (e.g. a huge tool output inlined in a message), a missing newline causing frames to merge, or a non-ACP peer writing arbitrary data to the pipe.","commonSituations":"Agent returning enormous file contents or diffs inline in one message; protocol desync where a payload without a trailing newline swallows subsequent frames; connecting the reader to a stream that emits binary data.","solutions":["Truncate or paginate large payloads on the sending side (chunk tool outputs, use file references) so no single ACP line exceeds the limit.","Verify the peer actually terminates every JSON message with a newline; fix any writer that omits it.","If legitimately large messages are expected, raise MAX_LINE_SIZE in xai-acp-lib to a safe upper bound.","Confirm the transport carries text ACP frames, not binary/interleaved output from another process."],"exampleFix":"// before (sender, agent side)\nlet msg = serde_json::to_vec(&huge_result)?;\nstream.write_all(&msg).await?;\n// after\nlet msg = serde_json::to_vec(&truncate_result(&huge_result, MAX_INLINE_BYTES))?;\nstream.write_all(&msg).await?;\nstream.write_all(b\"\\n\").await?;","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"fn is_oversized_acp_message(err: &io::Error) -> bool {\n    err.kind() == io::ErrorKind::InvalidData\n        && err.to_string().contains(\"ACP message exceeds\")\n}","tryCatchPattern":"match reader.read_line_capped(&mut buf).await {\n    Ok(n) => parse(&buf[..n])?,\n    Err(e) if is_oversized_acp_message(&e) => {\n        tracing::warn!(\"peer sent oversized ACP line; dropping frame\");\n        // resync reader on next newline\n    }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Truncate or chunk large payloads on the sending agent before writing","Always terminate JSON messages with a newline on the wire","Never connect the ACP reader to binary or third-party output streams","Review MAX_LINE_SIZE when payloads are expected to grow"],"tags":["protocol","acp","io","limits"],"backgroundTag":"message-exceeds-size-limit","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}