fix(files): await pull-mode stream readiness

This commit is contained in:
2026-07-10 17:38:35 +02:00
parent 306bf08452
commit 8c67a00f37
2 changed files with 93 additions and 6 deletions

View File

@@ -444,8 +444,12 @@ export function createFilesHttpClient(
};
return out;
}
// Streamed read — only supported when the queue drainer is wired.
if (drainer === null) {
// Streamed read — only supported when pull-mode was configured.
// `drainer` is assigned asynchronously after the streams bridge has
// subscribed, so checking it here races client construction. The
// promise itself is the synchronous configuration signal; awaiting it
// also guarantees the drainer has been installed by its `.then()`.
if (streamsBridgePromise === null) {
throw new InternalFileError(
`http RPC client received a streamed read (size ${wire.size}) but is in inline-only mode. Pass { outboundQueueUrl, transferBaseUrl } when constructing the client to enable streamed reads.`,
);
@@ -507,8 +511,11 @@ export function createFilesHttpClient(
);
}
// Streamed write — requires the queue drainer + streams-bridge.
if (drainer === null) {
// Streamed write — requires pull-mode configuration. Do not inspect
// `drainer` as a readiness flag: bridge registration is asynchronous,
// and an immediate large write must wait for it instead of being
// misclassified as an inline-only client.
if (streamsBridgePromise === null) {
throw new ConflictError(
`http RPC client supports inline writes only (≤ ${INLINE_THRESHOLD} bytes). The supplied input was promoted to streams (size ${decision.size ?? 'unknown'}). Pass { outboundQueueUrl, transferBaseUrl } to enable streamed writes.`,
);