Files
floci/docs
Facundo ParedesandFacundo Paredes 9288769607 fix(stepfunctions): bound a running execution the four ways AWS does (#2782)
* fix(stepfunctions): enforce both TimeoutSeconds clocks

The state machine's top-level TimeoutSeconds was read back by
DescribeStateMachine and copied into activityScheduledEventDetails but
never used as a deadline, so an execution ran to completion however long
it took. Compute the budget once in doExecute, check it before every
state and inside the Wait sleep, and end the execution TIMED_OUT with
stopDate set, no error, no cause, and one ExecutionTimedOut event
carrying States.Timeout and previousEventId 0.

A Task's two bounds were swapped: HeartbeatSeconds acted as the total
wait and TimeoutSeconds was decorative, so "TimeoutSeconds": 5,
"HeartbeatSeconds": 60 failed at 60 seconds instead of 5. awaitToken now
bounds the whole wait with TimeoutSeconds and the gap between heartbeats
with HeartbeatSeconds. SendTaskHeartbeat only logged, so the gap bound
needed a per-token timestamp: the service now records one when the token
is registered and again on every heartbeat, and forgets it when the
waiting task stops listening.

Either clock ends the state as a TaskTimedOutException, which is what
us-east-1 answers for a heartbeat expiry: an ActivityTimedOut event
carrying error States.Timeout and no cause, then an execution reading
FAILED with error States.Timeout and no cause key, over the six-event
history ExecutionStarted, TaskStateEntered, ActivityScheduled,
ActivityStarted, ActivityTimedOut, ExecutionFailed. A Catch still
matches a heartbeat expiry under States.HeartbeatTimeout, so ErrorEquals
matching now asks the failure which names it answers to rather than
comparing one string.

The Wait sleep stops at the execution deadline instead of sleeping its
full duration first, which would have reported the timeout as many
seconds late as the Wait outlasts the budget and left a WaitStateExited
behind for a state AWS never finished. awaitToken discards its token on
the way out; without that the token would stay pending for the life of
the process and a later SendTaskSuccess would be answered as if someone
were still waiting.

Neither timeout carries a cause, so failExecution now reads a null cause
as the failure having none and leaves the key out of both
DescribeExecution and the ExecutionFailed event. The two other failures
that reach it without a cause -- a Fail state with no Cause, and
SendTaskFailure with no cause -- keep reporting an empty one, since
AWS's shape for those is unmeasured.

Refs #2733

* fix(stepfunctions): bound an execution's history and make StopExecution stop it

AWS puts two bounds on a running execution that floci did not: it ends one that
reaches 25,000 history events with States.Runtime, event 25,000 being the
ExecutionFailed event itself, and StopExecution stops the worker rather than
relabelling an execution that goes on to overwrite the status it wrote.

Counting an event against that limit and numbering it in the published history
are two meanings that one AtomicLong was carrying. They are separated here.
producedEventCount counts every event the execution produces, the top-level
flow's and those of its Parallel branches and inline Map iterations alike, and
is what the limit judges. The published history numbers its own events: an
event's id is its position in the list, which makes the list the only authority
for the next id, where the counter and the seal in StepFunctionsService used to
be a second one that agreed with it only at rest. A branch's events are counted
and never built, so executeBranch no longer assembles HistoryEvent objects with
full input and output JSON into a list it throws away.

A Distributed Map runs each item as a child execution on AWS, and a child
execution has a history of its own, so its items are counted against their own
limit rather than the parent's: a Distributed Map over 13,000 items no longer
fails the parent partway through with States.Runtime.

The count is taken before it is judged. Reading it and then taking it let 40
concurrent inline Map iterations through the same check and spent more events
than the execution had.

StopExecution records its abort against a history that need not be in memory.
Executions are stored and histories are not, so a restart in persistent mode
brings a RUNNING execution back with nothing behind it, and the same window
opens between a reset emptying the cache and emptying the store; the abort was
written to the store and then thrown away as a 500.

* fix(stepfunctions): end an execution that spends its budget waiting

A state machine's TimeoutSeconds budget was read only between states and
around the two pauses a definition asks for, a Wait and a Retry backoff. Every
other way a state blocks outlasted it: a Task waiting for its token, a
states:startExecution.sync or ecs:runTask.sync poll, and a Parallel or Map
waiting for its branches. Those executions ended past their budget, and ended
FAILED or SUCCEEDED rather than TIMED_OUT.

Each of those waits now stops at the budget, and the Task path publishes no
failure event for the state it cuts. Measured against us-east-1: a state
machine with TimeoutSeconds 5 over an activity Task whose own TimeoutSeconds
is 60 stops at exactly 5.000 s with status TIMED_OUT, and its history is
ExecutionStarted, TaskStateEntered, ActivityScheduled, ExecutionTimedOut, with
no ActivityTimedOut and no ExecutionFailed.

---------

Co-authored-by: Facundo Paredes <naranjax@MAC-69786.local>
2026-08-30 18:40:07 -04:00
..
2026-03-15 17:43:56 -05:00