Repository navigation
feat(#514): three of six published instance states become reachable, and how long they last is seedable - #1143
Merged
Conversation
…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 Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
pending,stoppingandshutting-downare three of the six codesinstanceState'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 whataws ec2 wait instance-running, Terraform'saws_instanceand 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_StartInstancesshowscurrentState0 /pendingbesidepreviousState80 /stopped, andAPI_StopInstancesshows 64 /stoppingbeside 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:
RunInstancesanswerspending,StartInstancespending,StopInstancesstopping,TerminateInstancesshutting-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 assertedcurrentState,previousStateor any transient state name, which is how the divergence survived.How long the transient state is reported is seeded
POST /v1/ec2/instance-statewith{"instanceId","transientObservations"};DELETEclears one seed or all.instanceIdtakes an ID or*(the default), an ID-scoped seed wins over the wildcard, the count defaults to0— the instantaneous behaviour the whole existing suite pins — and a negative count is refused.DescribeInstancesandDescribeInstanceStatusread it, the latter both in the body and in its owninstance-state-namefilter, 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):
TimeController.Nowadvances with wall time, so a duration seed would make every "still pending" assertion depend on how long the rest of the test took.*seed, so one describe over five instances does not burn five observations off a shared countdown (SQS: a wildcard consistency seed can be double-consumed, because the lock is striped by queue name #582's hazard).pending"when it is launched or when it is started after being in the stopped state",stopping,shutting-down— where a snapshot'sstatusis a free choice from five values. So the seed carries a count and nothing else.A
terminatedinstance can no longer be started or stoppedBoth operations wrote the new state unconditionally, so a stop of a terminated instance produced a
stoppedone and a start produced arunningone — against the lifecycle state table's "has been permanently deleted and cannot be started." NowIncorrectInstanceState/ 400.Provenance
Every citation is published, and the two places where it is thinner are recorded as such rather than smoothed over:
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.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.Replayresets the wholeStateManagerbefore 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.mdsaid 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
RunInstancesmints 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.Marshalof a one-int struct, ajson.Marshalof the seed struct, and a mapping arm no write site can reach.Closes #514