Skip to content

Propagate run context through agent streams - #4753

Merged
asim merged 1 commit into
masterfrom
codex/increment-4752
Jul 11, 2026
Merged

Propagate run context through agent streams#4753
asim merged 1 commit into
masterfrom
codex/increment-4752

Conversation

@asim

@asim asim commented Jul 11, 2026

Copy link
Copy Markdown
Member

Propagates agent run context into provider streaming calls and skips provider/memory work when a stream is already canceled.

Testing:

  • go build ./...
  • go test ./agent
  • go test ./... (fails in sandbox due existing loopback/env provider restrictions)
  • golangci-lint run ./... (fails because installed lint binary was built with Go 1.24 while the module targets Go 1.25.12)

Closes #4750
Closes #4752

@asim asim added the codex label Jul 11, 2026
Copilot AI review requested due to automatic review settings July 11, 2026 22:57
@asim asim added the codex label Jul 11, 2026
@asim
asim merged commit 3995ed9 into master Jul 11, 2026
12 checks passed

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 improves agent streaming behavior by threading ai.RunInfo through the agentImpl.Stream call path so downstream providers can observe run metadata, and by avoiding work when the caller’s context is already canceled.

Changes:

  • Attach ai.RunInfo (RunID/ParentID/Agent) to the context used for provider streaming calls.
  • Short-circuit agentImpl.Stream early when ctx is already canceled, and add tests asserting provider/memory are skipped on pre-canceled contexts.
  • Extend streaming tests to assert providers receive RunInfo.

Reviewed changes

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

File Description
agent/agent.go Adds context cancellation short-circuiting and injects ai.RunInfo into provider streaming calls.
agent/stream_test.go Adds assertions that RunInfo reaches the provider stream and that canceled contexts skip provider/memory.

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

Comment thread agent/agent.go
Comment on lines 237 to +246
toolList, err := a.discoverTools()
if err != nil {
return nil, fmt.Errorf("discover tools: %w", err)
}
runID := uuid.New().String()
ctx = ai.WithRunInfo(ctx, ai.RunInfo{
RunID: runID,
ParentID: a.parentRunID,
Agent: a.opts.Name,
})
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 #210 Propagate agent run cancellation and deadlines through model and tool calls

3 participants