App-vNext/Polly · error · InvalidOperationException
Unable to accept outcome for a task that is not completed.
Error message
Unable to accept outcome for a task that is not completed.
What it means
AcceptOutcome() only succeeds when ExecutionTaskSafe is completed; otherwise it throws InvalidOperationException. The hedging controller calls AcceptOutcome to promote a hedged task's result, and accepting an incomplete task would lock in a result that has not yet been produced, breaking the hedging decision logic.
Source
Thrown at src/Polly.Core/Hedging/Controller/TaskExecution.cs:76
public ResilienceContext Context => _activeContext ?? throw new InvalidOperationException("TaskExecution is not initialized.");
public HedgedTaskType Type { get; set; }
public Action<TaskExecution<T>>? OnReset { get; set; }
public TimeSpan ExecutionTime => _timeProvider.GetElapsedTime(_startExecutionTimestamp, _stopExecutionTimestamp);
public int AttemptNumber { get; private set; }
public void AcceptOutcome()
{
if (ExecutionTaskSafe?.IsCompleted == true)
{
IsAccepted = true;
}
else
{
throw new InvalidOperationException("Unable to accept outcome for a task that is not completed.");
}
}
public void Cancel()
{
if (!IsAccepted)
{
_cancellationSource!.Cancel();
}
}
public async ValueTask<bool> InitializeAsync<TState>(
HedgedTaskType type,
ResilienceContext primaryContext,
Func<ResilienceContext, TState, ValueTask<Outcome<T>>> primaryCallback,
TState state,
int attemptNumber)
{View on GitHub (pinned to d0e46bdb1e)
Solutions
- Await ExecutionTaskSafe (which never throws) to completion before calling AcceptOutcome.
- If you only need the result, read Outcome after completion instead of forcing acceptance.
- Let the HedgingResilienceStrategy manage acceptance; do not call AcceptOutcome from user code.
Defensive patterns
Strategy: validation
Prevention
- Do not call AcceptOutcome from user code; the HedgingResilienceStrategy owns acceptance.
- If driving TaskExecution manually, await ExecutionTaskSafe to completion first.
- Prefer reading Outcome after completion over forcing acceptance early.
When it happens
Trigger: Calling AcceptOutcome on a TaskExecution whose ExecutionTaskSafe is null or still running. In normal flow the controller only accepts after awaiting completion; a misbehaving custom HedgingHandler or internal race that calls AcceptOutcome too early triggers it.
Common situations: Custom hedging action generators or test doubles that drive TaskExecution manually; instrumentation that races with the controller; a fork that reordered the accept/completion sequence.
Related errors
- TaskExecution is not initialized.
- Cannot add any more resilience strategies to the builder aft
- This instance of 'CircuitBreakerStateProvider' is already in
- No predicates were configured. There must be at least one pr
- Disposing this resilience pipeline is not allowed because it
AI-assisted analysis of App-vNext/Polly@d0e46bdb1e (2026-08-13).
Data as JSON: /api/errors/902593e96c348088.
Report an issue: GitHub.