fix(workspaces): cap WorkspaceKernel in-memory file path to prevent DO resets#621
Draft
posthog[bot] wants to merge 1 commit into
Draft
fix(workspaces): cap WorkspaceKernel in-memory file path to prevent DO resets#621posthog[bot] wants to merge 1 commit into
posthog[bot] wants to merge 1 commit into
Conversation
…O resets The WorkspaceKernel Durable Object materializes whole file bodies in its ~128MB isolate on upload ingest and read (@cloudflare/shell only exposes whole-buffer read/write, so there is no streaming path). A large enough file exceeds the isolate memory limit or holds the storage output gate past its timeout, resetting the object mid-operation and risking in-flight writes. Bound the in-memory path by size so oversized files fail cleanly instead of resetting the object: - Reject uploads above the kernel cap at the route (handled 413) and again defensively in the DO before buffering. - Refuse to load over-cap bodies on read (covers files ingested before the cap). - Skip the memory-heavy preview decode (pdfium/photon-wasm) for large files. Files large enough to trip these caps already failed today — just catastrophically, by resetting the whole DO. Generated-By: PostHog Code Task-Id: a2948632-0f77-473d-ac45-0e43e79edfd2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
WorkspaceKernelDurable Object was resetting on the/workspaces/<id>file flow, throwing paired "isolate exceeded its memory limit" and "storage operation exceeded timeout" errors. The cause is inworkspace-kernel-file-commands.ts: it materializes whole file bodies in the DO's ~128MB isolate (object.arrayBuffer()on upload,readFileBytes()on read) while interleaving SQL storage writes. Since the product allows single uploads up to 200MB, a large enough file blows the isolate memory ceiling or holds the storage output gate past its timeout, resetting the object mid-operation.@cloudflare/shell(theShellWorkspacebacking storage) only exposes whole-bufferreadFileBytes/writeFileBytes— there is no streaming API to route bodies through. So this bounds the in-memory path by size instead, which the report sanctions as the minimum fix. Oversized files now fail cleanly rather than resetting the object:413), and again defensively in the DO before buffering.pdfium/photon-wasmdecode for large files (best-effort; degrades to no thumbnail).Caps live in a new
workspace-kernel-file-limits.tswith the rationale documented.Why
Production error tracking flagged
WorkspaceKernelDO resets on the core file flow. It's contained today (a single user/session/workspace) but the root cause scales with file size and usage, and a reset mid-operation risks losing concurrent in-flight writes. Note: files large enough to trip these caps already failed — just catastrophically, by resetting the whole object; they now fail with a handled error instead.Test plan
pnpm run check(format, lint, types) passesCreated with PostHog Code from an inbox report.
Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.