aws-durable-execution-sdk-java
AGENTS.md28 starsChanged 6 months agoApache-2.0View on GitHub
AI coding agent instructions for the AWS Lambda Durable Execution Java SDK. AWS Lambda Durable Execution SDK for Java - enables building resilient, multi-step Lambda workflows that can run for up to one year with automatic state management, checkpoint-and-replay, and failure recovery. This repository is the Java implementation of the AWS Lambda durable execution SDK. Related SDKs exist for JavaScript/TypeScript and Python. Cloud example tests are disabled by default. Enable them only when the required Lambda functions and AWS credentials…
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
The file
Show its rules and text
We split this AGENTS.md into the rules it gives an agent
39 rules. About 0 are common, 18 are distinctive, and 21 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈18
Distinctive · estimate
This author's own choices. Worth a look.
21
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 112
No unnecessary interfaces: - Use concrete classes when only one implementation exists.
- Distinctive: line 113
Constructor injection: - All dependencies via constructors or builders, no field injection.
- Distinctive: line 117
Preserve public API compatibility: - Do not change public method signatures or remove deprecated overloads unless explicitly instructed.
- Very specific: line 118
TypeToken for generics: - Use TypeToken<T> overloads when result types are generic.
- Very specific: line 126
Use context.getLogger() instead of SLF4J's LoggerFactory in example handlers.
- Distinctive: line 132
Add new dependencies without explicit approval.
- Distinctive: line 133
Create interfaces for single implementations.
- Distinctive: line 134
Write tests for POJO getters/setters.
- Very specific: line 139
Use Thread.sleep() or blocking timers to model durable waits.
- Very specific: line 140
Use deprecated Supplier-based step() overloads in new examples or tests.
- Distinctive: line 183
Test individual classes in isolation.
- Distinctive: line 199
Test SDK components working together.
- Very specific: line 200
Use LocalDurableTestRunner (in-memory, no AWS).
- Distinctive: line 201
Test replay, checkpointing, suspension/resume, retry, callbacks, child contexts, and concurrency.
- Very specific: line 212
Use runner.run(input) when you need to inspect an intermediate PENDING state.
- Distinctive: line 233
All changes MUST include related tests.
- Distinctive: line 235
Do NOT add conformance tests — conformance tests live in a separate repository (aws-durable-execution-conformance-tests) and are managed by …
- Distinctive: line 239
Test business logic, replay behavior, suspension/resume behavior, and edge cases.
- Distinctive: line 240
Do not test simple POJO getters/setters.
- Very specific: line 241
Use LocalDurableTestRunner for fast tests.
- Very specific: line 242
Use CloudDurableTestRunner only for end-to-end validation.
- Very specific: line 243
Prefer runUntilComplete() unless the test needs to assert an intermediate PENDING state.
- Very specific: line 291
Create a class in operation/ extending BaseDurableOperation or SerializableDurableOperation<T>.
- Very specific: line 292
Add configuration/result/exception types only when the operation needs them.
- Very specific: line 293
Add sync and async methods to DurableContext.
- Distinctive: line 295
Add unit tests for first execution, replay, validation, and error cases.
- Very specific: line 296
Add integration tests using LocalDurableTestRunner.
- Distinctive: line 297
Add or update examples and docs if the operation is public.
- Very specific: line 301
Update the relevant config/ builder.
- Distinctive: line 304
Add unit tests for defaults, custom values, and validation failures.
- Very specific: line 308
Put the handler under the matching examples/src/main/java/.../examples/<category>/ package.
- Very specific: line 309
Use context.getLogger() for example logging.
- Very specific: line 310
Add a local test using LocalDurableTestRunner.
- Distinctive: line 311
Add cloud coverage only when the scenario needs deployed Lambda behavior.
- Very specific: line 315
Check ExecutionManager for active thread registration/deregistration, replay transitions, and operation lookup.
- Distinctive: line 319
Ask clarifying questions before making risky assumptions.
- Very specific: line 320
Check existing code for patterns, especially in operation/, context/, config/, and nearby tests.
- Distinctive: line 321
Prefer minimal changes over large refactors.
- Very specific: line 326
Run mvn spotless:apply after Java changes.
≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
AGENTS.md
AI coding agent instructions for the AWS Lambda Durable Execution Java SDK.
Project Overview
AWS Lambda Durable Execution SDK for Java - enables building resilient, multi-step Lambda workflows that can run for up to one year with automatic state management, checkpoint-and-replay, and failure recovery.
Key Concepts
- Checkpoint-and-replay: Durable operations create checkpoints; on reinvocation, completed operations replay from cached state instead of re-running user code.
- Durable operations:
step()executes code with retry,wait()suspends without compute charges, callbacks resume on external events, and invoke/child-context/concurrency APIs coordinate larger workflows. - Concurrency:
map()andparallel()run work in child contexts, using isolated checkpoint logs and configurable completion behavior. - Replay-aware logging and plugins:
DurableLoggersuppresses duplicate replay logs for handlers; plugin hooks expose invocation, operation, and user-function lifecycle events. - Use cases: Order processing, human approvals, AI agent workflows, distributed transactions, and long-running orchestrations.
This repository is the Java implementation of the AWS Lambda durable execution SDK. Related SDKs exist for JavaScript/TypeScript and Python.
Build & Test Commands
# Build all modules and run tests
mvn clean install
# Run all tests
mvn test
# Run a specific test class
mvn test -Dtest=DurableContextTest
# Run tests for a module
mvn -pl sdk test
mvn -pl otel-plugin test
# Skip tests
mvn install -DskipTests
# Format Java code (ALWAYS run after making Java changes)
mvn spotless:applyCloud example tests are disabled by default. Enable them only when the required Lambda functions and AWS credentials are configured:
cd examples
mvn test -Dtest="CloudBasedIntegrationTest,CloudBasedOtelIntegrationTest" -Dtest.cloud.enabled=trueThe project targets Java 17. The examples module has a Java 21 virtual-thread example that is automatically excluded on JDKs below 21.
Key Directories
sdk/ # Core SDK module
├── src/main/java/software/amazon/lambda/durable/
│ ├── DurableHandler.java # Lambda entry point (extend this)
│ ├── DurableContext.java # User-facing API interface
│ ├── StepContext.java # Context available inside step functions
│ ├── DurableConfig.java # SDK configuration
│ ├── DurableFuture.java # Future API that can suspend execution
│ ├── context/ # DurableContext/StepContext implementations
│ ├── execution/ # DurableExecutor, ExecutionManager, checkpointing
│ ├── operation/ # Step, wait, invoke, callback, child, map, parallel operations
│ ├── config/ # Operation and SDK configuration types
│ ├── model/ # Result/status data structures
│ ├── retry/ # Retry, polling, wait strategies
│ ├── serde/ # JSON serialization
│ ├── client/ # AWS Lambda Durable Functions client integration
│ ├── logging/ # DurableLogger and logger configuration
│ ├── plugin/ # Lifecycle plugin API
│ └── exception/ # Domain exceptions
sdk-testing/ # LocalDurableTestRunner, CloudDurableTestRunner, test helpers
sdk-integration-tests/ # Integration tests using sdk-testing
otel-plugin/ # OpenTelemetry plugin implementation
examples/ # Customer-facing examples with local and cloud tests
coverage-report/ # Aggregated JaCoCo coverage report module
docs/ # User docs, design notes, ADRs, migration guideCoding Guidelines
Java Style (MUST follow)
// USE var when type is obvious
var config = StepConfig.builder().build();
var operations = new HashMap<String, Operation>();
// USE static imports for common utilities, assertions, and enum constants
import static java.util.Collections.emptyList;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static software.amazon.lambda.durable.model.ExecutionStatus.SUCCEEDED;
// ALWAYS use proper imports, NEVER use fully qualified class names in code
// Bad: var lambda = software.amazon.awssdk.services.lambda.LambdaClient.create();
// Good: import software.amazon.awssdk.services.lambda.LambdaClient;
// var lambda = LambdaClient.create();
// Prefer StepContext-based step lambdas; Supplier overloads are deprecated
var result = context.step("process", String.class, stepCtx -> "done");
// USE constructor injection
public DurableExecutor(DurableExecutionClient client, SerDes serDes) {
this.client = client;
this.serDes = serDes;
}Architecture Rules
- No unnecessary interfaces - Use concrete classes when only one implementation exists. Keep existing public interfaces such as
DurableContext,DurableFuture,SerDes,RetryStrategy, and plugin interfaces. - Constructor injection - All dependencies via constructors or builders, no field injection.
- Defensive copies - Copy mutable collections in constructors and builders.
- Single responsibility - One class, one job.
- Methods <=30 lines - Extract helpers if longer.
- Preserve public API compatibility - Do not change public method signatures or remove deprecated overloads unless explicitly instructed.
- TypeToken for generics - Use
TypeToken<T>overloads when result types are generic.
Package Naming
The package root is software.amazon.lambda.durable. Prefer descriptive domain packages: model, execution, operation, serde, exception, config, retry, context, plugin, and logging.
Logging in Examples
Use context.getLogger() instead of SLF4J's LoggerFactory in example handlers. It includes execution metadata and suppresses duplicate handler logs during replay.
StepContext logs are attempt-based and are not replay-suppressed. isReplaying() is available on DurableContext, not StepContext or BaseContext.
Do Not
- Add new dependencies without explicit approval.
- Create interfaces for single implementations.
- Write tests for POJO getters/setters.
- Expose mutable state via getters.
- Change public API signatures without instruction.
- Swallow exceptions silently.
- Use field injection.
- Use
Thread.sleep()or blocking timers to model durable waits; usecontext.wait()or polling/wait strategies. - Use deprecated Supplier-based
step()overloads in new examples or tests.
Testing Approach
Test Organization
sdk/src/test/ # Unit tests for SDK internals
├── DurableContextTest # Public API/default behavior
├── context/DurableContextImplTest
├── execution/ExecutionManagerTest
├── operation/StepOperationTest
├── serde/JacksonSerDesTest
└── retry/RetryStrategiesTest
sdk-integration-tests/src/test/ # SDK components working together via LocalDurableTestRunner
├── IntegrationTest
├── RetryIntegrationTest
├── InvokeIntegrationTest
├── CallbackIntegrationTest
├── MapIntegrationTest
├── ParallelIntegrationTest
├── WaitForConditionIntegrationTest
└── InvocationOtelPluginIntegrationTest
otel-plugin/src/test/ # OpenTelemetry plugin unit tests
examples/src/test/ # Customer-facing examples + cloud tests
├── step/SimpleStepExampleTest
├── wait/WaitExampleTest
├── callback/CallbackExampleTest
├── invoke/InvokeExampleTest
├── map/SimpleMapExampleTest
├── parallel/ParallelExampleTest
├── otel/OtelXRayExamplesTest
├── CloudBasedIntegrationTest
└── CloudBasedOtelIntegrationTestTesting Strategy
Unit Tests (sdk/src/test/)
- Test individual classes in isolation.
- Mock dependencies.
- Fast, no external dependencies.
- Cover replay behavior, error paths, validation, and serialization edge cases.
@Test
void stepReturnsResultOnReplay() {
var context = createTestContext(completedOperations);
var result = context.step("test", String.class, stepCtx -> "new");
assertEquals("cached", result);
}Integration Tests (sdk-integration-tests/)
- Test SDK components working together.
- Use
LocalDurableTestRunner(in-memory, no AWS). - Test replay, checkpointing, suspension/resume, retry, callbacks, child contexts, and concurrency.
@Test
void testRetryBehavior() {
var runner = LocalDurableTestRunner.create(Input.class, handler::handleRequest);
var result = runner.runUntilComplete(new Input("test"));
assertEquals(ExecutionStatus.SUCCEEDED, result.getStatus());
}Use runner.run(input) when you need to inspect an intermediate PENDING state. Use runner.runUntilComplete(input) when the test should auto-advance waits/retries that do not need manual intervention.
Example Tests (examples/src/test/)
- Demonstrate SDK usage patterns.
- Local tests use
LocalDurableTestRunner. - Cloud tests use
CloudDurableTestRunnerand are disabled by default (-Dtest.cloud.enabled=true).
@Test
@EnabledIf("isCloudTestsEnabled")
void testAgainstRealLambda() {
var arn = "arn:aws:lambda:us-east-1:123456789012:function:my-fn:live";
var runner = CloudDurableTestRunner.create(arn, Input.class, Output.class);
var result = runner.run(new Input("test"));
assertEquals(ExecutionStatus.SUCCEEDED, result.getStatus());
}Testing Requirements
All changes MUST include related tests. At minimum, include unit tests. Include integration tests when the change affects cross-component behavior, public API surfaces, or end-to-end workflows. For isolated bug fixes where a unit test alone sufficiently covers the fix, integration tests are not required.
Do NOT add conformance tests — conformance tests live in a separate repository (aws-durable-execution-conformance-tests) and are managed by the team. If a change warrants a new conformance test, note it in the PR description or open an issue in that repository.
Test Guidelines
- Test business logic, replay behavior, suspension/resume behavior, and edge cases.
- Do not test simple POJO getters/setters.
- Use
LocalDurableTestRunnerfor fast tests. - Use
CloudDurableTestRunneronly for end-to-end validation. - Prefer
runUntilComplete()unless the test needs to assert an intermediatePENDINGstate. - JUnit uses static imports for assertions.
Architecture Essentials
Checkpoint-and-Replay
- Operations get stable, globally unique string IDs.
- Child context operation IDs are prefixed by parent operation IDs (for example,
1-1). - Completed operations are stored in
ExecutionManager. - On replay, cached operation state is returned and user code is skipped where appropriate.
- New operations checkpoint through
CheckpointManager. CheckpointManagerbatches and polls durable API requests throughApiRequestDelayedBatcher(750 KB and 200 update limits).
Key Classes
| Class | Responsibility |
DurableHandler<I,O> | Lambda entry point, extend this |
DurableContext | User API: step, wait, invoke, callbacks, child contexts, map, parallel, waitForCondition, withRetry |
StepContext | Context available inside step functions |
DurableFuture<T> | Future abstraction whose get() may suspend execution |
DurableExecutor | Orchestrates execution lifecycle |
ExecutionManager | Thread coordination, replay state, operation storage |
CheckpointManager | Batches checkpoint API calls and polls for operation updates |
ApiRequestDelayedBatcher | Shared delayed batching primitive for checkpoint/poll requests |
BaseDurableOperation | Shared operation lifecycle base class |
SerializableDurableOperation<T> | Base for operations with serialized results/exceptions |
StepOperation | Executes steps with retry logic and step semantics |
WaitOperation | Handles durable waits |
CallbackOperation | Creates external callback wait points |
InvokeOperation | Invokes another Lambda function and waits for its result |
ChildContextOperation | Runs isolated child durable contexts |
WaitForConditionOperation | Polls a condition function with configurable backoff |
MapOperation | Applies a function across items concurrently via child contexts |
ParallelOperation | Runs named child-context branches concurrently |
ConcurrencyOperation | Shared base for map/parallel concurrency limiting and completion evaluation |
DurableExecutionPlugin | Lifecycle hook interface |
InvocationOtelPlugin | OpenTelemetry plugin implementation in otel-plugin |
Serialization
The default SerDes is JacksonSerDes. Custom SerDes implementations must be able to deserialize SDK-managed values immediately after serialization. The SDK validates this by default so first execution matches replay behavior; DurableConfig.withDeserializeAfterSerialization(false) is an escape hatch, not the default recommendation.
Common Tasks
Add a New Operation Type
- Create a class in
operation/extendingBaseDurableOperationorSerializableDurableOperation<T>. - Add configuration/result/exception types only when the operation needs them.
- Add sync and async methods to
DurableContext. - Implement delegation in
context/DurableContextImpl. - Add unit tests for first execution, replay, validation, and error cases.
- Add integration tests using
LocalDurableTestRunner. - Add or update examples and docs if the operation is public.
Add or Change Configuration
- Update the relevant
config/builder. - Validate invalid values at build time.
- Preserve immutability and defensive copies.
- Add unit tests for defaults, custom values, and validation failures.
Add an Example
- Put the handler under the matching
examples/src/main/java/.../examples/<category>/package. - Use
context.getLogger()for example logging. - Add a local test using
LocalDurableTestRunner. - Add cloud coverage only when the scenario needs deployed Lambda behavior.
Debug Thread Coordination
Check ExecutionManager for active thread registration/deregistration, replay transitions, and operation lookup. Check CheckpointManager and ApiRequestDelayedBatcher for checkpoint batching, polling, and suspension/resume issues.
When Unsure
- Ask clarifying questions before making risky assumptions.
- Check existing code for patterns, especially in
operation/,context/,config/, and nearby tests. - Prefer minimal changes over large refactors.
- Review
docs/design.mdand the relevantdocs/core/*.mdpage for operation semantics.
After Making Changes
Run mvn spotless:apply after Java changes. Then run the narrowest relevant test first, and broaden to mvn test or mvn clean install when touching shared behavior, public APIs, serialization, concurrency, or execution lifecycle code.
Further Reading
Repository Docs
- Internal Design
- Testing
- Configuration
- Error Handling
- Logging
- Migration from 1.x to 2.x
Official AWS SDKs
- JavaScript/TypeScript: https://github.com/aws/aws-durable-execution-sdk-js
- Python: https://github.com/aws/aws-durable-execution-sdk-python
AWS Documentation
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

