Skip to content

Step Functions: DeleteStateMachine and DeleteActivity refuse an absent resource with a code their pages do not publish #995

Closed

Description

@scttfrdmn

DeleteStateMachine and DeleteActivity refuse an absent resource with a code neither operation publishes, and neither models the asynchronous delete AWS documents.

Surfaced while implementing #912, which rewired every ARN-taking Step Functions operation onto a shared parser. The resolution defect is fixed there and the two *DoesNotExist codes were moved from HTTP 404 to 400 along with the rest. What #912 deliberately did not change is whether these two operations should refuse an absent resource at all, because the evidence is an absence from a published error list rather than an explicit idempotence sentence, and that deserves its own argument.

What AWS publishes

API_DeleteStateMachine lists exactly two errors:

Code Status
InvalidArn 400
ValidationException 400

StateMachineDoesNotExist is not among them, although it appears on API_DescribeStateMachine, API_UpdateStateMachine, API_StartExecution, API_StartSyncExecution and API_ListExecutions. The page's description also states the delete is asynchronous and that the state machine's status becomes DELETING:

Deletes a state machine. This is an asynchronous operation. It sets the state machine's status to DELETING and begins the deletion process.

API_DeleteActivity lists exactly one error, InvalidArn/400 — not ActivityDoesNotExist, which is one of only two errors on API_DescribeActivity. Its success is documented as:

If the action is successful, the service sends back an HTTP 200 response with an empty HTTP body.

What substrate answers today

After #912, deleteStateMachine (emulator/stepfunctions_plugin.go) answers StateMachineDoesNotExist/400 and deleteActivity answers ActivityDoesNotExist/400 for a well-formed ARN naming nothing. Both codes are real Step Functions codes at real Step Functions operations — just not at these two.

Why the absence is not conclusive on its own

The SNS precedent (#992) had a published idempotence sentence to lean on: API_DeleteTopic's "This action is idempotent, so deleting a topic that does not exist does not result in an error." Here there is no such sentence in either direction — the pages simply do not list the code. Two readings are open:

  1. The list is exhaustive, per CommonErrors' framing, so an absent resource is a 200 with an empty body and the delete is idempotent. This is the reading the error list supports literally.
  2. The list is incomplete, and AWS does refuse. Nothing on either page says so, and the argument rests only on the code existing elsewhere in the service.

Reading 1 also fits the documented asynchronous delete: a caller that has already issued a delete and retries has no way to distinguish "already gone" from "still DELETING", which is exactly the situation an idempotent delete exists for.

Adjacent, and part of the same decision

StateMachineDeleting — "The specified state machine is being deleted. Execution will not be started or updated." — is published at API_UpdateStateMachine, API_StartExecution and API_StartSyncExecution, and substrate models no DELETING status at all: deleteStateMachine removes the record synchronously, so nothing can ever observe the transition. Whether to model the status is the same question as whether the delete is idempotent, since a status a caller can observe is the only thing that makes a second delete distinguishable from the first.

Acceptance criteria

Provenance

API_DeleteStateMachine, API_DeleteActivity, API_DescribeActivity, API_UpdateStateMachine and API_StartExecution error lists, read in full while researching #912. Every Step Functions error on all eleven pages fetched is HTTP 400.

Activity

  1. added this to the v0.119.0 milestone on Sep 17, 2026
  2. added
    type: bug
    on Sep 17, 2026
  3. scttfrdmn commented on Sep 18, 2026

    @scttfrdmn
    OwnerAuthor

    Premise corrections before the PR opens

    Three things in the body are off, and one of the acceptance criteria would have destroyed coverage if followed literally. Recording them here so the divergence is on the issue rather than buried in a CHANGELOG bullet.

    1. Line drift. The citations are two and six lines low respectively: deleteStateMachine's refusal is stepfunctions_plugin.go:470/:479, not :471/:480, and deleteActivity's is :1038/:1049, not :1032/:1040.

    2. Neither page states idempotence. The body reads API_DeleteStateMachine's "This is an asynchronous operation. It sets the state machine's status to DELETING and begins the deletion process." as a published idempotence guarantee. It is not one — AWS never says a second delete succeeds. What actually carries the change is weaker and worth stating as such:

    • the error list is the only thing either page says on the matter, and it omits StateMachineDoesNotExist / ActivityDoesNotExist — both of which are real Step Functions codes, published at DescribeStateMachine, UpdateStateMachine, StartExecution, StartSyncExecution, ListExecutions and DescribeActivity, just not here;
    • the asynchronous description makes an idempotent delete the behaviour a caller needs, because a caller that has issued a delete and retries cannot distinguish "already gone" from "still DELETING".

    So this is substrate's reading of an absent code, and it is materially weaker evidence than #992's SNS DeleteTopic, whose page states the property outright. The code comment, docs/services.md and the CHANGELOG all say so rather than claiming AWS published it.

    Why substrate answered the unpublished code at all: both deletes went through the same require* helper as their five and one published siblings, so the code arrived with the lookup rather than by a decision. The fix loads directly and keeps the ARN parse ahead of the load, so every InvalidArn refusal survives.

    3. DELETING is documented but unreachable — and stays that way. stepfunctions_types.go:220 claimed StateMachineState.Status carries ACTIVE or DELETING. A tree-wide grep for a Status: writer in Step Functions finds exactly one, and it writes "ACTIVE". Nothing can write DELETING: the delete removes the record synchronously, so there is no observation between ACTIVE and gone for the value to occupy. StateMachineDeleting/400 — published at UpdateStateMachine, StartExecution and StartSyncExecution — is unreachable for the same reason.

    Modelling the transition is genuinely in scope for substrate (it is a seedable, observation-counted progression, exactly the shape the scope note in CLAUDE.md describes), but it is separate work. This PR states the limitation in the type's doc comment, in docs/services.md under The DELETING status is not modelled, and in a test that asserts the emulator's actual answer, so whoever models it later hits a failing assertion naming this decision instead of silently widening the enum.

    4. The acceptance criterion about the ARN tables is wrong and was not followed. It asks that both deletes "come out of sfnArnStateMachineOps (stepfunctions_arn_test.go:157-172) and sfnArnActivityOps (:174-185)". Removing them would have deleted live coverage: those two tables drive three other tests in which both deletes still must answer InvalidArn — the malformed-shape sweep, the wrong-resource-type sweep, and the version/alias-qualified sweep. Only the absent-resource loop changes.

    The tables therefore keep both operations and gain a column instead. The three anonymous structs collapse into one named type:

    type sfnArnOpCall struct {
    	op                 string
    	body               map[string]any
    	absentIsIdempotent bool
    }

    DeleteStateMachine and DeleteActivity carry absentIsIdempotent: true, and both absent-resource loops branch on it to assert an empty error code and a 200. The operation inventory stays in one place, which is the property that made those tables worth having.

    The closing assertion at :273-277 did need the restructuring the body predicted, and for the reason it gives: a 200 on a foreign ARN must still not touch the caller's own resource. Before this change the refusal itself proved the delete had not acted; now nothing about the status does, so that assertion is the only thing carrying it. Its comment now says so.

  4. added a commit that references this issue on Sep 18, 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: bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions