fix(rpc): accept exact-boundary v2 chunks

This commit is contained in:
Wolfgang Schoenberger
2026-07-22 19:13:53 -07:00
parent a0cb946057
commit 00a9167223
4 changed files with 58 additions and 2 deletions
@@ -147,7 +147,7 @@ export class RpcFrameDecoder {
count < 2 ||
count > Math.ceil(MAX_RPC_REASSEMBLED_BYTES / RPC_CHUNK_PAYLOAD_BYTES) ||
index >= count ||
byteLength <= MAX_RPC_FRAME_BYTES ||
byteLength < MAX_RPC_FRAME_BYTES ||
byteLength > MAX_RPC_REASSEMBLED_BYTES
)
throw new Error("invalid rpc chunk metadata");
@@ -208,6 +208,27 @@ describe("RPC frame encoding", () => {
expect(decoded).toEqual(frame);
});
it("accepts a chunked logical frame at the exact physical-frame boundary", () => {
const frame = {
id: "request-boundary",
type: "response",
command: "get_state",
success: true,
data: { payload: "" },
};
const emptyBytes = Buffer.byteLength(JSON.stringify(frame), "utf8");
frame.data.payload = "x".repeat(MAX_RPC_FRAME_BYTES - emptyBytes);
expect(Buffer.byteLength(JSON.stringify(frame), "utf8")).toBe(MAX_RPC_FRAME_BYTES);
const encoder = new RpcFrameEncoder();
encoder.setProtocolVersion(2);
const decoder = new RpcFrameDecoder();
let decoded: object | undefined;
for (const line of encoder.encode(frame).trimEnd().split("\n")) decoded = decoder.push(JSON.parse(line));
expect(decoded).toEqual(frame);
});
it("preserves terminal message counts above the protocol v2 ceiling", () => {
const encoder = new RpcFrameEncoder();
encoder.setProtocolVersion(2);