{"record":{"id":"383309c1f30c7d6e","repo":"alibaba/open-code-review","slug":"all-d-file-scan-s-failed-check-your-llm-config","errorCode":null,"errorMessage":"all %d file scan(s) failed — check your LLM configuration and API key","messagePattern":"all (.+?) file scan\\(s\\) failed — check your LLM configuration and API key","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/scan/agent.go","lineNumber":573,"sourceCode":"\t\t// CommentWorkerPool.Await is cumulative across batches - that is fine\n\t\t// since batches are sequential here.\n\t\tif a.args.CommentWorkerPool != nil {\n\t\t\ta.args.CommentWorkerPool.Await()\n\t\t}\n\n\t\tdedupCheckpoints := a.maybeRunDedup(ctx, bi, batchStart)\n\t\ta.recordBatchCheckpoints(checkpoints, batchStart, dedupCheckpoints)\n\n\t\t// The per-file budget gate inside dispatchBatch tripped — stop\n\t\t// scheduling any remaining batches.\n\t\tif budgetHit {\n\t\t\tbreak\n\t\t}\n\t}\n\n\tfailed := atomic.LoadInt64(&a.subtaskFailed)\n\tif failed > 0 && failed == dispatched {\n\t\treturn nil, fmt.Errorf(\"all %d file scan(s) failed — check your LLM configuration and API key\", dispatched)\n\t}\n\treturn a.args.CommentCollector.Comments(), nil\n}\n\ntype batchCheckpoint struct {\n\titem             model.ScanItem\n\treused           bool\n\toriginalComments []model.LlmComment\n}\n\n// recordBatchCheckpoints persists safe per-file comments after batch dedup.\n// New same-file groups use the canonical result. Reused items keep their source\n// checkpoint, and cross-file groups keep raw per-file comments so invalidating\n// one file cannot erase another file's finding on resume.\nfunc (a *Agent) recordBatchCheckpoints(\n\tcheckpoints []batchCheckpoint,\n\tbatchStart int,\n\tdedupCheckpoints map[string][]model.LlmComment,","sourceCodeStart":555,"sourceCodeEnd":591,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/internal/scan/agent.go#L555-L591","documentation":"dispatchSubtasks in the scan Agent fans out per-file scan subtasks and counts failures in a.subtaskFailed. When every dispatched file scan failed (failed == dispatched > 0), it aborts with this error instead of returning partial comments, since no file could be scanned. It points at LLM configuration because the dominant cause is every subtask failing auth/model setup.","triggerScenarios":"Agent.Run dispatched one or more file-scan subtasks and every single one returned an error (e.g. each subtask's LLM call failed with 401/404/network error), so atomic.LoadInt64(&a.subtaskFailed) equals the dispatched count.","commonSituations":"Invalid or missing API key, wrong base URL or model name in config, quota exhaustion, network/proxy outage, or all target files failing to read/scan due to encoding or permission problems.","solutions":["Verify the LLM API key is set and valid (run a trivial LLM call or check env var/config file).","Confirm the configured model name and base URL exist and are enabled for your account.","Check network/proxy reachability to the LLM endpoint (curl the endpoint).","Re-run the scan with fewer files or check per-subtask logs to find the underlying error each subtask reported."],"exampleFix":"// before: key not exported\nocr scan ./...\n// after\nexport LLM_API_KEY=sk-...\nocr scan ./...","handlingStrategy":"try-catch","validationCode":"if os.Getenv(\"LLM_API_KEY\") == \"\" {\n    return fmt.Errorf(\"LLM_API_KEY is not set; scan would fail for all files\")\n}\n// optionally: probe with a tiny completion before dispatching subtasks","typeGuard":"func allSubtasksFailed(failed, dispatched int64) bool {\n    return dispatched > 0 && failed == dispatched\n}","tryCatchPattern":"comments, err := agent.Run(ctx)\nif err != nil {\n    var cfgErr *ConfigError\n    if errors.As(err, &cfgErr) || strings.Contains(err.Error(), \"all\") && strings.Contains(err.Error(), \"scan(s) failed\") {\n        // stop; fix LLM config first — retrying won't help\n        return fmt.Errorf(\"fix LLM configuration: %w\", err)\n    }\n    return err\n}","preventionTips":["Validate the API key and model name in a preflight check before scanning.","Log each subtask's underlying error so root cause is visible, not just the aggregate.","Set sensible timeouts and retries per subtask to distinguish transient network blips from config errors.","Run a single-file scan first to validate configuration before batch runs."],"tags":["llm","scan","configuration"],"backgroundTag":"invalid-api-key","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}