Skip to content

fix(replay): a recorded success body's RequestId is reproducible (#866) - #872

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/866-request-id
Sep 15, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/866-request-id

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

generateRequestID is "req-" + time.Now().UnixNano(), and 66 non-test sites across seven plugins
render it into a response body (SQS 19, SNS 19, Redshift 10, CloudWatch 9, Lambda 5, STS 3,
CloudFormation 1). 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. 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 be
byte-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
SUBSTRATE because there the value identifies the emulator, while a success body's identifies the
request, 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
generateRequestID rather than left implicit. Deriving one from the request would collide two
identical requests onto a single id — the objection iamSLRTaskUUID's own comment records — and
making every minted value derived is #856's question, not this one's.

Compatibility

A replayed success body's RequestId now 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 RequestId into every body. The field round-trips through both the
file 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:

  • TestReplayedSuccessBodyReproducesTheRecordedRequestID carries the byte-identity assertion
    (issue AC 4) using a plugin that renders ctx.RequestID the way the real sites do and keeps every
    body 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.
  • TestReplayOfAStreamWithoutARecordedRequestIDFallsBackToTheEventID covers streams already on
    disk. The event is hand-built because that is the only way to produce a stream the current
    recorder cannot write.
  • TestRecordedSQSSuccessBodyCarriesTheEventsRequestID closes the gap the echo plugin leaves:
    it records CreateQueue over the wire and asserts on raw bytes that the recorded event's id is
    what <RequestId> holds in both the live and the recorded body — a decoded ResponseMetadata
    would 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 RecordRequest write removed and the
fallback 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 test and
GOTOOLCHAIN=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.md gains a "What a replayed response reproduces" subsection stating which
assertions 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.

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

codecov Bot commented Sep 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit b30af41 into main Sep 15, 2026
17 checks passed
@scttfrdmn
scttfrdmn deleted the fix/866-request-id branch September 15, 2026 03:42
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.

replay: a success body's RequestId derives from the wall clock and the event never records it, so a recorded run cannot be reproduced

1 participant