Skip to content

Commit 624cd36

Browse files
saphidclaude
authored andcommitted
perf(server): Cursor turns no longer write every streamed token to provider logs
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 30084f0 commit 624cd36

2 files changed

Lines changed: 61 additions & 0 deletions

File tree

‎apps/server/src/provider/EventNdjsonLogger.test.ts‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,53 @@ it.layer(NodeServices.layer)("EventNdjsonLogger", (it) => {
258258
}),
259259
);
260260

261+
it.effect("drops Cursor streaming deltas while keeping its lifecycle updates", () =>
262+
Effect.gen(function* () {
263+
const tempDir = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-provider-log-"));
264+
const basePath = NodePath.join(tempDir, "events.log");
265+
const threadId = ThreadId.make("cursor-deltas");
266+
const cursorUpdate = (update: object) => ({
267+
provider: "cursor",
268+
kind: "protocol",
269+
event: {
270+
direction: "incoming",
271+
stage: "decoded",
272+
payload: { type: "interaction.update", runId: "run-1", update },
273+
},
274+
});
275+
const toolCall = { type: "shell", args: { command: "ls" } };
276+
const transient = [
277+
{ type: "text-delta", text: "Hel" },
278+
{ type: "thinking-delta", text: "Hmm" },
279+
{ type: "token-delta", tokens: 3 },
280+
{ type: "shell-output-delta", event: { stdout: "a.ts\n" } },
281+
{ type: "partial-tool-call", callId: "call-1", modelCallId: "m-1", toolCall },
282+
].map(cursorUpdate);
283+
const retained = [
284+
{ type: "tool-call-started", callId: "call-1", modelCallId: "m-1", toolCall },
285+
{ type: "tool-call-completed", callId: "call-1", modelCallId: "m-1", toolCall },
286+
{ type: "turn-ended" },
287+
].map(cursorUpdate);
288+
289+
try {
290+
const store = yield* makeEventNdjsonLogStore(basePath, { batchWindowMs: 0 });
291+
const native = store.logger("native");
292+
for (const event of [...transient, ...retained]) {
293+
yield* native.write(event, threadId);
294+
}
295+
yield* store.close();
296+
297+
const records = NodeFS.readFileSync(ownedLogPath(basePath, "cursor-deltas"), "utf8")
298+
.trim()
299+
.split("\n")
300+
.map((line) => decodeUnknownJson(parseLogLine(line).payload));
301+
assert.deepEqual(records, retained);
302+
} finally {
303+
NodeFS.rmSync(tempDir, { recursive: true, force: true });
304+
}
305+
}),
306+
);
307+
261308
it.effect("bounds oversized records while retaining failure details", () =>
262309
Effect.gen(function* () {
263310
const tempDir = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-provider-log-"));

‎apps/server/src/provider/EventNdjsonLogger.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ const transientNativeMethods = new Set([
5959
"turn/diff/updated",
6060
]);
6161
const transientAcpUpdates = new Set(["agent_message_chunk", "agent_thought_chunk"]);
62+
const transientCursorUpdates = new Set([
63+
"text-delta",
64+
"thinking-delta",
65+
"token-delta",
66+
"shell-output-delta",
67+
"partial-tool-call",
68+
]);
6269

6370
export type EventNdjsonStream = "native" | "canonical" | "orchestration";
6471

@@ -210,6 +217,13 @@ export function shouldPersistProviderEvent(stream: EventNdjsonStream, event: unk
210217
}
211218
}
212219

220+
if (nativeType === "interaction.update") {
221+
const update = Reflect.get(nativeEvent, "update");
222+
if (typeof update !== "object" || update === null) return true;
223+
const updateType = Reflect.get(update, "type");
224+
return typeof updateType !== "string" || !transientCursorUpdates.has(updateType);
225+
}
226+
213227
const payload = Reflect.get(nativeEvent, "payload");
214228
if (typeof payload !== "object" || payload === null) return true;
215229

0 commit comments

Comments
 (0)