{"record":{"id":"160798a5e31fb1ed","repo":"Hmbown/CodeWhale","slug":"stream-overflow","errorCode":"stream_overflow","errorMessage":"Stream exceeded maximum content size of {limit_bytes} bytes, closing","messagePattern":"Stream exceeded maximum content size of (.+?) bytes, closing","errorType":"console","errorClass":"StreamError::Overflow","httpStatus":null,"severity":"error","filePath":"crates/tui/src/core/engine/turn_loop.rs","lineNumber":4842,"sourceCode":"            // Guard: max wall-clock duration\n            if stream_start.elapsed() > max_duration {\n                let envelope = StreamError::DurationLimit {\n                    limit_secs: max_duration_secs,\n                }\n                .into_envelope();\n                crate::logging::warn(&envelope.message);\n                stream_error.get_or_insert(envelope.message.clone());\n                let _ = self.tx_event.send(Event::error(envelope)).await;\n                break;\n            }\n\n            // Guard: max accumulated content bytes\n            if stream_content_bytes > max_content_bytes {\n                let envelope = StreamError::Overflow {\n                    limit_bytes: max_content_bytes,\n                }\n                .into_envelope();\n                crate::logging::warn(&envelope.message);\n                stream_error.get_or_insert(envelope.message.clone());\n                let _ = self.tx_event.send(Event::error(envelope)).await;\n                break;\n            }\n\n            let event = match event_result {\n                Ok(e) => {\n                    last_progress_mono = Instant::now();\n                    last_progress_wall = std::time::SystemTime::now();\n                    // Only content-bearing events make a stream productive.\n                    // Ping, usage/terminal deltas, block stops, and MessageStop\n                    // are protocol bookkeeping; counting them as content hid\n                    // empty/truncated provider responses from retry policy and\n                    // produced false time-to-first-token measurements.\n                    if !any_content_received && stream_event_has_actionable_content(&e) {\n                        any_content_received = true;\n                        first_token_at.get_or_insert_with(Instant::now);\n                    }","sourceCodeStart":4824,"sourceCodeEnd":4860,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/core/engine/turn_loop.rs#L4824-L4860","documentation":"A guard in the stream loop enforces a maximum number of accumulated content bytes. When the streamed response exceeds max_content_bytes, a StreamError::Overflow envelope is logged, emitted as an error event, and the stream loop breaks. This prevents unbounded memory growth from runaway generations.","triggerScenarios":"In run_turn's streaming loop, stream_content_bytes exceeds max_content_bytes after accumulating deltas; StreamError::Overflow { limit_bytes } is built via into_envelope() and the loop breaks.","commonSituations":"A model stuck in a repetition loop emitting megabytes of tokens; adversarial or pathological prompts producing enormous outputs; a misconfigured content-size limit that is too small for legitimate large code-generation tasks.","solutions":["Raise the max stream content bytes configuration if large outputs are legitimate.","Reduce the requested output size (lower max_tokens) so the response fits the budget.","Detect and avoid degenerate model repetition loops (adjust temperature/frequency penalties).","Split the work across multiple turns instead of one giant streamed response."],"exampleFix":"// before\nmax_content_bytes = 1 MiB  // large refactors overflow\n// after\nmax_content_bytes = 16 MiB","handlingStrategy":"validation","validationCode":"// ensure the requested output budget fits under the byte cap\nlet max_bytes = max_tokens * 4; // ~4 bytes/token\nif max_bytes > max_content_bytes { lower_max_tokens(); }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep max_content_bytes above the largest output your max_tokens allows.","Use repetition penalties to avoid runaway loops.","Split large tasks into multiple turns."],"tags":["streaming","llm","limits","payload-size"],"backgroundTag":"payload-too-large","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-22T21:17:16.096Z"}