{"record":{"id":"902593e96c348088","repo":"App-vNext/Polly","slug":"unable-to-accept-outcome-for-a-task-that-is-not-co","errorCode":null,"errorMessage":"Unable to accept outcome for a task that is not completed.","messagePattern":"Unable to accept outcome for a task that is not completed\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Polly.Core/Hedging/Controller/TaskExecution.cs","lineNumber":76,"sourceCode":"    public ResilienceContext Context => _activeContext ?? throw new InvalidOperationException(\"TaskExecution is not initialized.\");\n\n    public HedgedTaskType Type { get; set; }\n\n    public Action<TaskExecution<T>>? OnReset { get; set; }\n\n    public TimeSpan ExecutionTime => _timeProvider.GetElapsedTime(_startExecutionTimestamp, _stopExecutionTimestamp);\n\n    public int AttemptNumber { get; private set; }\n\n    public void AcceptOutcome()\n    {\n        if (ExecutionTaskSafe?.IsCompleted == true)\n        {\n            IsAccepted = true;\n        }\n        else\n        {\n            throw new InvalidOperationException(\"Unable to accept outcome for a task that is not completed.\");\n        }\n    }\n\n    public void Cancel()\n    {\n        if (!IsAccepted)\n        {\n            _cancellationSource!.Cancel();\n        }\n    }\n\n    public async ValueTask<bool> InitializeAsync<TState>(\n        HedgedTaskType type,\n        ResilienceContext primaryContext,\n        Func<ResilienceContext, TState, ValueTask<Outcome<T>>> primaryCallback,\n        TState state,\n        int attemptNumber)\n    {","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/App-vNext/Polly/blob/d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac/src/Polly.Core/Hedging/Controller/TaskExecution.cs#L58-L94","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["hedging","internal","invalid-operation","lifecycle","polly-core"],"backgroundTag":null,"analyzedSha":"d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac","analyzedAt":"2026-08-13T16:36:01.959Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}