Add virtual-context support to standalone RunInChildContextAsync#2463
Merged
Conversation
The SDK internals already supported virtual child contexts (ChildContextOperation takes isVirtual; MakeChildFactory re-parents inner ops via CreateVirtualChild), but the only public entry point was the concurrent Map/Parallel path via NestingType.Flat. Standalone RunInChildContextAsync had no way to opt in. Add ChildContextConfig.NestingType (default Nested), matching the existing convention on MapConfig/ParallelConfig, and wire RunChildContext to pass isVirtual when NestingType.Flat is set. Under Flat the child emits no CONTEXT checkpoint of its own; inner operations re-parent to the nearest non-virtual ancestor and replay from their own checkpoints, mirroring the JS SDK's virtualContext behavior. Closes #2461
normj
approved these changes
Jul 7, 2026
philasmar
approved these changes
Jul 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
Closes #2461
The .NET Durable Execution SDK exposed virtual (flat) contexts only through the concurrent
MapAsync/ParallelAsyncpaths (NestingType.Flat). There was no equivalent option for a standaloneRunInChildContextAsync, so users porting Java/JS examples that manually fan out child contexts and await them withTask.WhenAllhad to switch toMapAsync/ParallelAsync.Investigation
The SDK internals already fully supported virtual standalone child contexts:
ChildContextOperation<T>takes anisVirtualflag and suppresses its ownCONTEXTSTART/SUCCEED/FAIL checkpoints while still propagating results and exceptions.DurableContext.MakeChildFactoryhandles the virtual case viaOperationIdGenerator.CreateVirtualChild, re-parenting inner operations to the nearest non-virtual ancestor.The only missing piece was public API surface + wiring for the standalone entry point.
Referencing the JS SDK as ground truth,
ChildConfig.virtualContext?: booleandrivesisVirtual = options?.virtualContext === truein the run-in-child-context handler, which skips checkpoints and re-parents inner ops when virtual.Change
I chose the
NestingTypeshape (the issue's first suggestion) rather than avirtualContext/IsVirtualbool, because it matches the existing convention onMapConfigandParallelConfig— consistent for .NET consumers, identical wire behavior to the JSvirtualContextbool.ChildContextConfig.NestingType— new property, defaults toNestingType.Nested.DurableContext.RunChildContext— passesisVirtual: config?.NestingType == NestingType.Flatto the operation.Users can now write the exact shape requested in the issue:
Tests
Added 3 tests to
ChildContextOperationTests:RunInChildContextAsync_FlatNesting_EmitsNoContextCheckpointAndReparentsInnerOps— Flat emits noCONTEXTcheckpoint; inner ops re-parent to the non-virtual ancestor.RunInChildContextAsync_FlatNesting_ReplayReExecutesBodyFromInnerCheckpoint— with noCONTEXTcheckpoint, replay re-executes the body while inner steps replay from their own checkpoints (mirrors JS "virtual: re-execute then round-trip").RunInChildContextAsync_FlatNesting_FuncThrows_EmitsNoFailCheckpointButPropagates— Flat suppresses theCONTEXT FAILcheckpoint but still propagates the exception.Build: clean (0 warnings). Tests: 408/408 pass on net8.0 and net10.0.
Change file
Included:
.autover/changes/durable-childcontext-virtual.json(Minor,Amazon.Lambda.DurableExecution).