WorkflowReplayer replayWorkflowExecution

Hi
I have exported the workflow history from temporal UI(8088), which is a son file and trying to replay with
WorkflowReplayer.replayWorkflowExecution(
new File(absolutePath+"/dithostory.json"), MyWorkFlowImpl.class);

I am getting exception –
io.temporal.common.converter.DataConverterException: com.google.protobuf.InvalidProtocolBufferException: JsonObject

Please let me know I thought json works for this case, may be I am missing some thing

1 Like

Currently the JSON that you get from the Web UI needs a little bit of “massaging” to get it working with WorkflowReplayer. We are working on fixing that.

The problem is some properties, for example via Web UI you get:

"eventType": "WorkflowExecutionStarted",

where it should be:

"eventType": "EVENT_TYPE_WORKFLOW_EXECUTION_STARTED",

(the SDK needs the enum types, not the enum values)

You can take a look at this JSON for example where I went and did all the find/replace to fix it: temporal-patient-onboarding/onboardingrunhistory.json at main · tsurdilo/temporal-patient-onboarding · GitHub

If you send your JSON history I can do the same for you and then you can see the diff to do it yourself.

Getting execution history JSON from the CLI (tctl) should work however, could you test?

Hi
I also got the same exception.

My setting:
Temporal server: docker-compose v1.11.3
Temporal Java SDK: 1.0.7

First, I exported the json file from Temporal UI:

[
	{
		"eventId": "1"
		...
	}
]

Then I got the exception:

io.temporal.common.converter.DataConverterException: com.google.protobuf.InvalidProtocolBufferException: Expect message object but got: [{"eventId":"1","eventTime":...}]

So I modified the json to: (add "events")

{
	"events": [
		{
			"eventId": "1"
			...
		}
	]
}

But still got:

io.temporal.common.converter.DataConverterException: com.google.protobuf.InvalidProtocolBufferException: JsonObject
Caused by: com.google.protobuf.InvalidProtocolBufferException: JsonObject

I roughly checked the enum types in json and thought they are correct:

"eventType": "EVENT_TYPE_WORKFLOW_EXECUTION_STARTED"
"kind": "TASK_QUEUE_KIND_NORMAL"
"initiator": "CONTINUE_AS_NEW_INITIATOR_UNSPECIFIED"

The most weird thing is that I tried patient-onboard but still got another exception:
(temporal-patient-onboarding/onboardingrunhistory.json at main · tsurdilo/temporal-patient-onboarding · GitHub)

java.lang.RuntimeException: query failure for workflow_id: "workflow_id_in_replay"
run_id: "run_id_in_replay"
, queryType=__replay_only, args=Optional.empty, error=io.temporal.internal.replay.InternalWorkflowTaskException: Failure handling event 5 of 'EVENT_TYPE_ACTIVITY_TASK_SCHEDULED' type. IsReplaying=true, PreviousStartedEventId=3, workflowTaskStartedEventId=9223372036854775807, Currently Processing StartedEventId=3
Caused by: java.lang.IllegalStateException: COMMAND_TYPE_SCHEDULE_ACTIVITY_TASK doesn't match EVENT_TYPE_ACTIVITY_TASK_SCHEDULED with EventId=5

I’m trying to use tctl these days, but did you have any other suggestion?
Thanks a lot!

Updated the patient onboarding demo json, it was outdated - temporal-patient-onboarding/testrun.json at main · tsurdilo/temporal-patient-onboarding · GitHub
and enabled the replay test. Should be ok now. Thank you for noticing this.

Can you vote up issue Fix workflow history json (displayed and exported) to work with Java SDK WorkflowReplayer · Issue #350 · temporalio/web · GitHub?
As it stands right now for Java SDK the only options for WorkflowReplayer is indeed to manually change the enums in json.
Would be great to get this fixed asap.

@Ramprasad_Indarapu @tihomir

I was experiencing the same issue and I believe it is due to a protobuf limitation in deserializing the io.temporal.api.history.v1.HistoryEvent.

The field HistoryEvent.event_time field is defined as a Timestamp, here.

Looking at proto’s code, I found we will attempt to mergeTimestamp from a JsonElement. However, based on the formatting of our replay history, we will have serialized data such as "eventTime": { "seconds": "1634673055", "nanos": 102059312 }. This will be deserialized as a JSONObject by gson, and will throw an UnsupportedOperationException when attempting to parse.

Interestingly, this issue was opened (coincidentally today) against the protobuf project on github: [JAVA]supporting nanos and second in timestamp merge by michaelandrepearce · Pull Request #9118 · protocolbuffers/protobuf · GitHub.

To fix this for temporal java sdk, I believe we may need to convert the struct into a single primitive timestamp.

@tihomir which temporal version(s) were you using to generate this event history? It has quite a few differences with the ones I am seeing on 1.10.x.

@akd @Ramprasad_Indarapu
In Java SDK 1.4.0 we fixed the incompatibility with json history generated via tctl, see Support tctl format of history (#729) · temporalio/sdk-java@257a8c9 · GitHub

1 Like