{"record":{"id":"349d5e5040022301","repo":"alibaba/open-code-review","slug":"background-file-q-is-d-bytes-exceeding-the-maxi","errorCode":null,"errorMessage":"background file %q is %d bytes, exceeding the maximum of %d bytes; please provide a smaller file","messagePattern":"background file %q is (.+?) bytes, exceeding the maximum of (.+?) bytes; please provide a smaller file","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/opencodereview/background_file.go","lineNumber":75,"sourceCode":"\t}\n\tif inline == \"\" && commit != \"\" {\n\t\tif msg, err := getCommitMessage(repoDir, commit); err == nil && msg != \"\" {\n\t\t\treturn msg, nil\n\t\t}\n\t}\n\treturn inline, nil\n}\n\nfunc loadBackgroundFile(path string) (string, error) {\n\tinfo, err := os.Stat(path)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"read background file %q: %w\", path, err)\n\t}\n\tif info.IsDir() {\n\t\treturn \"\", fmt.Errorf(\"background file %q is a directory, not a file\", path)\n\t}\n\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\",","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/cmd/opencodereview/background_file.go#L57-L93","documentation":"loadBackgroundFile rejects files larger than maxBackgroundFileBytes, reporting the actual size and the cap. The background text is injected into the LLM prompt, so oversized files would blow the token budget; a smaller file is requested explicitly.","triggerScenarios":"Passing a background file whose os.Stat size exceeds maxBackgroundFileBytes to resolveBackground — e.g. a whole book-sized markdown document or a concatenated corpus.","commonSituations":"Dumping entire logs, generated docs, or a large wiki export as background; concatenating many files into one background document; raising the limit unknowingly via a huge auto-generated changelog.","solutions":["Trim the file to the essentials — background should be short project context, not a full corpus.","Split into a small curated summary file and pass that instead.","Check the file size (du -h <path>) against maxBackgroundFileBytes and compress the content (remove code blocks, history, boilerplate).","If the feature genuinely needs a bigger cap, build with a raised maxBackgroundFileBytes constant — but prefer summarizing."],"exampleFix":"// before\nocr review --background ./full-architecture-docs.md   # 2 MB\n// after\nocr review --background ./docs/summary.md   # curated < maxBackgroundFileBytes","handlingStrategy":"validation","validationCode":"const fs = require('fs');\nconst MAX = 512 * 1024; // match maxBackgroundFileBytes\nconst st = fs.statSync(path);\nif (st.size > MAX) throw new Error(`background file is ${st.size} bytes; cap is ${MAX}`);","typeGuard":"func fitsBackgroundLimit(path string, max int64) bool {\n    info, err := os.Stat(path)\n    return err == nil && !info.IsDir() && info.Size() <= max\n}","tryCatchPattern":null,"preventionTips":["Keep background files small and curated — it is injected into the LLM prompt","Check file size with du -h before passing large documents","Strip code blocks, history, and boilerplate from exported docs","Prefer a short summary file over a full corpus dump"],"tags":["cli","file-size","validation","go"],"backgroundTag":"background-file-too-large","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}