{"record":{"id":"843a151b5488b46e","repo":"alibaba/open-code-review","slug":"resolve-commit-q","errorCode":null,"errorMessage":"resolve commit %q","messagePattern":"resolve commit %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/agent/identity.go","lineNumber":98,"sourceCode":"\t\t}\n\t\thead, err := resolveCommitHead(ctx, args, args.To)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tresolved := diff.NewProvider(args.RepoDir, from, head, args.GitRunner).ResolveInput(ctx)\n\t\tif resolved.ResolvedBase == \"\" {\n\t\t\treturn nil, fmt.Errorf(\"resolve merge-base between %q and %q\", args.From, args.To)\n\t\t}\n\t\treturn &resolved, nil\n\tdefault:\n\t\treturn nil, nil\n\t}\n}\n\nfunc resolveCommitHead(ctx context.Context, args Args, ref string) (string, error) {\n\thead := diff.NewCommitProvider(args.RepoDir, ref, args.GitRunner).ResolveInput(ctx).ResolvedHead\n\tif head == \"\" {\n\t\treturn \"\", fmt.Errorf(\"resolve commit %q\", ref)\n\t}\n\treturn head, nil\n}\n\n// runIdentity reads the identity off the agent's current selection.\n//\n// It is only meaningful once the selection is final: sourceArtifactSHA256 hashes\n// whatever a.diffs holds, so calling it before both filter passes yields a digest\n// no run ever records, and a resume comparing that digest against a parent\n// manifest would reject work it should have reused.\nfunc (a *Agent) runIdentity() session.RunIdentity {\n\tid := session.RunIdentity{\n\t\tMode:                 a.manifestMode(),\n\t\tSourceArtifactSHA256: a.sourceArtifactSHA256(),\n\t\tRuleConfigSHA256:     a.ruleConfigSHA256(),\n\t}\n\tif raw := a.repoRemoteIdentity; raw != \"\" {\n\t\tsum := sha256.Sum256([]byte(raw))","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/internal/agent/identity.go#L80-L116","documentation":"resolveCommitHead returns this when diff.CommitProvider.ResolveInput yields an empty ResolvedHead for the given ref, i.e. the ref could not be resolved to a commit SHA in the repository. It is raised while freezing moving head refs into immutable commits before the admission diff is loaded, and it names the offending ref in the message.","triggerScenarios":"args.Commit, args.From, or args.To is a ref that does not exist locally (unknown branch/tag/SHA, typo, or a commit only present on a remote in a shallow/partial clone), so ResolveInput cannot produce a head SHA.","commonSituations":"CI shallow checkouts missing the pushed commit; reviewing a branch name that was force-pushed/deleted; typos in SHAs; running before 'git fetch' in a worktree with stale refs.","solutions":["Confirm the ref resolves locally: 'git rev-parse --verify <ref>^{commit}'","Fetch the missing objects ('git fetch origin <ref>') or disable shallow clone in CI","Check for typos in the branch/tag/SHA passed via Args","If the ref may legitimately be absent, validate it before calling ResolveIdentity and surface a friendlier message"],"exampleFix":"// before\nhead, err := resolveCommitHead(ctx, args, args.To) // fails: 'origin/main' not fetched\n// after: fetch first\nrunGit(args.RepoDir, \"fetch\", \"origin\", args.To)\nhead, err := resolveCommitHead(ctx, args, args.To)","handlingStrategy":"validation","validationCode":"func refExists(repoDir, ref string) bool {\n    return execGit(repoDir, \"rev-parse\", \"--verify\", ref+\"^{commit}\") == nil\n}\n// guard:\nif !refExists(args.RepoDir, args.To) { return fmt.Errorf(\"ref %q not found; fetch first\", args.To) }","typeGuard":null,"tryCatchPattern":"head, err := resolveCommitHead(ctx, args, ref)\nif err != nil {\n    if execErr := runGit(args.RepoDir, \"fetch\", \"origin\", ref); execErr == nil {\n        head, err = resolveCommitHead(ctx, args, ref)\n    }\n    if err != nil { return fmt.Errorf(\"cannot resolve %q: %w\", ref, err) }\n}","preventionTips":["Verify refs with 'git rev-parse --verify <ref>^{commit}' before review","Fetch the pushed ref in CI before running reviews","Disable shallow clone or use 'git fetch --unshallow' for the range","Guard against force-push/deleted branches by pinning to SHAs early"],"tags":["git","ref-resolution","resume"],"backgroundTag":"git-ref-not-found","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}