{"record":{"id":"5d0e246e7700a5cc","repo":"zed-industries/zed","slug":"anthropic-ended-the-stream-without-finishing-its-c","errorCode":null,"errorMessage":"Anthropic ended the stream without finishing its compaction summary","messagePattern":"Anthropic ended the stream without finishing its compaction summary","errorType":"exception","errorClass":"LanguageModelCompletionError","httpStatus":null,"severity":"error","filePath":"crates/anthropic/src/completion.rs","lineNumber":739,"sourceCode":"                        \"end_turn\" => StopReason::EndTurn,\n                        \"max_tokens\" => StopReason::MaxTokens,\n                        \"tool_use\" => StopReason::ToolUse,\n                        \"refusal\" => StopReason::Refusal,\n                        \"compaction\" => StopReason::EndTurn,\n                        _ => {\n                            log::error!(\"Unexpected anthropic stop_reason: {stop_reason}\");\n                            StopReason::EndTurn\n                        }\n                    };\n                }\n                vec![Ok(LanguageModelCompletionEvent::UsageUpdate(\n                    convert_usage(&self.usage),\n                ))]\n            }\n            Event::MessageStop => {\n                // Anthropic closes every content block before ending the\n                // message, so an unclosed compaction block means the stream\n                // was malformed and its finalized summary never arrived.\n                // Consumers would otherwise see `Started` with no terminal\n                // event and treat the compaction as still in progress.\n                if !self.compactions_by_index.is_empty() {\n                    self.compactions_by_index.clear();\n                    return vec![Err(LanguageModelCompletionError::Other(anyhow::anyhow!(\n                        \"Anthropic ended the stream without finishing its compaction summary\"\n                    )))];\n                }\n                vec![Ok(LanguageModelCompletionEvent::Stop(self.stop_reason))]\n            }\n            Event::Error { error } => {\n                vec![Err(completion_error_from_anthropic_api(\n                    error,\n                    self.provider_name.clone(),\n                ))]\n            }\n            _ => Vec::new(),\n        }","sourceCodeStart":721,"sourceCodeEnd":757,"githubUrl":"https://github.com/zed-industries/zed/blob/916fc2b8cb3a815cbef4a3b40e13081be72036b6/crates/anthropic/src/completion.rs#L721-L757","documentation":"On Event::MessageStop the Anthropic mapper found a compaction content block that was started but never closed with a finishing delta; Anthropic closes every block before message stop, so an unclosed compaction block means the stream was truncated or malformed and the compaction summary cannot be used.","triggerScenarios":"Thrown at crates/anthropic/src/completion.rs:736 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Retry the compaction request to get a complete stream","Retain the pre-compaction context when the summary is incomplete so history is not lost","Log the raw event sequence and report persistent truncation to Anthropic"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"916fc2b8cb3a815cbef4a3b40e13081be72036b6","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}