{"record":{"id":"09d51cff704d799f","repo":"alibaba/open-code-review","slug":"scan-template-main-task-is-missing-or-empty","errorCode":null,"errorMessage":"scan template MAIN_TASK is missing or empty","messagePattern":"scan template MAIN_TASK is missing or empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/scan/agent.go","lineNumber":304,"sourceCode":"}\n\nfunc scanItemFingerprint(it model.ScanItem) string {\n\tsum := sha256.Sum256([]byte(session.ReviewModeFullScan + \"\\x00\" + it.Path + \"\\x00\" + it.Content))\n\treturn fmt.Sprintf(\"%x\", sum)\n}\n\nfunc resumedFromSession(resume *session.ResumeState) string {\n\tif resume == nil {\n\t\treturn \"\"\n\t}\n\treturn resume.SessionID\n}\n\n// Run executes the full-scan pipeline: enumerate → filter → token-filter →\n// dispatch one subtask per file → collect comments.\nfunc (a *Agent) Run(ctx context.Context) ([]model.LlmComment, error) {\n\tif len(a.args.Template.MainTask.Messages) == 0 {\n\t\treturn nil, fmt.Errorf(\"scan template MAIN_TASK is missing or empty\")\n\t}\n\n\t// Base prompt-cache affinity key for any LLM request in this run that a\n\t// task doesn't re-scope. Each task conversation (plan, per-file main\n\t// loop, dedup, summary) refines it with llm.SessionTaskKey where it\n\t// starts, so affinity keys stay per-conversation — the granularity\n\t// provider prompt caches actually reuse prefixes at.\n\tctx = llm.ContextWithSessionKey(ctx, a.SessionID())\n\n\tctx, scanSpan := telemetry.StartSpan(ctx, \"scan.enumerate\")\n\tprovider := NewProvider(a.args.RepoDir, a.args.Paths, a.args.GitRunner, a.args.MaxFileSizeBytes)\n\titems, err := provider.Enumerate(ctx)\n\tif err != nil {\n\t\tscanSpan.End()\n\t\treturn nil, fmt.Errorf(\"enumerate files: %w\", err)\n\t}\n\ttelemetry.SetAttr(scanSpan, \"files.enumerated\", len(items))\n\tscanSpan.End()","sourceCodeStart":286,"sourceCodeEnd":322,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/internal/scan/agent.go#L286-L322","documentation":"Agent.Run refuses to start the full-scan pipeline when the scan template's MAIN_TASK prompt has no messages. The MAIN_TASK template drives the per-file review loop, so an empty template means the scan cannot produce meaningful requests; the error fails fast before any enumeration or LLM calls.","triggerScenarios":"Running a scan where the resolved scan template (built-in or custom via template config) has an empty or missing MAIN_TASK section — e.g. a custom template file defining only other task keys, or a template path pointing at the wrong file.","commonSituations":"Pointing --template/custom template config at a file that defines PLAN_TASK/DEDUP_TASK but omits MAIN_TASK; an older template format after an OCR upgrade renamed the key; an empty template file created by mistake.","solutions":["Provide a template whose MAIN_TASK section defines at least one message, or drop the custom template override to use the built-in default","Check the template key spelling — it must be MAIN_TASK (uppercase) with a non-empty messages list","Regenerate/refresh a custom template that was authored against an older OCR version"],"exampleFix":"# before (custom template)\n[PLAN_TASK]\nmessages = [...]\n# after — add the required section\n[MAIN_TASK]\nmessages = [{ role = \"user\", content = \"Review this file: {{.Content}}\" }]","handlingStrategy":"validation","validationCode":"// validate the template before running the scan\nif len(args.Template.MainTask.Messages) == 0 {\n    return fmt.Errorf(\"custom template must define a non-empty MAIN_TASK section\")\n}","typeGuard":null,"tryCatchPattern":"comments, err := agent.Run(ctx)\nif err != nil && strings.Contains(err.Error(), \"MAIN_TASK is missing or empty\") {\n    // fall back to the built-in template or fix the custom template file\n}","preventionTips":["When supplying a custom template, always include MAIN_TASK with at least one message","Re-validate custom templates after OCR upgrades in case keys changed","Smoke-test custom templates on a single-file scan before full runs"],"tags":["config","template","scan","prompt"],"backgroundTag":"missing-template-section","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}