Files
floci/docs
Facundo ParedesandFacundo Paredes f7f16cd2a3 fix(stepfunctions): bound $range allocation at the AWS memory limit (#2790)
* fix(stepfunctions): open a JSONata query evaluation cause with the AWS sentence

evaluateField now wraps a thrown JSONata failure with "The JSONata expression
'<expr>' specified for the field '<field>' threw an error during evaluation"
before the existing tail, matching real AWS. The separator is ". " when the
tail carries a JSONata error code and ": " when it is a bound message with
none. evaluate() keeps producing the bare tail unchanged for its direct
callers.

evaluate() stays the only place the JSONata engine is called and the only
catch around it: evaluateField calls it and enriches the failure it throws,
rather than reaching the engine itself. QueryEvaluationFailure carries the
separator across that throw, so a catch added to evaluate() later covers both
entry points. All 11 AslExecutor call sites reach the evaluator through
evaluateField or resolveTemplate, so a catch installed anywhere else would be
dead on every real execution path.

* fix(stepfunctions): catch Error from JSONata evaluation as States.QueryEvaluationError

An OutOfMemoryError or StackOverflowError raised while parsing or evaluating a JSONata
expression escaped JsonataEvaluator's catch (Exception) and reached AslExecutor's own
last-resort catch (Error), failing the whole execution as States.Runtime before the
state's own Retry and Catch ever ran. JsonataEvaluator.evaluate now also catches Error at
the same seam and translates it into a FailStateException with States.QueryEvaluationError,
so a Catch on the state (or on States.ALL) can recover, matching real AWS.

Closes #2738

* fix(stepfunctions): match AWS on the JSONata expressions it refuses

Four expression classes where Floci and AWS disagreed on whether the state
fails at all, all measured against us-east-1 with test-state.

The evaluation-depth ceiling drops from 500 to 100, which is AWS's own: five
nesting shapes bisected one n at a time all put its last accepted evaluation at
depth 100 and its first refusal at 101. An addition chain nests one level per
term and AWS accepts 100 terms; parentheses, brackets and the chain operator
nest one level more than their count and AWS accepts 99 of each; a
non-tail-recursive $f(n) nests 3n+5 and AWS accepts n=31, depth 98, refusing
n=32, depth 101.

The memory an expression may hold is now bounded, which it was not: one value an
evaluation step produces may hold 6,990,256 bytes, counting a number as eight
and a character as one. The two shapes AWS was bisected on, [1..873782] and a
string doubled 22 times, bracket a number at between five and nine bytes a
character: with the bound at 873,782 numbers, anything in that range leaves
4,194,304 characters inside it and 8,388,608 outside, and four or ten does not.
Eight is what a double costs, and it is inside the bracket. The check walks the
value and stops at the bound, and a lazy range is counted from its length rather
than materialised.

$eval is unbound, as AWS disables it, so a call to it answers T1006 the way AWS
does and $parse stays the replacement.

A non-finite number the expression itself evaluates to comes back as the string
AWS writes for it, since JSON has no literal for one: 1/0 and 1e308*10 are
"Infinity" and $parseInteger("abc","0") is "NaN", where the first two raised
D1001 and the third returned nothing and failed the field. One the library's
arithmetic buries inside a value, as in [1/0], still fails the state, because
the refusal is the only place the library leaves the value and it has already
unwound what was being built; one a function answers nests like any other value.
$formatNumber checks its picture string against the fourteen rules of XPath F&O
4.7.3 first, so $formatNumber(1, "x") fails with D3086 instead of answering "x1".
Which of the fourteen codes AWS reports is what fixes the order the rules are
read in: a picture with no digit breaks D3085 and D3086 at once and AWS reports
the second, so the last rule broken names the failure rather than the first.

Closes #2737

* fix(stepfunctions): bound $range allocation at the AWS memory limit

AWS accepts $range(1, 360145, 1), all 360,145 elements, and refuses one
element more on its own memory limit. Floci's $range had no such bound:
it built the array in full before the memory check on the value ever ran,
so a call far past AWS's limit spent gigabytes and either exhausted the
heap or hung instead of failing the state cleanly.

range() now refuses a call whose produced element count exceeds the
measured bound before allocating, throwing the same
States.QueryEvaluationError JException the held-memory check raises,
whose message is now a single shared constant. Other built arrays keep
the looser, byte-based bound.

* test(stepfunctions): pin the number model of the execution input

Measured against real AWS (test-state, 2026-08-30): a Pass state with
Output {"v": "{% $states.input.amount %}"} answers {"v": 1} for input
{"amount": 1.0} and {"v": 9.223372036854776E18} for input
{"amount": 9223372036854775808}. That is exactly what routing the
execution input through toJsonataValue/toJsonataNumber already
produces, so these two tests pin it against silent regression.

---------

Co-authored-by: Facundo Paredes <25681464+facuparedes@users.noreply.github.com>
2026-08-31 00:16:52 -04:00
..
2026-03-15 17:43:56 -05:00