Skip to content

feat(#514): three of six published instance states become reachable, and how long they last is seedable - #1143

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/514-instance-state-progression
Sep 19, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/514-instance-state-progression

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

pending, stopping and shutting-down are three of the six codes instanceState's own Valid Values publish, and no code path in substrate could produce any of them: every state change reached its terminal state in the request that asked for it. So the one loop callers actually write around this API — run, start or stop, then poll until the state settles, which is what aws ec2 wait instance-running, Terraform's aws_instance and CDK's own custom resources all do — exited on its first iteration, and the retry, timeout and give-up branches those loops carry were never taken.

Two halves, and only the second needs a seed.

The operation's own response reports the transient state, unconditionally

AWS publishes this in the sample responses of the operations themselves: API_StartInstances shows currentState 0 / pending beside previousState 80 / stopped, and API_StopInstances shows 64 / stopping beside 16 / running. Substrate reported the settled state at all four write sites, so a consumer reading the transition out of the call it just made — a waiter's first observation — was told a transition that had already finished.

That is a published-response divergence with nothing to do with seeding, so it is corrected for every caller rather than behind a seed: RunInstances answers pending, StartInstances pending, StopInstances stopping, TerminateInstances shutting-down. The record still settles, so an unseeded describe answers exactly as before and no existing fixture changes — verified before the change by establishing that no test in the tree asserted currentState, previousState or any transient state name, which is how the divergence survived.

How long the transient state is reported is seeded

POST /v1/ec2/instance-state with {"instanceId","transientObservations"}; DELETE clears one seed or all. instanceId takes an ID or * (the default), an ID-scoped seed wins over the wildcard, the count defaults to 0 — the instantaneous behaviour the whole existing suite pins — and a negative count is refused. DescribeInstances and DescribeInstanceStatus read it, the latter both in the body and in its own instance-state-name filter, substituted before the filters so a filter cannot select a state the body does not report. Every state change restarts the count, which is what makes one seed serve a stop-then-start sequence rather than only its first transition.

Three shape decisions, each recorded in the doc comment against the in-tree snapshot precedent (#715):

A terminated instance can no longer be started or stopped

Both operations wrote the new state unconditionally, so a stop of a terminated instance produced a stopped one and a start produced a running one — against the lifecycle state table's "has been permanently deleted and cannot be started." Now IncorrectInstanceState / 400.

Provenance

Every citation is published, and the two places where it is thinner are recorded as such rather than smoothed over:

  • The start refusal rests on "has been permanently deleted and cannot be started" directly. The stop refusal rests on "permanently deleted" alone — no page found states a stop precondition — and is substrate's reading rather than letting a stop resurrect a deleted instance into a state it could then start from.
  • IncorrectInstanceState's published description is the general rule this is an instance of ("The instance is in an incorrect state for the requested action"); neither operation page publishes an error of its own, so the message text is substrate's.
  • EC2: every instance state transition is instantaneous, so pending, stopping and shutting-down are never observable #514's AC5 also asked for an operation to be refused from a transient state. Its supporting claim is published on neither page (both Errors sections are empty) and the criterion is vacuous by construction under the precedent's own rule: because a seed never rewrites the record, no operation ever observes a transient state. That is also what keeps seeding from breaking a caller's start-after-stop.

Two assertions in place of AC6's replay, and a new issue

AC6 asked for a replay of the event log to prove the sequence reproduces. That cannot hold for any seed in substrate: a seed is written through the control plane and so never enters the event stream, while ReplayEngine.Replay resets the whole StateManager before re-executing — so a replay of a seeded stream answers the unseeded sequence, with no event failing to make it visible. Filed as #1140 with the three candidate fixes; docs/services.md said the opposite ("Seeds live in the state manager, so they replay like any other state") and is corrected here.

In its place, two assertions that can hold and say more between them: the sequence run twice over two servers sharing nothing, and a replay proving the record was never rewritten by a seeded observation — which is the sharp test of the rule the whole design rests on. The replay's recorded stream carries no instance ID, because a replayed RunInstances mints a new one and a recorded request naming the old one is unreplayable (#856, untouched here).

Verification

Thirteen tests, 34 cases, all at HTTP level because the whole of the defect was observable only through a response. Alongside the behaviour above they pin the deliberate divergence from the snapshot precedent in both directions: an unreadable or unparseable seed leaves a describe alone (it answers the record's own state, because a control-plane failure must not turn a describe of a hundred instances into an error about none), while a state change that cannot restart the countdown fails (a silently unrestarted countdown would report a settled state for a transition the caller seeded to be observable). Five control-plane error paths answer 500 with the reason, since a seed that was not stored must not answer 200.

Full gate green (S1–S9). Coverage 85.9% emulator / 85.4% total, against the 85.5/85.0 floor. Three uncovered added blocks remain, all unreachable: a json.Marshal of a one-int struct, a json.Marshal of the seed struct, and a mapping arm no write site can reach.

Closes #514

…ate both pages publish

Two halves, and only the second needs a seed.

The operation's own response reports the transient state, unconditionally:
`API_StartInstances`' sample response shows `currentState` 0/`pending` beside
`previousState` 80/`stopped`, `API_StopInstances` 64/`stopping` beside
16/`running`. Substrate reported the settled state at all four write sites, so a
consumer reading the transition out of the call it just made saw one that had
already finished. That is a published-response divergence independent of
seeding, so it is corrected for every caller; the record still settles, so an
unseeded describe answers exactly as before.

How long the transient state is reported is seeded, through
`POST`/`DELETE /v1/ec2/instance-state`. Counted in observations rather than
measured as a duration, per the in-tree snapshot precedent and against #514's
own recommendation — the simulated clock advances with wall time. Per instance
even under a `*` seed. The transient state itself is derived from the target by
the published lifecycle, not seedable.

`StartInstances` and `StopInstances` now refuse a `terminated` instance with
`IncorrectInstanceState`/400 instead of resurrecting it.

Closes #514
@codecov

codecov Bot commented Sep 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.40260% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/ec2_instance_state_control.go 96.85% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 7334ed9 into main Sep 19, 2026
17 checks passed
@scttfrdmn
scttfrdmn deleted the feat/514-instance-state-progression branch September 19, 2026 19:55
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.

EC2: every instance state transition is instantaneous, so pending, stopping and shutting-down are never observable

1 participant