Skip to content

substrate replay wires an empty registry, a nil state manager, and never loads the events #855

Closed

Description

@scttfrdmn

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:

  1. The store is never loaded. NewEventStore constructs a file backend eagerly "so Load can be called right away" (eventstore.go:229-231) — but Load (:703) is called by nothing in cmd/ or in non-test emulator/ code. So the in-memory event slice is empty, GetStream returns no events, and Replay fails with no events in stream: <id> for every stream that was ever recorded. The command cannot succeed today.
  2. The registry is empty. NewPluginRegistry() with no RegisterDefaultPlugins, so once events are loaded, RouteRequest answers ServiceNotAvailable for every one of them. Every event would be reported as failed.
  3. The state manager is nil. NewReplayEngine(store, nil, …) — so resetState is a no-op (replay.go:598-608), computeStateHash returns "" (: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 bare no events in stream.
  • The engine is wired to a real StateManager (per cfg.State) and to a registry populated by RegisterDefaultPlugins, 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 without event_store.include_bodies cannot be replayed, and the command should say so rather than report Success: N.
  • ReplayConfig is populated from config rather than being the zero value, at least for ValidateState and StopOnError.
  • 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

  1. added this to the v0.116.0 milestone on Sep 14, 2026
  2. added
    type: bug
    on Sep 14, 2026
  3. scttfrdmn commented on Sep 15, 2026

    @scttfrdmn
    OwnerAuthor

    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 main

    newReplayCmd is cmd/substrate/main.go:281-328. The store is built with no options (:300), the time controller from time.Now() (:301), the registry is an empty NewPluginRegistry() with no RegisterDefaultPlugins (:302), and the engine takes nil as the state manager with a zero-value ReplayConfig (:304-305). EventStore.Load is now at eventstore.go:769 and still has no non-test caller anywhere in the tree — so Replay fails at no events in stream (replay.go:184) on any persistent backend, exactly as described. With a nil state manager resetState is a no-op (replay.go:640-648) and computeStateHash returns "" (:675-677), so StateValid is vacuously true — worth stating plainly, because the field reads as a passing verdict.

    The summary omission is bigger than the issue says. :313-320 prints TotalEvents, SuccessEvents, FailedEvents and len(Differences), and omits SkippedEvents, StateValid and StateErrors — that is, the two fields ReplayResults' 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 calls Load either, and ExportNDJSON/ExportCSV read GetEvents (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), hardcodes EventStoreConfig{Enabled: true, Backend: "memory"} (:498-501), and therefore always prints stream %q contains no events (:510) under help text promising to list them.

    A shared Load in 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 (per cfg.State)" is not implementable today. StateCfg (config.go:203-210) has only Backend ("memory"; sqlite is deferred to #2) and Path, and Config.State has no reader that constructs anything — only DefaultConfig (:610) and Validate (:774) touch it. The server itself calls NewMemoryStateManager() unconditionally (main.go:164). So "per cfg.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 — a NewMemoryStateManager(), which is what the server uses — so the engine resets and hashes real state instead of silently doing neither. Honouring cfg.State is a separate issue, and it lands when there is a second backend to choose.

    AC 4's "ReplayConfig is populated from config" requires a new config section. There is no Replay field on Config and no ReplayCfg type, so it pulls in DefaultConfig, Validate, the docs, and the substrate.yaml example. That is new scope, not wiring, and is filed separately.

    The remaining criteria — Load before replaying with an error naming the backend and path, a registry populated by RegisterDefaultPlugins, Skipped in 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 in RunE, 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 is main.go:156-176's, because authCtrl must be constructed before RegisterDefaultPlugins — 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 from cmd/. newFaultController and newCredentialWiring are 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; RunE is never invoked by any test today, which is why none of this was caught.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions