JuliusBrussee/caveman · error
rewriter: response exceeds %d bytes
Error message
rewriter: response exceeds %d bytes
What it means
The rewriter provider's response body exceeded maxProviderResponseBody bytes; the code deliberately reads one byte past the limit to distinguish over-limit from exact-limit and fails closed. This bounds memory use against misbehaving or malicious endpoints and prevents parsing unbounded provider output.
Source
Thrown at rewriter/provider.go:209
// error rather than a panic inside the proxy hot path.
if resp == nil {
return nil, fmt.Errorf("rewriter: %s: nil response", endpoint)
}
if resp.Body == nil {
resp.Body = http.NoBody
}
defer resp.Body.Close()
if resp.StatusCode < 200 || resp.StatusCode > 299 {
detail, _ := io.ReadAll(io.LimitReader(resp.Body, maxErrorBody))
return nil, fmt.Errorf("rewriter: %s: status %d: %s", endpoint, resp.StatusCode, strings.TrimSpace(string(detail)))
}
raw, err := io.ReadAll(io.LimitReader(resp.Body, maxProviderResponseBody+1))
if err != nil {
return nil, fmt.Errorf("rewriter: read response: %w", err)
}
if len(raw) > maxProviderResponseBody {
return nil, fmt.Errorf("rewriter: response exceeds %d bytes", maxProviderResponseBody)
}
return raw, nil
}
View on GitHub (pinned to 766dce6b13)
Solutions
- Treat the provider as misconfigured or hostile and refuse its output
- Raise the configured response ceiling only if the provider legitimately returns larger completions
- Skip the rewrite; the gate records the rejection without forwarding the bytes
Defensive patterns
Strategy: fallback
When it happens
Trigger: Thrown at rewriter/provider.go:209 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of JuliusBrussee/caveman@766dce6b13 (2026-08-18).
Data as JSON: /api/errors/6cd67792a8543237.
Report an issue: GitHub.