fix(coding-agent): preserve small RPC terminal frames

This commit is contained in:
Wolfgang Schoenberger
2026-07-18 15:13:09 -07:00
parent 63c8cc189a
commit f8cc72ff36
3 changed files with 49 additions and 54 deletions
@@ -121,13 +121,16 @@ function overflowFrame(frame: object): object {
/** Serialize a complete JSONL frame while enforcing the transport byte ceiling. */
export function encodeRpcFrame(frame: object, streamedMessageCount = 0, streamedMessages?: readonly unknown[]): string {
const compacted = compactTerminalFrame(frame, streamedMessageCount, streamedMessages);
let json = JSON.stringify(compacted);
let json = JSON.stringify(frame);
if (serializedFrameBytes(json) <= MAX_RPC_FRAME_BYTES) return `${json}\n`;
if (isRecord(compacted) && compacted.type === "response") {
return `${JSON.stringify(overflowFrame(compacted))}\n`;
if (isRecord(frame) && frame.type === "response") {
return `${JSON.stringify(overflowFrame(frame))}\n`;
}
const compacted = compactTerminalFrame(frame, streamedMessageCount, streamedMessages);
json = JSON.stringify(compacted);
if (serializedFrameBytes(json) <= MAX_RPC_FRAME_BYTES) return `${json}\n`;
for (const pass of SHRINK_PASSES) {
json = JSON.stringify(shrinkValue(compacted, pass));
if (serializedFrameBytes(json) <= MAX_RPC_FRAME_BYTES) return `${json}\n`;