Skip to content

agent: cancel StreamAsk on close#4226

Merged
asim merged 1 commit into
masterfrom
codex/increment-4225
Jul 7, 2026
Merged

agent: cancel StreamAsk on close#4226
asim merged 1 commit into
masterfrom
codex/increment-4225

Conversation

@asim

@asim asim commented Jul 7, 2026

Copy link
Copy Markdown
Member

Summary:

  • Cancel StreamAsk and ResumeStreamAsk contexts when callers close the stream so in-flight model calls can stop promptly.
  • Add coverage proving Close cancels an in-flight streaming model call.

Testing:

  • go build ./...
  • go test ./... (fails in this environment: atlascloud fixture reached provider endpoint and loopback gRPC tests are blocked by envoy)
  • golangci-lint run ./... --timeout=10m

Closes #4217
Closes #4225

Copilot AI review requested due to automatic review settings July 7, 2026 08:04
@asim asim added the codex label Jul 7, 2026
@asim asim merged commit 32d0c46 into master Jul 7, 2026
11 checks passed
@asim asim deleted the codex/increment-4225 branch July 7, 2026 08:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the agent streaming implementation so callers can cancel in-flight model work when they close a StreamAsk/ResumeStreamAsk stream, and adds a regression test asserting that Close() cancels an in-flight model call.

Changes:

  • Wrap StreamAsk / resumeStreamAsk contexts with context.WithCancel and plumb the cancel func into agentStream.Close().
  • Add a test that verifies Close() cancels a blocked model Generate call.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
agent/stream.go Adds per-stream cancelation and triggers it from AgentStream.Close().
agent/stream_test.go Adds coverage to ensure closing a stream cancels an in-flight model call.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread agent/stream.go
Comment on lines 79 to 83
go func() {
defer close(events)
defer close(done)
resp, err := a.askWithStreamEvents(ctx, message, events)
resp, err := a.askWithStreamEvents(streamCtx, message, events)
if err != nil {
Comment thread agent/stream.go
Comment on lines 103 to 107
go func() {
defer close(events)
defer close(done)
resp, err := a.resumeWithStreamEvents(ctx, runID, events)
resp, err := a.resumeWithStreamEvents(streamCtx, runID, events)
if err != nil {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Loop: build increment #114 ai: broaden provider streaming coverage through chat and A2A

3 participants