Skip to content

fix(replay): a counter that stood for work, and a comparison that ran (#833, #817) - #857

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/replay-reporting
Sep 14, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/replay-reporting

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Three defects in replay's reporting, all the same kind as this release's other groups: a number or a comparison that stood for work that never happened.

Part of #833 and part of #817 — their reporting halves. Both issues stay open; the execution halves need a shared request pipeline and a protocol-aware body differ, and both are blocked on #856. Deliberately no closing keyword.

A skipped event was counted as a success

replayEvent incremented SkippedEvents and returned a nil error for an event with no request; the driver read the nil error as a success and incremented SuccessEvents too. Since IncludeBodies defaults to false, no event on a default-configured stream carries a request — so every event was skipped, and a replay of such a stream reported total=N success=N while executing none of them.

replayEvent now returns whether it executed the event, separately from the error, because a skip is neither a success nor a failure and both return nil. The three counters now partition the stream, stated as an invariant on ReplayResults, and the completion log reports the skipped and difference counts — total=N success=N and total=N skipped=N are the same stream with and without bodies, and only one of them verified anything.

SuccessEvents is documented as "re-executed without returning an error", not "matched the recording".

A recorded refusal that replays as a success reported no difference

The error comparison sat inside the err != nil arm, so a successful replay never consulted event.Error; and the status comparison could not stand in for it, because every pre-plugin refusal records with a nil response, so event.Response is nil for exactly the events that were refused. A recorded 403 replaying as a 200 was reported as no difference at all — and, before the counter fix, as a success.

Classed critical, matching the reverse case already there: a replay that grants what the recording denied is the divergence most likely to make a passing test meaningless, because it is the one that lets a request through.

ValidateState was inert on every recorded stream

IncludeStateHashes was declared, plumbed through config and defaulted, and never read; StateHashBefore/StateHashAfter were never written outside a hand-built test event. Both comparisons were guarded on a field that was always empty — AttachmentCount's defect (#847) in another subsystem.

Server and StackDeployer now record both hashes when the store keeps them, taken before the pipeline's first refusal point so that a refused request records the same hash on both sides rather than leaving the field empty and having the replay skip the check. EventStore.RecordRequest gains WithStateHashes(before, after); the caller supplies both because only the caller knows when "before" was, and the store's config stays the authority on whether the event keeps them.

The recorded hash and the replayed hash come from one function, stateSnapshotHash, for the reason #826 established for ARNs: two implementations of "hash the state" would be two answers, and the comparison would report a difference on every event.

Hashing is routed through the server and the deployer rather than by giving the store a state manager, deliberately: NewEventStore starts a background snapshot goroutine when SnapshotInterval > 0 && stateRef != nil, and the default interval is 100 — so that wiring would have started a goroutine in every test server.

Enabling this on a stream containing a create now reports a mismatch. That is the honest answer, not a defect: substrate mints most identifiers from crypto/rand, so the minted value differs between a recording and its replay and lands in the state being hashed (#856). Making the comparison run is what surfaces it.

StartTestServer can record bodies and hashes

WithRecordedBodies() and WithRecordedStateHashes(), both off by default. The first is what any replay test needs, and its absence is why the flagship end-to-end journey passed while replaying nothing — IncludeBodies defaults to false and there was no option to change it.

TestJourney_RecordAndReplay is rewritten accordingly. It now asserts SkippedEvents == 0 and SuccessEvents == TotalEvents, and reads the object back afterwards — Replay wipes state first, so an object readable after the replay can only have been written by the replay. A counter cannot make that claim, which is the whole reason the old version passed.

Recorded, not fixed

Both were narrower in the issues than in the tree, and both are now on the issues:

  • isReplaying is dead at three sites, not one — quota.go:87, consistency.go:85, consistency.go:127 — because a replay calls RouteRequest directly and never enters the pipeline that would set it.
  • A replay never freezes the clock. SetScale is called nowhere on that path and TimeController.Now() is baseline + (wall elapsed × scale), so Replay: deep-compare response bodies during verification #817's premise that simulated-clock timestamps in a body compare equal across a recording and its replay is false. With LastModified formatted RFC3339Nano, every ListObjectsV2 body diverges.

Two prerequisites filed rather than folded in: #855 (substrate replay builds an empty registry and a nil state manager, so every routed request answers ServiceNotAvailable) and #856 (deterministic identifier minting, which is what unblocks both replay issues).

Verification

Each new test was checked against the defect it exists for, by reverting that one behaviour and confirming the test fails:

Reverted Fails
skip arm returns true (old semantics) ASkippedEventIsNotCountedAsASuccess — SuccessEvents was 2, want 0
the new event.Error != "" difference ARecordedRefusalReplayingAsSuccessIsCritical — 0 differences, want 1
recordedStateHash returns "" StateHashesAreRecorded and ValidateStateReportsADivergence
WithRecordedBodies() dropped from the e2e journey TestJourney_RecordAndReplay — skipped 2 of 2, and GetObject 404s

Each defect test has a negative twin, so neither direction is vacuous: a stream with nothing refused reports no error difference, a server that did not ask for hashes records none, and ValidateState on a stream without hashes reports nothing. All eight tests record over the wire through StartTestServer and replay that stream — the putTest* helpers are not extended (#765), and a hand-built event can carry a hash nothing would have recorded, which is how the existing coverage passed while the feature did nothing.

Full nine-command gate green: gofmt/build/vet, golangci-lint, make test, GOTOOLCHAIN=go1.26.6 make test, coverage (emulator 83.8%, total 83.2% — baseline held), docs reference + version + authz checks, npm --prefix docs run build, and e2e vet + tests.

Three defects of one kind — a number or a comparison standing for work that
never happened.

A skipped event was counted as a success. replayEvent incremented
SkippedEvents and returned nil, and the driver read the nil error as a
success, so a skip incremented both. IncludeBodies defaults to false, so no
event on a default-configured stream carries a request: every event was
skipped, and a replay reported total=N success=N having executed none of
them. replayEvent now reports whether it executed the event, separately from
the error, and the three counters partition the stream.

A recorded refusal that replayed as a success reported no difference. The
error comparison ran only when the replay itself errored, and the status
comparison could not stand in for it because a pre-plugin refusal records
with a nil response — so event.Response is nil for exactly the refused
events. A recorded 403 replaying as a 200 was no difference at all. It is
now critical, matching the reverse case: a replay that grants what the
recording denied is the divergence that makes a passing test meaningless.

ValidateState was inert. IncludeStateHashes was declared, plumbed and
defaulted, and never read, so both comparisons were guarded on a field
nothing wrote. The server and the stack deployer now record both hashes when
the store keeps them, taken before the first refusal point so a refused
request records the same hash on both sides. One function produces the
recorded and the replayed hash, for the reason #826 established for ARNs.

StartTestServer gains WithRecordedBodies and WithRecordedStateHashes. The
first is why the flagship e2e journey passed while replaying nothing, and
there was no option to change it; that test now asserts events were
executed, and reads the object back to prove it.

Recorded, not fixed: isReplaying is dead at three sites, not one, and a
replay never freezes the clock — so #817's premise that simulated-clock
timestamps compare equal is false. Both need #856 first.

Part of #833. Part of #817.
@scttfrdmn scttfrdmn added this to the v0.115.0 milestone Sep 14, 2026
@codecov

codecov Bot commented Sep 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.46154% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/cfn_deployer.go 88.88% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 926a2cc into main Sep 14, 2026
14 checks passed
@scttfrdmn
scttfrdmn deleted the fix/replay-reporting branch September 14, 2026 19:27
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.

1 participant