{"record":{"id":"77c52460c72509fb","repo":"zed-industries/zed","slug":"no-expected-patch-hunks-found-in-response","errorCode":null,"errorMessage":"No expected patch hunks found in response","messagePattern":"No expected patch hunks found in response","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/edit_prediction_cli/src/synthesize.rs","lineNumber":591,"sourceCode":"    // Parse ANALYSIS section (Claude's planning) - this is the primary reasoning\n    let reasoning = extract_section(\n        response,\n        \"ANALYSIS:\",\n        &[\"NAME:\", \"REASONING:\", \"EDIT_HISTORY:\", \"EXPECTED_PATCH:\"],\n    )\n    .unwrap_or_default();\n\n    // Parse EDIT_HISTORY diff block\n    let edit_history_hunks = extract_diff_block(response, \"EDIT_HISTORY:\")?;\n\n    // Parse EXPECTED_PATCH diff block\n    let expected_patch_hunks = extract_diff_block(response, \"EXPECTED_PATCH:\")?;\n\n    if edit_history_hunks.is_empty() {\n        anyhow::bail!(\"No edit history hunks found in response\");\n    }\n    if expected_patch_hunks.is_empty() {\n        anyhow::bail!(\"No expected patch hunks found in response\");\n    }\n\n    Ok(Some(ClaudeResponse {\n        name,\n        reasoning,\n        edit_history_hunks,\n        expected_patch_hunks,\n    }))\n}\n\nfn extract_section(text: &str, start_marker: &str, end_markers: &[&str]) -> Option<String> {\n    let start_idx = text.find(start_marker)?;\n    let content_start = start_idx + start_marker.len();\n\n    let end_idx = end_markers\n        .iter()\n        .filter_map(|marker| text[content_start..].find(marker))\n        .min()","sourceCodeStart":573,"sourceCodeEnd":609,"githubUrl":"https://github.com/zed-industries/zed/blob/f4178619acd0d47ea1f76a2025c42962c6d6638c/crates/edit_prediction_cli/src/synthesize.rs#L573-L609","documentation":"Bailed while parsing the Claude-style generation response in synthesize: the `EXPECTED_PATCH:` section was missing or contained no parseable fenced diff block. This is the second half of the two-block contract — EDIT_HISTORY may have parsed fine, but without an expected-patch diff the example cannot be validated.","triggerScenarios":"The model stops after the EDIT_HISTORY block, omits EXPECTED_PATCH, or wraps it without a fenced code block; truncation by max output tokens commonly cuts off this final section first.","commonSituations":"Token-limit truncation of long generations; models summarizing the expected patch in prose instead of a diff; format drift.","solutions":["Inspect the raw response — if it ends mid-diff, raise max output tokens and regenerate","Retry the generation; emphasize in the prompt that EXPECTED_PATCH must be a fenced diff","Include a complete two-block example in the prompt so the model anchors on the format"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if !response.contains(\"EXPECTED_PATCH:\") || !has_fenced_block_after(response, \"EXPECTED_PATCH:\") {\n    // regenerate before attempting to parse\n}","typeGuard":null,"tryCatchPattern":"Catch the parse error, keep the raw text, retry with a corrective prompt mentioning the missing EXPECTED_PATCH diff; treat persistent failures as bad samples.","preventionTips":["Budget max tokens for the longest section (EXPECTED_PATCH comes last and truncates first)","State in the prompt that both blocks are mandatory","Monitor parse-failure rates per model to catch format drift early"],"tags":["llm-parsing","synthesize","edit-prediction","rust"],"backgroundTag":"llm-response-parse-failed","analyzedSha":"f4178619acd0d47ea1f76a2025c42962c6d6638c","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}