Skip to content

Commit dde8b6a

Browse files
foxy1402Copilot
andcommitted
Add detailed timing logs for stream diagnostics
- Log stream start time, keepalive send time, first chunk time - Log exact disconnect timing to diagnose premature closes - Will help identify if qodercli is too slow or client is too aggressive Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent f549f50 commit dde8b6a

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/routes/chat.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,17 @@ router.post('/', (req, res) => {
7979
if (stream) {
8080
setSSEHeaders(res);
8181

82+
const streamStartTime = Date.now();
83+
console.log('[Stream Timing] Stream started at', streamStartTime);
84+
8285
// Disable socket timeout and enable keepalive for long-running streams
8386
req.socket.setTimeout(0);
8487
req.socket.setKeepAlive(true);
8588

8689
// Send SSE comment immediately to keep connection alive (IDE compatibility)
8790
// Don't send an empty delta - some IDEs interpret that as end of stream
8891
res.write(': keep-alive\n\n');
92+
console.log('[Stream Timing] Keepalive sent at', Date.now() - streamStartTime, 'ms');
8993

9094
// Explicitly flush the response buffer
9195
if (typeof res.flush === 'function') res.flush();
@@ -103,6 +107,10 @@ router.post('/', (req, res) => {
103107
const toolCalls = extractToolCalls(data.message?.content);
104108
const finishReason = data.message?.stop_reason || null;
105109

110+
if (!hasReceivedData) {
111+
console.log('[Stream Timing] First chunk received at', Date.now() - streamStartTime, 'ms');
112+
}
113+
106114
if (finishReason) lastFinishReason = finishReason;
107115

108116
if (toolCalls && toolCalls.length > 0) {
@@ -142,6 +150,8 @@ router.post('/', (req, res) => {
142150
});
143151

144152
req.on('close', () => {
153+
const disconnectTime = Date.now() - streamStartTime;
154+
console.log('[Stream Timing] Client disconnected at', disconnectTime, 'ms');
145155
if (!hasReceivedData) {
146156
console.log('[chat/completions] Client disconnected before receiving any data');
147157
}

0 commit comments

Comments
 (0)