{"record":{"id":"c8caadb9a489bc49","repo":"zed-industries/zed","slug":"only-tool-result-should-be-extracted","errorCode":null,"errorMessage":"Only tool result should be extracted","messagePattern":"Only tool result should be extracted","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/language_models/src/provider/ollama.rs","lineNumber":407,"sourceCode":"                        .extract_if(.., |x| matches!(x, MessageContent::ToolResult(..)))\n                    {\n                        match tool_result {\n                            MessageContent::ToolResult(tool_result) => {\n                                let images = tool_result\n                                    .images()\n                                    .map(|image| image.source.to_string())\n                                    .collect::<Vec<_>>();\n                                messages.push(ChatMessage::Tool {\n                                    tool_name: tool_result.tool_name.to_string(),\n                                    content: tool_result.text_contents(),\n                                    images: if images.is_empty() {\n                                        None\n                                    } else {\n                                        Some(images)\n                                    },\n                                })\n                            }\n                            _ => unreachable!(\"Only tool result should be extracted\"),\n                        }\n                    }\n                    if !msg.content.is_empty() {\n                        messages.push(ChatMessage::User {\n                            content: msg.string_contents(),\n                            images: if images.is_empty() {\n                                None\n                            } else {\n                                Some(images)\n                            },\n                        })\n                    }\n                }\n                Role::Assistant => {\n                    let mut text_content = String::new();\n                    let mut thinking = None;\n                    let mut tool_calls = Vec::new();\n                    for content in msg.content.into_iter() {","sourceCodeStart":389,"sourceCodeEnd":425,"githubUrl":"https://github.com/zed-industries/zed/blob/916fc2b8cb3a815cbef4a3b40e13081be72036b6/crates/language_models/src/provider/ollama.rs#L389-L425","documentation":"When converting Zed's internal message representation into an Ollama chat request, the code maps message content parts to Ollama message types. Tool-result content parts are expected to be filtered/extracted earlier in the conversion; if any other content-part variant reaches this match arm, the code declares it a logic error and panics with 'Only tool result should be extracted'.","triggerScenarios":"Streaming a completion whose request message contains a content part that is neither handled upstream nor a tool result — e.g. a `ToolUse` or image/text variant reaching the extraction branch in `to_ollama_request` because the assistant/user message wasn't normalized first.","commonSituations":"New `MessageContent` variants added to the language model protocol without updating the Ollama provider conversion; requests built from conversation history containing unmatched tool-call/tool-result pairs.","solutions":["Update the Ollama provider's `to_ollama_request` to map the new content-part variant to the appropriate Ollama message type.","Filter non-tool-result parts before this match so only tool results are extracted, mirroring how other providers do it.","Log and skip unrecognized parts instead of panicking, so chats with mixed content degrade gracefully."],"exampleFix":"// before\n_ => unreachable!(\"Only tool result should be extracted\"),\n// after\nother => {\n    log::warn!(\"skipping unsupported content part in ollama request: {other:?}\");\n    continue;\n}","handlingStrategy":"fallback","validationCode":"// validate message contents before building the request\nlet unsupported: Vec<_> = msg.content.iter().filter(|p| !matches!(p, MessageContent::ToolResult(_))).collect();\nif !unsupported.is_empty() { /* log and skip or return an error */ }","typeGuard":"fn is_tool_result(part: &MessageContent) -> bool {\n    matches!(part, MessageContent::ToolResult(_))\n}","tryCatchPattern":"// the panic is unreachable!(); wrap request building at the boundary\nlet request = std::panic::catch_unwind(|| to_ollama_request(&messages)).map_err(|_| anyhow!(\"ollama request conversion failed\"))?;","preventionTips":["Normalize/extract tool results from messages before provider-specific conversion.","When adding MessageContent variants, update every provider's to_*_request.","Prefer warn-and-skip over unreachable for unrecognized content parts."],"tags":["ollama","llm","request-conversion","unreachable","panic"],"backgroundTag":"unexpected-response-shape","analyzedSha":"916fc2b8cb3a815cbef4a3b40e13081be72036b6","analyzedAt":"2026-09-19T19:09:50.599Z","contentChangedAt":"2026-09-19T19:09:50.599Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}