feat(nested-steps): Stop hardcoding Root context thread#9
Merged
Conversation
…ler threads in .get().
maschnetwork
requested changes
Jan 19, 2026
Contributor
maschnetwork
left a comment
There was a problem hiding this comment.
Thanks for working on this. Some comments to discuss.
examples/src/main/java/com/amazonaws/lambda/durable/examples/NestedStepExample.java
Outdated
Show resolved
Hide resolved
examples/src/test/java/com/amazonaws/lambda/durable/examples/NestedStepExampleTest.java
Outdated
Show resolved
Hide resolved
sdk/src/main/java/com/amazonaws/lambda/durable/operation/StepOperation.java
Outdated
Show resolved
Hide resolved
zhongkechen
reviewed
Jan 20, 2026
| this.serDes = serDes; | ||
| this.lambdaContext = lambdaContext; | ||
| this.operationCounter = new AtomicInteger(0); | ||
| this.uniqueThreadName = Thread.currentThread().getName(); // Auto-detect handler thread |
Contributor
There was a problem hiding this comment.
Is this guaranteed to be unique with all executors? I assume we're going to allow customers to use their own Executor implementation.
Contributor
Author
There was a problem hiding this comment.
This is a good point @zhongkechen. I actually tested some edge-cases and we should avoid relying on synchronizing the thread name with our tracking of active threads in Execution Manager.
- Users can provide their own executor with their own naming strategy which we would overwrite (bad user experience)
- Thread pools can re-use threads which can lead to side-effects in concurrency scenarios.
A better solution might be to track the currently active thread context with a thread local. Something like:
- DurableContext -> enters "Context" thread
- Step.execute() -> enters "Step" thread
- Step.get() -> check if currently active context is a context or step thread
- RunInChild context can create a new "Context" thread with another name
Contributor
Author
There was a problem hiding this comment.
I fixed this problem in the newest revision and we raise an exception now when nested step calling happens.
… threads. Merge threadlocal into a single OperationContext record.
…xecution manager.
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.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
Issue Link, if available
#7
Description
This PR removes hardcoding of the "Root" context thread name. Now, the
DurableContextthread default to the name assigned by the managed executor. Steps will run in their own thread and set the thread name on their own in sync with e.g.stepTaskId. This way, we can de-register the calling thread by thread name in.get().We also removed
ThreadTypesince it was unused and only used in DEBUG logs. If we need it again in the future, we can re-add it.Demo/Screenshots
Added NestedStepExample:
Logs (see how step 2 is de-registered from step 1 running
.get()inside step 2). This can be interpreted as handing off control from step 2 (running in "Root" context) to step 1 running in step 2 and then back up the chain.Checklist