fix(server): retain the legacy structured diff payload budget

This commit is contained in:
Mohamed Boudra
2026-11-06 06:14:33 +01:00
parent 567c1617f5
commit 870180cbe5
2 changed files with 23 additions and 3 deletions
@@ -11,7 +11,10 @@ import {
type DiffBody,
} from "@getpaseo/protocol/binary-frames/index";
import type { ParsedDiffFile } from "@getpaseo/protocol/messages";
import { resolveCheckoutDiffBase } from "../utils/checkout-git.js";
import {
CHECKOUT_DIFF_MAX_STRUCTURED_BYTES,
resolveCheckoutDiffBase,
} from "../utils/checkout-git.js";
import { expandTilde } from "../utils/path.js";
import { toCheckoutError } from "./checkout-git-utils.js";
@@ -105,7 +108,7 @@ export class CheckoutDiffManager {
next.set(entry.path, file);
}
files = next;
payload = { cwd, files: [...next.values()], error: null };
payload = legacySnapshot(cwd, [...next.values()]);
}
pending = null;
if (delivered) listener(payload);
@@ -169,3 +172,19 @@ export class CheckoutDiffManager {
await this.streams.close();
}
}
function legacySnapshot(cwd: string, files: ParsedDiffFile[]): CheckoutDiffSnapshotPayload {
let bytes = 2;
for (let index = 0; index < files.length; index++) {
bytes += Buffer.byteLength(JSON.stringify(files[index])) + Number(index > 0);
if (bytes > CHECKOUT_DIFF_MAX_STRUCTURED_BYTES) {
return {
cwd,
files: [],
diffTooLarge: true,
error: toCheckoutError(new Error("Diff too large to display")),
};
}
}
return { cwd, files, error: null };
}
@@ -142,7 +142,8 @@ test("keeps the socket usable after rejecting an oversized structured diff", asy
commitFile(cwd, "large-b.js", "const value = 0;\n");
// Short lines stay eligible for highlighting; a giant single line is skipped
// before token expansion and cannot exercise the structured-payload limit.
const denseExpression = `const value = ${"a+".repeat(100)}a;\n`.repeat(4_000);
// Stay below the full-source highlighting budget as well.
const denseExpression = `const value = ${"a+".repeat(100)}a;\n`.repeat(3_500);
writeFileSync(path.join(cwd, "large-a.js"), denseExpression);
writeFileSync(path.join(cwd, "large-b.js"), denseExpression);