Skip to content

feat(sdk): add distributed map result and exception types - #915

Draft
nvasiu wants to merge 1 commit into
feat/distributed-mapfrom
feat/distributed-map-results
Draft

nvasiu wants to merge 1 commit into
feat/distributed-mapfrom
feat/distributed-map-results

Conversation

@nvasiu

@nvasiu nvasiu commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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

#912

Description

Adds the result types a distributed map run returns, and the exception it throws. PR 1 of 6 (see the issue). It needs no new Lambda model and depends on no other PR.

model/

The result types a customer receives back from a map run.

  • DistributedMapSummary: describes the run's overall outcome.
  • DistributedMapResult: contains individual map run item outcomes.
  • DistributedMapError: the error on a run or on one item.
  • DistributedMapStatus: the run's terminal status.

exception/DistributedMapException.java

The error type a customer catches.

  • DistributedMapException: thrown by throwIfError() when a run or an item fails.

Demo/Screenshots

N/A

Design

See Rules for every change.

  • Design note (rule 3), for a new feature, a new option or a public API change: Feature planned internally.
  • Simpler options considered (rule 2), if the change adds logic: N/A
  • Root cause (rule 5), for a bug fix: N/A
  • Net change in source lines and in public API members:
    • +310 lines in src/main and +318 in src/test.
    • New public members: 4 result types in model/ and 1 exception type.

Assumptions

Each assumption about the service, Lambda, the runtime or another library, with its evidence, or marked "unverified" (rule 6):

  • A distributed map operation ends in one of SUCCEEDED, FAILED, STOPPED or TIMED_OUT. Unverified.

Decisions not covered by the issue or the design note

One line each, with the reason (rule 7):

  • DistributedMapException extends DurableOperationException, because a run maps to one distributed map operation, like the other operation exceptions.

Checklist

  • I have filled out every section of the PR template
  • I have thoroughly tested this change
  • Every new branch has a test that fails without it (rule 4)
  • For a bug fix: the description or commit order shows the regression test failing before the fix and passing after it (rule 5)
  • Every edited test expectation is listed in the description, with the reason (rule 5)

Testing

Unit Tests

Have unit tests been written for these changes?

Yes. model/DistributedMapSummaryTest and model/DistributedMapResultTest: the result types and throwIfError().

Integration Tests

Have integration tests been written for these changes?

No. LocalDurableTestRunner does not support distributed map yet.

Examples

Has a new example been added for the change? (if applicable)

No.

String distributedMapRunArn,
DistributedMapError error,
Long totalCount,
Operation operation) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this record serializable?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jackson can't serialize Operation, so returning a DsitributedMapSummary/Result from `runInChildContext or the handler failed.

The summary only holds the operation so throwIfError() can pass it to DurableOperationException. Nothing else uses it. So I just removed it from the summary so DsitributedMapSummary/Result are serializable now.

throwIfError() still builds DistributedMapException from the run's status, failure count and error. But DistributedMapException has no operation now, so getOperation() returns null. Left a comment explaining this.

long failureCount,
String message,
DistributedMapError error) {
super(operation, toErrorObject(error, message), message);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this error always have the fields we expect?

@nvasiu nvasiu Dec 4, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. errorType and errorMessage can each be null or empty, and a run can end with no error. DistributedMapException handles these the same way as the SDK's other operation exceptions:

  • getErrorObject() returns the recorded error unchanged.
  • When there is no error, getErrorObject() uses the exception's class name and message.
  • The exception message leaves out a type or message that is null or empty.

@nvasiu
nvasiu changed the base branch from main to feat/distributed-map November 25, 2026 18:11
}

/** Returns items that succeeded. */
public List<Item<O>> succeeded() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These method names return different things than on MapResult.

MapResult.succeeded() returns the result values and MapResult.failed() returns the errors (MapResult.java line 67 and 75). Here succeeded() and failed() return List<Item<O>>, and results() returns only the succeeded outputs. Someone moving from ctx.map to ctx.distributedMap gets different data from the same call.

