Hmbown/CodeWhale · error

{err}

Error message

{err}

What it means

`take_sse_line` extracted a complete line from the byte buffer and its strict UTF-8 decode failed (`InvalidSseUtf8`, reporting `valid_up_to`/`error_len`). Per #5374 the client never uses `from_utf8_lossy`: genuinely invalid bytes fail closed instead of injecting U+FFFD into model output. Note that a multi-byte character split across two network reads is safe by design — decode only happens on complete lines — so this error means real invalid bytes.

Source

Thrown at crates/tui/src/client/chat.rs:1362

                    yield Err(anyhow::anyhow!("SSE buffer exceeded {MAX_SSE_BUF} bytes — aborting stream"));
                    break;
                }

                if byte_buf.len() > SSE_BACKPRESSURE_HIGH_WATERMARK {
                    tokio::time::sleep(Duration::from_millis(SSE_BACKPRESSURE_SLEEP_MS)).await;
                }

                // Process complete SSE lines from the buffer. Strict UTF-8:
                // never `from_utf8_lossy` here — a mid-character TCP split
                // stays in `byte_buf` until `\n`, and a genuinely invalid
                // line fails closed instead of injecting U+FFFD (#5374).
                let mut lines_processed = 0usize;
                loop {
                    let line = match super::take_sse_line(&mut byte_buf) {
                        Ok(Some(line)) => line,
                        Ok(None) => break,
                        Err(err) => {
                            yield Err(anyhow::anyhow!("{err}"));
                            break 'stream;
                        }
                    };

                    if line.is_empty() {
                        // Empty line = event boundary, process accumulated data
                        if !line_buf.is_empty() {
                            let data = std::mem::take(&mut line_buf);
                            match parse_sse_data_frame(
                                &data,
                                &mut content_index,
                                &mut text_started,
                                &mut thinking_started,
                                &mut tool_indices,
                                &mut reasoning_detail_buffers,
                                &mut inline_reasoning_tags,
                                reasoning_stream_style,
                            ) {

View on GitHub (pinned to 8880682c63)

Solutions

  1. Retry the request — transient corruption usually clears
  2. Bypass proxies/VPNs between the client and the provider
  3. Confirm the provider endpoint serves UTF-8 SSE
  4. If deterministic, capture the raw bytes and report upstream
Defensive patterns

Strategy: try-catch

Type guard

fn is_invalid_sse_utf8(err: &anyhow::Error) -> bool {
    err.to_string().contains("SSE line is not valid UTF-8")
}

Try / catch

match stream.next().await {
    Some(Err(e)) if is_invalid_sse_utf8(&e) => {
        // Real corruption (split chars across reads are handled): retry or bypass proxy
        backoff_retry().await;
    }
    Some(Err(e)) => return Err(e),
    other => { /* forward */ }
}

Prevention

When it happens

Trigger: Corrupt bytes from a proxy/CDN; a response that is not actually UTF-8; an intermediary rewriting the body; truncation that lands mid-multibyte-character on a line boundary edge case.

Common situations: MITM proxies transcoding responses; provider serving a mis-encoded frame; corrupted transfer over flaky links.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@8880682c63 (2026-08-16). Data as JSON: /api/errors/fd34ac3ff4c49b4d. Report an issue: GitHub.