Skip to content

fix(#1073): a definition that reads back and cannot run is refused - #1102

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/1073-asl-structure
Sep 19, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/1073-asl-structure

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

CreateStateMachine and UpdateStateMachine checked four things about a definition after #996 — non-empty, valid JSON, a JSON object, no wrongly-typed member — and nothing about whether the document named a runnable state machine. So {} created a state machine and answered 200, and so did a StartAt naming no state, a state with no Type, and a Next in one Parallel branch pointing into another.

Fourteen structural rules now apply at both writers, each resting on a sentence AWS publishes, and each message names the offending state and field — a caller fixing a generated document cannot act on "The provided Amazon States Language definition is not valid."

States present and non-empty (absent and {} answer different messages, the distinction #1062 needed for WAFv2's Addresses); StartAt naming a member of it; a published Type on every state; End refused on Choice/Succeed/Fail and exactly one of Next/End required on the other five; Choices non-empty with a Next on every top-level rule; Branches present on a Parallel; a Map carrying exactly one sub-state-machine; and every transition — Next, Catch[].Next, a rule's Next, Default — resolving inside its own States object, which is what refuses a branch that transitions out of itself.

State names are walked in sorted order, so a definition with two faults reports the same one on every run. A map range would have made the refusal a coin flip and the event log unreplayable.

The boundary

Structure, not semantics: a rule exists only where a published sentence makes the document malformed regardless of any input. So a Next on a Succeed or Fail state is accepted although it can never be taken — only End is published for those types, and borrowing the rest by analogy is what #671 forbids. A field a state type does not support is invisible, because ASLState is one flat struct carrying every type's members, apart from the three cases the pages name outright. Everything that depends on a run stays unchecked. docs/services.md lists each of these, plus the 1 MB definition-size quota substrate does not measure, replacing the paragraph that said only that conformance was unchecked.

Provenance corrections (posted on the issue before this PR opened)

  • The three capitalised-"MUST" sentences the issue quotes are states-language.net, which AWS links but does not host; none of the AWS pages read for this uses "MUST" at all. Every rule is cited to amazon-states-language-state-machine-structure.html or to the state type's own page, in AWS's words.
  • A fifth trap the issue's rule list omits: the Choice page publishes that "the Next field can appear only in a top-level Choice Rule", and ChoiceRule models a Next on every nested rule. A validator written to the acceptance criteria as phrased would have resolved that Next and accepted the document AWS refuses; it is refused where it stands instead.
  • ItemProcessor had to be added to ASLState, contrary to the issue's claim that no schema widening is needed. AWS marks it "(Required)", lists Iterator under "Deprecated fields", and then recommends Iterator to Step Functions Local — exactly the class of tool substrate is. So either spelling is accepted and both together refused.
  • The breaking test is cfn_intrinsics_test.go:628, not :620, and it is the only one in the corpus.

Fixed in passing

aslRunMap read Iterator alone, so a Map written with ItemProcessor iterated zero times and returned an empty array — a silently wrong answer rather than a refusal. Validator and executor now both read ASLState.mapWorkflow, and a new StartSyncExecution test iterates an ItemProcessor Map over three items.

Verification

Nine-command gate green; coverage 85.7% emulator / 85.2% total, above the 85.5%/85.0% floor. A 28-case refusal table runs at both writers, asserting code, status, AWS's message, the fault in the decoded Message, and that nothing was stored or moved; an 11-document acceptance test states what must still create; TestSFNASL_TwoFaultsReportTheSameOneEveryTime asserts a byte-identical body across twelve runs.

Closes #1073

#996 made CreateStateMachine and UpdateStateMachine check that a definition was
non-empty, valid JSON, a JSON object and free of wrongly-typed members, and
stopped there — so `{}` created a state machine and answered 200, as did a
StartAt naming no state and a Next in one Parallel branch pointing into another.

Fourteen structural rules now apply, each resting on a sentence AWS publishes,
with the message naming the offending state and field. The boundary is structure
over semantics: a rule exists only where a published sentence makes the document
malformed regardless of any input, so a Next on a Succeed state is accepted
(only End is published for that type) and everything that depends on a run stays
unchecked. docs/services.md lists what is left out.

Provenance: the issue's three capitalised-"MUST" sentences are
states-language.net, not an AWS page; the rules are cited to
amazon-states-language-state-machine-structure.html and the state pages instead.
The Choice page's "the Next field can appear only in a top-level Choice Rule" is
a trap the issue's rule list omits — a nested Next is refused where it stands
rather than resolved and accepted.

ItemProcessor is added to ASLState, contrary to the issue's claim that no schema
widening is needed: AWS marks it Required, lists Iterator under deprecated
fields, and recommends Iterator to Step Functions Local. Either spelling is
accepted and both together refused. aslRunMap read Iterator alone, so an
ItemProcessor Map iterated zero times and returned an empty array; both writers
now read ASLState.mapWorkflow.

Closes #1073
@scttfrdmn scttfrdmn added this to the v0.120.0 milestone Sep 19, 2026
@codecov

codecov Bot commented Sep 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.64865% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/stepfunctions_asl_structure.go 98.60% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit f20fe20 into main Sep 19, 2026
17 checks passed
@scttfrdmn
scttfrdmn deleted the fix/1073-asl-structure branch September 19, 2026 03:59
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.

Step Functions: a definition is checked for JSON readability but not for Amazon States Language structure

1 participant