fix(workspaces): bound R2 page reads to avoid connection limit#663
Draft
posthog[bot] wants to merge 1 commit into
Draft
fix(workspaces): bound R2 page reads to avoid connection limit#663posthog[bot] wants to merge 1 commit into
posthog[bot] wants to merge 1 commit into
Conversation
readWorkspacePageProjection opened every selected page's R2 object in one Promise.all pass and only read the bodies in a second pass, so all response bodies were held open as live connections at once. A read can request up to maxWorkspacePageReadCount (20) pages, which exceeds the Cloudflare Workers ~6 concurrent open-connection limit and makes object.text() throw "Response closed due to connection limit", severing the agent conversation. Collapse the two passes into bounded batches that get() and text() each page in the same task, capped at pageReadConcurrency = 6, mirroring the existing pageWriteConcurrency guard on the write path. Generated-By: PostHog Code Task-Id: 3344d727-3576-48b1-a601-c6adc7ab7f02
|
React Doctor found no new issues. 🎉 Reviewed by React Doctor for commit |
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 AI agent's
read_workspace_itemstool threw "Response closed due to connection limit" whenever it read more than ~6 pages of an extracted file, which severed the agent conversation.readWorkspacePageProjectionfetched every selected page's R2 object in onePromise.allpass and only read the bodies in a second pass, so all response bodies were held open as live connections simultaneously. Since a read can request up tomaxWorkspacePageReadCount(20) pages, this exceeded Cloudflare Workers' ~6 concurrent open-connection limit.The fix collapses the two passes into bounded batches that
get()andtext()each page in the same task, capped atpageReadConcurrency = 6— mirroring the existingpageWriteConcurrencyguard already used on the write path. This keeps simultaneously-open R2 connections under the limit regardless of how many pages are requested.A regression test models the connection limit (a body counts as open between
get()andtext()) and asserts a 20-page read never opens more than 6 connections; it fails on the old code and passes with the fix.Why
A production error on the
posthog-edgeworker deterministically broke the core AI file-read flow for any multi-page read, severing the agent conversation.Test plan
vp test --run src/features/workspaces/extraction/workspace-page-projection.test.ts— 5 passingvp check— format, lint, and typecheck cleanCreated with PostHog Code from this inbox report.
Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.