Add RunInChildContextAsync#2370
Conversation
d943d16 to
7ca2099
Compare
e146869 to
369a029
Compare
7ca2099 to
5a29b3e
Compare
369a029 to
5a29b3e
Compare
Adds child-context support to the .NET Durable Execution SDK. A child context is a logical sub-workflow with its own deterministic operation-ID space, persisted as a CONTEXT operation so subsequent invocations replay the cached value without re-executing the function. Public surface: - IDurableContext.RunInChildContextAsync<T> (reflection + AOT-safe ICheckpointSerializer<T> overloads, plus a void overload). - ChildContextConfig with SubType (observability label) and ErrorMapping (transform exceptions before they surface to the caller). - ChildContextException for failure surfacing. Used as a building block for upcoming WaitForCallbackAsync. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds a RunInChildContextAsync API to IDurableContext enabling user functions to be executed inside a logical sub-workflow whose result is checkpointed as a CONTEXT operation. The child context shares the parent's state, termination manager, batcher, and Lambda context, but uses a child OperationIdGenerator so its operation IDs are deterministically namespaced. Failures are surfaced via a new ChildContextException, optionally remapped via ChildContextConfig.ErrorMapping. This is positioned as a building block for a future WaitForCallbackAsync.
Changes:
- New
ChildContextOperation<T>mirroring the Step/Wait pattern with replay branches forSUCCEEDED,FAILED,STARTED/PENDING. - Public surface additions:
IDurableContext.RunInChildContextAsync(typed and void overloads),ChildContextConfig,ChildContextException. - Service-client mapping extended to copy
ContextDetails(Result, partialError) from SDK responses, plus 14 new unit tests.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| Libraries/src/Amazon.Lambda.DurableExecution/IDurableContext.cs | Adds typed/void RunInChildContextAsync to the public interface. |
| Libraries/src/Amazon.Lambda.DurableExecution/DurableContext.cs | Implements RunInChildContextAsync and constructs ChildContextOperation with a child-context factory. |
| Libraries/src/Amazon.Lambda.DurableExecution/Internal/ChildContextOperation.cs | New operation type implementing fresh execution, replay, and failure paths. |
| Libraries/src/Amazon.Lambda.DurableExecution/ChildContextConfig.cs | New config type with SubType and ErrorMapping. |
| Libraries/src/Amazon.Lambda.DurableExecution/DurableExecutionException.cs | Adds ChildContextException with SubType, ErrorType, ErrorData, OriginalStackTrace. |
| Libraries/src/Amazon.Lambda.DurableExecution/Services/LambdaDurableServiceClient.cs | Maps ContextDetails from the SDK operation; drops ErrorData/StackTrace. |
| Libraries/test/Amazon.Lambda.DurableExecution.Tests/ChildContextOperationTests.cs | 14 tests covering fresh, replay, suspension, error-mapping, and non-determinism paths. |
| Libraries/test/Amazon.Lambda.DurableExecution.Tests/LambdaDurableServiceClientTests.cs | New test for ContextDetails Result/Error copy. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ContextDetails = sdkOp.ContextDetails != null ? new Internal.ContextDetails | ||
| { | ||
| Result = sdkOp.ContextDetails.Result, | ||
| Error = sdkOp.ContextDetails.Error != null ? new ErrorObject | ||
| { | ||
| ErrorType = sdkOp.ContextDetails.Error.ErrorType, | ||
| ErrorMessage = sdkOp.ContextDetails.Error.ErrorMessage | ||
| } : null | ||
| } : null |
Summary
RunInChildContextAsynctoIDurableContextwith two overloads: returningTand void.ChildContextConfig(SubTypefor observability,ErrorMappingfor exception remapping) andChildContextExceptionfor failure surfacing.Internal/ChildContextOperation<T>mirroring the Step/Wait pattern: sync-flushCONTEXT START-> run user func -> emitSUCCEEDwith serialized result, orFAILwith error and throwChildContextException. Replay:SUCCEEDEDreturns cached value,FAILEDthrows (afterErrorMapping),STARTED/PENDINGre-runs the func and lets the child's own operations replay from their own checkpoints.ILambdaSerializerregistered onILambdaContext.Serializer(consistent withStepOperation); no separate AOT overload is needed since the AOT story is owned by the registered serializer (e.g.SourceGeneratorLambdaJsonSerializer<TContext>).LambdaDurableServiceClient.MapFromSdkOperationto copyContextDetails(Result+Error).This is a building block for upcoming
WaitForCallbackAsync, which (per the Java/JS reference SDKs) wrapsCreateCallbackAsync+ a submitter step inside a child context for observability and clean error mapping.#2216
Test plan
ChildContextOperationTests.cscovering: fresh execution + checkpoint emission, deterministic child operation IDs, replaySUCCEEDED, replayFAILED(with and withoutErrorMapping), suspended child (Wait inside child propagates termination), replaySTARTEDwith completed inner step, void overload, type-mismatch non-determinism detection, andSubTypepropagation.