alibaba/open-code-review · error

load diffs: %w

Error message

load diffs: %w

What it means

ResolveIdentity wraps any failure from Agent.loadDiffs with the 'load diffs:' prefix while computing the pre-flight identity for a review run. loadDiffs runs git to obtain the diff the review would analyze; if git fails (bad ref, missing repo, plumbing errors), the resume/admission flow aborts before any session is created. The wrapped error preserves the underlying git cause.

Source

Thrown at internal/agent/identity.go:58

//
// Those filter passes are chatty, and the review that follows in the same
// command prints them again, so this stays silent. stdout.Quiet is safe here for
// the reason it documents: this is pre-flight work on the main goroutine, before
// any concurrent output exists.
func ResolveIdentity(ctx context.Context, args Args) (*SealedInput, error) {
	defer stdout.Quiet()()

	resolution, err := resolveInputBeforeDiff(ctx, args)
	if err != nil {
		return nil, err
	}
	if resolution != nil {
		args.SealedInput = resolution
	}

	a := &Agent{args: args}
	if err := a.loadDiffs(ctx); err != nil {
		return nil, fmt.Errorf("load diffs: %w", err)
	}
	a.diffs = a.filterDiffs(a.diffs)
	a.diffs = a.filterLargeDiffs(a.diffs)
	return &SealedInput{Identity: a.runIdentity(), Resolution: a.inputResolution}, nil
}

// resolveInputBeforeDiff turns every moving head ref into an immutable commit
// before the diff used for admission is loaded. Range mode then computes its
// merge-base against that frozen head; commit mode needs only the frozen head.
func resolveInputBeforeDiff(ctx context.Context, args Args) (*diff.InputResolution, error) {
	switch {
	case args.Commit != "":
		head, err := resolveCommitHead(ctx, args, args.Commit)
		if err != nil {
			return nil, err
		}
		return &diff.InputResolution{ResolvedHead: head}, nil
	case args.From != "" && args.To != "":

View on GitHub (pinned to 5cf97d0d15)

Solutions

  1. Run 'git rev-parse <ref>' in RepoDir for each ref in args to confirm they resolve before calling ResolveIdentity
  2. Verify args.RepoDir is a valid git work tree ('git rev-parse --is-inside-work-tree')
  3. Inspect the wrapped underlying error for the exact git failure (e.g. unknown revision)
  4. For shallow clones, unshallow or fetch the missing commits before resolving
  5. Confirm the uncommitted-sha / commit mode selection matches what the repo actually contains

Example fix

// before
sealed, err := agent.ResolveIdentity(ctx, args)
// after: pre-validate refs
if out, err := git(args.RepoDir, "rev-parse", "--verify", args.From+"^{commit}"); err != nil {
    return fmt.Errorf("bad ref %s: %w", args.From, err)
}
sealed, err := agent.ResolveIdentity(ctx, args)
Defensive patterns

Strategy: validation

Validate before calling

func canLoadDiffs(repoDir, from, to string) error {
    if err := execGit(repoDir, "rev-parse", "--is-inside-work-tree"); err != nil {
        return fmt.Errorf("not a git repo: %w", err)
    }
    for _, ref := range []string{from, to} {
        if ref == "" { continue }
        if err := execGit(repoDir, "rev-parse", "--verify", ref+"^{commit}"); err != nil {
            return fmt.Errorf("unresolvable ref %q: %w", ref, err)
        }
    }
    return nil
}

Try / catch

sealed, err := agent.ResolveIdentity(ctx, args)
if err != nil {
    var loadErr error
    if errors.As(err, &loadErr) && strings.Contains(err.Error(), "load diffs:") {
        return fmt.Errorf("cannot admit run: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: Calling agent.ResolveIdentity with Args whose RepoDir is not a git repository, whose From/To/Commit refs do not exist, or when the underlying git command (via GitRunner) fails during diff parsing (e.g. empty or corrupt repo, network fetch failure for remote refs).

Common situations: CI checking out a shallow clone missing the target commit; typo'd branch or SHA in --from/--to; running outside a git work tree; refs deleted between push and review (force-push).

Related errors


AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02). Data as JSON: /api/errors/526ca5315631e6e6. Report an issue: GitHub.