From 498efc2ba3fae30b14c8d567f61c8b81cf5136bd Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Wed, 11 Nov 2026 16:39:47 -0800 Subject: [PATCH 1/2] Fix incorrect last bytes sent API timing data from nested requests --- packages/typescript/src/api/syncChannel.ts | 4 ++ packages/typescript/test/sync/timing.test.ts | 44 ++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 packages/typescript/test/sync/timing.test.ts diff --git a/packages/typescript/src/api/syncChannel.ts b/packages/typescript/src/api/syncChannel.ts index 9195d9615c452..92c43c8f5c278 100644 --- a/packages/typescript/src/api/syncChannel.ts +++ b/packages/typescript/src/api/syncChannel.ts @@ -327,6 +327,10 @@ export class SyncRpcChannel { ); } if (this.collectTiming) { + // A callback may have issued a nested request while waiting for this response. + this.lastBytesSent = typeof payload === "string" + ? Buffer.byteLength(payload, "utf-8") + : payload.length; this.lastBytesReceived = this._msgPayload.length; } return this._msgPayload; diff --git a/packages/typescript/test/sync/timing.test.ts b/packages/typescript/test/sync/timing.test.ts new file mode 100644 index 0000000000000..6f287fa8c47b3 --- /dev/null +++ b/packages/typescript/test/sync/timing.test.ts @@ -0,0 +1,44 @@ +import { API } from "@typescript/typescript/sync"; +import assert from "node:assert"; +import { + describe, + test, +} from "node:test"; +import { fileURLToPath } from "node:url"; +import { createVirtualFileSystem } from "../testUtils.ts"; + +describe("sync IPC timing", () => { + test("records the outer request size after a nested request", () => { + const fs = createVirtualFileSystem({ "/tsconfig.json": "{}", "/a.ts": "" }); + const nestedArgument = "x".repeat(10_000); + let nested = false; + let api: API | undefined; + using instance = new API({ + cwd: fileURLToPath(new URL("../../../../", import.meta.url).toString()), + collectTiming: true, + fs: { + ...fs, + readFile: path => { + if (!nested) { + nested = true; + if (!api) throw new Error("API is not initialized"); + api.parseCommandLine([nestedArgument]); + } + return fs.readFile!(path); + }, + }, + }); + api = instance; + + instance.createSnapshot({ openProjects: ["/tsconfig.json"] }); + + assert.ok(nested); + const { recentRequests } = instance.getTimingInfo(); + const nestedIndex = recentRequests.findIndex(request => request.method === "parseCommandLine"); + assert.ok(nestedIndex >= 0); + assert.ok(recentRequests[nestedIndex].bytesSent > nestedArgument.length); + const outer = recentRequests[nestedIndex + 1]; + assert.equal(outer.method, "createSnapshot"); + assert.ok(outer.bytesSent < nestedArgument.length, `${outer.method} recorded ${outer.bytesSent} bytes sent`); + }); +}); From b2931219661cab5bb15967619e2982366d9e9b19 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 12 Nov 2026 12:14:07 -0800 Subject: [PATCH 2/2] Fix weird using usage --- packages/typescript/test/sync/timing.test.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/packages/typescript/test/sync/timing.test.ts b/packages/typescript/test/sync/timing.test.ts index 6f287fa8c47b3..7a6d0b93b59fa 100644 --- a/packages/typescript/test/sync/timing.test.ts +++ b/packages/typescript/test/sync/timing.test.ts @@ -12,8 +12,7 @@ describe("sync IPC timing", () => { const fs = createVirtualFileSystem({ "/tsconfig.json": "{}", "/a.ts": "" }); const nestedArgument = "x".repeat(10_000); let nested = false; - let api: API | undefined; - using instance = new API({ + using api = new API({ cwd: fileURLToPath(new URL("../../../../", import.meta.url).toString()), collectTiming: true, fs: { @@ -21,19 +20,16 @@ describe("sync IPC timing", () => { readFile: path => { if (!nested) { nested = true; - if (!api) throw new Error("API is not initialized"); api.parseCommandLine([nestedArgument]); } return fs.readFile!(path); }, }, }); - api = instance; - - instance.createSnapshot({ openProjects: ["/tsconfig.json"] }); + api.createSnapshot({ openProjects: ["/tsconfig.json"] }); assert.ok(nested); - const { recentRequests } = instance.getTimingInfo(); + const { recentRequests } = api.getTimingInfo(); const nestedIndex = recentRequests.findIndex(request => request.method === "parseCommandLine"); assert.ok(nestedIndex >= 0); assert.ok(recentRequests[nestedIndex].bytesSent > nestedArgument.length);