Repository navigation
Hosted request limits; paced X media downloads - #57
Merged
Merged
Conversation
…nloads
A 100 MiB request body to a hosted OpenAI instance answered 500 (Cloudflare
1101): the Durable Object's isolate exceeded its 128 MB memory limit and was
reset, ending every request in it, a paced stream on the same instance
included. From about 24 MiB it failed now and then, as the body was held
several times over: the Worker buffered it, the ledger's clone kept a second
copy, and each save kept the JSON of the whole store.
- The Worker refuses a body over the service's limit with a 413 before
reading it, in the provider's error shape where it has one, and streams
every other body to the instance. Hosted limit 16 MiB.
- The OpenAI emulator accepts request bodies up to 32 MiB, locally too, and
refuses a larger one with 413 request_too_large in OpenAI's error shape.
OpenAI documents no overall limit for these endpoints.
- The ledger records a body declared over 1 MiB by size, without a clone.
- A save keeps a fingerprint of each stored value, not its JSON.
- A write that would take an instance's stored data past 32 MiB is refused
with a 507; GET /_emulate/persistence shows the size and the budget.
- A local server ends the connection after answering a request whose body
it did not read.
X: a DM attachment's download can be paced, the same controls as the OpenAI
emulator's paced answers: attachment.stream { chunks, interval_ms } in the
seed or on /_emulate/x/dm/arrive, or POST /_emulate/x/media/:media_key/stream.
Unpaced stays the default.
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.
Two gaps on the hosted emulators.
1. Large request bodies reset an instance, and every stream in it. A 100 MiB body to a hosted OpenAI instance answered 500 (
error code: 1101).wrangler tailshowed the cause: "Durable Object's isolate exceeded its memory limit and was reset". On the previous code, a paced stream on the same instance was cut the moment the 100 MiB request arrived. Streams on 32 other instances, in three runs, survived; Cloudflare can place several objects in one isolate, so it is possible, but it did not happen in those runs. Bodies from about 24 MiB failed now and then, because the body was held several times over: the Worker buffered it, the ledger's clone kept a second copy, and each save kept the JSON of the whole store.content-lengthagainst the service's limit and answers413in the provider's error shape where it has one. It streams every other body to the instance; a body of unknown length is read up to the limit. The hosted limit is 16 MiB.413with{"error":{"message":…,"type":"invalid_request_error","param":null,"code":"request_too_large"}}, before the body is read, locally and hosted.507 instance_storage_fullrather than running the isolate out of memory.GET /_emulate/persistenceshowsstored_bytesandbudget_bytes.serveends the connection after answering a request whose body it did not read, so a client still uploading gets the answer.Measured on a staging copy of the hosted worker:
2. Paced X DM media downloads.
dmConversationsMediaDownloadcan send an attachment as exactlychunkspiecesinterval_msapart, the same controls the OpenAI emulator has for a paced answer. It is set withattachment.streamin the seed or on/_emulate/x/dm/arrive, or withPOST /_emulate/x/media/:media_key/stream. It is an emulator control, listed in the manifest. Unpaced stays the default. On staging, 90 MiB as 300 pieces 100 ms apart arrived whole in 30.1 s, with no gap over 135 ms.Tests:
request-limits.test.ts: the oversized body is refused unread in both forms, and bodies at the limit pass in both forms.hosted-writes.test.ts: the store budget.