Repository navigation
fix(replay): a recorded success body's RequestId is reproducible (#866) - #872
Merged
Merged
Conversation
generateRequestID is "req-" + time.Now().UnixNano(), and 66 non-test sites across seven plugins render it into a response body. Event had no request-ID field and RecordRequest copied none, so the recorded value was unrecoverable in principle — no work in the replay engine could reproduce a value the recording never stored. A replay rendered event.ID instead (service-op-seq-<UnixNano>), a third shape that was neither the recorded id nor a freshly minted one. Event now carries the request id, RecordRequest writes it, and replayEvent dispatches the handler with it, so a replayed success body is byte-identical to the recording. None of the 66 render sites needed editing. This is the missing half of a decision already taken. substrateRequestID's comment states that an error body has to be byte-identical across two replays of one recorded run; nothing had generalized the rule to the success path. The two halves now cross-reference each other, and they differ deliberately: an error body carries the fixed id SUBSTRATE because there the value identifies the emulator, while a success body's identifies the request. A live request's id still derives from the wall clock, recorded on generateRequestID rather than left implicit. Deriving one from the request would collide two identical requests onto a single id — the objection iamSLRTaskUUID already records — and making every minted value derived is #856's question. A stream recorded before the field existed replays with the event id in that position, since the original value was never written down and nothing can recover it; that keeps an older stream replaying exactly as it did rather than carrying an empty RequestId. The field round-trips through the file and SQLite backends, whose rows carry the serialized event. Three tests, split by what each can observe. A replay hands its caller counters and differences, never a response body — deep-comparing bodies is #817's remaining work — so the byte-identity assertion is made by a plugin that keeps the bytes it rendered, dispatched once live and once by the replay. A second test covers the pre-field stream. The third closes the gap the echo plugin leaves: it records SQS CreateQueue over the wire and asserts, on raw bytes, that the recorded event's id is the one <RequestId> holds in both the live and the recorded body. Part of #817. Closes #866.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 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.
generateRequestIDis"req-" + time.Now().UnixNano(), and 66 non-test sites across seven pluginsrender it into a response body (SQS 19, SNS 19, Redshift 10, CloudWatch 9, Lambda 5, STS 3,
CloudFormation 1).
Eventhad no request-ID field andRecordRequestcopied none, so the recordedvalue was unrecoverable in principle — no work in the replay engine could reproduce a value the
recording never stored. A replay rendered
event.IDinstead (service-op-seq-<UnixNano>), a thirdshape that was neither the recorded id nor a freshly minted one.
Eventnow carries the request id,RecordRequestwrites it, andreplayEventdispatches thehandler with it. None of the 66 render sites needed editing — they keep rendering
ctx.RequestID, which is now the recorded value on a replay.The missing half of a decision already taken
substrateRequestID's comment already states the rule, verbatim: "an error body has to bebyte-identical across two replays of one recorded run, and a caller diffing responses must not see a
field that changes on its own." Nothing had generalised it to the success path. The two halves now
cross-reference each other, and they differ deliberately: an error body carries the fixed id
SUBSTRATEbecause there the value identifies the emulator, while a success body's identifies therequest, and a caller correlating a response with a log line needs those distinct.
A live request's id still derives from the wall clock, and that is now recorded on
generateRequestIDrather than left implicit. Deriving one from the request would collide twoidentical requests onto a single id — the objection
iamSLRTaskUUID's own comment records — andmaking every minted value derived is #856's question, not this one's.
Compatibility
A replayed success body's
RequestIdnow matches the recording rather than differing from it.Nothing else observable changes.
A stream recorded before the field existed replays with the event id in that position. That is not a
reproduction of the original run — nothing can be, since the value was never written down — but it
is what such a stream replayed to before, so an older stream keeps replaying exactly as it did
instead of carrying an empty
RequestIdinto every body. The field round-trips through both thefile and SQLite backends, whose rows carry the serialised event rather than a fixed column list, so
neither needed a schema change.
Tests, and why they are split three ways
A replay hands its caller counters and differences, never a response body — deep-comparing bodies is
#817's remaining work — so no assertion on the bytes a replayed handler produced is available from
outside a plugin. Hence:
TestReplayedSuccessBodyReproducesTheRecordedRequestIDcarries the byte-identity assertion(issue AC 4) using a plugin that renders
ctx.RequestIDthe way the real sites do and keeps everybody it rendered, dispatched once live and once by the replay. It also asserts the replayed body
does not contain the event id, which is what distinguishes the fix from a coincidence — that
is precisely what the body carried before.
TestReplayOfAStreamWithoutARecordedRequestIDFallsBackToTheEventIDcovers streams already ondisk. The event is hand-built because that is the only way to produce a stream the current
recorder cannot write.
TestRecordedSQSSuccessBodyCarriesTheEventsRequestIDcloses the gap the echo plugin leaves:it records
CreateQueueover the wire and asserts on raw bytes that the recorded event's id iswhat
<RequestId>holds in both the live and the recorded body — a decodedResponseMetadatawould compare equal whether the element held the recorded id or nothing at all. This is what makes
"no render site needed editing" an assertion rather than a claim.
Negativity checked directly rather than assumed: with the
RecordRequestwrite removed and thefallback forced, tests 1 and 3 fail and test 2 passes — which is correct, since test 2 exercises the
unchanged path.
Full gate green —
gofmt/build/vet,golangci-lint(0 issues),make testandGOTOOLCHAIN=go1.26.6 make test, coverage (83.9% emulator / 83.3% total), the four docs checks,the docs site build, and the e2e suite.
docs/testing-guide.mdgains a "What a replayed response reproduces" subsection stating whichassertions about a request id are safe and which is not — two live calls with the same input do not
share one.
Part of #817, whose response-body comparison cannot run while a body field is guaranteed to differ.
Closes #866.