WeKnora icon indicating copy to clipboard operation
WeKnora copied to clipboard

[Bug]: MinerU result-package download (1 GiB) and per-entry (64 MiB) ceilings are still hard-coded — WEKNORA_MINERU_MAX_IMAGE_BYTES cannot rescue a package rejected at download

Open JSJ189 opened this issue 1 week ago • 0 comments

Version: v0.9.1 (commit 71c32af9)

What happens

PR #4963 (fix for #4955) made the decompressed-image budget of a MinerU result package configurable via WEKNORA_MINERU_MAX_IMAGE_BYTES. Two sibling ceilings that guard the very same artifact are still compile-time constants with no override:

  1. mineruV1MaxZipBytes = 1 << 30 — the download cap for the result package itself, used by both the self-hosted MinerU V1 client and the MinerU Cloud converter.
  2. maxZipEntryBytes = 64 << 20 — the per-entry cap applied to every decompressed ZIP member.

For a document whose result package exceeds 1 GiB, raising WEKNORA_MINERU_MAX_IMAGE_BYTES cannot help: the download is rejected before anything is decompressed, and the knowledge entry ends up parse_status=failed. There is no environment variable, per-knowledge override or per-parser-engine setting that changes either number; the only workarounds are patching the constant and rebuilding the app image, or degrading the render settings / splitting the source PDF upstream.

A measured example: a 524-page technical volume produced a MinerU result package of 1,461,704,070 B (1.36 GiB) at MinerU's own render settings — above this ceiling. That is the artifact MinerU itself emits, i.e. exactly what a deployment that points WeKnora straight at a self-hosted MinerU (V1 API, no intermediate rewriting) receives; the same artifact already hit a hard failure at an earlier stage of our own pipeline that enforced an identical 1 GiB limit, so the figure is not hypothetical.

Where in the code

internal/infrastructure/docparser/mineru_v1_client.go

// :34
const (
	mineruV1PollInitial  = 2 * time.Second
	mineruV1PollMax      = 30 * time.Second
	mineruV1APITimeout   = 30 * time.Second
	mineruV1MaxZipBytes  = 1 << 30
	mineruV1CancelBudget = 10 * time.Second
)

// :90 — every client instance gets the constant
maxZipBytes: mineruV1MaxZipBytes,

// :528-534 — download is buffered, then rejected
data, err := io.ReadAll(io.LimitReader(resp.Body, c.maxZipBytes+1))
if err != nil {
	return nil, err
}
if int64(len(data)) > c.maxZipBytes {
	return nil, fmt.Errorf("artifact exceeds %d bytes", c.maxZipBytes)
}

internal/infrastructure/docparser/zip_limits.go

// :16-23
// maxResultPackageBytes caps a downloaded result package. Same ceiling the
// V1 client applies to the same artifact.
maxResultPackageBytes = mineruV1MaxZipBytes
...
maxZipEntryBytes = 64 << 20

internal/infrastructure/docparser/mineru_cloud_converter.go:380 — Cloud path, same ceiling:

zipData, err := readResultPackage(resp.Body, maxResultPackageBytes)

Second ceiling, maxZipEntryBytes, is applied to the package markdown (readZipEntry, mineru_cloud_converter.go:506), to every extracted image (readZipEntryBytes, :507, called at :455) and to the layout JSON (mineru_layout.go:121) and CSV-to-markdown conversion (csv_converter.go:15). Its failure mode is different and quieter: at mineru_cloud_converter.go:455-459 an over-cap entry logs failed to read zip image ... and the loop continues, so the document parses "successfully" while silently losing that page image.

grep -rn "os.Getenv" internal/infrastructure/docparser/ returns only MAX_FILE_SIZE_MB, IMAGE_HOST_KEEP_URL and WEKNORA_MINERU_MAX_IMAGE_BYTES. In v0.9.1 the documentation states the position explicitly (website-docs/01-getting-started/04-configuration.md: "下载 1 GiB、单条目 64 MiB 上限仍生效").

Why it matters

  • The 1 GiB ceiling, not the image budget, is now the binding constraint for large technical documents. Scanned engineering drawings and 500+ page volumes at lossless PNG cross 1 GiB compressed as a matter of course. #4963 raised the budget one layer deeper but left this one in place, so the documented remedy cannot unblock exactly the class of documents #4955 was filed about — the operator sets WEKNORA_MINERU_MAX_IMAGE_BYTES=2147483648, re-creates the app container, and the document still fails with artifact exceeds 1073741824 bytes.
  • The error message names no variable and gives no hint that the limit is fixed, so the failure looks like the env override simply not working.
  • Separately, the cap is enforced by buffering up to 1 GiB per artifact in RAM and then holding the whole decompressed set too; N concurrent parses multiply that. Any fix that only raises the constant scales that memory profile linearly.

Expected

Any one of the following:

  1. Make both ceilings configurable next to the existing one and document them the same way, e.g.

    • WEKNORA_MINERU_MAX_ZIP_BYTES (default 1073741824)
    • WEKNORA_MINERU_MAX_ZIP_ENTRY_BYTES (default 67108864)

    and name the variable in the error text, as the image-budget error already does (... exceed configured limit %d bytes (%s)).

  2. Or collapse them into one knob: validate the download against a size derived from the image budget so a single setting governs the artifact end to end.

  3. At minimum, have artifact exceeds 1073741824 bytes say that this limit is fixed and not affected by WEKNORA_MINERU_MAX_IMAGE_BYTES, and note it in the configuration docs.

Streaming the artifact to a temp file and reading it with zip.OpenReader (validating Content-Length first) instead of io.ReadAll would also let the ceiling stop being a memory multiplier.

Related

  • #4955 — original 512 MiB image-budget report (closed by #4963)
  • #5095 — same "hard-coded asset ceiling blocks real documents" shape in the anydoc path

JSJ189 avatar Nov 24 '26 08:11 JSJ189