feat(lua): workflow history replayer module - #547
Open
xepozz wants to merge 1 commit into
Open
Conversation
Add a builtin `replayer` Lua module that exposes Temporal's WorkflowReplayer to
Lua so tests can verify a workflow.lua entry replays deterministically against a
recorded event history (equivalent to the Go/TS/Java WorkflowReplayer).
local replayer = require("replayer")
local ok, err = replayer.replay_json_file("app.foo:my_workflow", "history.json")
The module wraps worker.WorkflowReplayer and registers the runtime's existing
dynamic workflow.DefinitionFactory (the SDK registry accepts it as a
WorkflowDefinitionFactory). ClassIO — usable from function.lua/tests, not a
workflow body. Registered via a boot component mirroring the other lua modules.
Tests: unit tests for bind + argument validation; an integration test that runs
a Lua workflow on a dev server, fetches its history, and replays it against the
DefinitionFactory (nil error == deterministic).
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new Lua-facing replayer builtin module that wraps Temporal’s worker.WorkflowReplayer, enabling determinism/replay-safety tests for Lua workflows by replaying recorded workflow histories (including from JSON files).
Changes:
- Introduces
runtime/lua/modules/replayerLua module withreplay_json_file(...)binding and type manifest. - Registers the module via a new boot component so it’s available consistently with other Lua builtins.
- Adds an integration test that runs a workflow, fetches its history, and validates replay (including JSON-file replay).
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| service/temporal/workflow/replay_integration_test.go | New integration test that replays recorded history to validate deterministic replay behavior. |
| runtime/lua/modules/replayer/module.go | Implements the Lua replayer module and replay_json_file binding. |
| runtime/lua/modules/replayer/types.go | Adds the type manifest for the new Lua module. |
| runtime/lua/modules/replayer/module_test.go | Adds unit tests for binding and argument/context validation behavior. |
| boot/components/runtime/lua/replayer.go | Registers the new Lua module via boot component. |
| boot/components/runtime/lua/constants.go | Adds the boot component name constant. |
| boot/components/runtime/lua/all.go | Includes the new component in the default Lua component set. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+14
to
+19
| moduleType := typ.NewInterface("replayer", []typ.Method{ | ||
| {Name: "replay_json_file", Type: typ.Func(). | ||
| Param("workflow_id", typ.Any). | ||
| Param("history_json_path", typ.Any). | ||
| Returns(typ.Any, typ.NewOptional(typ.LuaError)).Build()}, | ||
| }) |
Comment on lines
+70
to
+75
| ctx := l.Context() | ||
|
|
||
| dcReg := temporalapi.GetDataConverterRegistry(ctx) | ||
| if dcReg == nil { | ||
| return invalidError(l, "temporal data converter registry not available in context") | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reason for This PR
Lua workflows have no way to test determinism / replay safety. Every other
Temporal SDK exposes a
WorkflowReplayerto re-execute a recorded history andcatch non-deterministic changes, but there is no equivalent reachable from Lua
or the native test runner. Today such regressions surface only on a live
cluster (as replay panics after a worker restart), never in CI.
This PR adds a Lua-facing replayer so a test can assert a
workflow.luaentryreplays deterministically against a recorded event history.
Description of Changes
New builtin module
replayerthat wraps the SDK'sworker.WorkflowReplayer:replay_json_file(workflow_id, history_json_path[, workflow_type_name])registers the runtime's existing dynamic
workflow.DefinitionFactoryon aWorkflowReplayer(the SDK registry accepts it as aWorkflowDefinitionFactory)and replays the history file produced by
temporal workflow show --workflow-id <id> --output json.workflow_type_nameoverrides the registered type name forworkflows that set a custom
metaname; it defaults toworkflow_id.from the runtime context so payloads decode exactly as recorded.
ClassIO, ClassNondeterministic— usable fromfunction.lua/tests,not from a workflow body. Registered via a boot component, consistent with the
other Lua modules.
Files:
runtime/lua/modules/replayer/{module.go,types.go,module_test.go}boot/components/runtime/lua/replayer.go(+all.go,constants.go)service/temporal/workflow/replay_integration_test.goTests: unit tests for bind + argument validation; an integration test that runs
a workflow on a dev server, fetches its history, and replays it (both in-memory
and via the JSON-file path) against the
DefinitionFactory, asserting nil error.