gitbutlerapp/gitbutler · error
The model returned resolved hunks for " " but the file has…
Error message
The model returned {} resolved hunks for "{}" but the file has {} conflicts What it means
`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.
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
Example fix
// before
hunks: [mergeConflicts(file.hunks)] // 1 hunk for 3 conflicts
// after
hunks: file.hunks.map(h => ({ resolvedContent: resolve(h) })) // one per conflict Defensive patterns
Strategy: validation
Validate before calling
for (const r of response.resolutions) {
const f = request.files.find(f => normalizePath(f.path) === normalizePath(r.path));
if (f && r.hunks.length !== f.hunks.length) throw new Error('hunk count mismatch for ' + f.path);
} Type guard
null
Try / catch
try {
await api.resolveAiSpecs(ctx, commitId, specs);
} catch (e) {
if (/but the file has \d+ conflicts/.test(e.message)) retryWithPerHunkInstructions();
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Enter an Anthropic API key
- Enter an OpenAI API key
- is required
- Invalid prompt: must be a non-empty array
- The model returned a resolution for
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/589cda660eab9081.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but-api/src/resolve/mod.rs:632
let mut picks: apply::PicksPerFile = vec![BTreeMap::new(); request.files.len()];
let mut resolved_files: Vec<Option<ResolvedFile>> = vec![None; request.files.len()];
for resolution in &response.resolutions {
let Some(&index) = files_by_path.get(&apply::normalize_path(&resolution.path)) else {
bail!(
"The model returned a resolution for \"{}\", which was not requested",
resolution.path
);
};
if resolved_files[index].is_some() {
bail!(
"The model returned more than one resolution for \"{}\"",
resolution.path
);
}
let file = &request.files[index];
if resolution.hunks.len() != file.hunks.len() {
bail!(
"The model returned {} resolved hunks for \"{}\" but the file has {} conflicts",
resolution.hunks.len(),
file.path,
file.hunks.len()
);
}
if resolution.reasoning.trim().is_empty() {
bail!("The model returned no reasoning for \"{}\"", file.path);
}
for (hunk_index, hunk) in resolution.hunks.iter().enumerate() {
apply::ensure_no_markers(&hunk.resolved_content, &file.path)?;
picks[index].insert(
hunk_index,
apply::HunkPick::Content(hunk.resolved_content.clone()),
);
}
resolved_files[index] = Some(ResolvedFile {
path: file.path.clone(),View on GitHub (pinned to 58e5313667)