Skip to content

Commit 5dad918

Browse files
author
卧龙
committed
fix: prevent event loop saturation from trajectory flush
Three changes to prevent the trajectory flush from blocking the event loop for 25+ minutes under heavy session load: 1. queued-file-writer: yield event loop via setImmediate between each queued write to prevent the promise chain from consuming 100% of the event loop. Without this yield, 700+ queued writes (50MB trajectory) block the event loop continuously. 2. trajectory paths: reduce TRAJECTORY_RUNTIME_FILE_MAX_BYTES from 50MB to 10MB to prevent any single trajectory file from growing large enough to cause multi-second flush delays. 3. run-cleanup-timeout: increase AGENT_CLEANUP_STEP_TIMEOUT_MS from 10s to 30s to give large trajectories more time to flush before the timeout warning fires. Closes #75839
1 parent b6f9b5f commit 5dad918

3 files changed

Lines changed: 3 additions & 2 deletions

File tree

src/agents/queued-file-writer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ export function getQueuedFileWriter(
130130
write: (line: string) => {
131131
queue = queue
132132
.then(() => ready)
133+
.then(() => new Promise<void>((resolve) => setImmediate(resolve)))
133134
.then(() => safeAppendFile(filePath, line, options))
134135
.catch(() => undefined);
135136
},

src/agents/run-cleanup-timeout.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { formatErrorMessage } from "../infra/errors.js";
22

3-
export const AGENT_CLEANUP_STEP_TIMEOUT_MS = 10_000;
3+
export const AGENT_CLEANUP_STEP_TIMEOUT_MS = 30_000;
44

55
type AgentCleanupLogger = {
66
warn: (message: string) => void;

src/trajectory/paths.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from "node:fs";
22
import path from "node:path";
33
import { resolveHomeRelativePath } from "../infra/home-dir.js";
44

5-
export const TRAJECTORY_RUNTIME_FILE_MAX_BYTES = 50 * 1024 * 1024;
5+
export const TRAJECTORY_RUNTIME_FILE_MAX_BYTES = 10 * 1024 * 1024;
66
export const TRAJECTORY_RUNTIME_EVENT_MAX_BYTES = 256 * 1024;
77

88
type TrajectoryPointerOpenFlagConstants = Pick<

0 commit comments

Comments
 (0)