alibaba/open-code-review · error
resolve commit %q
Error message
resolve commit %q
What it means
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.
Source
Thrown at internal/agent/identity.go:98
}
head, err := resolveCommitHead(ctx, args, args.To)
if err != nil {
return nil, err
}
resolved := diff.NewProvider(args.RepoDir, from, head, args.GitRunner).ResolveInput(ctx)
if resolved.ResolvedBase == "" {
return nil, fmt.Errorf("resolve merge-base between %q and %q", args.From, args.To)
}
return &resolved, nil
default:
return nil, nil
}
}
func resolveCommitHead(ctx context.Context, args Args, ref string) (string, error) {
head := diff.NewCommitProvider(args.RepoDir, ref, args.GitRunner).ResolveInput(ctx).ResolvedHead
if head == "" {
return "", fmt.Errorf("resolve commit %q", ref)
}
return head, nil
}
// runIdentity reads the identity off the agent's current selection.
//
// It is only meaningful once the selection is final: sourceArtifactSHA256 hashes
// whatever a.diffs holds, so calling it before both filter passes yields a digest
// no run ever records, and a resume comparing that digest against a parent
// manifest would reject work it should have reused.
func (a *Agent) runIdentity() session.RunIdentity {
id := session.RunIdentity{
Mode: a.manifestMode(),
SourceArtifactSHA256: a.sourceArtifactSHA256(),
RuleConfigSHA256: a.ruleConfigSHA256(),
}
if raw := a.repoRemoteIdentity; raw != "" {
sum := sha256.Sum256([]byte(raw))View on GitHub (pinned to 5cf97d0d15)
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
Example fix
// before head, err := resolveCommitHead(ctx, args, args.To) // fails: 'origin/main' not fetched // after: fetch first runGit(args.RepoDir, "fetch", "origin", args.To) head, err := resolveCommitHead(ctx, args, args.To)
Defensive patterns
Strategy: validation
Validate before calling
func refExists(repoDir, ref string) bool {
return execGit(repoDir, "rev-parse", "--verify", ref+"^{commit}") == nil
}
// guard:
if !refExists(args.RepoDir, args.To) { return fmt.Errorf("ref %q not found; fetch first", args.To) } Try / catch
head, err := resolveCommitHead(ctx, args, ref)
if err != nil {
if execErr := runGit(args.RepoDir, "fetch", "origin", ref); execErr == nil {
head, err = resolveCommitHead(ctx, args, ref)
}
if err != nil { return fmt.Errorf("cannot resolve %q: %w", ref, err) }
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- resolve current input identity: %w
- load diffs: %w
- resume rejected: repository identity changed, so this is not
- resume rejected: the reviewed input changed since session %q
- preview failed: %w
AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02).
Data as JSON: /api/errors/843a151b5488b46e.
Report an issue: GitHub.