From b5ebfe157748f99c4ad3f14dce1db4937031706e Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 23 Jun 2026 17:58:50 +0000 Subject: [PATCH] Fix stuck flushScheduled flag and permanent failedSegments in EventNdjsonLogger Bug 1: The flushScheduled flag could become stuck true if scheduleFlush() failed or was interrupted, preventing future timer-based flushes for low-volume threads. Fix: always clear flushScheduled after any drain, and reset the flag on schedule failure via catchCause. Bug 2: A single transient I/O error permanently added a thread segment to failedSegments, silencing all future logging for that thread. Fix: start each drain with a fresh failedSegments set so transient errors don't block subsequent flush attempts. --- .../server/src/provider/Layers/EventNdjsonLogger.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/apps/server/src/provider/Layers/EventNdjsonLogger.ts b/apps/server/src/provider/Layers/EventNdjsonLogger.ts index e02721f5b1..e54a8351ad 100644 --- a/apps/server/src/provider/Layers/EventNdjsonLogger.ts +++ b/apps/server/src/provider/Layers/EventNdjsonLogger.ts @@ -318,7 +318,7 @@ function drainPending(input: { } const sinks = new Map(input.state.sinks); - const failedSegments = new Set(input.state.failedSegments); + const failedSegments = new Set(); const failures: Array = []; const attributionByStream = new Map< EventNdjsonStream, @@ -399,7 +399,7 @@ function drainPending(input: { pendingBytes: 0, sinks, failedSegments, - flushScheduled: input.timerFired ? false : input.state.flushScheduled, + flushScheduled: false, closed: input.close, lastRetentionAt: retentionDue ? input.now : input.state.lastRetentionAt, }, @@ -557,7 +557,14 @@ export const makeEventNdjsonLogStore = Effect.fnUntraced(function* ( if (action.flush) { yield* flush(false, false); } else if (action.schedule) { - yield* scheduleFlush(); + yield* scheduleFlush().pipe( + Effect.catchCause(() => + SynchronizedRef.update(stateRef, (state) => ({ + ...state, + flushScheduled: false, + })), + ), + ); } });