alibaba/open-code-review · error

enumerate files: %w

Error message

enumerate files: %w

What it means

Agent.Run wraps a failure from the file provider's Enumerate with 'enumerate files: %w'. Enumerate walks the repo paths (via git and filesystem) to produce the candidate file list; any failure there (git command failure, unreadable path, repository problems) surfaces under this prefix after the telemetry span is closed.

Source

Thrown at internal/scan/agent.go:319

// dispatch one subtask per file → collect comments.
func (a *Agent) Run(ctx context.Context) ([]model.LlmComment, error) {
	if len(a.args.Template.MainTask.Messages) == 0 {
		return nil, fmt.Errorf("scan template MAIN_TASK is missing or empty")
	}

	// Base prompt-cache affinity key for any LLM request in this run that a
	// task doesn't re-scope. Each task conversation (plan, per-file main
	// loop, dedup, summary) refines it with llm.SessionTaskKey where it
	// starts, so affinity keys stay per-conversation — the granularity
	// provider prompt caches actually reuse prefixes at.
	ctx = llm.ContextWithSessionKey(ctx, a.SessionID())

	ctx, scanSpan := telemetry.StartSpan(ctx, "scan.enumerate")
	provider := NewProvider(a.args.RepoDir, a.args.Paths, a.args.GitRunner, a.args.MaxFileSizeBytes)
	items, err := provider.Enumerate(ctx)
	if err != nil {
		scanSpan.End()
		return nil, fmt.Errorf("enumerate files: %w", err)
	}
	telemetry.SetAttr(scanSpan, "files.enumerated", len(items))
	scanSpan.End()

	a.items = items
	a.injectScanContentMap()
	a.args.Tools.Freeze()

	totalDiscovered := len(a.items)
	a.items = a.filterScanItems(a.items)
	a.items = a.filterLargeScans(a.items)

	reviewable := len(a.items)
	fmt.Fprintf(stdout.Writer(), "[ocr] full-scan: %d file(s) discovered, reviewing %d in %s\n",
		totalDiscovered, reviewable, a.args.RepoDir)

	if reviewable == 0 {
		fmt.Fprintln(stdout.Writer(), "[ocr] No reviewable files. Skipping scan.")

View on GitHub (pinned to 5cf97d0d15)

Solutions

  1. Run from (or point --repo-dir at) a valid git working tree and confirm `git status` works there
  2. Check each supplied path exists and is readable; fix typos or remove stale paths
  3. Ensure the git binary is installed and on PATH in the execution environment (especially CI containers)

Example fix

// before
ocr review --paths ./src_old
// after — path renamed
ocr review --paths ./src
Defensive patterns

Strategy: try-catch

Validate before calling

// verify repo and paths before scanning
if _, err := os.Stat(filepath.Join(repoDir, ".git")); err != nil {
    return fmt.Errorf("%s is not a git repository", repoDir)
}
for _, p := range paths {
    if _, err := os.Stat(p); err != nil {
        return fmt.Errorf("path %q does not exist", p)
    }
}

Try / catch

comments, err := agent.Run(ctx)
if err != nil {
    var enumErr error
    if strings.Contains(err.Error(), "enumerate files") {
        errors.As(err, &enumErr) // inspect wrapped git/fs cause; fix repo or paths
    }
}

Prevention

When it happens

Trigger: provider.Enumerate(ctx) returns an error: the git runner fails (not a git repo, git binary missing, corrupt index), a supplied --paths entry does not exist or is unreadable, or filesystem traversal hits a permission error.

Common situations: Running ocr outside a git repository; specifying a path that was deleted or renamed; running in a CI checkout with submodules not initialized; insufficient read permissions on a target directory.

Related errors


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