From 2565fb012fe1fc4b90aa03a08864045bdfa1f9e8 Mon Sep 17 00:00:00 2001 From: pikann Date: Thu, 30 Jul 2026 10:14:57 +0000 Subject: [PATCH] feat: enhance WASI reactor module instantiation with real OS clock support --- services/api/internal/platform/plugin/runtime.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/services/api/internal/platform/plugin/runtime.go b/services/api/internal/platform/plugin/runtime.go index 21f7e9f8a..6cfecf18a 100644 --- a/services/api/internal/platform/plugin/runtime.go +++ b/services/api/internal/platform/plugin/runtime.go @@ -228,8 +228,16 @@ func (r *Runtime) Load(ctx context.Context, p plugindom.Plugin) error { _ = wasmRT.Close(ctx) return fmt.Errorf("runtime load %q: compile: %w", p.Name, err) } - // For WASI reactor builds, _initialize must be called before exported functions - mod, err := wasmRT.InstantiateModule(ctx, compiled, wazero.NewModuleConfig().WithName(p.Name).WithStartFunctions("_initialize")) + // For WASI reactor builds, _initialize must be called before exported functions. + // WithSysWalltime/WithSysNanotime wire the module's clock to the real OS + // clock; without them wazero silently falls back to a fake clock frozen at + // 1970-01-01 (nanotime) / 2022-01-01 (walltime), which is what plugins would + // otherwise observe from time.Now() — see issue #339. + mod, err := wasmRT.InstantiateModule(ctx, compiled, wazero.NewModuleConfig(). + WithName(p.Name). + WithStartFunctions("_initialize"). + WithSysWalltime(). + WithSysNanotime()) if err != nil { _ = wasmRT.Close(ctx) return fmt.Errorf("runtime load %q: instantiate: %w", p.Name, err)