{"record":{"id":"259040b502b870a9","repo":"elsa-workflows/elsa-core","slug":"no-activity-execution-context-found-with-the-specified-id","errorCode":null,"errorMessage":"No activity execution context found with the specified ID.","messagePattern":"No activity execution context found with the specified ID\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/modules/Elsa.Workflows.Core/Services/WorkflowRunner.cs","lineNumber":151,"sourceCode":"            triggerActivityId,\n            cancellationToken);\n\n        var bookmarkId = options?.BookmarkId;\n        var activityHandle = options?.ActivityHandle;\n\n        if (!string.IsNullOrEmpty(bookmarkId))\n        {\n            var bookmark = workflowState.Bookmarks.FirstOrDefault(x => x.Id == bookmarkId);\n\n            if (bookmark != null)\n                workflowExecutionContext.ScheduleBookmark(bookmark);\n        }\n        else if (activityHandle != null)\n        {\n            if (!string.IsNullOrEmpty(activityHandle.ActivityInstanceId))\n            {\n                var activityExecutionContext = workflowExecutionContext.ActivityExecutionContexts.FirstOrDefault(x => x.Id == activityHandle.ActivityInstanceId)\n                                               ?? throw new(\"No activity execution context found with the specified ID.\");\n                workflowExecutionContext.ScheduleActivityExecutionContext(activityExecutionContext);\n            }\n            else\n            {\n                var activity = workflowExecutionContext.FindActivity(activityHandle);\n                if (activity != null) workflowExecutionContext.ScheduleActivity(activity);\n            }\n        }\n        else if (workflowExecutionContext.Scheduler.HasAny)\n        {\n            // Do nothing. The scheduler already has activities to schedule.\n        }\n        else\n        {\n            // Check if there are any interrupted activities.\n            var interruptedActivityExecutionContexts = workflowExecutionContext.ActivityExecutionContexts.Where(x => x.IsExecuting).ToList();\n\n            if (interruptedActivityExecutionContexts.Count > 0)","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/elsa-workflows/elsa-core/blob/fe9217bdfa0e27f0e09e45006eb6898f616e513d/src/modules/Elsa.Workflows.Core/Services/WorkflowRunner.cs#L133-L169","documentation":"When resuming or running a workflow with an activity handle that carries an ActivityInstanceId, WorkflowRunner looks up the matching ActivityExecutionContext in the current execution context to re-schedule it. If no activity execution context with that ID exists in this workflow instance, the handle is dangling and this exception is thrown.","triggerScenarios":"Calling WorkflowRunner.RunAsync (or ExecuteWorkflowAsync overloads) with an ActivityHandle whose ActivityInstanceId does not match any ActivityExecutionContext in the target workflow instance — e.g. the ID belongs to another instance, the instance was reloaded after the context completed, or the ID was stale after a state re-extraction.","commonSituations":"Bookmark resumption after the target activity already completed and its context was pruned; copying activity instance IDs between workflow instances; workflow state restored from persistence missing that execution context; retry logic resuming a finished activity.","solutions":["Verify the ActivityHandle.ActivityInstanceId belongs to the same workflow instance you are running; reload the correct instance.","Check whether the activity already completed — if so, resume the workflow without an activity handle instead of targeting the finished context.","Re-extract/persist workflow state so the referenced ActivityExecutionContext is present before resuming.","Fall back to scheduling by activity node ID (ActivityHandle by activity ID/path) instead of instance ID when the instance ID may be stale."],"exampleFix":"// before\nawait runner.RunAsync(instance, new ActivityHandle { ActivityInstanceId = staleId });\n// after\nvar handle = workflowExecutionContext.ActivityExecutionContexts.Any(x => x.Id == staleId)\n    ? new ActivityHandle { ActivityInstanceId = staleId }\n    : new ActivityHandle { ActivityId = activityNodeId }; // or resume with no handle","handlingStrategy":"validation","validationCode":"var handle = new ActivityHandle { ActivityInstanceId = instanceId };\n// before running, confirm the context exists in the loaded instance state:\nbool valid = workflowState.ActivityExecutionContexts.Any(x => x.Id == instanceId);","typeGuard":"bool contextExists = workflowExecutionContext.ActivityExecutionContexts.Any(x => x.Id == handle.ActivityInstanceId);","tryCatchPattern":"try { await runner.RunAsync(instance, handle); } catch (Exception ex) { logger.LogError(ex, \"Stale ActivityInstanceId {Id}; falling back to plain resume\", instanceId); await runner.RunAsync(instance); }","preventionTips":["Only pass ActivityInstanceIds captured from the same workflow instance's live state","Skip resuming against contexts for activities that already completed","Persist workflow state after scheduling so instance IDs remain valid across restarts"],"tags":["workflow-runner","resumption","csharp"],"backgroundTag":"entity-not-found","analyzedSha":"fe9217bdfa0e27f0e09e45006eb6898f616e513d","analyzedAt":"2026-09-13T20:32:34.702Z","contentChangedAt":"2026-09-13T20:32:34.702Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}