From 4ab3bf409ace2dfba3bc3ed56be06b759e1858f8 Mon Sep 17 00:00:00 2001 From: Eason Liang Date: Thu, 27 Aug 2026 09:33:23 +0800 Subject: [PATCH] perf(write-path): remove artificial write delays by default (part of #1375) Two latency sources on the agent file-write path were removed or defaulted off: - DEFAULT_WRITE_DELAY_MS is now 0 instead of 1000, so writes no longer wait a full second for post-save diagnostics by default. The setting itself is unchanged: users who rely on auto-formatters that settle asynchronously (e.g. goimports for Go) can raise writeDelayMs back up; the comment on the constant documents that tradeoff. - WriteToFileTool no longer waits delay(300) before scrollToFirstDiff(). The other five write tools (EditFile, Edit, SearchReplace, ApplyPatch, ApplyDiff) already call scrollToFirstDiff() directly, and DiffViewProvider already re-reveals the first diff on a deferred 100ms timer to beat the diff editor's late layout pass, so the 300ms pause was redundant pacing. The delay() import is removed (DiffViewProvider still uses the package). Tests: ClineProvider spec now asserts the default via DEFAULT_WRITE_DELAY_MS instead of a hardcoded 1000. WriteToFileTool and ClineProvider suites pass (19 + 151). --- packages/types/src/global-settings.ts | 8 +++++--- src/core/tools/WriteToFileTool.ts | 2 -- src/core/webview/__tests__/ClineProvider.spec.ts | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/types/src/global-settings.ts b/packages/types/src/global-settings.ts index 95f246dbe7..8793883576 100644 --- a/packages/types/src/global-settings.ts +++ b/packages/types/src/global-settings.ts @@ -17,10 +17,12 @@ import { languagesSchema } from "./vscode.js" /** * Default delay in milliseconds after writes to allow diagnostics to detect potential problems. - * This delay is particularly important for Go and other languages where tools like goimports - * need time to automatically clean up unused imports. + * Defaults to 0: the write path adds no artificial pacing by default, and post-save + * diagnostics are reported after the (zero) delay. Users who rely on auto-formatters that + * settle asynchronously (e.g. goimports for Go) can raise this setting to give formatters + * time to settle before diagnostics are captured. */ -export const DEFAULT_WRITE_DELAY_MS = 1000 +export const DEFAULT_WRITE_DELAY_MS = 0 /** * Default values for the "auto-close files Zoo opened" settings. diff --git a/src/core/tools/WriteToFileTool.ts b/src/core/tools/WriteToFileTool.ts index ae026b4b86..0c5c80abb9 100644 --- a/src/core/tools/WriteToFileTool.ts +++ b/src/core/tools/WriteToFileTool.ts @@ -1,5 +1,4 @@ import path from "path" -import delay from "delay" import fs from "fs/promises" import { type ClineSayTool, DEFAULT_WRITE_DELAY_MS } from "@roo-code/types" @@ -146,7 +145,6 @@ export class WriteToFileTool extends BaseTool<"write_to_file"> { true, ) - await delay(300) task.diffViewProvider.scrollToFirstDiff() let unified = fileExists diff --git a/src/core/webview/__tests__/ClineProvider.spec.ts b/src/core/webview/__tests__/ClineProvider.spec.ts index 731124cccc..a064184b6c 100644 --- a/src/core/webview/__tests__/ClineProvider.spec.ts +++ b/src/core/webview/__tests__/ClineProvider.spec.ts @@ -1409,14 +1409,14 @@ describe("ClineProvider", () => { expect(state.language).toBe("pt-BR") }) - test("writeDelayMs defaults to 1000ms", async () => { + test("writeDelayMs defaults to DEFAULT_WRITE_DELAY_MS", async () => { // Mock globalState.get to return undefined for writeDelayMs ;(mockContext.globalState.get as any).mockImplementation((key: string) => { return key === "writeDelayMs" ? undefined : null }) const state = await provider.getState() - expect(state.writeDelayMs).toBe(1000) + expect(state.writeDelayMs).toBe(DEFAULT_WRITE_DELAY_MS) }) test("getState applies fallback defaults for write, diff, and terminal settings", async () => {