@devries-cameron20 / t3code Mirror · read-only / commits / d406823a83
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 03:37 UTC

perf(github): skip decoding oversized GraphQL responses (#39928)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Adamulek123 committed Nov 21, 2026 at 00:54 UTC d406823a833395a6a964d2eeacd66426039d6593
2 files changed +25 -20
packages/provider-core/src/server/collectStreamText.ts
+17 -13
@@ -22,13 +22,13 @@ interface CollectState {
22 readonly truncated: boolean;
23 }
24
25 -export const collectUint8StreamText = <E>(input: {
25 +interface CollectUint8StreamInput<E> {
26 readonly stream: Stream.Stream<Uint8Array, E>;
27 readonly maxBytes?: number | undefined;
28 - readonly truncatedMarker?: string | null | undefined;
29 -}): Effect.Effect<CollectedUint8StreamText, E> => {
28 +}
29 +
30 +export const collectUint8StreamChunks = <E>(input: CollectUint8StreamInput<E>) => {
31 const maxBytes = input.maxBytes ?? Number.POSITIVE_INFINITY;
31 - const truncatedMarker = input.truncatedMarker ?? "";
32
33 return input.stream.pipe(
34 Stream.runFold(
@@ -64,17 +64,21 @@ export const collectUint8StreamText = <E>(input: {
64 };
65 },
66 ),
67 - Effect.map((state): CollectedUint8StreamText => {
68 - const decoded = decodeUtf8(Buffer.concat(state.chunks, state.bytes));
67 + );
68 +};
69 +
70 +export const collectUint8StreamText = <E>(
71 + input: CollectUint8StreamInput<E> & { readonly truncatedMarker?: string | null | undefined },
72 +): Effect.Effect<CollectedUint8StreamText, E> =>
73 + collectUint8StreamChunks(input).pipe(
74 + Effect.map(({ chunks, bytes, truncated }) => {
75 + const decoded = decodeUtf8(Buffer.concat(chunks, bytes));
76 + const marker = input.truncatedMarker ?? "";
77 return {
70 - text:
71 - state.truncated && truncatedMarker.length > 0
72 - ? `${decoded.text}${truncatedMarker}`
73 - : decoded.text,
74 - bytes: state.bytes,
75 - truncated: state.truncated,
78 + text: truncated ? decoded.text + marker : decoded.text,
79 + bytes,
80 + truncated,
81 invalidUtf8: decoded.invalidUtf8,
82 };
83 }),
84 );
80 -};
packages/source-control-github/src/server/gitHubGraphQlClient.ts
+8 -7
@@ -10,7 +10,10 @@ import { HttpClient, HttpClientError, HttpClientResponse } from "effect/http";
10 import * as Headers from "effect/http/Headers";
11 import { GraphQLClientError, GraphQLMiddleware, GraphQLProtocol } from "effect/graphql";
12 import * as SourceControlRateLimit from "@t3tools/source-control-core/server/SourceControlRateLimit";
13 -import { collectUint8StreamText } from "@t3tools/provider-core/server/collectStreamText";
13 +import {
14 + collectUint8StreamChunks,
15 + decodeUtf8,
16 +} from "@t3tools/provider-core/server/collectStreamText";
17
18 import * as GitHubCredentials from "./GitHubCredentials.ts";
19 import * as GitHubRequestPolicy from "./GitHubRequestPolicy.ts";
@@ -189,10 +192,10 @@ const capResponse = Effect.fn("gitHubGraphQlClient.capResponse")(function* (
192 onNone: () => DEFAULT_MAX_RESPONSE_BYTES,
193 onSome: (target) => target.maxResponseBytes ?? DEFAULT_MAX_RESPONSE_BYTES,
194 });
192 - const collected = yield* collectUint8StreamText({ stream: response.stream, maxBytes }).pipe(
195 + const collected = yield* collectUint8StreamChunks({ stream: response.stream, maxBytes }).pipe(
196 Effect.catchIf(
197 (error) => error.reason._tag === "EmptyBodyError",
195 - () => Effect.succeed({ text: "", truncated: false }),
198 + () => Effect.succeed({ chunks: [], bytes: 0, truncated: false }),
199 ),
200 );
201 if (collected.truncated) {
@@ -204,12 +207,10 @@ const capResponse = Effect.fn("gitHubGraphQlClient.capResponse")(function* (
207 }),
208 });
209 }
210 + const { text } = decodeUtf8(Buffer.concat(collected.chunks, collected.bytes));
211 return HttpClientResponse.fromWeb(
212 response.request,
209 - new Response(collected.text === "" ? null : collected.text, {
210 - status: response.status,
211 - headers: response.headers,
212 - }),
213 + new Response(text === "" ? null : text, { status: response.status, headers: response.headers }),
214 );
215 });
216