Skip to content

Deprecate IStartupTask and AddStartupTask with warnings#9763

Merged
ReubenBond merged 7 commits intomainfrom
copilot/deprecate-addstartuptask-and-istartuptask
Nov 10, 2025
Merged

Deprecate IStartupTask and AddStartupTask with warnings#9763
ReubenBond merged 7 commits intomainfrom
copilot/deprecate-addstartuptask-and-istartuptask

Conversation

Copy link
Contributor

Copilot AI commented Nov 10, 2025

Deprecates IStartupTask interface and AddStartupTask extension methods per Microsoft's recommendation to use BackgroundService or IHostedService instead. These standard .NET hosting mechanisms provide better error handling and don't cause silo unavailability on transient failures.

Changes

  • Added [Obsolete] attributes with error: false to:
    • IStartupTask interface
    • All three AddStartupTask method overloads (generic, interface-typed, delegate-typed)
  • Regenerated API surface file to reflect deprecation attributes
  • Suppressed CS0618 warnings in existing test files using #pragma warning disable

Deprecation Warning

Users will see compiler warnings pointing to the documentation:

// Now generates CS0618 warning with guidance
public class MyStartupTask : IStartupTask
{
    public Task Execute(CancellationToken cancellationToken) => Task.CompletedTask;
}

builder.UseOrleans(silo => silo.AddStartupTask<MyStartupTask>());

Warning message: "IStartupTask is deprecated. Use BackgroundService or IHostedService instead. See https://learn.microsoft.com/dotnet/orleans/host/configuration-guide/startup-tasks for more information."

Original prompt

This section details on the original issue you should resolve

<issue_title>Deprecate AddStartupTask and IStartupTask</issue_title>
<issue_description>See the documentation notes here: https://learn.microsoft.com/en-us/dotnet/orleans/host/configuration-guide/startup-tasks#orleans-startup-tasks

While startup tasks are still supported, we recommend using BackgroundService or IHostedService instead, as they are the standard .NET hosting mechanism for running background tasks.

and

Any exceptions thrown from a startup task are reported in the silo log and stop the silo. This fail-fast approach helps detect configuration and bootstrap issues during testing rather than causing unexpected problems later. However, it can also mean that transient failures in a startup task cause host unavailability.

Make the deprecation a warning and point to the documentation for alternatives.</issue_description>

<agent_instructions>Read the linked documentation first.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Microsoft Reviewers: Open in CodeFlow

Co-authored-by: ReubenBond <203839+ReubenBond@users.noreply.github.com>
Copilot AI changed the title [WIP] Deprecate AddStartupTask and IStartupTask with warnings Deprecate IStartupTask and AddStartupTask with warnings Nov 10, 2025
Copilot AI requested a review from ReubenBond November 10, 2025 21:54

public static partial class SiloBuilderStartupExtensions
{
[System.Obsolete("AddStartupTask is deprecated. Use BackgroundService or IHostedService instead. See https://learn.microsoft.com/dotnet/orleans/host/configuration-guide/startup-tasks for more information.", false)]
Copy link
Member

Choose a reason for hiding this comment

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

Undo all changes under the src/api directory

@ReubenBond ReubenBond marked this pull request as ready for review November 10, 2025 23:00
Copilot AI review requested due to automatic review settings November 10, 2025 23:00
@ReubenBond ReubenBond enabled auto-merge November 10, 2025 23:00
Copy link
Contributor

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

This PR deprecates the IStartupTask interface and AddStartupTask extension methods by marking them with [Obsolete] attributes (as warnings, not errors). The deprecation follows Microsoft's recommendation to use standard .NET hosting mechanisms like BackgroundService or IHostedService instead, which provide better error handling and don't cause silo unavailability on transient failures.

Key changes:

  • Added [Obsolete] attributes with descriptive messages and documentation links to IStartupTask and all three AddStartupTask method overloads
  • Suppressed CS0618 obsolete warnings in existing test files that legitimately use the deprecated APIs

Reviewed Changes

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

File Description
src/Orleans.Runtime/Lifecycle/IStartupTask.cs Added [Obsolete] attribute to the IStartupTask interface with guidance message
src/Orleans.Runtime/Hosting/SiloBuilderStartupExtensions.cs Added [Obsolete] attributes to all three AddStartupTask method overloads with consistent guidance messages
test/Tester/StartupTaskTests.cs Added #pragma warning disable CS0618 to suppress obsolete warnings for existing tests that verify startup task functionality

@ReubenBond ReubenBond added this pull request to the merge queue Nov 10, 2025
Merged via the queue into main with commit 1a1a8c1 Nov 10, 2025
38 of 42 checks passed
@ReubenBond ReubenBond deleted the copilot/deprecate-addstartuptask-and-istartuptask branch November 10, 2025 23:52
ReubenBond added a commit that referenced this pull request Nov 18, 2025
github-merge-queue bot pushed a commit that referenced this pull request Nov 18, 2025
Revert "Deprecate IStartupTask and AddStartupTask with warnings (#9763)"

This reverts commit 1a1a8c1.
@github-actions github-actions bot locked and limited conversation to collaborators Dec 11, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deprecate AddStartupTask and IStartupTask

2 participants

Comments