refactor(runtime): drop unused receiver from handleStream#2539
Merged
dgageot merged 1 commit intodocker:mainfrom Apr 27, 2026
Merged
refactor(runtime): drop unused receiver from handleStream#2539dgageot merged 1 commit intodocker:mainfrom
dgageot merged 1 commit intodocker:mainfrom
Conversation
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
rumpl
approved these changes
Apr 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
handleStreamis the chunked-stream aggregator inpkg/runtime/streaming.go— it consumes an LLM provider'schat.MessageStreamand turns the deltas into an aggregatedstreamResultplus events on theeventschannel.It was declared as a method on
*LocalRuntime, but its body nevertouches
r. The receiver is a pure artefact of where the file sits.Drop it, tighten the events channel direction, document why.
What this is, and what it isn't
This is a pure isolation win:
handleStreambecomes a free function. It is now unit-testablewith a mock
chat.MessageStreamalone — noLocalRuntime, team,hooks, model store, or any of the other runtime wiring required.
events chan Event→events chan<- Eventmatches the rest ofthe package's send-only conventions (
swapCurrentAgentetc.) anddocuments at compile time that the function never reads.
calls into the chunker, never the reverse.
This is not:
streamResultstays unexported inpkg/runtime. Lifting this intopkg/runtime/internal/streamprocwould require inverting the events-channel dependency (
Eventiscurrently a runtime-defined type), which is a much larger refactor
and explicitly out of scope here.
handleStreamis still ~200 lines doing tool-callaggregation, content/reasoning aggregation, usage tracking, and
finish-reason coercion. Those concerns could be split, but that's
a separate refactor.
Diff
Two files, six lines of substantive change:
pkg/runtime/streaming.go: drop(r *LocalRuntime), tightenchannel direction, add doc paragraph explaining why.
pkg/runtime/fallback.go: drop ther.qualifier at the singlecall site.
streamResultandstripImageContentare unchanged.Validation
mise lint— 0 issuesmise test— full suite passes (existingstripImageContenttable test still works since both functions live in the same
package)