{"record":{"id":"6ff45b6fe764ab24","repo":"gitbutlerapp/gitbutler","slug":"the-model-returned-more-than-one-resolution-for","errorCode":null,"errorMessage":"The model returned more than one resolution for \"{}\"","messagePattern":"The model returned more than one resolution for \"(.+?)\"","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-api/src/resolve/mod.rs","lineNumber":625,"sourceCode":"/// full-coverage picks plus the per-file display payload. Any mismatch fails\n/// validation so the caller can retry the model once before giving up.\nfn validate_ai_response(\n    request: &ResolutionRequest,\n    response: &ResolutionResponse,\n) -> anyhow::Result<(apply::PicksPerFile, Vec<ResolvedFile>)> {\n    let files_by_path = apply::index_files_by_path(request)?;\n    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)?;","sourceCodeStart":607,"sourceCodeEnd":643,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-api/src/resolve/mod.rs#L607-L643","documentation":"`validate_ai_response` rejects responses containing two resolutions for the same conflicted file. Each requested file may be resolved at most once; a duplicate means ambiguous content to apply, so validation fails.","triggerScenarios":"An AI model returns a `response.resolutions` array with two entries whose normalized `path` maps to the same index in `request.files`, when passed through `resolve_ai_specs` or `resolve_commit_conflicts_with`.","commonSituations":"The model emits one resolution per hunk-group plus a whole-file resolution; prompt changes cause duplicated JSON objects; a retried request's outputs are concatenated.","solutions":["Deduplicate resolutions by normalized path before submitting/validating, keeping the last or best entry","Instruct the model to emit exactly one resolution per conflicted file and validate with a schema that enforces uniqueness","Retry the request once if the API's single retry does not clear it"],"exampleFix":"// before\nconst resolutions = [...partial, ...full]; // same path twice\n// after\nconst unique = new Map(resolutions.map(r => [normalizePath(r.path), r]));\nresponse.resolutions = [...unique.values()];","handlingStrategy":"validation","validationCode":"const seen = new Set();\nfor (const r of response.resolutions) {\n  const k = normalizePath(r.path);\n  if (seen.has(k)) throw new Error('duplicate resolution for ' + r.path);\n  seen.add(k);\n}","typeGuard":"null","tryCatchPattern":"try {\n  await api.resolveCommitConflictsWith(ctx, commitId, specs);\n} catch (e) {\n  if (e.message.includes('more than one resolution')) dedupeAndRetryOnce();\n}","preventionTips":["Deduplicate model output by path before applying","Prompt for exactly one resolution per file","Never concatenate outputs from multiple model attempts"],"tags":["ai","validation","duplicate"],"backgroundTag":"unexpected-response-shape","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"}