Skipped mutableSideEffect leaks an empty RecordMarker command after a full replay, and the workflow task fails on every retry
维护者通常 2 天内回复
评估
调研方向
Start with MutableSideEffectStateMachine.InvocationStateMachine.handleWorkflowTaskStarted() and the replay handling in WorkflowStateMachines; the issue describes a proposed transition and a reproducer in skippedMutableSideEffectSurvivesFullReplay. Run that reproducer on the time skipping test server, then verify the fix with the SDK test suite. Done means the replay no longer sends an empty record marker and the workflow completes on retry.
由索引模型根据 Issue 内容生成。
描述
Expected Behavior
A Workflow.mutableSideEffect call whose comparator says "unchanged" records nothing. Replaying a history that contains such a call produces the same commands as the original execution.
Actual Behavior
After a full replay, the worker can send a COMMAND_TYPE_RECORD_MARKER whose RecordMarkerCommandAttributes are completely empty: no marker_name and no details. The server rejects that completion:
- Test server (
temporal-testing1.40.0):INVALID_ARGUMENT: marker name is required, fromTestWorkflowMutableStateImpl.processRecordMarker. - Real server (
temporal server start-dev, CLI 1.8.3, server 1.31.2): the workflow task fails with
WORKFLOW_TASK_FAILED_CAUSE_BAD_RECORD_MARKER_ATTRIBUTES, "BadRecordMarkerAttributes: MarkerName is not set on
RecordMarkerCommand." The validator isCommandAttrValidator.ValidateRecordMarkerAttributes.
Every retry is again a full replay of the same history, so it produces the same bad command. Against the dev server, 30 seconds after the first failure the execution was still running and the pending workflow task was on attempt 4, every attempt failing the same way. On the time-skipping test server time also stops advancing, so tests hang instead of failing.
These are the commands from a captured rejected RespondWorkflowTaskCompletedRequest. The second one is the accept for an update the task was delivering:
commands {
command_type: COMMAND_TYPE_RECORD_MARKER
record_marker_command_attributes {
}
}
commands {
command_type: COMMAND_TYPE_PROTOCOL_MESSAGE
protocol_message_command_attributes {
message_id: "edc1dddd-.../request/accept"
}
}
Root cause (as far as we can tell from the 1.40.0 source)
io.temporal.internal.statemachines.MutableSideEffectStateMachine.InvocationStateMachine behaves differently while executing and while replaying:
- Executing.
createMarker()sees that the function returned empty (a skip). It addsStateMachineCommandUtils.RECORD_MARKER_FAKE_COMMAND, which isRecordMarkerCommandAttributes.getDefaultInstance(), and moves toSKIPPED. WhenWorkflowStateMachines.prepareImpl()handles the command,SKIPPED --RECORD_MARKER--> SKIPPED_NOTIFIEDcallscancelCommandNotifyCachedResult(). The fake is cancelled immediately and never sent. - Replaying.
createFakeCommand()adds the same fake command. On the RECORD_MARKER command handling it movesMARKER_COMMAND_CREATED_REPLAYING -> RESULT_NOTIFIED_REPLAYING, which is not cancelled. From there it is cancelled only byNON_MATCHING_EVENT, insidehandleEvent(), andhandleEvent()is reached only fromWorkflowStateMachines.handleCommandEvent()when a later command event is matched against the queue head.
A skipped call writes no marker. So if the workflow task that made the skipped call emitted no other commands, history after its WorkflowTaskCompleted has no command events. Nothing ever calls handleEvent() on the fake, and it stays uncancelled in WorkflowStateMachines.commands, which is only drained by handleCommandEvent.
Replay then reaches the current task, replaying becomes false, and WorkflowStateMachines.takeCommands() returns every uncancelled entry, the leaked fake included. It goes out ahead of the task's real commands.
The trigger needs all of these:
- A full replay: sticky cache miss, eviction, or worker restart.
- The last completed workflow task before the current one called
mutableSideEffectwith an unchanged value. - That task produced no commands. For example: a loop pass that reads a setting and then blocks in
Workflow.await(condition)with no timer.
Any later command event cancels the fake, which is why this is easy to miss. Only the last completed task matters.
A possible fix
WorkflowTaskCommandsListener.workflowTaskStarted already calls handleWorkflowTaskStarted() on every queued command. During replay it fires from WorkflowTaskStateMachine.handleCompleted(), at the next task's WorkflowTaskCompleted, so by then every command event of the previous task has been applied. A mutableSideEffect fake still in RESULT_NOTIFIED_REPLAYING at that point can only belong to a skipped call.
In that state the cached result has not been delivered yet either, so the fix has to notify as well as cancel. The existing NON_MATCHING_EVENT transition does both:
// MutableSideEffectStateMachine.InvocationStateMachine
@Override
public void handleWorkflowTaskStarted() {
if (getState() == State.RESULT_NOTIFIED_REPLAYING) {
explicitEvent(ExplicitEvent.NON_MATCHING_EVENT);
}
}
We tried this locally by putting a patched copy of the class on the test classpath:
- the repro below passes;
- our own workflow's test suite passes with the patch and with skipping comparators.
We have not run the SDK's own test suite against it.
Steps to Reproduce the Problem
The test fails every time on the time-skipping test server. The same workflow fails against a real dev server too, pointed at it with setUseExternalService(true) and setTarget(...). A cache eviction stands in for a worker restart, and the eviction goes through reflection because WorkerFactory.getCache() is package-private.
@WorkflowInterface
public interface ProbeWorkflow {
@WorkflowMethod
long run();
@SignalMethod
void poke();
}
public static class ProbeWorkflowImpl implements ProbeWorkflow {
private long pokes;
@Override
public long run() {
long seen = 0;
while (seen < 2) {
// Same value every time: recorded on the first call, skipped afterwards.
Workflow.mutableSideEffect("k", Long.class, (a, b) -> !a.equals(b), () -> 1L);
long s = seen;
Workflow.await(() -> pokes != s); // no timer: this task emits no commands
seen = pokes;
}
return seen;
}
@Override
public void poke() {
pokes++;
}
}
@Test
public void skippedMutableSideEffectSurvivesFullReplay() throws Exception {
TestWorkflowEnvironment env = TestWorkflowEnvironment.newInstance();
try {
env.newWorker("probe").registerWorkflowImplementationTypes(ProbeWorkflowImpl.class);
env.start();
ProbeWorkflow stub =
env.getWorkflowClient()
.newWorkflowStub(
ProbeWorkflow.class,
WorkflowOptions.newBuilder().setTaskQueue("probe").setWorkflowId("probe").build());
WorkflowClient.start(stub::run);
Thread.sleep(500);
stub.poke(); // task 2: mutableSideEffect skipped, no commands
Thread.sleep(500);
// Simulate a worker restart: the next task is a full replay.
Method getCache = WorkerFactory.class.getDeclaredMethod("getCache");
getCache.setAccessible(true);
Object cache = getCache.invoke(env.getWorkerFactory());
cache.getClass().getMethod("invalidateAll").invoke(cache);
stub.poke(); // task 3: replay leaks task 2's fake marker
long result =
WorkflowStub.fromTyped(stub).getResultAsync(Long.class).get(10, TimeUnit.SECONDS);
assertEquals(2L, result); // TimeoutException; the worker logs "marker name is required"
} finally {
env.close();
}
}
The worker logs:
WARN i.t.internal.worker.WorkflowWorker - Failure while reporting workflow progress to the server. ...
io.grpc.StatusRuntimeException: INVALID_ARGUMENT: marker name is required
at ...WorkflowServiceBlockingStub.respondWorkflowTaskCompleted(...)
Two cheap ways to confirm the cause:
- Return a value from the function so the call never skips, for example comparator
(a, b) -> true. The test then passes. - Add a timer (
Workflow.await(Duration, condition)), so the task has a command event to cancel the fake. The test also passes.
Workaround
Never let mutableSideEffect skip: pass an updated comparator that always returns true, so every call records a marker. In replay mode the comparator is not consulted, so this is replay-compatible in both directions with histories written while values were skipped. We checked this with WorkflowReplayer. The cost is one MarkerRecorded event per call.
This does not help an execution whose last completed task was written by code that skipped. Such an execution still fails on its next full replay.
Related
- #1668: "Subsequent MutableSideEffect calls inside one Workflow Task may explode with non-determinism on replay". It is the same state machine, and the same skipped-versus-recorded asymmetry during replay. The symptom differs: there, a recorded marker is matched to the wrong call (non-determinism); here, a skipped call's fake command is never matched at all.
Specifications
- Version:
temporal-sdk/temporal-testing1.40.0, the latest release. Nothing since v1.40.0 onmaintouchesMutableSideEffectStateMachine. - Platform: macOS, OpenJDK 21.0.12. Our workflow is Kotlin 2.4.10; the repro above is plain Java.
- How we found it: an intermittent hang in a full test suite on the time-skipping test server. We saw full replays there both after
UnhandledCommandrejections and without one.
- 主要语言
- Java
- 星标
- 441
- 派生
- 260
- 平均合并
- 5 天 3 小时
- 30 天内合并 PR
- 19
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
temporalio/sdk-java 的其他 Issue
-
enhancement
难度 2/5 1-3 小时 新手友好度 65/100
temporalio/sdk-java#1825 ·
维护者通常 2 天内回复
-
Add Spring Boot auto-configuration for standalone ActivityClient可能已有人在做 @Quinn-With-Two-Ns 于 7 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 35/100
temporalio/sdk-java#3146 · 2 条评论 · 已指派 1 人 ·
维护者通常 2 天内回复
-
Proposal: handle SIGTERM by default to initiate graceful worker shutdown可能已有人在做 @eamsden 于 22 天前认领。 未关闭
temporalio/sdk-java#3135 · 1 条评论 · 已指派 1 人 ·
维护者通常 2 天内回复
-
Skip result deserialization for local activities and SideEffect when not replaying (mutableSideEffect already does this)可能已有人在做 @Quinn-With-Two-Ns 于 17 天前认领。 未关闭enhancement
难度 4/5 3-5 天 新手友好度 54/100
temporalio/sdk-java#3125 · 2 条评论 · 已指派 1 人 ·
维护者通常 2 天内回复
-
Skip input serialization for local activities when doNotIncludeArgumentsIntoMarker is set可能已有人在做 @Quinn-With-Two-Ns 于 17 天前认领。 未关闭enhancement
难度 3/5 1-2 天 新手友好度 55/100
temporalio/sdk-java#3124 · 已指派 1 人 ·
维护者通常 2 天内回复
查看 temporalio/sdk-java 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
IdentityArrayObjectSet iterator remove may throw ArrayIndexOutOfBoundsException可能已有人在做 @jiteshkhatri11 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
javapathfinder/jpf-core#660 · 1 条评论 ·
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
breaking change bug needs human review not ready priority medium size S
难度 2/5 1-3 小时 新手友好度 76/100
martin-francois/symphony-trello#1193 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复