{"record":{"id":"59a441313bdfa394","repo":"zed-industries/zed","slug":"anthropic-streamed-a-compaction-delta-before-start","errorCode":null,"errorMessage":"Anthropic streamed a compaction delta before starting its content block","messagePattern":"Anthropic streamed a compaction delta before starting its content block","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/anthropic/src/completion.rs","lineNumber":542,"sourceCode":"                }\n                ContentDelta::ThinkingDelta { thinking } => {\n                    vec![Ok(LanguageModelCompletionEvent::Thinking {\n                        text: thinking,\n                        signature: None,\n                    })]\n                }\n                ContentDelta::SignatureDelta { signature } => {\n                    vec![Ok(LanguageModelCompletionEvent::Thinking {\n                        text: \"\".to_string(),\n                        signature: Some(signature),\n                    })]\n                }\n                ContentDelta::CompactionDelta {\n                    content,\n                    encrypted_content,\n                } => {\n                    let Some(compaction) = self.compactions_by_index.get_mut(&index) else {\n                        return vec![Err(LanguageModelCompletionError::Other(anyhow::anyhow!(\n                            \"Anthropic streamed a compaction delta before starting its content block\"\n                        )))];\n                    };\n                    // Unlike summary text, `encrypted_content` arrives whole:\n                    // a later delta carries a complete replacement value, not\n                    // a chunk to append (Anthropic's own SDKs assign it, the\n                    // way they do thinking signatures).\n                    if let Some(encrypted_content) =\n                        encrypted_content.filter(|encrypted| !encrypted.is_empty())\n                    {\n                        compaction.encrypted_content = Some(encrypted_content);\n                    }\n                    let Some(content) = content.filter(|content| !content.is_empty()) else {\n                        return Vec::new();\n                    };\n                    compaction.summary.push_str(&content);\n                    vec![Ok(LanguageModelCompletionEvent::Compaction(\n                        CompactionUpdate::SummaryDelta(content),","sourceCodeStart":524,"sourceCodeEnd":560,"githubUrl":"https://github.com/zed-industries/zed/blob/bc538def4545534201bbfcac4e95ac34ea6501b6/crates/anthropic/src/completion.rs#L524-L560","documentation":"Raised inside the Anthropic streaming state machine. Compaction blocks are registered in compactions_by_index when their content_block_start event arrives; a CompactionDelta for an index with no registered block means the SSE stream is malformed (delta before block start), so the adapter errors instead of writing into a missing block.","triggerScenarios":"A content_block_delta carrying ContentDelta::CompactionDelta arrives for an index whose content_block_start was never seen - dropped or reordered SSE events, a proxy rewriting the stream, or an upstream regression in Anthropic's compaction feature.","commonSituations":"Long-context compaction/summarization sessions on Claude; corporate proxies or LLM gateways that buffer, chunk, or reorder server-sent events; flaky connections that drop early frames.","solutions":["Retry the request - transient stream corruption usually replays cleanly on a fresh stream.","Remove or reconfigure proxies/gateways in front of api.anthropic.com so SSE events arrive unmodified and in order.","If reproducible with the official Anthropic SDK, capture raw SSE frames (request id, model, timestamps) and report to Anthropic.","Temporarily disable context compaction/summarization in the client so compaction deltas are not produced."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"while polling the completion stream, match Err(LanguageModelCompletionError::Other(e)) where e.to_string() contains \"compaction delta before starting\": discard partial state and re-issue the request once (bounded single retry); otherwise propagate.","preventionTips":["Keep SSE connections unbuffered end-to-end (disable proxy buffering)","Pin a known-good base URL for api.anthropic.com","Record and replay stream fixtures covering compaction blocks in tests"],"tags":["anthropic","streaming","sse","compaction","malformed-response"],"backgroundTag":null,"analyzedSha":"bc538def4545534201bbfcac4e95ac34ea6501b6","analyzedAt":"2026-08-16T07:30:46.435Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}