alibaba/open-code-review · error

file too large (%d bytes, max %d)

Error message

file too large (%d bytes, max %d)

What it means

readRuleFileSafe size guard: a rule file (custom instructions loaded into the review prompt) exceeds 512 KiB. Oversized rule files would bloat prompts and slow or break LLM requests, so reading is refused with the actual and maximum sizes reported. The path must also be inside the repo and have an allowed extension, both checked before this.

Source

Thrown at internal/config/rules/system_rules.go:656

	if err != nil {
		return "", err
	}

	if confineRoot != "" && !pathutil.WithinBase(confineRoot, resolved) {
		return "", fmt.Errorf("rule file path %q escapes repo dir %q", resolved, confineRoot)
	}

	if !allowedRuleExts[strings.ToLower(filepath.Ext(resolved))] {
		return "", fmt.Errorf("unsupported extension %q, only .md/.txt/.markdown allowed", filepath.Ext(resolved))
	}

	const maxSize = 512 * 1024
	info, err := os.Stat(resolved)
	if err != nil {
		return "", err
	}
	if info.Size() > maxSize {
		return "", fmt.Errorf("file too large (%d bytes, max %d)", info.Size(), maxSize)
	}

	content, err := os.ReadFile(resolved)
	if err != nil {
		return "", err
	}

	return strings.TrimRight(string(content), "\n"), nil
}

View on GitHub (pinned to 5cf97d0d15)

Solutions

  1. Split the rule file into smaller focused files and reference only the relevant one
  2. Trim the rule file to the essential review guidelines (well under 512 KiB)
  3. Generate a condensed summary of a large doc and use that as the rule file
  4. Check which file is actually being passed — a wrong --rule target may be the oversized one

Example fix

// before
ocr review --rule ./docs/full-handbook.md   # 2 MB
// after
ocr review --rule ./docs/review-guidelines.md   # 40 KB summary
Defensive patterns

Strategy: validation

Validate before calling

func ensureRuleFileSize(p string, max int64) error {
    fi, err := os.Stat(p)
    if err != nil { return err }
    if fi.Size() > max {
        return fmt.Errorf("%s is %d bytes (max %d); trim or split it", p, fi.Size(), max)
    }
    return nil
}
// ensureRuleFileSize(rulePath, 512*1024) before running ocr

Try / catch

_, err := tryReadRuleFile(rulePath, confineRoot)
if err != nil && strings.Contains(err.Error(), "file too large") {
    fmt.Fprintln(os.Stderr, "split the rule file into smaller focused .md files")
    os.Exit(2)
}

Prevention

When it happens

Trigger: os.Stat on the resolved rule file reports a size > 524288 bytes; readRuleFileSafe returns before os.ReadFile.

Common situations: Pointing --rule at a huge generated doc, a concatenated changelog, or an entire documentation dump instead of a focused rules file; accidentally passing a data export (.md) with embedded base64 images.

Related errors


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