Repository navigation
Description
What is wrong
RequestContext.RequestID is filled by generateRequestID() (emulator/parser.go:155), which is "req-" + time.Now().UnixNano() (emulator/parser.go:823). 66 non-test sites render ctx.RequestID into a success response body — among them cloudformation_plugin.go:1464, sqs_plugin.go:947, eleven sites in cloudwatch_plugin.go, five in redshift_plugin.go, five in lambda_plugin.go.
So no two runs of the same input agree on a success body's RequestId, and a caller diffing two responses sees a field that changes on its own.
Worse, it is not merely nondeterministic — it is unrecoverable in principle:
- the
Eventstruct has no request-ID field (emulator/eventstore.go:128-182); RecordRequest(emulator/eventstore.go:398-445) never copies one;- on replay,
replayEventsetsRequestIDfromevent.ID(emulator/replay.go:305), i.e.service-op-seq-<UnixNano>(emulator/eventstore.go:929) — a third shape, neither the recorded value nor the live one.
No amount of work in the replay engine can reproduce the recorded value, because the recording never stored it.
Why this is the missing half of an existing decision
The error path was fixed for exactly this reason and the success path was never done. emulator/error_protocol.go:8-16, verbatim:
// substrateRequestID is the request id every error document carries. It is a fixed
// string rather than generateRequestID(), which derives from time.Now().UnixNano():
// 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.
const substrateRequestID = "SUBSTRATE"Used at emulator/error_protocol.go:423. The rule stated there — "byte-identical across two replays of one recorded run" — applies verbatim to a success body, and nothing generalised it.
Scope, and what this issue is not
This is not deterministic identifier minting (#856). A live request's ID may keep deriving from the wall clock; what must hold is that a recorded run replays to the same bytes. That needs the ID carried on the event rather than re-minted, which is a small, self-contained change and does not depend on #856's much larger question of how every generate* function draws its randomness.
It is also an unconditional prerequisite of #817, independent of #856: response bodies cannot be deep-compared while one of their fields is guaranteed to differ.
Acceptance criteria
-
Eventcarries the request ID of the request that produced it. -
RecordRequestwrites it. - Replay restores it onto the
RequestContext, so a replayed handler renders the recorded value rather thanevent.ID. - A test records a run that produces a success body carrying
RequestId, replays it, and asserts the two bodies are byte-identical — asserted on raw bytes, not on a decoded struct. - The 66 success-body sites are left rendering
ctx.RequestID; none needs editing. - The comment on
substrateRequestID(emulator/error_protocol.go:8-16) is cross-referenced, so the two halves of the rule are discoverable from each other. - It is recorded that a live request ID still derives from the wall clock, and why that is compatible with the rule.
Compatibility
A replayed success body's RequestId now matches the recording rather than differing from it. Nothing else observable changes.
Part of #817.
Activity