zed-industries/zed · error

No expected patch hunks found in response

Error message

No expected patch hunks found in response

What it means

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.

Source

Thrown at crates/edit_prediction_cli/src/synthesize.rs:591

    // Parse ANALYSIS section (Claude's planning) - this is the primary reasoning
    let reasoning = extract_section(
        response,
        "ANALYSIS:",
        &["NAME:", "REASONING:", "EDIT_HISTORY:", "EXPECTED_PATCH:"],
    )
    .unwrap_or_default();

    // Parse EDIT_HISTORY diff block
    let edit_history_hunks = extract_diff_block(response, "EDIT_HISTORY:")?;

    // Parse EXPECTED_PATCH diff block
    let expected_patch_hunks = extract_diff_block(response, "EXPECTED_PATCH:")?;

    if edit_history_hunks.is_empty() {
        anyhow::bail!("No edit history hunks found in response");
    }
    if expected_patch_hunks.is_empty() {
        anyhow::bail!("No expected patch hunks found in response");
    }

    Ok(Some(ClaudeResponse {
        name,
        reasoning,
        edit_history_hunks,
        expected_patch_hunks,
    }))
}

fn extract_section(text: &str, start_marker: &str, end_markers: &[&str]) -> Option<String> {
    let start_idx = text.find(start_marker)?;
    let content_start = start_idx + start_marker.len();

    let end_idx = end_markers
        .iter()
        .filter_map(|marker| text[content_start..].find(marker))
        .min()

View on GitHub (pinned to f4178619ac)

Solutions

  1. Inspect the raw response — if it ends mid-diff, raise max output tokens and regenerate
  2. Retry the generation; emphasize in the prompt that EXPECTED_PATCH must be a fenced diff
  3. Include a complete two-block example in the prompt so the model anchors on the format
Defensive patterns

Strategy: retry

Validate before calling

if !response.contains("EXPECTED_PATCH:") || !has_fenced_block_after(response, "EXPECTED_PATCH:") {
    // regenerate before attempting to parse
}

Try / catch

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.

Prevention

When it happens

Trigger: 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.

Common situations: Token-limit truncation of long generations; models summarizing the expected patch in prose instead of a diff; format drift.

Related errors


AI-assisted analysis of zed-industries/zed@f4178619ac (2026-08-20). Data as JSON: /api/errors/77c52460c72509fb. Report an issue: GitHub.