{"record":{"id":"9cfceb943d0b839e","repo":"alibaba/open-code-review","slug":"load-diffs-w","errorCode":null,"errorMessage":"load diffs: %w","messagePattern":"load diffs: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/agent/agent.go","lineNumber":299,"sourceCode":"\t// so affinity keys stay per-conversation, the granularity provider prompt caches actually reuse prefixes at.\n\tctx = llm.ContextWithSessionKey(ctx, a.SessionID())\n\n\t// Step 1: Parse diffs\n\tctx, diffSpan := telemetry.StartSpan(ctx, \"diff.parse\")\n\tif err := a.loadDiffs(ctx); err != nil {\n\t\tdiffSpan.End()\n\t\t// The builder already exists (agent.New created session + manifest), but\n\t\t// no item was selected yet. Record the run-level input failure at this\n\t\t// trigger point, then finalize and persist so the run still emits a\n\t\t// session_end with a failed manifest instead of looking aborted.\n\t\tif b := a.session.Manifest(); b != nil {\n\t\t\t_ = b.SetRunFailure(session.RunFailureInput, \"failed to resolve review input\")\n\t\t}\n\t\tmanifestErr := a.finalizeManifest()\n\t\t// Keep the load failure as the primary cause, but never drop a persistence\n\t\t// failure: a run that could not even write its failed session_end must\n\t\t// report both rather than silently prefer one.\n\t\tloadErr := fmt.Errorf(\"load diffs: %w\", err)\n\t\tif ferr := a.session.Finalize(); ferr != nil {\n\t\t\tmanifestErr = errors.Join(manifestErr, fmt.Errorf(\"finalize session: %w\", ferr))\n\t\t}\n\t\tif manifestErr != nil {\n\t\t\treturn nil, errors.Join(loadErr, manifestErr)\n\t\t}\n\t\treturn nil, loadErr\n\t}\n\ttelemetry.SetAttr(diffSpan, \"files.changed\", len(a.diffs))\n\ttelemetry.SetAttr(diffSpan, \"lines.inserted\", int64(a.totalInsertions))\n\ttelemetry.SetAttr(diffSpan, \"lines.deleted\", int64(a.totalDeletions))\n\tdiffSpan.End()\n\n\t// Build the read-only DiffMap from ALL parsed diffs (before filtering)\n\t// so the LLM can query diffs of related but filtered-out files.\n\ta.injectDiffMap()\n\ta.args.Tools.Freeze()\n","sourceCodeStart":281,"sourceCodeEnd":317,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/internal/agent/agent.go#L281-L317","documentation":"Agent.Run in internal/agent/agent.go wraps a failure from a.loadDiffs (diff parsing) as 'load diffs: %w'. This is the step-1 failure of the review pipeline: the agent could not resolve the review input (parse diffs from git). Before returning, the agent records a run-level input failure in the session manifest and finalizes the session so a failed session_end is still persisted.","triggerScenarios":"Calling Agent.Run when loadDiffs fails — e.g. the configured base/ref produces no valid git diff, a git command error (bad ref, empty repo, detached state), or the diff source is unreadable. The wrapped cause (err) names the actual git/diff problem.","commonSituations":"Reviewing a PR branch that was force-pushed or deleted; running in a shallow clone missing the base commit; wrong --from/--to/--commit ref names; running outside a git repository.","solutions":["Fix the underlying git error shown by the wrapped cause (check the ref names exist: git rev-parse <ref>)","Run in a full clone (git fetch --unshallow) so the base commit is available","Verify you are in a git repository and the diff mode flags (--from/--to/--commit) are valid","Inspect the persisted session manifest for the RunFailureInput record"],"exampleFix":"// before (shallow clone in CI)\ngit clone --depth 1 repo && ocr review --from main\n// after\ngit clone repo && git fetch origin main && ocr review --from origin/main","handlingStrategy":"try-catch","validationCode":"git rev-parse --verify \"$FROM_REF\" && git rev-parse --verify \"$TO_REF\" || { echo \"ref missing\" >&2; exit 1; }\ngit rev-parse --is-inside-work-tree >/dev/null || exit 1","typeGuard":null,"tryCatchPattern":"comments, err := agent.Run(ctx)\nif err != nil {\n    var loadErr error\n    if errors.As(err, &loadErr) && strings.Contains(err.Error(), \"load diffs:\") {\n        // inspect wrapped cause with errors.Unwrap / %v for the git error\n        log.Fatalf(\"review input could not be loaded: %v\", err)\n    }\n    return err\n}","preventionTips":["Verify all refs (--from/--to/--commit) exist with git rev-parse before running","Avoid shallow clones when reviewing against a base branch","Run the CLI inside a git work tree","Check the session manifest's RunFailureInput record for diagnostics"],"tags":["git","diff","pipeline","agent"],"backgroundTag":"git-diff-load-failure","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}