Skip to content

Commit 7921f71

Browse files
thomhurstclaude
andcommitted
refactor: simplify FlushModuleOutput - modules now flush immediately
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent d7a398b commit 7921f71

2 files changed

Lines changed: 7 additions & 24 deletions

File tree

src/ModularPipelines/Console/ConsoleCoordinator.cs

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -262,38 +262,22 @@ public IModuleOutputBuffer GetModuleBuffer(Type moduleType)
262262
/// <inheritdoc />
263263
public void FlushModuleOutput()
264264
{
265+
// Output is now flushed immediately when modules complete.
266+
// This method remains for API compatibility but only flushes
267+
// unattributed output (pipeline-level logs).
265268
if (_originalConsoleOut == null)
266269
{
267-
throw new InvalidOperationException("ConsoleCoordinator is not installed.");
270+
return; // Not installed, nothing to flush
268271
}
269272

270273
var formatter = _formatterProvider.GetFormatter();
271274

272-
// Flush unattributed output first (if any)
275+
// Flush unattributed output (if any)
273276
if (_unattributedBuffer.HasOutput)
274277
{
275278
var unattributedLogger = _outputLogger ?? _loggerFactory.CreateLogger("ModularPipelines.Output");
276279
_unattributedBuffer.FlushTo(_originalConsoleOut, formatter, unattributedLogger);
277280
}
278-
279-
// Flush module buffers in completion order
280-
var orderedBuffers = _moduleBuffers.Values
281-
.Where(b => b.HasOutput)
282-
.OrderBy(b => b.CompletedAtUtc ?? DateTime.MaxValue)
283-
.ToList();
284-
285-
foreach (var buffer in orderedBuffers)
286-
{
287-
// Resolve the registered ILogger<T> from DI to use any custom loggers injected by tests
288-
var loggerType = typeof(ILogger<>).MakeGenericType(buffer.ModuleType);
289-
var moduleLogger = (ILogger)_serviceProvider.GetService(loggerType)
290-
?? _loggerFactory.CreateLogger(buffer.ModuleType);
291-
buffer.FlushTo(_originalConsoleOut, formatter, moduleLogger);
292-
}
293-
294-
// Clear buffers after flush to release memory
295-
// This prevents accumulation in long-running pipelines
296-
_moduleBuffers.Clear();
297281
}
298282

299283
/// <inheritdoc />

src/ModularPipelines/Console/IConsoleCoordinator.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,9 @@ internal interface IConsoleCoordinator : IAsyncDisposable
7272
IModuleOutputBuffer GetUnattributedBuffer();
7373

7474
/// <summary>
75-
/// Flushes all module output in completion order.
76-
/// Should be called after progress phase ends.
75+
/// Flushes any remaining unattributed output.
76+
/// Module output is flushed immediately when modules complete.
7777
/// </summary>
78-
/// <exception cref="InvalidOperationException">Thrown if not installed.</exception>
7978
void FlushModuleOutput();
8079

8180
/// <summary>

0 commit comments

Comments
 (0)