Skip to content

[Durable Execution]: Add virtual context support to RunInChildContextAsync #2461

Description

@zhongkechen

Summary

The .NET Durable Execution SDK does not appear to expose virtual-context support directly on IDurableContext.RunInChildContextAsync.

Virtual contexts are available through concurrent operations via MapConfig.NestingType = NestingType.Flat and ParallelConfig.NestingType = NestingType.Flat, but there is no equivalent option on ChildContextConfig for a standalone RunInChildContextAsync operation.

Why this matters

The Java Durable Execution SDK supports this directly:

context.runInChildContextAsync(
    "order-validation",
    String.class,
    child -> { ... },
    RunInChildContextConfig.builder().isVirtual(true).build());

That makes it possible to create individual virtual child contexts, including when users manually fan out work and collect the returned futures.

In the .NET SDK, code that wants the same shape currently has to switch to MapAsync or ParallelAsync with NestingType.Flat. That works for batch-shaped workloads, but it is less direct when porting Java examples or when the workflow naturally wants to compose standalone child contexts with RunInChildContextAsync and Task.WhenAll.

Current .NET behavior

RunInChildContextAsync accepts ChildContextConfig, but ChildContextConfig does not expose a virtual/flat nesting option.

The SDK internals appear to support virtual child contexts already. For example, ChildContextOperation has an isVirtual path, and concurrent operations use it when NestingType.Flat is configured. The missing piece seems to be public API surface for standalone child contexts.

Requested behavior

Please consider adding a virtual-context option to standalone child context configuration, for example:

await context.RunInChildContextAsync(
    async (childContext, cancellationToken) =>
    {
        return await childContext.StepAsync(
            (_, stepCancellationToken) => Task.FromResult("result"),
            name: "compute",
            cancellationToken: cancellationToken);
    },
    name: "child-0",
    config: new ChildContextConfig
    {
        NestingType = NestingType.Flat
    });

or:

config: new ChildContextConfig
{
    IsVirtual = true
}

Workaround

For batch workloads, MapAsync or ParallelAsync with NestingType.Flat can provide virtual contexts:

await context.MapAsync(
    items,
    async (itemContext, item, index, allItems, cancellationToken) =>
        await itemContext.StepAsync(
            (_, stepCancellationToken) => Task.FromResult(index),
            name: $"compute-{index}",
            cancellationToken: cancellationToken),
    config: new MapConfig
    {
        NestingType = NestingType.Flat
    });

This is useful, but it does not cover the standalone RunInChildContextAsync parity case.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions