feat(lambda): run durable functions with checkpoints, waits and step retries (#5047)

* feat(lambda): run durable functions with checkpoints, waits and step retries

Invoking a durable function starts a durable execution, through Invoke or through an ARN (EventBridge, Scheduler, function URLs, destinations). The function checkpoints through CheckpointDurableExecution and GetDurableExecutionState, and Floci re-invokes it when a wait or a step retry comes due. GetDurableExecution, GetDurableExecutionHistory, ListDurableExecutionsByFunction and StopDurableExecution read and stop executions. Timers are persisted deadlines fired by a background sweep, so an execution survives a restart. Callbacks and chained invokes are rejected at checkpoint time.

* fix(iam): authorize durable execution actions against the owning function

A durable execution route has no /functions/ segment, so its resource fell back to *. The function name now comes from the execution ARN in the path.

* fix(lambda): keep durable executions inside their account

The execution APIs took the account from the ARN in the path, so another account could read or stop an execution. An ARN of another account is now ResourceNotFoundException.

* fix(lambda): limit the error size of an EXECUTION checkpoint too

* fix(lambda): reject an EXECUTION close that carries the other result kind

AWS rejects SUCCEED with an Error and FAIL with a Payload on the EXECUTION operation, as it does for steps.

* fix(lambda): spend a durable wake-up when a failed invocation schedules its retry

* fix(lambda): keep a durable crash retry's backoff across a restart

* fix(lambda): bound the durable execution locks

A lock per execution ARN was kept forever, even for an ARN that did not exist. A fixed set of striped locks replaces it. Locks are never nested, so a shared stripe cannot deadlock.

* fix(lambda): accept PAUSED, PAUSING and DELETING as durable status filters

AWS accepts them and answers an empty list, since Floci never puts an execution in those states.

* fix(lambda): reject a non-finite durable list timestamp

* test(lambda): resume a durable execution from its JSON file after a restart

* fix(lambda): keep durable executions inside their region

An execution ARN of another region now answers ResourceNotFoundException "Function not found", as AWS does, instead of reaching the execution past the IAM check of the request region.

* fix(lambda): validate durable list parameters before an empty status filter answers

Statuses of only PAUSED, PAUSING or DELETING still checks MaxItems and Marker, as AWS does. The bad Marker message is "Invalid Marker".

* perf(lambda): skip the execution scan for a status filter that matches nothing

Statuses of only PAUSED, PAUSING or DELETING now checks MaxItems and Marker without listing the account's executions.

* test(lambda): drop durable tests that repeat other coverage

The in-memory restart test repeats the persistence test, and the Docker success case repeats the compat suite's checkpoint loop. The Docker test keeps the failure case.

* fix(lambda): re-attach a durable execution name only on the same version

AWS keeps execution names unique per function across versions. A sync Invoke of another version with the same name and payload is DurableExecutionAlreadyStartedException, not the existing execution.

* chore(lambda): simplify the durable execution engine

Drop stored fields nothing reads, share the unseen-operations and
page-cursor helpers, skip the name scan for a generated name, and save
an execution once per invocation instead of twice.

* fix(lambda): reject a non-integer durable MaxItems as AWS does

AWS answers MaxItems=x on the durable execution APIs with
SerializationException "'x' can not be converted to Integer".

* docs(lambda): list the durable execution size limits as not emulated

* fix(iam): authorize durable execution actions against the execution ARN

The durable execution actions take the durable execution resource,
function:name:version/durable-execution/name/id. A role allowed on
function:name:* may checkpoint, one allowed only on the unqualified
function ARN is denied.

* fix(lambda): answer an unknown durable execution on checkpoint as a bad token

CheckpointDurableExecution and GetDurableExecutionState do not model
ResourceNotFoundException. AWS answers InvalidParameterValueException:
"Checkpoint token is not valid for the durable execution ARN" for a
token minted for another execution, "Invalid checkpoint token" otherwise.

* fix(lambda): replay a durable checkpoint retried with the same ClientToken

AWS answers a retry of the last checkpoint with the same ClientToken
with the same state and a usable next token, even though the request
token is spent. A different ClientToken, a retry after the next
checkpoint, or a retry of the checkpoint that closed the execution is
still an invalid checkpoint token.

* fix(lambda): validate durable list filters as AWS does

ListDurableExecutionsByFunction takes one status at most and answers
more with InvalidParameterValueException "Cannot filter by more than one
status". An unreadable StartedAfter or StartedBefore is
SerializationException "'<value>' can not be converted to Date", and a
plain date is accepted. Type errors come first, then MaxItems and status
values, then the single-status rule, then the function lookup.

* docs(lambda): note the history IncludeExecutionData default

* fix(lambda): report durable MaxItems and Statuses errors as AWS does

AWS puts an invalid MaxItems and an invalid Statuses into one
ValidationException ("2 validation errors detected: ...; ..."), MaxItems
first. A negative MaxItems must be greater than or equal to 0. MaxItems
is checked before the execution or function is looked up.

* refactor(lambda): share one durable execution ARN pattern with IAM

IAM and the durable execution service now recognize an execution ARN
with the same pattern, the one AWS validates it with.

* fix(lambda): replay a durable checkpoint answer as it was sent

On AWS a retry with the same ClientToken returns the operations as the
first answer had them: a WAIT stays STARTED in the retry even after it
has elapsed, while a fresh checkpoint reports it SUCCEEDED.
This commit is contained in:
TATSUNO “Taz” Yasuhiro authored and GitHub committed 2026-10-04 20:08:39 -04:00
1 parent 383c32443d
commit 6a3bc12769
49 files changed
+5007 -10

No files matched your search

+49 -3
View File
@@ -16,7 +16,7 @@ Floci Lambda runs your function code locally inside real Docker containers - clo
| `UpdateFunctionCode` | Upload new code |
| `UpdateFunctionConfiguration` | Update runtime, handler, memory, timeout, environment, architectures, tracing, layers, and more |
| `DeleteFunction` | Remove a function |
| `Invoke` | Invoke a function synchronously or asynchronously |
| `Invoke` | Invoke a function synchronously or asynchronously. A durable function starts a durable execution |
| `CreateEventSourceMapping` | Connect SQS / Kinesis / DynamoDB Streams to a function |
| `GetEventSourceMapping` | Get event source mapping details |
| `ListEventSourceMappings` | List all event source mappings |
@@ -55,6 +55,12 @@ Floci Lambda runs your function code locally inside real Docker containers - clo
| `GetFunctionEventInvokeConfig` | Read the asynchronous invocation settings |
| `DeleteFunctionEventInvokeConfig` | Remove the asynchronous invocation settings |
| `ListFunctionEventInvokeConfigs` | List the asynchronous invocation settings of every version and alias of a function |
| `CheckpointDurableExecution` | Record the operation updates of the Durable Execution SDK and return the new state |
| `GetDurableExecutionState` | Operations of a running durable execution, for replay |
| `GetDurableExecution` | Status, result or error and the DurableConfig of a durable execution |
| `GetDurableExecutionHistory` | Event log of a durable execution, oldest or newest first |
| `ListDurableExecutionsByFunction` | Durable executions of a function or version, filtered by status, name and start time |
| `StopDurableExecution` | Stop a running durable execution with an error |
`UpdateFunctionConfiguration` validates `MemorySize` and `Timeout` as whole numbers in their
supported ranges before changing any stored settings. A rejected value returns
@@ -147,6 +153,43 @@ Two limits are worth knowing:
that fans back to the function, or a bus rule targeting it, each start a fresh chain at zero.
Avoid configuring one until this is closed.
### Durable Functions
A function created with `DurableConfig` is a durable function. Invoking it through a version or
alias (`name:1`, `name:live`, `?Qualifier=1`) starts a durable execution. An unqualified name is
rejected, as on AWS. `X-Amz-Durable-Execution-Name` names the execution, and Floci generates a
UUID when it is absent. `X-Amz-Durable-Execution-Arn` returns the execution ARN. A
`RequestResponse` invoke blocks until the execution ends, waits included, and needs an
`ExecutionTimeout` of 15 minutes or less. `Event` answers 202 and the execution continues in the
background. Invocations through an ARN (EventBridge, Scheduler, function URLs, destinations) start
durable executions the same way.
The checkpoint protocol under `/2025-12-01` is the real one, so the Durable Execution SDK works
unchanged for steps, waits, step retries and replay. Timers are persisted and fired by a
background sweep, so an execution survives a restart of Floci. A function that returns something
other than the `{Status, Result, Error}` envelope fails its execution with
`Invalid Status in invocation output.` A function that throws is re-invoked four more times, after
1, 2, 4 and 8 seconds, and then fails the execution with its error. AWS does the same over a few
minutes.
`GetDurableExecutionHistory` leaves payloads out unless `IncludeExecutionData=true` is sent. The
API reference names `true` as the default, but AWS answers this way.
The public `public.ecr.aws/lambda` images do not bundle the SDK that the managed runtimes carry.
Add `aws-durable-execution-sdk-python` or `@aws/durable-execution-sdk-js` to your deployment
package.
Not emulated yet:
- Callbacks (`WaitForCallback` and the `SendDurableExecutionCallback*` APIs) and chained invokes
(`context.invoke`). Both are rejected at checkpoint time.
- Durable executions started by Step Functions or by an event source mapping. These invoke the
function as a plain one.
- Payload encryption. `KMSKeyArn` is stored and returned only.
- EventBridge status-change events, the X-Ray `TraceHeader`, and a dead-letter queue or
destinations for durable executions.
- The per-execution limits of 3,000 operations and 100 MB of persisted payload.
## Hot-Reloading via Reactive S3 Sync
Floci supports an automatic hot-reloading mechanism when functions are deployed via S3. This follows the standard AWS behavior where S3 and Lambda interact, but is optimized for a seamless local development experience.
@@ -344,6 +387,8 @@ These AWS Lambda operations have no handler in Floci. Calls will return `404` or
- Layer permissions (`AddLayerVersionPermission`, `RemoveLayerVersionPermission`, `GetLayerVersionPolicy`)
- Provisioned concurrency (`PutProvisionedConcurrencyConfig`, `GetProvisionedConcurrencyConfig`, `ListProvisionedConcurrencyConfigs`, `DeleteProvisionedConcurrencyConfig`)
- `InvokeWithResponseStream`
- Durable function callbacks and chained invokes (`SendDurableExecutionCallbackSuccess`,
`SendDurableExecutionCallbackFailure`, `SendDurableExecutionCallbackHeartbeat`). See Durable Functions
- Code signing enforcement. A configuration is created, read, updated, deleted and listed, and
nothing verifies a signature against it, so it never gates a deployment. Attaching one to a
function is not wired either: there is no `PutFunctionCodeSigningConfig`, so
@@ -369,6 +414,8 @@ These AWS Lambda operations have no handler in Floci. Calls will return `404` or
| `FLOCI_SERVICES_LAMBDA_HONOUR_ARCHITECTURES` | `false` | Select each function's declared architecture for Docker image pulls and containers |
| `FLOCI_SERVICES_LAMBDA_DEFAULT_MEMORY_MB` | `128` | Default function memory (MB) |
| `FLOCI_SERVICES_LAMBDA_DEFAULT_TIMEOUT_SECONDS` | `3` | Default function timeout (seconds) |
| `FLOCI_SERVICES_LAMBDA_DURABLE_SWEEP_ENABLED` | `true` | Fire durable execution timers (waits, step retries, execution timeouts, retention expiry) |
| `FLOCI_SERVICES_LAMBDA_DURABLE_SWEEP_INTERVAL_SECONDS` | `1` | How often the durable sweep runs |
| `FLOCI_SERVICES_LAMBDA_RUNTIME_API_BASE_PORT` | `12000` | First port in the Lambda Runtime API range |
| `FLOCI_SERVICES_LAMBDA_RUNTIME_API_MAX_PORT` | `12499` | Last port in the Lambda Runtime API range. One port is held per running container, so the range width caps concurrent executions. Each running container also holds two Docker connections, so a wider range needs a matching `FLOCI_DOCKER_MAX_CONNECTIONS` |
| `FLOCI_SERVICES_LAMBDA_CODE_PATH` | `./data/lambda-code` | Directory where Lambda ZIP files are stored |
@@ -703,8 +750,7 @@ is a permanent diff rather than a cosmetic omission.
`DurableConfig` requires `ExecutionTimeout` on create. A durable function created without
a `Timeout` gets `min(ExecutionTimeout, 900)`. It always logs in JSON format, and
`LogFormat: Text` is rejected. On update the members are merged, and a function created
without `DurableConfig` cannot gain one. The durable execution itself (checkpoints, waits,
callbacks) is not emulated yet; the configuration only round-trips.
without `DurableConfig` cannot gain one. See Durable Functions for the execution itself.
`LogGroup` is validated against AWS's documented constraint: 1-512 characters matching
`[.\-_/#A-Za-z0-9]+`. `ApplicationLogLevel` and `SystemLogLevel` are accepted with any