@devries-cameron20 / t3code Mirror · read-only / commits / c2b06f9df8
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 14:45 UTC

perf(server): Cursor turns no longer write every streamed token to provider logs (#29641)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Alex Southwell committed Nov 15, 2026 at 01:54 UTC c2b06f9df8491cde7f707e62506aaff1183b19a3
2 files changed +78
apps/server/src/provider/EventNdjsonLogger.test.ts
+59
@@ -255,6 +255,65 @@ it.layer(NodeServices.layer)("EventNdjsonLogger", (it) => {
255 }),
256 );
257
258 + it.effect("drops Cursor streaming deltas while keeping its lifecycle updates", () =>
259 + Effect.gen(function* () {
260 + const tempDir = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-provider-log-"));
261 + const basePath = NodePath.join(tempDir, "events.log");
262 + const threadId = ThreadId.make("cursor-deltas");
263 + const cursorUpdate = (update: object) => ({
264 + provider: "cursor",
265 + kind: "protocol",
266 + event: {
267 + direction: "incoming",
268 + stage: "decoded",
269 + payload: { type: "interaction.update", runId: "run-1", update },
270 + },
271 + });
272 + const toolCall = { type: "shell", args: { command: "ls" } };
273 + const transient = [
274 + { type: "text-delta", text: "Hel" },
275 + { type: "thinking-delta", text: "Hmm" },
276 + { type: "token-delta", tokens: 3 },
277 + { type: "shell-output-delta", event: { stdout: "a.ts\n" } },
278 + { type: "partial-tool-call", callId: "call-1", modelCallId: "m-1", toolCall },
279 + {
280 + type: "tool-call-delta",
281 + callId: "call-1",
282 + modelCallId: "m-1",
283 + taskUpdate: { type: "text-delta", text: "Sub" },
284 + },
285 + ].map(cursorUpdate);
286 + const retained = [
287 + { type: "tool-call-started", callId: "call-1", modelCallId: "m-1", toolCall },
288 + {
289 + type: "tool-call-delta",
290 + callId: "call-1",
291 + modelCallId: "m-1",
292 + taskUpdate: { type: "tool-call-completed", callId: "call-2", toolCall },
293 + },
294 + { type: "tool-call-completed", callId: "call-1", modelCallId: "m-1", toolCall },
295 + { type: "turn-ended" },
296 + ].map(cursorUpdate);
297 +
298 + try {
299 + const store = yield* makeEventNdjsonLogStore(basePath, { batchWindowMs: 0 });
300 + const native = store.logger("native");
301 + for (const event of [...transient, ...retained]) {
302 + yield* native.write(event, threadId);
303 + }
304 + yield* store.close();
305 +
306 + const records = NodeFS.readFileSync(ownedLogPath(basePath, "cursor-deltas"), "utf8")
307 + .trim()
308 + .split("\n")
309 + .map((line) => decodeUnknownJson(parseLogLine(line).payload));
310 + assert.deepEqual(records, retained);
311 + } finally {
312 + NodeFS.rmSync(tempDir, { recursive: true, force: true });
313 + }
314 + }),
315 + );
316 +
317 it.effect("bounds oversized records while retaining failure details", () =>
318 Effect.gen(function* () {
319 const tempDir = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-provider-log-"));
apps/server/src/provider/EventNdjsonLogger.ts
+19
@@ -63,6 +63,13 @@ const transientNativeMethods = new Set([
63 "turn/diff/updated",
64 ]);
65 const transientAcpUpdates = new Set(["agent_message_chunk", "agent_thought_chunk"]);
66 +const transientCursorUpdates = new Set([
67 + "text-delta",
68 + "thinking-delta",
69 + "token-delta",
70 + "shell-output-delta",
71 + "partial-tool-call",
72 +]);
73
74 export type EventNdjsonStream = "native" | "canonical" | "orchestration";
75
@@ -219,6 +226,18 @@ export function shouldPersistProviderEvent(stream: EventNdjsonStream, event: unk
226 }
227 }
228
229 + if (nativeType === "interaction.update") {
230 + let update = Reflect.get(nativeEvent, "update");
231 + if (typeof update !== "object" || update === null) return true;
232 + // Subagent updates arrive wrapped; keep the wrapper when it carries a lifecycle record.
233 + if (Reflect.get(update, "type") === "tool-call-delta") {
234 + update = Reflect.get(update, "taskUpdate");
235 + if (typeof update !== "object" || update === null) return true;
236 + }
237 + const updateType = Reflect.get(update, "type");
238 + return typeof updateType !== "string" || !transientCursorUpdates.has(updateType);
239 + }
240 +
241 const payload = Reflect.get(nativeEvent, "payload");
242 if (typeof payload !== "object" || payload === null) return true;
243