MCPcopy Create free account
hub / github.com/CopilotKit/aimock / tripTruncation

Function tripTruncation

src/recorder.ts:1136–1161  ·  view source on GitHub ↗
(cap: "byte" | "frame")

Source from the content-addressed store, hash-verified

1134 // full. We still skip recording — the cap means "don't journal", not
1135 // "don't answer the client".
1136 const tripTruncation = (cap: "byte" | "frame") => {
1137 bufferTruncated = true;
1138 truncationCap = cap;
1139 frameTimestamps.length = 0;
1140 frameBuffer = "";
1141 // Intentional: the returned flush string is discarded (frameBuffer was
1142 // just cleared and recording is skipped), but `.end()` releases any
1143 // partial-multibyte bytes the StringDecoder is internally holding — so
1144 // this frees decoder state rather than being dead cleanup.
1145 frameDecoder.end();
1146 binaryFrameBuffer = Buffer.alloc(0);
1147 if (isProgressiveStream) {
1148 chunks.length = 0;
1149 bufferedBytes = 0;
1150 }
1151 // State which cap tripped accurately (do not conflate the two caps),
1152 // and report the relay truthfully — the client received every byte on
1153 // the streamed path and, post-fix, on the non-streamed path too.
1154 const detail =
1155 cap === "byte"
1156 ? `byte cap (${maxBufferBytes} bytes)`
1157 : `frame cap (${maxBufferFrames} frames)`;
1158 logger?.warn(
1159 `Upstream response exceeded the proxy buffer ${detail} — relaying full body to client, but skipping in-memory collapse/recording to bound memory`,
1160 );
1161 };
1162 const onUpstreamData = (chunk: Buffer) => {
1163 totalBytes += chunk.length;
1164 // Trip truncation on EITHER bytes OR frame count. The byte cap alone

Callers 1

onUpstreamDataFunction · 0.85

Calls 2

endMethod · 0.80
warnMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…