chore: strip per-request DEBUG logs from chat path

Remove [DBG:STREAM] chunk/pipe/EOF instrumentation and [DBG:SSE] flush +
fetch success lines that spam the dev console every request. Keep the stream
stall watchdog and the fetch-error (✖) diagnostics.
This commit is contained in:
MUH. IQRAM BAHRING
2026-08-07 04:24:54 +08:00
parent ad43a267ac
commit 041e039793
4 changed files with 5 additions and 33 deletions
+5 -21
View File
@@ -1,6 +1,6 @@
// Stream handler with disconnect detection - shared for all providers
import { STREAM_STALL_TIMEOUT_MS } from "../config/runtimeConfig.js";
import { dbg, isDebugEnabled } from "./debugLog.js";
import { dbg } from "./debugLog.js";
// Get HH:MM:SS timestamp
function getTimeString() {
@@ -190,11 +190,6 @@ export function createDisconnectAwareStream(transformStream, streamController, o
*/
export function pipeWithDisconnect(providerResponse, transformStream, streamController, onAbortTerminal = null, stallTimeoutMs = STREAM_STALL_TIMEOUT_MS) {
let stallTimer = null;
let chunkCount = 0;
let totalBytes = 0;
let lastChunkAt = Date.now();
const t0 = Date.now();
const tag = "STREAM";
const clearStall = () => {
if (stallTimer) { clearTimeout(stallTimer); stallTimer = null; }
};
@@ -202,7 +197,6 @@ export function pipeWithDisconnect(providerResponse, transformStream, streamCont
clearStall();
stallTimer = setTimeout(() => {
stallTimer = null;
dbg(tag, `STALL TIMEOUT ${stallTimeoutMs}ms | chunks=${chunkCount} | bytes=${totalBytes} | sinceLast=${Date.now() - lastChunkAt}ms`);
streamController.handleError?.(new Error("stream stall timeout"));
streamController.abort?.();
}, stallTimeoutMs);
@@ -215,30 +209,20 @@ export function pipeWithDisconnect(providerResponse, transformStream, streamCont
signal: streamController.signal,
startTime: streamController.startTime,
isConnected: () => streamController.isConnected(),
handleComplete: () => { dbg(tag, `complete | chunks=${chunkCount} | bytes=${totalBytes} | dur=${Date.now() - t0}ms`); clearStall(); streamController.handleComplete(); },
handleError: (e) => { dbg(tag, `error: ${e?.message} | chunks=${chunkCount} | bytes=${totalBytes} | dur=${Date.now() - t0}ms`); clearStall(); streamController.handleError(e); },
handleDisconnect: (r) => { dbg(tag, `disconnect: ${r} | chunks=${chunkCount} | bytes=${totalBytes} | dur=${Date.now() - t0}ms`); clearStall(); streamController.handleDisconnect(r); },
handleComplete: () => { clearStall(); streamController.handleComplete(); },
handleError: (e) => { clearStall(); streamController.handleError(e); },
handleDisconnect: (r) => { clearStall(); streamController.handleDisconnect(r); },
abort: () => { clearStall(); streamController.abort(); }
};
armStall();
dbg(tag, `pipe start | stallTimeout=${stallTimeoutMs}ms`);
const upstreamTap = new TransformStream({
transform(chunk, controller) {
chunkCount++;
const sz = chunk?.byteLength || chunk?.length || 0;
totalBytes += sz;
const now = Date.now();
const gap = now - lastChunkAt;
lastChunkAt = now;
if (isDebugEnabled && (chunkCount <= 5 || chunkCount % 20 === 0 || gap > 5000)) {
dbg(tag, `chunk #${chunkCount} | size=${sz}B | gap=${gap}ms | total=${totalBytes}B`);
}
armStall();
controller.enqueue(chunk);
},
flush() { dbg(tag, `upstream EOF | chunks=${chunkCount} | bytes=${totalBytes} | dur=${Date.now() - t0}ms`); clearStall(); }
flush() { clearStall(); }
});
const transformedBody = providerResponse.body