chenhg5/cc-connect · error
Content-Length too large: %d
Error message
Content-Length too large: %d
What it means
readMessage enforces a 10 MB cap on the declared Content-Length to prevent huge or malicious allocations (`body := make([]byte, contentLength)` would otherwise allocate whatever the peer claims). If the header value exceeds 10*1024*1024 the message is rejected with "Content-Length too large: %d".
Source
Thrown at agent/copilot/jsonrpc.go:115
// End of headers
break
}
if strings.HasPrefix(line, "Content-Length: ") {
val := strings.TrimPrefix(line, "Content-Length: ")
n, err := strconv.Atoi(strings.TrimSpace(val))
if err != nil {
return nil, fmt.Errorf("invalid Content-Length: %w", err)
}
contentLength = n
}
// Ignore other headers (Content-Type, etc.)
}
if contentLength < 0 {
return nil, fmt.Errorf("missing Content-Length header")
}
if contentLength > 10*1024*1024 {
return nil, fmt.Errorf("Content-Length too large: %d", contentLength)
}
body := make([]byte, contentLength)
if _, err := io.ReadFull(lr.reader, body); err != nil {
return nil, fmt.Errorf("read body: %w", err)
}
return body, nil
}
// rpcClient manages JSON-RPC request IDs and pending responses.
type rpcClient struct {
writer *lspWriter
nextID atomic.Int64
pendingMu sync.Mutex
pending map[int64]chan *jsonRPCResponse
}
View on GitHub (pinned to 4000b2338a)
Solutions
- Fix the message producer to send the true byte length of its JSON body
- If you legitimately need larger messages, raise the 10*1024*1024 cap in jsonrpc.go and re-test
- Log and inspect the declared length vs actual bytes to find the framing bug
- Split oversized payloads at the protocol level rather than in one frame
Example fix
// before (test/mock emits wrong length) body := buildHugeResult() fmt.Fprintf(w, "Content-Length: %d\r\n\r\n", len(body)*2) // after fmt.Fprintf(w, "Content-Length: %d\r\n\r\n", len(body))
Defensive patterns
Strategy: validation
Validate before calling
func plausibleContentLength(n int) bool {
return n > 0 && n <= 10*1024*1024
} Try / catch
body, err := readMessage(lr)
if err != nil {
if strings.Contains(err.Error(), "too large") {
slog.Error("copilot: oversized frame declared", "err", err)
return errFatal
}
return err
} Prevention
- Compute Content-Length with len(body) — never hand-write it
- Split large results into multiple smaller JSON-RPC messages
- Keep test payloads representative of production sizes
- Review any change to the child's writer for byte-count unit mistakes
When it happens
Trigger: The copilot child process (or test mock) sends a Content-Length header whose value is greater than 10485760 bytes — e.g. a corrupt/misencoded large payload, a bogus integer in a test fixture, or a malformed writer emitting an absurd length.
Common situations: TestLSPReader_TooLargeContentLength style fixtures; a writer that emits the body length before appending more content (counting wrong); a hostile/corrupted child process; unit confusion (bytes vs KiB) when constructing a big fake response.
Understand the failure class
Background: payload too large / request exceeds maximum size: why libraries cap bytes and how to fix oversize payloads — this error's family across 50 libraries.
Related errors
- hook input exceeds %d bytes
- invalid Content-Length: %w
- missing Content-Length header
- copilot: session.delete: %s
- copilot: session.delete failed: %s
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/488cc07b4fdbde0e.
Report an issue: GitHub.