Recreate session on RunnerSessionInvalid from broker#4556
Merged
luketomlinson merged 5 commits intoJul 16, 2026
Conversation
The actions-broker-listener now returns HTTP 400 with a structured broker error body of errorKind "RunnerSessionInvalid" when a runner polls or acknowledges with an invalid session. Map that errorKind to TaskAgentSessionExpiredException and, in BrokerMessageListener, recreate the session and keep polling instead of failing with a misleading 'runner deprecated' error. This mirrors the legacy MessageListener pipelines behavior. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
luketomlinson
force-pushed
the
luketomlinson-recreate-session-on-runner-session-inval
branch
from
July 14, 2026 18:23
1280604 to
bc7df92
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the broker polling path so that when the broker returns a structured RunnerSessionInvalid error (HTTP 400), the runner treats it like an expired session, recreates the session, and continues polling—matching the legacy/MessageListener behavior and avoiding misleading fatal “deprecated runner” failures.
Changes:
- Add
RunnerSessionInvalidtoBrokerErrorKind. - Map
RunnerSessionInvalidtoTaskAgentSessionExpiredExceptioninBrokerHttpClient.GetRunnerMessageAsync. - Update
BrokerMessageListener.GetNextMessageAsyncto recreate the session onTaskAgentSessionExpiredException(unlessSkipSessionRecover), plus an L0 test validating the listener recovery behavior.
Show a summary per file
| File | Description |
|---|---|
| src/Test/L0/Listener/BrokerMessageListenerL0.cs | Adds an L0 test asserting session recreation and continued polling after TaskAgentSessionExpiredException. |
| src/Sdk/WebApi/WebApi/BrokerHttpClient.cs | Maps broker error kind RunnerSessionInvalid to TaskAgentSessionExpiredException for GET /message. |
| src/Sdk/RSWebApi/Contracts/BrokerErrorKind.cs | Introduces the RunnerSessionInvalid broker error-kind constant. |
| src/Runner.Listener/BrokerMessageListener.cs | Adds recovery logic to recreate the session when TaskAgentSessionExpiredException occurs during broker polling. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 4
- Review effort level: Low
Comment on lines
126
to
130
| case BrokerErrorKind.HostedRunnerDeprovisioned: | ||
| throw new HostedRunnerDeprovisionedException(brokerError.Message); | ||
| case BrokerErrorKind.RunnerSessionInvalid: | ||
| throw new TaskAgentSessionExpiredException(brokerError.Message); | ||
| default: |
Comment on lines
126
to
130
| case BrokerErrorKind.HostedRunnerDeprovisioned: | ||
| throw new HostedRunnerDeprovisionedException(brokerError.Message); | ||
| case BrokerErrorKind.RunnerSessionInvalid: | ||
| throw new TaskAgentSessionExpiredException(brokerError.Message); | ||
| default: |
Comment on lines
126
to
130
| case BrokerErrorKind.HostedRunnerDeprovisioned: | ||
| throw new HostedRunnerDeprovisionedException(brokerError.Message); | ||
| case BrokerErrorKind.RunnerSessionInvalid: | ||
| throw new TaskAgentSessionExpiredException(brokerError.Message); | ||
| default: |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Treat TaskAgentSessionExpiredException as non-retriable in BrokerServer.ShouldRetryException so a RunnerSessionInvalid propagates immediately to the recover branch instead of being retried 5x. Reword the recover-branch comment to reference the runner session/service rather than the DT agent session. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
luketomlinson
commented
Jul 15, 2026
| @@ -108,7 +108,7 @@ public Task ForceRefreshConnection(VssCredentials credentials) | |||
|
|
|||
| public bool ShouldRetryException(Exception ex) | |||
Contributor
Author
There was a problem hiding this comment.
maybe this layer is unnecessary, I'm not sure
aiqiaoy
approved these changes
Jul 16, 2026
luketomlinson
deleted the
luketomlinson-recreate-session-on-runner-session-inval
branch
July 16, 2026 20:00
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.
What
The service is changing so that when a runner polls (
GET /message) or acknowledges with an invalid session, it returns HTTP 400 with a structured broker error body:{"source":"actions-broker-listener","errorKind":"RunnerSessionInvalid","statusCode":400,"errorMessage":"Runner session is invalid"}instead of a bare
403. Today a bare403makes the runner throw a fatal, misleadingAccessDeniedException{ErrorCode=1}("runner deprecated") and stop.This PR makes the broker path behave like legacy Azure Pipelines did: on an expired/invalid session the runner recreates its session and keeps polling.
This brings it into parity with the MessageListener.cs
Changes
BrokerErrorKind.cs— add theRunnerSessionInvalidconstant.BrokerHttpClient.GetRunnerMessageAsync— mapRunnerSessionInvalidtoTaskAgentSessionExpiredException.BrokerMessageListener.GetNextMessageAsync— mirror legacyMessageListener: onTaskAgentSessionExpiredException(and when!SkipSessionRecover), recreate the session and continue polling instead of throwing a non-retryable error.Added an L0 test asserting that when
GetRunnerMessageAsyncthrowsTaskAgentSessionExpiredException, the listener recreates the session and continues polling.Rollout
Companion service PR: github/actions-broker-listener#2490. The runner change must roll out BEFORE the service enables its
RejectInvalidSessionsflag.Co-authored-by: Copilot App 223556219+Copilot@users.noreply.github.com