Skip to content

15 of 67 default plugin registrations omit time_controller, so those plugins run on wall-clock time #904

Closed

Description

@scttfrdmn

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/time and POST /v1/control/scale do not move these plugins' clocks, so a consumer testing ACM certificate expiry, an API Gateway createdDate, an ECR image pushedAt or an SES SentAt against a controlled clock gets wall-clock values instead.
  • It defeats replay. ReplayEngine.replayEvent sets 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.sendEmail mints MessageId as msg-<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 own SESv2Plugin wired 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 SentAt or ACM's NotAfter is the cheapest).
  • The workaround in emulator/replay_plugin_reset_test.go (startFrozenServer's SES v2 re-registration) removed, and the test asserting the whole MessageId.
  • 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 Initialize fail when no time controller is supplied, or having RegisterDefaultPlugins build the PluginConfig in one place so a new plugin cannot be registered without one.

Activity

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

    @scttfrdmn
    OwnerAuthor

    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 own Initialize, 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, PriceListPlugin and APIGatewayProxyPlugin have no clock field at all. APIGatewayProxyPlugin.Initialize (emulator/apigateway_plugin.go:1461-1468) reads only Options["registry"], and emulator/tagging_plugin.go, emulator/health_plugin.go and emulator/pricing_plugin.go do not so much as import time.

    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, SESv2Plugin and FirehosePlugin. 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) called time.Now() directly. It has no receiver, so it could not reach the plugin's clock however that clock was supplied, and a SequenceNumber is observable — PutRecord and PutRecords report it and GetRecords echoes it back. Registering KinesisPlugin with 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 pass p.tc.Now(). The random half stays crypto/rand; that half is #856's.

    Three callers of RegisterDefaultPlugins are not counted anywhere in the issue

    Beyond the server (cmd/substrate/main.go:257) and StartTestServer (emulator/testing.go:250) there are three more: cmd/substrate/main.go:364 (the replay command), cmd/gen-service-reference/main.go:102, and emulator/debug_ui.go:290. The last matters: it passes NewTimeController(time.Time{}), so the eleven newly-wired plugins move from the wall clock to year 1 in the debug UI's stateAtSequence. That is consistent with what the other 52 already did there, and in practice masked because replayEvent sets the clock per event, but it is a behaviour change and the changelog says so.

    AC 4: one place, not a hard failure

    Consider making Initialize fail when no time controller is supplied, or having RegisterDefaultPlugins build the PluginConfig in one place so a new plugin cannot be registered without one.

    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 missing registry — 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 outside RegisterDefaultPlugins.

    So the fix is a pluginWiring struct holding {registry, state, logger, tc} with one register method that builds the PluginConfig, 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 *TimeController is 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 of RegisterDefaultPlugins were 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.

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