Skip to content

Conversation

stephentoub
Copy link
Member

No description provided.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Allows in-process runtime subscriptions to run in parallel instead of sequentially by collecting processing tasks and awaiting them together.

  • Switches from catching and aggregating exceptions to spawning tasks and using Task.WhenAll
  • Introduces a static local function ProcessSubscriptionAsync for each subscription
  • Changes the topic-match check to add matching subscriptions to the task list
Comments suppressed due to low confidence (3)

dotnet/src/Microsoft.Extensions.AI.Agents.Runtime.Abstractions/InProcessRuntime.cs:265

  • [nitpick] The variable name tasks is generic and may be ambiguous; consider renaming it to subscriptionTasks to clarify that it holds subscription processing tasks.
            List<Task>? tasks = null;

dotnet/src/Microsoft.Extensions.AI.Agents.Runtime.Abstractions/InProcessRuntime.cs:297

  • This change introduces parallel execution of subscription handlers. Please add or update tests to verify behavior when multiple subscriptions run concurrently, including cases with successful, faulted, and cancelled tasks.
                await Task.WhenAll(tasks).ConfigureAwait(false);

dotnet/src/Microsoft.Extensions.AI.Agents.Runtime.Abstractions/InProcessRuntime.cs:271

  • Launching all subscription handlers as concurrent tasks can introduce race conditions if the underlying ISubscriptionDefinition implementations or actor interactions are not thread-safe; ensure those components can handle parallel execution or serialize access where necessary.
                    (tasks ??= []).Add(ProcessSubscriptionAsync(message, subscription.Value, topic, cancellationToken));

Copy link
Contributor

@crickman crickman left a comment

Choose a reason for hiding this comment

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

Beautiful

@stephentoub
Copy link
Member Author

stephentoub commented Jul 12, 2025

How important is it that we throw an AggregateException with all the exceptions? I neglected to do so, such that right now tests are failing because only the first exception is propagating. I can fix it to be an aggregate if that's important...? Otherwise I'll fix the tests.

@stephentoub stephentoub merged commit 80c1e2e into microsoft:main Jul 12, 2025
7 checks passed
@stephentoub stephentoub deleted the subparallel branch July 12, 2025 01:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants