Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions docs/adr/005-filesystem-serdes.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ Entity IDs are `operation/<operation-id>/result`,
`operation/<operation-id>/invoke-payload`. Polling state shares the result identity;
retries and polling can serialize more than one value for an identity. External
callback/invoke results can have a different producer identity from their consumer.
References must therefore be self-contained and remain readable after later writes.
Readers therefore rebuild the file path from the consumer's own context and ignore
the envelope's file path, so a reference cannot name another file.

Include `FileSystemSerDes` and its storage/path options in the main
`aws-durable-execution-sdk-java` artifact under
Expand All @@ -44,11 +45,12 @@ The filesystem serializer wraps a configurable delegate, supports `ALWAYS` and
the complete inline UTF-8 JSON envelope against 255 KiB. File/preview envelopes
must meet the same limit. Null serialized values remain null.

Every write uses a unique immutable file under the execution directory. The write
and local flush must succeed before its pointer is returned. This preserves older
checkpoints if a subsequent polling/retry write succeeds but its checkpoint does
not. Ordinary exceptions trigger cleanup of unpublished files; crashes may leave
orphans. No successful payload file is deleted automatically.
Each entity has one file under the execution directory, named from the entity ID,
matching the JavaScript and Python SDKs. A later write to the same entity replaces
the file (last write wins), so an older checkpoint reads the newer value. The write
and local flush must succeed before its pointer is returned. A failed write never
deletes the file, but one that fails partway can leave it partial or empty. No payload file is deleted
automatically.

Filesystem SerDes is configured per operation, matching .NET. Context-free calls
fail clearly. Global Lambda input/output and the internal durable protocol envelope
Expand All @@ -62,11 +64,12 @@ arrange compatible envelopes and shared storage on both sides of those boundarie
thread affinity. No inheritance-based thread-local propagation is needed.
- Filesystem I/O stays synchronous, consistent with the existing SerDes contract.
Delegate encoding still materializes a string in memory.
- Immutable files preserve replay but require external retention and cleanup.
- Last write wins: a retried or polled entity replaces its earlier value, and files
need external retention and cleanup.
- Mounted storage must survive execution-environment replacement. `/tmp` cannot
do this; delayed mount synchronization can also lose recent writes.
- The application controls the mount. Path confinement and symlink checks protect
against malformed references but do not sandbox another process with mount access.
- The application controls the mount. Rebuilding the path and the symlink checks protect
against forged references but do not sandbox another process with mount access.
- Filesystem serialization uses the existing SDK build, coverage, and publication.
Unit tests live in `sdk`; local-runner integration tests live in
`sdk-integration-tests`. No module or third-party library is added.
Expand All @@ -81,9 +84,10 @@ A separate `PayloadOffloader`, dedicated executors, deserialization caches, and
serializer retry decorators may be useful independently. They are not required for
the per-operation filesystem feature and would expand its API and runtime scope.

Overwriting one file per entity uses less storage but can corrupt an older
checkpoint when a write succeeds and checkpoint publication fails. Immutable
references are required instead.
A unique file per write keeps older checkpoints readable when a write succeeds and
checkpoint publication fails, but it uses more storage and differs from the
JavaScript and Python SDKs. One file per entity was chosen instead, and last write
wins.

See the [filesystem serialization guide](../advanced/filesystem-serdes.md) for
configuration, wire format, storage lifetime, and validation.
80 changes: 56 additions & 24 deletions docs/advanced/filesystem-serdes.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ Custom delegates and preview generators must support concurrent use.
| `previewGenerator` | Add a small JSON object alongside a file pointer. Return null to omit it. Previews are visible in checkpoint APIs; include only intended fields. |

A pointer plus preview must also fit within 255 KiB. Oversized previews fail
serialization and the unpublished file is removed. Preview failures propagate.
serialization before any file is written. Preview failures propagate.

## Operations and external boundaries

Configure `serDes(files)` on `StepConfig`, `RunInChildContextConfig`, `MapConfig`,
`ParallelBranchConfig`, or `WaitForConditionConfig`. Step exceptions are offloaded
through the same serializer with a separate entity identity. Polling states keep
separate immutable files even though they share an operation ID.
through the same serializer with a separate entity identity. Polling states
share one file, so each poll replaces the previous state (last write wins).

Like the .NET filesystem serializer, this implementation requires operation
context. Do not use it as `DurableConfig.withSerDes(files)`: the global serializer
Expand All @@ -68,23 +68,37 @@ Keep handler inputs/outputs small and normally encoded. Calling the two original
context-free SerDes methods throws a descriptive `SerDesException`.

`CallbackConfig.serDes(files)` and `InvokeConfig.serDes(files)` expect the producer
to supply a filesystem envelope and both sides to access the same mounted path.
The producer can call the explicit context overload with its own stable identity:
to supply a filesystem envelope. The consumer reads a `file` envelope from the path
it builds for its own execution and operation, so a producer should send an inline
`{"data":"<JSON>"}` envelope, for example from an `OVERFLOW` serializer. `OVERFLOW`
stores an inline envelope up to 255 KiB, including escaping; a larger payload still
overflows to a `file` envelope under the producer's identity. The consumer reads its
own file, so this inline route only carries payloads under that
limit:

```java
import software.amazon.lambda.durable.serde.FileSystemSerDes;
import software.amazon.lambda.durable.serde.FileSystemStorageMode;
import software.amazon.lambda.durable.serde.SerDesContext;

var envelope = files.serialize(value,
var inline = FileSystemSerDes.builder(base).storageMode(FileSystemStorageMode.OVERFLOW).build();
var envelope = inline.serialize(value,
new SerDesContext(durableExecutionArn, "external/approval/result"));
// Send envelope as the callback result, or return it from the invoked function.
```

The consumer context identifies the receiving operation; it need not equal the
producer context. Ordinary JSON callback/invoke results are not automatically
interpreted as filesystem envelopes. For a normal JSON invoke request with an
offloaded response, explicitly set `InvokeConfig.payloadSerDes(new JacksonSerDes())`
and `.serDes(files)`. Offloading the request itself with `.payloadSerDes(files)`
requires the invoked function to explicitly decode that envelope.
A producer can still offload a payload over that limit, by serializing it with a
`SerDesContext` naming the **consumer's own** execution ARN and the exact entity
value the consumer reads: `operation/<id>/result` for a callback or invoke result,
`operation/<id>/invoke-payload` for an invoke request. The producer also needs the
same `basePath` and `pathEncoding`. A `file` envelope written under any other
identity, including the producer's own, is not read. Ordinary JSON
callback/invoke results are not automatically interpreted as filesystem envelopes.
For a normal JSON invoke request with an offloaded response, explicitly set
`InvokeConfig.payloadSerDes(new JacksonSerDes())` and `.serDes(files)`. Offloading
the request itself with `.payloadSerDes(files)` means the invoked function must
decode that envelope with the **caller's** execution ARN and operation ID, the
identity `InvokeOperation` wrote the payload under, not its own.

Test runners support an explicit serializer when inspecting a step result:

Expand All @@ -101,37 +115,55 @@ Use `getStepDetails().result()` to inspect the raw checkpoint string. See

## Storage and replay

Use a durable, shared mount such as EFS with the same absolute path on every
Use a durable, shared mount such as EFS, with the same `basePath` on every
execution environment. Lambda `/tmp` is ephemeral and unsuitable for production
replay. Filesystems with delayed remote synchronization, including S3 Files, can
lose recent writes on runtime failure; local flush completion does not remove
that storage-specific durability limitation.

Each successful serialization creates a new file, closes and flushes it, then
returns its pointer. Later writes for the same execution/entity never change
previously returned references. A failed write or envelope construction removes
its unpublished file when possible. A process crash can leave an orphaned file.
Each entity has one file. A successful serialization writes it, closes and flushes
it, then returns its pointer. A later write for the same execution and entity
replaces the file (last write wins), so an earlier envelope reads the newer value.
For example, if a polling state is written but its checkpoint then fails, replay
reads that newer state. Concurrent writes to one entity can leave a torn file.
A failed write never deletes the file, but one that fails partway can leave it
partial or empty.

Files are never automatically deleted, including after completion. Retain them
for the complete execution and replay lifetime and arrange external cleanup for
completed/abandoned executions and orphaned writes. Repeated polling, retries,
and child-context execution can create additional files.

The mount and base directory must be controlled by the application. Readers reject
relative paths, traversal outside the base, and symlinks below it; writers reject
symlink execution directories. These checks do not isolate the application from
completed and abandoned executions.

The `file` path in an envelope is for people who browse the mount. Readers do not
open that path. They rebuild it from the base path, the execution ARN and the entity
ID, the same way the writer did. An envelope that names another execution's or
entity's file reads this execution's and entity's file instead, and fails if there
is none. A callback or invoke producer that sends a `file` envelope must have written
it with a `FileSystemSerDes` that used the consumer's execution ARN and entity ID and
the same `basePath` and `pathEncoding`. The `basePath` and `pathEncoding`
must stay the same for an execution's replay lifetime, because the path is rebuilt
from them.

The mount and base directory must be controlled by the application. Readers ignore the
envelope's file path and reject symlinks in the rebuilt path; writers reject
symlink execution directories and symlink files. These checks do not isolate the application from
other processes that can modify its mount. Filesystem permissions and retention
remain the application's responsibility. Missing files and I/O failures surface
as `SerDesException` with their original cause.

Executions that wrote files with an earlier SDK version cannot be read after
upgrading, because those file names carry a write ID. Let in-flight executions
finish before upgrading.

## Checkpoint format

```json
{"data":"<delegate-serialized string>"}
{"file":"<absolute path to an immutable payload file>"}
{"file":"<absolute path to the entity's payload file>"}
{"file":"<absolute path>","preview":{"characters":400000}}
```

The writer emits an absolute path. Readers ignore it, so any non-blank string is accepted.

Exactly one string field, `data` or `file`, is required. Inline data is a JSON
string containing the delegate payload, not an embedded JSON object. A file
contains the delegate payload itself. Null values use the existing null SerDes
Expand Down
4 changes: 2 additions & 2 deletions docs/advanced/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ identity it was created with, including after replay or when a cloud runner is
reused for another execution.

Local filesystem tests can use a JUnit `@TempDir`. Cloud tests that decode file
references need access to the same filesystem at the absolute path stored by the
function; the runner does not download payload files from Lambda. Collecting
references use a `FileSystemSerDes` with the function's `basePath` and `pathEncoding`
and need that mount; the runner does not download payload files from Lambda. Collecting
results and inspecting raw pointers remains possible without that mount. An
explicit filesystem read fails with `SerDesException` if its file is unavailable.

Expand Down
6 changes: 3 additions & 3 deletions docs/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ The execution ARN remains stable across Lambda invocations. An entity ID combine

`SerializableDurableOperation` supplies this context when serializing and deserializing results and exception data. `InvokeOperation` supplies the request context before checkpointing an invocation. Result deserialization receives the same operation identity during initial execution and replay. Exception type reconstruction and stack traces remain the responsibility of the operation runtime and `ExceptionHelper`.

An entity identifies a payload role, not an individual write: retries and polling can serialize multiple values for the same entity. External-storage serializers must preserve every reference already returned for checkpointing. Callback and invoke results may have a different producer identity; their deserialization context identifies the receiving operation.
An entity identifies a payload role, not an individual write: retries and polling can serialize multiple values for the same entity. `FileSystemSerDes` keeps one file per entity, so a later write replaces an earlier value. Callback and invoke results may have a different producer identity; their deserialization context identifies the receiving operation.

SerDes calls run synchronously on the calling thread. Serialization and deserialization can occur on different worker or context threads, so context is passed directly to each call and shared serializers must support concurrent use. Calls may repeat, including repeated result reads; there is no general SerDes deserialization cache or dedicated SerDes executor.

Expand Down Expand Up @@ -750,9 +750,9 @@ The checkpoint representations are:

A null delegate result remains null without creating a file. File-pointer envelopes, including any preview, must also fit within 255 KiB. Deserialization validates that the envelope contains exactly one string-valued `data` or `file` field, then delegates the inline or loaded payload using the caller's `TypeToken` and context.

Each offload writes a unique immutable file under the execution directory and flushes and closes it before returning the pointer. If a later write succeeds but its checkpoint fails, an earlier checkpoint still reads its original file. Ordinary failures attempt to remove unpublished files; a process crash can leave an orphan. Published files remain until the application cleans them up after their full execution and replay lifetime.
Each offload writes one file per entity under the execution directory and flushes and closes it before returning the pointer. A later write for the same entity replaces the file (last write wins), and a failed write never deletes it but can leave it partial or empty. Files remain until the application cleans them up after their full execution and replay lifetime.

Filesystem paths must remain accessible at the same absolute location across execution environments. Use a durable shared mount such as EFS; Lambda `/tmp` cannot support that replay contract. Local flush completion does not guarantee remote persistence for mounts with delayed synchronization, including S3 Files. The application controls the mount and base directory; the serializer rejects references outside the base and symlinks below it, but does not isolate other processes with write access to the mount.
Filesystem paths must be reachable through the same `basePath` across execution environments. Use a durable shared mount such as EFS; Lambda `/tmp` cannot support that replay contract. Local flush completion does not guarantee remote persistence for mounts with delayed synchronization, including S3 Files. The application controls the mount and base directory; the serializer ignores the envelope's file path, rebuilds the path under the base, and rejects symlinks in the rebuilt path, but does not isolate other processes with write access to the mount.

`FileSystemSerDes` rejects context-free calls, so it cannot be the global `DurableConfig` serializer. Configure it through `StepConfig`, `RunInChildContextConfig`, `MapConfig`, `ParallelBranchConfig`, or `WaitForConditionConfig`. Callback and invoke use also requires the external producer/consumer to understand the envelope and share the storage. Ordinary Lambda input/output and ordinary JSON callback/invoke payloads do not become filesystem envelopes automatically.

Expand Down
Loading