Skip to content

refactor(agent): return streamedTurn from streamWithFrozen - #7786

Merged
esengine merged 2 commits into
main-v2from
refactor/agent-stream-turn
Aug 7, 2026
Merged

refactor(agent): return streamedTurn from streamWithFrozen#7786
esengine merged 2 commits into
main-v2from
refactor/agent-stream-turn

Conversation

@esengine

@esengine esengine commented Aug 6, 2026

Copy link
Copy Markdown
Owner

Part of the agent god-object cleanup series (agent.go grew to 4.7k LOC / Agent to 99 fields over the last 6 weeks).

What

  • streamWithFrozen returned 13 positional values; its only consumers were stream (same tuple) and streamTurnFrozen, whose sole purpose was to repack the tuple into the existing streamedTurn struct. It now returns streamedTurn directly.
  • Deleted the streamTurnFrozen wrapper; streamWithSamplingRecovery calls streamWithFrozen directly.
  • The six mid-stream exit paths (ctx cancel, channel close on cancel, reasoning byte limit, stream interrupt, chunk error ×2) share a collect helper; the clean-terminal and intercept-error paths keep explicit literals because they run under the interceptProviderResponse shadowed scope and override fields (partialToolStarted forced false on clean terminal, now stated in a comment instead of an anonymous positional false).

Pure mechanical repack — no behavior change.

Verification

  • gofmt clean, go vet ./internal/agent/... clean
  • go test ./internal/agent/ and go test -race ./internal/agent/ green
  • Full go test ./... green (English locale)

Cache-impact: none - pure mechanical repack of streamWithFrozen return values into the existing streamedTurn struct; no request building, cache_control placement, or usage accounting logic changes.
Cache-guard: existing coverage - internal/agent cache_shape_test.go and usage_accounting_test.go pass unchanged (go test -race ./internal/agent/).
Documentation-impact: none - internal refactor with no user-visible behavior change; no docs describe these internals.

streamWithFrozen returned 13 positional values whose only consumer
immediately repacked them into streamedTurn via the streamTurnFrozen
wrapper. Return the struct directly, delete the wrapper, and share a
collect helper across the mid-stream exit paths. No behavior change.
@esengine
esengine requested a review from SivanCola as a code owner August 6, 2026 15:31
@github-actions github-actions Bot added v2 Go rewrite (1.x) — main-v2 branch, active development agent Core agent loop (internal/agent, internal/control) labels Aug 6, 2026
@esengine
esengine merged commit 41cf534 into main-v2 Aug 7, 2026
22 checks passed
@esengine
esengine deleted the refactor/agent-stream-turn branch August 7, 2026 00:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent Core agent loop (internal/agent, internal/control) v2 Go rewrite (1.x) — main-v2 branch, active development

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant