Repository navigation
Description
#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 theStatesfields."
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:
-
Statespresent and an object with at least one member. -
StartAtpresent, a string, and naming a member ofStates. - Every state has a
Type, and theTypeis one of the published values. - Every
Nextnames a member ofStates, including insideChoices,Catch,BranchesandIterator. - 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
sfnValidateDefinitionor a sibling it calls, so both writers get them from one place as they do today. -
TestSFNDefinition_ASLConformanceIsNotCheckedis replaced rather than deleted: its four cases become refusals and its doc comment stops recording a gap. - The nested
Nextcases are tested, becauseBranchesandIteratorrecurse 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.mdreplaces the current boundary paragraph with the new one. -
CHANGELOG.mdunder## [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
scttfrdmn commentedon Sep 19, 2026
Premise corrections, verified at
a33aad2against the tree and against six AWS Step Functions pagesThe defect is real and unfixed:
sfnValidateDefinition(stepfunctions_definition.go:37-59) checks exactly four things — empty,!json.Valid,trimmed[0] != '{', and a type error fromjson.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 publishInvalidDefinition/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. Citeamazon-states-language-state-machine-structure.html, which publishes both verbatim:The first sentence carries the issue's rules 1 and 2 together, including
StartAthaving to name a member ofStates.2. The
Next-or-Endrule must exempt three state types, and AWS names themSame page, verbatim:
So
Choice,SucceedandFailare exempt. The Choice page is stronger than that, and this is the part worth building to:A top-level
Nexton aChoicestate is therefore itself a divergence, not merely an alternative toEnd.ASLStatehas one flatNext(stepfunctions_types.go:26) shared by all eight types, so substrate can express the invalid document today and accepts it.3. The
Nextinventory is wrong in both directionsThe AC lists
Choices,Catch,BranchesandIterator. Two omissions and one thing that must be refused rather than resolved:Missing:
Choice'sDefault. It is a state reference —stepfunctions_types.go:68, consumed atstepfunctions_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 checksChoices[].Nextand notDefaultpasses aChoicestate whose fallback names nothing.Missing:
ItemProcessor— see 4.Wrong: a
Nextinside a nestedAnd/Or/Notmust be refused as misplaced, not resolved as a state reference. The Choice page publishes this outright:ChoiceRulemodelsAnd []ChoiceRule,Or []ChoiceRuleandNot *ChoiceRule, each nested rule carrying its ownNext(stepfunctions_types.go:163-173), so substrate accepts the document AWS refuses — and a validator written to the AC as phrased would resolve thatNextagainstStatesand accept it whenever the target happens to exist. Also published there and absent from the rule list:Choicesis Required and non-empty — "You must define at least one rule in theChoicestate."4.
ItemProcessoris the current spelling, and AWS tells tools like substrate to keep takingIteratorASLStatemodelsIterator *StateMachineDefinition(:82) and nothing namedItemProcessor. Onstate-map-inline.htmlthe field list marksItemProcessor(Required) andIteratorsits under a heading literally titled "Deprecated fields". But AWS accepts both:And the sentence that settles substrate's position, on the same page:
So the rule is exactly one of
ItemProcessororIterator, either accepted — refusing aMapfor a missingIteratorwould reject the spelling AWS marks Required, and refusing one for a missingItemProcessorwould reject the spelling AWS recommends to local emulators. This contradicts the issue's closing claim that "StateMachineDefinitionandASLStatealready model every field the rules above read, so no schema widening is needed" —ItemProcessorhas 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
Nextis scoped to the top-levelStatesmap; it follows fromStartAt'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:So each nested
Nextresolves against its ownStatesmap, and a nestedNextnaming a top-level state is a refusal rather than a pass.Branchesis a value slice andIteratora 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 namedStatesandStartAt, whose meanings are exactly like those in the top level of a state machine."6. Absent
Statesand emptyStatesare distinguishable, and should answer different messagesStates map[string]*ASLStateis 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'sAddresses. 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 oneNot
:620. Swept everyDefinitionStringin every test: that line's"DefinitionString": "{}"is the single template in the corpus that would start failing.8. Two acceptance criteria already hold
{"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 absentDefinitionStringfalls through to it.Typeis one of the published values" — the eight AWS publishes are exactly the eight already named inASLState.Type's doc comment (:22), so the enum needs no research, only enforcement.9.
TestSFNDefinition_ASLConformanceIsNotCheckedis atstepfunctions_definition_test.go:178Its 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 expectedInvalidDefinition/400 with the message naming the fault — which is also where the absent-vs-emptyStatessplit from 6 gets pinned.fix(#1074): the state machine definition resolves through the intrins…