Bug
The chat-path /imagegen command handler (the one that wraps image generation as a synthetic chat completion) creates an imagegenAbort AbortController and correctly passes its signal to payFetch and the poll loop. But the outer catch (err) at line 4300 does not check imagegenAbort.signal.aborted before logging and writing the error response.
When the client disconnects mid-generation, the AbortError propagates to this catch, logs a spurious [ClawRouter] /imagegen error: The operation was aborted and attempts res.writeHead(500) on the already-closed socket.
Current code (line 4300)
} catch (err) {
const errMsg = err instanceof Error ? err.message : String(err);
console.error(`[ClawRouter] /imagegen error: ${errMsg}`);
if (!res.headersSent) {
res.writeHead(500, ...);
Expected (matches chat-path /img2img at line 4512)
} catch (err) {
if (imagegenAbort.signal.aborted) return; // client gone nothing to report
const errMsg = err instanceof Error ? err.message : String(err);
console.error(`[ClawRouter] /imagegen error: ${errMsg}`);
Working references
- API-path image gen catch (line 2808):
if (clientAbort.signal.aborted) return; ✅
- Chat-path
/img2img catch (line 4512): if (img2imgAbort.signal.aborted) return; ✅
- API-path img2img catch (line 2952):
if (clientAbort.signal.aborted) return; ✅
Impact
Bogus error log noise on every client disconnect during /imagegen. Attempted write to closed socket (silently fails due to !res.headersSent guard, but the log line is still wrong).
Bug
The chat-path
/imagegencommand handler (the one that wraps image generation as a synthetic chat completion) creates animagegenAbortAbortController and correctly passes its signal topayFetchand the poll loop. But the outercatch (err)at line 4300 does not checkimagegenAbort.signal.abortedbefore logging and writing the error response.When the client disconnects mid-generation, the
AbortErrorpropagates to this catch, logs a spurious[ClawRouter] /imagegen error: The operation was abortedand attemptsres.writeHead(500)on the already-closed socket.Current code (line 4300)
Expected (matches chat-path /img2img at line 4512)
Working references
if (clientAbort.signal.aborted) return;✅/img2imgcatch (line 4512):if (img2imgAbort.signal.aborted) return;✅if (clientAbort.signal.aborted) return;✅Impact
Bogus error log noise on every client disconnect during
/imagegen. Attempted write to closed socket (silently fails due to!res.headersSentguard, but the log line is still wrong).