{"record":{"id":"91d11ce3a11562aa","repo":"Hmbown/CodeWhale","slug":"stream-duration-limit","errorCode":"stream_duration_limit","errorMessage":"Stream exceeded maximum duration of {limit_secs}s, closing","messagePattern":"Stream exceeded maximum duration of (.+?)s, closing","errorType":"console","errorClass":"StreamError::DurationLimit","httpStatus":null,"severity":"error","filePath":"crates/tui/src/core/engine/turn_loop.rs","lineNumber":4830,"sourceCode":"                let preview = summarize_text(pending.content.trim(), 120);\n                pending_steers.push(pending);\n                let _ = self\n                    .tx_event\n                    .send(Event::status(format!(\"Steer input queued: {preview}\")))\n                    .await;\n            }\n\n            if self.cancel_token.is_cancelled() {\n                break;\n            }\n\n            // 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 {","sourceCodeStart":4812,"sourceCodeEnd":4848,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/core/engine/turn_loop.rs#L4812-L4848","documentation":"A guard in the stream loop enforces a maximum wall-clock duration for a single model stream. When elapsed time exceeds max_duration, a StreamError::DurationLimit envelope is created, logged, sent as an error event, and the loop breaks. This bounds runaway or endless streams.","triggerScenarios":"In run_turn's streaming loop, stream_start.elapsed() > max_duration on the next iteration check; the envelope message is stored in stream_error and the loop breaks.","commonSituations":"Models stuck emitting tokens indefinitely or in tool-call loops; a provider streaming very slowly so a huge response takes minutes; forgetting to bound extremely long agentic generations.","solutions":["Reduce request size (shorter prompt or lower max_tokens) so the stream completes inside the limit.","Raise the maximum stream duration configuration if long streams are expected for your workload.","Check for model/provider degenerate behavior (repeating tokens) that inflates stream time.","Split the task into smaller turns instead of one very long streamed generation."],"exampleFix":"// before\nmax_stream_duration = 60s\n// after\nmax_stream_duration = 300s  // large code-generation responses stream for minutes","handlingStrategy":"validation","validationCode":"// estimate worst-case stream duration before sending\nlet est = est_tokens(prompt) * avg_secs_per_token;\nif est > max_stream_duration { shrink_prompt_or_raise_limit(); }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set a stream duration limit comfortably above your largest expected response time.","Bound max_tokens per turn so streams cannot run indefinitely.","Detect degenerate repetition early and cancel."],"tags":["streaming","timeout","llm","limits"],"backgroundTag":"request-timeout","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"}