Repository navigation
Description
Found while writing the replay-determinism test for #886.
Most plugins take the server's simulated clock through Options["time_controller"] and fall back to a private real-time clock when it is absent:
if tc, ok := cfg.Options["time_controller"].(*TimeController); ok {
p.tc = tc
} else {
p.tc = NewTimeController(time.Now())
}RegisterDefaultPlugins (emulator/plugins.go) passes time_controller for 52 of its 67 registrations. The other 15 take the fallback, so they run on wall-clock time inside an emulator whose whole point is a controlled clock:
TaggingPlugin, ACMPlugin, APIGatewayPlugin, APIGatewayV2Plugin, APIGatewayProxyPlugin, ECRPlugin, ECSPlugin, CognitoIDPPlugin, CognitoIdentityPlugin, KinesisPlugin, CloudFrontPlugin, HealthPlugin, PriceListPlugin, SESv2Plugin, FirehosePlugin.
Each of these reads Options["time_controller"] in its own Initialize, so the plugin is ready for the clock; only the wiring is missing. This is a wiring omission, not a design decision — there is nothing in the code or comments to suggest any of the 15 was meant to be exempt.
What it costs
POST /v1/control/timeandPOST /v1/control/scaledo not move these plugins' clocks, so a consumer testing ACM certificate expiry, an API GatewaycreatedDate, an ECR imagepushedAtor an SESSentAtagainst a controlled clock gets wall-clock values instead.- It defeats replay.
ReplayEngine.replayEventsets the time controller to each recorded event's timestamp so a replayed handler sees the time the recording saw; a plugin holding a private clock ignores that and stamps the replay with the current wall time. - Concretely,
SESv2Plugin.sendEmailmintsMessageIdasmsg-<p.tc.Now().UnixNano()>-<counter>. replay: PluginRegistry has no reset hook, so plugin-held counters survive resetState #886 made the counter half reproducible across replays in a process; the clock half cannot be, because the clock is not the server's. The test added by replay: PluginRegistry has no reset hook, so plugin-held counters survive resetState #886 (emulator/replay_plugin_reset_test.go) has to register its ownSESv2Pluginwired to the server's clock in order to assert on the whole identifier — a workaround that should be deleted when this is fixed.
Acceptance criteria
- All 15 registrations pass
Options["time_controller"]. - A test that sets the simulated clock and asserts a timestamp minted by at least one previously-unwired plugin follows it (SES v2's
SentAtor ACM'sNotAfteris the cheapest). - The workaround in
emulator/replay_plugin_reset_test.go(startFrozenServer's SES v2 re-registration) removed, and the test asserting the wholeMessageId. - Check whether the fallback should exist at all: a plugin silently substituting a real clock is what let this hide for 67 registrations. Consider making
Initializefail when no time controller is supplied, or havingRegisterDefaultPluginsbuild thePluginConfigin one place so a new plugin cannot be registered without one.
Activity
scttfrdmn commentedon Sep 17, 2026
Four premise corrections before the fix lands, and the answer to AC 4.
Only eleven of the fifteen can take the clock at all
The body says "Each of these reads
Options["time_controller"]in its ownInitialize, so the plugin is ready for the clock; only the wiring is missing." That holds for eleven. It does not hold for four:TaggingPlugin,HealthPlugin,PriceListPluginandAPIGatewayProxyPluginhave no clock field at all.APIGatewayProxyPlugin.Initialize(emulator/apigateway_plugin.go:1461-1468) reads onlyOptions["registry"], andemulator/tagging_plugin.go,emulator/health_plugin.goandemulator/pricing_plugin.godo not so much as importtime.So supplying the option to those four is a silent no-op — correct to do, since the wiring is what is being made uniform, but it changes nothing observable and no test can assert it does. The eleven that do fall back are
ACMPlugin,APIGatewayPlugin,APIGatewayV2Plugin,ECRPlugin,ECSPlugin,CognitoIDPPlugin,CognitoIdentityPlugin,KinesisPlugin,CloudFrontPlugin,SESv2PluginandFirehosePlugin. The count of registrations to change is still fifteen; the count of behaviours that change is eleven.Wiring alone would not have fixed Kinesis
generateKinesisSeqNo(emulator/kinesis_plugin.go) calledtime.Now()directly. It has no receiver, so it could not reach the plugin's clock however that clock was supplied, and aSequenceNumberis observable —PutRecordandPutRecordsreport it andGetRecordsechoes it back. RegisteringKinesisPluginwith the simulated clock and stopping there would have left the one Kinesis value a caller can assert on the wall clock. It now takes the clock as a parameter and both call sites passp.tc.Now(). The random half stayscrypto/rand; that half is #856's.Three callers of
RegisterDefaultPluginsare not counted anywhere in the issueBeyond the server (
cmd/substrate/main.go:257) andStartTestServer(emulator/testing.go:250) there are three more:cmd/substrate/main.go:364(the replay command),cmd/gen-service-reference/main.go:102, andemulator/debug_ui.go:290. The last matters: it passesNewTimeController(time.Time{}), so the eleven newly-wired plugins move from the wall clock to year 1 in the debug UI'sstateAtSequence. That is consistent with what the other 52 already did there, and in practice masked becausereplayEventsets the clock per event, but it is a behaviour change and the changelog says so.AC 4: one place, not a hard failure
The second, and the first is rejected on evidence: no plugin hard-fails on a missing clock today. The only hard-fail precedent is
CloudFormationPlugin.Initialize(emulator/cloudformation_plugin.go:109-112), which refuses a missingregistry— and the same function falls back silently for the clock four lines earlier (:103-107). Making the clock mandatory would break every test helper that constructs a plugin without one, and there are many; the fallback is load-bearing outsideRegisterDefaultPlugins.So the fix is a
pluginWiringstruct holding{registry, state, logger, tc}with oneregistermethod that builds thePluginConfig, and a table of sixty-seven{plugin, name, extra}entries in the original order with the original error-wrap names. A registration can no longer spell its own config out, which is what made the omission invisible at each individual call site.One detail worth recording: a nil
*TimeControlleris left out of the options map rather than stored. Every plugin reads the value with a type assertion to*TimeController, which succeeds for a typed nil and hands the plugin a clock that panics on first use, where an absent key takes the documented fallback instead. No caller passes nil today — all eleven call sites ofRegisterDefaultPluginswere checked, five in non-test code and six in tests — so the guard is defensive, but the Cost Explorer registration already guarded exactly this individually before the wiring was shared.