{"record":{"id":"2eea72923aefdb4f","repo":"elsa-workflows/elsa-core","slug":"nohttpcontext","errorCode":"NoHttpContext","errorMessage":"The HTTP context was lost during workflow execution. This typically occurs when a workflow initiated from an HTTP endpoint is suspended and later resumed in a different execution context (e.g., background processing, virtual actor, or after a workflow transition). The original HTTP request context that expects a response is no longer available.","messagePattern":"The HTTP context was lost during workflow execution\\. This typically occurs when a workflow initiated from an HTTP endpoint is suspended and later resumed in a different execution context \\(e\\.g\\., background processing, virtual actor, or after a workflow transition\\)\\. The original HTTP request context that expects a response is no longer available\\.","errorType":"error_code","errorClass":"FaultException","httpStatus":null,"severity":"error","filePath":"src/modules/Elsa.Http/Activities/WriteFileHttpResponse.cs","lineNumber":74,"sourceCode":"    /// </summary>\n    [Input(Description = \"Whether to enable resumable downloads. When enabled, the client can resume a download if the connection is lost.\")]\n    public Input<bool> EnableResumableDownloads { get; set; } = null!;\n\n    /// <summary>\n    /// The correlation ID of the download. Used to resume a download.\n    /// </summary>\n    [Input(Description = \"The correlation ID of the download used to resume a download. If left empty, the x-download-id header will be used.\")]\n    public Input<string> DownloadCorrelationId { get; set; } = null!;\n\n    /// <inheritdoc />\n    protected override async ValueTask ExecuteAsync(ActivityExecutionContext context)\n    {\n        var httpContextAccessor = context.GetRequiredService<IHttpContextAccessor>();\n        var httpContext = httpContextAccessor.HttpContext;\n\n        if (httpContext == null)\n        {\n            throw new FaultException(\n                HttpFaultCodes.NoHttpContext, \n                HttpFaultCategories.Http, \n                DefaultFaultTypes.System, \n                \"The HTTP context was lost during workflow execution. This typically occurs when a workflow initiated from an HTTP endpoint is suspended and later resumed in a different execution context (e.g., background processing, virtual actor, or after a workflow transition). The original HTTP request context that expects a response is no longer available.\");\n        }\n\n        await WriteResponseAsync(context, httpContext);\n    }\n\n    private async Task WriteResponseAsync(ActivityExecutionContext context, HttpContext httpContext)\n    {\n        // Get content and content type.\n        var content = context.Get(Content);\n\n        // Write content.\n        var downloadables = GetDownloadables(context, httpContext, content).ToList();\n        await SendDownloadablesAsync(context, httpContext, downloadables);\n","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/elsa-workflows/elsa-core/blob/fe9217bdfa0e27f0e09e45006eb6898f616e513d/src/modules/Elsa.Http/Activities/WriteFileHttpResponse.cs#L56-L92","documentation":"WriteFileHttpResponse writes its response to the live ASP.NET HTTP context of the request that started the workflow. If IHttpContextAccessor.HttpContext is null at execution time, the activity throws a FaultException with code NoHttpContext, because there is no response stream to write to. This happens when the workflow was suspended after the HTTP request ended and later resumed outside the original request context.","triggerScenarios":"ExecuteAsync of WriteFileHttpResponse runs while httpContextAccessor.HttpContext is null — the workflow resumed from a bookmark on a background thread, in a virtual actor scheduler, after a server restart, or on a different node, so the original HTTP request/response pair no longer exists.","commonSituations":"A workflow blocks (e.g., waits for user task or timer) after an HttpEndpoint trigger and then attempts to write an HTTP file response upon resume; load-balanced deployments where the resume happens on another instance; long-running workflows outliving the HTTP request timeout.","solutions":["Do not use WriteHttpResponse/WriteFileHttpResponse after a suspension point; instead complete the HTTP request early (e.g., 202 Accepted) and deliver results via another channel (webhook callback, SignalR, storage link).","Restructure the workflow so the HTTP response is written before any blocking/bookmark activity.","If HTTP-correlated resume is required, ensure the resuming request itself carries the HTTP context (i.e., resume via an HttpEndpoint activity) rather than a non-HTTP trigger."],"exampleFix":"// before: HTTP trigger -> Delay/Task -> WriteFileHttpResponse (fails on resume)\n// after: HTTP trigger -> WriteHttpResponse(\"accepted\") -> Delay/Task -> deliver file via callback/storage","handlingStrategy":"validation","validationCode":"// Before the WriteFileHttpResponse activity runs, assert an HTTP context exists\nvar httpContext = httpContextAccessor.HttpContext;\nif (httpContext is null || !httpContext.Response.HasStarted ^ true)\n{\n    // take an alternate delivery path (202 + callback) instead of writing an HTTP file response\n}","typeGuard":null,"tryCatchPattern":"// Handle at workflow fault level\ncontext.Faulted += (args) => {\n    if (args.Fault.Code == HttpFaultCodes.NoHttpContext)\n        logger.LogWarning(\"Workflow tried to write an HTTP response without a live request; use callback delivery instead\");\n};","preventionTips":["Never place WriteHttpResponse/WriteFileHttpResponse after bookmarks, timers, or events in an HTTP-triggered workflow.","Respond 202 Accepted early and deliver files via durable storage links or webhooks.","Document which activities require a live HTTP context."],"tags":["http","workflow","suspension","aspnetcore"],"backgroundTag":"invalid-state-transition","analyzedSha":"fe9217bdfa0e27f0e09e45006eb6898f616e513d","analyzedAt":"2026-09-13T20:32:34.702Z","contentChangedAt":"2026-09-13T20:32:34.702Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}