is this intended? maybe it should be the similar

🤖 AI-assisted comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intended, I made Dmap's behaviour consistent with map and dmap in the other SDKs, and Java's MapResult is actually inconsistent with other operations.

Here's a table of how they work:

Accessor JS / Python map and distributed map Java DistributedMapResult Java MapResult
succeeded() succeeded items succeeded items succeeded result values
failed() failed items failed items failed errors (MapError)
getResults() / get_results() / results() succeeded result values only succeeded result values only every item's result, null for failed and skipped items
getErrors() / get_errors() / errors() failed errors only failed errors only no such method


/** Applies a defensive copy and defaults. */
public DistributedMapResult {
items = items != null ? List.copyOf(items) : Collections.emptyList();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A null summary fails later with a NullPointerException that has no message.

The constructor defaults items but not summary. Every getter that reads summary (status(), successCount(), throwIfError()) fails at the first call. We should populate summary.

🤖 AI-assisted comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SDK always builds a DistributedMapResult with a summary, so a null summary only comes from code that builds the record by hand. Added Objects.requireNonNull(summary, "summary") to the constructor, so that mistake fails where the record is built, with a message naming summary. A summary has no sensible default, because it carries the run's status and counts.

* cycles without requiring AWS SDK-specific Jackson modules.
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public record DistributedMapError(String errorType, String errorMessage, String errorData, List<String> stackTrace) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a near copy of MapResult.MapError.

MapResult.MapError(errorType, errorMessage, stackTrace) has the same fields as this record minus errorData, and of(Throwable) does the same as MapError.of. Suggest one shared error record with errorData for map, parallel and distributed map, or say in the PR why a second type is needed. Also, of always sets errorData to null, while ExceptionHelper.buildErrorObject fills it for DurableOperationException types.

🤖 AI-assisted comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think MapError and DistributedMapError are different enough to be separate. MapError always comes from an exception from inside a map, so its errorType is a Java class name. DistributedMapError holds the run's error and errors returned by the processors, which can be any language. So its errorType isn't always a Java class name, and it can carry errorData.

The JS SDK also has separate types for these, but the Python SDK uses a shared type. So it's valid to make a shared type in Java, but that would make a breaking change to map/parallel. I think that's out of scope for the PR, and if we wanted to we could make map/parallel/dmap use a shared type in a later PR.

Also of() leaves errorData null on purpose. buildErrorObject puts the serialized exception there so the SDK can rebuild the exception class on replay. of() builds a processor's item error, which goes back to the durable function that called ctx.distributedMap. That function may not have the processor's exception class, so it cannot use the serialized exception. This matches MapError.of, which sets no error data either.

@nvasiu

nvasiu commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

Updates to address comments:

  1. DistributedMapSummary no longer holds Operation, so DistributedMapSummary and DistributedMapResult serialize. DistributedMapException no longer takes an operation and passes null to DurableOperationException. A comment on the super(...) call explains why.
  2. DistributedMapResult rejects a null summary with Objects.requireNonNull(summary, "summary").
  3. The run exception message skips an empty error message, so it no longer ends in a stray colon. runMessage and itemMessage share a hasText check.
  4. Tests:
    • The operation assertions became assertNull(error.getOperation()).
    • Added constructor_rejectsNullSummary.
    • Added throwIfError_runMessageSkipsEmptyErrorMessage.

Add the types a distributed map run returns: DistributedMapSummary with
the run's status and counts, DistributedMapResult with each item's
outcome, and DistributedMapException, thrown by throwIfError when the
run or an item failed. The exception extends DurableOperationException
like the other operation exceptions.
@nvasiu
nvasiu force-pushed the feat/distributed-map-results branch from 0de4e34 to fe091c4 Compare December 4, 2026 22:35

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants