Skip to content

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

Closed

Description

@scttfrdmn

#996 made CreateStateMachine and UpdateStateMachine refuse a definition substrate could not read back — that it is non-empty, parses as JSON, and describes a JSON object. That is deliberately narrower than what AWS checks, and docs/services.md records the boundary rather than implying full validation. This issue is the rest.

What is accepted today and AWS refuses

{} creates a state machine. So do all of these:

Definition Why AWS refuses it
{} no StartAt, no States
{"States":{"Start":{"Type":"Pass","End":true}}} no StartAt
{"StartAt":"Start"} no States
{"StartAt":"Nowhere","States":{"Start":{"Type":"Pass","End":true}}} StartAt names no state

TestSFNDefinition_ASLConformanceIsNotChecked pins all four as accepted, deliberately, so this issue's fix arrives as four failing assertions naming the decision rather than a silent change.

What the Amazon States Language requires

The ASL specification's State Machine section, which is the citation trail this issue rests on rather than any single API page:

  • "A State Machine MUST have an object field named States, whose fields represent the states."
  • "A State Machine MUST have a string field named StartAt, whose value MUST exactly match one of names of the States fields."

And per state: "All states MUST have a Type field", and a non-terminal state MUST have exactly one of Next or End: true — with Next's value having to match a sibling state's name.

The API-level landing place is already in the tree: InvalidDefinition/400, "The provided Amazon States Language definition is not valid.", which API_CreateStateMachine and API_UpdateStateMachine publish and which sfnInvalidDefinition (emulator/stepfunctions_errors.go) constructs. So this issue adds rules, not a code.

Scope, and where to stop

Full ASL validation is not the goal and would be a poor use of the boundary in CLAUDE.md: a definition's semantics are close to workload-internal, and substrate does not execute arbitrary ASL faithfully in the first place. What is worth having is the structural set a consumer's own test would trip over, because those are the mistakes a generator of IaC actually makes:

  • States present and an object with at least one member.
  • StartAt present, a string, and naming a member of States.
  • Every state has a Type, and the Type is one of the published values.
  • Every Next names a member of States, including inside Choices, Catch, Branches and Iterator.
  • Each rule's message names the offending state or field, since a caller fixing a generated document needs to know which one.
  • Anything left unvalidated is listed in docs/services.md, replacing the current paragraph that says only that conformance is unchecked.

StateMachineDefinition and ASLState (emulator/stepfunctions_types.go) already model every field the rules above read, so no schema widening is needed.

Acceptance criteria

  • The rules above, in sfnValidateDefinition or a sibling it calls, so both writers get them from one place as they do today.
  • TestSFNDefinition_ASLConformanceIsNotChecked is replaced rather than deleted: its four cases become refusals and its doc comment stops recording a gap.
  • The nested Next cases are tested, because Branches and Iterator recurse and a validator that checks only the top level would pass a broken Map state.
  • The CloudFormation deployer's stub definition still validates, and so does every definition in the test corpus.
  • docs/services.md replaces the current boundary paragraph with the new one.
  • CHANGELOG.md under ## [Unreleased].

Provenance

The Amazon States Language specification's State Machine and State sections. InvalidDefinition's code, status and message come from API_CreateStateMachine and API_UpdateStateMachine, both fetched while implementing #996.

Activity

  1. added this to the v0.120.0 milestone on Sep 18, 2026
  2. added
    type: feature
    on Sep 18, 2026
  3. scttfrdmn commented on Sep 19, 2026

    @scttfrdmn
    OwnerAuthor

    Premise corrections, verified at a33aad2 against the tree and against six AWS Step Functions pages

    The defect is real and unfixed: sfnValidateDefinition (stepfunctions_definition.go:37-59) checks exactly four things — empty, !json.Valid, trimmed[0] != '{', and a type error from json.Unmarshal — none of them structural, and all four of the accepted-garbage cases in the table above reproduce. sfnInvalidDefinition (stepfunctions_errors.go:167-173) exists and both pages publish InvalidDefinition/400, so this adds rules and not a code, as the issue says. Nine things below change what gets built.

    1. The provenance is wrong: no AWS page carries those sentences

    The three quoted "MUST" sentences are from states-language.net, which AWS links but does not host. None of the six docs.aws.amazon.com/step-functions/ pages checked uses capitalised "MUST" at all — AWS states every one of these rules in different words, under a (Required) marker. Cite amazon-states-language-state-machine-structure.html, which publishes both verbatim:

    StartAt (Required) A string that must exactly match (is case sensitive) the name of one of the state objects.

    States (Required) An object containing a comma-delimited set of states.

    The first sentence carries the issue's rules 1 and 2 together, including StartAt having to name a member of States.

    2. The Next-or-End rule must exempt three state types, and AWS names them

    Same page, verbatim:

    Only one of Next or End can be used in a state. Some state types, such as Choice, or terminal states, such as Succeed workflow state and Fail workflow state, don't support or use the End field.

    So Choice, Succeed and Fail are exempt. The Choice page is stronger than that, and this is the part worth building to:

    Choice states do not support the End field. In addition, they use Next only inside their Choices field.

    A top-level Next on a Choice state is therefore itself a divergence, not merely an alternative to End. ASLState has one flat Next (stepfunctions_types.go:26) shared by all eight types, so substrate can express the invalid document today and accepts it.

    3. The Next inventory is wrong in both directions

    The AC lists Choices, Catch, Branches and Iterator. Two omissions and one thing that must be refused rather than resolved:

    • Missing: Choice's Default. It is a state reference — stepfunctions_types.go:68, consumed at stepfunctions_asl.go:231-233 — and AWS publishes it as one: "Default (Optional, Recommended) The name of the state to transition to if no Choice Rule evaluates to true." A validator that checks Choices[].Next and not Default passes a Choice state whose fallback names nothing.

    • Missing: ItemProcessor — see 4.

    • Wrong: a Next inside a nested And/Or/Not must be refused as misplaced, not resolved as a state reference. The Choice page publishes this outright:

      The values of the And and Or operators must be non-empty arrays of Choice Rules that must not themselves contain Next fields. Likewise, the value of a Not operator must be a single Choice Rule that must not contain Next fields.

      You can create complex, nested Choice Rules using And, Not, and Or. However, the Next field can appear only in a top-level Choice Rule.

      ChoiceRule models And []ChoiceRule, Or []ChoiceRule and Not *ChoiceRule, each nested rule carrying its own Next (stepfunctions_types.go:163-173), so substrate accepts the document AWS refuses — and a validator written to the AC as phrased would resolve that Next against States and accept it whenever the target happens to exist. Also published there and absent from the rule list: Choices is Required and non-empty — "You must define at least one rule in the Choice state."

    4. ItemProcessor is the current spelling, and AWS tells tools like substrate to keep taking Iterator

    ASLState models Iterator *StateMachineDefinition (:82) and nothing named ItemProcessor. On state-map-inline.html the field list marks ItemProcessor (Required) and Iterator sits under a heading literally titled "Deprecated fields". But AWS accepts both:

    The ItemProcessor field replaces the now deprecated Iterator field. Although you can continue to include Map states that use the Iterator field, we highly recommend that you replace this field with ItemProcessor.

    And the sentence that settles substrate's position, on the same page:

    Step Functions Local doesn't currently support the ItemProcessor field. We recommend that you use the Iterator field with Step Functions Local.

    So the rule is exactly one of ItemProcessor or Iterator, either accepted — refusing a Map for a missing Iterator would reject the spelling AWS marks Required, and refusing one for a missing ItemProcessor would reject the spelling AWS recommends to local emulators. This contradicts the issue's closing claim that "StateMachineDefinition and ASLState already model every field the rules above read, so no schema widening is needed" — ItemProcessor has to be added to the type, and it is the only schema change the issue needs.

    5. Scoping is published for Parallel and Map specifically, not as a general rule

    There is no AWS sentence saying a top-level Next is scoped to the top-level States map; it follows from StartAt's wording only by analogy. What is published is the containment rule at each recursion point, and these two sentences are the citation for recursing at all:

    Each branch must be self-contained. A state in one branch of a Parallel state must not have a Next field that targets a field outside of that branch, nor can any other state outside the branch transition into that branch.

    States within the ItemProcessor field can only transition to each other. No state outside the ItemProcessor field can transition to a state within it.

    So each nested Next resolves against its own States map, and a nested Next naming a top-level state is a refusal rather than a pass. Branches is a value slice and Iterator a pointer (:80, :82), so the two recursion arms are not symmetrical in code. And the Parallel page supplies the reason the top-level rules apply unchanged at depth: "Branches (Required) An array of objects that specify state machines to execute in parallel. Each such state machine object must have fields named States and StartAt, whose meanings are exactly like those in the top level of a state machine."

    6. Absent States and empty States are distinguishable, and should answer different messages

    States map[string]*ASLState is nil when the member is absent and non-nil-but-empty for "States":{}, so the AC's "present and an object with at least one member" is two faults, not one — the same three-way distinction #1062 needed for WAFv2's Addresses. Given the AC's own requirement that each message name the offending field, report them separately.

    7. Citation drift: the breaking test is cfn_intrinsics_test.go:628, and it is the only one

    Not :620. Swept every DefinitionString in every test: that line's "DefinitionString": "{}" is the single template in the corpus that would start failing.

    8. Two acceptance criteria already hold

    • "The CloudFormation deployer's stub definition still validates" — the stub is {"Comment":"stub","StartAt":"Start","States":{"Start":{"Type":"Pass","End":true}}} (cfn_resources_v20.go:36-38) and passes every rule above. It is also genuinely reachable rather than dead: marshalToJSON(nil) returns "" (cfn_deployer.go:6071-6074), so an absent DefinitionString falls through to it.
    • "the Type is one of the published values" — the eight AWS publishes are exactly the eight already named in ASLState.Type's doc comment (:22), so the enum needs no research, only enforcement.

    9. TestSFNDefinition_ASLConformanceIsNotChecked is at stepfunctions_definition_test.go:178

    Its four subtests are keyed by label in a map and each asserts a 200 plus a round-tripped definition. Replacing it means each label becomes an expected InvalidDefinition/400 with the message naming the fault — which is also where the absent-vs-empty States split from 6 gets pinned.

  4. added a commit that references this issue on Sep 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: feature

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions