Skip to content

fix(workspaces): send content-length for R2 processor requests#647

Draft
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-code/fix-workspace-preview-content-length
Draft

fix(workspaces): send content-length for R2 processor requests#647
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-code/fix-workspace-preview-content-length

Conversation

@posthog

@posthog posthog Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Summary

The R2 storage migration (31e5e0f6) started streaming the R2 object body directly to the workspace file processor with duplex: "half", but the request only carried a custom x-file-size header — never content-length. Cloudflare Workers refuses to send a streamed request body without a known length, so requestWorkspaceFileProcessor threw TypeError: Provided readable stream must have a known length on every preview request, breaking PDF/image preview generation completely.

The fix declares the length via the standard content-length header, using the sizeBytes already threaded through from the source object's verified size. Because all processor paths (/preview/image, /preview/pdf, /parse/pdf, /validate/pdf) share this helper, they're all covered by the single change. Added a focused test asserting the outgoing request carries content-length.

Why

Freshly deployed production regression: workspace file preview generation was failing 100% of the time for PDF and image uploads, surfacing in error tracking within the first hour of the deploy.


Created with PostHog Code from an inbox report.


View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.

Review in cubic

The R2 storage migration (31e5e0f) started streaming the R2 object body
straight to the file processor with duplex: "half" but only a custom
x-file-size header. Cloudflare Workers refuses to send a streamed request
body without a known length, so every preview generation threw
`TypeError: Provided readable stream must have a known length`.

Declare the length via the standard content-length header using the
already-threaded verified sizeBytes. This covers all processor paths
(/preview/*, /parse/pdf, /validate/pdf) since they share the helper.

Generated-By: PostHog Code
Task-Id: 571bc333-acb2-4fc8-b784-76b09256b91d
@github-actions

Copy link
Copy Markdown

React Doctor found no new issues. 🎉

Reviewed by React Doctor for commit 3111ab9.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

0 participants