MCPcopy Create free account
hub / github.com/codehamr/codehamr / sendChat

Method sendChat

internal/llm/llm.go:355–368  ·  view source on GitHub ↗

sendChat POSTs the request and returns the response on 200. On failure it returns the Event the caller forwards, populated with Kind/Err/Budget. The body is closed on every non-200 branch; 200 leaves it open for the caller.

(parent context.Context, msgs []chmctx.Message, tools []Tool)

Source from the content-addressed store, hash-verified

353 }
354 if errEvt != nil {
355 sendEvent(parent, out, *errEvt)
356 return
357 }
358 defer resp.Body.Close()
359
360 // Idle watchdog: bufio.Scanner.Scan() ignores context, so a server that
361 // stops sending after 200 OK would wedge readSSE forever. Closing the body
362 // from the timer unblocks the in-flight Read; readSSE then returns and we
363 // surface a stall. parent isn't cancelled, so (unlike Ctrl+C) the error
364 // reaches the user.
365 //
366 // TWO windows, not one. The silent pre-first-token prefill scales with the
367 // packed context and can legitimately run many minutes, so it gets the long
368 // window. Every window after the first covers a LIVE stream, where minutes
369 // of silence means a dead socket, so readSSE's onFrame swaps in the short
370 // one. Arming both at the prefill length is what let a dropped connection
371 // cost a full hour of an unattended run.

Callers 1

runMethod · 0.95

Calls 2

postChatMethod · 0.95
toWireFunction · 0.85

Tested by

no test coverage detected