Repository navigation
Description
substrate replay cannot replay anything. It builds an empty plugin registry, a nil state manager, and never loads the events it was asked to replay.
newReplayCmd (cmd/substrate/main.go:281-328):
store := substrate.NewEventStore(cfg.EventStore.ToEventStoreConfig())
tc := substrate.NewTimeController(time.Now())
registry := substrate.NewPluginRegistry()
engine := substrate.NewReplayEngine(store, nil, tc, registry,
substrate.ReplayConfig{}, logger)
ctx := context.Background()
results, err := engine.Replay(ctx, streamID)Three independent defects, in the order a user hits them:
- The store is never loaded.
NewEventStoreconstructs a file backend eagerly "so Load can be called right away" (eventstore.go:229-231) — butLoad(:703) is called by nothing incmd/or in non-testemulator/code. So the in-memory event slice is empty,GetStreamreturns no events, andReplayfails withno events in stream: <id>for every stream that was ever recorded. The command cannot succeed today. - The registry is empty.
NewPluginRegistry()with noRegisterDefaultPlugins, so once events are loaded,RouteRequestanswersServiceNotAvailablefor every one of them. Every event would be reported as failed. - The state manager is nil.
NewReplayEngine(store, nil, …)— soresetStateis a no-op (replay.go:598-608),computeStateHashreturns""(:614-621), and any state validation is silently inert. Plugins would also have nowhere to read or write, which is the same problem as (2) from the other side.
The --config flag is honoured for the event-store config and the log format only; nothing else in cfg reaches the engine.
The summary printed also omits SkippedEvents (:313-320), which after the v0.115.0 reporting fix is the number that distinguishes "replayed 100 events" from "read 100 events and executed none of them".
Why this is separate from #833 and #817
Those two are about replay fidelity — whether a re-executed request is decided the same way and produces the same bytes. This is about the shipped command not wiring the engine to anything at all. It is reachable by any user following the CLI's own help text ("Replay a previously recorded event stream against the emulator"), it needs no pipeline refactor, and the in-tree recipe already exists: startTestServer (emulator/testing.go:184-252) wires a state manager, a time controller, a registry via RegisterDefaultPlugins, and a store, in about fifteen lines.
Acceptance criteria
-
substrate replay <stream>loads the recorded events from the configured backend (EventStore.Load) before replaying, and reports a clear error naming the backend and path when there are none, rather than the bareno events in stream. - The engine is wired to a real
StateManager(percfg.State) and to a registry populated byRegisterDefaultPlugins, so events route to the plugins that recorded them. - The printed summary includes
Skipped, and says explicitly when every event was skipped for want of a recorded body — a stream recorded withoutevent_store.include_bodiescannot be replayed, and the command should say so rather than reportSuccess: N. -
ReplayConfigis populated from config rather than being the zero value, at least forValidateStateandStopOnError. - A test that records a stream to a file backend in one store, then replays it through the command's own wiring path, and asserts a non-zero executed count. (The wiring belongs in a testable function, not inline in
RunE.)
Found during the v0.115.0 replay-reporting research. Independent of #833 and #817.
Activity
scttfrdmn commentedon Sep 15, 2026
Verified before implementing, as part of the v0.116.0 cut. Every factual claim in this issue holds; the line numbers have drifted, two acceptance criteria are not implementable as written and are split out, and the defect is CLI-wide rather than replay-only.
Confirmed, at current
mainnewReplayCmdiscmd/substrate/main.go:281-328. The store is built with no options (:300), the time controller fromtime.Now()(:301), the registry is an emptyNewPluginRegistry()with noRegisterDefaultPlugins(:302), and the engine takes nil as the state manager with a zero-valueReplayConfig(:304-305).EventStore.Loadis now ateventstore.go:769and still has no non-test caller anywhere in the tree — soReplayfails atno events in stream(replay.go:184) on any persistent backend, exactly as described. With a nil state managerresetStateis a no-op (replay.go:640-648) andcomputeStateHashreturns""(:675-677), soStateValidis vacuously true — worth stating plainly, because the field reads as a passing verdict.The summary omission is bigger than the issue says.
:313-320printsTotalEvents,SuccessEvents,FailedEventsandlen(Differences), and omitsSkippedEvents,StateValidandStateErrors— that is, the two fieldsReplayResults' own doc comment (replay.go:86-97) names as the verdict. All three are added.The same one-line cause affects two other commands, now filed as #879
export(main.go:350) never callsLoadeither, andExportNDJSON/ExportCSVreadGetEvents(eventstore.go:500,:520→:482), i.e. the in-memory slice — so it exports zero events from a file or sqlite backend, exit 0, with no stderr line at all on the default--output -.debug(:480-536) is worse: it loads the config and discards it (_ = cfg // used for future persistence options,:496), hardcodesEventStoreConfig{Enabled: true, Backend: "memory"}(:498-501), and therefore always printsstream %q contains no events(:510) under help text promising to list them.A shared
Loadin one place covers all three, so this issue's fix and #879's are the same extraction. #879 records the two commands separately so they are not closed by implication.Two acceptance criteria are out of scope as written, and are split out rather than quietly dropped
AC 2's "wired to a real
StateManager(percfg.State)" is not implementable today.StateCfg(config.go:203-210) has onlyBackend("memory"; sqlite is deferred to #2) andPath, andConfig.Statehas no reader that constructs anything — onlyDefaultConfig(:610) andValidate(:774) touch it. The server itself callsNewMemoryStateManager()unconditionally (main.go:164). So "percfg.State" would mean building the config plumbing that does not exist, for one backend value. What ships is the wiring to a real state manager — aNewMemoryStateManager(), which is what the server uses — so the engine resets and hashes real state instead of silently doing neither. Honouringcfg.Stateis a separate issue, and it lands when there is a second backend to choose.AC 4's "
ReplayConfigis populated from config" requires a new config section. There is noReplayfield onConfigand noReplayCfgtype, so it pulls inDefaultConfig,Validate, the docs, and thesubstrate.yamlexample. That is new scope, not wiring, and is filed separately.The remaining criteria —
Loadbefore replaying with an error naming the backend and path, a registry populated byRegisterDefaultPlugins,Skippedin the summary with an explicit statement when every event was skipped for want of a recorded body, and a test through the command's own wiring path against a file backend — all ship, and the wiring goes in a testable function rather than inline inRunE, per the criterion's parenthetical.One correction to the issue's own suggestion
The issue points at
startTestServer(emulator/testing.go) as the recipe to copy. The order that matters ismain.go:156-176's, becauseauthCtrlmust be constructed beforeRegisterDefaultPlugins— CloudFormation takes it, per the comment at:167-170. There is no shared "build a working emulator" helper in the tree; four inline recipes exist (main.go:156-176,testing.go,debug_ui.go,cmd/gen-service-reference/main.go) and none is callable fromcmd/.newFaultControllerandnewCredentialWiringare the in-package precedent for extracting testable wiring, and that is the shape used.Also for the record:
main_test.go's only replay test asserts the command is non-nil;RunEis never invoked by any test today, which is why none of this was caught.