{"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":null,"httpStatus":null,"severity":"error","filePath":"crates/anthropic/src/completion.rs","lineNumber":677,"sourceCode":"                        _ => {\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        }\n    }\n}\n\nstruct RawToolUse {\n    id: String,","sourceCodeStart":659,"sourceCodeEnd":695,"githubUrl":"https://github.com/zed-industries/zed/blob/bc538def4545534201bbfcac4e95ac34ea6501b6/crates/anthropic/src/completion.rs#L659-L695","documentation":"Anthropic closes every content block before message_stop. This error fires when Event::MessageStop arrives while compactions_by_index still holds an open compaction block: the finalized summary never arrived, and consumers would otherwise see a Started compaction with no terminal event and treat it as still in progress. The partial compaction state is cleared before erroring.","triggerScenarios":"The stream ends (MessageStop) with a compaction content block that was started but never closed - a dropped content_block_stop event, a connection cut mid-block, or upstream truncation of a long encrypted summary.","commonSituations":"Network interruptions during long compaction summaries; proxies that close long-lived SSE connections; very large encrypted summaries hitting server limits.","solutions":["Retry the completion - truncation is usually transient.","Check for proxy/VPN idle timeouts on long-lived streaming connections and raise them.","Reduce the conversation size before compaction triggers (clear or split the thread) so summaries stay short.","If it persists, report to Zed/Anthropic with the request id and stream log."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"on stream end, if the final event is Err containing \"without finishing its compaction summary\", drop the partial compaction state and retry the completion once; otherwise surface the error to the UI layer.","preventionTips":["Raise proxy/VPN idle timeouts for long SSE streams","Trim conversation size before compaction triggers","Watch for correlated network drops when the error repeats"],"tags":["anthropic","streaming","compaction","truncation","sse"],"backgroundTag":null,"analyzedSha":"bc538def4545534201bbfcac4e95ac34ea6501b6","analyzedAt":"2026-08-16T07:30:46.435Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}