Craft Anything: understand how any software works, and craft your own.
Rust
Say a server may still be loading when its answer stream ends early (#1040)
Yash Patadiyae85e6acf5c60
diff --git a/crates/ai/src/openai.rs b/crates/ai/src/openai.rsindex 712ea483..5d87d61a 100644--- a/crates/ai/src/openai.rs+++ b/crates/ai/src/openai.rs@@ -425,7 +425,10 @@ impl ChatStream {Some(f) => StopReason::parse(f),None if has_calls => StopReason::ToolUse,None if self.done => StopReason::EndTurn,- None => return Err(ToolError::new(ErrorCode::Truncated, "The answer stream ended early.")),+ None => {+ return Err(ToolError::new(ErrorCode::Truncated, "The answer stream ended early.")+ .with_remediation("The server ended the answer early (a local server may still be loading the model). Try again in a minute."));+ }};// Some servers say "stop" for tool calls. A limit or refusal must still prevent execution.let stop = if has_calls && stop == StopReason::EndTurn { StopReason::ToolUse } else { stop };@@ -949,6 +952,17 @@ mod tests {}}+ #[test]+ fn early_stream_end_is_reported_with_remediation() {+ let st = ChatStream::default();+ let err = st.finish("m").unwrap_err();+ assert_eq!(err.code, ErrorCode::Truncated);+ assert_eq!(err.message, "The answer stream ended early.");+ let fix = err.remediation.as_deref().expect("remediation is set");+ assert!(fix.contains("loading the model"));+ assert!(fix.contains("Try again in a minute."));+ }+/// #369: OpenRouter routes to an upstream provider per request, and one without tool calling/// answered "400: Provider returned error". With tools in the request, only providers that/// support every parameter are used; nothing else changes.diff --git a/docs/ROADMAP.md b/docs/ROADMAP.mdindex 8e26cd19..2b1f44f6 100644--- a/docs/ROADMAP.md+++ b/docs/ROADMAP.md@@ -421,6 +421,7 @@ been run live.- [ ] A chat sent while a llama.cpp router is still loading the model ended after 31 s with "Theanswer stream ended early." and no next step (seen once live, 27B model); say the server maystill be loading it and to try again in a minute+ — claimed: yashpatadiya1724-cmyk, branch bugfix/r5.4-stream-loading-remediation### R5.5 API-key builds fail in words people can useOwner: open · Status: todo