Buffer backend output before persisting failure logs

- Capture child process output in memory during normal runs
- Persist buffered output only on failures and bound retained data
- Increase trace/event batching windows to reduce flush churn
This commit is contained in:
Julius Marminge committed 2026-06-17 16:20:24 -07:00
1 parent 0ebbdad6c2
commit 2b59d67c05
8 files changed
+421 -80

No files matched your search

+1 -1
View File
@@ -38,7 +38,7 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
const defaultObservabilityConfig = {
traceMinLevel: "Info",
traceTimingEnabled: true,
traceBatchWindowMs: 200,
traceBatchWindowMs: 1_000,
traceMaxBytes: 10 * 1024 * 1024,
traceMaxFiles: 10,
otlpTracesUrl: undefined,
+1 -1
View File
@@ -91,7 +91,7 @@ const EnvServerConfig = Config.all({
),
traceMaxBytes: Config.int("T3CODE_TRACE_MAX_BYTES").pipe(Config.withDefault(10 * 1024 * 1024)),
traceMaxFiles: Config.int("T3CODE_TRACE_MAX_FILES").pipe(Config.withDefault(10)),
traceBatchWindowMs: Config.int("T3CODE_TRACE_BATCH_WINDOW_MS").pipe(Config.withDefault(200)),
traceBatchWindowMs: Config.int("T3CODE_TRACE_BATCH_WINDOW_MS").pipe(Config.withDefault(1_000)),
otlpTracesUrl: Config.string("T3CODE_OTLP_TRACES_URL").pipe(
Config.option,
Config.map(Option.getOrUndefined),
@@ -90,6 +90,41 @@ function resolveStreamLabel(stream: EventNdjsonStream): string {
}
}
function writeBatchedMessages(
sink: RotatingFileSink,
messages: ReadonlyArray<string>,
maxBytes: number,
): number {
let pendingMessages: Array<string> = [];
let pendingBytes = 0;
let logicalWriteBytes = 0;
const flush = () => {
if (pendingMessages.length === 0) {
return;
}
sink.write(pendingMessages.join(""));
pendingMessages = [];
pendingBytes = 0;
};
for (const message of messages) {
const messageBytes = textEncoder.encode(message).byteLength;
logicalWriteBytes += messageBytes;
if (pendingBytes > 0 && pendingBytes + messageBytes > maxBytes) {
flush();
}
pendingMessages.push(message);
pendingBytes += messageBytes;
if (pendingBytes >= maxBytes) {
flush();
}
}
flush();
return logicalWriteBytes;
}
const toLogMessage = Effect.fn("toLogMessage")(function* (
event: unknown,
): Effect.fn.Return<string | undefined> {
@@ -144,14 +179,9 @@ const makeThreadWriter = Effect.fn("makeThreadWriter")(function* (input: {
const startedAt = yield* Clock.currentTimeMillis;
const flushResult = yield* Effect.sync(() => {
try {
let logicalWriteBytes = 0;
for (const message of messages) {
sink.write(message);
logicalWriteBytes += textEncoder.encode(message).byteLength;
}
return {
ok: true as const,
logicalWriteBytes,
logicalWriteBytes: writeBatchedMessages(sink, messages, input.maxBytes),
count: messages.length,
};
} catch (error) {