{"record":{"id":"e776666c6020f4dc","repo":"gitbutlerapp/gitbutler","slug":"the-model-returned-a-resolution-for-which-wa","errorCode":null,"errorMessage":"The model returned a resolution for \"{}\", which was not requested","messagePattern":"The model returned a resolution for \"(.+?)\", which was not requested","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-api/src/resolve/mod.rs","lineNumber":619,"sourceCode":"        );\n        attempt()\n    })\n}\n\n/// Check the model response against the request and translate it into\n/// 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            );","sourceCodeStart":601,"sourceCodeEnd":637,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-api/src/resolve/mod.rs#L601-L637","documentation":"`validate_ai_response` rejects an AI resolution response that references a file path not present in the request. Paths are normalized and looked up in `files_by_path`; an unknown path means the model hallucinated or reformatted a filename, so the whole response is invalid and nothing is applied.","triggerScenarios":"Calling `resolve_ai_specs` or `resolve_commit_conflicts_with` where the model's response contains a `resolution.path` whose normalized form has no entry in the request's `request.files`.","commonSituations":"The model invents a path, uses a different separator or casing, adds a repo prefix (e.g. `src/` when the request used a bare name), or resolves a stale commit after the user changed conflicts.","solutions":["Retry the AI request once (the API already retries invalid responses once) with the exact requested file paths echoed in the prompt","Normalize the model output paths before validation (trim prefixes, unify separators)","Constrain the model with a strict JSON schema enumerating the allowed paths"],"exampleFix":"// before\nresolutions: [{ path: 'src/' + file.path, hunks: [...] }]\n// after\nresolutions: [{ path: file.path, hunks: [...] }] // path exactly as listed in request.files","handlingStrategy":"validation","validationCode":"const allowed = new Set(request.files.map(f => normalizePath(f.path)));\nfor (const r of response.resolutions) {\n  if (!allowed.has(normalizePath(r.path))) throw new Error('unexpected path: ' + r.path);\n}","typeGuard":"const isKnownPath = (p: string, files: ResolvedFile[]) =>\n  files.some(f => normalizePath(f.path) === normalizePath(p));","tryCatchPattern":"try {\n  await api.resolveAiSpecs(ctx, commitId, specs);\n} catch (e) {\n  if (e.message.includes('which was not requested')) retryWithPromptReinforcement();\n}","preventionTips":["Echo exact requested paths in the prompt and require verbatim reuse","Normalize paths (separators, prefixes, casing) before comparing","Use a JSON schema that enumerates allowed path values"],"tags":["ai","validation","response-validation"],"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"}