fix(files): count the document body against the export limit - #6006
Conversation
The 250 MB export cap measured only the embedded assets' declared sizes. The markdown body was downloaded with no limit and never counted, so a large document with modest attachments cleared the check and still produced a zip well over the stated limit, materialized whole in memory. The body is the largest single entry in most bundles, so excluding it left the limit unenforced against the item most able to exceed it. It is now capped on read and counted alongside its assets, and the message names both. Follow-up to #5995, which introduced the asset caps without extending them to the body.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview The export handler now downloads the markdown with Export route tests are extended for body counting, capped reads, and size-limit errors; a new v1 file GET test file documents rendered download behavior (content type, disposition, Reviewed by Cursor Bugbot for commit 6950e22. Configure here. |
Greptile SummaryCaps markdown export body size and counts it toward the 250 MB bundle limit.
Confidence Score: 5/5Safe to merge; the prior body-oversize 500 path is fixed and no blocking failures remain. Oversized body downloads are caught as PayloadSizeLimitError and returned as 400 with an export-limit message, covered by tests; body bytes are included in the bundle budget with matching coverage.
|
| Filename | Overview |
|---|---|
| apps/sim/app/api/files/export/[id]/route.ts | Body download is capped and size-limited errors return 400; total budget includes body plus assets; asset count cap removed in favor of upstream embed bound. |
| apps/sim/app/api/files/export/[id]/route.test.ts | Tests body contribution to the limit, maxBytes on the body download, and 400 (not 500) on PayloadSizeLimitError for an oversized body. |
| apps/sim/app/api/v1/files/[fileId]/route.test.ts | New tests for v1 file download content type, disposition, Content-Length, compile 409, and missing-file 404. |
Reviews (3): Last reviewed commit: "chore(files): drop the unreachable expor..." | Re-trigger Greptile
The route had no tests, and #5995 changed what it serves: rendered bytes, the resolved content type rather than the record's source MIME, Content-Length from the rendered length, and a retryable 409 while an artifact compiles. One test pins the filename/content-type relationship. A review flagged the download as naming a rendered file with a source extension, but the renderer picks its output format from the file name — getE2BDocFormat and COMPILABLE_FORMATS both key on it — so a .docx renders to a docx and the two cannot disagree. The test makes that argument executable rather than a comment.
Capping the body read meant an oversized document threw PayloadSizeLimitError, which nothing caught, so the caller got a generic 500 — hiding the very limit message the cap was added to produce. It now returns the same 400 as the bundle check, naming the export limit.
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit b7f6acd. Configure here.
extractEmbeddedFileRefs stops collecting at MAX_EMBEDDED_IMAGES, so the list this route receives is already bounded before it arrives and the count check could never fire. Its test only passed because it mocked the extractor, so it asserted a branch production cannot reach. The byte ceilings are the real bound and stay. A comment records where the count is actually enforced, so the next reader does not add a second one.
|
Dropped the export's asset-count cap — it was unreachable.
The byte ceilings are the real bound and stay. A comment now records where the count is actually enforced so the next reader does not add a second one. |
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 6950e22. Configure here.
Follow-up to #5995, from Bugbot's finding on the v0.7.47 release PR (#6005).
Summary
Provenance
#5995 added the asset caps but did not extend them to the body. The unbounded body read predates that PR; what #5995 introduced was an export limit that silently excluded the largest item — so this closes a gap it created rather than an unrelated defect.
Type of Change
Testing
Two tests added to the suite #5995 introduced: the body counting toward the limit when assets alone sit under it, and the body read carrying the cap. Seven tests on this route pass; lint,
check:utils, typecheck andcheck:api-validationclean.Checklist