Skip to content

Keep the Copilot run alive on rate-limit errors eligible for auto-switch - #714

Merged
George Adams (gdams) merged 1 commit into
microsoft:mainfrom
PratikDhanaveFork:copilot-rate-limit-auto-switch
Jul 29, 2026
Merged

Keep the Copilot run alive on rate-limit errors eligible for auto-switch#714
George Adams (gdams) merged 1 commit into
microsoft:mainfrom
PratikDhanaveFork:copilot-rate-limit-auto-switch

Conversation

@PratikDhanave

Copy link
Copy Markdown
Contributor

What

responseUpdateForSessionEvent in provider/copilotprovider/copilot.go mapped every *copilot.SessionErrorData to a terminal (done=true, error), so the run loop yielded the error and returned, terminating the session.

The Copilot SDK sets SessionErrorData.EligibleForAutoSwitch only on errorType: "rate_limit", documented as: when true, the runtime will follow this error with an auto_mode_switch.requested event and keep the session alive (or silently switch). The follow-up auto_mode_switch.requested/completed events are already handled by the provider's default (non-terminal) case, and the run naturally completes on the subsequent session.idle.

This change dereferences EligibleForAutoSwitch in the SessionErrorData case: when non-nil and true, the error is surfaced as a non-terminal raw notification (done=false, err=nil) so the loop keeps pumping the auto-switch events and the eventual idle completion. Every other session error (nil/false flag, or any non-rate-limit type) keeps the existing terminal behavior. Recovery is confined to exactly the SDK-documented rate-limit auto-switch case.

Why

This aligns the Go provider with the runtime contract the SDK exposes via EligibleForAutoSwitch: a rate-limit that the runtime is about to auto-recover from should not surface to the caller as a fatal run error. Treating these as terminal caused spurious run failures on transient, auto-recoverable rate limits.

Tests

Added to the canonical copilot_test.go, driving the full run loop through the existing fake-runtime harness:

  • TestRun_WithRateLimitEligibleForAutoSwitch_KeepsSessionAlive — a session.error with errorType: "rate_limit" and eligibleForAutoSwitch: true, followed by auto_mode_switch.requested, an assistant.message, and session.idle. Asserts the run does not fail and emits the assistant message.
  • TestRun_WithRateLimitNotEligibleForAutoSwitch_ReturnsError — a rate-limit error without the flag still terminates with the session error.

Both tests fail before the fix and pass after. go build ./..., go vet ./provider/copilotprovider/..., and go test ./provider/copilotprovider/... all pass.

Copilot AI review requested due to automatic review settings July 24, 2026 02:57
@PratikDhanave
PratikDhanave (PratikDhanave) requested a review from a team as a code owner July 24, 2026 02:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This pull request updates the Copilot Go provider’s session event handling so that session.error events representing rate-limit errors that the runtime will auto-recover from (via EligibleForAutoSwitch) do not terminate the run loop. This aligns provider behavior with the Copilot SDK/runtime contract by allowing the session to continue through subsequent auto-switch events and complete normally on session.idle.

Changes:

  • Treat SessionErrorData.EligibleForAutoSwitch == true as a non-terminal session notification (no error returned, run loop continues).
  • Add an end-to-end fake-runtime test asserting the run survives an eligible rate-limit error and still emits the assistant message.
  • Add a test asserting a rate-limit error without the eligibility flag remains terminal and returns the session error.

Reviewed changes

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

File Description
provider/copilotprovider/copilot.go Makes eligible rate-limit session.error non-terminal so the run loop can process auto-switch and reach session.idle.
provider/copilotprovider/copilot_test.go Adds regression tests covering eligible vs non-eligible rate-limit errors through the full run loop.

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

@github-actions

This comment has been minimized.

@github-actions github-actions Bot added the parity-approved Go API consistency review found no parity issues label Jul 24, 2026
responseUpdateForSessionEvent mapped every session.error to a terminal
error, aborting the run. The SDK sets SessionErrorData.EligibleForAutoSwitch
only on errorType "rate_limit" to signal that the runtime will follow the
error with an auto_mode_switch.requested event and keep the session alive.
When that flag is set, surface the error as a non-terminal notification so
the run loop keeps pumping the auto-switch events and the eventual idle
completion instead of terminating. All other session errors keep the
existing terminal behavior.
@github-actions

Copy link
Copy Markdown
Contributor

Parity Review: No Issues Found

This PR modifies only an unexported internal function (responseUpdateForSessionEvent) inside provider/copilotprovider/copilot.go. No exported Go API surface is added, removed, or changed.

The behavioral change is specific to the GitHub Copilot SDK (EligibleForAutoSwitch on SessionErrorData), which is a Go-provider-specific integration contract. The upstream microsoft/agent-framework .NET and Python implementations do not have a Copilot SDK provider equivalent, so cross-repo parity does not apply here.

Verdict: This PR stays within Go-internal implementation details. Cross-repo parity is preserved. The parity-approved label remains correct. The public-api-change label is not warranted.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • awmgmcpg

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "awmgmcpg"

See Network Configuration for more information.

Generated by Go API Consistency Review Agent · 22.2 AIC · ⌖ 5.53 AIC · ⊞ 5.9K ·

@gdams
George Adams (gdams) added this pull request to the merge queue Jul 29, 2026
Merged via the queue into microsoft:main with commit 1bb0ffb Jul 29, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

parity-approved Go API consistency review found no parity issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants