Skip to content

Commit d624cbd

Browse files
committed
refactor(runtime): drop unused receiver from handleStream
handleStream is the chunked-stream aggregator that turns an LLM provider's chat.MessageStream into a streamResult plus a sequence of events. It was declared as a method on *LocalRuntime, but its body never touches `r` — the receiver is purely an artefact of where the file sits. Drop it. This is a pure isolation win, not a behaviour change: - handleStream is now a free function, callable (and unit-testable) without spinning up a LocalRuntime, a team, hooks, or anything else; a mock chat.MessageStream is the only dependency. - The events parameter tightens from `chan Event` to `chan<- Event`, matching the rest of the package's send-only conventions and documenting that the function never reads from the channel. - Doc comment now states the dependency direction explicitly: the loop calls into the chunker, never the reverse. - Only caller (tryModelWithFallback in fallback.go) updated to drop the `r.` qualifier. streamResult and stripImageContent are unchanged. A future follow-up could lift this into pkg/runtime/internal/streamproc to enforce the boundary at compile time, but that requires inverting the events-channel dependency (Event is currently a runtime type) and is out of scope here. Assisted-By: docker-agent
1 parent b27e9d2 commit d624cbd

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

pkg/runtime/fallback.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ func (r *LocalRuntime) tryModelWithFallback(
285285
}
286286
}
287287

288-
res, err := r.handleStream(ctx, stream, a, agentTools, sess, m, events)
288+
res, err := handleStream(ctx, stream, a, agentTools, sess, m, events)
289289
if err != nil {
290290
lastErr = err
291291

pkg/runtime/streaming.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@ type streamResult struct {
3434
// events (content deltas, partial tool calls, reasoning tokens) and returning
3535
// the aggregated streamResult. The caller is responsible for adding the
3636
// resulting assistant message to the session.
37-
func (r *LocalRuntime) handleStream(ctx context.Context, stream chat.MessageStream, a *agent.Agent, agentTools []tools.Tool, sess *session.Session, m *modelsdev.Model, events chan Event) (streamResult, error) {
37+
//
38+
// handleStream is a pure stream-aggregation routine: it does not touch
39+
// runtime state and can be unit-tested by feeding a mock chat.MessageStream.
40+
// It is intentionally a free function rather than a method on *LocalRuntime
41+
// so the dependency direction is explicit (the loop calls into the chunker,
42+
// never the reverse).
43+
func handleStream(ctx context.Context, stream chat.MessageStream, a *agent.Agent, agentTools []tools.Tool, sess *session.Session, m *modelsdev.Model, events chan<- Event) (streamResult, error) {
3844
defer stream.Close()
3945

4046
var fullContent strings.Builder

0 commit comments

Comments
 (0)