{"record":{"id":"589cda660eab9081","repo":"gitbutlerapp/gitbutler","slug":"the-model-returned-resolved-hunks-for-but","errorCode":null,"errorMessage":"The model returned {} resolved hunks for \"{}\" but the file has {} conflicts","messagePattern":"The model returned (.+?) resolved hunks for \"(.+?)\" but the file has (.+?) conflicts","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-api/src/resolve/mod.rs","lineNumber":632,"sourceCode":"    let mut picks: apply::PicksPerFile = vec![BTreeMap::new(); request.files.len()];\n    let mut resolved_files: Vec<Option<ResolvedFile>> = vec![None; request.files.len()];\n\n    for resolution in &response.resolutions {\n        let Some(&index) = files_by_path.get(&apply::normalize_path(&resolution.path)) else {\n            bail!(\n                \"The model returned a resolution for \\\"{}\\\", which was not requested\",\n                resolution.path\n            );\n        };\n        if resolved_files[index].is_some() {\n            bail!(\n                \"The model returned more than one resolution for \\\"{}\\\"\",\n                resolution.path\n            );\n        }\n        let file = &request.files[index];\n        if resolution.hunks.len() != file.hunks.len() {\n            bail!(\n                \"The model returned {} resolved hunks for \\\"{}\\\" but the file has {} conflicts\",\n                resolution.hunks.len(),\n                file.path,\n                file.hunks.len()\n            );\n        }\n        if resolution.reasoning.trim().is_empty() {\n            bail!(\"The model returned no reasoning for \\\"{}\\\"\", file.path);\n        }\n        for (hunk_index, hunk) in resolution.hunks.iter().enumerate() {\n            apply::ensure_no_markers(&hunk.resolved_content, &file.path)?;\n            picks[index].insert(\n                hunk_index,\n                apply::HunkPick::Content(hunk.resolved_content.clone()),\n            );\n        }\n        resolved_files[index] = Some(ResolvedFile {\n            path: file.path.clone(),","sourceCodeStart":614,"sourceCodeEnd":650,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-api/src/resolve/mod.rs#L614-L650","documentation":"`validate_ai_response` requires the model to resolve every conflict hunk in a file; the count of returned hunks must equal `file.hunks.len()`. A mismatch means the model skipped or split conflicts, so the resolution is rejected.","triggerScenarios":"A resolution for file `f` has `resolution.hunks.len() != file.hunks.len()` during `resolve_ai_specs` or `resolve_commit_conflicts_with` — e.g. the model returned 1 hunk for a file with 3 conflict regions.","commonSituations":"The model merges adjacent conflicts into one block; it omits hunks it considers trivial; the request was built against a different version of the commit than the one the model saw.","solutions":["Retry the AI request, emphasizing one resolved block per conflict hunk in order","Regenerate the request so hunks and the response are aligned to the same commit state","Fall back to manual/edit-mode resolution for files with many conflict regions"],"exampleFix":"// before\nhunks: [mergeConflicts(file.hunks)] // 1 hunk for 3 conflicts\n// after\nhunks: file.hunks.map(h => ({ resolvedContent: resolve(h) })) // one per conflict","handlingStrategy":"validation","validationCode":"for (const r of response.resolutions) {\n  const f = request.files.find(f => normalizePath(f.path) === normalizePath(r.path));\n  if (f && r.hunks.length !== f.hunks.length) throw new Error('hunk count mismatch for ' + f.path);\n}","typeGuard":"null","tryCatchPattern":"try {\n  await api.resolveAiSpecs(ctx, commitId, specs);\n} catch (e) {\n  if (/but the file has \\d+ conflicts/.test(e.message)) retryWithPerHunkInstructions();\n}","preventionTips":["Instruct the model to return exactly one resolved hunk per conflict, in order","Validate hunk counts before applying resolutions","Regenerate the request when the commit's conflict set changes"],"tags":["ai","validation","hunk-count"],"backgroundTag":"shape-mismatch","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}