{"record":{"id":"ca16a9763f676822","repo":"alibaba/open-code-review","slug":"background-file-q-must-not-contain-the-reserved-d","errorCode":null,"errorMessage":"background file %q must not contain the reserved delimiters %q or %q","messagePattern":"background file %q must not contain the reserved delimiters %q or %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/opencodereview/background_file.go","lineNumber":92,"sourceCode":"\tif info.Size() > maxBackgroundFileBytes {\n\t\treturn \"\", fmt.Errorf(\n\t\t\t\"background file %q is %d bytes, exceeding the maximum of %d bytes; please provide a smaller file\",\n\t\t\tpath, info.Size(), maxBackgroundFileBytes,\n\t\t)\n\t}\n\n\traw, err := os.ReadFile(path)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"read background file %q: %w\", path, err)\n\t}\n\n\tcleaned := sanitizeMarkdown(string(raw))\n\tif cleaned == \"\" {\n\t\treturn \"\", fmt.Errorf(\"background file %q is empty after sanitisation\", path)\n\t}\n\n\tif strings.Contains(cleaned, backgroundOpenTag) || strings.Contains(cleaned, backgroundCloseTag) {\n\t\treturn \"\", fmt.Errorf(\n\t\t\t\"background file %q must not contain the reserved delimiters %q or %q\",\n\t\t\tpath, backgroundOpenTag, backgroundCloseTag,\n\t\t)\n\t}\n\n\t// Enforce the limits on the cleaned content only: the wrapper delimiters add\n\t// overhead the user cannot control, so counting them would make the reported\n\t// character count misleading.\n\tif n := len([]rune(cleaned)); n > backgroundHardLimit {\n\t\treturn \"\", fmt.Errorf(\n\t\t\t\"background content is %d characters, exceeding the hard limit of %d (aborting)\",\n\t\t\tn, backgroundHardLimit,\n\t\t)\n\t} else if n > backgroundSoftLimit {\n\t\tfmt.Fprintf(os.Stderr,\n\t\t\t\"[ocr] --background-file content is %d characters, exceeding the recommended %d (continuing but review quality might be impacted)\\n\",\n\t\t\tn, backgroundSoftLimit,\n\t\t)","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/cmd/opencodereview/background_file.go#L74-L110","documentation":"The background content is wrapped in the reserved delimiters <ocr_user_background> and </ocr_user_background> before being placed in the review prompt. If the user's own file already contains either tag, the wrapping would produce nested or spoofed delimiters that break prompt parsing. loadBackgroundFile rejects such files outright.","triggerScenarios":"`ocr review --background-file <path>` where the file text contains the literal string `<ocr_user_background>` or `</ocr_user_background>` anywhere after sanitisation.","commonSituations":"Reusing an OCR-generated prompt artifact as background input; documenting ocr's prompt format inside a background file; copy-pasting examples from OCR docs into the background file.","solutions":["Edit the file and remove or reword the literal `<ocr_user_background>` / `</ocr_user_background>` strings.","Escape by rephrasing, e.g. write 'the ocr user background tag' instead of the literal tag.","Move conflicting example content into a different document that is not passed as --background-file.","Pass the content inline with --background only after stripping the tags."],"exampleFix":"// before (background.md)\nExample: <ocr_user_background>your notes here</ocr_user_background>\n// after (background.md)\nExample: ocr-user-background tags wrap your notes; do not type them literally.","handlingStrategy":"validation","validationCode":"// Go: reject files containing the reserved delimiters before invoking ocr\nif strings.Contains(content, \"<ocr_user_background>\") || strings.Contains(content, \"</ocr_user_background>\") {\n\treturn fmt.Errorf(\"%s contains reserved ocr delimiters\", path)\n}","typeGuard":"func containsReservedDelimiter(s string) bool {\n\treturn strings.Contains(s, \"<ocr_user_background>\") || strings.Contains(s, \"</ocr_user_background>\")\n}","tryCatchPattern":"if err := runOcrReview(backgroundFile); err != nil {\n\tif strings.Contains(err.Error(), \"must not contain the reserved delimiters\") {\n\t\t// sanitize the file programmatically and retry once\n\t}\n}","preventionTips":["Never quote OCR's internal prompt tags in documentation you feed back as background.","Add a grep to your pipeline: `grep -q 'ocr_user_background' bg.md && exit 1` before running reviews.","Keep example prompt artifacts out of the repo's background directory."],"tags":["cli","input-validation","reserved-delimiter"],"backgroundTag":"reserved-delimiter-conflict","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}